Data Area Abraca-data
Compiled languages have a great advantage over interpreted languages: you cannot use variables you have not defined. This means that if you make a typo in a variable name, the compiler alerts you. The program doesn't have a chance to run and give you incorrect information.
RPG/400 is compiled, and yet it has a feature that spells trouble if your fingers don't do the walking on the right keys. The RPG code shown in 1 seems all right, but suppose there is no GHOST data area anywhere in your library list. Maybe you can't expect the compiler to check for existence of data areas, but at least you expect to get some kind of error message at run time.
RPG/400 is compiled, and yet it has a feature that spells trouble if your fingers don't do the walking on the right keys. The RPG code shown in Figure 1 seems all right, but suppose there is no GHOST data area anywhere in your library list. Maybe you can't expect the compiler to check for existence of data areas, but at least you expect to get some kind of error message at run time.
The problem is that there isn't any. The program runs without issuing as much as an *INFO message. In fact, the system goes on to create data area GHOST in QTEMP. Try it and you'll see; you're not seeing ghosts. The RPG/400 User's Guide for V2R2M0 says the following on page 279:
"For a data area data structure [that's STRUCT in 1], if the data area exists in a library that is specified in the library list, the data area is copied into the program. If the data area does not exist in a library that is specified in the library list, the name and length of the data structure are used to generate a data area in the job's temporary library (QTEMP)."
"For a data area data structure [that's STRUCT in Figure 1], if the data area exists in a library that is specified in the library list, the data area is copied into the program. If the data area does not exist in a library that is specified in the library list, the name and length of the data structure are used to generate a data area in the job's temporary library (QTEMP)."
Got that? The system creates data area GHOST in QTEMP as a four-byte character data area because STRUCT is defined that way. The problem is that you may have typed in the data area name incorrectly, perhaps transposing two characters, when you entered the DEFN statement. If you do an IN op code on STRUCT somewhere in your program, you'd be reading blanks from the bogus data area in QTEMP, when in fact you should be reading a different data area in a different library!
Two observations:
o The data area created in QTEMP is always of type *CHAR. o If you remove the U in the data structure definition statement, the program halts with an error message when you run it, saying that the data area doesn't exist.
- Gregory Leister
Editor's Note: It seems that, in general, you should avoid employing this combination of UDS and DEFN. There's little or no gain in doubly-defining the data area and it can get you in trouble.
TechTalk: Data Area Abraca-data
Figure 1 Doubly-defined Data Area
... 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ISTRUCT UDS I 1 4 ABC * C *NAMVAR DEFN GHOST STRUCT C MOVE *ON *INLR
LATEST COMMENTS
MC Press Online