as400 interview questions and answers-Part 27


1. Explain SETGT opcode with example.

 

Ans:

 

SETGT (E)   (Set Greater Than)         

·         This opcode positions the file pointer at the next record which is having the key/RRN value just greater than the current key /RRN value.

·         After positioning the file pointer we can go for any file operation e.g. READ, READP, READPE, READE.

·         In factor-1 we can use figurative constants *LOVAL, *HIVAL, *START, *END or we can use RRN VALUE or KEY VALUE or KEY LIST.

·         SETGT if successful sets EOF() to *OFF, else if not successful doesn’t do anything to EOF().

·         For a descending order file, to read the first record we can do:

*HIVAL    SETGT    File001

          READ

·         For a descending order file, to read the last record we can do:

*LOVAL    SETGT    File001

          READP

·         For an ascending order file, to read the first record we can do:

*LOVAL    SETGT    File001

          READ

·         For an ascending order file, to read the last record we can do:

*HIVAL    SETGT    File001

          READP

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

 

Factor 1

Op-code

Factor 2

Result Field

Resulting Indicators

      HI                            LO                      EQ

Search argument

SETGT(E)

File or record format name

 

Greater value match found

Error

 

 

 

 

Example – I : SETGT sets EOF()=*ON if successful

 

 


Columns . . . :    6  80               Browse                                  AMITCC/QRPGLESRC
SEU==>                                                                                OP_SETGT
FMT FX FFilename++IPEASF.....L.....A.Device+.Keywords+++++++++++++++++++++++++++++
*************** Beginning of data ****************************************************
0001.00 FPF0001    IF   E           K DISK                                              130211
0003.00 C     *HIVAL        SETGT     PF0001                                            130212
0004.00 C                   READ      PF0001                                            130212
0005.00 C                   IF        %EOF(PF0001)                                      130212
0006.00 C     'END OF FILE' DSPLY                                                       130212
0007.00 C                   ENDIF                                                       130212
0008.00 C     'P00000000001'SETGT     REC2                                              130212
0009.00 C                   IF        %FOUND(PF0001)                                    130212
0010.00 C     'HIGHER VALUE'DSPLY                                                       130212
0011.00 C                   ELSE                                                        130212
0012.00 C     'NO RECORDS'  DSPLY                                                       130212
0013.00 C                   ENDIF                                                       130211
0014.00 C                   IF        NOT %EOF(PF0001)                                  130212
0015.00 C     'NOT EOF'     DSPLY                                                       130212
0016.00 C                   ENDIF                                                       130212
0017.00 C                   SETON                                        LR             130128
****************** End of data *******************************************************


 

 

 

OUTPUT

 

END OF FILE             

HIGHER VALUE            

NOT EOF                 

 

 

 

Example – II : Use of  %found(File name) with SETGT

 

Physical file used in the program: PF0001

PNAME       PNUM          PADDR       OPNDD  OPNMM  OPNYY   OPNSTS
AMINEM      P00000000001  CONIZA TOJ     2      1   2,012      1
IROBO       P00000000002  HENGURIZZA     1      6   2,012      1
ZENNIE      P00000000003  UENAI         13      1   2,012      2
JOHNNE      P00000000004  HOLLYNIA      14      2   2,011      1
JENNUMA     P00000000008  UNIBAR         9      1   2,011      2
            ********  End of report  ********

 

·         First of all put ‘P00000000007’ in factor-1 for SETGT operation.


