Source Code

This code can be used and modified but is not guaranteed by IBM 

The source for the GENDDLSRC tool will be in three parts. The GENDDLSRC command source, the QGENDDL source for the CL program, and the GENDDL source for the C program that contains the QSQGNDDL API.

In the prolog for each set of source, there will be the command used to create the object. For example, the GENDDLSRC command source will contain the CRTCMD command to create the command.

References are used in the source for MYLIB and MYSRCFILE. The user can modify these names to their own library and source file.

The user is responsible for setting the authority they want for the objects and the user profile they want the programs to run under.
 

GENDDLSRC command source

/********************************************************************/
/*                                                                  */
/*  NAME:  GENDDLSRC - TYPE CMD                                     */
/*                                                                  */
/*  DESCRIPTION: COMMAND SOURCE FOR GENDDLSRC                       */
/*               COMMAND WILL PASS ARGUMENTS TO CL PROGRAM QGENDDL. */
/*               QGENDDL THEN CALLS C PROGRAM GENDDL THAT INVOKES   */
/*               THE QSQGNDDL API.                                  */
/*                                                                  */
/*  CRTCMD TO CREATE GENDDLSRC COMMAND                              */
/*                                                                  */
/*  CRTCMD CMD(MYLIB/GENDDLSRC) PGM(MYLIB/QGENDDL)                  */
/*         SRCFILE(MYLIB/MYSRCFILE) TEXT('GENERATE SQL STATEMENT')  */
/*                                                                  */
/********************************************************************/
GENDDLSRC: CMD   PROMPT('GENERATE DDL SOURCE - QSQGNDDL')             
                                                                      
           PARM  KWD(OBJNAME) +                             
                 TYPE(*CHAR) LEN(258) INLPMTLEN(25) +             
                 MIN(1) MAX(1) RSTD(*NO) VARY(*NO) PASSATR(*NO) + 
                 PROMPT('OBJECT NAME')                            
                                                                      
           PARM  KWD(OBJLIB) +                            
                 TYPE(*CHAR) LEN(258) INLPMTLEN(25) +            
                 MIN(1) MAX(1) RSTD(*NO) VARY(*NO) PASSATR(*NO) +
                 PROMPT('OBJECT LIBRARY')                           
                                                                 
           PARM  KWD(OBJTYPE) +                                  
                 TYPE(*CHAR) LEN(10) RSTD(*YES) MIN(1) MAX(1) + 
                 SPCVAL( +                                      
                        (*ALIAS ALIAS) +                        
                        (*CST CONSTRAINT) +                     
                        (*FUNC FUNCTION) +                      
                        (*INDEX INDEX) +                        
                        (*PROC PROCEDURE) +                     
                        (*SCHEMA SCHEMA) +                      
                        (*TABLE TABLE) +                        
                        (*TRG TRIGGER) +                        
                        (*TYPE TYPE) +                     
                        (*VIEW VIEW) +                     
                       ) +                                 
                  VARY(*NO) PASSATR(*NO) +  
                  PROMPT('OBJECT TYPE')     
                                                        
           PARM  KWD(SRCFILE) +                   
                 TYPE(*NAME) LEN(10) RSTD(*NO) +        
                 MIN(1) MAX(1) VARY(*NO) PASSATR(*NO) + 
                 PROMPT('TARGET SOURCE FILE')           
                                       
           PARM  KWD(SRCLIB) +                    
                 TYPE(*NAME) LEN(10) RSTD(*NO) +        
                 SPCVAL((*CURLIB) (*LIBL)) +            
                 MIN(1) MAX(1) VARY(*NO) PASSATR(*NO) + 
                 PROMPT('SOURCE FILE LIBRARY')          
                                       
           PARM  KWD(SRCMBR) +                    
                 TYPE(*NAME) LEN(10) RSTD(*NO) +        
                 SPCVAL((*FIRST) (*LAST)) +             
                 MIN(1) MAX(1) VARY(*NO) PASSATR(*NO) + 
                 PROMPT('SOURCE FILE MEMBER')           
                                                               
           PARM  KWD(STDOPT) +                                 
                 TYPE(*CHAR) LEN(1) RSTD(*YES) MIN(0) MAX(1) + 
                 DFT(*AS400) +                                 
                 SPCVAL((*AS400 0) +                           
                        (*DB2 1) +                             
                        (*ISO 2)) +                            
                 VARY(*NO) PASSATR(*NO) +           
                 PROMPT('STANDARDS OPTION')                    
                                                               
           PARM  KWD(NAMING) +                                 
                 TYPE(*CHAR) LEN(3) RSTD(*YES) MIN(0) MAX(1) + 
                 DFT(*SQL) +                                 
                 SPCVAL((*SQL SQL) +                           
                        (*SYS SYS)) +                          
                 VARY(*NO) PASSATR(*NO) +           
                 PROMPT('NAMING OPTION')                    
                                                                
           PARM  KWD(DATFMT) +                                 
                 TYPE(*CHAR) LEN(3) RSTD(*YES) MIN(0) MAX(1) + 
                 DFT(*JOB) +                                 
                 SPCVAL((*JOB JOB) +                           
                        (*ISO ISO) +                             
                        (*EUR EUR) +                             
                        (*JIS JIS) +                             
                        (*USA USA) +                             
                        (*MDY MDY) +                             
                        (*DMY DMY) +                             
                        (*YMD YMD) +                             
                        (*JUL JUL)) +                          
                 VARY(*NO) PASSATR(*NO) +           
                 PROMPT('DATE FORMAT')                    
                                                               
           PARM  KWD(DATSEP) +                                 
                 TYPE(*CHAR) LEN(1) RSTD(*YES) MIN(0) MAX(1) + 
                 DFT(*JOB) +                                 
                 SPCVAL((*JOB J) +                           
                        (*SLASH '/') +                             
                        (*PERIOD '.') +                             
                        (*COMMA ',') +                             
                        (*DASH  '-') +                             
                        (*BLANK ' ')) +                          
                 VARY(*NO) PASSATR(*NO) +           
                 PROMPT('DATE SEPARATOR')                    
                                                               
           PARM  KWD(TIMFMT) +                                 
                 TYPE(*CHAR) LEN(3) RSTD(*YES) MIN(0) MAX(1) + 
                 DFT(*ISO) +                                 
                 SPCVAL((*ISO ISO) +                           
                        (*EUR EUR) +                             
                        (*JIS JIS) +                             
                        (*USA USA) +                             
                        (*HMS HMS)) +                          
                 VARY(*NO) PASSATR(*NO) +           
                 PROMPT('TIME FORMAT')                    
                                                               
           PARM  KWD(TIMSEP) +                                 
                 TYPE(*CHAR) LEN(1) RSTD(*YES) MIN(0) MAX(1) + 
                 DFT(*JOB) +                                 
                 SPCVAL((*JOB J) +                           
                        (*COLON ':') +                             
                        (*PERIOD '.') +                             
                        (*COMMA ',') +                             
                        (*BLANK ' ')) +                          
                 VARY(*NO) PASSATR(*NO) +           
                 PROMPT('TIME SEPARATOR')                    
                                                              
           PARM  KWD(DECPOINT) +                                 
                 TYPE(*CHAR) LEN(1) RSTD(*YES) MIN(0) MAX(1) + 
                 DFT(*PERIOD) +                                 
                 SPCVAL((*PERIOD '.') +                           
                        (*COMMA ',')) +                          
                 VARY(*NO) PASSATR(*NO) +           
                 PROMPT('DECIMAL POINT')                    
                                                              
           PARM  KWD(DROPOPT) +                                 
                 TYPE(*CHAR) LEN(1) RSTD(*YES) MIN(0) MAX(1) + 
                 DFT(*NO) +                                 
                 SPCVAL((*NO 0) +                           
                        (*YES 1)) +                          
                 VARY(*NO) PASSATR(*NO) +           
                 PROMPT('DROP STATEMENT GENERATED')                    
                                                              
           PARM  KWD(COMMENT) +                                 
                 TYPE(*CHAR) LEN(1) RSTD(*YES) MIN(0) MAX(1) + 
                 DFT(*NO) +                                 
                 SPCVAL((*NO 0) +                           
                        (*YES 1)) +                          
                 VARY(*NO) PASSATR(*NO) +           
                 PROMPT('COMMENT ON GENERATED')                    
                                                              
           PARM  KWD(LABEL) +                                 
                 TYPE(*CHAR) LEN(1) RSTD(*YES) MIN(0) MAX(1) + 
                 DFT(*NO) +                                 
                 SPCVAL((*NO 0) +                           
                        (*YES 1)) +                          
                 VARY(*NO) PASSATR(*NO) +           
                 PROMPT('LABEL ON GENERATED')                    
                                                              
           PARM  KWD(SYSNAMOPT) +                                 
                 TYPE(*CHAR) LEN(1) RSTD(*YES) MIN(0) MAX(1) + 
                 DFT(*NO) +                                 
                 SPCVAL((*NO 0) +                           
                        (*YES 1)) +                          
                 VARY(*NO) PASSATR(*NO) +           
                 PROMPT('RENAME STATEMENT GENERATED')                    
                                                               
           PARM  KWD(APIFMT) +                                 
                 TYPE(*CHAR) LEN(10) RSTD(*YES) MIN(0) MAX(1) +
                 DFT(*SQLR0100) +                              
                 SPCVAL((*SQLR0100 SQLR0100)) +                
                 VARY(*NO) PASSATR(*NO) +           
                 PROMPT('API FORMAT NAME')                     











