stream UDC - main
# comments
if "!streamparms" = "" or pos("entry=","!streamparms") = 0 then # main entry point of UDC setvar _str_jobfile word("!streamparms") # extract 1st arg . . . # extract remaining stream parameters setvar _str_parms ups( & repl(rht("!streamparms",-delimpos("!streamparms"))," ","")) if setvar(_str_pos, pos(;JOBQ=,_str_parms)) > 0 then setvar _str_jobq word(_str_parms,,2,,_str_pos+5) endif if _str_jobq = then # no jobq=name in stream command so look at JOB card STREAM _str_jobcard entry=read_jobcard <!_str_jobfile if setvar(_str_pos,pos(";JOBQ=",_str_jobcard)) > 0 then setvar _str_jobq word(_str_jobcard,,2,,_str_pos+5) endif endif
Notes:
- The main entry point is detected by the absence of all parameters or by the lack of the entry= keyword.
- The first parameter extracted is the name of the file to be streamed.
- The remaining parameters are captured in the variable _str_parms, after the command line has been upshifted and all blanks have been removed.
- If the ;JOBQ= keywords is found in the command line the queue name is extracted. You might wonder why the second word (instead of the default of 1), and why at a position that indexes the = rather than the character immediately right of the =? Using word(_str_parms,,,,_str_pos+6) works in all cases, including a null (empty) jobq value. However, it fails when ;jobq= with no value is the last token on the command line. It fails in this case since the index (_str_pos+6) is beyond the end of the _str_parms string length. Extracting the second word starting at the = works in all cases.
- If jobq= is not present in the command line, the STREAM UDC invokes itself (highlighted in blue) using an alternate entry point, with $STDIN redirected to the file being streamed. This method allows the stream file to be read efficiently by the UDC.