What is the purpose of /DEFINE before H-spec?

Tags:
AS/400
RPGLE
/DEFINE is a part of compiler directives, which if used will reduce source listings of the program. But I would like to know what happens in runtime if I use this directive. for eg: If I use /DEFINE in pgm : /DEFINE MOD_1..then in I write /If Defined(Mod_2) read FileA; /Else read FileB; /endIf
1

Answer Wiki

Thanks. We'll let you know when a new response is added.

You need to read the programming manual.

Some excellent examples are provided.

but briefly, if you are abstracting functionality to single source files you wish to avoid duplication on insert calls. so you can define conditions which are checked by the compile source preprocessor.

There are concepts, sound concepts, for program construction which you need to gain familiarity with. 
A forum like this will  give you simplistic, and possibly erroneous answers.  Read the book.

 

Discuss This Question: 4  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • TheRealRaven
    The compiler will insert the "read FileB;" statement and won't put "read FileA;" in the program at all. So "read FileB;" is all that will ever be run.

    The compiler directives are only active during compiles. They are gone after the object is compiled.
    36,430 pointsBadges:
    report
  • Supriyoas400
    Hi..thanks for your answer, but my real question is if "Read FileA" is not put in the program ,then what is the use of defining it, beacuse FileA will never be read..if this is the case then we could have simply commented/ommited statements for FileA....please correct me if i am wrong..thanks
    250 pointsBadges:
    report
  • TheRealRaven
    (Stupid editor really messed up my earlier reply, with no way to tell when I did it and no way to correct it.)

    It would be defined for conditions when "/DEFINE MOD_2" would be used for the compile. Under some conditions, the developer wants to compile the program to read from FileA; but other times the program should be compiled to read from FileB.

    Maybe the file changed after an application upgrade. The application runs on some systems as version 1 and on other systems as version 2. The developer wants one version of source for the program. Simply by changing the condition at compile-time, the same source can be used for both versions.

    I use it most often to compile programs for different versions of the OS. I'd guess it's used much more often in commercial program source where different customer sites have different requirements. Different compiles go to different customers.
    36,430 pointsBadges:
    report
  • TheRealRaven
    I also use it to have prototypes, procedure interfaces and related data definitions in a single source member. I can use the same member at different points in a compile and pull in different parts. I might use all three parts in the *MODULE itself, but only use the prototype portion, and probably data definitions, in the calling procedure.
    36,430 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: