如何複製報表並可更改報表屬性(如報表擁有人, 報表名稱...) (Command DUPCHGSPLF)?
要複製報表並可更改報表屬性(如報表擁有人, 報表名稱...), 有多種方式, 利用
CPYSPLF, OVRPRTF, 及 CPYF 三個指令組合方式也可以完成, 但繁瑣耗時, 這裡介
紹直接用 API , 並製作成指令 DUPCHGSPLF.
File : QCLSRC
Member: DUPCHGSPLF
Type : CLP
Usage : CRTCLPGM DUPCHGSPLF
Version: ALL
/* Program : DUPCHGSPLF */
/* System : iSeries */
/* */
/* Description : Duplicate and Change Spooled File */
/* */
/* To compile : */
/* */
/* CRTCLPGM PGM(XXX/DUPCHGSPLF) SRCFILE(XXX/QCLSRC) */
/* */
DUPCHGSPLF: PGM PARM(&JOB &SPLFILE &SPLNBRBIN &LPI &CPI +
&FONT &PAGRTT &OUTQ &DRAWER &FORMTYPE +
&USRDTA &HOLD &SAVE &DUPLEX &OUTBIN +
&NEWUSER &NEWSPLNAME &DLTSPLF)
/* Parameters */
DCL VAR(&JOB) TYPE(*CHAR) LEN(26)
DCL VAR(&SPLFILE) TYPE(*CHAR) LEN(10)
DCL VAR(&SPLNBRBIN) TYPE(*CHAR) LEN(4)
DCL VAR(&LPI) TYPE(*CHAR) LEN(4)
DCL VAR(&CPI) TYPE(*CHAR) LEN(4)
DCL VAR(&PAGRTT) TYPE(*CHAR) LEN(4)
DCL VAR(&DRAWER) TYPE(*CHAR) LEN(4)
DCL VAR(&FONT) TYPE(*CHAR) LEN(5)
DCL VAR(&OUTQ) TYPE(*CHAR) LEN(20)
DCL VAR(&FORMTYPE) TYPE(*CHAR) LEN(10)
DCL VAR(&USRDTA) TYPE(*CHAR) LEN(10)
DCL VAR(&HOLD) TYPE(*CHAR) LEN(10)
DCL VAR(&SAVE) TYPE(*CHAR) LEN(10)
DCL VAR(&DUPLEX) TYPE(*CHAR) LEN(10)
DCL VAR(&OUTBIN) TYPE(*CHAR) LEN(4)
DCL VAR(&NEWUSER) TYPE(*CHAR) LEN(10)
DCL VAR(&NEWSPLNAME) TYPE(*CHAR) LEN(10)
DCL VAR(&DLTSPLF) TYPE(*CHAR) LEN(10)
/* Variables */
DCL VAR(&SPLNBRDEC) TYPE(*DEC) LEN(8 0)
DCL VAR(&SPLNBRCHR) TYPE(*CHAR) LEN(8)
DCL VAR(&JOBNAME) TYPE(*CHAR) LEN(10)
DCL VAR(&JOBUSER) TYPE(*CHAR) LEN(10)
DCL VAR(&JOBNBR) TYPE(*CHAR) LEN(6)
DCL VAR(&HANDLE) TYPE(*CHAR) LEN(4) /* Spooled +
file handle */
DCL VAR(&BUFFER) TYPE(*CHAR) LEN(4) /* number of +
buffers to get */
DCL VAR(&SPLATTR) TYPE(*CHAR) LEN(5000)
DCL VAR(&ATTRLEN) TYPE(*CHAR) LEN(4)
DCL VAR(&INDIC) TYPE(*CHAR) LEN(1)
/* Parameters for the QUSCRTUS API */
DCL VAR(&USPNAME) TYPE(*CHAR) LEN(10) /* user +
space name */
DCL VAR(&USPLIB) TYPE(*CHAR) LEN(10) /* user +
space library */
DCL VAR(&USPQUAL) TYPE(*CHAR) LEN(20) /* user +
space qualified name */
DCL VAR(&USPTYPE) TYPE(*CHAR) LEN(10) /* user +
space type */
DCL VAR(&USPSIZE) TYPE(*CHAR) LEN(4) /* user +
space size */
DCL VAR(&USPFILL) TYPE(*CHAR) LEN(1) /* user +
space fill character */
DCL VAR(&USPAUT) TYPE(*CHAR) LEN(10) /* user +
space authority */
DCL VAR(&USPTEXT) TYPE(*CHAR) LEN(50) /* user +
space text */
/* Parameters for the QUSRTVUS API */
DCL VAR(&STARTPOS) TYPE(*CHAR) LEN(4)
DCL VAR(&DATALEN ) TYPE(*CHAR) LEN(4)
DCL VAR(&HEADER) TYPE(*CHAR) LEN(150)
CHGVAR VAR(%BIN(&ATTRLEN)) VALUE(5000)
/* Create User space */
CHGVAR VAR(&USPNAME) VALUE('DUPCHGSPLF') /* set +
user space name */
CHGVAR VAR(&USPLIB) VALUE('QTEMP') /* set user +
space library */
CHGVAR VAR(&USPQUAL) VALUE(&USPNAME *CAT &USPLIB) +
/* set user space qualified name */
CHGVAR VAR(&USPTYPE) VALUE('MYTYPE') /* set user +
space type */
CHGVAR VAR(%BIN(&USPSIZE)) VALUE(64000) /* set +
user space size */
CHGVAR VAR(&USPFILL) VALUE(' ') /* set user space +
fill character */
CHGVAR VAR(&USPAUT) VALUE('*USE') /* set user +
space authority */
CHGVAR VAR(&USPTEXT) VALUE('my user space') +
/* set user space text */
CALL PGM(QUSCRTUS) PARM(&USPQUAL &USPTYPE +
&USPSIZE &USPFILL &USPAUT &USPTEXT)
/* Open spooled file */
CHGVAR VAR(&BUFFER) VALUE(X'FFFFFFFF')
CALL PGM(QSPOPNSP) PARM(&HANDLE &JOB ' ' ' ' +
&SPLFILE &SPLNBRBIN &BUFFER X'00000000')
/* Get spooled file data */
CALL PGM(QSPGETSP) PARM(&HANDLE &USPQUAL +
'SPFR0200' &BUFFER '*WAIT' X'00000000')
/* Close spooled file */
CALL PGM(QSPCLOSP) PARM(&HANDLE X'00000000')
/* Retrieve Spooled file attributes */
CALL PGM(QUSRSPLA) PARM(&SPLATTR &ATTRLEN +
'SPLA0200' &JOB ' ' ' ' &SPLFILE &SPLNBRBIN)
IF COND(%BIN(&LPI) *NE 0) THEN(CHGVAR +
VAR(%SST(&SPLATTR 181 4)) VALUE(&LPI))
IF COND(%BIN(&CPI) *NE 0) THEN(CHGVAR +
VAR(%SST(&SPLATTR 185 4)) VALUE(&CPI))
IF COND(&FONT *NE *SAME) THEN(CHGVAR +
VAR(%SST(&SPLATTR 537 4)) VALUE(&FONT))
IF COND(%BIN(&PAGRTT) *NE -4) THEN(CHGVAR +
VAR(%SST(&SPLATTR 553 4)) VALUE(&PAGRTT))
IF COND(&OUTQ *NE *SAME) THEN(CHGVAR +
VAR(%SST(&SPLATTR 191 20)) VALUE(&OUTQ))
IF COND(%BIN(&DRAWER) *NE 0) THEN(CHGVAR +
VAR(%SST(&SPLATTR 533 4)) VALUE(&DRAWER))
IF COND(%BIN(&OUTBIN) *NE -1) THEN(CHGVAR +
VAR(%SST(&SPLATTR 3313 4)) VALUE(&OUTBIN))
IF COND(&FORMTYPE *NE *SAME) THEN(CHGVAR +
VAR(%SST(&SPLATTR 89 10)) VALUE(&FORMTYPE))
IF COND(&USRDTA *NE *SAME) THEN(CHGVAR +
VAR(%SST(&SPLATTR 99 10)) VALUE(&USRDTA))
IF COND(&HOLD *NE *SAME) THEN(CHGVAR +
VAR(%SST(&SPLATTR 129 10)) VALUE(&HOLD))
IF COND(&SAVE *NE *SAME) THEN(CHGVAR +
VAR(%SST(&SPLATTR 139 10)) VALUE(&SAVE))
IF COND(&DUPLEX *NE *SAME) THEN(CHGVAR +
VAR(%SST(&SPLATTR 561 10)) VALUE(&DUPLEX))
IF COND(&NEWUSER *NE *SAME) THEN(CHGVAR +
VAR(%SST(&SPLATTR 59 10)) VALUE(&NEWUSER))
CHGVAR VAR(&JOBNAME) VALUE(%SST(&SPLATTR 49 10))
CHGVAR VAR(&JOBUSER) VALUE(%SST(&SPLATTR 59 10))
IF COND(&NEWSPLNAME *EQ *JOBNAME) THEN(CHGVAR +
VAR(&NEWSPLNAME) VALUE(&JOBNAME))
IF COND(&NEWSPLNAME *EQ *USER) THEN(CHGVAR +
VAR(&NEWSPLNAME) VALUE(&JOBUSER))
IF COND(&NEWSPLNAME *NE *SAME) THEN(CHGVAR +
VAR(%SST(&SPLATTR 75 10)) VALUE(&NEWSPLNAME))
/* Create Spooled file */
CALL PGM(QSPCRTSP) PARM(&HANDLE &SPLATTR +
X'00000000')
/* Put Spooled File data */
CALL PGM(QSPPUTSP) PARM(&HANDLE &USPQUAL +
X'00000000')
/* Close Spooled file */
CALL PGM(QSPCLOSP) PARM(&HANDLE X'00000000')
/* Retrieve User space HEADER information */
CHGVAR VAR(%BIN(&STARTPOS)) VALUE(1) /* set start +
position */
CHGVAR VAR(%BIN(&DATALEN)) VALUE(140) /* set data +
length */
CALL PGM(QUSRTVUS) PARM(&USPQUAL &STARTPOS +
&DATALEN &HEADER)
DLTUSRSPC USRSPC(&USPLIB/&USPNAME)
CHGVAR VAR(&INDIC) VALUE(%SST(&HEADER 87 1))
IF COND(&INDIC *EQ C) THEN(DO)
SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA('Spooled +
file' *BCAT &SPLFILE *BCAT 'duplicated') +
MSGTYPE(*COMP)
ENDDO
ELSE CMD(DO)
SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA('Spooled +
file' *BCAT &SPLFILE *BCAT 'not +
completely duplicated') MSGTYPE(*ESCAPE)
ENDDO
/* Delete Original Spooled File */
IF COND(&DLTSPLF *EQ *NO) THEN(RETURN)
IF COND(&JOB *EQ '*') THEN(RTVJOBA +
JOB(&JOBNAME) USER(&JOBUSER) NBR(&JOBNBR))
ELSE CMD(DO)
CHGVAR VAR(&JOBNAME) VALUE(%SST(&JOB 1 10))
CHGVAR VAR(&JOBUSER) VALUE(%SST(&JOB 11 10))
CHGVAR VAR(&JOBNBR) VALUE(%SST(&JOB 21 6))
ENDDO
IF COND(%BIN(&SPLNBRBIN) *EQ 0) THEN(CHGVAR +
VAR(&SPLNBRCHR) VALUE(*ONLY))
IF COND(%BIN(&SPLNBRBIN) *EQ -1) THEN(CHGVAR +
VAR(&SPLNBRCHR) VALUE(*LAST))
IF COND(%BIN(&SPLNBRBIN) *GT 0) THEN(DO)
CHGVAR VAR(&SPLNBRDEC) VALUE(%BIN(&SPLNBRBIN))
CHGVAR VAR(&SPLNBRCHR) VALUE(&SPLNBRDEC)
ENDDO
DLTSPLF FILE(&SPLFILE) +
JOB(&JOBNBR/&JOBUSER/&JOBNAME) +
SPLNBR(&SPLNBRCHR)
MONMSG MSGID(CPF0000)
END: ENDPGM
File : QCMDSRC
Member: DUPCHGSPLF
Type : CMD
Usage : CRTCMD CMD(DUPCHGSPLF) PGM(DUPCGHSPLF)
Version: ALL
/* */
/* \\\\\\\ */
/* ( o o ) */
/*------------------------oOO----(_)----OOo-------------------------*/
/* */
/* Command : DUPCHGSPLF */
/* System : iSeries */
/* */
/* Description : Duplicate and Change Spooled file */
/* */
/* ooooO Ooooo */
/* ( ) ( ) */
/*----------------------( )-------------( )---------------------*/
/* (_) (_) */
/* */
/* To compile : */
/* */
/* CRTCMD CMD(XXX/DUPCHGSPLF) PGM(XXX/DUPCHGSPLF) + */
/* SRCFILE(XXX/QCMDSRC) */
/* */
DUPCHGSPLF: CMD PROMPT('Duplicate and change SPLF')
PARM KWD(JOB) TYPE(JOBNAME) DFT(*) SNGVAL((*)) +
PROMPT('Job name')
PARM KWD(SPLFILE) TYPE(*NAME) LEN(10) DFT(QPRINT) +
PROMPT('Spooled file name')
PARM KWD(SPLNBR) TYPE(*INT4) DFT(*LAST) RANGE(1 +
9999) SPCVAL((*ONLY 0) (*LAST -1)) MIN(0) +
PROMPT('Spooled file number')
PARM KWD(LPI) TYPE(*INT4) RSTD(*YES) DFT(*SAME) +
SPCVAL((*SAME 0) (6 60) (8 80) (3 30) (4 +
40) (7.5 75) (7,5 75) (9 90) (12 120)) +
MIN(0) PROMPT('Lines per inch')
PARM KWD(CPI) TYPE(*INT4) RSTD(*YES) DFT(*SAME) +
SPCVAL((*SAME 0) (10 100) (5 50) (12 120) +
(13.3 133) (13,3 133) (15 150) (16.7 167) +
(16,7 167) (18 180) (20 200)) MIN(0) +
PROMPT('Characters per inch')
PARM KWD(FONT) TYPE(*CHAR) LEN(5) RSTD(*YES) +
DFT(*SAME) VALUES(*SAME *CPI) PROMPT('Font')
PARM KWD(PAGRTT) TYPE(*INT4) RSTD(*YES) +
DFT(*SAME) VALUES(0 90 180 270) +
SPCVAL((*AUTO -1) (*DEVD -2) (*COR -3) +
(*SAME -4)) PROMPT('Degree of page rotation')
PARM KWD(OUTQ) TYPE(OUTQ) DFT(*SAME) +
SNGVAL((*SAME)) MIN(0) PROMPT('Output queue')
PARM KWD(DRAWER) TYPE(*INT4) DFT(*SAME) RANGE(1 +
255) SPCVAL((*SAME 0) (*E1 -1)) +
PROMPT('Source drawer')
PARM KWD(FORMTYPE) TYPE(*CHAR) LEN(10) DFT(*SAME) +
SPCVAL((*SAME) (*STD)) PROMPT('Formtype')
PARM KWD(USRDTA) TYPE(*CHAR) LEN(10) DFT(*SAME) +
SPCVAL((*SAME)) PROMPT('User specified data')
PARM KWD(HOLD) TYPE(*CHAR) LEN(10) RSTD(*YES) +
DFT(*SAME) VALUES(*YES *NO) +
SPCVAL((*SAME)) PROMPT('Hold file before +
written')
PARM KWD(SAVE) TYPE(*CHAR) LEN(10) RSTD(*YES) +
DFT(*SAME) VALUES(*YES *NO) +
SPCVAL((*SAME)) PROMPT('Save file after +
written')
PARM KWD(DUPLEX) TYPE(*CHAR) LEN(10) RSTD(*YES) +
DFT(*SAME) VALUES(*YES *NO *TUMBLE +
*FORMDF) SPCVAL((*SAME)) PROMPT('Print on +
both sides (Duplex)')
PARM KWD(OUTBIN) TYPE(*INT4) DFT(*SAME) RANGE(1 +
65535) SPCVAL((*SAME -1) (*DEVD 0)) +
PROMPT('Output bin')
PARM KWD(NEWUSER) TYPE(*NAME) LEN(10) DFT(*SAME) +
SPCVAL((*SAME)) PROMPT('New User')
PARM KWD(NEWSPLNAME) TYPE(*NAME) LEN(10) +
DFT(*SAME) SPCVAL((*SAME) (*JOBNAME) +
(*USER)) PROMPT('New Spool file name')
PARM KWD(DLTSPLF) TYPE(*CHAR) LEN(10) RSTD(*YES) +
DFT(*NO) VALUES(*YES *NO) PROMPT('Delete +
file after duplication')
OUTQ: QUAL TYPE(*NAME) LEN(10) MIN(1)
QUAL TYPE(*NAME) LEN(10) DFT(*LIBL) +
SPCVAL((*CURLIB) (*LIBL)) PROMPT('Library')
JOBNAME: QUAL TYPE(*NAME) LEN(10) MIN(1)
QUAL TYPE(*NAME) LEN(10) DFT(' ') SPCVAL((' ')) +
CHOICE('Name') PROMPT('User')
QUAL TYPE(*CHAR) LEN(6) DFT(' ') RANGE(000000 +
999999) SPCVAL((' ')) FULL(*YES) +
CHOICE('000000-999999') PROMPT('Number')
A blog about IBM i (AS/400), MQ and other things developers or Admins need to know.
星期四, 11月 02, 2023
2002-12-02 如何複製報表並可更改報表屬性(如報表擁有人, 報表名稱...) (Command DUPCHGSPLF)?
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言