View previous topic :: View next topic
|
Author |
Message |
jackzhang75
Active User
Joined: 09 Jun 2014 Posts: 125 Location: US
|
|
|
|
Hi,
I got the following input , I have the rexx to store the first colum data according to the same second colum . But my question is that each time the number of these data is changed , is anyway to dynamically assgin the different variable to store first colum data by same second colum instead of write lots of select (Variable name1....n )each time ?
Thank you so much !
Input :
Code: |
INP01A 01
OUT01A 01
OUT01B 01
OUT01C 01
OUT01D 01
OUT01E 01
INP02A 02
OUT02A 02
INP03A 03
OUT03A 03
OUT03B 03
OUT03C 03
INP06A 06
OUT06A 06
INP07A 07
OUT07A 07
INP08A 08
OUT08A 08 |
My code :
Code: |
DO CU=1 TO Q
DROP STEPNAME
PARSE VALUE STEP.CU WITH STEPNAME TYPE
SELECT
WHEN TYPE='01' then
NAME1 = STEPNAME
WHEN TYPE='02' then
NAME2 = STEPNAME
WHEN TYPE='03' then
NAME3 = STEPNAME
WHEN TYPE='04' then
NAME4 = STEPNAME ----- and so on .
END
OTHERWISE
END
END
|
|
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
You've already managed one stem variable, why not another? |
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
Use the INTERPRET instruction:
Code: |
INTERPRET "NAME"TYPE" = STEPNAME" |
This will assign values to NAME01, NAME02 and so on.
You'll have to take care of the zero if you don't want it. |
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
In addition:- You don't need to DROP STEPNAME.
- I would add a period (.) after TYPE in the PARSE line.
- To do nothing (in the OTHERWISE), use NOP.
|
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
Bill Woodger wrote: |
You've already managed one stem variable, why not another? |
Panels can't handle stem vars. Maybe that's the reason ? |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Maybe, but I was thinking since they'd not complained about this:
Code: |
PARSE VALUE STEP.CU WITH STEPNAME TYPE |
then there shouldn't be a problem.
/understatement on
Knowing a bit more about what the aim of the thing is would help, as always
/understatement off |
|
Back to top |
|
|
jackzhang75
Active User
Joined: 09 Jun 2014 Posts: 125 Location: US
|
|
|
|
Hi Marso,
Really apprecaite your answer. I changed the code according to your suggestion
Code: |
DO CU=1 TO Q
DROP STEPNAME
PARSE VALUE STEP.CU WITH STEPNAME TYPE
INTERPRET "NAME"TYPE".CU = STEPNAME"
END |
It does the job and another thing is i need these data to be stored in the array variable ,so i made "NAME"TYPE".CU. But when i print out the variable Name01 , it looks like following.
1. How to correct this ? i don't want NAME01.*, i only want it has actual data.
2. How to get total number of input in Name** variable ?
Thank you for your help!
Code: |
INP01A
OUT01A
OUT01B
OUT01C
OUT01D
OUT01E
NAME01.7
NAME01.8
NAME01.9
NAME01.10
NAME01.11--- and so on |
|
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Presumably you have something which was used to stuff the data into STEP. so why don't you use that instead of the ravishingly descriptive Q? |
|
Back to top |
|
|
Pedro
Global Moderator
Joined: 01 Sep 2006 Posts: 2546 Location: Silicon Valley
|
|
|
|
Quote: |
But when i print out the variable Name01... |
Show us the code for printing. |
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
Do I really have to quote myself ?
Marso wrote: |
In addition:- You don't need to DROP STEPNAME.
- I would add a period (.) after TYPE in the PARSE line.
- To do nothing (in the OTHERWISE), use NOP.
|
Now that makes less sense:
jackzhang75 wrote: |
i need these data to be stored in the array variable ,so i made "NAME"TYPE".CU. |
If you can use stems. why not use NAME.TYPE.CU
When I have a case like this, I also keep a list of the allocated values:
Code: |
If WordPos(TYPE,TYPElist) = 0 Then
TYPElist = TYPElist TYPE |
Code: |
Do Z = 1 To Words(TYPElist)
curTYPE = Word(TYPElist,Z)
Say '<'NAME.curTYPE.CU'>'
End |
And one more tip: when displaying a variable, place it around special signs:
Code: |
Say "NAME.TYPE.CU=<"NAME.TYPE.CU'>' |
Like this you'll see exactly the contents of the variable
(hint inside the tip: in stems, trailing spaces count...) |
|
Back to top |
|
|
|