You are on page 1of 144

RPG Programming Language

RPG/400 Session 1

INTRODUCTION
RPG is an abbreviation for Report Program Generator.It is a high level language in which the programmer codes the specifications. 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. Developed by IBM in 1960s. Each entry must start in a specific position depending on the type of entry and the type of specification. There are seven types of RPG IV specifications.

Each specification type is optional.


Specifications must be entered into your source program in the order HFDICO.

FEATURES OF RPG

Structured language

It helps us in approaching a modular program design,and also facilitates us with the sequence,selective and iterative constants.

Strong at file operation

RPG does not impose any limitations in accessing the data records unlike the other programming languages.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 a minimal programming effect.

Provision of Arrays:

Arrays is an useful concept,which is provided by almost all the high level languages and also it makes the code looks very shorter.

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.

RPG Figurative constants:


The letter begin with an asterisk with an few exceptions.
*LOVAL
*HIVAL *BLANKS *ZEROS *LIKE

Date group reserved words


*UDATE *UDAY *UMONTH

*UYEAR
UDATE is a six-digit numeric,and others are each two-digit numeric fields.the format of UDATE is determined by the system value,which has been set at installation and may be ddmmyy,mmddyy, or yymmdd. It may be overridden by an entry in column 19 of H spec.

RPG/400 SPECIFICATIONS
RPG source statements consists of 80-character card images having line numbers in the first few columns of each source statements. Any statement with an asterisk*in column 7 is a comment. Every line having a form type in column 6.

Specification types:

1. Control specifications 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 describe all the files that your program uses.

3. Definition specifications describe the data used by the program. 4. Procedure specifications describe prototyped procedures that are specified after the main source section, otherwise known as subprocedures 5. Calculation specifications 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 describe the output records and fields used by the program.

File Specifications
RPG/400 Session 2

File Description specification


Each File used in a program must be described in FSPEC. One file is described per entry. Only one primary file can be specified. The presence of a primary file is not required. Only one record-address file. A maximum of eight PRINTER files. There is no limit for the maximum number of files allowed.

File Description Specification Statement


Position Description

6
7-80 7 42 44 80 81 100

F
non-commentary part fixed-format entries Key word entries Comments

Columns
1-5 6 7-16 17 Sequence number F File Name File Type: C Combined I Input, O Output, U Update File Designation : Blank Output F Full procedural P Primary R Record Address S Secondary T Array or Table

Description

18

19

End of file: Blank allow LR before all records are processed. E all records must process before LR

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 Record Length

Description

21

22

23-27 28

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 Format E Limits Processing File Type I READ DOW EXFMT READ ENDDO SETON End of Designation F Record Address Type K Device DISK File File Addition Sequence LR K DISK WORKSTN EMPRECFMT *IN10=*OFF READING EMPRECFMT 10 10

Calculation Specifications
RPG/400 Session 3

C-SPEC
In this specification we code variable declaration and the executable statements. It consists of essentially a verb and three operands known an FACTOR-1, FACTOR-2, RESULT Operation codes, entered on the calculation specifications, indicate what operations will be done. For example, if you want to read a new record, you could use the READ operation code.

Layout
Columns 1-5 Description Sequence number

6
7-8

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 and Extender

Columns 36-49 or 36-80

Description Factor 2 or Extended factor 2

50-63 64-68

Result Field Result Field Length

69-70
71-76

Result Field Decimal Positions


Resulting Indicators (High/Low/Equal)

77-80

(Blank)

81-100

Comments

Indicators
An indicator is a one-byte character field that is either set on (1) or off (0).

It is Generally used to indicate the result of an operation or to condition (control) the processing of an operation. Indicators are like switches in the flow of the program logic.
They determine the path the program will take during processing, depending on how they are set or used.

Indicators can be defined as variables on the definition specifications. You can also use RPG IV indicators, which are defined either by an entry on a specification or by the RPG IV program itself. How to set OFF and ON the indicator In RPG400 we have opcodes SETON <indicator> SETOFF <indicator> or Move 0 <ind> Move 1 <ind> For ILE RPG we have EVAL *IN<ind> = *ON or *OFF Or we can use the same functions as above

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 store data in punch cards. 2. External indicators U1 to U8. Used to pass parameters 3. First Page 1P - used for logic cycle 4. Matching Indicator MR - used for logic cycle 5. Level Break L0 L9, LR Last record ( used for logic cycle) 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

