725 pts.
 How does KLIST work?
Hi, I'm debugging an RPG program and came across a 'KLIST ' with 'KFLDS'. What I know so far is that a KLIST is used as a search argument and KFLDS make up the argument, but what I want to know is how does this actually work? Are the KFLDS concentrated to make up one search argument or does a KLIST search a file with each KFLD one at a time? And finally what is a scenario in which I will need to use a KLIST?

Software/Hardware used:
RPG
ASKED: February 12, 2013  1:36 PM
UPDATED: February 12, 2013  2:18 PM

Answer Wiki:
Last Wiki Answer Submitted:  Be the first to answer this question.
All Answer Wiki Contributors:  Be the first to answer this question. Michael Tidmarsh   11,410 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 
A physical or logical file can have a composite key –

k OrdType

k CustNum

k OrdNum

Using this access path it’s possible to access the file using

OrdTyp

OrdTyp-CusNum

OrdType-CusNum-OrdNum

The key can be used in RPG code using the SETLL, READE, CHAIN, READPE

The way to present the composite key to the Operation is through a klist.

MyKey1   Klist
               Kfld       MyOrdTyp

MyKey2   Klist
               Kfld       MyOrdTyp
               Kfld        MoCusNum
           
MyKey3   Klist
               Kfld       MyOrdTyp
               Kfld        MyCusNum
               Kfld        MyOrdfNum

With these three klists the file can be accessed by the first, first and second, first second and third keys.  

                   MyOrdTyp = ‘A’
                    MyCusNum = ’12345′
                     MyOrdfNum = 512

MyKey3      Chain   Myfile
would find the record that matched all three values

MyKey2      Chain   Myfile
Would find the first record that matched the two values

MyKey1      Chain   Myfile
Would find the first record that matched the single field



RPGLE provides some alternatives to klist but the concept remains the same.



 44,220 pts.

 

Thanks a lot philp. It makes sense now.

 725 pts.