RPG is an abbreviation for Report Program Generator. It is a high level language in which the programmer codes the specifications.
FEATURES OF RPG
Structured language
RPG provides structured programming constructs (Opcodes, Subroutines, Subprograms) that helps us in approaching a modular program design.
The data records can be accessed in any direction, sequentially or randomly with out need to open and close the files.
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.
RPG in combination with RLU (Report Layout Utility) helps us in generating formatted and complex reports.
program.
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 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
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
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.
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
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
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
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
Columns 36-49
71-76
77-80 81-100
(Blank) Comments
1.
Arithmetic operations
ADD SUB MULT DIV MVR SQRT Z-ADD Z-SUB
2.
3. Date/time operations
TIME (Time of Day)
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)
7.
File operations
OPEN (Open File for Processing)
COMIT (Commit)
9. Array operations
MOVEA (Move Array)
XLATE (Translate)
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
ADD
NUM1
NUM2
RNUM
HI
LO EQ
Format : 2
CODE
Factor 1
Factor 2
ADD
NUM2
RNUM
HI
LO EQ
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.
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
C D
20
20 LR
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.
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
BONUS PERKS
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:
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:
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:
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:
NUM
NUM
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:
CABXX :
CABXX(COMPARE AND BRANCH) command is simply a combination of IF & GOTO statement. Example:
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:
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:
Factor 1 Compared
Factor 2 Compared
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:
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
MULSR NUM1
DIVSR
BEGSR
0022.02 C
0022.03 C
NUM1
DIV
ENDSR
NUM2
RESULT
0000.50 PW1
0000.60 0000.70 0000.80 0000.90 0001.00
REL-V4R4M0 5769-
A A A A
3S 0B 10 50 3S 0B 12 50 5S 0O 16 50 1A I 14 50
Factor 1
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
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
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 :' :' :'
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).
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
0005.03 C
0006.00 C 0007.00 C
YYYY
DSPLY
SETON LR
DATE1 DSPLY
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
O/P DSPLY ZERO DIV DS.PSSR 2901 tried to divide by zero (factor 2)
0011.00 0012.00
C C
SRLNO ALPHA
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
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
ADALPA 1 ALPHA
BEGSR DO 26 I 20
0036.00
0037.00 0038.00
C
C C
ENDDO
ADD 1 I
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
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
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
Expanded load
Loads enough records to fill first screen.
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
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.
0008.02 ** LOADING DATA 0008.03 C 0009.00 C 0009.01 C READ DOW WRITE PFREC03 *IN90=*OFF DATA1 90
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'
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
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'
C* PAGE DOWN KEY PRESSED C C C *IN22 IFEQ *ON EXSR PGD ENDIF
0007.05
0007.07 0007.08 0007.09
0007.10
0007.11 0007.12
C
C C
ENDDO
SETOF SETON 10 LR
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
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
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
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)
A A A 10 A 10 A 40 A 50 A
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
Runtime Array
Run time array elements are facilitated from the data base. They are loaded into array during runtime.
4S 0 INZ(1) DOWLE12
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
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.
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
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
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.
17
18-20
21-29
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'
O O O O
H2
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