Anda di halaman 1dari 134

INTRODUCTION

RPG is an abbreviation for Report Program Generator. It is a high level language in which the programmer codes the specifications.

Developed by IBM in 1960s.


RPG code is written on a variety of specification forms, each with a specific set of functions. Many of the entries which make up a specification type are position-dependent. Each entry must start in a specific position depending on the type of entry and the type of specification. There are seven types of specifications. Each specification type is optional. Specifications must be entered into your source program in the order HFELICO.

FEATURES OF RPG

Structured language

RPG provides structured programming constructs (Opcodes, Subroutines, Subprograms) that helps us in approaching a modular program design.

Strong at file operation

The data records can be accessed in any direction, sequentially or randomly with out need to open and close the files.

Strong interactive programming language

RPG in combination with Screen Design Aid (SDA) forms a powerful interactive programming language. The screens designed through SDA can be easily accessed from an RPG program.

Sub files

This is excellent feature of RPG. Sub files are special kind of screen files using which we can display multiple records onto a screen with minimal programming effect.

Generation of Complex Reports:

RPG in combination with RLU (Report Layout Utility) helps us in generating formatted and complex reports.

Interface with CL language :


We can establish data communication among a CL language and an RPG

program.

Naming Conventions & Data Types


Naming Conventions First character of all variable names must be A to Z (or a to z), @, # or $. Subsequent characters A to Z (or a to z), @, # or $, 0 to 9, or the underscore (_) character Not case sensitive If @, # or $ is used as the first character of a variable name, at least one other character must be specified No embedded blanks or periods allowed All names are global to all areas of program A file / recrd format name must be 1 to 10 characters in length A file name cannot be the same as record format name Data Types Character (A or blank) Float (F), Packed (P), Integer (I) Date (D), Time (T), Timestamp (Z)

Indicators
An indicator is a logical variable that is either set ON (1) or OFF (0). They are generally used to indicate the result of an operation, indicate error condition, indicate file operation status or to condition (control) the processing of an operation. They determine the path the program will take during processing depending on how they are set or used.

Indicators can be defined as variables


Indicators can be set ON or OFF using Opcodes SETON and SETOFF or using MOVE statements

Indicators are of 2 types General indicators and special indicators General Indicators are 0 99. Special Indicators: 1. Halt indicators H1 H9. These are used to signal severe error. When Halt indicator is set on, program ends abnormally. 2. External indicators U1 to U8. Passed from out side RPG program. Used to condition opening of a file or to control calculations 3. First Page 1P - Used in logic cycle program to print Report Header 4. Matching Indicator MR - Used in logic cycle program to process matching records of Primary and Secondary files 5. Level Break L0 L9 ( used in logic cycle), LR Last record 6. Return Indicator RT used as return function 7. Overflow indicator OA to OG, OV used for printer files 8. Command keys (or) Function keys KA to KN, KP to KY command level keys F1 to F24

Constants and Literal Values


Named constants are defined with data type N using I Spec Figurative constants: Special, built-in names that have predefined values associated with them. Names begin with an asterisk (*)

*BLANKS *ZEROS *LOVAL *HIVAL *OFF *ON

Reserved Fields

Compiler Directives
Directs compiler to perform certain operations such as printing compiler listing, inclusion of source members. Begin in position 7 of RPG statement

/COPY
/TITLE

: Compiler includes source code from other source member


: Prints specified text on top of each page of compiler listing

/SPACE : Causes blank lines to be printed on compiler listing

Reserved Words
Reserved words are special names with predefined purpose *DATE : Used to retrieve program run date. Format is determined by the system value. Format may be overridden by an entry in column 19 of H spec. *DAY : Used to retrieve the session day *MONTH : Used to retrieve the session month *YEAR : Used to retrieve the session year *ENTRY : Used with PLIST to define the entry parameter list *INZSR : Used with BEGSR to define the Initialization subroutine *LIKE : Used with DEFN to define a field like another field *LOCK : Used with IN, OUT to perform read/write to data area with lock *DTAARA : Used with DEFN, IN, OUT to define and perform read/write operations on data area *PSSR : Used with BEGSR to define the Program status subroutine

RPG/400 SPECIFICATIONS
RPG source statements consists of 80-character card images having line numbers in the first few columns of each source statements. Every line having a form type in column 6 (H, F, E, L, I, C, O). Any statement with an asterisk (*) in column 7 is a comment.

Specification types:
1. Control specifications (H spec) provide the compiler with information about generating and running programs, such as the program name, date format, and use of alternate collating sequence or file translation. 2. File description specifications (F Spec) describe all the files that the program uses.

3. Extension specifications (E Spec) contains the array definitions 4. Line Counter Specifications (L spec) describe the length of the form and the number of lines to print on a page for a program described Printer file 5. Input Specifications (I spec) describe the structure of program described files, data structure and subfield definitions and named constant definitions 5. Calculation specifications (C spec) describe the calculations done on the data and the order of the calculations. Calculation specifications also control certain input and output operations. 6. Output specifications (O Spec) describe the output records and fields used by the program.

Sample RPG Program - Demo


Creating a new RPG source member using PDM Entering source statements using SEU Compilation and resolving compilation errors Executing RPG program from command line

CONTROL SPECIFICATION

Control Specifications - H Spec


Identified by H in column 6 Provides information about generating and running programs Only one control specification is allowed per program Data area named RPGHSPEC can be created to contain the information to be used for all RPG/400 programs that do not contain a control specification

CRTDTAARA DTAARA(QGPL/RPGHSPEC)+ TYPE(*CHAR) + LEN(26) + VALUE(DATFMT(*YMD/) TIMFMT(*HMS)) + TEXT(Default RPG H-SPEC) OR CRTDTAARA DTAARA(QPRG/DFTHSPEC)+ TYPE(*CHAR) + LEN(26) + VALUE(DATFMT(*YMD/) TIMFMT(*HMS)) + TEXT(Default RPG H-SPEC)

OR
Use H specification in RPG

File Specifications

File Description Specification

Position 6 7-80 7 42 44 80 81 100 Comments F

Description non-commentary part fixed-format entries

Columns 6 Form type (F)

Description

7 14

File Name

15

File Type (Mode in which file is being used in the program) I Input file, O Output file, U Update File, C Combined

16
17

File Designation (F Full Procedural, P Primary, S Secondery)


End Of File

18
19

Sequence
File Format (E externally described file, F Program described file)

Columns 20 File addition Blank Do not add records A Allow record Adds Match field sequence Blank or A Ascending D Descending File Format: E Externally Described F Program Described

Description

21

22

23-27
28

Record Length
Limits processing : Blank : Sequential or random processing L Limits processing Length of key or record address

29-33

Columns

Description

34

