Q: How can I determine the library from which an RPG program is loaded?
A: You can determine the library from which an RPG program or service program is loaded by examining positions 81 - 90 of the Program Status Data Structure. Consider the following sample program that displays the library from which it is loaded:
D PgmStatus SDS Qualified
D PgmLib 81 90
/Free
Dsply PgmStatus.PgmLib ;
*InLR = *On ;
/End-Free
This program simply defines the program status data structure as a qualified data structured named PgmStatus. At execution time, subfield PgmStatus.PgmLib will contain the name of the library from which the program is loaded.
You can also determine the library from which a service program is loaded by defining the program status data structure in the global (main) section. You can then retrieve the information from the data structure from within the service program's procedures.