I have been trying to create a Main program that calls another program, sending it two variables. The called program then is supposed to open an output file and print the passed variables to output file, then return control to Main program.
I have created the Main program and the Sub-Program. They both compile without errors. The sub program works as stand alone program, but when I run Main program, the program branches to sub program and then fails when it tries to open the Output file.
The code is as follows. Any input on what I have done wrong would be greatly appreciated. Thank you.
CALLING PROGRAM:
MAIN START 0
PRINT NOGEN SUPPRESS GENERATED INSTRUCTIONS
STM 14,12,12(13)
BALR 12,0
USING *,12
MVC MONTH1,=C'March'
MVC MONTH2,=C'June'
LA 9,=A(MONTH1,MONTH2) Parameters to pass stored in R9
SR 1,1
LOAD EP='SEARCH.COM'
ST 13,SAVMAIN+4
LA 13,SAVMAIN
LR 15,0
BALR 14,15
WTO 'Subprogram was successful in finding data passed'
RETURNPT WTO 'AND IT RETURNED'
RETURN
MONTH1 DS CL12
MONTH2 DS CL12
DS 0F
SAVMAIN DS 18F
END MAIN
CALLED PROGRAM:
SEARCH START 0
REGS
PRINT NOGEN SUPPRESS GENERATED INSTRUCTIONS
STM R14,R12,12(R13)
BALR R12,R0
USING *,R12 Set base register to R12
ST R13,SAVE+4
LA R13,SAVE
WTO 'SUB PROGRAM REACHED'
********
* Or Immediate files for reading and writing. Needed only on PC/370
********
OI OUTPUT+10,X'08'
WTO 'OI PROCESSED'
********
* Open all files needed for programming assignment
********
OPEN OUTPUT
WTO 'OUTPUT FILE OPENED'
*
*********************************************************
*** MAIN CODE ***
*********************************************************
*
L R8,0(R0,R9)
MVC FIND1,0(R8)
L R8,4(R0,R9)
MVC FIND2,0(R8)
WTO FIND1
WTO FIND2
MVC CTEMP,FIND1
MVC OWORD,=C'WORD 1:'
PUT OUTPUT,OREC
MVC CTEMP,FIND2
MVC OWORD,=C'WORD 2:'
PUT OUTPUT,OREC
*
*********************************************************
*** EOJ PROCESSING ***
*********************************************************
*
********
* Close all files needed for programming assignment
********
*
ATEND EQU *
CLOSE OUTPUT
WTO 'Subprogram was successful in printing passed data'
*********************************************************
*** END PROGRAM ***
*********************************************************
*
EXIT EQU *
RETURN
LTORG
*********************************************************
**** FILE DEFINITIONS ***
*********************************************************
OUTPUT DCB LRECL=29,RECFM=F,MACRF=P,DDNAME='MAINOUT.TXT'
OREC DS 0CL29
OWORD DS CL12
DC CL3' '
ORESULT DS CL12
DC X'0D25'
FIND1 DS CL12
FIND2 DS CL12
CTEMP DS CL12
DS 0F
SAVE DS 18F
END SEARCH
I realized that this question has remained unanswered. I finally figured out how to correctly perform Assembly program linkage in PC-370.
The output is commented, for the most part. I give this code in hopes of helping another student deal with this concept.
If someone comes across this and finds an error in the logic, please PM me and I will fix it.
I hope this helps those in need.
SUBCAN
This is the MAIN.MLC program that calls the SUBPRG.MLC program.
This is the called program, SUBPRG.MLC