ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Read indexed file on CLLE program

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Read indexed file on CLLE program

    Hi all, can you tell me please a way to read an indexed file on CLLE program? or how can I retrieve one record for an unique key like chain or several records like setll.
    I know only the option with receive file - RCVF and loop until I get enf of file with CPF0864, are there any other options? I understand that I can retrieve with OVRDBF with position with key, can you give me an exemple please? thanks in advance

  • #2
    The OVRDBF command is a good option if you only want to retrieve one record by key value. Another method would be to use the OPNQRYF command to do more advanced record selection and/or sequencing.

    Code:
    OVRDBF     FILE([I]filename[/I]) POSITION(*KEY [I]#keys rcdfmt keyvalues[/I])
    RCVF
    MONMSG     MSGID(CPF4137) /* key value not found */
    
    or
    
    OVRDBF     FILE([I]filename[/I]) SHARE(*YES)
    OPNQRYF    FILE(([I]filename[/I])) QRYSLT([I]selection criteria[/I]) KEYFLD(*FILE) or KEYFLD([I]sequence fields[/I])
    
    DOWHILE    COND('1')                 
    RCVF                                 
    MONMSG     MSGID(CPF0864) EXEC(LEAVE)
    ... program logic
    ENDDO

    Comment


    • #3
      Thanks Brian for the example

      Comment


      • #4
        I have an error when I try to retrieve a record from a logical file with one key - the position option for member MYFILEL1 file MYFILEL1 in library MYLIB is not valid
        The conditions that can cause this error include:
        -- The relative record number or key specified with the OVRDBF command
        does not exist in the file.
        -- A key position was specified with the OVRDBF command for a file that is
        either not keyed or is being opened for an arrival sequence.
        -- A relative record number position for a keyed file was specified with
        the OVRDBF command.
        -- A relative record number position for a distributed file was specified
        with the OVRDBF command.
        -- An error occurred while the operation to set the position in the file
        was being done.
        Recovery . . . : Do one of the following and try your request again:
        -- Use the OVRDBF command to specify a record that exists in member
        MYFILEL1.
        -- If the file is keyed, do not open the file for an arrival sequence.
        -- If the file is not keyed, specify the position by relative record
        number.
        -- If you need to set the initial record position by relative record
        number, open the file for arrival sequence.
        -- If the file is a keyed distributed file, set the initial record
        position by key rather than by relative record number. If you need to set
        the initial record position by relative record number, then change the file
        so it is not a distributed file.
        -- Display the low-level messages and correct any errors.



        I have in the program like this:
        OVRDBF FILE(MYFILEL1) POSITION(*KEY 1 MYFORMAT_RECORD &VAR) --> &VAR filled with value for comparing with the key from file
        RCVF OPNID(P1)
        MONMSG MSGID(CPF4137) EXEC(GOTO CMDLBL(END))


        In the debug mode:
        OVRDBF FILE(MYFILEL1) POSITION(*KEY 1 MYFORMAT_RECORD 'TEST1') --> I have a record with key='TEST1' in the file
        RCVF DEV(*FILE) RCDFMT(*FILE) WAIT(*YES) OPNID(P1)

        Comment


        • #5
          Is MYFORMAT_RECORD really the name of the record format of file MYFILEL1? The record format name cannot be more than 10 characters long. To get the actual record format name, use command DSPFD FILE(MYFILEL1) TYPE(*RCDFMT). Also, the OPNID parameter on the RCVF command is valid only if you used the same open ID when you declared the file.

          Comment


          • #6
            One other thing about the record format name, if you don't want to bother using it, you can skip it altogether:
            OVRDBF FILE(MYFILEL1) POSITION(*KEY 1 *N &VAR)

            Comment


            • #7
              No, the record format is ok, it was just a substitution, but it is no longer then 10.
              I also tried with *N but I have the same error, I will check again all the statement

              Comment


              • #8
                I verified and I succeded in this way to retrieve the record by key:

                OVRDBF FILE(MY_FILE) POSITION(*KEYAE 1 *N &VAR)
                RCVF OPNID(P1)
                MONMSG MSGID(CPF4137) EXEC(GOTO CMDLBL(END))

                where &VAR is the variable filled with value desired for my key from MY_FILE - and MY_FILE is a logic with one key on a PF without key

                it goes well with *KEYAE instead of *KEY in the parameter for position OVRDBF

                Comment


                • #9
                  OK, but beware that using *KEYAE will return a record with an unequal key value if no record is found matching the key. From the command help text:
                  *KEYAE
                  The record identified by the search values is the first record read. If there is no record that matches those values, the record with the next highest value is selected.

                  Comment

                  Working...
                  X