gtpa3m0qApplication Requester User's Guide

Using the Same Cursor in Multiple Programs

Because of the TPF system restriction to a 4 KB program size for assembler and TARGET(TPF) programs, you may have to use the same cursor throughout multiple TPF segments (the SQL source programs). If so, you must make the following modifications to your SQL source programs.

Segment size is not a problem for ISO-C programs, so this section is restricted to TARGET(TPF) and assembler considerations.

The DB2 precompiler needs to have all of the programs in one file in order to create the DBRM. The individual TPF segments must be placed into a single source file for the DB2 precompiler to work on. After the DB2 precompiler has finished, a single modified source output is returned. This modified source output contains the updated source code with the SQL commands removed. If the host language used was C, the modified source output needs to be run through the DB2PP processor before continuing. The modified source file now has to be separated into the different original TPF source program segments. Figure 17 shows this process.

Figure 17. Modifying Non-ISO-C SQL Source Programs for the DB2 Precompiler When Using the Same Cursor




After the file has been separated into the different original segments, modifications need to be made, depending upon the host language used.

Note:
When using the same cursor throughout multiple TPF segments, the same host language must be used in all of the segments.

TARGET C Language Modifications

When the TPF segments are coded in C language, the large source file needs to be precompiled and then run through the TPF DB2PP program to process the precompiled output. After these have both been run with successful completion, the top of the returned source file in the first TPF segment contains the lines of code shown in Figure 18.

Note:
If the VERSION option was not used on the precompile run, the last seven lines starting with the SQLVTAG structure are not present.

Figure 18. C Code to Copy to Each TPF Segment


typedef struct
              { short   SQLPLLEN;
                short   SQLFLAGS
                short   SQLCTYPE
                char    SQLPROGN[8];
                short   SQLTIMES[4];
                short   SQLSECTN;
                char   *SQLCODEP;
                char   *SQLVPARM;
                char   *SQLAPARM;
                short   SQLSTNUM;
                short   SQLSTYPE;
              } SQLPLIST;
typedef struct
              { short    SQLTYPE;
                short    SQLLEN;
                char    *SQLADDR;
                char    *SQLIND;
              } SQLELTS;
typedef SQLELTS     *SQLELTS_PTR;
static char SQLTEMP??(19??) ;
struct SQLVTAG
    { char    *VERSPRE ;
      char    *VERSSTR ;
    } ;
static struct SQLVTAG SQLVERS = {
 "VER.",
 "JT"};
static char DSNPNM??(57??) ;

When the modified output is separated into the different TPF segments, this code must be copied to each of the segments. When adding this code to the each segment, this code should be placed at the top of the individual segments after any #includes that are used. (The #include is a C programming structure.)

The individual TPF segments can then be compiled and loaded, and the DBRM can be bound.

Assembler Modifications

The assembler modifications are similar to those for C language.

In the modified assembler source file that is returned, two areas need to be copied: one at the top of the modified assembler (shown in Figure 19), and the other at the bottom of the first TPF program, just before the END statement (shown in Figure 20).

Note:
Note that the SQLVERSP and SQLVERD1 tags are only found when the VERSION parameter is coded in the precompile options.

Figure 19. Assembler Code Area Needed at the Top of Each Separated TPF Segment


         MACRO
         SQLSECT &TYPE
         GBLC  &SQLSECT
         AIF ('&TYPE' EQ 'RESTORE').REST
&SQLSECT SETC  '&SYSECT'
         MEXIT
.REST    ANOP
&SQLSECT CSECT
         MEND

Figure 20. Assembler Code Area Needed in Each TPF Segment before the END Statement


SQLVERSP DC    CL4'VER.' VERSION-ID PREFIX
SQLVERD1 DC    CL64'JT'        VERSION-ID
***$$$ SQL WORKING STORAGE
SQLDSIZ  DC    A(SQLDLEN) SQLDSECT SIZE
SQLDSECT DSECT
SQLPLIST DS    F
SQLPLLEN DS    H         PLIST LENGTH
SQLFLAGS DS    XL2       FLAGS
SQLCTYPE DS    H         CALL-TYPE
SQLPROGN DS    CL8       PROGRAM NAME
SQLTIMES DS    CL8       TIMESTAMP
SQLSECTN DS    H         SECTION
SQLCODEP DS    A         CODE POINTER
SQLVPARM DS    A         VPARAM POINTER
SQLAPARM DS    A         AUX PARAM PTR
SQLSTNUM DS    H         STATEMENT NUMBER
SQLSTYPE DS    H         STATEMENT TYPE
SQLPVARS DS    F,1CL12
SQLAVARS DS    F,1CL12
SQLTEMP  DS    CL18      TEMPLATE
         DS    0D
SQLDLEN  EQU   *-SQLDSECT

Place the code in exactly the same places you found it in the first segment: at the top and before the END statement.