Dynamic populate the value inside user function



IBM's Command List programming language & Restructured Extended Executor

Dynamic populate the value inside user function

Postby Amit_learn » Wed Sep 19, 2012 12:59 am

IF IND='P' THEN DYNDATA="'4','INVALID CHOICE'"
ELSE DYNDATA="'5','AGAIN"

XX = FUNC(VAL,'1','RED','2','WHITE',
        '3','NO COLOR',DYNDATA,' ',' ')
FUNC:
    DO I = 2 TO ARG() BY 2
      SAY ARG(I) ';' ARG(I+1)
    END
RETURN 0
***************************
Required Output:
1;RED
2;WHITE
3;NO COLOR
4;INVALID CHOICE

I am getting the 1,2,3 correctly but for 4/5, depending upon the IND I have set the DYNDATA dynamically and use it into FUNC.
But when I am passing DYNDATA as "'4','INVALID CHOICE'", not getting the correct output (4,INVALID CHOICE; ).
Any suggestion?
Amit_learn
 
Posts: 2
Joined: Wed Sep 19, 2012 12:44 am
Has thanked: 0 time
Been thanked: 0 time

Re: Dynamic populate the value inside user function

Postby Akatsukami » Wed Sep 19, 2012 1:09 am

And what did the trace show you?
"You have sat too long for any good you have been doing lately ... Depart, I say; and let us have done with you. In the name of God, go!" -- what I say to a junior programmer at least once a day
User avatar
Akatsukami
Global moderator
 
Posts: 1058
Joined: Sat Oct 16, 2010 2:31 am
Location: Bloomington, IL
Has thanked: 6 times
Been thanked: 51 times

Re: Dynamic populate the value inside user function

Postby enrico-sorichetti » Wed Sep 19, 2012 1:35 am

Any suggestion?

strong suggestion
read the rexx manuals about the rules for passing parameters to rexx functions/subroutines

hint ...
the way You do it
arg(8) contains the whole <message>
according to Your coding You expect 11 arguments
the VAL thing + 5 couples

when really the call is passing just 10 ( as per rexx rules )

change Your function to
FUNC:
say arg()
DO I = 2 TO ARG() BY 2
SAY i ">"ARG(I)"<" ';' i+1 ">"ARG(I+1)"<"
END
RETURN 0

and You will see the problem

here is the link to the rexx manuals
http://publibz.boulder.ibm.com/cgi-bin/ ... s/IKJ4BK90

not the latest ones but more than enough
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2994
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times

Re: Dynamic populate the value inside user function

Postby delorimier » Wed Sep 19, 2012 6:22 am

It looks like there is a single quote missing just after the word AGAIN. Could it be the problem?

Rene
delorimier
 
Posts: 9
Joined: Sat Aug 25, 2012 7:01 am
Has thanked: 0 time
Been thanked: 0 time

Re: Dynamic populate the value inside user function

Postby prino » Wed Sep 19, 2012 12:52 pm

delorimier wrote:It looks like there is a single quote missing just after the word AGAIN. Could it be the problem?

You're missing the issue by about a mile...
Robert AH Prins
robert.ah.prins @ the.17+Gb.Google thingy
User avatar
prino
 
Posts: 635
Joined: Wed Mar 11, 2009 12:22 am
Location: Vilnius, Lithuania
Has thanked: 3 times
Been thanked: 28 times

Re: Dynamic populate the value inside user function

Postby delorimier » Wed Sep 19, 2012 6:03 pm

It was just a suggestion Rob.

But, point taken, I apologize for posting to the forum without having the expertise, and I'll stay quiet from now on.

Yours truly,

Rene
delorimier
 
Posts: 9
Joined: Sat Aug 25, 2012 7:01 am
Has thanked: 0 time
Been thanked: 0 time

Re: Dynamic populate the value inside user function

Postby BillyBoyo » Wed Sep 19, 2012 7:20 pm

Rene,

Welcome to the forum. Sometimes you can meet a certain "shortness" here. You then have to take the "rough", but it is not so often.

It may not have been the main point, but no-one else seems to have spotted it :-) Good eyes. You don't need any expertise for that. Perhaps a little more experience before suggesting it as the answer :-)

Feel free to type something when you think you have something. If anything becomes too rough, you'll probably find a Moderator does some tidying-away :-)
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: Dynamic populate the value inside user function

Postby enrico-sorichetti » Wed Sep 19, 2012 8:07 pm

It looks like there is a single quote missing just after the word AGAIN. Could it be the problem?

just esthetics, the code would display something different from what it was meant :mrgreen:

meditate on dbz signature
Programming Languages, SQL and JCL have the tendency to do what you coded,
not necessarily what you wanted.


t may not have been the main point, but no-one else seems to have spotted it


... because there was nothing to spot ;)
in REXX strings can be delimited by ' or "

so there is no need to double anything
You need to double only when the character inside the string is the same as the string delimiter

apost = "'"
apost = '''
quote = '"'
quote ="""""
'


ap = "'"
ap1 = ''''
qt = '"'
qt1 = """"
say ap ap1 qt qt1



provide exactly the same functionality

my personal preference is to use "
also provides better readability
Last edited by enrico-sorichetti on Wed Sep 19, 2012 8:13 pm, edited 2 times in total.
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2994
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times

Re: Dynamic populate the value inside user function

Postby Akatsukami » Wed Sep 19, 2012 8:13 pm

delorimier wrote:But, point taken, I apologize for posting to the forum without having the expertise, and I'll stay quiet from now on.

Not a lack of expertise per se, but a lack of understanding of what the TS is trying to accomplish.

As Dr. Sorichetti has indicated, the function func is receiving ten arguments, not eleven. Assigning dyndata a value containing pic marks (single quotes) does not make it multiple arguments when simply passed to a function (using INTERPRET would, but that's overkill).

Additionally, the statement
XX = FUNC(VAL,'1','RED','2','WHITE',
        '3','NO COLOR',DYNDATA,' ',' ')

is missing a comma on the first line. The trailing comma is interpreted as a line continuation character, not a parameter separator. This causes the literals "WHITE" and "3" to be interpreted as a single argument, with a space infixed.
"You have sat too long for any good you have been doing lately ... Depart, I say; and let us have done with you. In the name of God, go!" -- what I say to a junior programmer at least once a day
User avatar
Akatsukami
Global moderator
 
Posts: 1058
Joined: Sat Oct 16, 2010 2:31 am
Location: Bloomington, IL
Has thanked: 6 times
Been thanked: 51 times

Re: Dynamic populate the value inside user function

Postby enrico-sorichetti » Wed Sep 19, 2012 8:17 pm

I considered the missing comma as a cut and paste error
but if the code was as as posted it should be considered a programming error

it is a pity that REXX ( any flavor ) does not raise the NOVALUE exception for arguments out of range !
confirmed by testing :geek:
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2994
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times

Next

Return to CLIST & REXX

 


  • Related topics
    Replies
    Views
    Last post