CL program source for the QGENDDL 

/********************************************************************/
/*                                                                  */
/*  NAME:  QGENDDL CL PROGRAM – CPP FOR GENDDLSRC COMMAND           */
/*         TYPE - CLP                                               */ 
/*                                                                  */
/*  DESCRIPTION:                                                    */
/*     EXTRACTS TIME AND DATE VALUES FOR THE JOB                    */
/*     ADD MEMBER TO SOURCE FILE IF NEEDED                          */
/*     CALLS C PROGRAM GENDDL                                       */
/*     SENDS SUCCESS OR FAIL MESSAGE                                */
/*                                                                  */
/*  CREATE CL PROGRAM USING CRTCLPGM COMMAND                        */
/*                                                                  */
/*  CRTCLPGM PGM(MYLIB/QGENDDL) SRCFILE(MYLIB/MYSRCFILE)            */
/*                                                                  */
/********************************************************************/
PGM PARM(&OBJNAME +                                                   
         &OBJLIB  +                                                   
         &OBJTYPE +                                                   
         &SRCFILE +                                                   
         &SRCLIB  +                                                   
         &SRCMBR  +                                                   
         &STDOPT +                                                    
         &NAMOPT +                                                    
         &DATFMT +                                                    
         &DATSEP +                                                    
         &TIMFMT +                                                    
         &TIMSEP +                                                    
         &DECPT +                                                    
         &DROPOPT +                        
         &CMNTON +                        
         &LABELON +                       
         &SYSNAMO +                        
         &APIFMT)                                                     
                                            
  DCL VAR(&OBJNAME) TYPE(*CHAR) LEN(258)    
  DCL VAR(&OBJLIB)  TYPE(*CHAR) LEN(258)    
  DCL VAR(&OBJTYPE) TYPE(*CHAR) LEN(10)     
  DCL VAR(&SRCFILE) TYPE(*CHAR) LEN(10)     
  DCL VAR(&SRCLIB)  TYPE(*CHAR) LEN(10)     
  DCL VAR(&SRCMBR)  TYPE(*CHAR) LEN(10)     
  DCL VAR(&STDOPT)  TYPE(*CHAR) LEN(1)      
  DCL VAR(&NAMOPT)  TYPE(*CHAR) LEN(3)      
  DCL VAR(&DATFMT)  TYPE(*CHAR) LEN(3)      
  DCL VAR(&DATSEP)  TYPE(*CHAR) LEN(1)      
  DCL VAR(&TIMFMT)  TYPE(*CHAR) LEN(3)      
  DCL VAR(&TIMSEP)  TYPE(*CHAR) LEN(1)      
  DCL VAR(&DECPT)   TYPE(*CHAR) LEN(1)      
  DCL VAR(&DROPOPT) TYPE(*CHAR) LEN(1)      
  DCL VAR(&CMNTON)  TYPE(*CHAR) LEN(1)      
  DCL VAR(&LABELON) TYPE(*CHAR) LEN(1)      
  DCL VAR(&SYSNAMO) TYPE(*CHAR) LEN(1)      
  DCL VAR(&APIFMT)  TYPE(*CHAR) LEN(10)     
                                            
  DCL VAR(&MODOBJNAME) TYPE(*CHAR) LEN(258) 
  DCL VAR(&MODOBJLIB)  TYPE(*CHAR) LEN(258) 
  DCL VAR(&MODOBJTYPE) TYPE(*CHAR) LEN(10)  
  DCL VAR(&MODSRCFILE) TYPE(*CHAR) LEN(10)  
  DCL VAR(&MODSRCLIB)  TYPE(*CHAR) LEN(10)  
  DCL VAR(&MODSRCMBR)  TYPE(*CHAR) LEN(10)  
  DCL VAR(&MODSTDOPT)  TYPE(*CHAR) LEN(1)               
  DCL VAR(&MODNAMOPT)  TYPE(*CHAR) LEN(3)               
  DCL VAR(&MODDATFMT)  TYPE(*CHAR) LEN(3)               
  DCL VAR(&MODDATSEP)  TYPE(*CHAR) LEN(1)      
  DCL VAR(&MODTIMFMT)  TYPE(*CHAR) LEN(3)      
  DCL VAR(&MODTIMSEP)  TYPE(*CHAR) LEN(1)      
  DCL VAR(&MODDECPT)   TYPE(*CHAR) LEN(1)      
  DCL VAR(&MODDROPOPT) TYPE(*CHAR) LEN(1)      
  DCL VAR(&MODCMNTON)  TYPE(*CHAR) LEN(1)      
  DCL VAR(&MODLABELON) TYPE(*CHAR) LEN(1)      
  DCL VAR(&MODSYSNAMO) TYPE(*CHAR) LEN(1)      
  DCL VAR(&MODAPIFMT)  TYPE(*CHAR) LEN(10)              

  DCL VAR(&RTVDATFMT) TYPE(*CHAR) LEN(4)               
  DCL VAR(&RTVDATSEP) TYPE(*CHAR) LEN(1)               
  DCL VAR(&RTVTIMSEP) TYPE(*CHAR) LEN(1)               
                                           
  DCL VAR(&MSGID) TYPE(*CHAR) LEN(7)               
  DCL VAR(&MSGDATA) TYPE(*CHAR) LEN(500)               
                                           
  MONMSG MSGID(CPF9999) EXEC(GOTO ERREXIT) 
                     
  CHGVAR VAR(&MODOBJNAME) VALUE(&OBJNAME)                     
  CHGVAR VAR(&MODOBJLIB)  VALUE(&OBJLIB)                      
  CHGVAR VAR(&MODOBJTYPE) VALUE(&OBJTYPE)                     
  CHGVAR VAR(&MODSRCFILE) VALUE(&SRCFILE)                     
  CHGVAR VAR(&MODSRCLIB)  VALUE(&SRCLIB)                      
  CHGVAR VAR(&MODSRCMBR)  VALUE(&SRCMBR)                      
  CHGVAR VAR(&MODSTDOPT)  VALUE(&STDOPT)  
  CHGVAR VAR(&MODNAMOPT)  VALUE(&NAMOPT)  
  CHGVAR VAR(&MODDROPOPT) VALUE(&DROPOPT)  
  CHGVAR VAR(&MODCMNTON)  VALUE(&CMNTON)  
  CHGVAR VAR(&MODLABELON) VALUE(&LABELON)  
  CHGVAR VAR(&MODSYSNAMO) VALUE(&SYSNAMO)  
  CHGVAR VAR(&MODAPIFMT)  VALUE(&APIFMT)                      
  
  IF COND(&DATFMT = 'JOB') THEN(DO)
    RTVJOBA DATFMT(&RTVDATFMT)
    CHGVAR VAR(&MODDATFMT) VALUE(%SST(&RTVDATFMT 2 3))
    ENDDO
  ELSE CMD(CHGVAR VAR(&MODDATFMT) VALUE(&DATFMT))       
  
  IF COND(&DATSEP = 'J') THEN(DO)
    RTVJOBA DATSEP(&RTVDATSEP)
    CHGVAR VAR(&MODDATSEP) VALUE(&RTVDATSEP)
    ENDDO
  ELSE CMD(CHGVAR VAR(&MODDATSEP) VALUE(&DATSEP))       
  
  IF COND(&TIMSEP = 'J') THEN(DO)
    RTVJOBA TIMSEP(&RTVTIMSEP)
    CHGVAR VAR(&MODTIMSEP) VALUE(&RTVTIMSEP)
    ENDDO
  ELSE CMD(CHGVAR VAR(&MODTIMSEP) VALUE(&TIMSEP))       
  
  CHGVAR VAR(&MODTIMFMT) VALUE(&TIMFMT)        
  CHGVAR VAR(&MODDECPT) VALUE(&DECPT)        
                                                            
  CHKOBJ OBJ(&MODSRCLIB/&MODSRCFILE) OBJTYPE(*FILE) MBR(*NONE)      
  MONMSG MSGID(CPF9810 CPF9801) EXEC(GOTO ERREXIT)                  
                                                                    
  CHKOBJ OBJ(&MODSRCLIB/&MODSRCFILE) OBJTYPE(*FILE) MBR(&MODSRCMBR) 
  MONMSG MSGID(CPF9815) EXEC(GOTO GENADDMBR)                        
                                                             
  GOTO GENCALL /* File, Library, Member exist */                    
                                                                    
  GENADDMBR:                                                        
  ADDPFM FILE(&MODSRCLIB/&MODSRCFILE) MBR(&MODSRCMBR)               
                                                                    
  GENCALL:                                                          
  CALL PGM(MYLIB/GENDDL) +       
         PARM(&MODOBJNAME +     
              &MODOBJLIB  +     
              &MODOBJTYPE +     
              &MODSRCFILE +     
              &MODSRCLIB  +     
              &MODSRCMBR  +     
              &MODSTDOPT  +     
              &MODNAMOPT  +     
              &MODDATFMT  +     
              &MODDATSEP  +     
              &MODTIMFMT  +     
              &MODTIMSEP  +     
              &MODDECPT   +     
              &MODDROPOPT +     
              &MODCMNTON  +     
              &MODLABELON +     
              &MODSYSNAMO +     
              &MODAPIFMT  +
              &MSGID +
              &MSGDATA +
             )                  

  IF COND(&MSGID = '       ') + 
    THEN(DO)                     
    SNDPGMMSG MSG('QSQGNDDL WAS SUCCESSFUL')               
    ENDDO                                                  
  ELSE CMD(DO)                                             
    SNDPGMMSG MSG('QSQGNDDL FAILED')
    IF COND(%SST(&MSGID 1 3) = 'SQL') + 
      THEN(DO)
      SNDPGMMSG MSGID(&MSGID) MSGF(QSQLMSG) +
        MSGTYPE(*ESCAPE) MSGDTA(&MSGDATA)
      ENDDO 
    ELSE CMD(DO)
      SNDPGMMSG MSGID(&MSGID) MSGF(QCPFMSG) +
        MSGTYPE(*ESCAPE) MSGDTA(&MSGDATA)
      ENDDO 
    ENDDO
 
