Using the Program Stack to Pass Data Between Programs

The following example describes one way of how you can use the program stack. CMSHELLO EXEC first asks for your first name, last name, and the language of your source program. Then CMSHELLO EXEC places your first name and last name on the program stack. Then, depending on the language of your source program, CMSHELLO EXEC places the name of the source program on the program stack and calls the corresponding compiler exec to compile, load, and execute a source program.

Suppose, in our example, the source program is a FORTRAN program. Therefore, CMSHELLO EXEC identifies HELLO FORTRAN as the source program and calls the compiler exec called COMPFORT EXEC. COMPFORT EXEC compiles, loads, and executes the HELLO FORTRAN program. The HELLO FORTRAN program welcomes you to CMS by displaying a message.

You do not have to respond to program prompts in the source program because the HELLO FORTRAN reads the lines stacked in CMSHELLO EXEC. By using CMSHELLO EXEC, you do not have to know the name of the source program that welcomes you to CMS or the commands needed to compile, load, and execute the source program.

CMSHELLO contains the following:
/* This is a setup exec to determine what source file
   will be used to welcome you to CMS.                */
say 'What is your first name?'
pull firstname
say 'What is your last name?'
pull lastname
say 'What language are you using:  FORTRAN, COBOL, PL/I, or C?'
pull lang
/* Putting your last name and first name on the stack. */
push lastname
push firstname
/* Determining what language you are using, placing the name of the
   corresponding source file on the stack, and invoking the
   correct compiler exec.                                            */
select
  when lang='FORTRAN' then do
    push 'HELLO'
    'EXEC COMPFORT'
    end
  when lang='COBOL' then do
    push 'HELLO'
    'EXEC COMPCOB'
    end
  when lang='PL/I' then do
    push 'HELLO'
    'EXEC COMPPLI'
    end
  when lang='C' then do
    push 'HELLO'
    'EXEC COMPC'
    end
  otherwise
    say 'No language was specified.  Your program has ended!'
end
'DROPBUF'
exit
COMPFORT EXEC contains the following:
/* the executor language version of COMPILE EXEC */
'SET CMSTYPE HT'
Mainpart:
    signal on error
    pull pname
    'FORTVS2' pname
    if rc¬=0
      then signal on error
      else do
        'SET CMSTYPE RT'
        'GLOBAL TXTLIB VSF2FORT CMSLIB'
        'GLOBAL LOADLIB VSF2LOAD'
        'LOAD' pname
        'GENMOD' pname
        pname
        end
    exit
    Error:
    rcsave = rc
    'SET CMSTYPE RT'
    say "Unexpected return code" rcsave "from command at line number "sigl":"
    say "     " sourceline(sigl)
    exit
To invoke this exec, enter:
cmshello
Once you answer the prompts, the following appears on the screen:
What is you first name?
John
What is your last name?
Doe
What language are you using: FORTRAN, COBOL, PL/I, or C?
FORTRAN
Welcome to CMS, John     Doe