ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Question about RCVF

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

  • Question about RCVF

    Hello guys,

    First of all thank you for your fast help !!

    I have a CL there i am reading a database with rcvf. i just read that if you use this it will read only 1 record.

    I just used it and it stuck at the first record. how can i read the next record ?

  • #2
    You can create a loop to cycle back to the RCVF to read the next record.
    Use MONMSG to check for end of file and exit the loop.

    Something like

    Code:
    DCLF MyFile
    READNEXT:  RCVF           /* Read a record  */
               MONMSG  MSGID(CPF0864)  EXEC(GOTO EOF)   /* End of file */
             /* Procees steps */
    Code
    More code
    /* Finished processing  */
               GOTO  READNEXT       /*  Get next record  */
    EOF:       /*  End of File  */
    I found some examples by internet search for "ibmi rcvf loop"

    I'm not sure what this website's policy is about linking to other sites, so I didn't include any, but there are numerous examples. Probably some on this site too.
    Last edited by MFisher; July 13, 2020, 01:34 PM.

    Comment


    • #3
      As MFisher has eluded, each time you issue the RCVF command, CL will read the next record in the file so you need to do the reads in a loop. When you get to the end of file and you try to read the next record, a CPF0864 error will be generated which you need to trap or your program will go into MSGW.
      There's many ways to do this and I prefer to use a the newer DOWHILE loops for this. Something like this:

      Code:
      DCL        VAR(&TRUE)      TYPE(*LGL)  VALUE('1')
      DCL        VAR(&FALSE)     TYPE(*LGL)  VALUE('0')
      DCL        VAR(&EoF)       TYPE(*LGL)
      DCLF       FILE(MyFile)
      
      CHGVAR     VAR(&eof) VALUE(&FALSE)
      RCVF
      MONMSG     MSGID(cpf0864) EXEC(CHGVAR VAR(&eof) VALUE(&TRUE))
      DOWHILE    COND(*NOT &eof)
         /* Your code goes here */
      
         RCVF                                                         
         MONMSG     MSGID(cpf0864) EXEC(CHGVAR VAR(&eof) VALUE(&TRUE))
      ENDDO

      Comment


      • #4
        Hey,
        thank you for your fast reply. My code is like your code but it still stucks on the first record when i debug my programm. i dont know why. I tried it with the dowhile loop and its the same. it stucks on the first record.



        Code:
        LOOP:  RCVF                                      
        MONMSG (CPF0864) EXEC(GOTO ENDE)                
        
        CALL       PGM(TEST) PARM(&PTH)            
        goto LOOP
        //Edit: My solution is correct. There is no problem with the RCVF. The problem is the call. I dont know why.

        Comment


        • #5
          We really don't have enough information to give any real assistance here. The small snippet you have provided looks fine so we'd need to see more details on the program. If you could supply the code it would be beneficial.
          How does &PTH get populated? Is it a field in the file? Where is the ENDE label? Is it after the LOOP label? What do you mean by it's stuck on the first record? Is the RCVF only being called once or do you think it's reading the same record or is it looping?
          The issue could also be in the TEST program but we have no details on that to provide any assistance.

          Comment


          • #6
            lynargs, in your edit, you say the problem is on the call. Can you describe the problem with the call? Is the call getting an error message, or is the called program getting the wrong value in the parameter, or ... ?

            Comment


            • #7
              Hello,
              i got the solution for my problem. the problem was that i had different parameter lengths. in my CL i had a variable that i was passing to my rpg programm. the lenght of the variable and the parameter was different.

              Comment

              Working...
              X