Hi All,
I need to insert a line(Say: "New Message here") after specific line (Say: "After this line") in a PS File(Say: "APP.D1111.FILE") using REXX
For Eg:
Contents of APP.D1111.FILE
First Line
After this line
Second Line
Third Line
After this line
Fourth Line
Output Needed:
First Line
After this line
New Message here
Second Line
Third Line
After this line
New Message here
Fourth Line
Thanks for help in Advance
~Anshul
Insert a line in PS File after some specific Keyword: REXX
-
- Posts: 2
- Joined: Wed Aug 07, 2019 7:48 am
- Skillset: SAS, PL/1, JCL
- Referer: Google
-
- Posts: 474
- Joined: Thu Mar 10, 2016 5:03 pm
- Skillset: assembler rexx zOS ispf racf smf
- Referer: saw it in the experts foprum thought I could help here
Re: Insert a line in PS File after some specific Keyword: RE
something like:
If you need to allocate and free the dataset then I suggest that you look at the BPXWDYN command (preferred) or the ALLOC / FREE command set.
Code: Select all
"execio * diskr ddname (finis)" /* stack the dataset contents */
qn=queued()
do qn /* process stacked data */
parse pull r
queue r
if pos('whatever you are looking for',r)>0 then queue ' inserted data'
end
"execio" queued() "diskw ddname (finis)" /* rewrite dataset */
If you need to allocate and free the dataset then I suggest that you look at the BPXWDYN command (preferred) or the ALLOC / FREE command set.
-
- Posts: 2
- Joined: Wed Aug 07, 2019 7:48 am
- Skillset: SAS, PL/1, JCL
- Referer: Google
Re: Insert a line in PS File after some specific Keyword: RE
Thanks a Lot Willy, it worked. I submitted the program three times as it was erroring out due to free command. Now i see three 'Inserted data' lines are inserted. Is this because it got queued 3 times? How can we clear the queued() if this is the case.
-
- Posts: 474
- Joined: Thu Mar 10, 2016 5:03 pm
- Skillset: assembler rexx zOS ispf racf smf
- Referer: saw it in the experts foprum thought I could help here
Re: Insert a line in PS File after some specific Keyword: RE
If you run it 3 times,then of course you will get 3 inserts as you haven't removed the trigger line.
But you raise a good point, which I should have mentioned.
I find it advisable to always delete the stack at the top of my program (command "delstack") if I know that I are going to create a stack. This prevents processing some leftover stack entries. Or you can use the "NEWSTACK" command at the top with a "DELSTACK" at the end. I suggest that you read up on stacks in the manual.
But you raise a good point, which I should have mentioned.
I find it advisable to always delete the stack at the top of my program (command "delstack") if I know that I are going to create a stack. This prevents processing some leftover stack entries. Or you can use the "NEWSTACK" command at the top with a "DELSTACK" at the end. I suggest that you read up on stacks in the manual.
- sergeyken
- Posts: 458
- Joined: Wed Jul 24, 2019 10:12 pm
- Skillset: Assembler, JCL, Utilities, PL/I, C/C++, DB2, SQL, REXX, COBOL, etc. etc. etc.
- Referer: Internet search
Re: Insert a line in PS File after some specific Keyword: RE
willy jensen wrote:I find it advisable to always delete the stack at the top of my program (command "delstack") if I know that I are going to create a stack. This prevents processing some leftover stack entries. Or you can use the "NEWSTACK" command at the top with a "DELSTACK" at the end. I suggest that you read up on stacks in the manual.
Using "DELSTACK" at the beginning is not very good idea: we could accidentally eliminate some data created by the "outer" program for its own purpose.
Correct and robust way is #2 mentioned: enclose your own code supposed to use the stack in the pair of commands: "NEWSTACK"-----"DELSTACK"
It can be considered as "creation of the private stack", without disturbing possible other code outside of your program, which is using the stack too.
Javas and Pythons come and go, but JCL and SORT stay forever.
-
- Posts: 474
- Joined: Thu Mar 10, 2016 5:03 pm
- Skillset: assembler rexx zOS ispf racf smf
- Referer: saw it in the experts foprum thought I could help here
Re: Insert a line in PS File after some specific Keyword: RE
Well, if your pgm issues the "newstack" and then terminates prematurely before doing "delstack", then any 'outside' pgm will work with your newly created stack, though the "qstack" command might help there. All I'm saying is be carefull. Personally I try to avoid using stacks, but a a stack did make sense in this particular case.
- sergeyken
- Posts: 458
- Joined: Wed Jul 24, 2019 10:12 pm
- Skillset: Assembler, JCL, Utilities, PL/I, C/C++, DB2, SQL, REXX, COBOL, etc. etc. etc.
- Referer: Internet search
Re: Insert a line in PS File after some specific Keyword: RE
willy jensen wrote:Well, if your pgm issues the "newstack" and then terminates prematurely before doing "delstack", then any 'outside' pgm will work with your newly created stack,
This may happen only in two cases:
- 1) the program has been wrongly designed, and may EXIT in the middle of its code (the same effect as GOTO within spaghetti-code). -- Need to be re-designed.
- 2) the program failed abnormally. -- If so it doesn't matter too much if the stack is empty, or not; it is disaster to be investigated anyway.
Using "NEWSTACK"---"DELSTACK" prevents unexpected results during normal run; in general we don't know what the calling program is doing outside of the scope of this specific part of code.
Javas and Pythons come and go, but JCL and SORT stay forever.
-
- Similar Topics
- Replies
- Views
- Last post
-
-
REXX to Edit 3rd Line of all members in PDS
by shiitiizz » Thu Aug 13, 2020 5:21 pm » in CLIST & REXX - 3
- 3721
-
by Pedro
View the latest post
Fri Aug 14, 2020 3:50 am
-
-
-
Insert Delimiters In File Using SYNCSORT
by Mobius » Wed Sep 07, 2022 10:48 pm » in DFSORT/ICETOOL/ICEGENER - 2
- 2097
-
by Mobius
View the latest post
Thu Sep 08, 2022 7:19 pm
-
-
-
Process file/records until a specific total is reached.
by chillmo » Thu Mar 24, 2022 6:18 am » in Syncsort/Synctool - 12
- 3789
-
by sergeyken
View the latest post
Wed Mar 30, 2022 10:12 pm
-
-
-
FORMAT THE FILE SO ALL CHILD UNDER SAME PARENT IN ONE LINE
by azhar » Wed May 31, 2023 4:27 pm » in JCL - 1
- 1752
-
by sergeyken
View the latest post
Thu Jun 01, 2023 3:06 am
-
-
-
Need to check whether file is ESDS file or not by using REXX
by Devrana » Sat Oct 05, 2024 2:28 pm » in CLIST & REXX - 6
- 3114
-
by sergeyken
View the latest post
Tue Oct 08, 2024 5:25 pm
-