Record Address type Blank Non keyed processing A - Character keys D - Date Keys G - Graphic keys K - Externally described key P - Packed key T - Time Keys Z - Time Stamp Keys

35

File Organization B Non Keyed , Program described I - indexed T Record address

Columns 36-42

Description Device Disk - Disk file Printer - Printer File SEQ - Sequentially Organized SPECIAL - Special device WORKSTN - Workstation file

43

(reserved)

44-80

File Keywords

81-100

Comments

FILE READ
0001.00 FEMPMASTER IF E 0002.00 FDSPLYFILE CF E 0002.01 C 0005.00 C 0006.00 C 0007.00 C 0008.00 C 0009.00 C File Filename EMPMASTER File Type I READ DOW EXFMT READ ENDDO SETON End of Designation F File File Addition Sequence LR K DISK WORKSTN EMPRECFMT *IN10=*OFF READING EMPRECFMT 10 10

File
Format E

Limits
Processing

Record
Address Type K Device DISK

Calculation Specifications

C-SPEC
In this specification, we code variable declarations and the executable statements. It primarily consists of essentially a Operation code (verb) and three operands known as FACTOR-1, FACTOR-2 and RESULT Operation codes entered on the calculation specifications indicate the kind of operation to be performed For example, for reading a record, READ operation code will be used.

Layout
Columns 1-5 6 7-8 Description Sequence number C Control Level : Blank,L0,L1-L9,LR,SR,AN,OR

9-11

Indicators : Blank,01-99,KA-KN,KP-KY,L1-L9,LR,MR,H!-H9,RT,U1-U8,OAOG,OV

12-25 26-35

Factor 1 Operation code

Columns 36-49

Description Factor 2 or Extended factor 2

50-63 64-68 69-70

Result Field Result Field Length Result Field Decimal Positions

71-76

Resulting Indicators (High/Low/Equal)

77-80 81-100

(Blank) Comments

1.

Arithmetic operations
ADD SUB MULT DIV MVR SQRT Z-ADD Z-SUB

2.

Variable Definition and Move operations


MOVE MOVEL DEFN

3. Date/time operations
TIME (Time of Day)

4. Structured programming operations


IFxx (If)
SELEC (Begin a Select Group) WHxx (When True Then Select) DO (Do)ENDDO DOUxx (Do Until)ENDDO DOWxx (Do While)ENDDO ITER (Iterate) LEAVE (Leave a Do Group)

5.

Branching operations
TAG (Tag) GOTO (Go To) CABxx (Compare and Branch)

6.

Call operations
BEGSR (Beginning of Subroutine) ENDSR (End of Subroutine) EXSR (execute Subroutine)

CASxx (Compare And branch to Subroutine)

CALL (Call a Program) PARM (Identify Parameters)

PLIST (Identify a Parameter List)

7.

File operations
OPEN (Open File for Processing)

CLOSE (Close Files)


READ (Read a Record) WRITE (Create New Records) READC (Read Next Changed Record)

READE (Read Equal Key)

READP (Read Prior Record)

REDPE (Read Prior Equal)

SETGT (Set Greater Than)

SETLL (Set Lower Limit)

KFLD (Define Parts of a Key)

KLIST (Define a Composite Key)

CHAIN (Random Retrieval from a File)

UPDAT (Modify Existing Record)

DELET (Delete Record)

COMIT (Commit)

ROLBK (Roll Back)

UNLCK (Unlock a Data Area or Release a Record)

8. Data area operations


IN (Retrieve a Data Area)

OUT (Write a Data Area)

9. Array operations
MOVEA (Move Array)

XFOOT (Summing the Elements of an Array)

LOKUP (Look Up a Table or Array Element)

SORTA (Sort an Array)

10. String operations


SCAN (Scan String)

CHECK (Check Characters)

SUBST (Sub string)

XLATE (Translate)

CAT (Concatenate Two Strings)

ARITHMATIC OPERATIONS
ADD
The add verb is used to find the sum of numeric values.it has two formats: Format1:

CODE

Factor 1

Factor 2

Result Field INDICATORS

ADD

NUM1

NUM2

RNUM

HI

LO EQ

This statement is equivalent to saying RNUM=NUM1+NUM2

Format : 2

CODE

Factor 1

Factor 2

Result Field INDICATORS

ADD

NUM2

RNUM

HI

LO EQ

If factor1 is blank,factor2 is added to result and sum placed in result field.

SUB
The SUB verb is with numeric values for subtract operation.

MULT
The MULT verb is used to find the product of two numbers.

DIV
The DIV verb is used for division operation with numeric values.

MVR
The MVR operation moves the remainder from the previous DIV operation to a separate field named in the result field.

SQRT
The SQRT operation derives the square root of the field named in the result field.

Z-ADD
The Z-ADD stands for zero add. Zero is added to the factor 2 and the sum is placed in the result. This is basically used to declare, initialize or move a value into the numeric filed.

Z-SUB
The Z-SUB stands for zero subtract. Factor 2 is subtracted from zero and the difference is placed in the result. This is basically used to negate the value of a variable.

Program for Arithmetic operation


C C C C ** A = A + B C* C* A ** C A C C ** C A C C ** C A C C ** MOVE MOVE MOVE MOVE 9 A 7 B *ZEROS *ZEROS A 20 20 C D 30 20

ADD B DSPLY

ADD B DSPLY
SUB B DSPLY MULT DSPLY B

C C C C C C ** C C ** C C C

A C D C

DIV B MVR DSPLY DSPLY SQRT A DSPLY Z-ADD DSPLY 2

C D

20

Z-SUB 2 DSPLY SETON

20 LR

O/P DSPLY 16 ,DSPLY 2 ,DSPLY 63 ,DSPLY DSPLY 2 ,DSPLY 2-

1 ,DSPLY 2 ,DSPLY

Move operations
MOVE
MOVE is used to move data into a field. The value specified in factor1 will be moved into the filed specified in result field. Used to convert numeric data to character and vice versa

MOVEL
MOVEL (move left) is similar to MOVE with the only difference that the factor 2 will be moved in to but is left justified.

DEFN
Define a field based on the attributes (data type,length and decimal positions) of another field. Define field as a data area.

Program for move operation


0001.00 C 0002.00 C 0002.01 ** 0002.02 C 0002.03 C 0002.04 ** 0004.03 C 0004.04 C 0004.05 ** 0004.06 C 0004.07 C 0004.08 C RES MOVE DSPLY SETON LR 'ABCDE' RES 3 RES MOVEL DSPLY 'ABCDE' RES 3 NUM1 MOVEL DSPLY 1234637 NUM1 50 NUM1 MOVE DSPLY 2345678 NUM1 50

O/p DSPLY DSPLY DSPLY DSPLY

45678 12346 ABC CDE

Structured programming operations


IFxx
IF operation is used for conditional execution of statements. Each IF has a corresponding ENDIF or END statement. The statements placed between the IF and ENDIF will be executed only when the condition satisfied The condition may also be a compound condition supplemented by ANDxx or ORxx ELSE state can also be coded between IF and ENDIF so that if the condition is not satisfied then the statements between ELSE and ENDIF can be executed.

NOTE:

XX Denotes a relational operator which could any one of the following EQ NE GT LT GE LE Equal to Not equal to Greater than Less than Greater than or equal to Less than or equal to

Example 1
Calculation of Bonus AND PERKS if basic greater than or equal to 3000
0002.00 0003.00 0004.00 0005.00 0005.02 0005.03 0005.04 0007.00 o/p DSPLY 4000 DSPLY 3000 C C C C C C C C Z-ADD3000 BASIC IFGE 3000 Z-ADD4000 Z-ADD3000 BONUS DSPLY PERKS DSPLY ENDIF SETON BASIC 40 BONUS 40 PERKS 40

LR

Example :2
A clerk with salary more than 2500 or a manager will get a bonus of 4000 and perks of 3000. Otherwise bonus would be 2000 and perks would be 1200
0000.02 C 0000.03 C 0000.04 C 0001.00 C 0001.01 C 0001.02 C 0001.03 C 0001.04 C 0001.07 C 0002.00 C 0002.01 C 0005.01 C MOVEL MOVEL Z-ADD IFEQ ANDGT OREQ Z-ADD Z-ADD ELSE Z-ADD Z-ADD ENDIF 'CLERK' DESIGN 7 'MANAGER' DESIGN 7 2500 BASIC 40 'CLERK' 2500 'MANAGER' 4000 BONUS 40 3000 PERKS 40 2000 1200 BONUS PERKS 40 40

DESIGN BASIC DESIGN

0005.04 C 0005.05 C 0006.00 C O/p

BONUS PERKS

DSPLY DSPLY SETON

LR

DSPLY 4000 DSPLY 3000 NOTE: Only change manager to manager1 you get an output as 2000,1200

SELEC :
when we have multiple nested IFs the code becomes complex and we will have to take care of matching the IFs with their corresponding ENDIFs. SELECENDSL can be used as an alternative in such a case. Here we have multiple WHXX statements between SELEC and ENDSL. If any of the WHXX condition is satisfied then the statements under it will be executed. If none of the condition satisfy then the statements under OTHER will be executed.

SYNTAX:

FACTOR1

OPCODE
SELEC WHXX -----OTHER -----ENDSL

FACTOR2

DO ..ENDDO :
A DO statement can be used to repeat the code enclosed between DO and ENDDO, a specific number of times. Example:

DISPLAY ALL ODD NUMBERSS BETWEEN 1 TO 10


0002.00 C 0003.00 C 0004.00 C 0005.00 C O/P 1,3,5,7,9 1 NUM DO 10 DSPLY ENDDO 2 SETON NUM 50

LR

DOUXX ..ENDDO :
DOUXX (do until loop) this loop will be executed at least once irrespective of whether the condition is satisfied initially or not because, here the condition is post-tested .

Example:

INITIALIZATION AND INCREMENTATION HAS TO BE EXPLICITLY DONE


0001.00 C 0002.00 C 0003.00 C 0004.00 C 0005.00 C 0006.00 C O/P 1,3,5,7,9 NUM NUM Z-ADD DOUGT DSPLY ADD ENDDO SETON LR 2 NUM 1 10 NUM 50

DOWXX ..ENDDO :
DOWXX (do while loop) is similar to DOU loop except that the loop continues execution as long as the condition is true and terminates once it becomes false. Also the condition is per-tested. Example:

DISPLAY ALL ODD NUMBERSS BETWEEN 1 TO 10


0002.00 C 0002.01 C 0002.02 C 0002.03 C 0002.04 C 0003.00 C O/P 1,3,5,7,9 Z-ADD 1 BASIC DOWLE 10 BASIC DSPLY ADD 2 ENDDO SETON BASIC 20

BASIC LR

LEAVE :
LEAVE statement can only be given inside a loop. It abruptly terminates the loop execution and transfers the control to the next statement after ENDDO.

ITER :
ITER statement can only be given inside any of the loop. It is used to transfer the control to the beginning of the loop to continue execution. Example:

DISPLAY ALL ODD NUMBERSS EXCEPT 5 ,BETWEEN 1 TO 10


0001.00 C 0002.00 C 0003.00 C 0004.00 C 0005.00 C 0005.01 C* 0006.00 C NUM NUM Z-ADD 1 DOWLE 10 IFEQ 5 ADD 2 ITER LEAVE ENDIF NUM 50

NUM

0007.00 C 0008.00 C 0009.00 C 0010.00 C O/P 1 3 7 9

NUM

DSPLY ADD 2 ENDDO SETON

NUM LR

NOTE:
In the above example if leave is coded in place of ITER the loop execution terminates once the value of num is equal to 5.hence only 1 and 3 will get displayed.

Branching operations
TAG & GOTO

NOTE: While using TAG only factor1 is coded which contains the label name. GOTO statement is coded with the name of the label in factor 2.

TAG is used in accordance with GOTO in a program. Using GOTO we can transfer the control from one place to another with in a routine.
The place where the control needs to be transferred should be labeled (named) using a TAG statement.

Example:

DISPLAY NUMBERS FROM 10 TO 1


0002.00 C 0002.01 C 0003.00 C 0004.00 C 0005.00 C 0006.00 C 0006.01 C* 0007.00 C 0008.00 C O/P 10,9,8,7,6,5,4,3,2,1 CBSI NUM NUM NUM Z-ADD10 NUM 50 TAG DSPLY SUB 1 NUM IFGE 1 GOTO CBSI CABGE1 CBSI ENDIF SETON LR

CABXX :
CABXX(COMPARE AND BRANCH) command is simply a combination of IF & GOTO statement. Example:

DISPLAY NUMBERS FROM 10 TO 1


0002.00 C 0002.01 C CBSI 0003.00 C NUM 0004.00 C 0006.01 C NUM 0008.00 C O/P 10,9,8,7,6,5,4,3,2,1 Z-ADD10 TAG DSPLY SUB 1 CABGE1 SETON NUM 50

NUM CBSI
LR

Date/Time operations
The time operation accesses the system time of day Result : Must be of either a 6,12 or 14 digit numeric field (no decimal positions) If six-digit numeric field :Time of the day only If 12-digit numeric field :Time of the day and system date with out century. If 14-digit numeric field: Time of the day and system date with out century.

Example:

DISPLAY SYSTEM DATE/TIME


0000.01 0001.00 0002.00 0003.00 C C C C Z-ADD0 TIME DSPLY SETON NUM1 120 NUM1 LR

NUM1

Call operations
BEGSRENDSR
BEGSRENDSR Is used to code a subroutine with in a program. BEGSR is required at the beginning of every subroutine. The name of the subroutine is mentioned in factor 1 of BEGSR.

EXSR
EXSR is used to call a subroutine and after the execution of the subroutine control returns back to the next statement after EXSR. The name of the subroutine is given in factor 2 position.

Example:

THE MESSAGES WILL BE DISPLAYED IN THE SEQUENCE BEFORE,INSIDE,AFTER


0001.00 C 0002.00 C 0003.00 C 0004.00 C* 0004.01 C 0005.00 C 0006.00 C 0007.00 C O/p DSPLY BEFORE ,DSPLY INSIDE,DSPLY AFTER NOTE: If the name of the subroutine is changed to *INZSR then, the sequence of the messages would be INSIDE,BEFORE,INSIDE,AFTER. DSPSR 'INSIDE' 'AFTER' 'BEFORE' DSPLY EXSR DSPLY RETURN SETON BEGSR DSPLY ENDSR LR DSPSR

CASXX . END CODE CASxx


Factor 1 Compared

Factor 2 Compared

Result Field INDICATORS Subroutine name HI LO EQ

This helps us in conditional execution of subroutine. Factor-1 and factor-2 are compared and if the condition satisfied the subroutine named in the result field is executed. Example:

HERE ADDSR,SUBSR,MULSRDIVSR WILL BE EXECUTED IF OPT CONTAINS A.S,M,OR D RESPECTIVELY.


0001.00 FDSPSELECT CF E WORKSTN 0002.00 C *IN03 DOWEQ *OFF 0003.00 C EXFMT OPCODE

0005.00 C 0006.00 C 0007.00 C

OPT OPT OPT

CASEQ CASEQ CASEQ

'A' 'S' 'M'

ADDSR SUBSR MULSR

0008.00 C
0009.00 C 0010.00 C 0011.00 C

OPT

CASEQ
ENDCS ENDDO SETON

'D'

DIVSR

LR

0012.00 C*
0013.00 C 0014.00 C 0015.00 C 0017.00 C 0018.00 C 0019.00 C SUBSR NUM1 ADDSR NUM1

RETURN
BEGSR ADD ENDSR BEGSR SUB ENDSR NUM2 RESULT NUM2 RESULT

0020.00 C 0021.00 C 0022.00 C 0022.01 C

MULSR NUM1

BEGSR MULT ENDSR NUM2 RESULT

DIVSR

BEGSR

0022.02 C
0022.03 C

NUM1

DIV
ENDSR

NUM2

RESULT

DSPSELECT_CASXX 0000.40 A R OPCODE

0000.50 PW1
0000.60 0000.70 0000.80 0000.90 0001.00

A*%%TS SD 20050802 125252 QSECOFR


A A A A A CA03(03) 12 34'B 10 34'A 14 34'OPT 16 34'C =' =' =' ='

REL-V4R4M0 5769-

0001.10 0001.20 0001.30 0001.40

A A A A

NUM1 NUM2 RESULT OPT

3S 0B 10 50 3S 0B 12 50 5S 0O 16 50 1A I 14 50

CALL : CODE CALL

Factor 1

Factor 2 Called program name

Result Field

INDICATORS HI LO EQ

CALL is used to execute another RPG program from inside an RPG program. The program in which had the CALL statement is referred as the parent or a calling program and the program being called is termed as child or called program. CALLED program has to be compiled before compiling a calling program. Because while compiling the calling program it looks for a compiled object of the called program and if it is not found an error occurs .