Types of OPCODES
1. Arithmetic operations
ADD SUB MULT DIV MVR SQRT Z-ADD Z-SUB

2.

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 (Conditionally Invoke 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. This statement is equivalent to saying RNUM=RNUM+NUM2

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 .zero is factor 2 is subtracted from zero and the difference is placed in the result.this is basically used to move a negative value into the filed.

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.

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

DEFN
Define 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 ** NUM1 MOVEL DSPLY 1234637 NUM1 50 NUM1 MOVE DSPLY 2345678 NUM1 50

0004.03 C
0004.04 C 0004.05 ** 0004.06 C RES

MOVEL
DSPLY

'ABCDE'

RES

MOVE

'ABCDE'

RES

0004.07 C
0004.08 C

RES

DSPLY
SETON LR

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 have 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 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

DSPLY 4000 DSPLY 3000

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

DESIGN BASIC DESIGN

2000 1200

BONUS PERKS

40 40

0005.04 C 0005.05 C 0006.00 C O/p DSPLY 4000

BONUS PERKS

DSPLY DSPLY SETON

LR

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 there 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 WHLT ------

FACTOR2

OTHER
------

DO ..ENDDO :

ENDSL

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 the condition is post-tested .

Example:

INITIALIZATION AND INCREMENTATION HAS TO BE EXPLICITLY DONE


0001.00 C Z-ADD 1 NUM 50

0002.00 C
0003.00 C 0004.00 C 0005.00 C

NUM
NUM

DOUGT
DSPLY ADD ENDDO 2

10

NUM

0006.00 C
O/P 1,3,5,7,9

SETON

LR

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 loops.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 NOTE:

NUM

DSPLY ADD 2 ENDDO SETON

NUM LR

In the above example if leave is coded in place of ITER the 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

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.

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.

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 access the system time of day and,if specified the system date at any time during program processing.the system time is based on 24-hour clock. Result : Must contain either at 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 return 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 'BEFORE' DSPLY

0002.00 C
0003.00 C 0004.00 C* 0004.01 C 'AFTER'

EXSR
DSPLY RETURN SETON

DSPSR

LR

0005.00 C
0006.00 C 0007.00 C O/p

DSPSR
'INSIDE'

BEGSR
DSPLY ENDSR

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.

CASXX.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 ADDSR NUM1

RETURN
BEGSR ADD ENDSR NUM2 RESULT

0017.00 C
0018.00 C 0019.00 C

SUBSR
NUM1

BEGSR
SUB ENDSR NUM2 RESULT

0020.00 C 0021.00 C 0022.00 C 0022.01 C 0022.02 C 0022.03 C

MULSR NUM1

BEGSR MULT ENDSR NUM2 RESULT

DIVSR NUM1

BEGSR DIV ENDSR NUM2 RESULT

DSPSELECT_CASXX 0000.40 0000.50 PW1 0000.60 0000.70 A R OPCODE REL-V4R4M0 5769-

A*%%TS SD 20050802 125252 QSECOFR A A CA03(03) 12 34'B ='

0000.80
0000.90 0001.00

A
A A

10 34'A
14 34'OPT 16 34'C

='
=' ='

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 the call statement is called 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 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 C 'BEFORE' DSPLY

0003.00
0004.00

C
C 'AFTER'

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 0002.02 C 0002.03 C 0002.04 C 0003.00 C 0004.00 C 0004.01 C 0004.02 C 0005.00 C LIST1 CF E PLIST PARM PARM PARM PARM PARM EXFMT CALL EXFMT SETON P R T SI A INTEREST 'PLISTSUB' INTEREST LR LIST1 50 40 20 70 80 WORKSTN

PLISTSUB_NM(SUBPROGRAM)

0001.00 C 0002.00 C 0003.01 C 0003.02 C 0003.03 C 0004.00 C 0004.01 C 0005.00 C 0006.00 C 0007.00 C 0008.00 C

*ENTRY

PLIST PARM PARM PARM PARM PARM P1 R1 T1 SI1 A1 R1 SI1 100 P1 SI1 SI1 SI1 A1 50 40 20 70 80

P1 T1

MULT MULT DIV

SI1

ADD

RETURN

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

0004.70
0004.90 0005.10 0005.30

A
A A A

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

0005.50
0005.70 0005.90 0006.30

A
A A A P

15 10'SIMPLE INTEREST IS :'


17 10'AMOUNT IS :'

20 41'PRESS ENTER TO CONTINUE' 5S 0B 9 33

0006.40
0006.50 0006.60 0006.70

A
A A A

R
T SI A

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 DS 1 2

0003.00 DMM
0004.00 DYYYY 0005.00 C 0005.01 C 0005.02 C 0005.03 C 0006.00 C 0007.00 C DD MM YYYY

3
5 MOVEL DSPLY DSPLY DSPLY SETON

4
8 UDATE DATE1

DATE1 DSPLY LR

External data structure


READ DATA FROM A DATA BASE FILE USING EXTERNAL DS.
External Datastructures 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 CF DS E Workstn INFDS(DSDisplay)

D FileName
DFileOpen DFileeof DMsgId

*File
9 10 46 9 10 52

DSCRSize
DKeyPress DCursorloc

*SIZE
369 370 369 371B 0

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 IDS1 I C C C SDS *STATUS ERR Z-ADD100 Z-ADD0 NUM1 DIV NUM1 NUM2 NUM2 30 30 NUM3 30

0029.02
0029.03 0033.00 0033.01

C
C C C

RETRN
*PSSR BEGSR ERR IFEQ 102

'ZERO DIV'DSPLY

0033.02
0033.03 0045.04

C
C* C

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 FDSPARR CF E WORKSTN

0001.02
0002.00 0002.01 0003.01

E
IDS1 I I

LETTER 1 26 1
UDS 1 2 STATE 3 40AREA

0003.02
0003.03 0007.00 0008.00

I
I C C

5 5 ALPHA
6 90SRLNO *NAMVAR DEFN *IN03 AREA0 9

DOWEQ*OFF

0009.00
0010.00

C
C

*LOCK

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

C
C C C

ELSE
EXSR ADSLNO ENDIF MOVE DS1 FLD001

0021.00
0022.00 0023.00 0024.00

C
C C C

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

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

0035.00
0036.00 0037.00 0038.00

C
C C C

ENDIF
ENDDO ADD 1 I

MOVE LETTER,I ALPHA

0040.00 0041.00 0043.00

C C C ADSLNO

Z-ADD1 ENDSR BEGSR

SRLNO

0044.00
0045.00 0045.01 0045.02

C
C C C

ADD 1
ENDSR UPDSR BEGSR MOVE DS1

SRLNO

AREA0

0045.03
0045.04 0046.00 ** 0047.00 A

C
C

*LOCK OUT AREA0


ENDSR V

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 0003.50 0003.90 0004.00 A R VEHREG REL-V4R4M0 5769-PW1 A*%%TS SD 20050801 182655 QSECOFR A A A A A A FLD001 CA03(03) 8 15'AUTOMATIC GENERATION OF VE GISTRATION NUMBER' 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 or required to be displayed. Having indicator for SFLDSPCTL is optional.

SFLCLR

Normally SFLCLR will have the negative conditioning indicator that is given for SF 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 SETON 102040

0007.00 C
0007.01 C 0008.01 C

WRITE
SETOFF Z-ADD

HEADING1
40 1 RRN 40

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 DOW SETON *IN03=*OFF 1020

0014.04 C
0016.00 C 0017.00 C 0017.01 C

WRITE
EXFMT SETOFF ENDDO

FOOTING
HEADING1 1020

0017.02 **
0018.00 C SETON LR

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 A R DATA1 SFL

0000.60
0000.70 0000.80

A
A A

PFEMNO
PFEMNA PFADD1

R
R R

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

A A A 10 A 20 A 30 A 40

R HEADING1

SFLCTL(DATA1) CA03(03) SFLDSP SFLDSPCTL SFLINZ SFLCLR

0001.60
0001.70 0001.80 0001.90

A 50
A A A

SFLEND(*MORE)
SFLSIZ(0050) SFLPAG(0005) 6 36'EMPDETAILS'

0003.10
0003.30 0003.50

A
A A

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 FEXPPF IF E FEXPDSP CF E F C *IN03 DISK WORKSTN RRN KSFILE SFLREC DOWEQ*OFF

C*SFL CLEAR C SETON 40

0006.00
0007.00 0007.01 0007.02

C
C C* C

WRITESFLCTL
SETOF 40

Z-ADD1

RRN

40

0007.04
0007.05 0007.06 0009.04

C
C C C**

STR

TAG
SETOF Z-ADD1 20 RRNCT 40

0009.05 0012.00 0013.00 0014.00 0015.00 0016.00

C C C C C C

RRNCT

DO 10 33

READ EXPPF *IN33 IFEQ *ON MOVE *ON ELSE RRN IFLT 9999 *IN50

END

0017.00
0017.01 0017.02 0017.03

C
C C C

WRITESFLREC
ADD 1 ADD 1 ENDIF RRN RRNCT

0018.00
0020.00 0022.03 0023.00

C
C C C

ENDIF
ENDDO SETON EXFMTSFLCTL 20

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 A A A R SFLREC PFEMNO R CF03(03) SFL O 6 4REFFLD(PFREC03/PFEMNO MINDA

0000.90
0001.10 0001.30

A
A A

PFEMNA
PFADD1 PFADD2

R
R R

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 0003.10 0003.30 0003.50

A A A 20 A 20 A 40 A 50 A A A 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' 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 FPAGEPF IF E FPAGEDSP CF E F I* C C 10 Z-ADD10 EXSR CLE C DISK WORKSTN RRN KSFILE SFLREC CRSIZE CRSIZE 40

0003.05
0003.06 0003.07 0003.08

C
C C C *IN03

EXSR LOA
DOWEQ*OFF SETON WRITEFOOT 10

0003.09

EXFMTSFLCTL

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 0007.16 0007.17 0007.18 0007.19 0007.20 0007.21 0007.22 0007.23 0007.24 0007.25 0007.26

C* =====================PAGE DOWN================== C C C C C C C C C *IN31 LKEY PGD LKEY BEGSR SETGTPAGEPF READ PAGEPF IFEQ *OFF SETGTPAGEPF EXSR CLE EXSR LOA ENDIF ENDSR 31

C* =====================PAGE UP======================= C C C PUP FKEY BEGSR SETLLPAGEPF READ PAGEPF 31

0007.27 0007.28 0007.29 0007.31 0007.32 0007.33

C C C C C C

*IN31 FKEY

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

0007.34
0007.35 0007.36 0007.37

C
C C C

*IN31

IFEQ *ON
ENDIF ENDDO EXSR CLE

0007.38
0007.40 0007.41 0007.42

C
C C C

FKEY SETLLPAGEPF
EXSR LOA ENDIF ENDSR

0008.00 0009.00 0009.01 0009.02 0009.03 0009.05 0009.06 0009.07 0009.10 0009.11 0009.13 0009.14 0009.15 0009.16 0009.17

C* ===================LOADING DATA=========== C C C C C C C C C C C C C C RRN *IN31 *IN31 LOA BEGSR Z-ADD1 SETOF READ PAGEPF IFEQ *OFF MOVE PFEMNO ENDIF DOWLECRSIZE ANDNE*ON WRITESFLREC MOVE PFEMNO ADD 1 RRN 31 LKEY 70 FKEY 70 RRN 40 10 31

READ PAGEPF ENDDO

0009.19 0009.20 0009.21 0009.22 0009.23 0009.24

C C C C C C

*IN31

IFEQ *ON SETON ELSE SETOF ENDIF ENDSR 50 50

0009.25
0009.26 0010.00 0011.00

C*================== CLEAR SCREEN =======================


C C C CLE BEGSR SETON WRITESFLCTL 40

0012.00
0013.00

C
C

SETOF
ENDSR

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 0002.40

A A A 10 A 10 A 40 A 50 A A

PAGEDOWN(22) PAGEUP(23) SFLDSP SFLDSPCTL SFLCLR SFLEND(*MORE) SFLSIZ(0011) 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 D-spec, by specifying the array name,entries per record,entries per table and length of an entry. DABC 10A Dim(10) PERRCD(1) CTDATA Here Array name = ABC Entries per record =1 Entries per table = 10 Length of entry =10 This is an array of 10 elements,each element of size 10 bytes.

Types of Arrays Compile time Array Preruntime Array

Runtime Array

Compile time Array


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

Preruntime Array
Preruntime 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 ** COMPILE TIME ARRAY USING MULTIDIMENSION ARRAY DABC DI C C C I S S 15A Dim(12) PERRCD(1) CTDATA

4S 0 INZ(1) DOWLE12

ABC,I DSPLY XYZ,I DSPLY

0007.00
0008.00 0009.00 0010.00 **

C
C C

ADD 1
ENDDO SETON

LR

0011.00 JANUARY
0012.00 FEBRUARY

31
28

0013.00 MARCH 0014.00 APRIL 0015.00 MAY 0016.00 JUNE 0017.00 JULY 0018.00 AUGUST

31 30 31 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 IT F 30 S 30 DISK DIM(10) FROMFILE(PF1)

0003.00 DI
0004.00 C 0005.00 C 0006.00 C

S
DO ARR1(I) DSPLY EVAL

4 0 INZ(1)
10

I=I+1

0007.00 C
0008.00 C

ENDDO
SETON LR

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 that,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 a string and placed it with another one and puts the resulting string into the result field. Factor 1 must contain the find string,followed by a colon,followed by the replace string.

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.if factor 1 is not specified,the length of the string from the first position is used.

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 that,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 **STRING CONCAT C C C C S1 P1 MOVE 'ANIL' S1 4 5 10

MOVE 'KUMAR' T1 CAT T1:1 DSPLY P1

**SCAN METHOD

0002.04
0002.05 0002.06 0002.07

C
C

'ABC'
NUM

SCAN 'DEFABC' NUM


DSPLY

100

90

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

0002.08

NUM

DSPLY

0002.09 0002.10 0002.11 0002.12 0002.13 0002.14

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

MOVEL'ABCDEF' S2 SUBSTS2:S DSPLY P2

**XLATE STRING

0002.15
0002.16 0002.17 0003.00

C
C C C

MOVEL'999B9999'NUM1
'B':'-' XLATENUM1 FLD1 DSPLY SETON LR FLD1 8

O/p DSPLY ANIL KUMAR DSPLY DSPLY DSPLY DE DSPLY 999-9999 4 1

C-spec---prompt
pmt SeqNbr Lvl N01 C 0002.04 N02N03 Factor 1 'ABC' OpCode Factor 2 SCAN 'DEFABC' Result NUM

Len Dec H/N/P Hi Lo Eq Comment

10 0

90

OUTPUT SPECIFICATION
RPG/400 Session 5

O-Spec
Describe 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

Descriptions
Sequence number O Record Name

16-18

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 Descriptions

18

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 FPFNAME IP E FQSYSPRT O F K 80 OF DISK PRINTER

OQSYSPRT H 2 2 2 1P O O O* UDATE Y 70 40 'ABC COMPANY'

0005.02
0005.03 0006.00 0007.00

OQSYSPRT H 2
O OQSYSPRT H 2 O

1P
40 '===========' 1P 20 'EMPLOYEE DETAILS'

0007.01
0007.02 0007.03

OQSYSPRT H 2
O O*

1P
20 '================' '

0009.00 0010.00 0011.01 0012.00 0012.01 0012.02

O O O O

H2

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

OQSYSPRT H 2 O

0012.03
0012.04 0012.05

O
O O*

71 '========================
74 '==='

0012.06

OQSYSPRT D 2

N1P

0013.00
0013.01 0013.02 0014.00

O
O* O* O

NUMBER
SALARY NAMERY NAME

36
68 69 ' 68 . '

0015.00
0016.00

O
O

SALARY

69 '

. '

71 'RS'

PFNAME_OSPEC
0001.00 0002.00 0003.00 0004.00 0005.00 A A A A A R RECNAME NUMBER NAME SALARY K NUMBER 10 30 10 2

CONTROL SPECIFICATION
RPG/400 Session 6

HEADER SPECIFICATION
Columns Description

1-5

Sequence number

7-80

Control Key Words

81-100

Comments

Key words in HSPEC


Key Word COPYRIGHT(string) CURSYM(sym) Description Provides copyright information to include in a module Character to use a s currency symol enclosed in quotes

DATFMT(fmt{seperator})
DEBUG(*YES|*NO)

Format of date literals defaults to *ISO


Enables Dump opcode

NOMAIN TIMFMT(fmt{seperator})
DFTNAME(rpg_name)

Indicates that there is no main procedure in this module Format of Time literals defaults to *ISO
Default name of RPG program or module

Standard control specification


Three methods to provide control information to the compiler. H-specs in the source *LIBL/RPGLEHSPEC(user defined data area) QRPGLE/DFTLEHSPEC(IBM-supplied data area)

CRTDTAARA DTAARA(QGPL/RPGLEHSPEC)+ TYPE(*CHAR) + LEN(26) + VALUE(DATFMT(*YMD/) TIMFMT(*HMS)) + TEXT(Default RPG H-SPEC) OR CRTDTAARA DTAARA(QPRGLE/DFTLEHSPEC)+ TYPE(*CHAR) + LEN(26) + VALUE(DATFMT(*YMD/) TIMFMT(*HMS)) + TEXT(Default RPG H-SPEC) OR In the program type H DATFMT(*YMD/) H TIMFMT(*HMS)

RPG LIMITS
File Name No of files in a program 10 *

Record format name


Field name Character field size No of decimal places Data structure name Data structure size Array name Number of array elements Named constant size No of subroutines in a program Size of program

10
10 32767 30 10 32767 10 32767 1024 * *

DEFINITION SPECIFICATION
RPG/400 Session 7

The Definitive Specification


Definition specification caters to the data definition requirements. Arrays Data Structures Work fields Data Areas Named Constants Procedure Prototypes are defined here.

D-Spec Layout
Columns
1-5
6 7-21 22

Description
Sequence Number
D Definition Name(Data structure,sub field,standalone field,named constant) Externally Described: (Blank) Program Described E Externally described Data Structure Type: (Blank) Miscellaneous definition S Program status data structure U Data area data structure

23

Key Words
Key Word ALIGN ALT(array_name) ASCEND Description Aligns data structure sub fields of integer data type on two or four byte boundaries. Names a main array for use with this alternating array Array or table entries are in ascending order.

BASED(Basing_pointe Names a pointer to the address of the data item r_name) CONST(Constant) CTDATA DATFMT DESCEND DIM (numeric constant) Specifies a value of the named constant or indicates that a passed parameter is read only. Specifies a compile time table or array Default date format and separator Array or table entries are in descending order Defines the number of elements in an array or a table

Key Word DTAARA(dataareaname) EXPORT

Description Associates the data item with the external data area: Data_area_name,*LDA,*PDA Allows the data item to be accessed by another ILE module, using the IMPORT Key word.This ILE module allocates the storage.

EXTFLD(field_name) EXTFMT(Code)

Renames a subfield in an externally described data structure. External Data type for Compile time and pre runtime tables. B Binary I- signed integer L-left sign P Packed decimal R- Right sign S Zoned decimal
File Containing field descriptions used for subfields in a data structure. Names a program whose prototype is being defined. Names a procedure whose prototype is being defined. File with input data for pre runtime array or table.

EXTNAME(Filename:{formatn ame}) EXTPGM(program name) EXTPROC(procedure name) FROMFILE(file_name)

Key Word IMPORT INZ(constant) LIKE(RPGname) NOOPT OCCURS(numeric Constant)

Description Storage for data item is allocated in another ILE module with the EXPORT Keyword.This module can use the same storage. Initializes the data item Data Items Attributes (length, type) are based upon another variable. Do not perform optimization for this data item Number of occurrences of a multiple occurrence data structure

OPDESC
OPTIONS

Passes operational descriptors with parameters defined within a prototype


Specifies one or more parameter passing options *NOPASS Parameter need not be passed *OMIT *OMIT IS allowed for parameter *VARSIZE Parameter may be shorter than the defined length Data structure sub Field overlays the storage of another field

OVERLAY(name:{pos })

Key Word PACKEVEN PERRCD(Numeric Constant) PREFIX(Prefix string:{number of Characters replaced}) PROCPTR STATIC

Description Zeroes out the high order digit when pack field has even number of digits Number of elements per record of an array or table. String to be prefixed to sub field names of an externally described data structure Defines an item as a procedure pointer Defines a local variable with static storage, holding its value across procedure calls. Default time format and the separator File to which an array or table is to be written Specifies that a parameter will be passed by value instead of reference.

TIMFMT(format {separator}) TOFILE(Filename) VALUE

Program using D-spec


0002.00 Df8 0003.00 DI10 0005.01 C 0005.02 C 0006.01 C 0006.02 C F8 I10 S S EVAL EVAL DSPLY DSPLY 8F INZ(-1) 10I 0 INZ(-265) F8=%ABS(F8) I10=%ABS(I10-365)

0008.00 C

SETON

LR

You might also like