Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Recreating TSO REXX program using REXX400

Status
Not open for further replies.

Ju5

Programmer
May 25, 2007
85
PH
Hi,


I've been asked to recreate a TSO REXX program in the AS400. I'm not too good with TSO commands so I don't know the AS400 commands that I need to use. I know not everything in TSO REXX applies to REXX400 like OUTTRAP.

I wanted to start slow and made a program that will check if the compiled object exists and display a message if there are any errors but I'm only seeing the "End of Terminal Session mesage" and not any error messages I coded. Below is the code I'm running.

/* REXX */
Arg progname

"CHKOBJ OBJ(mylib/"PROGNAME") OBJTYPE(*PGM)"
"MONMSG MSGID(CPF9801) EXEC(SNDPGMMSG MSG('NOT FOUND'))"
"MONMSG MSGID(CPF9810) EXEC(SNDPGMMSG MSG('MISSING'))"
***************************
mylib is the hardcoded library.

What am I doing wrong?
 
Check the special register RC for specified message produced by CHKOBJ command - see this example:
objexist.rexx
Code:
[COLOR=#0000ff]/************ main *****************/[/color]
[COLOR=#0000ff]/* Check if OBJ exists */[/color]

[COLOR=#0000ff]/* existing program   */[/color]
[COLOR=#804040][b]call [/b][/color][COLOR=#008080]check_pgm[/color] [COLOR=#ff00ff]'IBPDPGM'[/color][COLOR=#804040][b],[/b][/color] [COLOR=#ff00ff]'OZNDRXML'[/color]
[COLOR=#0000ff]/* noexisting program */[/color]
[COLOR=#804040][b]call [/b][/color][COLOR=#008080]check_pgm[/color] [COLOR=#ff00ff]'IBPDPGM'[/color][COLOR=#804040][b],[/b][/color] [COLOR=#ff00ff]'NOEXPGM'[/color]
[COLOR=#804040][b]exit[/b][/color]

[COLOR=#0000ff]/**********  functions *************/[/color]
[COLOR=#008080]check_pgm[/color][COLOR=#804040][b]:[/b][/color] [COLOR=#804040][b]procedure[/b][/color]
  [COLOR=#804040][b]parse arg[/b][/color] my_lib[COLOR=#804040][b],[/b][/color] my_pgm

  my_lib_pgm [COLOR=#804040][b]=[/b][/color] my_lib[COLOR=#804040][b]||[/b][/color][COLOR=#ff00ff]'/'[/color][COLOR=#804040][b]||[/b][/color]my_pgm
  [COLOR=#6a5acd]RC[/color] [COLOR=#804040][b]=[/b][/color] 0

  my_cmd [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]'CHKOBJ OBJ('[/color][COLOR=#804040][b]||[/b][/color]my_lib_pgm[COLOR=#804040][b]||[/b][/color][COLOR=#ff00ff]') OBJTYPE(*PGM)'[/color]
  [COLOR=#804040][b]address[/b][/color] [COLOR=#ff00ff]'COMMAND'[/color] my_cmd
  [COLOR=#804040][b]say[/b][/color] [COLOR=#ff00ff]"CHKOBJ-RC = '"[/color] [COLOR=#804040][b]||[/b][/color] [COLOR=#6a5acd]RC[/color] [COLOR=#804040][b]||[/b][/color] [COLOR=#ff00ff]"'"[/color]

  [COLOR=#804040][b]if[/b][/color] [COLOR=#6a5acd]RC[/color] [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]'CPF9801'[/color] [COLOR=#804040][b]then[/b][/color]
    [COLOR=#0000ff]/* if OBJ not exists */[/color]
    [COLOR=#804040][b]say[/b][/color] [COLOR=#ff00ff]'The program '[/color] my_lib_pgm [COLOR=#ff00ff]'does not exist!'[/color]
  [COLOR=#804040][b]else[/b][/color]
    [COLOR=#804040][b]say[/b][/color] [COLOR=#ff00ff]'OK, the program '[/color] my_lib_pgm [COLOR=#ff00ff]'exist'[/color]
  [COLOR=#0000ff]/* if-else */[/color]
  [COLOR=#804040][b]return[/b][/color]
Running the REXX procedure above with
Code:
STRREXPRC SRCMBR(OBJEXIST)
gives
Code:
   CHKOBJ-RC = '0'                             
   OK, the program  IBPDPGM/OZNDRXML exist     
   CHKOBJ-RC = 'CPF9801'                       
   The program  IBPDPGM/NOEXPGM does not exist!
   Press ENTER to end terminal session.
 
Thanks for the reply. Are there any AS400 equivalents for the TSO external functions(OUTTRAP, SYSDSN, GETMSG, etc)?
 
You might talk with the as400 system support people - hopefully, they would know.
 
Ju5 said:
Are there any AS400 equivalents for the TSO external functions(OUTTRAP, SYSDSN, GETMSG, etc)?
Because there isn't TSO on iSeries, there isn't 1:1 equivalent for these functions.
IMHO, the philosophy doing things on iSeries differs a little bit from zSeries. I don't have experience with TSO REXX, but I googled what the functions you mentioned should do - and here are my suggestions:

* OUTTRAP seems to store command results in REXX variable.
On iSeries I would try to get the command result in a temporary file and then process this file with REXX. Most of the build-in iSeries commands have the option OUTFILE for specifying "File to receive output"

* SYSDSN
You can check with CHKOBJ if the file exists and other file attributes with DSPFD command

* GETMSG
After the command execution you will get the MsgId in the special REXX variable RC - see the example I posted above.
 
I got it to work! Thanks for the help.


Is there a way to append to the last line of a file? Below is my REXX program. I want AUTHOR comments to be written on a new line/appended to the end of file everytime I run the program instead of overwriting the first line.



Parse Arg lib
TotLines=0
'RTVMBRD FILE('lib'/temp) NBRCURRCD(&TotLines)'

'OVRDBF FILE(STDIN) TOFILE('lib'/temp)'
'OVRDBF FILE(STDOUT) TOFILE('lib'/chkrpt)'
Do TotLines
/* Pull SrcCode */
Parse Linein SrcCode . Author
If Pos("AUTHOR.",SrcCode) > 0
Then Do
If Author > ' '
Then Say "AUTHOR statement found."
Else
Say "AUTHOR does not exist."
End
End
Exit


 
Use in your code
Code:
'OVRDBF FILE(STDOUT) TOFILE('lib'/chkrpt) [COLOR=red]POSITION(*END)[/color]'
 
I added teh POSITION parameter but it seems to overwrite the contents of the file instead of appending.
 
I took a look at the joblog and found this message:
Position open ignored for member chkrpt.

Pressed F1 and found this:

Message ID . . . . . . : CPF4016 Severity . . . . . . . : 10
Message type . . . . . : Diagnostic
Date sent . . . . . . : 03/21/11 Time sent . . . . . . : 08:14:15

Message . . . . : Position open option ignored for member CHKRPT.
Cause . . . . . : The position open option specified for member CHKRPT
file CHKRPT in LIMJD was ignored because of one of the following reasons:
-- The file was opened for output only.
-- The file does not allow the input operation.
Recovery . . . : Either do not specify the position open option, or open
the file for input and output. Then try your request again.


Below is the OVRDBF command I am currently using:
'OVRDBF FILE(STDOUT) TOFILE('lib'/stdchkrpt) POSITION(*END)'

I looked up the parameters for OVRDBF and couldn't find one that forces it to open a file for update.
 
Just for reference, I'm working in a v3r2. We're rtying to get a 6.1 but until then I have 3.2.
 
I have V5R4. V3R2 could be a decade or so old...

Have you tried to do it with another file too?
If not, then try the same with another file in QTEMP or your library, for example
'OVRDBF FILE(STDOUT) TOFILE(QTEMP/MYFILE) POSITION(*END)'
and look if it works or not.
 
Still not working. Were you able to get the following code to work for you?

Parse Arg lib
TotLines=0
'RTVMBRD FILE('lib'/temp) NBRCURRCD(&TotLines)'

'OVRDBF FILE(STDIN) TOFILE('lib'/temp)'
'OVRDBF FILE(STDOUT) TOFILE('lib'/chkrpt) POSITION(*END)'
Do TotLines
/* Pull SrcCode */
Parse Linein SrcCode . Author
If Pos("AUTHOR.",SrcCode) > 0
Then Do
If Author > ' '
Then Say "AUTHOR statement found."
Else
Say "AUTHOR does not exist."
End
End
Exit

Reading on the description of the POSITION parameter it says the POSITION is for where to start reading.

I think since I already have STDIN STDOUT is automatically a Output only file and can't be read.


Do you think it would be better if I just write to a file for each program then merge them all together using CPYF later?
 
I would suggest you do what you need to get it working NOW, and worry about getting closer to the original design after.


Nic
 
Is there any faster way to move records from a file to a stem other than using a DO loop?

TSO REXX has "EXECIO * DISKR file(STEM. FINIS)", I know it's specific to Mainframe but using a DO loop takes too long.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top