Example: CALLING PROGRAM(THIS PROGRAM CALLSUB PROGRAM WHICH FINDS THE SUM OF FIRST 100 NATURAL NUMBERS. 0002.00 0003.00 0004.00 C C C 'AFTER' 'BEFORE' DSPLY CALL 'CALLSUB' DSPLY

0005.00 C RETRN CALLSUB (Called program) 0000.01 C 1 DO 100 NUM 0000.02 C ADD NUM SUM 0000.04 C ENDDO 0000.05 C SUM DSPLY 0000.06 C RETRN 0000.07 C *INZSR BEGSR 0001.01 C Z-ADD0 SUM 80 0002.00 C Z-ADD0 NUM 30 0003.00 C ENDSR O/p DSPLY BEFORE, DSPLY 5050,DSPLY AFTER

PLIST & PARM


When parameters are passed into called program, it should be capable enough to receive the same. For that reason we code PLIST statement at the top of the called program. *ENTRY Should appear in factor1 of PLIST command followed by PARMs.

Example:
*ENTRY PLIST PARM PARM PARM A B C

POINTS TO NOTE:
1.The number of parameters passed and receiving should be the same. 2.Their attributes (data type and size) should preferably the same. 3.the order of parameters should be the same. 4.can have different names or same names in called and calling programs.

Example: PLISTPP_NM

PROGRAM FOR CALCULATION OF SIMPLE INTEREST


0001.00 FDSPARR 0001.01 C 0002.01 C LIST1 CF E PLIST PARM P 50 WORKSTN

0002.02 C
0002.03 C 0002.04 C 0003.00 C

PARM
PARM PARM PARM

R
T SI A

40
20 70 80

0004.00 C
0004.01 C 0004.02 C 0005.00 C

EXFMT
CALL EXFMT SETON

INTEREST
'PLISTSUB' INTEREST LR LIST1

PLISTSUB_NM(SUBPROGRAM)

0001.00 C
0002.00 C 0003.01 C 0003.02 C

*ENTRY

PLIST
PARM PARM PARM P1 R1 T1 50 40 20

0003.03 C
0004.00 C 0004.01 C 0005.00 C P1 T1

PARM
PARM MULT MULT R1 SI1

SI1
A1 SI1 SI1

70
80

0006.00 C
0007.00 C 0008.00 C SI1

DIV
ADD

100
P1

SI1
A1

RETURN

DSPARR_DSPLAYFILE
0004.20 0004.40 A A R INTEREST 5 27'SIMPLE INTEREST CALCULATION

0004.70
0004.90 0005.10 0005.30 0005.50 0005.70 0005.90 0006.30 0006.40 0006.50 0006.60 0006.70

A
A A A A A A A A A A A P R T SI A

6 27'==========================
9 10'ENTER PRINICIPLE 11 10'ENTER RATE 13 10'ENTER TIME :' :' :'

15 10'SIMPLE INTEREST IS :' 17 10'AMOUNT IS :'

20 41'PRESS ENTER TO CONTINUE' 5S 0B 9 33 4S 0B 11 33 2S 0B 13 33 7S 0O 15 33 8S 0O 17 33

File operations
READ : The READ operation reads the record from a file. WRITE : The WRITE operation writes a new record into the file. READE :The READE operation retrieves the next sequence record from a file. READP : READP (read prior) operation reads the prior record from a file. READPD :The READPF operation is just a combination of READE and READP. READC : The READC operation can be used only with an externally described
workstation file to obtain the next changed record in a sub file.

SETGT & SETLL : SETGT & SETLL only positions the record pointer and does
not read the records.

UPDAT :

The UPDAT operation is modify the records of an update disk file. (U in file type i.e., position 15 of F-Spec).

PROGRAM FOR FILE READ


FILEREAD_RPG
0001.00 FEMPMASTER IF E K DISK 0002.00 FDSPLYFILE CF E WORKSTN 0002.01 C READ EMPRECFMT 0005.00 C DOW *IN10=*OFF 0006.00 C EXFMT READING 0007.00 C READ EMPRECFMT 0008.00 C ENDDO 0009.00 C SETON

10

10 LR

EMPMASTER_PF
0001.00 0002.00 0003.00 0004.00 0005.00 A A A A A R EMPRECFMT EMPNUMBER 5 EMPNAME 10 EMPSALARY 10 2 K EMPNUMBER

DSPLYFILE_DISPLAY FILE
0001.60 0001.90 0002.00 0002.10 0002.20 0002.30 0002.40 0002.50 0002.60 0002.70 0002.80 0002.90 0003.00 0003.10 A A A A A A A A A A A A A A R READING CA03(03) 5 33'KARISHMA S/W LTD' DSPATR(UL) DSPATR(HI) 8 38'EMPNO:' 10 37'EMPNAME:' 12 32' ' 12 29' ' 12 27' ' EMPNUMBER R B 8 46REFFLD(EMPRECFMT/EMPNUMBER MINDADB/EMPMASTER) EMPNAME R B 10 46REFFLD(EMPRECFMT/EMPNAME MINDADB/EMPMASTER)

Introduction
Data structures allow to define an area of space within memory to store individual elements of data.

Purpose:
Subdividing fields into subfields Restructure records into different layouts Change field data types Define character fields longer than 256 bytes To add second dimension to arrays Data structures can also be defined externally.

TYPES:
Simple Data Structure External data structure Data Area Data structure File information data structure Program status data structure

Simple Data Structure


To define data structure specify DS in 24-25. Follow the definition with sub field definitions. From to positions indicate the sub fields positions on IPD prompt.

Examples: DISPLAY SYSTEM DATE AND TIME & YEAR


0001.00 DDATE1 0002.00 DDD 0003.00 DMM 0004.00 DYYYY 0005.00 C 0005.01 C 0005.02 C DD MM DS 1 3 5 MOVEL DSPLY DSPLY 2 4 8 UDATE DATE1

0005.03 C
0006.00 C 0007.00 C

YYYY

DSPLY
SETON LR

DATE1 DSPLY

External data structure


READ DATA FROM A DATA BASE FILE USING EXTERNAL DS.
External Data structures

FFLTFILE IF F 112 DISK FEMPPF UF A E DISK DEMPFILE E DS EXTNAME(EMPPF) DID 1 6 DNAME 7 17 DSTATUS 18 19 C *LOVAL SETLL FLTFILE C READ FLTFILE 90 C DOW *IN90 = *OFF C EVAL EMPFILE = FLTFILE C C WRITE EREC 90 C ENDDO C SETON LR

File information data structure


FMaintCust DSDisplay D FileName DFileOpen DFileeof DMsgId DSCRSize DKeyPress DCursorloc *SIZE 369 370 369 371B 0 CF DS *File 9 10 46 9 10 52 E Workstn INFDS(DSDisplay)

INFDS keyword is specified in the F-spec against the file declaration.

File Information Data Structure:


*FILE File Name *RECORD External file RECORD FORMAT Program file Record ID *OPCODE *STATUS Error Code *ROUTINE Name of the routine where error occurred.

File Status codes


00000 00013 01021 01041 01211 01215 01218 01221 01241 01331 No Error Sub file Full Duplicate Key Not allowed Array/Table Sequence error I/O operation to closed file OPEN issued to file already open Unable to allocate Record Update without prior read Record number not found Wait time exceeded for read from work station file.

Program Status Data structure


DS.PSSR_DS 0002.00 0003.01 0003.04 0029.00 0029.01 0029.02 0029.03 0033.00 0033.01 0033.02 0033.03 0045.04 IDS1 I C C C C C C C C C* C SDS *STATUS ERR Z-ADD100 Z-ADD0 NUM1 DIV RETRN *PSSR BEGSR ERR IFEQ 102 NUM1 NUM2 NUM2 30 30 NUM3 30

'ZERO DIV'DSPLY ENDIF MOVE 'CANCLE' RET ENDSR 6

O/P DSPLY ZERO DIV DS.PSSR 2901 tried to divide by zero (factor 2)

Program Status codes


00121- Invalid array index 00202 Called program failed 00211- Called program not found 00231 Called program Halt indicator On 00333- Error on DSPLY operation 00414- Not authorized to use data area 00415 Not authorized to update data area 00431- Data area previously locked 00907- Decimal data error 09999 System program exception error

Program for Data Areas


AUTOMATIC GENARATION OF VEHICAL REGISTRATION NUMBER
0001.00 0001.02 0002.00 0002.01 0003.01 0003.02 0003.03 0007.00 0008.00 0009.00 0010.00 FDSPARR CF E E IDS1 I I I I C C C C WORKSTN LETTER 1 26 1 UDS 1 2 STATE 3 40AREA 5 5 ALPHA 6 90SRLNO *NAMVAR DEFN *IN03 *LOCK AREA0 9

DOWEQ*OFF IN AREA0 MOVE AREA0 DS1

0011.00 0012.00

C C

SRLNO ALPHA

IFEQ 9999 IFEQ 'Z'

0013.00
0014.00 0015.00 0016.00

C
C C C

EXSR ADARA
ELSE EXSR ADALPA ENDIF

0017.00
0018.00 0019.00 0020.00 0021.00 0022.00 0023.00 0024.00

C
C C C C C C C

ELSE
EXSR ADSLNO ENDIF MOVE DS1 FLD001

EXFMTVEHREG EXSR UPDSR ENDDO SETON LR

0025.00 0025.01 0026.00 0027.00 0028.00 0029.00 0030.00 0031.00 0032.00 0033.00 0034.00 0035.00

C* C* C C C C C C C C C C

ERRRTN

BEGSR RETRN

ADARA

BEGSR ADD 1 MOVE 'A' Z-ADD1 ENDSR AREA ALPHA SRLNO

ADALPA 1 ALPHA

BEGSR DO 26 I 20

IFEQ LETTER,I LEAVE ENDIF

0036.00
0037.00 0038.00

C
C C

ENDDO
ADD 1 I

MOVE LETTER,I ALPHA

0040.00 0041.00 0043.00 0044.00 0045.00 0045.01 0045.02 0045.03 0045.04 0046.00 ** 0047.00 A

C C C C C C C C C ADSLNO

Z-ADD1 ENDSR BEGSR ADD 1 ENDSR UPDSR BEGSR MOVE DS1 *LOCK OUT AREA0 ENDSR V

SRLNO

SRLNO

AREA0

0048.00 B ------------z

Display Data Area


Data area . . . . . . . : AREA0 Library . . . . . . . : MINDADB

Type . . . . . . . . . : *CHAR Length . . . . . . . . : 9 Value 'AP01A0001'

DSPARR_DISPALYFILE
0002.40 0002.50 0002.60 0002.70 0002.80 A R VEHREG REL-V4R4M0 5769-PW1 A*%%TS SD 20050801 182655 QSECOFR A A A CA03(03) 8 15'AUTOMATIC GENERATION OF VE GISTRATION NUMBER'

0003.50
0003.90 0004.00

A
A A FLD001

13 20'NEW VEHICAL REGISTRATON NUM:


12A O 13 60 18 56'F3 = EXIT'

Structure of PSDS
16-20 Previous status code 21-28 RPG Source sequence number 40-46 Exception Error ID MCH or CPF 201-208 Name of the file last used 244-253 Job Name 254-263 User name 264-269 Job Number 276-281 --System Date in Udate Format 288-293 Date Compiled 304-333 Source file/library/member

Subfiles
1. A subfile is a series of similar records that can be displayed simultaneously on the screen.

2. When you load data to a subfile data remains in main memory until subfile is written on to the screen.
3.When subfile is written on to the screen data is passed on to the workstation controller.

4. Controller assumes responsibility for handling subfile data on screen until control is returned to the program.
5. A subfile can hold a maximum of 9999 records. 6. At a time 24 subfiles can be active.

Components of a subfile
Two record formats are required SFL - Subfile record format and SFLCTL - Subfile Control Record format. The Subfile Record format holds the actual data and is similar to the database file. The Subfile Control Record format Describes the headings for the fields and controls the subfile size, Display, Number of records and specifies how data is retrieved and what is to be done on data in the subfile on various events.

SUBFILE TYPES Load All Subfile Expanded Load Single Page Load

Load All Subfile


All records are loaded at once.

Maximum 9999 records can be loaded.


Applicable for files with fewer number of records. ROLLUP and ROLLDOWN operations are automatically handled by the program. Control returns to the program once the user moves past the last record in the subfile.

Expanded load
Loads enough records to fill first screen.

Rollup key impression brings control to the program.


First screen records stay in the subfile and new records are appended each time rollup is pressed.

Roll down automatically handled by subfile.

Page at a time subfile


Stores only page worth of records. Program handles both rollup and roll down keys. Subfile is cleared and new page of records are loaded on each key impression after clearing the subfile. Rollup/page down load next set of records. Roll down/page up previous set of records are loaded . Subfile preferred for database having large set of records works without impacting performance.

Key Words
SFLCTL
Defines Subfile control record format Links subfile record format with Subfile format One subfile format maps to one and only one subfile control format and vice versa

SFLSIZ
Specifies size of the subfile. No of records that subfile can hold.Can be hard coded or passed as a hidden field ,S type, 0 Decimals and 5 digits long.

SFLPAG
Specifies number of records that appear on a single screen and must be less than or equal to SFLSIZ

SFLDSPCTL and SFLCTL


Normally conditioned with indicators to display control format or the subfile. Empty subfile- (SFLCTL) cannot be displayed so indicator is seton when subfile is filled or required to be displayed. Having indicator for SFLDSPCTL is optional.

SFLCLR
Normally SFLCLR will have the negative conditioning indicator that is given for SFLCTL and SFLDSPCTL. When indicator is set on it will clear the records in the subfile.

Program for Load all sub file


0001.00 FEXPPF IF E DISK WORKSTN SFILE(DATA1 : RRN) S 4 0 0002.00 FLOADDSP CF E 0003.00 F 0004.00 DRRN 0005.03 ** CLEAR SFL 0005.05 C 0007.00 C 0007.01 C 0008.01 C SETON WRITE SETOFF Z-ADD 1 RRN HEADING1 40 40 102040

0008.02 ** LOADING DATA 0008.03 C 0009.00 C 0009.01 C READ DOW WRITE PFREC03 *IN90=*OFF DATA1 90

0011.00 C 0013.00 C 0013.01 C

ADD READ ENDDO

RRN 90

PFREC03

0014.01 ** DSPLY SFL 0014.02 C 0014.03 C 0014.04 C 0016.00 C 0017.00 C 0017.01 C 0017.02 ** 0018.00 C SETON LR DOW SETON WRITE EXFMT SETOFF ENDDO FOOTING HEADING1 1020 *IN03=*OFF 1020

EXPPF_LOADALL
0000.01 0001.00 0002.00 0003.00 0004.00 0005.00 0006.00 A A A A A A R PFREC03 PFEMNO PFEMNA PFADD1 PFADD2 K PFEMNO 7 25 10 10 COLHDG('EMPLOYEE NUMBER') COLHDG('EMPLOYEE NAME') COLHDG('ADDRESS1') COLHDG('ADDRESS2') UNIQUE

LOADDSP_DISPALYFILE
0000.40 0000.60 0000.70 0000.80 A A A A R DATA1 PFEMNO PFEMNA PFADD1 R R R SFL O 13 17REFFLD(PFREC03/PFEMNO MINDADB O 13 27REFFLD(PFREC03/PFEMNA MINDADB O 13 53REFFLD(PFREC03/PFADD1 MINDADB

0000.90 0001.10 0001.20 0001.30 0001.40 0001.50 0001.60 0001.70 0001.80 0001.90 0003.10 0003.30 0003.50

A A A 10 A 20 A 30 A 40 A 50 A A A A A A

R HEADING1

SFLCTL(DATA1) CA03(03) SFLDSP SFLDSPCTL SFLINZ SFLCLR SFLEND(*MORE) SFLSIZ(0050) SFLPAG(0005) 6 36'EMPDETAILS' 11 19'NUMBER' 11 37'NAME' 11 54'ADDRESS1'

Program for Expanded Load


0001.00 0002.00 0003.00 0004.00 0004.02 0005.00 0006.00 0007.00 0007.01 0007.02 0007.04 0007.05 0007.06 0009.04 FEXPPF IF E FEXPDSP CF E F C *IN03 DISK WORKSTN RRN KSFILE SFLREC DOWEQ*OFF

C*SFL CLEAR C C C C* C C C C C** STR Z-ADD1 TAG SETOF Z-ADD1 20 RRNCT 40 RRN 40 SETON WRITESFLCTL SETOF 40 40

0009.05 0012.00 0013.00 0014.00 0015.00 0016.00 0017.00 0017.01 0017.02 0017.03 0018.00 0020.00 0022.03 0023.00

C C C C C C C C C C C C C C

RRNCT

DO 10 33

READ EXPPF *IN33 IFEQ *ON MOVE *ON ELSE RRN IFLT 9999 WRITESFLREC ADD 1 ADD 1 ENDIF ENDIF ENDDO SETON EXFMTSFLCTL 20 RRN RRNCT *IN50

END

0023.01 0024.00 0025.00 0026.00 0026.01 0028.00

C* PAGE DOWN C C C C C *IN35 IFEQ *ON GOTO STR ENDIF ENDDO SETON LR

EXPDSP_DISPLAYFILE
0000.40 0000.50 0000.70 0000.90 0001.10 0001.30 A A A A A A R SFLREC PFEMNO PFEMNA PFADD1 PFADD2 R R R R CF03(03) SFL O 6 4REFFLD(PFREC03/PFEMNO MINDA O 6 14REFFLD(PFREC03/PFEMNA MINDA O 6 40REFFLD(PFREC03/PFADD1 MINDA O 6 62REFFLD(PFREC03/PFADD2 MINDA

0001.50 0001.70 0001.80 0001.90 0002.00 0002.10 0002.20 0002.30 0002.40 0001.90

A A A 20 A 20 A 40 A 50 A A A A

R SFLCTL

SFLCTL(SFLREC) ROLLUP(35) SFLDSP SFLDSPCTL SFLCLR SFLEND(*MORE) SFLSIZ(0011) SFLPAG(0010) 1 29'EXPANDING SUBFILE 6 36'EMPDETAILS' '

0003.10
0003.30 0003.50

A
A A

11 19'NUMBER'
11 37'NAME' 11 54'ADDRESS1'

Program for Single page load


0001.00 0002.00 0003.00 0003.02 0003.03 0003.04 0003.05 0003.06 0003.07 0003.08 0003.09 FPAGEPF IF E FPAGEDSP CF E F I* C C C C C C C *IN03 10 Z-ADD10 EXSR CLE EXSR LOA DOWEQ*OFF SETON WRITEFOOT EXFMTSFLCTL 10 C DISK WORKSTN RRN KSFILE SFLREC CRSIZE CRSIZE 40

0007.01 0007.02 0007.03 0007.04

C* PAGE DOWN KEY PRESSED C C C *IN22 IFEQ *ON EXSR PGD ENDIF

0007.05
0007.07 0007.08 0007.09

C* PAGE UP KEY PRESSED


C C C *IN23 IFEQ *ON EXSR PUP ENDIF

0007.10
0007.11 0007.12

C
C C

ENDDO
SETOF SETON 10 LR

0007.13 0007.14 0007.15

C* =====================PAGE DOWN================== C C PGD LKEY BEGSR SETGTPAGEPF

0007.16
0007.17 0007.18 0007.19

C
C C C *IN31 LKEY

READ PAGEPF
IFEQ *OFF SETGTPAGEPF EXSR CLE

31

0007.20
0007.21 0007.22 0007.23

C
C C

EXSR LOA
ENDIF ENDSR

C* =====================PAGE UP=======================

0007.24
0007.25 0007.26

C
C C

PUP
FKEY

BEGSR
SETLLPAGEPF READ PAGEPF 31

0007.27 0007.28 0007.29 0007.31 0007.32 0007.33 0007.34 0007.35 0007.36 0007.37 0007.38 0007.40 0007.41 0007.42

C C C C C C C C C C C C C C

*IN31 FKEY

IFEQ *OFF SETLLPAGEPF Z-ADDCRSIZE DO CRSIZE READPPAGEPF MOVE PFEMNO FKEY 31 SRCNT 20

*IN31

IFEQ *ON ENDIF ENDDO EXSR CLE

FKEY SETLLPAGEPF EXSR LOA ENDIF ENDSR

0008.00 0009.00 0009.01

C* ===================LOADING DATA=========== C C LOA BEGSR Z-ADD1 RRN 40

0009.02
0009.03 0009.05 0009.06

C
C C C *IN31

SETOF
READ PAGEPF IFEQ *OFF MOVE PFEMNO

10
31

FKEY

70

0009.07
0009.10 0009.11 0009.13

C
C C C RRN *IN31

ENDIF
DOWLECRSIZE ANDNE*ON WRITESFLREC

0009.14
0009.15 0009.16 0009.17

C
C C C

MOVE PFEMNO
ADD 1 RRN

LKEY

70

READ PAGEPF ENDDO

31

0009.19 0009.20 0009.21 0009.22 0009.23 0009.24 0009.25 0009.26 0010.00 0011.00 0012.00 0013.00

C C C C C C

*IN31

IFEQ *ON SETON ELSE SETOF ENDIF ENDSR 50 50

C*================== CLEAR SCREEN ======================= C C C C C CLE BEGSR SETON WRITESFLCTL SETOF ENDSR 40 40

PAGEPF_PHYSICALFILE:
SAME AS EXPANDED LOAD

PPAGEDSP_DISPLAYFILE
0000.40 0000.50 0000.70 A A A R SFLREC PFEMNO R CF03(03) SFL O 7 3REFFLD(PFREC03/PFEMNO MINDA

0000.90
0001.10 0001.30 0001.50

A
A A A

PFEMNA
PFADD1 PFADD2 R SFLCTL

R
R R

O 7 18REFFLD(PFREC03/PFEMNA MINDA
O 7 44REFFLD(PFREC03/PFADD1 MINDA O 7 57REFFLD(PFREC03/PFADD2 MINDA SFLCTL(SFLREC)

0001.70 0001.80 0001.90 0002.00 0002.10 0002.20 0002.30

A A A 10 A 10 A 40 A 50 A

PAGEDOWN(22) PAGEUP(23) SFLDSP SFLDSPCTL SFLCLR SFLEND(*MORE) SFLSIZ(0011)

0002.40

SFLPAG(0010)

Introduction
Arrays and tables allow program to organize groups of related data elements for easy retrieval. Array consists of series of elements with like characteristics (data type and size). Here every element in an array is accessed by means of an index which indicates the relative position of the element from the beginning of the array. The numbering starts from 1.

Declaration of Arrays
Arrays are declared on the E-spec, by specifying the array name, entries per record, entries per table and length of an entry. Description Form Type (E) Array Name Entries per record Entries per Array or Table Length of Entry Data Format Decimal positions

Position 6 27-32 & 46-51 33-35 36-39 40-42 & 52-54 43 and 55 44 and 56

Types of Arrays Compile time Array Pre runtime Array Runtime Array

Compile time Array


Compile time array elements are facilitated at the end of the code.

Pre runtime Array


Pre runtime array elements are facilitated before the execution of the program.

Runtime Array
Run time array elements are facilitated from the data base. They are loaded into array during runtime.

Program for compile time array


0000.01 0001.00 0002.00 0003.00 0004.00 0006.00 0007.00 0008.00 0009.00 0010.00 ** 0011.00 JANUARY 0012.00 FEBRUARY 31 28 ** COMPILE TIME ARRAY USING MULTIDIMENSION ARRAY DABC DI C C C C C C I S S 15A Dim(12) PERRCD(1) CTDATA

4S 0 INZ(1) DOWLE12

ABC,I DSPLY XYZ,I DSPLY ADD 1 ENDDO SETON LR I

0013.00 MARCH 0014.00 APRIL 0015.00 MAY

31 30 31

0016.00 JUNE
0017.00 JULY 0018.00 AUGUST

30
30 31

0019.00 SEPTEMBER 30

0020.00 OCTOBER
0021.00 NOVEMBER 0022.00 DECEMBER

31
30 31

Program for preruntime time array


0001.00 FPF1 0002.00 DARR1 0003.00 DI 0004.00 C 0005.00 C 0006.00 C 0007.00 C 0008.00 C IT F 30 S S DO ARR1(I) DSPLY EVAL ENDDO SETON LR I=I+1 30 DISK DIM(10) FROMFILE(PF1)

4 0 INZ(1) 10

String operations
CAT
The CAT operation concatenates the character strings specified in factor2 to the end of the character specified in factor1 and places it in the result field.

SCAN
The SCAN operation scans a character string (base string) contained in factor 2 for a sub string (compare string) contained in factor1. If the string is found then the position where it is found is placed in the result field.

XLATE
XLATE (translate) is used to find for a sub string in Fator2 and replaces it with another string (Factor1) and places the resulting string into the result field. Factor 1 must contain the find string followed by a colon followed by the replace string. Example ABCDE:abcde

SUBST
The SUBST operation returns a sub string from factor2, starting at the location specified in factor 2 for the length specified in factor 1 and places this sub string in the result field.

CHECK
The CHECK operation checks a mismatched character string (base string) contained in factor 2 for a sub string (compare string) contained in factor1. If the string is found then the position where it is found is placed in the result field.

Program for string opcodes


0000.01 0000.02 0000.03 0001.00 0002.00 0002.03 0002.04 0002.05 0002.06 0002.07 0002.08 **STRING CONCAT C C C C S1 P1 MOVE 'ANIL' S1 4 5 10

MOVE 'KUMAR' T1 CAT T1:1 DSPLY P1

**SCAN METHOD C C 'ABC' NUM SCAN 'DEFABC' NUM DSPLY 100 90

**CHECK C C 'ABC' NUM CHECK'DEFABC' NUM DSPLY 100 90

0002.09 0002.10 0002.11 0002.12 0002.13 0002.14 0002.15 0002.16 0002.17 0003.00

**SUBSTRING C C C C 2 P2 Z-ADD4 S 20 10 10

MOVEL'ABCDEF' S2 SUBSTS2:S DSPLY P2

**XLATE STRING C C C C MOVEL'999B9999'NUM1 'B':'-' XLATENUM1 FLD1 DSPLY SETON LR FLD1 8 8

O/p DSPLY ANIL KUMAR DSPLY DSPLY DSPLY DE DSPLY 999-9999 C-spec---prompt pmt SeqNbr Lvl N01 C 0002.04 N02N03 Factor 1 'ABC' OpCode Factor 2 SCAN 'DEFABC' Result NUM 4 1

Len Dec H/N/P Hi Lo Eq Comment 10 0 90

OUTPUT SPECIFICATION

O-Spec
Describes the record and the format of fields in a program-described output file and when the record is to be written.

Optional for an externally described file.


Divided into two categories: Record identification and control (positions 7 through 51), Field description and control (positions 21 through 80).

Output specification layout Externally Described files 1. Record Identifier specifications


Columns 1-5 6 7-15 16-18 Descriptions Sequence number O Record Name Logical Relationship AND,OR

17

Type of record to write: D Detail E Exception (EXCEPT) H Detail (header) T Total

Record Identifier specifications Continued .. 2


Columns 18 Descriptions Release Record after output : R or Blank

18-20

Record Addition : ADD, DEL

21-29

Output Conditioning indicators:Blank,01-99,KA-KN,KP-KY,L1-L9,H1-H9,U1U8,MR,LR,RT,1P


EXCEPT name (Blank) Comments

30-39 40-80 81-100

2. Field Description Specifications


Columns 1-5 6 7-20 21-29 30-43 44 45 46-80 81-100 Descriptions Sequence number O (BLANK) Output Conditioning indicators: Blank,10-99,KA-KN,KP-KY,L1-L9,H1-H9,U1U8,MR,LR,RT,1P Field Name or *ALL (BLANK) Result field contents after writing record : Blank or B (BLANK) Comments

Program for O-spec


0001.00 0002.00 0003.00 0003.02 0004.00 0005.00 0005.02 0005.03 0006.00 0007.00 0007.01 0007.02 0007.03 FPFNAME IP E FQSYSPRT O F K 80 OF DISK PRINTER

OQSYSPRT H 2 2 2 1P O O O* OQSYSPRT H 2 O OQSYSPRT H 2 O OQSYSPRT H 2 O O* 1P 20 '================' ' 1P 20 'EMPLOYEE DETAILS' 1P 40 '===========' UDATE Y 70 40 'ABC COMPANY'

0009.00 0010.00 0011.01 0012.00 0012.01 0012.02 0012.03 0012.04 0012.05

O O O O

H2

1P 35 'EMP NUMBER' 53 'EMPLOYEE NAME' 73 'EMPLOYEE SALARY' 1P 47 '========================' 71 '======================== 74 '==='

OQSYSPRT H 2 O O O O*

0012.06

OQSYSPRT D 2

N1P

0013.00
0013.01 0013.02 0014.00 0015.00 0016.00

O
O* O* O O O

NUMBER
SALARY NAMERY NAME SALARY

36
68 69 ' 68 69 ' . ' . '

71 'RS'

PFNAME_OSPEC
0001.00 A R RECNAME

0002.00
0003.00 0004.00 0005.00

A
A A A

NUMBER
NAME SALARY K NUMBER

10
30 10 2

Anda mungkin juga menyukai