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