HOW WRITE AND RUN
A REXX PROGRAM
 
 

  REXX is defined for the AS/400, isn't it? Can anyone point to a good reference for a non-AS/400 programmer who needs to acclimate to a new environment?
FRANK CLARKE: subject AS/400 in comp.lang.rexx 1999/02/05>

In this chapter I will demonstrate how write and run small, simple, maybe useful program. But first you have to create the source database file for texts of programs.

Have a look at the following program DSPLIBF written in the Rexx language for the AS/400 environment. It directs the output from the DSPLIB command into the INFO file in the library MYLIB. The DSPLIB (Display Library) command displays the contents of one or more specified libraries and has syntax:

DSPLIB LIB(library) OUTPUT({*|*PRINT})

The parameter OUTPUT specifies whether the output from the command is shown at the requesting work station (*) or printed with the job's spooled output (*PRINT); * is the default.

/* DSPLIBF */
parse arg Library
do while Library = ""
  say "Please, write the name of library"
  parse linein Library
end
'DSPLIB' Library 'OUTPUT(*PRINT)'
'CHKOBJ MYLIB/INFO *FILE'

if RC <> 0 then 'CRTPF MYLIB/INFO RCDLEN(132)'
'CPYSPLF FILE(QPDSPLIB) TOFILE(MYLIB/INFO) SPLNBR(*LAST)'
if RC = 0 then say 'OK'; else say 'Not OK'

The DSPLIBF program shows how CL commands are issued from a Rexx program. Commands are expressions which are passed to the current command environment. In this article comands (and later SQL statements) in programs are blue coloured. By default, Rexx submits commands to the CL command environment for processing. Words as DSPLIB and CHKOBJ are CL commands. The CHKOBJ (Check Object) command checks object existence; the CRTPF (Create Physical File) command creates a physical file or a table in SQL terminology with the length of rows 132 chars; the CPYSPLF (Copy Spooled File) command copies the specified spooled file, i.e. the last spooled file created by the DSPLIB command with the parameter OUTPUT(*PRINT) in the file INFO.

How do you write and run the DSPLIBF program? If you do not have a source file for texts of programs and library, type the Create Library (CRTLIB) command on an AS/400 command line and press Enter to create a library for your source file. For example:

CRTLIB MYLIB

Note: Ask the system administrator for a name of your library. In this article I will use the name MYLIB.

Type the Create Source Physical File (CRTSRCPF) command to create a source file for Rexx programs

CRTSRCPF FILE(MYLIB/QREXSRC)

Step 1

Now you can create your first program. The WRKMBRPDM FILE(MYLIB/QREXSRC) command shows:


                       Work with Members Using PDM
File  . . . . . .   QREXSRC   
  Library . . . .     MYLIB               Position to  . . . .  Type options, press Enter.
 2=Edit         3=Copy  4=Delete 5=Display       6=Print  8=Display description  9=Save  13=Change text  14=Compile

Opt  Member      Type       Text
  (No members in file)

Press F6, i.e. Create.

Step 2

The following entry display requests you to enter a name of a program (DSPLIBF) and its source type (REXX). You can attach a comment (Output from DSPLIB into the INFO file), too. Then use the Enter key to submit information.


                  Start Source Entry Utility (STRSEU)
Type choices, press Enter.
Source file  . . . . . . . . . . . > QREXSRC       Name, *PRV   Library  . . . . . . . . . . . . >   MYLIB       Name, *LIBL, Source member  . . . . . . . . . .   DSPLIBF       Name, *PRV,  Source type  . . . . . . . . . . .   REXX          Name, *SAME, Text 'description' . . . . . . . .   Output from DSPLIB into the INFO

Step 3

Rewrite the text of the program DSPLIBF. Press the F3 key to end the editing.


Columns . . . :    1   71            Edit
SEU==>                                                           FMT **  ...+... 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+..
       *************** Beginning of data *********************** '''''' /* DSPLIBF */
'''''' 

Step 4

Press the Enter key to confirm the saving of the source text on the Exit display. On the following Work with Members Using PDM display type a 16 in the option field, i.e. Run, and press the F4 key.


                       Work with Members Using PDM
 
File  . . . . . .   QREXSRC   
  Library . . . .     MYLIB               Position to  . . . . 
 Type options, press Enter.
 2=Edit         3=Copy  4=Delete 5=Display       6=Print
 8=Display description  9=Save  13=Change text  14=Compile

Opt  Member      Type       Text
16   DSPLIBF     REXX       Output from DSPLIB into the INFO   

Step 5

Type a name of a library to the parameters field. Press the Enter key for run of the program. Of course, the DSPLIBF program you can run immediately, hence press in previous step instead F4 the Enter key. The program will ask for a name of a library oneself.


                  Start REXX Procedure (STRREXPRC)
Type choices, press Enter.
Source member  . . . . . . . . . > DSPLIBF       Name
Source file  . . . . . . . . . . > QREXSRC       Name
  Library  . . . . . . . . . . . >   MYLIB       Name, *LIBL Parameters . . . . . . . . . . .   MYLIB                    

Note: you can start the DSPLIBF program when you enter the STRREXSRC (Start REXX Procedure) command as well as:

STRREXPRC SRCMBR(DSPLIBF) SRCFILE(MYLIB/QREXSRC) PARM(MYLIB)

The following display shows information about the run of the program


 
 
 
 
 
 
 
Start of terminal session.
OK
Press ENTER to end terminal session.

The DSPPFM (Display Physical File Member) command shows the result on the screen

DSPPFM FILE(MYLIB/INFO)

And there is a fragment of the screen:


                         Display Physical File Member
File . . . . . . :   INFO                Library  . . . . :   MYLIB Member . . . . . :   INFO                Record . . . . . :   1 Control  . . . . .                       Column . . . . . :   1 Find . . . . . . .                                            *...+....1....+....2....+....3....+....4....+....5....+....6....+..  5763SS1 V3R2M0  960517                   Display Library
 Library . . . . . . . . . . . . . :   MYLIB
 Type  . . . . . . . . . . . . . . :   PROD


tour from Rexx to AS/400

 [How write and run Rexx program]

 [Standard Input and Output]

 [External Data Queue]

 [SQL statements]


main page ceska verze

last modified 26th April 2002
Copyright 1998-2002 Vladimir Zabrodsky
Czech Republic