1

I have a REXX parameter string in this format:

arg = 'update summary(A summary of something) description(The description)'

and I'm parsing out the mode, summary and description as follows:

parse upper var arg mode . ,
   1, 'SUMMARY('summary')' .,
   1, 'DESCRIPTION('description')' .

I convert the arg to upper-case so that the SUMMARY and DESCRIPTION keywords are effectively case-insensitive (the user can code Summary or SUmmAry or sUmMaRy etc) but of course now I've just translated my actual summary and description to upper-case.

How can I make the parsing case-insensitive for the keywords, but keep the correct case for the actual parameters?

I've thought about extracting the character positions of the keywords and using them in the PARSE statement instead of '1' etc, but want a simple concise process if possible.

zarchasmpgmr
  • 1,422
  • 10
  • 21
Steve Ives
  • 7,894
  • 3
  • 24
  • 55
  • 1
    why not parse based on '(', ')' i.e. `parse var arg keyword '(' value ')' arg` and then test the keyword. Also loop through the keywords – Bruce Martin Jun 05 '19 at 11:34
  • @BruceMartin Hi Bruce - how's things been since Hoskyns and Greenford? :-) That might work although I've actually been thinking about picking up the keyword positions and have come up with something fairly simply that I could make an external subroutine - see my answer. – Steve Ives Jun 05 '19 at 11:44

3 Answers3

1

I came up with this 'toUpper' function, which is a bit simpler than expected. It takes a string and a list of words as input and returns the string with any of the words converted to upper case if found:

parms = 'UPdatE summary(The summary) Description(The description)'     
say 'Parms are :' parms                                                

parms = toUpper(parms, 'CHANGE UPDATE SUMMARY DESCRIPTION')            
say 'Parms are now :' parms                                            

exit                                                                   

/********************************************************************/ 
/* Subroutines                                                      */ 
/********************************************************************/ 
toUpper:                                                               

parse arg string, wordList                                             
stringUpper = string                                                   
upper stringUpper wordlist                                             

do i = 1 to words(wordlist)                                            
   word = word(wordlist,i)                                             
   pos = pos(word, stringUpper)                                        
   if pos > 0 then string = overlay(word, string, pos)                 
end                                                                    

return string 

Output:

Parms are : UPdatE summary(The summary) Description(The description)       
Parms are now : UPDATE SUMMARY(The summary) DESCRIPTION(The description) 
Steve Ives
  • 7,894
  • 3
  • 24
  • 55
  • 1
    That should work, I was thinking doing general purpose routine but focusing on the '(' ')' and saving as on a stem variable. I will write the basic code – Bruce Martin Jun 05 '19 at 13:40
1

This is a pretty common task when trying to simulate TSO-ish / IDCAMS-ish syntax in Rexx. I usually do something like this. It's such a short idiom, I never bother to make a subroutine out of it, just use it inline.

summary = 'Whatever the default value is'
description = 'Whatever the default value is'
parse var arg mode arg
mode = upper(mode)
do while arg <> ''
    parse var arg keyword '(' value ')' arg
    select upper(keyword)
        when 'SUMMARY' then summary = value
        when 'DESCRIPTION' then description = value
        otherwise Say 'Unknown option:' keyword
    end
end
Ross Patterson
  • 9,527
  • 33
  • 48
0

As supplied Ross's code won't work on a z/OS system. The REXX on z/OS is a bit ancient. :-( The following codes will work.

summary = 'Whatever the default value is'                           
description = 'Whatever the default value is'                       
arg =  'UPdatE summary(The summary) Description(The description)'   
parse var arg mode arg                                              
upper mode                                                          
do while arg <> ''                                                  
    parse var arg keyword '(' value ')' arg                         
    upper keyword                                                   
    select                                                          
        when keyword='SUMMARY' then summary = value                 
        when keyword='DESCRIPTION' then description = value         
        otherwise Say 'Unknown option:' keyword                     
    end                                                             
end                                                                 
GOVarney
  • 1,027
  • 1
  • 7
  • 9