Columns . . . :    6  80                  Edit                                AMITCC/QRPGLESRC
SEU==>                                                                               OP_SETGT
FMT FX FFilename++IPEASF.....L.....A.Device+.Keywords+++++++++++++++++++++++++++++
*************** Beginning of data ****************************************************
0001.00 FPF0001    IF   E           K DISK                                              130211
0003.00 DSTRING           S             35A   INZ(*BLANKS)                              130212
0004.00 C     'P00000000007'SETGT     REC2                               90             130212
0005.00 C                   IF        %FOUND(PF0001)                                    130212
0006.00 C                   READ      PF0001                                            130212
0007.00 C                   EVAL      STRING='HIGHER VALUE FOUND=' +  PNUM              130212
0008.00 C     STRING        DSPLY                                                       130212
0009.00 C                   ELSEIF    %EOF(PF0001)                                      130212
0010.00 C     'END OF FILE' DSPLY                                                       130212
0011.00 C                   ELSE                                                        130212
0012.00 C     'NO RECORDS'  DSPLY                                                       130212
0013.00 C                   ENDIF                                                       130211
0014.00 C                   SETON                                        LR             130128
****************** End of data *******************************************************

 

 

OUTPUT

 

DSPLY  HIGHER VALUE FOUND=P00000000008  

 

 

·         Now we put ‘P00000000015’ in factor-1 for SETGT operation.


Columns . . . :    6  80                 Edit                                 AMITCC/QRPGLESRC
SEU==>                                                                               OP_SETGT
FMT FX FFilename++IPEASF.....L.....A.Device+.Keywords+++++++++++++++++++++++++++++
*************** Beginning of data ****************************************************
0001.00 FPF0001    IF   E           K DISK                                              130211
0003.00 DSTRING           S             35A   INZ(*BLANKS)                              130212
0004.00 C     'P00000000015'SETGT     REC2                               90             130212
0005.00 C                   IF        %FOUND(PF0001)                                    130212
0006.00 C                   READ      PF0001                                            130212
0007.00 C                   EVAL      STRING='HIGHER VALUE FOUND=' +  PNUM              130212
0008.00 C     STRING        DSPLY                                                       130212
0009.00 C                   ELSEIF    %EOF(PF0001)  >>>>> SETGT if not successful       130212
0010.00 C     'END OF FILE' DSPLY                             doesn’t set EOF.          130212
0011.00 C                   ELSE                                                        130212
0012.00 C     'NO RECORDS'  DSPLY                                                       130212
0013.00 C                   ENDIF                                                       130211
0014.00 C                   SETON                                        LR             130128
****************** End of data *******************************************************


OUTPUT

NO RECORDS            

 

 

 

Example – III : To read a particular key value in reverse order

 

Physical file used in the program = ACCSUBPF

 

ORG CODE  ACC NUMBER    CURRENCY  ACCOUNT MNG  COUNTRY     PARTY
   190    A00000000001    EUR     DFJASHN      NKDAHFJ     P00000000001
   191    A00000000002    USD     DAJFK        DAJH        P00000000001
   192    A00000000003    TRY     DAHB         BJDKFA      P00000000001
   193    A00000000004    USD     KIRAN        NDKAL       P00000000001
   194    A00000000005    KWR     DANK         NKD         P00000000001
   195    A00000000006    TRY     APPRINA      SOUTN       P00000000001
   195    A00000000007    USD     SONATNA      SOUTN       P00000000001
****** ********  End of report  ********

 

 


Columns . . . :    6  80                 Browse                               AMITCC/QRPGLESRC
SEU==>                                                                              OP_READPE
FMT FX FFilename++IPEASF.....L.....A.Device+.Keywords+++++++++++++++++++++++++++++
*************** Beginning of data ****************************************************
0001.00 FACCSUBPF  IF   E           K DISK                                              130211
0002.00 C     'P00000000001'SETGT     ACCSUBPF                                          130211
0003.00 C     'P00000000001'READPE    ACCSUBPF                                          130211
0004.00 C                   DOW       NOT %EOF()                                        130211
0005.00 C     ACC           DSPLY                                                       130211
0006.00 C                   READPE    ACCSUBPF                                          130211
0007.00 C                   ENDDO                                                       130211
0008.00 C                   SETON                                        LR             130211
****************** End of data *******************************************************


 

 

 

 

OUTPUT

A00000000007

A00000000006

A00000000005

A00000000004

A00000000003

A00000000002

A00000000001

 

 

 



 

 







User Comments:



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