How can I retrieve the path of the currently executing RM/COBOL program?
I am making command-line calls via CALL "SYSTEM" and need a way to route the output depending on where the program is running.
#rm
#COBOL
Hi, Josh.
There are a couple ways to interpret your request, so I will toss out a few ideas.
You can get the main program name (the name that was started by the runcobol command, or by the BIS StartService tag) by using C$GetRMInfo. One of the fields returned is RM-MainProgramName. If you want the name of the program you are currently in, whether CALLed or executed from the runcobol command, you can use the PROGRAM-ID special register (see Chapter 1 of the RM/COBOL Language Reference Manual). Using the special register allows you to create a copybook that is usable in any program without jumping through hoops to get the program's name at run time.
Another way to get a program's name is to define a COBOL callable subroutine. In that subroutine, you can use C$WRU to obtain the caller's program name. (WRU = Who aRe yoU, from the old teletype days - not from current jargon, since C$WRU predates the internet!) The COBOL callable subroutine could implement the following and return the directory.
RM/COBOL uses the RUNPATH environment variable to find the COBOL object files when it has to load a program that is CALLed. But, if the RUNPATH contains multiple directories, you need to determine which directory contains a file.
So, you can define a binary sequential file, with a 1-character record size, which is the 'universal matching' file description. Place the program's object file name (minding case sensitivity on Unix based machines) in the pathname variable (defined on the SELECT), and do an OPEN INPUT.
Assuming the OPEN succeeded, you can then use C$GetLastFilename to obtain the pathname to the file. Strip off the file name from the pathname, and you have the directory where the file is located.
Does this meet your needs?
Best regards,
Tom Morrison
I like the idea of opening a "temp" file and using GetLastFilename to get the full path. Brilliant. I just assumed there was a simpler way to determine the path since when I turn on verbose logging for XML extensions it dumps the logs in the same dir as the executable.
Well I tried this...
SELECT DETERMINE-PATH
ASSIGN TO "TEST.TXT"
ORGANIZATION IS BINARY SEQUENTIAL
FILE STATUS IS FILE-IO-STATUS.
FD DETERMINE-PATH.
01 DETERMINE-PATH-DATA PIC 9.
01 WS-FILE PIC X(30).
01 WS-PATH PIC X(256).
OPEN OUTPUT DETERMINE-PATH.
MOVE 7 TO DETERMINE-PATH-DATA.
WRITE DETERMINE-PATH-DATA.
CLOSE DETERMINE-PATH.
CALL "C$GetLastFileName" WS-FILE WS-PATH.
WS-FILE shows "DETERMINE-PATH" where I would expect it to show "TEST.TXT". WS-PATH is blank.
A more careful reading of the documentation indicates that C$GetLastFileName does not have a value to return for path after a CLOSE.
I just read that about 10 seconds before you replied! Doh! Now I have it working. Thanks for your help Tom, this solution will work for me!
I just read that about 10 seconds before you replied! Doh! Now I have it working. Thanks for your help Tom, this solution will work for me!
Already have an account? Login
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.