as400 interview questions and answers-Part 28


1. Explain SETLL opcode with example.

 

Ans:

SETLL (E)  (Set Lower Limit)

·         SETLL sets the file pointer at the first occurrence of the record where the key field/RRN value is greater than or equal to the factor-1 search argument value.

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

  • If the SETLL operation is not successful (no records found condition), the file is positioned to the end of the file.

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

·         We use %FOUND to determine if the record found is having the key field/RRN value greater than or equal to the key field. In this case HI indicator will be *on.

·         We use %EQUAL to determine if the record found is having the key field/RRN value exactly same as the search argument value in factor-1.

·         For sequential file we can use RRN value only. In this case EQ indicator will be *on.

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

·         The Equal Indicator gets turned-on if and exact match is found. We can use this in place of %equal().

·         If Greater value match is found then HI level indicator will get turned on. We can use this in place of %found().

·         *LOVAL doesn’t work for non-keyed file.

·         SETLL if successful sets EOF() *OFF if it is *ON, else if not successful doesn’t do anything to EOF().

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

*HIVAL    SETLL    File001

          READ

 

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

*LOVAL    SETLL    File001

          READP

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

*LOVAL    SETLL    File001

          READ

 

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

*HIVAL    SETLL    File001

          READP

 

·         If a new record is added or a key field altered after a SETLL operation with either *LOVAL or *HIVAL, the file may no longer be positioned to the record with the lowest or highest key.

·         The SETLL operation does not apply the lock on the file hence if we just want to check the existence of a record it is better to go for SETLL instead of using CHAIN which locks the records and copies the data into input buffer leading to performance issue.

 

Factor 1

Op-code

Factor 2

Result Field

Resulting Indicators

       HI                            LO                      EQ

Search argument

SETLL(E)

File or record format name

 

Greater value match found

Error

Exact match found

 

 

Example-I : SETLL for sequential file

    000001    setll filename  (instead of: *LOVAL SETLL      REC1)

 

 

Example-II : SETLL does not set EOF to *ON if not successful.

 

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 ‘P00000000001’ in factor-1 for SETLL operation.


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


 

OUTPUT

EXACT MATCH

 

 

·         Now we put ‘P00000000007’ in factor-1 for SETLL operation.


Columns . . . :    6  80                      Browse                          AMITCC/QRPGLESRC
SEU==>                                                                               OP_SETLL
FMT FX FFilename++IPEASF.....L.....A.Device+.Keywords+++++++++++++++++++++++++++++
*************** Beginning of data ****************************************************
0001.00 FPF0001    IF   E           K DISK                                              130211
0003.00 C     'P00000000007'SETLL     REC2                                              130212
0004.00 C                   IF        %EQUAL(PF0001)                                    130211
0005.00 C     'EXACT MATCH' DSPLY                                                       130211
0006.00 C                   ELSEIF    %FOUND(PF0001)                                    130211
0007.00 C     'HIGHER MATCH'DSPLY                                                       130211
0008.00 C                   ELSEIF    %EOF(PF0001)                                      130212
0009.00 C     'END OF FILE' DSPLY                                                       130212
0010.00 C                   ELSE                                                        130211
0011.00 C     'NO RECORDS'  DSPLY                                                       130212
0012.00 C                   ENDIF                                                       130211
0013.00 C                   SETON                                        LR             130128
****************** End of data *******************************************************

 

OUTPUT

HIGHER MATCH

 

 

·         Now we put ‘P00000000009’ in factor-1 for SETLL operation.


Columns . . . :    6  80                     Browse                           AMITCC/QRPGLESRC
SEU==>                                                                               OP_SETLL
FMT FX FFilename++IPEASF.....L.....A.Device+.Keywords+++++++++++++++++++++++++++++
*************** Beginning of data ****************************************************
0001.00 FPF0001    IF   E           K DISK                                              130211
0003.00 C     'P00000000009'SETLL     REC2                                              130212
0004.00 C                   IF        %EQUAL(PF0001)                                    130211
0005.00 C     'EXACT MATCH' DSPLY                                                       130211
0006.00 C                   ELSEIF    %FOUND(PF0001)                                    130211
0007.00 C     'HIGHER MATCH'DSPLY                                                       130211
0008.00 C                   ELSEIF    %EOF(PF0001)                                      130212
0009.00 C     'END OF FILE' DSPLY       >>>>>>> SETLL never sets EOF if it doesn’t      130212
0010.00 C                   ELSE                       find a record                    130211
0011.00 C     'NO RECORDS'  DSPLY                                                       130212
0012.00 C                   ENDIF                                                       130211
0013.00 C                   SETON                                        LR             130128
****************** End of data *******************************************************


 

OUTPUT

NO RECORDS                   

 

 

 

Example-II : SETLL sets EOF to *OFF, if successful

 


Columns . . . :    6  80                Browse                               AMITCC/QRPGLESRC
SEU==>                                                                             OP_SETLL2
FMT FX FFilename++IPEASF.....L.....A.Device+.Keywords+++++++++++++++++++++++++++++
*************** Beginning of data ****************************************************
0001.00 FPF0001    IF   E           K DISK                                              130211
0003.00 C     *HIVAL        SETLL     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'SETLL     REC2                                              130212
0009.00 C                   IF        %EQUAL(PF0001)                                    130212
0010.00 C     'EXACT MATCH' DSPLY                                                       130211
0011.00 C                   ELSEIF    %FOUND(PF0001)                                    130211
0012.00 C     'HIGHER MATCH'DSPLY                                                       130211
0013.00 C                   ELSE                                                        130211
0014.00 C     'NO RECORDS'  DSPLY                                                       130212
0015.00 C                   ENDIF                                                       130211
0016.00 C                   IF        NOT %EOF(PF0001)                                  130212
0017.00 C     'NOT EOF'     DSPLY                                                       130212
0018.00 C                   ENDIF                                                       130212
0019.00 C                   SETON                                        LR             130128
****************** End of data *******************************************************


OUTPUT

END OF FILE              

EXACT MATCH               

NOT EOF                  

 

 




 

 







User Comments:



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