Page 1 of 1

parsing by line, need to get next line

PostPosted: Thu Aug 06, 2015 6:24 pm
by yodish
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!

Re: parsing by line, need to get next line

PostPosted: Thu Aug 06, 2015 6:41 pm
by enrico-sorichetti
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

Re: parsing by line, need to get next line

PostPosted: Thu Aug 06, 2015 6:51 pm
by yodish
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.'

Re: parsing by line, need to get next line

PostPosted: Thu Aug 06, 2015 6:59 pm
by yodish
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.

Re: parsing by line, need to get next line

PostPosted: Mon Aug 10, 2015 7:42 pm
by yodish
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!

Re: parsing by line, need to get next line

PostPosted: Mon Aug 10, 2015 9:21 pm
by enrico-sorichetti
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

Re: parsing by line, need to get next line

PostPosted: Wed Aug 12, 2015 6:01 pm
by yodish
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

Re: parsing by line, need to get next line

PostPosted: Wed Aug 12, 2015 7:22 pm
by Pedro
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.