15.10 - C INMOD Example - MultiLoad

Teradata MultiLoad Reference

prodname
MultiLoad
vrm_release
15.10
category
Programming Reference
featnum
B035-2409-035K

C INMOD Example

This INMOD example reads the function code and executes different processing functions based on its value.

               
               
               //JCKLC1 JOB 1,'JAMES KIM',MSGCLASS=A,NOTIFY=JCK,CLASS=B,
               REGION=4096K
               //******************************************************************
               //*                                                                *
               //*      IDENTIFY NECESSARY LOAD LIBRARIES                         *
               //*                                                                *
               //******************************************************************
               //JOBLIB   DD DISP=SHR,DSN=STV.GG10.APP.L
               //         DD DISP=SHR,DSN=STV.GG00.APP.L
               //         DD DISP=SHR,DSN=STV.TG00.APP.L
               //         DD DISP=SHR,DSN=STV.RG00.APP.L
               //         DD DISP=SHR,DSN=TER2.SASC301H.LINKLIB
               //C        EXEC PGM=LC370B
               
               //STEPLIB  DD DSN=TER2.SASC301H.LOAD,DISP=SHR
               //         DD DSN=TER2.SASC301H.LINKLIB,DISP=SHR
               //SYSTERM  DD SYSOUT=*
               //SYSPRINT DD SYSOUT=*
               //SYSUT1   DD UNIT=SYSDA,SPACE=(TRK,(10,10))
               //SYSUT2   DD UNIT=SYSDA,SPACE=(TRK,(10,10))
               //SYSLIN   DD DSN=&&OBJECT,SPACE=(3200,(10,10)),DISP=(MOD,PASS),
               //            UNIT=SYSDA
               //SYSLIB   DD DSN=TER2.SASC301H.MACLIBC,DISP=SHR
               //SYSDBLIB DD DSN=&&DBGLIB,SPACE=(4080,(20,20,1)),DISP=(,PASS),
               //            UNIT=SYSDA,DCB=(RECFM=U,BLKSIZE=4080)
               //SYSTMP01 DD UNIT=SYSDA,SPACE=(TRK,25)    VS1 ONLY
               //SYSTMP02 DD UNIT=SYSDA,SPACE=(TRK,25)     VS1 ONLY
               //SYSIN DD DATA,DLM=##
               /* This program is for Teradata MultiLoad INMOD testing using C
                  user exit routine.
                  When this routine is activated it looks at the content of the
                  function code passed (a->code) and depending on its value, it
                  0) initializes, i.e., opens a file, etc...
                  1) reads a record
                  5) acknowledges "close inmod" request.  The user exit routine
               must return "return code"(a->code)  and "length" (a->len). You
               should send return code = zero when no errors occur and non-zero for                an error. Teradata MultiLoad expects length = zero at the end of 
               file. Then it sends "CLOSE INMOD" request. THE USER EXIT routine 
               must explicitly return "return code" = ZERO to terminate the
               conversation.                                                */
               #include <stddef.h>
               #include <stdlib.h>
               #include <stdio.h>
               typedef unsigned short     Int16;
               typedef unsigned char      Int8;
               typedef unsigned long int  Int32;
               
               /* PASSING parameter structures */
               
               typedef struct {
                   Int32 code;
                   Int32 len;
                   Int8  buf[80];
               } inmodbuf;  
               
               typedef struct {
                   Int32 seq;
                   Int16 len;
                   char  param[80];
               } inmodpty;
                 
                 static FILE *IN;
                 static int count=0;
                 char *memcpy();
                  
               void _dynamn(a,b)
               inmodbuf *a;
               inmodpty *b;
               {int code=0; 
                char tempbuf[80];
                  
                 memcpy(tempbuf,a->buf,sizeof(a->buf));
                 tempbuf[79]='\0';
                 printf("BEGIN--> %d  %d  %s\n",a->code,a->len,tempbuf);
                 printf("     +++ %d  %d  %s\n",b->seq ,b->len,b->param);
               
                  code= (int) a->code;
                 switch (code) {
                  case 0:
                   /* Here you open the file and read the first record */
                   printf("## CODE=0, openinig...\n");
                   IN=fopen("ddn:INDATA","rb");
                   if (! ferror(IN)) {
                      if (! readrecord(a))
                         fclose(IN);
                   };
                  break;
                  case 1:
                   /* Teradata MultiLoad requested next record, read it */
                   printf("## CODE=1, reading...\n");
                   if (! readrecord(a))
                      fclose(IN);
                   break;
                  case 5:
                   /* Teradata MultiLoad is closing INMOD routine */
                   a->code=0;
                   a->len=0;
                   printf("## CODE=5, terminating...\n");
                   break;
                   default:
                   a->code=12; /* any number not = to zero */
                   a->len=0;
                   printf("##### UNKNOWN code ######\n");a->code=0;a->len=0;
                 }; 
               
                 memcpy(tempbuf,a->buf,sizeof(a->buf));
                 tempbuf[79]='\0';
                 printf("END  --> %d  %d  %s\n",a->code,a->len,tempbuf);
                 printf("     +++ %d  %d  %s\n",b->seq ,b->len,b->param);
               } 
                
                 
               int readrecord(a)
               inmodbuf *a;
               { 
               int rtn=0;
                char tempbuf[80];
               
                    if (fread((char *)&(a->buf),sizeof(a->buf),1,IN)) {
                      count++;
                  
                      memcpy(tempbuf,a->buf,sizeof(a->buf));
                      tempbuf[79]='\0';
                       printf("        %d  %s  \n",count,tempbuf);
                   
                       a->len=80;
                       a->code=0;
                       rtn=1; 
                    };
                     if ferror(IN) {
                        printf("==== error ====\n");
                       a->code=16; /* any non zero number */
                       a->len=0;
                    };
                    if feof(IN) {         /* EOF, set length = zero */
                       printf("=== EOF ===\n");
                       a->code=9;
                        a->len=9;
                    };
                    return(rtn);
               }   
               ##
               //LKED  EXEC PGM=LINKEDIT,PARM='LIST,MAP',COND=(8,LT,C)
               //SYSPRINT  DD SYSOUT=*,DCB=(RECFM=FBA,LRECL=121,BLKSIZE=1210)
               //SYSTERM   DD SYSOUT=*00153 
               //SYSLIN    DD DSN=*.C.SYSLIN,DISP=(OLD,PASS),VOL=REF=*.C.SYSLIN
               //          DD DDNAME=SYSIN
               //SYSLIB    DD DSN=TER2.SASC301H.SUBLIB,DISP=SHR
               //SYSUT1    DD DSN=&&SYSUT1,UNIT=SYSDA,DCB=BLKSIZE=1024,
               //          SPACE=(1024,(200,50))00158 
               //SYSLMOD DD  DSN=JCK.INMOD.LOAD(INMODG1),DISP=MOD,UNIT=3380,
               //          VOLUME=SER=TSO805
               //SYSIN     DD DATA,DLM=##
                  NAME INMODG1(R)
               ##
               //BDLDEL   EXEC PGM=IEFBR1400164 
               //BDLLOG   DD  DSN=JCK.INMOD.TDQ8.BDLLOG,
               //         DISP=(MOD,DELETE),UNIT=SYSDA,SPACE=(TRK,0)
               //BDLCAT   EXEC PGM=BLKMAIN
               //STEPLIB  DD  DSN=STV.GG00.APP.L,DISP=SHR
               //          DD  DSN=STV.TG00.APP.L,DISP=SHR
               //          DD  DSN=STV.RG00.APP.L,DISP=SHR
               
               //SYSPRINT  DD  SYSOUT=*00171 //BDLLOG    DD
                 DSN=JCK.INMOD.TDQ8.BDLLOG,DISP=(NEW,CATLG),
               //          UNIT=SYSDA,DCB=(RECFM=F,DSORG=PS,LRECL=8244),
               //          SPACE=(8244,(12,5))
               //SYSIN     DD  *
               //*****************************************************************
               //*THIS STEP WILL ONLY DROP THE TABLES IF MLOAD NOT IN APPLY PHASE*
               //*****************************************************************
               //CREATE   EXEC BTEQ 
               //STEPLIB  DD  DSN=STV.GG00.APP.L,DISP=SHR 
               //         DD  DSN=STV.TG00.APP.L,DISP=SHR
               //         DD  DSN=STV.RG00.APP.L,DISP=SHR
               //SYSPRINT DD  SYSOUT=*           
               //SYSABEND DD  SYSOUT=* 
               //SYSIN    DD  DATA,DLM=##
               .LOGON TDQ8/DBC,DBC;
               DROP TABLE XXXX.LOGTABLE;
               DROP TABLE XXXX.ET_INMODLC1;
               DROP TABLE XXXX.UV_INMODLC1;
               DROP TABLE XXXX.WT_INMODLC1;
               .QUIT;
               .LABEL NODROP;
               .EXIT 4;
               ##
               //******************************************************************
               //*                                                                *
               //*    RUN Teradata MultiLoad                                      *
               //*                                                                *
               //******************************************************************
               //LOADIT   EXEC PGM=MLOAD
               //STEPLIB  DD  DISP=SHR,DSN=STV.GG10.APP.L
               //         DD  DISP=SHR,DSN=STV.GG00.APP.L
               //         DD  DISP=SHR,DSN=STV.TG00.APP.L
               //         DD  DISP=SHR,DSN=STV.RG00.APP.L
               //         DD  DISP=SHR,DSN=TER2.SASC301H.LINKLIB
               //         DD  DISP=SHR,DSN=JCK.INMOD.LOAD,VOLUME=SER=TSO805,
               //             UNIT=338 
               //SYSPRINT DD  SYSOUT=*
               //SYSTERM  DD  SYSOUT=*
               //SYSOUT   DD  SYSOUT=*
               //SYSIN    DD  DATA,DLM=##
               .LOGTABLE XXXX.LOGTABLE;
               .LOGON TDQ8/XXXX,XXXX;
               /*  TEST DATAIN, DATALOC          */
               DROP TABLE XXXX.INMODLC1;
               CREATE TABLE INMODLC1 (F1 CHAR(10), F2 CHAR(70));
               .BEGIN IMPORT MLOAD TABLES INMODLC1;
               .Layout layname1;
               .Field L1Fld1 1 Char(10);
               .Field L1Fld2 * Char(70);
               .DML Label DML1;
               INSERT INMODLC1(F1,F2) VALUES (:L1FLD1, :L1FLD2);
               .IMPORT INMOD INMODG1 USING ("AAA" "BBB") LAYOUT LAYNAME1 APPLY DML1                    ;
               .End Mload;
               .LOGOFF;
               ##
               //INDATA  DD DATA,DLM=##
               01C       AAAAAAAAAAAAAAAA
               02C       BBBBBBBBBBBBBBBB
               03C       CCCCCCCCCCCCCCCC
               04C       DDDDDDDDDDDDDDDD00229 ##
               //SELECT   EXEC BTEQ
               //STEPLIB  DD  DSN=STV.GG00.APP.L,DISP=SHR
               //         DD  DSN=STV.TG00.APP.L,DISP=SHR
               //         DD  DSN=STV.RG00.APP.L,DISP=SHR
               //SYSPRINT DD  SYSOUT=*
               //SYSABEND DD  SYSOUT=*                                           
               //SYSIN    DD  DATA,DLM=##
               .LOGON TDQ8/XXXX,XXXX;
               SELECT * FROM INMODLC1;
               .LOGOFF;
               ##