View previous topic :: View next topic
|
Author |
Message |
HameedAli
Active User
Joined: 16 Apr 2009 Posts: 151 Location: India
|
|
|
|
I have the below set of records in a stem variable say ABC.
Code: |
ABCD.EFGHI.JKLM.OPFGTH
&ADDED
ABCD.EFGHI.JKLM.OPFGTH1
&DISC |
I want to filter only rows which starts with '&' into another stem variable called AB.
Below code is not working
Code: |
Do J = 1 to ABC.0
If Pos("&",ABC.J) = 0 Then
AB.J = ABC.J
End |
Need information on the same. |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8796 Location: Welsh Wales
|
|
|
|
Where do you set the value for AB.?
Putting data into AB.0 will do you no good at all |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
Quote: |
If Pos("&",ABC.J) = 0 Then |
Suggest you look-up the POS function:
Quote: |
...returns the position of one string, needle, in another, haystack.... |
here is the Link.
Also, even experienced REXX coders use the TRACE facility to always to debug their code.
Had you done so, you would not have had to make this post. |
|
Back to top |
|
|
HameedAli
Active User
Joined: 16 Apr 2009 Posts: 151 Location: India
|
|
|
|
that's a typo there
Code: |
AB.0 = 0
J = 1
Do I = 1 to ABC.0
If Pos("&",ABC.I) = 1 Then
AB.J = ABC.I
J = J + 1
End |
I don't see the output of the Pos, after these statements
Code: |
Do I = 1 to AB.0
Say Right(I,2) AB.I
End |
What could be the reasons? |
|
Back to top |
|
|
superk
Global Moderator
Joined: 26 Apr 2004 Posts: 4652 Location: Raleigh, NC, USA
|
|
|
|
This worked for me:
Code: |
J = 0
DO I = 1 TO ABC.0
IF POS("&",ABC.I) = 1 THEN
DO
J = J + 1
AB.J = ABC.I
AB.0 = J
END
END
DO I = 1 TO AB.0
SAY AB.I
END
|
|
|
Back to top |
|
|
HameedAli
Active User
Joined: 16 Apr 2009 Posts: 151 Location: India
|
|
|
|
Thanks a lot, Kevin |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8796 Location: Welsh Wales
|
|
|
|
We all code differently but I would change
Code: |
AB.0 = 0
J = 1
Do I = 1 to ABC.0
If Pos("&",ABC.I) = 1 Then
AB.J = ABC.I
J = J + 1
End |
to
Code: |
AB.0 = 0
J = 0
Do I = 1 to ABC.0
If Pos("&",ABC.I) = 1 Then do
J = J + 1
AB.J = ABC.I
End
End
A.0 = J
|
Because that way the J variable contains the true number of entries in the array, rather than one more than actually exists. |
|
Back to top |
|
|
superk
Global Moderator
Joined: 26 Apr 2004 Posts: 4652 Location: Raleigh, NC, USA
|
|
|
|
You see why that's wrong, I hope. |
|
Back to top |
|
|
HameedAli
Active User
Joined: 16 Apr 2009 Posts: 151 Location: India
|
|
|
|
I was not able to figure out the reason.
Code: |
J = 1; DS. = '';
Do I = 1 to FDS.0
Do
DS.J = FDS.I
DS.0 = J
J = J + 1
End
End
Trace I
I = 0;
Do I = 1 to DS.0
Say Right(I,2) DS.I
End
|
For the above code, I get the message listed below, How do I fix it?
Code: |
*-* I = 0
>L> "0"
*-* Do I = 1 to DS.0
>L> "1"
>V> ""
+++ Do I = 1 to DS.0
IRX0041I Error running DSLIMIT, line 80: Bad arithmetic conversion |
|
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8796 Location: Welsh Wales
|
|
|
|
What was the result of displaying DS.0 |
|
Back to top |
|
|
HameedAli
Active User
Joined: 16 Apr 2009 Posts: 151 Location: India
|
|
|
|
0 to N strings like
Code: |
ABCD.EFGHI.JKLM.OPFGTH
ABCD.EFGHI.JKLM.OPFGTH1
ABCD.EFGHI.JKLM.OPFGT3 |
|
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
Expat,
did you expect a different answer? |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8796 Location: Welsh Wales
|
|
|
|
dbzTHEdinosauer wrote: |
Expat,
did you expect a different answer? |
Errrrrrrrrrrrrrrrr just a little |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8796 Location: Welsh Wales
|
|
|
|
HameedAli wrote: |
0 to N strings like
Code: |
ABCD.EFGHI.JKLM.OPFGTH
ABCD.EFGHI.JKLM.OPFGTH1
ABCD.EFGHI.JKLM.OPFGT3 |
|
And substituting your code above
we get
Code: |
Do I = 1 to ABCD.EFGHI.JKLM.OPFGTH |
So yeah, an arithmatic error is exactly what I would expect to see.
Do you know the use of the .0 variable of a stem. If not, please read the REXX reference manual by clicking the "IBM manuals" button at the top of this page. Quickly. |
|
Back to top |
|
|
HameedAli
Active User
Joined: 16 Apr 2009 Posts: 151 Location: India
|
|
|
|
Oh! Correct me if my understanding is wrong.
I derived this understanding from
Rexx Reference Manual (TSO) by David Grund Sr. Rev 6 – April 27, 2007 Page 53
Quote: |
Example 2: Read a disk file into an array
"Alloc fi(DDIn) Da(Rexx.exec(TestData)) shr"
"ExecIO * DiskR DDIn (Stem Lines. Finis "
"Free Fi(DDIn)"
And then, to process the array:
Say "The disk file contains " Lines.0 "lines. Here they
are:"
Do I = 1 to Lines.0
Say Lines.I
End |
The above means the array elements of Lines will be displayed from 1 to maximum no of elements.
Is my understanding wrong? |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
Oh my! aren't we touchy?
Hameed Ali,
I ran your code
(after loading FDS.0 with 2, FDS.1 with "on" and FDS.2 with "OFF")
Code: |
J = 1; DS. = '';
Do I = 1 to FDS.0
Do
DS.J = FDS.I
DS.0 = J
J = J + 1
End
End
Trace I
I = 0;
Do I = 1 to DS.0
Say Right(I,2) DS.I
End
|
and did not have any problem.
Try using TRACE ?R in the future.
had you done that, we (more importantly you) would know what is in DS.0.
you have left some code out.
Oh, and by the way, I doubt if even David Grund Sr. would refer to a stem variable as an array.
stem.0 is normally used as a counter.
earlier you said something was a 'typo'
stop typing your code, use cut & paste. |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8796 Location: Welsh Wales
|
|
|
|
At this point I suggest that you follow Dicks advice and use TRACE ?R to see exactly what happens where. |
|
Back to top |
|
|
HameedAli
Active User
Joined: 16 Apr 2009 Posts: 151 Location: India
|
|
|
|
I was able to fix the issue, with Trace ?R
Thanks Dick Brenholtz and Expat |
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
Instead of using
Code: |
If Pos("&",ABC.I) = 1 Then |
you should use
Code: |
If Left(ABC.I,1) = "&" Then |
Why is it better?
LEFT will take the leftmost character and compare it to "&"
POS will search the whole string for "&" and compare result to 1
Why is it important?
I have no idea. I only know that LEFT is the right tool for the job, and POS is not. |
|
Back to top |
|
|
|