ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Chain returns no records, but I know they are there - what am I doing wrong!?

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

  • Chain returns no records, but I know they are there - what am I doing wrong!?

    Hello,

    I'm a noob and I'm trying to understand why my chain is failing to retrieve a record, any help would be appreciated.
    I am just trying to test reading from the same file whilst keeping the original read intact but I can't even get my crappy little test program to work, very disheartening...

    Some info;
    SICOMP is a 2 decimal field
    SISITE is a 4 character field

    I have tried defining RKCOMP and RKSITE manually as well as using LIKE() - same results.

    SiteF1 is a logical of SiteF, they share the same record format (SITEFR) and are both keyed by SICOMP and SISITE;

    Code:
    Record format . . . . . . . . . . . . . . . :            SITEFR  
      Key field . . . . . . . . . . . . . . . . :            SICOMP  
        Sequence  . . . . . . . . . . . . . . . :            Ascending
        Sign specified  . . . . . . . . . . . . :            SIGNED  
        Zone/digit specified  . . . . . . . . . :            *NONE    
        Alternative collating sequence  . . . . :            No      
      Key field . . . . . . . . . . . . . . . . :            SISITE  
        Sequence  . . . . . . . . . . . . . . . :            Ascending
        Sign specified  . . . . . . . . . . . . :            UNSIGNED
        Zone/digit specified  . . . . . . . . . :            *NONE    
        Alternative collating sequence  . . . . :            No
    The records I am trying to find 100% exist in both files, I have checked 1823 times and my library list is correct so they are the files I am expecting.
    What I am doing is running the below program in debug
    When the debug lands on a chain, I step the program to the next line and then do EVAL SISITE or EVAL RK_SISITE (depending on the chain) but the result is always ' '...

    I am completely baffled as to why nothing is found.

    Code:
    H option(*nodebugio)                                        
     *                                                          
    FSiteF     If   e           k disk                          
    FSiteF1    If   e           k disk    prefix(rk_)          
    F                                     rename(sitefr:sitefrk)
     *                                                          
    D rkcomp          s                   like(SICOMP)          
    D rksite          s                   like(SISITE)          
     *                                                          
    C                                                          
    C                   Eval      rkcomp=04                    
    C                   Eval      rksite='AB01'                
     *                                                          
    C     Key1          Chain     SITEF                        
     *                                                          
    C                   Eval      rksite='AT01'                
     *                                                          
    C     Key1          Chain     SITEF1              
    
    C                   eval      *inlr=*on          
    
     **********************************              
     * Sub Routines                                  
     **********************************              
    
    C     *INZSR        BegSr                        
    C                                                
    C     Key1          klist                        
    C                   kfld                    RKCOMP
    C                   kfld                    RKSITE
    C                                                
    C                   EndSr
    Many Thanks,
    Ryan
    Last edited by RDKells; August 21, 2017, 09:50 AM. Reason: Added field information

  • #2
    If you add DEBUG(*INPUT) to the H spec, then you will be able to see the contents of the record in debug. From the RPG Manual:
    *INPUT
    All externally described input fields will be read during input operations even if they are not used in the program. Normally, externally described input fields are only read during input operations if the field is otherwise used within the program.

    Comment


    • #3
      If your library list is correct -and- your key fields are defined properly and in the correct sequence, your code looks like is should work.

      I'm not a dedicated RPG'er...but I would be using result indicators on the CHAIN statements to see what they get set to...just in case ;-)

      Just my 2 cents...

      Comment


      • #4
        Thanks for the replies gents.

        I tried Brians suggestion and it worked, thank you very much.
        I guess if I used result indicators it would've reflected that I found a record yet no record was present so I would've been even more confused!

        Looks like I have a lot to learn, thanks again.

        Comment


        • #5
          You don't need to use result indicators. You can just check %FOUND.

          Code:
          chain ...;
          if %found();
             --- chain found a record
          endif;

          Comment

          Working...
          X