Tip

CHAIN operation in nutshell

In RPGLE, if you CHAIN to any file and try to evaluate the values of the file fields in debug (using 'Eval' on command prompt of STRDBG), only the fields that are used in the program will get populated by the CHAIN operation. Either the remaining fields will be zeros or blanks depending upon there file attributes.

It's possible that you CHAIN to a file using Klist constructed with work variables and CHAIN will be successful. Even still, the Key field values of the file won't be populated if you haven't used those key fields in your program. This may lead to the false assumption that CHAIN operation is not successful, but actually, it does and has populated the file fields that are mentioned in the program at one place or another.

In below example, CHAIN to employee file for Emp ID# = 100002 and Emp Location = 'BGL' is successful, but if you try and eval the values of EMPID# and EMPLOC field of file on STRDGB prompt using 'Eval', you will find these equal to zero and blank respectively.

 
  
*********** Beginning of Code ***********

 FEMPLOYEE  UF A E           K DISK

 

 C     K_IdLoc       Klist

 C                   Kfld                    W_LOC             3

 C                   Kfld                    W_EID#           10 0

 

 C                   Eval      W_Loc = 'BGL'

 C                   Eval      W_EID# = 100003

 C     K_IdLoc       Chain     EMP01

 C                   If        %Found(EMPLOYEE)

 C                   Eval      EMPNAME = 'Sandy'

 C                   EndIf

 

 C                   Seton                                        Lr

************** End of Code ************** 

This was first published in August 2005

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

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

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.