RPGLE multi-file processing with no match fields

850 pts.
Tags:
RPG
RPGLE
I believe I have found a bug in the way that RPGLE handles primary and secondary files with no match fields. My program will not process the primary file if there are no records in the secondary file; but it will process the secondary file, if there are no records in the primary file. RPG bug?


Software/Hardware used:
0

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

Discuss This Question: 26  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • ToddN2000
    We would need to see the code as to how you are reading the data from the files. It's hard to guess if there are no keys and also no CHAIN or READE op-codes being used.
    134,720 pointsBadges:
    report
  • ToddN2000
    Just though of something else. If you are using DO loops to process you will need to re-position the pointer to the beginning of the file at the end of a cycle. You can do this by making the files user controlled and then doing an OPEN and CLOSE manually.
    134,720 pointsBadges:
    report
  • GregManzo
    Can't use User Controlled open for Primary & Secondary files using the RPG cycle ('cos the cycle code has read a record from each before any C-specs get executed).
    Still, I'd be very surprised to find that significant a bug after this many years. Modiyooch, can you publish your code?
    2,970 pointsBadges:
    report
  • ToddN2000
    If these are truly input Primary and Secondary file I have not seen them used in decades. Back in the 80' when I was in college learning RPG II they were used but honestly I have not seen them in use since the mid 90's. It may be better to rewrite the the outdated code if you have the time to make it more efficient.
    134,720 pointsBadges:
    report
  • ej
    I haven't used Primary/Secondary file processing for a long while, but can't imagine the logic would have changed since the days of RPGII. Using the logic cycle, if no matching fields were declared (M1, M2, etc.) the primary file was read beginning-to-end before it would process any of the records in the secondary files.
    70 pointsBadges:
    report
  • pdraebel
    Could it have to do with which file turns on LR when it gets to end of file?
    7,545 pointsBadges:
    report
  • GregManzo
    I don't think so. From memory LR doesn't come on until the primary & all secondary files are at end; you process the last record from the last file, then the program ends.
    If this is more than just a homework question, then I'd suggest you avoid using the cycle for any permanent production code, because you want it to be maintainable by the next person to come along. There are only about 5 of us left on the planet that can read RPG cycle.
    2,970 pointsBadges:
    report
  • Modiyooch
    Sorry all,   Here is the code.   F and mainline C specs.  The cycle controls input and lr processing.  Thanks for your replies!

    FMCMSGJ6B  Ip   E           K disk                      
    FMCMSGJ6C  ISe  E           K disk    RENAME(MSGF: MSGF6
    Fmcmsgh    uF   E           K DISK                      
    Fommssts   iF   E           K DISK                      
    FITAXODM   O  A E             disk                      


     C                   if        mhpmid = '003' or mhpmid = '007
    C                   IF        MHUNIT > ' 10000'              
    c                   testn                   mdodom           
    c                   testn                   mdodom2          
     *Engine ECM                                                 
    c                   if        *in86                          
    C                   MOVEL     MDODom        XODM             
    c                   else                                     
    c                   eval      xodm = 0                       
    c                   end                                      
     *Odometer                                                   
    c                   if        *in87                          
    C                   MOVEL     MDODom2       XODM2            
    c                   else                                     
    c                   eval      xodm2= 0                       
    c                   end                                      
    C                   EVAL      XUNIT = MHUNIT                 
      *                                                            
    C     *LONGJUL      MOVE      MHDATE        USADAT            
    C                   MOVE      USADAT        xdate             
    C                   z-add     MHtime        xtym              
    C    
    C     *LONGJUL      MOVE      MHDATE        DateMC            
    C                   MOVE      MHtime        TymMC             
    C                   eval      TStmpMC = DateMC + TymMC        
    C                   movel     TStmpMC       WrkTStmp          
     *                                                            
    c                   exsr      CmpDate                         
    C   
    C                   movel     WrkTStmp      xdattym           
     /free                                                        
            xdattym = %replace('/': xdattym: %scan('-': xdattym));
            xdattym = %replace('/': xdattym: %scan('-': xdattym));
            xdattym = %replace(' ': xdattym: %scan('-': xdattym));
            xdattym = %replace(':': xdattym: %scan('.': xdattym));
     /end-free                                                    
     C                   end           
    850 pointsBadges:
    report
  • ToddN2000
    WOW after 35 year I though I had seen it all. You have a program with free form code and built in functions and it still is using the archaic primary/secondary RPG cycle? I would re write the program. It will make it much easier to understand the flow for others when it needs to be modified.
    134,720 pointsBadges:
    report
  • Modiyooch
    Personally, I'm not in the habit of rewriting code for the sake of it. I don't even think it's hard to follow. I also believe, if it isn't broken; don't touch it. I'm just surprised to find out that the behavior of an RPG program changed, and I consider it an error in the language. Although, it's not working like it should, in this environment, there will be a record in the primary file in a timely manner. The program runs every 10 minutes. I stumbled on what I think is an RPG error, and it was very aggravating to figure out that it wasn't the code. Unless, I'm missing something. That's why I presented the question.
    850 pointsBadges:
    report
  • ej
    Have you tried either taking the "e" off the F spec on your secondary file, or adding an E to the Primary file also? It tells the compiler to set on End of File based on that file only. I think that when your secondary file contains no records, it turns on LR and ends processing regardless of what you have for primary records. I think this would have always been the case even back to RPG or RPGII.
    70 pointsBadges:
    report
  • Modiyooch
    you know what's funny is that this three line program compiles, and can be used to test.

     FMCMSGJ6B  Ip   E           K disk                         
     FMCMSGJ6C  ISe  E           K disk    RENAME(MSGF: MSGF6C) 
     c                   testn                   mdodom         86
    850 pointsBadges:
    report
  • Modiyooch
    ej,  

    ILE RPG Reference

    Multi-file Processing with No Match Fields

    When no match fields are used in multi-file processing, records are selected from one file at a time. When the records from one file are all processed, the records from the next file are selected. The files are selected in this order:

    1. Primary file, if specified
    2. Secondary files in the order in which they are described on the file description specifications.
    850 pointsBadges:
    report
  • Modiyooch
    ej, adding an E to the primary file worked, which surprises me. I didn't think it would even compile that way.
    850 pointsBadges:
    report
  • Modiyooch
    If the records from all primary and secondary files must be processed, position 19 must be blank for all files or must contain E's for all files. For multiple input files, the end-of-program (LR) condition occurs when all input files for which an E is specified in position 19 have been processed. If position 19 is blank for all files, the end-of-program condition occurs when all input files have been processed.
    850 pointsBadges:
    report
  • Modiyooch
    Not a bug. Should have known.
    850 pointsBadges:
    report
  • Splat

    Am I correct in assuming the file layout / naming is the same between MCMSGJ6B & MCMSGJ6C?
    12,915 pointsBadges:
    report
  • ej

    I'm quite sure if you remove the e from you secondary file, so it looks like:

    FMCMSGJ6C IS_  E       K disk    RENAME(MSGF: MSGF6C), your program will run correctly. That position on the Fspec tells the compiler which file you want your program to use for End of File (LR) processing. When column 17 is blank for all files, RPG defaults that all records from all files (Primary and Secondary) must be processed before EOF occurs.

    70 pointsBadges:
    report
  • Modiyooch
    Splat, yes the file layouts are the same. I believe EJ is right in that all files need the E or no files need the E. I was able to test it, and it worked, plus I found IBM's explanation of the End of Program field. I do believe that it use to work differently, when only the last file had End of Program indication.
    850 pointsBadges:
    report
  • pdraebel
    I believe that in the RPG Cycle the first thing done is read from all files, test EOF condition and than continue. Both file are read and if on triggers EOF (LR) the program just ends before really doing anything.
    7,545 pointsBadges:
    report
  • ej
    That would be true as long as that file has the E (End of File) designation in the Fspec. If no file's Fspecs have the E, all primary and secondary files are read from beginning to end.
    70 pointsBadges:
    report
  • Modiyooch
    Primary file is suppose to be processed in it's entirety; then each secondary file in order of F spec. My program example never made it to a calc spec.
    850 pointsBadges:
    report
  • Splat
    Modiyooch, you, EJ, & others are correct about removing the end of file designator from the F spec. I'd run into that in the past &, quite simply, had forgotten it.
    Glad to know everything's working as needed.
    12,915 pointsBadges:
    report
  • Modiyooch
    Ok, it looks like a record is read from each file, and then determined which ones gets processed. With no matching fields, it would be the primary file, until read in full. It appears, that the E on the secondary file sets on LR on the initial read.
    850 pointsBadges:
    report
  • GregManzo
    Yes, that's because in order to make the match record logic work, the generated code actually does a read-ahead on each file (even if you aren't matching records).
    I had forgotten about the EOF field on the F-spec, most because I've never had to use it in the real world. (and so few programs use the cycle now anyway).
    More so than the mix of RPG cycle and /free code, I'm impressed by using primary/secondary on two logicals over the same data. How would that work anyway? Select/omit?
    2,970 pointsBadges:
    report
  • Modiyooch
    Greg, basically they are not just logicals, but join files with the same record layout. I'm processing MobileComm messages from transport trucks, and capturing their odometer readings associated with their data posts. Each message type returns a different layout of information sent. I have to parse the data from multiple records. I'm using two different type message returns.
    850 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: