2

I have this Rexx program which I want to write the output to a particular dataset. However I can't get to print the exact output produced on the terminal to the dataset.

/* REXX */
"FREE FI(outdd)"
"ALLOC FI(outdd) DA('Z01510.OUTPUT(SAMPLCBL)') SHR REUSE" 
row = 0
hline = '      *-----------------------'
mline.0 = '       IDENTIFICATION DIVISION.'
mline.1 = '      *'
mline.2 = '       PROGRAM-ID. '
mline.3 = '      *'
mline.4 = '      *'
mline.5 = '      * Description :'
mline.6 = '      *'
mline.7 = '      * Created on : 'date()
mline.8 = '      * Created by : '
mline.9 = '      *            : Userid('')'
mline.10 = '      *            : Using' '()'
mline.11 = '      *'
mline.12 = '      * Called by :'
mline.13 = '      *'
mline.14 = '      * Calls :'
mline.15 = '      * Change Activity :'
mline.16 = '      *             ©Copyright of -----.'
mline.17 = '       ENVIRONMENT DIVISION.'
mline.18 = '       INPUT-OUTPUT SECTION.'
mline.19 = '       DATA DIVISION.'
mline.20 = '       WORKING-STORAGE SECTION.'
mline.21 = '       LINKAGE SECTION.'
mline.22 = '       PROCEDURE DIVISION.'
mline.23 = '       A-MAIN SECTION.'
mline.24 = '           STOP RUN.'

mline.25 = '      *           End of '
say hline
say mline.0
say hline
say mline.2
say hline
do i = 4 to 16
    say mline.i
end
say hline
do i=17 to 24
    say mline.i
    say hline
end
say mline.25
"EXECIO * DISKW outdd (STEM mline."
"EXECIO 0 DISKW outdd (FINIS"
"FREE FI(outdd)" 
exit

