Accurate Program References
May 7, 2008 Ted Holt
|
I came across a situation recently that I thought some of you might find of interest. It has to do with program references (i.e., which objects a program uses) and conditional compilation. If you use a documentation package, whether homegrown or commercial, you may rely on program references without being aware of it. Here is my situation. As part of a conversion project, I have an RPG program that uses conditional compilation directives to select one of two SQL commands, like this:
D zKey s 3a
D zData s 5a
/free
*inlr = *on;
/if defined(SomeCondition)
exec sql
select key, data
into :zKey, :zData
from table1
where key = '1A';
/else
exec sql
select key, data
into :zKey, :zData
from table2
where key = '2A';
/endif
return;
I used the CRTSQLRPGI command to compile my program. Guess what? No matter how SomeCondition was set, the DSPPGMREF command showed that my program used both files–TABLE1 and TABLE2. For my project, reporting that both files are in use is unacceptable. My problem is that I was using the default RPGPPOPT(*NONE) on the CRTSQLRPGI command. A value of *NONE causes the SQL precompiler to process the source before the RPG compiler sees it. Since the SQL preprocessor doesn’t understand conditional compilation, it was passing both SQL commands to the compiler. The solution is to add the RPGPPOPT(*LVL1) parameter to the CRTSQLRPGI command. Doing so forces the RPG compiler to process the conditional directives before sending the source to the SQL precompiler. My project is back on track. Thanks to Barbara Morris of the RPG Compiler Team at IBM Toronto for her help with this tip. –Ted
|

