One of the problems I see over and over again is that programmers declare work fields immediately following a data structure, program described or externally described. The code example shown below is very common, and it often causes several hours--and sometimes days--of confusion and debugging.
One of the most common mistakes is an omission when declaring work fields outside of data structures. Often, a key identifier is overlooked and, because it is not intuitive, a programmer may not notice it.
So what's wrong with this code? Technically speaking, nothing. The data structures CUSTOMER and ITEMS are valid, as is the COUNT field. Or is it?
.....DName+++++++++++EUDS.......Length+TDc.Functions++++++
D Customer E DS ExtName(CUSTMAST)
D Count 10I 0
D Items E DS ExtName(ItemMast) Occurs(50)
In the code in the above example, there is a data structure named CUSTOMER that is externally described. All subfields in the CUSTOMER data structure come from the field descriptions of the CUSTMAST file. Next, the COUNT field is declared. In this case, it is declared with the intent of it being a work field. However, as it is coded, it is actually declared as an additional subfield for the CUSTOMER data structure.
What is missing from the original Definition specification is the inclusion of the Definition Type in the COUNT definition. (Don't confuse Definition Type with Data Type. They are two different components.) Without this Definition Type, COUNT is considered just another subfield of the CUSTOMER data structure and is not an independent or standalone field.
The COUNT field's correct definition is as follows:
D count S 10I 0
Note the "S" in position 22. This indicates that the field is a standalone field and is not part of a data structure.
The original statements, rewritten correctly, are as follows:
.....DName+++++++++++EUDS.......Length+TDc.Functions+++++++++
D Customer E DS ExtName(CUSTMAST)
D count S 10I 0
D Items E DS ExtName(ItemMast) Occurs(50)
Bob Cozzi has been programming in RPG since 1978. Since then, he has written many articles and several books, including The Modern RPG Language--the most widely used RPG reference manual in the world. Bob is also a very popular speaker at industry events such as RPG World and is the author of his own Web site and of the RPG ToolKit, an add-on library for RPG IV programmers.



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.
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:
LATEST COMMENTS
MC Press Online