Page 1 of 3

How to insert a new line in a PDS member using REXX..

PostPosted: Wed Jan 08, 2014 12:12 am
by santosh bm
Hii,,

Someone please give me tips to insert new lines inside a PDS member using REXX code.

I have used a cursor to fetch some rows from a table in my REXX code. The requirement is, if my cursor returns four rows, i need to insert those four rows into a PDS member (say in the line numbers 107,108,109 and 110 resp).

Re: How to insert a new line in a PDS member using REXX..

PostPosted: Wed Jan 08, 2014 1:58 am
by Pedro
You did not say how big the member is. If there are many lines, then rexx is not the right tool. Or perhaps, a PDS is not the right kind of data set to store your data.

Since you are inserting new lines, you will have to read the whole thing and then write the whole thing (including the new records). Perhaps the easiest approach to insert new lines:
1. use EXECIO to read in the PDS records into a stem variable.
2. copy the stem to a second stem, while also merging in your new records.
3. use EXECIO to write the second stem to the PDS member.

Re: How to insert a new line in a PDS member using REXX..

PostPosted: Wed Jan 08, 2014 5:14 pm
by santosh bm
The PDS member is being created by the same rexx code. The PDS member has about 140 lines. Why i need to insert those lines is, i'm creating certain forms, which are stored as pds members. I always read a flat file, string manipulate the data and write it to a pds member. My code has a query(cursor), which could fetch a number of rows from the table. I need to insert these lines into that pds member. Please inform me, if you need more information on this.

Re: How to insert a new line in a PDS member using REXX..

PostPosted: Wed Jan 08, 2014 5:19 pm
by NicC
I think Pedro has given you sufficient information to carry on.

Re: How to insert a new line in a PDS member using REXX..

PostPosted: Wed Jan 08, 2014 5:31 pm
by santosh bm
Is there any macro way of doing it ?

Re: How to insert a new line in a PDS member using REXX..

PostPosted: Wed Jan 08, 2014 5:38 pm
by santosh bm
Like ISREDIT or something ?

Re: How to insert a new line in a PDS member using REXX..

PostPosted: Wed Jan 08, 2014 7:25 pm
by Pedro
You can create an editor macro that issues LINE_AFTER statements. I think it is easier to start at the bottom and work your way up; because as you insert lines, the line numbers below it change.

Re: How to insert a new line in a PDS member using REXX..

PostPosted: Wed Jan 08, 2014 8:15 pm
by santosh bm
I'm facing two problems with the macro.
1] i'm not able to pass the data from rexx code to macro. i.e., the data i fetch from the query is not being passed on to the macro.
2] The pds member is getting opened in the edit mode, instead of getting closed after the edit process.

Macro is as below :
ADDRESS ISREDIT "MACRO (STRING)"                   
address ISREDIT "scan off"
if rc > 0 then exit 
address  ISREDIT "LINE_AFTER" 106 "=" (GDGNAME2) 
"end"                                             
"exit"

where GDGNAME2 is the variable in the rexx code which contains some data, i want to insert in the pds member.

Re: How to insert a new line in a PDS member using REXX..

PostPosted: Wed Jan 08, 2014 8:36 pm
by Steve Coalbran
The title is not the question.
This is the answer to the question of CHANGING 4 lines in a member (VERY OVER-SIMPLIFIED!)
;)

If you are running an EditMacro on the PDS member in question you could do this:
Outside process
:
/* get field values  into vnnn vars below */
ADDRESS DSNREXX stuff?
...
QUEUE v107
QUEUE v108
QUEUE v109
QUEUE v110
ADDRESS ISPEXEC "EDIT DATASET('"libname"') MEMBER("member") MACRO(ADD4FLDS) "
...


where EditMacro (ADD4FLDS) says something like...
ADDRESS ISPEXEC "CONTROL ERRORS RETURN "
ADDRESS ISREDIT
"MACRO NOPROCESS "
PARSE PULL v107
PARSE PULL v108
PARSE PULL v109
PARSE PULL v110
"LINE 107 = (V107) "
"LINE 107 = (V108) "
"LINE 107 = (V109) "
"LINE 107 = (V110) "
"END "

but this is a VERY simplified example! No variables. Just add logic!?!
Untested too, no intranet connection here today!
As has been said before on many posts... "SUPPLY YOUR CURRENT CODE" ...however embarrassing it may be.
We all started somewhere?! However long ago ahem! that may have been!?

If you are doing this for a whole PDS in the outside process then you need to use LM services around the EDITs on the members. Use DATAID instead of DATASET on the EDIT line etc.
Use MODEL with LMINIT, LMOPEN, LMMLIST, LMCLOSE, or failing all else RTFM ...
    SC34-4819 z/OS V1R13.0 ISPF Services Guide
    SC34-4820 z/OS V1R13.0 ISPF Edit and Edit Macros
I think I coded something like this about 10 years ago at some Customer's requirement.
Good luck.

Re: How to insert a new line in a PDS member using REXX..

PostPosted: Wed Jan 08, 2014 11:47 pm
by Pedro
2] The pds member is getting opened in the edit mode, instead of getting closed after the edit process.

You need to issue the END macro statement. You try to in your example, but you are missing the Address ISREDIT and instead of editor END, it tries to issue TSO END (likely resulting in 'command not found')

ADDRESS ISREDIT "MACRO (STRING)"                   
address ISREDIT "scan off"
if rc > 0 then exit
address  ISREDIT "LINE_AFTER" 106 "=" (GDGNAME2)
address  ISREDIT  "END"                                             


I do not think "EXIT" is needed.

Steve recommended QUEUE with PARSE PULL. I suggest that you use NEWSTACK and DELSTACK also. Actually, I recommend VPUT SHARED and VGET SHARED instead of using the stack. It just seems cleaner to me.