TechTalk: Data Area Abraca-data

General
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

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 
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: