View previous topic :: View next topic
|
Author |
Message |
valyk
Active User
Joined: 16 Apr 2008 Posts: 104 Location: South Carolina
|
|
|
|
I know there have been several post about this issue, and Rexx does not offer a easy way of doing it. I was curious about what the forum thought of my process.
First I have a dataset that contains the global variables that will be passed between program.
Code: |
RPT. /* REPEATING BLOCK ARRAY */
MAX_ROW /* DEFAULT SIZE DEPTH */
MAX_COL /* DEFAULT SIZE WIDTH */
INIT_CSR /* DEFAULT CURSOR POSITION */
PNL_PREF /* DEFAULT PANEL NAME PREFIX */
PNL_SUFF /* DEFAULT PANEL NAME SUFFIX */ |
Whenever a program is about to call another program, it will open the global variables dataset and it will create a single string with each parameter appended. Then, it will call the program, passing the parameter string.
Code: |
DRAW_PARMS:
PARMS = ''
ADDRESS TSO
"ALLOC DATASET('"DATASET"("GLOBALS")') FILE(PARM) SHR"
'EXECIO * DISKR PARM (FINIS STEM PARMS.'
'FREE FILE(PARM)'
DO I = 1 TO PARMS.0
PARM = SPACE(SUBSTR(PARMS.I,1,12))
IF PARM > '' THEN DO
IF POS('.',PARM) = LENGTH(PARM) THEN DO
INTERPRET "MAX = "PARM'0'
CALL CHANGE_STR PARM,'.',''
PARM = STRING
DO J = 0 TO MAX
INTERPRET "PARMS = PARMS PARM'.'J'='"PARM'.'J
END
END
ELSE
INTERPRET "PARMS = PARMS PARM'='"PARM
END
END
RETURN |
So in this example, the parameter string will look something like this:
Code: |
RPT.0=3 RPT.1=A RPT.2=B RPT.3=C MAX_ROW=24 MAX_COL=80 INIT_CSR=5 PNL_PREF=SCRN PNL_SUFF=MOD2 |
Then the calling program will parse the parameter string:
Code: |
PARSE_PARMS:
PARMS = ARG(1)
DO FOREVER
IF PARMS > '' THEN DO
PARSE VAR PARMS PARM PARMS
PARSE VAR PARM PARM_NAME '=' PARM_VAL .
IF POS('~',PARM_VAL) > 0 THEN
PARM_VAL = TRANSLATE(PARM_VAL,' ','~'
IF LENGTH(PARM_VAL) > 0 THEN DO
IF POS("'",PARM_VAL) > 0 THEN DO
PARM_VAL = '"'PARM_VAL'"'
INTERPRET PARM_NAME "="PARM_VAL
END
ELSE
INTERPRET PARM_NAME "='"PARM_VAL"'"
END
ELSE
INTERPRET PARM_NAME "='"PARM_VAL"'"
END
ELSE
LEAVE
END
RETURN |
|
|
Back to top |
|
|
superk
Global Moderator
Joined: 26 Apr 2004 Posts: 4652 Location: Raleigh, NC, USA
|
|
|
|
Yep, I've done that myself. |
|
Back to top |
|
|
Pedro
Global Moderator
Joined: 01 Sep 2006 Posts: 2546 Location: Silicon Valley
|
|
|
|
Code: |
PARSE VAR PARMS PARM PARMS |
This restricts you to numeric values or single word text values. I suggest you use a delimiter other than blank. I have seen '05'x used for that a few times.
Code: |
Do while (parms ^= '')
PARSE VAR PARMS PARM '05'x PARMS
INTERPRET parm
End
|
|
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10872 Location: italy
|
|
|
|
Code: |
RPT.0=3 RPT.1=A RPT.2=B RPT.3=C MAX_ROW=24 MAX_COL=80 INIT_CSR=5 PNL_PREF=SCRN PNL_SUFF=MOD2 |
why not separate the assignments wit a ";" and interpret in one shot the whole string??
no parsing needed! |
|
Back to top |
|
|
|