IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Array to Array movement in REXX


IBM Mainframe Forums -> CLIST & REXX
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
HameedAli

Active User


Joined: 16 Apr 2009
Posts: 151
Location: India

PostPosted: Fri May 22, 2009 4:26 pm
Reply with quote

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.

Code:
&DISC
&ADDED


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
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8796
Location: Welsh Wales

PostPosted: Fri May 22, 2009 4:34 pm
Reply with quote

Where do you set the value for AB.?
Putting data into AB.0 will do you no good at all
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri May 22, 2009 4:51 pm
Reply with quote

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
View user's profile Send private message
HameedAli

Active User


Joined: 16 Apr 2009
Posts: 151
Location: India

PostPosted: Fri May 22, 2009 5:31 pm
Reply with quote

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
View user's profile Send private message
superk

Global Moderator


Joined: 26 Apr 2004
Posts: 4652
Location: Raleigh, NC, USA

PostPosted: Fri May 22, 2009 5:43 pm
Reply with quote

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
View user's profile Send private message
HameedAli

Active User


Joined: 16 Apr 2009
Posts: 151
Location: India

PostPosted: Fri May 22, 2009 5:46 pm
Reply with quote

Thanks a lot, Kevin
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8796
Location: Welsh Wales

PostPosted: Fri May 22, 2009 5:49 pm
Reply with quote

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
View user's profile Send private message
superk

Global Moderator


Joined: 26 Apr 2004
Posts: 4652
Location: Raleigh, NC, USA

PostPosted: Fri May 22, 2009 5:49 pm
Reply with quote

Code:

Do I = 1 to AB.0


You see why that's wrong, I hope. icon_wink.gif
Back to top
View user's profile Send private message
HameedAli

Active User


Joined: 16 Apr 2009
Posts: 151
Location: India

PostPosted: Mon May 25, 2009 5:59 pm
Reply with quote

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
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8796
Location: Welsh Wales

PostPosted: Mon May 25, 2009 6:51 pm
Reply with quote

What was the result of displaying DS.0
Back to top
View user's profile Send private message
HameedAli

Active User


Joined: 16 Apr 2009
Posts: 151
Location: India

PostPosted: Mon May 25, 2009 7:06 pm
Reply with quote

0 to N strings like

Code:
ABCD.EFGHI.JKLM.OPFGTH
ABCD.EFGHI.JKLM.OPFGTH1
ABCD.EFGHI.JKLM.OPFGT3
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Mon May 25, 2009 7:17 pm
Reply with quote

Expat,

did you expect a different answer?
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8796
Location: Welsh Wales

PostPosted: Mon May 25, 2009 7:33 pm
Reply with quote

dbzTHEdinosauer wrote:
Expat,
did you expect a different answer?

Errrrrrrrrrrrrrrrr just a little icon_cry.gif
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8796
Location: Welsh Wales

PostPosted: Mon May 25, 2009 7:39 pm
Reply with quote

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
Code:
Do I = 1 to DS.0

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
View user's profile Send private message
HameedAli

Active User


Joined: 16 Apr 2009
Posts: 151
Location: India

PostPosted: Mon May 25, 2009 8:31 pm
Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Mon May 25, 2009 8:51 pm
Reply with quote

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
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8796
Location: Welsh Wales

PostPosted: Tue May 26, 2009 11:25 am
Reply with quote

At this point I suggest that you follow Dicks advice and use TRACE ?R to see exactly what happens where.
Back to top
View user's profile Send private message
HameedAli

Active User


Joined: 16 Apr 2009
Posts: 151
Location: India

PostPosted: Tue May 26, 2009 1:34 pm
Reply with quote

I was able to fix the issue, with Trace ?R
Thanks Dick Brenholtz and Expat
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Tue May 26, 2009 8:44 pm
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> CLIST & REXX

 


Similar Topics
Topic Forum Replies
No new posts Run rexx with JCL Job CLIST & REXX 1
No new posts Run rexx in batch job CLIST & REXX 7
No new posts Does anyone know rexx for VSE CLIST & REXX 3
No new posts TSO ALLOC In REXX Needs Improvement JCL & VSAM 3
No new posts REXX/CMS How to place command console... CLIST & REXX 4
Search our Forums:

Back to Top