Interaction with Display and File Processing Opcodes:
Overview:
This module enables the student to understand how to include a display file in RPG program, Figurative Constants and RPG/400 File Processing Opcodes.
Outline:
Topics covered,
- Interaction
with Display file
- Figurative
Constants
- File
Processing Opcodes.
Objective:
By the end of this module, the student should be
able to:
- How to Interact with Display file.
- Understand Figurative Constants-*LOVAL, *HIVAL, *BLANK, *BLANKS, *ZERO, *ZEROS
- Understand the various File Processing Opcodes like – SETLL,
SETGT, CHAIN, READE, READP, READPE, DELET, UPDATE
Display file are used for the
output operation and input operation.
Input
Operation: To get the records from the user.
Output
Operation: To give the information to the user.
In this session we create a
display file, in which there are three input field and one output field.
The three input field are
- First Number
- Second number
- Option
The one output field is
- Result
In first and second number field we enter
the number and in option field we enter the option (1=Add 2=Sub, 3=Mult, 4=Div)
then result of the operation is appear in the result field.
Display file
UUUUUUUUUU DD/DD/DD
TT:TT:TT
MATHS
OPERATION
ENTER THE FIRST NUMBER
.......: 999-
ENTER THE SECOND NUMBER
......: 999-
OPTION ................................................'3-
RESULT
................................................' 99999-
1=Add 2=Sub
3=Mult 4=Div
F3 = TO
EXIT
Display File Name: Math
Record:
S1
Fields Names: NUM1, NUM2, OPT, RES
RPG Program:
Columns . . . : 1
71 Edit PB01U01S/MYRPG
SEU==>
EXA16
FMT
FX .....FFilenameIPEAF........L..I........Device+......KExit++Entry+A....U
*************** Beginning of data *************************************
0001.00 FMATH
CF E WORKSTN
0001.01 *
0002.00 C *IN03 DOWEQ*OFF
0002.01 C Z-ADD*ZEROS OPT
0003.00 C EXFMTS1
0003.01 * IF F3 IS PRESS
0003.02 C
03 LEAVE
0003.04 * ADDITION
0003.05 C OPT IFEQ 1
0003.06 C NUM1 ADD
NUM2 RES
0003.07 C ENDIF
0003.08 * SUBTRACTION
0003.09 C OPT IFEQ 2
0003.10 C NUM1 SUB
NUM2 RES
0003.11 C ENDIF
0003.12 * MULTIPLICATION
0003.13 C OPT IFEQ 3
0003.14 C NUM1 MULT NUM2 RES
0003.15 C ENDIF
0003.16 * DIVISION
0003.17 C OPT IFEQ 2
0003.18 C NUM1 DIV
NUM2 RES
0003.19 C ENDIF
0003.20 *
0008.00 C ENDDO
0009.00 C SETON LR
****************** End of data ****************************************
F3=Exit
F4=Prompt F5=Refresh F9=Retrieve
F10=Cursor F11=Toggle
F16=Repeat find F17=Repeat change F24=More keys
Figurative Constants
1. *LOVAL
Represents
the lowest possible value for the data type i.e. being compared with or moved
to. For char field’s hexadecimal zeros and for numeric fields all nines with a
negative sign.
- *HIVAL
Represents the highest possible value for data type i.e. being compared with or moved to. For char fields hexadecimal FFs and for numeric fields all nines with a positive sign.
*BLANK *BLANKS
Valid
only for character fields. It represents all blanks.
- *ZERO *ZEROS
Valid
for both char and numeric fields. Represents all zeros.
File Processing Opcodes
1) Create Physical file ‘EMP’ as shown below
Columns . . . : 1
71 Edit PB01U01D/MYDDS
SEU==> EMP
FMT
PF .....A..........T.Name++++++RLen++TDpB......Functions++++++++++++++++++
*************** Beginning of data *************************************
0001.00 A
R EMPR
0002.00 A EMPNO 3S 0
0003.00 A ENAME 5A
0007.00 A
K EMPNO
****************** End of data ****************************************
F3=Exit
F4=Prompt F5=Refresh F9=Retrieve
F10=Cursor F11=Toggle
F16=Repeat find F17=Repeat change F24=More keys
(C)
COPYRIGHT IBM CORP. 1981, 2002.
SETLL (Set Lower Limit)
The SETLL positions the file at the first
record whose key is GREATER THAN or EQUAL TO the value specified in factor1.
Factor1 can be a literal, field name or figurative constant. Factor2 can be a
File name or a record format name. Use of indicator is optional. If used, it
can be used to check whether exact match or not. The resulting indicators
reflect the status of the operation. If an indicator is specified in (HI) it is
set on when the search argument is greater than the highest key or relative
record number in the file (i.e. not found). If an indicator is specified in
(LO) it is set on when an error occurs during running of the operation. If an
indicator is specified in (EQ) it is set on when a record is present whose key
or relative record number is equal to the search argument.
Factor 1 |
Search argument (Mandatory)
|
Factor 2 |
File name / record format
(Mandatory)
|
Result Field |
Data Structure (only for
program describe file)
|
HI |
|
LO |
ER (Optional)
|
EQ |
BOF
|
Columns . . . : 1
71 Edit PB01U01S/MYRPG
SEU==>
EXA17
FMT
F
.....FFilenameIPEAF....RlenLK1AIOvKlocEDevice+......KExit++Entry+A....U
*************** Beginning of data
*************************************
0001.00 FEMP
IF E K DISK
0001.01 C* SETLL
EXAMPLE
0002.00 C *LOVAL SETLLEMPR
0002.01 C* FILE POINTER IS SET TO THE LOWEST
VALUE
0002.02 C *IN90 DOWEQ*OFF
0002.03 C* IF INDICATOR 90 ON THEN ITER
0002.04 C
90 ITER
0002.05 C READ EMPR 90
0002.06 C*DISPLAY THE RECORDS
0004.00 C EMPNO DSPLY
0005.00 C ENAME DSPLY
0006.00 C DEP DSPLY
0006.01 C ENDDO
0008.00 C SETON LR
****************** End of data ****************************************
F3=Exit
F4=Prompt F5=Refresh F9=Retrieve
F10=Cursor F11=Toggle
F16=Repeat find F17=Repeat change F24=More keys
SETGT (Set greater Than)
The SETGT operation works similarly to
SETLL. The difference is that this operation positions the file to a record
whose key value is GREATER THAN the value of factor1. Factor1 value can be a
field name, literal, figurative constant. Factor2 can be a file name or record
format name.
Like SETLL, SETGT also positions the file;
it does not actually retrieve a record from the Database file. Use of indicator
is optional. If used, it can be used to check whether exact match or not. The
resulting indicators reflect the status of the operation. If an indicator is
specified in (HI) it is set on if no record found with a key or there is a
relative record number that is greater then the search argument specified in
the factor 1. (LO) it is set on when an error occurs during running of the
operation. If an indicator is specified in positions 58 and 59.
Factor 1 |
Search argument (Mandatory)
|
Factor 2 |
File name / record format
(Mandatory)
|
Result Field |
Data Structure (only for
program describe file)
|
HI |
|
LO |
|
EQ |
|
Columns . . . : 1
71 Edit PB01U01S/MYRPG
SEU==>
EXA18
FMT
FX .....FFilenameIPEAF........L..I........Device+......KExit++Entry+A....U
*************** Beginning of data
*************************************
0001.00 FEMP
IF E K DISK
0001.01 C* SETGT EXAMPLE
0001.02 C *HIVAL SETGTEMPR
0001.03 C* FILE POINTER IS SET TO HIGHEST
VALUE
0001.04 C READPEMPR 90
0001.05 C *IN90 IFEQ *OFF
0001.06 C EMPNO DSPLY
0001.07 C ENAME DSPLY
0001.08 C DEP DSPLY
0001.09 C ELSE
0001.10 C* IF INDICATOR 90 IS ON THEN ERROR IS
DISPLAYED
0001.11 C 'ERROR' DSPLY
0001.12 C ENDIF
0008.00 C SETON LR
****************** End of data ****************************************
F3=Exit
F4=Prompt F5=Refresh F9=Retrieve
F10=Cursor F11=Toggle
F16=Repeat find F17=Repeat change F24=More keys
CHAIN (Random Retrieval from a File)
RPG supports random access of the database
files through the CHAIN operation. CHAIN requires a factor1 entry; which
contains the key value of the record to be randomly read. Factor2, which is
also required, contains the name of the file or the record format of the file.
A required indicator in the HI (NR) position turns on when the random read is
unsuccessful. Indicators define in the LO (ER) factor get on if CHAIN operation
was not completed successful.
Factor 1 |
Search argument (Mandatory)
|
Factor 2 |
File name / record format (Mandatory)
|
Result Field |
Data Structure (only for program describe file)
|
HI |
NR (Mandatory)
|
LO |
ER (Optional)
|
EQ |
|
Columns . . . : 1
71 Edit PB01U01S/MYRPG
SEU==>
EXA19
FMT
F
.....FFilenameIPEAF....RlenLK1AIOvKlocEDevice+......KExit++Entry+A....U
*************** Beginning of data
*************************************
0001.00 FEMP
IF E K DISK
0001.01 C* CHAIN EXAMPLE
0002.00 C
EMPNO CHAINEMPR 90
0002.01 C* IF RECORD FOUND THEN DISPLAY
0003.00 C *IN90 IFEQ *OFF
0004.00 C EMPNO DSPLY
0005.00 C ENAME DSPLY
0006.00 C DEP DSPLY
0006.01 C ELSE
0006.02 C*IF NOT FOUND THEN DISPLAY ERROR
0006.03 C 'ERROR' DSPLY
0007.00 C ENDIF
0008.00 C SETON LR
****************** End of data ****************************************
F3=Exit
F4=Prompt F5=Refresh F9=Retrieve
F10=Cursor F11=Toggle
F16=Repeat find F17=Repeat change F24=More keys
READE (Read Equal)
The READE sequentially reads the next
record in a file whose key matches with the value in factor1.If the record’s
key does not match, or if it is the end of file, the indicator specified in the
EQ position turns ON.Factor1 can be field, literal or figurative
constant.Factor2 may be a file name or a record format name. Indicators define
in the LO (ER) factor get on if READE operation was not completed successful.
Factor 1 |
Search argument
|
Factor 2 |
File name / record format
(Mandatory)
|
Result Field |
Data Structure (only for
program describe file)
|
HI |
|
LO |
ER (Optional)
|
EQ |
EOF
|
Columns . . . : 1
71 Edit PB01U01S/MYRPG
SEU==>
EXA20
FMT
FX .....FFilenameIPEAF........L..I........Device+......KExit++Entry+A....U
*************** Beginning of
data *************************************
0001.00 FEMP
IF E K DISK
0001.01 C* READE EXAMPLE
0001.03 C Z-ADD1 RS
30
0001.04 C RS READEEMPR 90
0001.05 C *IN90 IFEQ *OFF
0001.06 C EMPNO DSPLY
0001.07 C ENAME DSPLY
0001.08 C DEP DSPLY
0001.09 C ELSE
0001.10 C* IF INDICATOR 90 IS ON THEN ERROR IS
DISPLAYED
0001.11 C 'ERROR' DSPLY
0001.12 C ENDIF
0008.00 C SETON LR
****************** End of data ****************************************
F3=Exit
F4=Prompt F5=Refresh F9=Retrieve
F10=Cursor F11=Toggle
F16=Repeat find F17=Repeat change F24=More keys
(C)
COPYRIGHT IBM CORP. 1981, 2002.
READP (Read Prior)
READP reads previous record from a full
procedural file. Record format/File name is written in the factor2 of the file
that is to be read. Indicators define in the EO factor get on if record is not
found. Indicators define in the LO (ER) factor get on if READP operation was
not completed successful.
Factor 1 |
Search argument
|
Factor 2 |
File name / record format
(Mandatory)
|
Result Field |
Data Structure (only for
program describe file)
|
HI |
|
LO |
ER (Optional)
|
EQ |
BOF
|
Columns . . . : 1
71 Edit PB01U01S/MYRPG
SEU==>
EXA21
FMT
FX .....FFilenameIPEAF........L..I........Device+......KExit++Entry+A....U
*************** Beginning of data
*************************************
0001.00 FEMP
IF E K DISK
0001.01 C* READP EXAMPLE
0001.02 C
*HIVAL SETGTEMPR
0001.03 C* FILE POINTER IS SET TO HIGHEST
VALUE
0001.04 C READPEMPR 90
0001.05 C *IN90 IFEQ *OFF
0001.06 C EMPNO DSPLY
0001.07 C ENAME DSPLY
0001.08 C DEP DSPLY
0001.09 C ELSE
0001.10 C* IF INDICATOR 90 IS ON THEN ERROR IS
DISPLAYED
0001.11 C 'ERROR' DSPLY
0001.12 C ENDIF
0008.00 C SETON LR
****************** End of data ****************************************
F3=Exit
F4=Prompt F5=Refresh F9=Retrieve
F10=Cursor F11=Toggle
F16=Repeat
find F17=Repeat change F24=More keys
REDPE (Read Prior Equal)
REDPE is used for keyed file processing.
REDPE reads previous record whose key values matches with search argument in
factor1. Record format/File name is written in the factor2 of the file that is
to be read. Indicators define in the EO factor get on if record is not found.
Indicators define in the LO (ER) factor get on if REDPE operation was not
completed successful.
Factor 1 |
Search argument
|
Factor 2 |
File name / record format
(Mandatory)
|
Result Field |
Data Structure (only for
program describe file)
|
HI |
|
LO |
ER (Optional)
|
EQ |
BOF
|
Columns . . . : 1
71 Edit PB01U01S/MYRPG
SEU==>
EXA22
FMT
FX .....FFilenameIPEAF........L..I........Device+......KExit++Entry+A....U
*************** Beginning of
data *************************************
0001.00 FEMP
IF E K DISK
0001.01 C* REDPE EXAMPLE
0001.06 C Z-ADD5 RR
30
0001.07 C RR CHAINEMPR 90
0001.08 C *IN90 IFEQ *OFF
0001.12 C *IN91 DOWEQ*OFF
0001.13 C READEEMPR 91
0001.14 C EMPNO DSPLY
0001.15 C ENAME DSPLY
0001.16 C ENDDO
0001.17 C ENDIF
0008.00 C SETON LR
****************** End of data ****************************************
F3=Exit
F4=Prompt F5=Refresh F9=Retrieve
F10=Cursor F11=Toggle
F16=Repeat
find F17=Repeat change F24=More keys
(C)
COPYRIGHT IBM CORP. 1981, 2002.
DELET (Delete record)
The DELET operation deletes a record from a
database file. Factor2 must contain the name of the update file or the name of
a record format in the file from which a record is to be deleted. You can
specify a resulting indicator in positions 56 and 57; it is set on it he DELET
operation is not completed successfully. The record must have been locked by a
previous input operation like CHAIN or READ.
Nr indicates no record for delete. Er
indicates DELET operation was not completed successfully.
If factor 1 has entry then we must have to
specify the indicator in the HI entry, if factor 1 is blank then leave the HI
entry blank. This indicator set on if the record specify in factor 1 is not
found in the file. Indicator define in the LO entry will set on if the delete
operation is not complete successfully.
Factor 1 |
Search argument (Optional)
|
Factor 2 |
File name / record format
(Mandatory)
|
Result Field |
Data Structure (only for
program describe file)
|
HI |
Nr
|
LO |
Er
|
EQ |
|
Columns . . . : 1
71 Edit PB01U01S/MYRPG
SEU==>
EXA23
FMT
FX .....FFilenameIPEAF........L..I........Device+......KExit++Entry+A....U
*************** Beginning of data
*************************************
0001.00 FEMP
UF E K DISK
0001.01 C* DELETE EXAMPLE
0001.06 C Z-ADD5 RR
30
0001.07 C RR CHAINEMPR 90
0001.08 C *IN90 IFEQ *OFF
0001.13 C DELETEMPR
0001.17 C ENDIF
0008.00 C SETON LR
****************** End of data ****************************************
F3=Exit
F4=Prompt F5=Refresh F9=Retrieve
F10=Cursor F11=Toggle
F16=Repeat
find F17=Repeat change F24=More keys
(C)
COPYRIGHT IBM CORP. 1981, 2002.
UPDAT (Modify Existing Record)
The UPDAT operation modifies the last
record retrieved for processing from an update disk file or subfile. No other
operation should be performed on the file between the input operation that
retrieved the record and the UPDAT operation. Factor2 must contain the name of
a file or record format to be updated. A record format name in factor2 is
required with an externally described file. You can specify a resulting
indicator in (LO) to be set on if the UPDAT operation is not completed
successfully.
Factor 1 |
|
Factor 2 |
File name / record format
(Mandatory)
|
Result Field |
Data Structure (only for
program describe file)
|
HI |
|
LO |
Er
|
EQ |
|
Columns . . . : 1
71 Edit PB01U01S/MYRPG
SEU==>
EXA24
FMT
FX .....FFilenameIPEAF........L..I........Device+......KExit++Entry+A....U
*************** Beginning of data
*************************************
0001.00 FEMP
UF E K DISK
0001.01 C* UPDATE EXAMPLE
0001.06 C Z-ADD3 RR
30
0001.07 C RR CHAINEMPR 90
0001.08 C *IN90 IFEQ *OFF
0001.09 C MOVEL*BLANKS ENAME
0001.10 C MOVEL'ARUN' ENAME
0001.13 C UPDATEMPR
0001.17 C ENDIF
0008.00 C SETON LR
****************** End of data ****************************************
F3=Exit
F4=Prompt F5=Refresh F9=Retrieve
F10=Cursor F11=Toggle
F16=Repeat find F17=Repeat change F24=More keys
(C)
COPYRIGHT IBM CORP. 1981, 2002.
No comments:
Post a Comment