There always seems to be an endless supply of oversights when writing code, and RPG IV is no exception. When I do code reviews, I often see the following problem in the Definition specification. Can you spot the problem?
D ITEM DS Inz
D Category 3A
D SeqNbr 5S 0
D Postfix 2S 0
D AmtDue 7P 2
The problem is that the field named AMTDUE (line 5) was not intended to be part of the ITEM data structure. In order for AMTDUE to be an independent field, the field must be declared as a standalone field. This requires an "S" in position 24 of the Definition specification. Here's the corrected code:
D ITEM DS Inz
D Category 3A
D SeqNbr 5S 0
D Postfix 2S 0
D AmtDue S 7P 2
Remember, a data structure or parameter list ends when it encounters another type of Definition specification. This means a statement with an entry in column 24 ends the prior Definition specification group. A Definition specification group is also terminated when an Input, Calc, or Output specification is encountered.
Knowing the LIKE Keyword
The LIKE keyword can be used on the Definition specification to create a new field like an existing field. What some people do not know, however, is that when the LIKE keyword is used, only the field's data type and length are inherited. Other keywords or attributes that apply to that field--such as the DIM keyword, an initial value, or date format--are not inherited. Therefore, when you use the LIKE keyword and you also want the new field to be an array or have the same initial value, you must specify those keywords as well as the LIKE keyword. Here's an example:
D CubsScores S Like(GameScores) Dim(%elem(games))
This creates two fields, GAMES and CUBSSCORES. Both are arrays with 10 elements each, and each element is a seven-position packed value with zero decimals.
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