According to https://www.ibm.com/docs/en/cobol-zos/6.4?topic=functions-structuring-user-defined, "Currently, the SQL
, CICS
, and JAVAIOP
facilities cannot be used with user-defined functions due to the need to include the user-defined function definition ahead of the program using them.".
This is in fact not true for CICS. As with any other structured compilation group that invokes user defined functions, you have to code the functions prior to their use, or code function prototypes instead, prior to invoking the associated function. The one special thing you have to do to is use a COBOL "PROCESS" statement to set the "CICS" option before any compilation unit that has an EXEC CICS in it, and use one to set NOCICS ahead of any compilation unit that does not contain any CICS statements. One caveat is that use must specify the CICS "NOLINKAGE" option so that the CICS precompiler does not implicitly insert the "USING DFHEIBLK DFHCOMMAREA" clause of the PROCEDURE DIVISION. (If you are doing a COBOL CALL or a function invocation of a UDF you don't use an implicit DFHEIBLK or DFHCOMMAREA.) Here is an example structured compilation group containing two programs that do not have any CICS statements, two UDFs that do not have any CICS statements, and one UDF (function-id. two.) that does include a CICS statement.
process nocics
identification division.
program-id. batcicsf.
procedure division.
call 'main'
goback.
end program batcicsf.
identification division.
function-id. one.
data division.
linkage section.
01 dummy pic x value '1'.
procedure division returning dummy.
display 'test one'
initialize dummy all to value
goback.
end function one.
process cics('nolinkage')
identification division.
function-id. two.
data division.
linkage section.
01 dummy pic x value '2'.
procedure division returning dummy.
exec cics write operator
text('test two')
end-exec
initialize dummy all to value
goback.
end function two.
process nocics
identification division.
function-id. three.
data division.
linkage section.
01 dummy pic x value '3'.
procedure division returning dummy.
display 'test three'.
initialize dummy all to value
goback.
end function three.
identification division.
program-id. main.
environment division.
configuration section.
repository.
function one
function two
function three.
procedure division.
display one space two space three
goback.
end program main.
So this is great! Quite useful. This also works for function prototypes, as long as you specify "PROCESS NOCICS" prior to the prototype(s). (If NOCICS is your default compile option you shouldn't even need this.)
On the other hand, this does not work for SQL. If in a single structured compilation unit you try to have one function (or program) compiled with NOSQL and another compiled with SQL you get an error:
IGYOS4009-E An attempt to change the "SQL" option during a batch
compilation was found. This option specification was
discarded.
I wonder how hard it might be to allow for this? Since the CICS coprocessor allows for it, I am hopeful that this could be allowed for SQL as well.
------------------------------
Frank Swarbrick
------------------------------