GENEXIT:
  RETURN
                                                       
ERREXIT:
  SNDPGMMSG MSG('QSQGNDDL FAILED')                       
  RETURN

ENDPGM    






























C program source for the GENDDL 

/********************************************************************/ 
/*                                                                  */ 
/*  NAME:  GENDDL - TYPE C                                          */ 
/*                                                                  */ 
/*  DESCRIPTION:                                                    */ 
/*     GENERATES DDL USING THE QSQGNDDL  API                        */ 
/*                                                                  */ 
/*  CREATE C PROGRAM USING THE CRTSQLCI COMMAND                     */ 
/*                                                                  */ 
/*  CRTSQLCI OBJ(MYLIB/GENDDL)                                      */
/*           SRCFILE(MYLIB/MYSRCFILE) COMMIT(*NONE)                 */
/*           OBJTYPE(*PGM) OUTPUT(*PRINT) DBGVIEW(*SOURCE)          */
/*           OPTION(*XREF *GEN *SYS *SECLVL)                        */
/*                                                                  */ 
/********************************************************************/ 
                                                                       
#include <string.h>   /* used for strcpy() */                          
#include <stdio.h>                                                     
#include <stdlib.h>                                                    
#include <QSQGNDDL.h>   /* defines template for QSQGNDDL */            
#include <QUSEC.h>      /* defines error code parameter */             
                                                                       
                                                                       
/********************************************************************/
/*  GLOBAL VARIABLES                                                */
/********************************************************************/
char text[300];                                                       
char stmt[300];                                                       
                                                                      
char objname[258];                                                    
char objlib[258];                                                     
char objtype[10];                                                     
char srcfile[10];                                                     
char srclib[10];                                                      
char srcmbr[10];                                                      
char stdopt[1];                                                       
char namopt[3];                                                       
char datfmt[3];                                                       
char datsep[1];                                                       
char timfmt[3];                                                       
char timsep[1];                                                       
char decpt[1];                                                       
char dropopt[1];                                                       
char cmnton[1];                                                       
char labelon[1];                                                       
char sysnamopt[1];                                                       
char apifmt[10];                                                      
char msgid[7];
int  msgdta_off; 
int  msgdta_len;
char msg_data[500];                                                           
                                                                      
_Packed struct InputTemplate                                          
 {                                   
  Qsq_SQLR0100_t  fixed;            
  char            reserved[10];     
 };                                 
                                    
_Packed struct ErrorCode            
 {                                  
  Qus_ERRC0200_t  fixed;            
  char            msgdata[500];     
 };                                 
                                    
struct InputTemplate  intemp;       
int    length;                      
char   formatName[9];               
struct ErrorCode  errcode;          
                                    
/********************************************************************/
/*  HOST VARIABLES                                                  */
/********************************************************************/
long hlong;                                                           
                                                                      
exec sql INCLUDE SQLCA;                                               
exec sql INCLUDE SQLDA;                                               
                                                                      
