Saturday, August 13, 2016

Reading and Writing files in REXX

In order to read or write a file using REXX, first step is to allocate a DDNAME. This step is required only when REXX is executed through Foreground mode. We can also execute REXX through background mode using JCL. In background mode, we aren't required to allocated DDNAME. It is auto allocated by the system.

Reading a file in REXX:

Step 1: Allocate ddname to the input file
"ALLOC FI(INDD) DA('"PDSNAME"("MEMNAME")') SHR "               

Step2: Read all records from the file and store in the stem variable Line.

The command * indicates all records, if you wish to read only one record, you can say 1 instead of * and make it in a loop.

"EXECIO * DISKR INDD (STEM LINE. FINIS"                                
Step3: Processing --- loop to process all records
DO I=1 TO LINE.0                                                
   CALL PROCESSING                                                
END                             
                                   
Step 4: This step deallocates the ddname.
"FREE FI(INDD)"                                             


Writing a file in REXX:

Writing file is similar to reading. Only difference is DISKW command is used instead of DISKR. 

Step 1: Allocate DDNAME to the output file
"ALLOC FI(OUTPUT) DA('"OUTPDS"("MEMBER")') SHR "

Step 2: Write the stem into the output file 
"EXECIO * DISKW OUTPUT (STEM WRITEDA. FINIS"    

Step 3: Deallocate the DDNAME
"FREE FI(OUTPUT)"                               


2 comments:

  1. Nevernevernever "EXECIO * DISKW".

    There is ALWAYS enough information available such that the "*" can be replaced by a real value, whether it be 'stem.0' or 'queued()' or something else.

    ReplyDelete
    Replies
    1. Ofcourse, it can be. But "*" can be very well used without any issues. When working with the same stem variable, it is necessary to drop the stem variable before using for the next time.

      Delete

Featured Post

REXX Skeleton: Submitting jobs through Rexx

Submitting jobs through REXX and reading the spool through REXX gives us immense potential to automate many manual activities in mainframes....