View previous topic :: View next topic
|
Author |
Message |
kbrahma
New User
Joined: 08 Oct 2007 Posts: 38 Location: Delhi
|
|
|
|
Good Day Everyone,
I have coded 2 different procedures (with a little help from this forum) for reading and writing in a PDS member. They are both very similar but ofcourse they are two separate procs for a reason. I was wondering if it is possible to combine both of them into one proc, making my code much smaller and easier to understand. I will give a brief intro of what both of my procs do;
This one reads (indd.i) a member in a PDS and searches for a string in the variable filestr.n, when it finds the string it starts reading the contents below it. After reaching a certain keyword (bttmline) inside the file, it writes the content in another PDS member (memname.n). Then it continues reading the member to find a different keyword in the variable filestr.n and write it on a new member in memname.n.
So this basically extracts certain portions of a file by reading sequentially and writes them in different members of a PDS.
Code: |
do i = 1 to indd.0
if pos(filestr.n,indd.i) > 0 then
do
"alloc shr fi(outdd) dataset('"PDS"("memname.n")')"
do a = i+1 to indd.0
dslist = delstr(indd.a,44)
if pos('bttmline',indd.a) > 0 then leave
push dslist
"execio 1 diskw outdd"
end
"execio 0 diskw outdd (finis"
"ispexec edit dataset('"PDS"("memname.n")')"
"free fi(outdd)"
leave
end
end |
-------------------------------------------------------------------------------------
This one on the other hand reads the member and looks for a certain texts which can be present anywhere in the file. It selects the lines which contains those keywords and prints them in a PDS member (bookmem).
Code: |
do i = 1 to indd.0
if pos('Txt2find',indd.i) > 0 then
do
"alloc shr fi(outdd) dataset('"PDS"("bookmem")')"
do a = i to indd.0
if pos('Txt2find',indd.a) > 0 then
do
books = delstr(indd.a,44)
push books
"execio 1 diskw outdd"
end
end
"execio 0 diskw outdd (finis"
"ispexec edit dataset('"PDS"("bookmem")')"
"free fi(outdd)"
leave
end
end |
I can combine the variable in bookmem to loop in memname.n but I get very undesirable results when I try to combine the 2 procs.
So firstly, is it possible to combine these 2 bad boys in one? and secondly, if it is possible, can I have a few logical pointers (pseudo code) on how to go about it?
Thanks in advance,
Kushal
P.S. I have come a long way since asking my first question in REXX a couple of weeks ago. But I am still a beginner in REXX and programming in general. |
|
Back to top |
|
|
suthish
New User
Joined: 27 Apr 2009 Posts: 3 Location: bangalore
|
|
|
|
Could you please brief shortly what exactly tje requirement is..
Few Queries:
U want to search the two strings in the same PDS and extract it in different PDS.??
In that case u can use or condition in the first loop itself... |
|
Back to top |
|
|
kbrahma
New User
Joined: 08 Oct 2007 Posts: 38 Location: Delhi
|
|
|
|
Hi Suthish,
In short:
I want to combine both of the procs (in my previous post) into a single proc. They are very similar but they read/write into a file differently.
My first proc reads and writes the file sequentially (from top to bottom) and exists when a keyword is found. Then it continues reading (the SAME file) after that keyword till the same keyword is found again and it prints that portion too in a different member. So it reads and writes portions of same file and print it in different members in a PDS.
The second one finds keywords in a file and prints the lines containing those keywords in a member of a PDS.
and to answer your question:
No, it's all happening in only one PDS.
What I want to achieve is a SINGLE proc (instead of 2) which breaks and prints the contents of a SINGLE file into multiple members of a single PDS.
I have achieved what I wanted in 2 procs, I was wondering if I can do it in one or just make the code a little smaller. |
|
Back to top |
|
|
suthish
New User
Joined: 27 Apr 2009 Posts: 3 Location: bangalore
|
|
|
|
U can set aa flag to identify which condition is getting satisfied :
Then check for the Flag and write it accordingly.. |
|
Back to top |
|
|
kbrahma
New User
Joined: 08 Oct 2007 Posts: 38 Location: Delhi
|
|
|
|
Hmmm... I have some conceptual confusion, can you please implement what you said in a code (pseudo/practical anything... ) |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8797 Location: Welsh Wales
|
|
|
|
Take a look at the post by Marso in your original thread and then rework the logic for two finds instead of one. |
|
Back to top |
|
|
kbrahma
New User
Joined: 08 Oct 2007 Posts: 38 Location: Delhi
|
|
|
|
Thank you for the pointers... Had to struggle a little but finally got it to work from a single proc!!
Thanks again guys! |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
PROC? what Proc, I did not see anything about PROC's in this discussion
about combining two REXX Scripts. |
|
Back to top |
|
|
kbrahma
New User
Joined: 08 Oct 2007 Posts: 38 Location: Delhi
|
|
|
|
Oops, forgot to mention that I was calling them as procedures in my program to process multiple PDS's. That's why I was calling them procs.
Sorry about the confusion... |
|
Back to top |
|
|
|