entry points (cont)
generic approach:
PARM p1 … entry=main # default entry is “main”
if “!entry” = “main” then
… initialize etc…
xeq !HPFILE !p1, … entry=go # run same script, different entry
… cleanup etc…
return
elseif “!entry” = “go” then...
# execute the GO subroutine ...
return
elseif “!entry” = … ...
endif
Notes:
- This shows a script structured so that it can accept multiple alternate entry points.
- There should be little or no code before the if “!entry” = “main” line.
- Notice that RETURN is used to exit the main and all alternate entries. This is not required since the CI will drop out of the entry block of code, reach the eof and naturally return back to where the script called itself. However, performance is improved using RETURN in the manner shown above.
- ANYPARM scripts with entries use a slightly different structure and require more parsing: ANYPARM p1 = ![‘’] if “!p1” = “” or pos(“entry=“,”p1”) = 0 then # main entry for script ….. xeq !hpfile some parm value entry =do_this return else # parse out entry name and execute entry subroutine, entry name is last word setvar _entry word(“!p1”,,-1) # remove “entry=name” from parm line setvar _parm lft(“!p1”,pos(‘entry=‘,”!p1”)-1) # case on entry name if _entry = “do_this” then … return elseif _entry = ... endif endif
- UDCs with entries need to specify OPTION RECURSION so that the UDC can invoke itself with the alternate entry name. OPTION RECURSION can be in the UDC header or a separate CI command.