Code:
- h option(*nodebugio)
- ‚*---------------------------------------------------------------*
- ‚* Program Name: CRTTOPFR Program Author: Tommy Holden *
- ‚* Program Date: 09/01/2004 Program Purpose: Create Output *
- ‚* File From "Template" File *
- ‚*---------------------------------------------------------------*
- ‚* Modifications Section *
- ‚*---------------------------------------------------------------*
- ‚* Programmer: Mod. Mark: *
- ‚* Date of Change: 00/00/1999 Project Number: *
- ‚* Purpose Of Changes: *
- ‚* Description: *
- *---------------------------------------------------------------*
-
- * Work Fields
- DCreateString s 30000a Varying
- DFieldName s 10a
- DColType s 8a
- DLength s 9s 0
- DDecimals s 9s 0
- DColNo s 9s 0
- d n2 s 4b 0
-
- * Template File DS
- D ds
- D FromFileDS 1 20a
- D FileName 1 10a
- D LibName 11 20a
-
- * Output File DS
- D ds
- D ToFileDS 1 20a
- D ToFileName 1 10a
- D ToLib 11 20a
-
- * Parameter Entry
- C *Entry PList
- C Parm FromFile 20
- C Parm ToFile 20
-
- * Load File DS's
- c Eval FromFileDS=FromFile
- c Eval ToFileDS=ToFile
-
- * SQL Error Trapping
- c/exec sql
- c+ whenever sqlerror continue
- c/end-exec
-
- * Declare SQL Cursor For Retrieving File Attributes From SYSCOLUMNS
- c/exec sql
- c+ declare FileCursor Cursor For
- c+ Select Sys_CName,ColType,Length,Scale,ColNo
- c+ From SYSCOLUMNS
- c+ Where Sys_DName= :LibName and Sys_TName= :FileName
- c+ Order By ColNo
- c+ For Fetch Only
- c/end-exec
-
- * Open SQL Cursor
- c/exec sql
- c+ Open FileCursor
- c/end-exec
-
- * Open SQL Cursor Failed
- c If SQLCOD<0
- c ExSR Terminate
- c EndIf
-
- * Initialize The SQL Statement Variable
- c Eval CreateString='CREATE TABLE '
- c +%Trim(ToLib)+'/'+%Trim(ToFileName)
- c +' ('
-
- * Load All Fields Into The SQL Variable
- c DoU SQLCOD=100
-
- * Read The SQL Cursor
- c/exec sql
- c+ Fetch FileCursor Into :FieldName,:ColType,
- c+ :Length,:Decimals:n2,:ColNo
- c/end-exec
-
- * End Of The SQL Cursor Data
- c If SQLCOD=100
- c ExSR Terminate
- c EndIf
-
- * SQL Error Occured Get Next Record
- c If SQLCOD<0
- c Iter
- c EndIf
-
- * If Column Type In SYSCOLUMNS is NOT TIMESTMP...
- c If ColType<>'TIMESTMP'
- c Eval CreateString=%Trim(CreateString)+
- c %Trim(FieldName)+' '
- c +%Trim(ColType)+' ('
- c +%Trim(%editc(Length:'Z'))+' '
- c Else
- ‚* If Column Type In SYSCOLUMNS is TIMESTMP...
- * Add The TIMESTAMP Column Type...
- c Eval CreateString=%Trim(CreateString)+
- c %Trim(FieldName)+' TIMESTAMP'
- c +' NOT NULL WITH DEFAULT,'
- c Iter
- c EndIf
-
- * If Column Type In SYSCOLUMNS is Numeric
- c If ColType<>'CHAR'
- c If Decimals<>0
- c Eval CreateString=%Trim(CreateString)
- c +', '+%Trim(%Editc(Decimals:'Z'))
- c Else
- c Eval CreateString=%Trim(CreateString)
- c +',0 '
- c EndIf
- c EndIf
-
- * Terminate This Field's Creation String
- c Eval CreateString=%Trim(CreateString)
- c +') NOT NULL WITH DEFAULT,'
- c EndDo
-
- * Terminate
- C Terminate BegSR
-
- * If End Of SQL Cursor, Terminate the Create Table String
- C If SQLCOD=100
- c Eval CreateString=%Trim(CreateString)
- c +' MNLIB CHAR (10) NOT NULL WITH '
- C +'DEFAULT)'
-
- * Prepare The Create Table as SQL
- c/exec sql
- c+ Prepare BuildFile From :CreateString
- c/end-exec
-
- * Execute The Create Table
- c/exec sql
- c+ Execute BuildFile
- c/end-exec
- c EndIf
-
- * Exit
- c Eval *InLR=*On
- c Return
- c EndSR
-
|
|