TechTip: Coding KLIST and KFLD Opcodes

RPG
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times
Q: How do I code KLIST and KFLD opcodes in free-form calcs?

A: In V5R1, you code a composite key using KLIST and KFLD. It's just that those opcodes have to be coded in fixed-form calcs. Many people code their KLIST and KFLD opcodes at the beginning of their calculation specifications to put them closer to the definition specifications.

In V5R2, there are more options available to you. First, you can code the search arguments of the compound key directly in the keyed I/O statement. For example:
"chain (arg1: arg2: arg3+17) rec;"

Individual search arguments may be any expression, and they have to match the corresponding keys in type only. Unlike KLIST, RPG handles length and format conversion for the list of search arguments.

Second, you can define your search arguments as subfields of a data structure and code your I/O operation as "chain %kds(kds) rec;". This is nice if you define the data structure using "extname(file:rec:*key)", which defines the data structure as an externally described data structure with just the key fields of the record as the subfields.

The %kds() more closely approximates the KLIST operation code, but the list of search arguments syntax is more flexible. Note that these two options are available only in free-form calculations.

--Hans Boldt
This email address is being protected from spambots. You need JavaScript enabled to view it.



Hans Boldt
Hans Boldt worked as a software developer for 26 years at the IBM Canada Laboratory in Toronto , mainly on S/38, AS/400, and iSeries RPG compilers. From 2004 to 2007, he worked on the PL/X compiler on the zSeries, which gave him an increased appreciation for the iSeries. With a B.Sc. (Honours) in Computing and Information Science from Queen's University, Hans' interests range from programming languages to Web design to Linux. His other interests include photography, model railroading, and stained glass art. 

 

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  •  

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: