Professional Documents
Culture Documents
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.
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.
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.
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.
RPG in combination with RLU(Report Layout Utility)helps us in generating formatted and complex reports.
program.
*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
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
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
50-63 64-68
69-70
71-76
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)
SELEC (Begin a Select Group) WHxx (When True Then Select) DO (Do)ENDDO DOUxx (Do Until)ENDDO
5.
Branching operations
TAG (Tag)
6.
Call operations
BEGSR (Beginning of Subroutine) ENDSR (End of Subroutine) EXSR (execute Subroutine)
7.
File operations
OPEN (Open File for Processing) CLOSE (Close Files) READ (Read a Record)
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
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.
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.
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.
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
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
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 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
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:
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:
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:
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:
NUM NUM
NUM
50
NUM
NUM
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:
CABXX :
CABXX(COMPARE AND BRANCH)command is simply a combination of IF & GOTO statement. Example:
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:
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:
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
NOTE: If the name of the subroutine is changed to *INZSR then, the sequence of the messages would be INSIDE,BEFORE,INSIDE,AFTER.
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 ADDSR NUM1
RETURN
BEGSR ADD ENDSR NUM2 RESULT
0017.00 C
0018.00 C 0019.00 C
SUBSR
NUM1
BEGSR
SUB ENDSR NUM2 RESULT
MULSR NUM1
DIVSR NUM1
0000.80
0000.90 0001.00
A
A A
10 34'A
14 34'OPT 16 34'C
='
=' ='
A A A A
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
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
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
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
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).
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
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
D FileName
DFileOpen DFileeof DMsgId
*File
9 10 46 9 10 52
DSCRSize
DKeyPress DCursorloc
*SIZE
369 370 369 371B 0
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)
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
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
ADALPA 1 ALPHA
BEGSR DO 26 I 20
0035.00
0036.00 0037.00 0038.00
C
C C C
ENDIF
ENDDO ADD 1 I
C C C ADSLNO
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
0048.00 B ------------z
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.
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.
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.
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
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.
0007.00 C
0007.01 C 0008.01 C
WRITE
SETOFF Z-ADD
HEADING1
40 1 RRN 40
0008.03 C
0009.00 C 0009.01 C
READ
DOW WRITE
PFREC03
*IN90=*OFF DATA1
90
RRN 90
PFREC03
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
A A A 10 A 20 A 30 A 40
R HEADING1
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'
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
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
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' '
0003.05
0003.06 0003.07 0003.08
C
C C C *IN03
EXSR LOA
DOWEQ*OFF SETON WRITEFOOT 10
0003.09
EXFMTSFLCTL
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.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 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
C C C C C C
*IN31
0009.25
0009.26 0010.00 0011.00
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)
A A A 10 A 10 A 40 A 50 A A
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.
Runtime Array
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.
4S 0 INZ(1) DOWLE12
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
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.
**SCAN METHOD
0002.04
0002.05 0002.06 0002.07
C
C
'ABC'
NUM
100
90
0002.08
NUM
DSPLY
**SUBSTRING C C C C 2 P2 Z-ADD4 S 20 10 10
**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
C-spec---prompt
pmt SeqNbr Lvl N01 C 0002.04 N02N03 Factor 1 'ABC' OpCode Factor 2 SCAN 'DEFABC' Result NUM
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).
Descriptions
Sequence number O Record Name
16-18
17
18
18-20
21-29
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 '================' '
O O O O
H2
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
81-100
Comments
DATFMT(fmt{seperator})
DEBUG(*YES|*NO)
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
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 *
10
10 32767 30 10 32767 10 32767 1024 * *
DEFINITION SPECIFICATION
RPG/400 Session 7
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
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.
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
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.
0008.00 C
SETON
LR