-
Notifications
You must be signed in to change notification settings - Fork 19
/
DB2UTILC.CLLE
121 lines (108 loc) · 6.07 KB
/
DB2UTILC.CLLE
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
PGM PARM(&SQL &OUTPUTFMT &JSONFMT &OUTPUTFILE &OPTION +
&SETPKGPATH &DSPSTDOUT &LOGSTDOUT +
&PRTSTDOUT &DLTSTDOUT &IFSSTDOUT &IFSFILE +
&IFSOPT &CCSID &PRTSPLF &PRTUSRDTA +
&PRTTXT &PRTHOLD &PRTOUTQALL &PASEJOBNAM +
&VIEWOUTPUT)
/*----------------------------------------------------------------------------*/
/* Variables */
/*----------------------------------------------------------------------------*/
DCL VAR(&VIEWOUTPUT) TYPE(*CHAR) LEN(4)
DCL VAR(&SQL) TYPE(*CHAR) LEN(1024)
DCL VAR(&OUTPUTFILE) TYPE(*CHAR) LEN(255)
DCL VAR(&OUTPUTFMT) TYPE(*CHAR) LEN(10)
DCL VAR(&JSONFMT) TYPE(*CHAR) LEN(10)
DCL VAR(&JSONEXPORT) TYPE(*CHAR) LEN(100)
DCL VAR(&OPTION) TYPE(*CHAR) LEN(10)
DCL VAR(&PRTHOLD) TYPE(*CHAR) LEN(4)
DCL VAR(&PRTOUTQALL) TYPE(*CHAR) LEN(20)
DCL VAR(&PRTOUTQ) TYPE(*CHAR) LEN(10)
DCL VAR(&PRTOUTQLIB) TYPE(*CHAR) LEN(10)
DCL VAR(&CMDLINE) TYPE(*CHAR) LEN(5000)
DCL VAR(&CURLCMDLIN) TYPE(*CHAR) LEN(5000)
DCL VAR(&SETPKGPATH) TYPE(*CHAR) LEN(4)
DCL VAR(&DSPSTDOUT) TYPE(*CHAR) LEN(4)
DCL VAR(&LOGSTDOUT) TYPE(*CHAR) LEN(4)
DCL VAR(&DLTSTDOUT) TYPE(*CHAR) LEN(4)
DCL VAR(&PRTSTDOUT) TYPE(*CHAR) LEN(4)
DCL VAR(&IFSSTDOUT) TYPE(*CHAR) LEN(4)
DCL VAR(&IFSOPT) TYPE(*CHAR) LEN(10)
DCL VAR(&IFSFILE) TYPE(*CHAR) LEN(255)
DCL VAR(&PRTSPLF) TYPE(*CHAR) LEN(10)
DCL VAR(&PRTUSRDTA) TYPE(*CHAR) LEN(10)
DCL VAR(&PRTTXT) TYPE(*CHAR) LEN(30)
DCL VAR(&QT) TYPE(*CHAR) LEN(1) VALUE('''')
DCL VAR(&CCSID) TYPE(*CHAR) LEN(10)
DCL VAR(&PASEJOBNAM) TYPE(*CHAR) LEN(10)
/*----------------------------------------------------------------------------*/
/* MONITOR FOR GLOBAL ERROR. ANY ERROR IS A CAUSE TO BLOW OUT OF HERE */
/* AND WE WANT A GRACEFUL EXIT. */
/*----------------------------------------------------------------------------*/
MONMSG MSGID(CPF0000) EXEC(GOTO CMDLBL(ERRORS))
/*----------------------------------------------------------------------------*/
/* Extract output queue info. */
/*----------------------------------------------------------------------------*/
CHGVAR VAR(&PRTOUTQ) VALUE(%SST(&PRTOUTQALL 1 10))
CHGVAR VAR(&PRTOUTQLIB) VALUE(%SST(&PRTOUTQALL 11 10))
/*----------------------------------------------------------------------------*/
/* MAIN */
/*----------------------------------------------------------------------------*/
/* Output file is required */
IF COND(&OUTPUTFILE *EQ ' ') THEN(DO)
SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA('Output +
file name must be specified') +
MSGTYPE(*ESCAPE)
ENDDO
/* Check for output file and replace if selected and exists */
QSHONI/QSHIFSCHK FILNAM(&OUTPUTFILE)
/* Not Found. Do nothing special */
MONMSG MSGID(CPF9898) EXEC(DO)
ENDDO
/* Found. Delete if selected */
MONMSG MSGID(CPF9897) EXEC(DO)
/* Delete output file if found and replace */
IF COND(&OPTION *EQ *REPLACE) THEN(DO)
ERASE OBJLNK(&OUTPUTFILE)
ENDDO
ENDDO
/* Build db2util command line to pass to qshell or bash */
/* with JSON formatting export statement */
IF COND(&OUTPUTFMT *EQ 'json') THEN(DO)
CHGVAR VAR(&CURLCMDLIN) VALUE('export +
DB2UTIL_JSON_CONTAINER=' |< &JSONFMT |< +
'; db2util -o' |> &OUTPUTFMT |> '"' |< +
&SQL |< '" >>' |> &OUTPUTFILE)
ENDDO
/* Build db2util command line to pass to qshell or bash */
/* with JSON formatting export statement */
IF COND(&OUTPUTFMT *NE 'json') THEN(DO)
CHGVAR VAR(&CURLCMDLIN) VALUE('db2util -o' |> +
&OUTPUTFMT |> '"' |< &SQL |< '" >>' |> +
&OUTPUTFILE)
ENDDO
/* Run the db2util command via QSHBASH */
QSHONI/QSHBASH CMDLINE(&CURLCMDLIN) +
SETPKGPATH(&SETPKGPATH) +
DSPSTDOUT(&DSPSTDOUT) +
LOGSTDOUT(&LOGSTDOUT) +
PRTSTDOUT(&PRTSTDOUT) +
DLTSTDOUT(&DLTSTDOUT) +
IFSSTDOUT(&IFSSTDOUT) IFSFILE(&IFSFILE) +
IFSOPT(&IFSOPT) CCSID(&CCSID) +
PRTSPLF(&PRTSPLF) PRTUSRDTA(&PRTUSRDTA) +
PRTTXT(&PRTTXT) PRTHOLD(&PRTHOLD) +
PRTOUTQ(&PRTOUTQLIB/&PRTOUTQ) +
MBROPT(*REPLACE) PASEJOBNAM(&PASEJOBNAM)
/* View output file after creation if selected */
IF COND(&VIEWOUTPUT *EQ *YES) THEN(DO)
EDTF STMF(&OUTPUTFILE)
ENDDO
SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA('db2util +
command completed to file' |> +
&OUTPUTFILE) MSGTYPE(*COMP)
RETURN
ERRORS:
SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA('db2util +
command failed') MSGTYPE(*ESCAPE)
ENDPGM:
ENDPGM