I run the Rexx script on the z/OS terminal and I get the following sample output which I want copied to the dataset in the exact same way.

    *-----------------------
       IDENTIFICATION DIVISION.
      *-----------------------
       PROGRAM-ID.
      *-----------------------
      *
      * Description :
      *
      * Created on : 14 Oct 2020
      * Created by :
      *            : Userid(')
      *            : Using ()
      *
      * Called by :
      *
      * Calls :
      * Change Activity :
      *             ©Copyright of -----.
      *-----------------------
       ENVIRONMENT DIVISION.
      *-----------------------
       INPUT-OUTPUT SECTION.
      *-----------------------
       DATA DIVISION.
      *-----------------------
       WORKING-STORAGE SECTION.
      *-----------------------
       LINKAGE SECTION.
      *-----------------------
       PROCEDURE DIVISION.
      *-----------------------
       A-MAIN SECTION.
      *-----------------------
           STOP RUN.
      *-----------------------
      *           End of
Fnechz
  • 151
  • 8
  • 1
    You have answer, but here's a coding tip : if yuo think you want to change between SAY statements and QUEUE statements, create an `output` subroutine to which you pass a string to be output. In the `output` subroutine, SAY, QUEUE or assign the passed string to the next member of a stem variable. Then changing between output methods is quick and easy. – Steve Ives Oct 15 '20 at 07:40
  • That is insightful, thanks – Fnechz Oct 15 '20 at 11:35

4 Answers4

4

You should not store data in mline.0 but the count of stem tails (mline.1 mline,2 etc) and pass this to EXECIO as the number of records to write. Using mline.0 is not wrong but 'normal' practice is to use it as a count - same as EXECIO does when it reads into a stem. If you want your hline to be written then you need to add it to the mline stem first at the appropriate places.

NicC
  • 293
  • 1
  • 6
  • And indeed, this is the core of the problem. `EXECIO * DISKW outdd (STEM mline.` isn't going to write anything if `mline.0` isn't the number of lines in `mline.`. – Ross Patterson Oct 19 '20 at 14:25
2

At least, you should not use mline.0. EXECIO DISKW will start writing from mline.1, index 0 is ignored.

Except this problem, I do not see any output error except if you want hline variable in the output file. In this case, just insert mline indices at the right place with the content of hline.

If this is not your problem, please, describe more precisely what do you mean by "I can't get to print the exact output"

Stephane34
  • 31
  • 2
  • I want the hline variable to appear on each division as typed above. How do I get the hline printed methodically as I gave on my sample terminal output. – Fnechz Oct 14 '20 at 20:19
2

I edited my previous answer so it does what you want. Here is the adjusted answer:

/* REXX */
queue '      *-----------------------'
queue '       IDENTIFICATION DIVISION.'
queue '      *-----------------------'
queue '       PROGRAM-ID. '
queue '      *-----------------------'
queue '      *'
queue '      *'
queue '      * Description :'
queue '      *'
queue '      * Created on : 'date()
queue '      * Created by : '
queue '      *            : Userid('')'
queue '      *            : Using' '()'
queue '      *'
queue '      * Called by :'
queue '      *'
queue '      * Calls :'
queue '      * Change Activity :'
queue '      *             ©Copyright of -----.'
queue '      *-----------------------'
queue '       ENVIRONMENT DIVISION.'
queue '      *-----------------------'
queue '       INPUT-OUTPUT SECTION.'
queue '      *-----------------------'
queue '       DATA DIVISION.'
queue '      *-----------------------'
queue '       WORKING-STORAGE SECTION.'
queue '      *-----------------------'
queue '       LINKAGE SECTION.'
queue '      *-----------------------'
queue '       PROCEDURE DIVISION.'
queue '      *-----------------------'
queue '       A-MAIN SECTION.'
queue '      *-----------------------'
queue '           STOP RUN.'
queue '      *-----------------------'
queue '      *           End of '
queue '      *-----------------------'

do i = 1 to queued()
    parse pull line
    say line
    mline.i = line
end

rc = BPXWDYN( 'alloc fi(outdd) da(''Z01510.OUTPUT(SAMPLCBL)'') shr reuse' )
address 'MVS' 'EXECIO * DISKW' outdd '(finis stem mline.'
rc = BPXWDYN( 'free fi(outdd)' )
exit rc
Milos Lalovic
  • 554
  • 3
  • 10
  • I want the output in the dataset to appear as I typed above, with the horizontal lines(hline variable) printed methodically as the command line terminal output I gave above – Fnechz Oct 14 '20 at 20:17
2

There's a few ways to achieve what you're looking for, but the easiest way would likely be to:

  1. Replace each say with QUEUE to place the lines on the stack
  2. Change EXECIO to accommodate writing out the stack
  3. Clear the stack with DELSTACK

So, your script would look like this:

/* REXX */                                                                      
"FREE FI(outdd)"                                                                
"ALLOC FI(outdd) DA('Z01510.OUTPUT(SAMPLCBL)') SHR REUSE"               
row = 0                                                                         
hline = '      *-----------------------'                                        
mline.0 = '       IDENTIFICATION DIVISION.'                                     
mline.1 = '      *'                                                             
mline.2 = '       PROGRAM-ID. '                                                 
mline.3 = '      *'                                                             
mline.4 = '      *'                                                             
mline.5 = '      * Description :'                                               
mline.6 = '      *'                                                             
mline.7 = '      * Created on : 'date()                                         
mline.8 = '      * Created by : '                                               
mline.9 = '      *            : Userid('')'                                     
mline.10 = '      *            : Using' '()'                                    
mline.11 = '      *'                                                            
mline.12 = '      * Called by :'                                                
mline.13 = '      *'                                                            
mline.14 = '      * Calls :'                                                    
mline.15 = '      * Change Activity :'                                          
mline.16 = '      *             Copyright of -----.'                            
mline.17 = '       ENVIRONMENT DIVISION.'                                       
mline.18 = '       INPUT-OUTPUT SECTION.'                                       
mline.19 = '       DATA DIVISION.'                                              
mline.20 = '       WORKING-STORAGE SECTION.'                                    
mline.21 = '       LINKAGE SECTION.'                                            
mline.22 = '       PROCEDURE DIVISION.'                                         
mline.23 = '       A-MAIN SECTION.'                                             
mline.24 = '           STOP RUN.'                                               
                                                                                
mline.25 = '      *           End of '                                          
QUEUE hline                                                                     
QUEUE mline.0                                                                   
QUEUE hline                                                                     
QUEUE mline.2                                                                   
QUEUE hline                                                                     
do i = 4 to 16                                                                  
    QUEUE mline.i                                                               
end                                                                             
QUEUE hline                                                                     
do i=17 to 24                                                                   
    QUEUE mline.i                                                               
    QUEUE hline                                                                 
end                                                                             
QUEUE mline.25                                                                  
"Execio "Queued()" DISKW outdd (FINIS"                                          
"FREE FI(outdd)"                                                                
"DELSTACK"                                                                      
exit
Rich Jackson
  • 301
  • 1
  • 5
  • Your edit works as expected, though I get this infor after running the script on the terminal: `FILE OUTDD NOT FREED, IS NOT ALLOCATED` – Fnechz Oct 14 '20 at 23:18
  • 1
    @Fnechz - That message is coming from that first `FREE FI(outdd)` statement, because the dataset is not allocated yet. You could remove that statement. – Rich Jackson Oct 14 '20 at 23:50