Midrange News for the IBM i Community

Posted by: Danny Hayes
Chain in RPG Free
has no ratings.
Published: 15 Apr 2013
Revised: 17 Apr 2013 - 3701 days ago
Last viewed on: 05 Jun 2023 (23965 views) 

Using IBM i? Need to create Excel, CSV, HTML, JSON, PDF, SPOOL reports? Learn more about the fastest and least expensive tool for the job: SQL iQuery.

Chain in RPG Free Published by: Danny Hayes on 15 Apr 2013 view comments(6)

I am at a new company, and am tasked with a little mod to an existing production program.

The pgm references a logical:

     A          R I0411                     PFILE(F0411     )
     A          K RPRMK                                      
     A          K RPAN8                                      
     A          K RPDOC   




The program using Free does the following:

Eval Wrknum=DaPnum  ;

Eval VndNum#=%Dec(DapVnd:8:0)   ;

Chain (WrkNum:VndNum#) F0411LAA ;

IF Not %Found(F0411LAA) OR RPCRC <> '835' ;

 Eval No835='Y'    ;

EndIf     ;


Have I slipped into an alternate reality where it is now possible to CHAIN using keys 2 and 3 while ignoring 1?

Thanks for your kind understanding.


Return to midrangenews.com home page.
Sort Ascend | Descend


(Sign in to Post a Comment)
Posted by: DannyFromOP
Premium member *
Comment on: Chain in RPG Free
Posted: 10 years 1 months 20 days 1 hours 47 minutes ago

Does it perhaps consider the first field blank and chain with that as the value?


Posted by: bobcozzi
Site Admin ****
Comment on: Chain in RPG Free
Posted: 10 years 1 months 20 days 14 minutes ago

Danny, is there a question in there somewhere?

All you're experiencing is the enhancement to the CHAIN opcode in free-format.

In Free-format, the KLIST/KFLD statements are no longer necessary. You use what's called "ad hoc key lists" instead. To do that you enclose the key fields that would normally appear on the KLIST/KFLD statements in parentheses. The keylist has to contain a field count that is less than or equal to the number of key fields defined in the file.

You can also specify %KDS( dataStruct : 3) and the compiler will use the first 3 (in this example) subfields of the specified data structure as the key fields. You can put any number you want in the 2nd parameter, again as long as it is less than or equal to the number of keyfields in the file.


Posted by: TFisher
Premium member *
Comment on: Chain in RPG Free
Posted: 10 years 1 months 19 days 23 hours 45 minutes ago

It "looks like" you are CHAINing with the first two keys of the file and the third key (RPDOC) isn't being used by the CHAIN.

Posted by: Viking
Premium member *
Comment on: Chain in RPG Free
Posted: 10 years 1 months 19 days 22 hours 51 minutes ago

Danny, no you can't chain with key 2 and 3 while ignoring key 1.  The code you've shown is chaining with wrknum and vndnum# as the first two keys.

You're obviously in JDE and F0411 is the Accounts Payable Ledger.  Field RPRMK is a "remark" field of 30A, and RPAN8 is the "address number" and is 8,0.  RPDOC is the "document number" and is also 8,0.  So your logical F0411LAA is by remark, address number, and document number, where the program is using the vendor number as the address number in question.

But are you sure that F0411LAA is the way you show in the beginning of your post?  If so, then yes the code does seem to chain with wrknum in the remark field and then vndnum# as the address number, and not specify the document number.

Something somewhere is not quite right it seems.  Maybe either the logical F0411LAA is not laid out the way you showed, or the code may be chaining to the wrong logical.  Or wrknum and dapnum are just very poorly named and really do contain the remark?

Posted by: Ringer
Premium member *
Comment on: Chain in RPG Free
Posted: 10 years 1 months 18 days 4 hours 17 minutes ago

Is this an INPUT F-Spec and not an UDPATE? If so, I *always* code chain(n) instead of chain (thanks GC). Yes, it generates a compiler warning. Why do I do this? Because as soon as the next programmer changes the IF to UF, adds an UPDATE statement somewhere in the code, compiles, installs it production, your code breaks with record locks out the wazoo. THEN after they get 50 phone calls, they check the source code back out and add the (n) everywhere. So might as well do it up front.

Chris Ringer

Posted by: neilrh
Premium member *
Jackson, MI
Comment on: Chain in RPG Free
Posted: 10 years 1 months 17 days 23 hours 20 minutes ago

Ringer... also if someone adds a shared open somewhere up stream, your file might suddenly find itself an update file, with no clues in program of the problems that could transpire.