□ Tips : 如何 Copy Spooled file to HTML file ?(command SPL2HTML)
--------------------------------
我開發了一個工具 SPL2HTML 可將 Spooled file 轉成 HTML file,
並可選頁,使用前,需建立 Source PF,
CRTSRCPF FILE(lib/file) RCDLEN(240) IGCDTA(*YES) ,
指定 SPL2HTML 參數 TOFILE(lib/file);
Compiled SPL2HTMLR ; SPL2HTMLC;
Create Command CRTCMD CMD(SPL2HTML) PGM(SPL2HTMLC)
--------------------------------
QCMDSRC -- SPL2HTML CMD
/*----------------------------------------------------------------*/
/* CL COMMAND SPL2HTML CONVERT SPOOLED FILE TO WEB PAGE */
/* COPYRIGHT (c) 2000 Vengoal Chang */
/* ALL RIGHTS RESERVED. */
/*----------------------------------------------------------------*/
CMD PROMPT('Convert Spooled File To HTML')
PARM KWD(FILE) TYPE(*NAME) LEN(10) MIN(1) +
FILE(*IN) EXPR(*YES) PROMPT('Spooled file' 1)
PARM KWD(TOFILE) TYPE(Q0309) MIN(1) FILE(*OUT) +
CHOICE(*NONE) PROMPT('To source physical +
file' 2)
PARM KWD(JOB) TYPE(Q036A) DFT(*) SNGVAL((*)) +
PROMPT('Job name' 3)
PARM KWD(SPLNBR) TYPE(*CHAR) LEN(5) DFT(*LAST) +
EXPR(*YES) CHOICE('1-9999 , *ONLY, +
*LAST') PROMPT('Spooled file number' 4)
PARM KWD(TOMBR) TYPE(*NAME) LEN(10) +
DFT(SPOOLFILE) SPCVAL((SPOOLFILE)) +
EXPR(*YES) PROMPT('To member' 5)
PARM KWD(MBROPT) TYPE(*CHAR) LEN(8) RSTD(*YES) +
DFT(*REPLACE) SPCVAL((*REPLACE) (*ADD)) +
EXPR(*YES) PROMPT('Replace or add records' 6)
Q0309: QUAL TYPE(*NAME) LEN(10) MIN(1) EXPR(*YES)
QUAL TYPE(*NAME) LEN(10) DFT(*LIBL) +
SPCVAL((*LIBL) (*CURLIB *CURLIB)) +
EXPR(*YES) PROMPT('Library')
Q036A: QUAL TYPE(*NAME) LEN(10) MIN(1) EXPR(*YES)
QUAL TYPE(*NAME) LEN(10) EXPR(*YES) PROMPT('User')
QUAL TYPE(*CHAR) LEN(6) RANGE('000000' '999999') +
FULL(*YES) EXPR(*YES) PROMPT('Number')
--------------------------------
QCLSRC SPL2HTMLC CLP
SPL2HTML: PGM PARM(&SPLNM &TOFIL &JOB &SPLNB &TOMBR &MBROP)
DCL VAR(&SPLNM) TYPE(*CHAR) LEN(10)
DCL VAR(&TOFIL) TYPE(*CHAR) LEN(20) /* FILE,LIB */
DCL VAR(&JOB) TYPE(*CHAR) LEN(26) /* JOB,USER,JOB_NO */
DCL VAR(&SPLNB) TYPE(*CHAR) LEN(5)
DCL VAR(&SPLNBT) TYPE(*CHAR) LEN(5)
DCL VAR(&SPLNBC) TYPE(*CHAR) LEN(5)
DCL VAR(&SPLNBL) TYPE(*CHAR) LEN(5)
DCL VAR(&TOMBR) TYPE(*CHAR) LEN(10)
DCL VAR(&MBROP) TYPE(*CHAR) LEN(8)
DCL VAR(&totpages) TYPE(*CHAR) LEN(5)
DCL VAR(&I) TYPE(*dec) LEN(1 0)
DCL VAR(&J) TYPE(*dec) LEN(1 0)
DCL VAR(&FILE) TYPE(*CHAR) LEN(10)
DCL VAR(&LIB) TYPE(*CHAR) LEN(10)
DCL VAR(&JOBNM) TYPE(*CHAR) LEN(10)
DCL VAR(&JOBUS) TYPE(*CHAR) LEN(10)
DCL VAR(&JOBNB) TYPE(*CHAR) LEN(6)
/* Message handling variables */
DCL VAR(&MSGID) TYPE(*CHAR) LEN(7)
DCL VAR(&MSGF) TYPE(*CHAR) LEN(10)
DCL VAR(&MSGFLIB) TYPE(*CHAR) LEN(10)
DCL VAR(&MSGDTA) TYPE(*CHAR) LEN(256)
DCLF SPOOL132
MONMSG MSGID(CPF0000 MCH0000) EXEC(GOTO CMDLBL(ERROR))
CHGVAR VAR(&FILE) VALUE(%SST(&TOFIL 1 10))
CHGVAR VAR(&LIB) VALUE(%SST(&TOFIL 11 10))
CHGVAR VAR(&JOBNM) VALUE(%SST(&JOB 1 10))
CHGVAR VAR(&JOBUS) VALUE(%SST(&JOB 11 10))
CHGVAR VAR(&JOBNB) VALUE(%SST(&JOB 21 6))
IF (%SST(&JOB 1 1) = '*') DO
RTVJOBA JOB(&JOBNM) USER(&JOBUS) NBR(&JOBNB)
ENDDO
IF (&SPLNB *NE '*LAST') DO
chgvar &I 5 /* from */
chgvar &J 5 /* to */
rightadj: /* '5 ' -> ' 5' */
If (%sst(&SPLNB &I 1) *NE ' ') Do
chgvar %sst(&SPLNBT &J 1) %sst(&SPLNB &I 1)
chgvar &J (&J-1)
EndDo
Chgvar &I (&I-1)
If (&I > 0) Do
Goto rightadj
EndDo
Else Do
Chgvar &J 1
chkchr0: /* ' 5' -> '00005' */
IF (%SST(&SPLNBT &J 1) = ' ') +
chgvar %SST(&SPLNBT &J 1) '0'
chgvar &J (&J+1)
if (&J < 6) goto chkchr0
if (&J = 6) Do
Chgvar &SPLNB &SPLNBT
Goto Next
EndDo
EndDo
ENDDO
Next:
ADDLIBLE WEBSAMP
MONMSG CPF0000
/* CREATE THE TEMP FILE TO RECEIVE THE OUTPUT */
DLTF FILE(QTEMP/HTMTMP)
MONMSG MSGID(CPF2105)
DLTF FILE(QTEMP/SPOOL132)
MONMSG MSGID(CPF2105)
CRTPF FILE(QTEMP/HTMTMP) RCDLEN(220) IGCDTA(*YES)
CRTPF FILE(QTEMP/SPOOL132) RCDLEN(220) IGCDTA(*YES)
WRKSPLF SELECT(&JOBUS) OUTPUT(*PRINT)
CPYSPLF FILE(QPRTSPLF) TOFILE(QTEMP/SPOOL132) +
SPLNBR(*LAST)
DLTSPLF FILE(QPRTSPLF) SPLNBR(*LAST)
OVRDBF FILE(SPOOL132) TOFILE(QTEMP/SPOOL132) +
LVLCHK(*NO)
LOOP: RCVF
MONMSG CPF0864 EXEC(GOTO CMDLBL(ENDLOOP))
CHGVAR &SPLNBC %SST(&spool132 101 5)
chgvar &I 1
chkchr:
IF (%SST(&SPLNBC &I 1) = ' ') +
chgvar %SST(&SPLNBC &I 1) '0'
chgvar &I (&I+1)
if (&I < 6) goto chkchr If (&SPLNB *NE '*LAST') DO
IF ((%SST(&SPOOL132 3 10)="&SPLNM" ) *AND +
(%SST(&SPOOL132 107 10)="&JOBNM" ) *AND +
(%SST(&SPOOL132 14 10)="&JOBUS" ) *AND +
(%SST(&SPOOL132 118 6)="&JOBNB" ) *AND +
(&SPLNBC="&SPLNB" )) DO
CHGVAR &TOTPAGES %SST(&SPOOL132 52 5)
/* SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA( +
'TOTAL pages' *CAT &TOTPAGES) +
MSGTYPE(*info) */
GOTO ENDLOOP
ENDDO
ENDDO
Else Do /* Spooled file nbr="*last" */
IF ((%SST(&SPOOL132 3 10)="&SPLNM" ) *AND +
(%SST(&SPOOL132 107 10)="&JOBNM" ) *AND +
(%SST(&SPOOL132 14 10)="&JOBUS" ) *AND +
(%SST(&SPOOL132 118 6)="&JOBNB" )) Do
If (&SPLNBC> &SPLNBL) Do
CHGVAR &SPLNBL &SPLNBC
CHGVAR &TOTPAGES %SST(&SPOOL132 52 5)
EndDo
/* SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA( +
'TOTAL pages' *CAT &TOTPAGES) +
MSGTYPE(*info) */
/* GOTO ENDLOOP */
ENDDO
Enddo
/* SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA('Spooled +
file' *BCAT &SPLNM *BCAT &SPLNBC +
*BCAT &SPLNB *CAT &TOTPAGES *BCAT +
%SST(&SPOOL132 3 10) *BCAT &splnm *bcat +
%SST(&SPOOL132 14 10) *BCAT &jobus *bcat +
%SST(&SPOOL132 107 10) *BCAT &jobnm *bcat +
%SST(&SPOOL132 118 6) *BCAT &jobnb *bcat +
'HTML member' *BCAT &TOMBR) MSGTYPE(*info)*/
GOTO LOOP
ENDLOOP:
CPYSPLF FILE(&SPLNM) TOFILE(QTEMP/HTMTMP) +
JOB(&JOBNB/&JOBUS/&JOBNM) SPLNBR(&SPLNB) +
MBROPT(*ADD) CTLCHAR(*PRTCTL)
CHKOBJ OBJ(&LIB/&FILE) OBJTYPE(*FILE) +
MBR(&TOMBR)
MONMSG MSGID(CPF9815) EXEC(DO) /* No EXIST*/
ADDPFM FILE(&LIB/&FILE) MBR(&TOMBR) +
TEXT(&TOMBR *BCAT 'member used by +
SPL2HTML command')
ENDDO /* No EXIST*/
CLRPFM FILE(&LIB/&FILE) MBR(&TOMBR)
OVRDBF FILE(INPUT) TOFILE(QTEMP/HTMTMP)
OVRDBF FILE(OUTPUT) TOFILE(&LIB/&FILE) MBR(&TOMBR)
CALL SPL2HTMLR (&SPLNM &JOBNM &JOBUS &JOBNB &TOTPAGES)
DLTOVR FILE(INPUT)
DLTOVR FILE(OUTPUT)
GOTO CMDLBL(OK)
error:
RCVMSG MSGTYPE(*LAST) MSGDTA(&MSGDTA) MSGID(&MSGID) +
MSGF(&MSGF) SNDMSGFLIB(&MSGFLIB)
MONMSG MSGID(CPF0000) /* In case */
SNDPGMMSG MSGID(&MSGID) MSGF(&MSGFLIB/&MSGF) +
MSGDTA(&MSGDTA) MSGTYPE(*ESCAPE)
MONMSG MSGID(CPF0000) /* In case */
OK:
SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA('Spooled +
file' *BCAT &SPLNM *BCAT 'converted to ' +
*CAT &LIB *TCAT '/' *CAT &FILE *BCAT +
'HTML member' *BCAT &TOMBR) MSGTYPE(*COMP)
ENDPGM
--------------------------------
QRPGLESRC -- SPL2HTMLR RPGLE
F* SPL2HTMLR - Copy text to spool - Called by SPL2HTMLR
F*
F* PRTCTL Keyword : Data structure A(12)+S(3)
* Position contents
* 1-3 A(3) space-before blank or 0-255
* 4-6 A(3) space-after blank or 0-255
* 7-9 A(3) skip-before blank or 0-255
* 10-12 A(3) skip-after blank or 0-255
* 13-15 S(3) line count 3 digit numeric
* (zoned decimal)
*
FINPUT IP F 220 DISK
Foutput O F 240 DISK
D LINE DS 15
D SPCBFR 3 3
D SKPBFR 7 9
D skpbfrn S 5 0
D spcbfrn S 1 0
D pagen S 5 0 inz(0)
D pagec S 5
D srcseq S 6s 0 in z(0)
D srcdat S 6s 0 inz(0)
D srcdta S 228
D I S 5 0 inz(1)
IINPUT AA 01
I 1 3 SKPBFR
I 4 4 SPCBFR
I 6 203 DATA
C *entry plist
C parm SPLNM 10
C parm JOBNM 10
C parm JOBUS 10
C parm JOBNB 6
C parm TOTPAGES 5
C
C If *in10 = *off
C Eval *in10 = *on
C Eval SRCDTA = ''
C Except PAGHAD
C Eval SRCDTA = 'Spooled File to HTML ' +
C 'Converter ©' +
C 'Vengoal Chang '
C Except PAGHAD
C Eval SRCDTA = ''
C Except PAGHAD
C Eval SRCDTA = 'File:'+ SPLNM + '
' +
C 'JOB :' +
C %trim(JOBNB) + '/' +
C %trim(JOBUS) + '/' +
C %trim(JOBNM) + '
'
C Except PAGHAD
C Eval SRCDTA = 'Goto Page:
'
C Except PAGHAD
C Eval SrcDta = *Blanks
C Move Totpages Pagebeg 5
C ' ':'0' Xlate Pagebeg Pagebeg
C Move Pagebeg Pagebegn 5 0
C For I = 1 to Pagebegn
C Eval SRCDTA = %trim(SRCDTA) + ' ' +
C '' + %trim(%editc(I:'Z')) + ' '
C If %Rem(I:10) = 0
C Eval SrcDta = %trim(SrcDta) + '
'
C Except PAGHAD
C Eval SrcDta = *Blanks
C EndIf
C EndFor
C Except PAGHAD
C EndIf
C If SKPBFR <> ' '
C ' ':'0' Xlate SKPBFR SKPBFR
C Move SKPBFR SKPBFRN
C If SKPBFRN <> 0
C Eval pagen = pagen + 1
C Eval pagec = %editc(pagen:'Z')
C Eval SRCDTA ='
' +
C '
' +
C 'Page ' + %trim(pagec) +' ' +
C '/' + %trim(totpages) +' ' +
C 'Back to Top
'
C EXCEPT paghad Print
C EndIf
C EndIf
C If SPCBFR <> ' '
C Move SPCBFR SPCBFRN
C If SPCBFRN > 1
C EXCEPT spclin
C EndIf
C EndIF
C EXCEPT PRINT Print
CLr Eval SRCDTA = '
SPL2HTML '+
C 'Utility from Vengoal Chang ' +
C 'Copyright © 2000'
CLr Except PAGHAD
CLr Eval SRCDTA = '
'
CLr Except PAGHAD
Ooutput E PRINT
O srcseq 6
O srcdat 12
O DATA 210
O E PAGHAD
O srcseq 6
O srcdat 12
O SRCDTA 240
O E SPCLIN
O srcseq 6
O srcdat 12
O 13 ' '
A blog about IBM i (AS/400), MQ and other things developers or Admins need to know.
星期二, 10月 31, 2023
2000-06-19 如何 Copy Spooled file to HTML file ?(Command SPL2HTML)
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言