Chapter Contents |
Previous |
Next |
Using C for CICS Application Programs |
Data Declarations for CICS |
The following declarations may be needed, depending on your application:
The header files necessary for these declarations were
noted earlier in Header Files for SAS/C CICS Applications.
The following sections introduce you to working with these components using
C.
The following global external variables are provided:
__commptr
__dibptr
__eibptr
The following examples illustrate how to use these variables.
Using __eibptr
. . . switch(_eibptr->EIBRESP){ case DFHRESP(NORMAL): break; case DFHRESP(NOTOPEN): return -1; default: . . . }
Defining your own __eibptr
. . . struct EIBLK *my_eib_ptr; EXEC CICS ADDRESS EIB(my__eib_ptr); . . . switch(my_eib_ptr->EIBRESP) { . . . }
Using __commptr
if (__commptr) { /* Because __commptr was not null, */ /* a COMMAREA was passed */ /* Perform "second" pass */ /* processing. */ EXEC CICS RECEIVE MAP... . . . } else { /* Because __commptr was null, */ /* no COMMAREA was passed; */ /* therefore, this must be */ /* the "first" pass. */ /* Display the main menu. */ EXEC CICS SEND MAP... . . . }
Using __dibptr
. . . #define STATUS(code) (memcmp(__dibptr->DIBSTAT,code,2)==0) . . .
BMS Definitions |
The BMS map language must be specified
as assembler. The symbolic map (DSECT) must be processed by DSECT2C using
this special compiler option:
-d
. To assist with this
process under OS/390, the SAS/C Compiler
and Library provides a DSECT2C cataloged procedure. Terminal Control and Basic Mapping Support provides complete documentation
for SAS/C BMS considerations.
Supplying Arguments to main( ) |
The C
main
function can be passed arguments
optionally. For CICS, the default arguments to
main
are similar to other
traditional high-level languages under CICS, that is, a pointer to the execution
interface block and a pointer to any COMMAREA (or a NULL pointer, if no COMMAREA
exists). These arguments are supplied by the run-time library to
main
as an alternative to using the CICS global external variables described earlier
in this chapter. To use this technique, code your program as follows:
main(struct EIBLK *eib_pointer, void *COMMAREA_pointer) { . . . }
Alternatively, if you need to pass other parameters
besides those of the EIB and COMMAREA, you can use the alternate entry points
$MAINC and $MAINO. These entry points are primarily for use if your
main
program is invoked via a CALL statement from another language.
When you use these entry points, the arguments to
main
are the more traditional
argc
and
argv
values. The
argv
vector is defined
as follows:
/* pointer to transaction id */ argv [0] char *tranid /* pointer to the EIB */ argv [1] struct EIB *ptr /* pointer to any COMMAREA */ argv [2] void *COMMAREA /* pointer to optional parm 1 */ argv [3] void *parm1 . . . /* pointer to optional parm n */ argv [n] void *parmn
When coding the CALL statement from another language,
you can code the CALL statement specifying $MAINC or $MAINO directly. Again,
the CALL statement must pass the EIB and COMMAREA pointers as the first two
parameters followed, optionally, by other parameters. Note that the C run-time
library processes this parameter list as a VL-style parameter list and does
not convert the CICS pseudo-null COMMAREA pointer value of x'ff000000' to
a NULL pointer. A pointer value of x'ff000000' always indicates the end of
the parameter list. If you are passing optional parameters, you must pass
a value of 0 if no COMMAREA is being passed to the called program. Because
the library expects a VL-style parameter list when called through the entry
points $MAINC/$MAINO, failing to pass one could cause the
argc
value to be incorrect or lead to other program failures.
For example, here is a short piece of COBOL code that
calls the statically linked C routine named
called1
:
PROCEDURE DIVISION. CALL 'CALLED1' USING DFHEIBLK DFHCOMMAREA. EXEC CICS RETURN END-EXEC. GOBACK.
And the following is representative of the way you can
code the C routine
called1
:
void called1() { EXEC CICS ASKTIME; }
The entry points $MAINC and $MAINO can also be used
when a
main
program is invoked directly by CICS (either
as the first program of a transaction or via a LINK or XCTL command). Select
the entry point via the linkage editor control statement ENTRY $MAINC or ENTRY
$MAINO. Note that ESA versions of CICS do not always construct VL-style parameter
lists when calling programs directly; thus, you may get unpredictable results.
When the initial C function invoked by CICS is compiled
with the
indep
compiler option, the arguments can have any
type and, therefore, cannot be modified, or even inspected, by the library.
In this case,
_commptr
is always set to NULL,
argc
is 0, and
argv
is NULL. For more information, see the
SAS/C Compiler and Library User's Guide.
Handle Condition and Handle AID |
The standard syntax for this command is
EXEC CICS HANDLE CONDITION condition(label) ...
;
EXEC CICS HANDLE CONDITION condition(function-name) ... ;
EXEC CICS HANDLE CONDITION ERROR(errfunc); . . . void errfunc(int errcode) { . . /* errcode is EIBRESP */ . }
Normal return from the function is to the instruction
immediately after the EXEC command that raised the condition. Note that your
program can freely execute a
longjmp()
from the error handler.
EXEC CICS HANDLE CONDITION ERROR;
Because no function is specified, you avoid the potential
for recursion.
The syntax for this command is
EXEC CICS HANDLE AID option(label) ... ;
EXEC CICS HANDLE AID option(function-name) ... ;
EXEC CICS HANDLE AID PF1(help); . . . void help(int aid) { . /* AID values are mapped in <dfhaid.h> */ . . }
Abend and Error Handling |
However, the label option of the EXEC CICS HANDLE ABEND command, coded as follows, is not supported:
EXEC CICS HANDLE ABEND LABEL(label);
If the label option is coded, the message LSCP038 is generated.
EXEC CICS HANDLE ABEND PROGRAM(name); EXEC CICS ABEND CANCEL; EXEC CICS PUSH HANDLE;
SAS/C I/O Functions and CICS |
Except for UNIX style I/O functions, all other SAS/C Library I/O functions for sequential input and output are supported for CICS applications. C also provides features for working with transient data and JES Spool File input and output, as well as support for DL/I and SQL. Handling Files provides details.
Environment Variable Support |
With Release 6.00 of SAS/C,
certain functions have been enhanced to support environment variables under
CICS. Consult Chapter 4, "System Interface Functions and Environment Variables,"
and the function descriptions for
getenv
and
putenv
in
SAS/C Library Reference, Volume 1 for details on this support.
Program Control |
Interval and Task Control |
The
only
SAS/C consideration
in this area is to note that the
sleep
function is fully
supported and recommended instead of DELAY. This is because
sleep
accepts an
int
argument rather than a packed decimal.
Debugging SAS/C CICS Applications |
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.