parsing by line, need to get next line



IBM's Command List programming language & Restructured Extended Executor

parsing by line, need to get next line

Postby yodish » Thu Aug 06, 2015 6:24 pm

Hello,
I am stuck on what may be a simple algorithm, that has yet to pop into my head. Essentially, I am parsing this report, by line, using a stem variable and looking for the line that contains the word 'AMOUNT.' My problem is, after I find that line, I need to return values from the NEXT line.

Here is a snippet of the report:
report sample.jpg


Here is the REXX code I am currently using to find the line containing 'AMOUNT':
"Alloc F(ddname) shr ds('SOME.REPORT')"                   
"Execio * Diskr ddname (Finis Stem rpt1."                 
"Free F(ddname)"                                                                                                                                         
do i=1 to rpt1.0                                           
   if Subword(rpt1.i,2,1) = 'AMOUNT' THEN                       
   say rpt1.i                           
end                                                       


Any suggestions are much appreciated!
You do not have the required permissions to view the files attached to this post.
yodish
 
Posts: 22
Joined: Thu Oct 25, 2012 3:03 am
Has thanked: 0 time
Been thanked: 0 time

Re: parsing by line, need to get next line

 

Re: parsing by line, need to get next line

Postby enrico-sorichetti » Thu Aug 06, 2015 6:41 pm

do i=1 to rpt1.0                                           
   if Subword(rpt1.i,2,1) = 'AMOUNT' THEN                       
   say rpt1.i                           
end                                                       


since You did not tell enough ( on what happens after ) we are just guessing

rpt1.1 = "..."
rpt1.2 = "..."
rpt1.3 = "FIRST AMOUNT"
rpt1.4 = "line after the first 'AMOUNT' line "
rpt1.5 = "..."
rpt1.6 = "..."
rpt1.7 = "..."
rpt1.8 = "SECND AMOUNT"
rpt1.9 = "line after the secnd 'AMOUNT' line "
rpt1.0 = 9
i = 0
do  while ( i < rpt1.0 )
    i = i + 1
    if  Word(rpt1.i,2) \= 'AMOUNT' then ,
        iterate
    say i rpt1.i
    i = i + 1
   /* You are now on the line after the 'AMOUNT' line */
    say i rpt1.i
end

to get
3 FIRST AMOUNT
4 line after the first 'AMOUNT' line
8 SECND AMOUNT
9 line after the secnd 'AMOUNT' line
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2644
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 130 times

Re: parsing by line, need to get next line

Postby yodish » Thu Aug 06, 2015 6:51 pm

Thank you for the reply Enrico,

I think I understand what you are saying; this would work (and i've already coded something similar to this) if the number of lines in the report never changed and I could always count on the values I need being on the same line. If that was the case, I could probably just go right to that line and avoid searching for 'AMOUNT.'

Unfortunately, I have to account for the unknown. All I am confident of is that the values I need to pull are going to be on the line after the "ITEMS AMOUNT ITEMS AMOUNT" line.

So, i'm struggling with a way to return the next line after I find the line containing 'AMOUNT.'
yodish
 
Posts: 22
Joined: Thu Oct 25, 2012 3:03 am
Has thanked: 0 time
Been thanked: 0 time

Re: parsing by line, need to get next line

Postby yodish » Thu Aug 06, 2015 6:59 pm

Ah jeez, I didn't scroll through all of your code first...
That worked beautifully!
Thank you!

Actually, adding a simple 'i = i +1' worked.
I overlooked the obvious.
yodish
 
Posts: 22
Joined: Thu Oct 25, 2012 3:03 am
Has thanked: 0 time
Been thanked: 0 time

Re: parsing by line, need to get next line

Postby yodish » Mon Aug 10, 2015 7:42 pm

I'm hoping you can help me add 1 more layer to this.

I now need to get a value from the next line, which I can do using the method described above. However, I also need a value from the line after that (i +2).

For example, if the report is this:
report sample2.JPG


I need to return both '100' and '450'

I can do one or the other, by commenting out one of the two 'i + ' statements in this code:

do i=1 to rpt2.0                                         
   if Subword(rpt2.i,1,2) = 'TOTALS' Then do
   i = i + 1                                             
   DBAMT2 = Word(rpt2.i,4)                               
   i = i + 2                                             
   CRAMT2 = Word(rpt2.i,3)                               
   end                                                   
end


Can someone help me to figure out how to return both the next line, and the line after that?

I appreciate everyone's help and patience!
You do not have the required permissions to view the files attached to this post.
yodish
 
Posts: 22
Joined: Thu Oct 25, 2012 3:03 am
Has thanked: 0 time
Been thanked: 0 time

Re: parsing by line, need to get next line

Postby enrico-sorichetti » Mon Aug 10, 2015 9:21 pm

i = i + 1
 DBAMT2 = Word(rpt2.i,4)                               
 i = i + 2
 CRAMT2 = Word(rpt2.i,3)   


IMNSHO You have more problems with basic logic than with the language itself.

after the first increment of I what is the line pointed to

use Your neuron to find out what increment to apply to i in order to point to the i(TOTAL) + 2 line
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2644
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 130 times

Re: parsing by line, need to get next line

Postby yodish » Wed Aug 12, 2015 6:01 pm

You are apparently a very competent programmer, I can respect that. You have well over 2,000 posts, which leads me to believe you are a well-respected member of this message board. I would also wager that you have helped many people who are struggling, like myself, get results quicker. Kudos!

Drivel removed
yodish
 
Posts: 22
Joined: Thu Oct 25, 2012 3:03 am
Has thanked: 0 time
Been thanked: 0 time

Re: parsing by line, need to get next line

Postby Pedro » Wed Aug 12, 2015 7:22 pm

a quote from the previous drivel that was removed

That was uncalled for.

You are correct, Enrico has helped numerous people and is well respected by all. It is not clear why you continue to be dis-respectful.
Pedro Vera
User avatar
Pedro
 
Posts: 569
Joined: Thu Jul 31, 2008 9:59 pm
Location: Silicon Valley
Has thanked: 0 time
Been thanked: 39 times


Return to CLIST & REXX

 


  • Related topics
    Replies
    Views
    Last post