exec sql SET OPTION SQLCURRULE = *STD;                                
                                                                      
/********************************************************************/
/*                       MAIN routine                               */
/********************************************************************/
int main(int argc, char* argv[])                                      
 {                                                                    
                                                                      
  exec sql WHENEVER SQLERROR CONTINUE;                                
                                                        
  /***************************************************/ 
  /* Copy INPUT ARGS/PARMS to local Variables ------ */ 
  /***************************************************/ 
  memcpy(objname,   argv[1] ,258);                         
  memcpy(objlib,    argv[2] ,258);                         
  memcpy(objtype,   argv[3] ,10);                          
  memcpy(srcfile,   argv[4] ,10);                          
  memcpy(srclib,    argv[5] ,10);                          
  memcpy(srcmbr,    argv[6] ,10);                          
  memcpy(stdopt,    argv[7] ,1);                           
  memcpy(namopt,    argv[8] ,3);                           
  memcpy(datfmt,    argv[9] ,3);                           
  memcpy(datsep,    argv[10],1);                           
  memcpy(timfmt,    argv[11],3);                           
  memcpy(timsep,    argv[12],1);                           
  memcpy(decpt,     argv[13],1);                           
  memcpy(dropopt,   argv[14],1);                           
  memcpy(cmnton,    argv[15],1);                           
  memcpy(labelon,   argv[16],1);                           
  memcpy(sysnamopt, argv[17],1);                           
  memcpy(apifmt,    argv[18],10);                          
  memcpy(msgid,     "       ",7);                          
  memcpy(msg_data,  " ",500);                          
                                                        
  /***************************************************/ 
  /* Copy INPUT ARGS/PARMS to GENDDL Input Template  */ 
  /***************************************************/                
  memset(intemp.fixed.Object_Name, ' ', 258);                          
  memcpy(intemp.fixed.Object_Name, objname, sizeof(objname));          
  memset(intemp.fixed.Object_Library, ' ', 258);                       
  memcpy(intemp.fixed.Object_Library, objlib, sizeof(objlib));         
  memcpy(intemp.fixed.Object_Type,         objtype     , 10);          
  memcpy(intemp.fixed.Source_File_Name,    srcfile     , 10);          
  memcpy(intemp.fixed.Source_File_Library, srclib      , 10);          
  memcpy(intemp.fixed.Source_File_Member,  srcmbr      , 10);          
  memcpy(intemp.fixed.Naming_Option,       namopt      ,  3);          
                                                                      
  /***************************************************/                
  /* Hardcode Set QSQGNDDL Options ----------------- */                
  /* If the user wants to pass in values, then the   */                
  /* GENDDLSRC command and QGENDDL CPP must have     */                
  /* changes to them.                                */                
  /***************************************************/                
  intemp.fixed.Severity_Level = 10;           /* allow info errors  */
  intemp.fixed.Replace_Option = '1';          /* clear file first   */
  intemp.fixed.Statement_Formatting_Option = '0'; /* no extra chars */
  intemp.fixed.Message_Level = 0;             /* generate all msgs  */  
  intemp.fixed.Header_Option = '1';           /* generate header    */  
  intemp.fixed.Trigger_Option = '1';          /* generate trigger   */  
  intemp.fixed.Constraint_Option = '1';       /* generate constraint*/  
 
  /***************************************************/                
  /* Set Formats and Seperators -------------------- */                
  /***************************************************/                
  memcpy(intemp.fixed.Date_Format, datfmt, 3);                          
  memcpy(intemp.fixed.Time_Format, timfmt, 3); 
  intemp.fixed.Date_Separator = *datsep;                          
  intemp.fixed.Time_Separator = *timsep;                                   
  intemp.fixed.Decimal_Point = *decpt;                                    
                                                                     
  /***************************************************/                 
  /* Set GENDDL STDS Format ------------------------ */                 
  /* 0 -- AS/400 standard                            */                 
  /* 1 -- DB2 standard                               */                 
  /* 2 -- ISO standard                               */                 
  /***************************************************/                 
  intemp.fixed.Standards_Option = *stdopt;                                
                                                                         
  /***************************************************/                  
  /* Set Other GENDDL Options ---------------------- */                  
  /***************************************************/                  
  intemp.fixed.Drop_Option = *dropopt;         /* DROP stmts not gen*/   
  intemp.fixed.Comment_Option = *cmnton;       /* must be 0 for ISO */ 
  intemp.fixed.Label_Option = *labelon;        /* must be 0 for ISO */  
  intemp.fixed.System_Name_Option = *sysnamopt;/* must be 0 for ISO */  
                                                                       
  /***************************************************/                  
  /* Set Size and Error Data ----------------------- */                  
  /***************************************************/                  
  length = sizeof(intemp);                                               
  memcpy(formatName, "SQLR0100", 8);                                     
                                                                         
  errcode.fixed.Bytes_Provided = sizeof(errcode);                        
  errcode.fixed.Key = -1;                                                
  errcode.fixed.Exception_Id[0] = ' ';                                   
                                                                         
  /***************************************************/                  
  /* Call the QSQGNDDL API ------------------------- */                  
  /***************************************************/    
  QSQGNDDL( &intemp, &length, formatName, &errcode );      
                                                           
  /***************************************************/    
  /* Check for errors ------------------------------ */    
  /***************************************************/    
  if ((errcode.fixed.Bytes_Available != 0) ||              
      (errcode.fixed.Exception_Id[0] != ' '))              
  {                                                        
    memcpy(text, "QSQGNDDL Failed     " ,20);              
    printf(text, "QSQGNDDL Failed %s");                    
    memcpy(msgid, errcode.fixed.Exception_Id, 7);            
    printf(msgid, "QSQGNDDL Failed %s");  
    memcpy(argv[19], msgid, 7);                  
    msgdta_off = errcode.fixed.Offset_Exc_Data;
    msgdta_len = errcode.fixed.Length_Exc_Data;
    memcpy(msg_data, errcode.msgdata, msgdta_len);            
    memcpy(argv[20], msg_data, msgdta_len);                  
   return 1;                                              
  }                                                        
  else                                                     
  {                                                        
    memcpy(text, "QSQGNDDL Successful " ,20);              
    printf(text, "QSQGNDDL Successful %s");                
  }                                                           
                                                              
  return 0;                                                   
                                                              
/***************************************************/         
/* ERROR ----------------------------------------- */         
/***************************************************/         
error:                                                        
  printf(text, "Bad SQLCODE received, SQLCODE = %d", SQLCODE); 
  return 1;                                                   
                                                              
}                                                           

Advertisement

IBMi News Sign Up Today! Past News Letters
not mf or hp