as400 interview questions and answers-Part 24


1. Explain READ opcode in rpgle with example.

Ans:

READ (N | E) (Read a Record)             

·         Read operation reads the records of a full procedural file. First of all it reads the record where currently the pointer is and then advances the pointer to the next record.

·         The READ operation applies a record lock to files that are open in update mode. To avoid lock we use operator extender ‘N’.

·         To handle READ exceptions (file status codes greater than 1000), either the operation code extender 'E' or an error indicator at LO level can be used.

·         If the data-structure is specified in result field then the result of the operation is filled in the data structure.

·         If there is an error or there is end of file condition, then we must reposition the file pointer to a valid record. For pointer reposition we can use CHAIN, SETLL or SETGT operation.

·         The Equal Indicator gets turned-on if the EOF condition is met else it will be off. Instead of using this indicator we can also go for %EOF ().

 

Factor 1

Op-code

Factor 2

Result Field

Resulting Indicators

       HI                            LO                      EQ

 

READ(N|E)

File or record format name

Data structure to hold the result

 

Error

End-of-file condition indicator

 

 

Example – I


Columns . . . :    6  80                   Browse                             AMITCC/QRPGLESRC
SEU==>                                                                             OP_READIND
FMT FX FFilename++IPEASF.....L.....A.Device+.Keywords+++++++++++++++++++++++++++++
*************** Beginning of data ****************************************************
0001.00 FPF0001    IF   E           K DISK
0002.00 DDS1              DS                  LIKEREC(REC2)
0003.00 C     *LOVAL        SETLL     REC2
0004.00 C                   READ      PF0001        DS1                      90
0005.00 C                   DOW       *IN90=*OFF    >>>>>> *in90 at EQ-position indicates
0006.00 C     DS1           DSPLY                             EOF() condition
0007.00 C                   READ      PF0001        DS1                      90
0008.00 C                   ENDDO
0009.00 C                   IF        *IN90=*ON
0010.00 C     'END OF FILE' DSPLY
0011.00 C                   ENDIF
0012.00 C                   SETON                                        LR
****************** End of data *******************************************************


Output


AMINEM    P00000000001CONIZA TOJ020120121
IROBO     P00000000002HENGURIZZA010620121
END OF FILE     

 

 

               

 

Example – II


Columns . . . :    6  80                 Browse                       AMITCC/QRPGLESRC
SEU==>                                                                     OP_READIN2
FMT FX FFilename++IPEASF.....L.....A.Device+.Keywords+++++++++++++++++++++++++++++
*************** Beginning of data ********************************************
0001.00 FPF0001    UF A E           K DISK
0002.00 DDS1              DS                  LIKEREC(REC2)
0003.00 C     *LOVAL        SETLL     REC2
0004.00 C                   READ      PF0001        DS1    >>> DS1 = Data structure to store result
0005.00 C                   DOW       NOT %EOF(PF0001)     >>>> Using %EOF() instead of EQ
0006.00 C     DS1           DSPLY                                 resulting indicator
0007.00 C                   READ(N)   PF0001        DS1
0008.00 C                   ENDDO
0009.00 C                   IF        %EOF(PF0001)
0010.00 C     'END OF FILE' DSPLY
0011.00 C                   ENDIF
0012.00 C                   SETON                                        LR
****************** End of data ************************************************

 

 

OUTPUT

 

AMINEM    P00000000001CONIZA TOJ020120121             
IROBO     P00000000002HENGURIZZA010620121            
END OF FILE    

 




 

 







User Comments:



Copyright © www.go4as400.com, 2013-2023. Copyright notice   Terms of services   Privacy policy