Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way using REXX to edit a ps dataset and insert a string after a particular line?

Tags:

mainframe

rexx

I am writing a REXX program which will update a PS dataset. I can edit a particular line using my REXX code. But I would want a code to insert a particular string after a particular line.
For Example: My PS dataset has 100 lines. I want to insert a text "ABCDE" after 44th line (in 45th line) which will increase the total lines of the file to 101 lines. The remaining lines should remain unchanged. Is this possible using REXX?

like image 291
Sudarsan Rajagopalan Avatar asked Dec 24 '22 02:12

Sudarsan Rajagopalan


2 Answers

Independent of REXX you need to effectively read the old dataset and write it out to a new file and add your new record (string) to the output file and then write the rest. There is no way to “insert” a record in a Physical Sequential (PS) dataset. At the end you would delete the old and rename the newly created file to the old name.

Another option would be to use a generation dataset group (GDG) and read the current (0) and create the new (+1) as the output. This way you still are referring to the same dataset name for others to reference.

like image 136
Hogstrom Avatar answered May 11 '23 05:05

Hogstrom


What @Hogstrom suggests is a good solution to the problem you describe. In the interest of completeness, here is a solution that may be necessary under extreme circumstances.

Create an edit macro...

/*REXX*/
ADDRESS ISREDIT 'MACRO NOPROCESS'
aLine = 'ABCDE'
ADDRESS ISREDIT 'LINE_AFTER 44 = DATALINE (ALINE)'

...and run ISPF edit in batch, executing this macro.

The JCL to run ISPF in batch is shop-specific, but many shops have created a cataloged procedure to do so.

If you are willing to copy your dataset to the z/Unix file system, you could also use sed or awk to make your changes.

I'm not recommending any of this, I'm just pointing out it can be done if @Hogstrom's solution won't work for you for some reason.

like image 31
cschneid Avatar answered May 11 '23 05:05

cschneid