如何將報表轉為 Text 或 Html 格式 ? (Command:CVTSPLSTMF)
此指令是將報表轉換為 Text 或 Html 格式,並可以轉換中文而且可將報表對齊,不過報表
中文控制碼(0E0F)要前後配對完整才可以,並將之存放在 IFS 目錄中,所以使用前須先建立
一個目錄,例如使用指令 MD '/spool' 建立一 spool 的目錄,使用 WRKLNK '/spool' ,並
選用 5 ,即可檢視該目錄內容:
===============================================================================
Work with Object Links
Directory . . . . : /
Type options, press Enter.
2=Edit 3=Copy 4=Remove 5=Display 7=Rename 8=Display attributes
11=Change current directory ...
Opt Object link
5 spool
Bottom
Parameters or command
===>
F3=Exit F4=Prompt F5=Refresh F9=Retrieve F12=Cancel F17=Position to
F22=Display entire field F23=More options
===============================================================================
Work with Object Links
Directory . . . . : /spool
Type options, press Enter.
2=Edit 3=Copy 4=Remove 5=Display 7=Rename 8=Display attributes
11=Change current directory ...
Opt Object link
Bottom
Parameters or command
===>
F3=Exit F4=Prompt F5=Refresh F9=Retrieve F12=Cancel F17=Position to
F22=Display entire field F23=More options
===============================================================================
使用CVTSPLSTMF 指令範例:
利用 AS/400 列印螢幕功能(HOST print),列印一份報表 QSYSPRT,在使用下列指令將
QSYSPRT 報表複製至目錄 /spool 中:
Convert Spool to Stream File (CVTSPLSTMF)
Type choices, press Enter.
From spooled file name . . . . . > QSYSPRT Name
To stream file name . . . . . . > QSYSPRT.TXT
To directory . . . . . . . . . . > '/spool'
Job name . . . . . . . . . . . . * Name, *
User . . . . . . . . . . . . . Name
Number . . . . . . . . . . . . 000000-999999
Spooled file number . . . . . . > *LAST 1-9999, *LAST, *ONLY
Stream file format . . . . . . . *TEXT *TEXT, *HTML
Stream file option . . . . . . . > *REPLACE *NONE, *REPLACE, *ADD
Bottom
F3=Exit F4=Prompt F5=Refresh F10=Additional parameters F12=Cancel
F13=How to use this display F24=More keys
==============================================================================
此時使用 WRKLNK '/spool' ,按執行鍵,並使用選項 5,會得到下列畫面,使用選項 5,
可以檢視報表資料:
Work with Object Links
Directory . . . . : /spool
Type options, press Enter.
2=Edit 3=Copy 4=Remove 5=Display 7=Rename 8=Display attributes
11=Change current directory ...
Opt Object link
QSYSPRT.TXT
Bottom
Parameters or command
===>
F3=Exit F4=Prompt F5=Refresh F9=Retrieve F12=Cancel F17=Position to
F22=Display entire field F23=More options
==============================================================================
當轉換為一般文字檔後,可以使用 FTP 方式或 AS/400 NetServer 方式將目錄分享出來,
PC 端即可取得報表資料了。
有關 As/400(iSeries) NetServer 詳細資料請參照
http://www-1.ibm.com/servers/eserver/iseries/netserver/
File : QRPGLESRC
Member: CVTSPLSTMR
Type : RPGLE
Usage : CRTBNDRPG CVTSPLSTMR
******************************************************************
* *
* PROGRAM NAME: CVTSPLSTMR called by CVTSPLSTMC *
* *
* AUTHOR : Vengoal Chang *
* *
* DATE WRITTEN: March 2006 *
* *
* DESCRIPTION : Converts spooled file data in work file *
* CvtSplWrk2 to HTML or TEXT format to work file *
* CvtSplWrk1. *
* *
* FUNCTIONS : Adds basic HTML headings and footings and a *
* title. *
* *
* Copyright 2006 (c) Vengoal Chang. *
* All rights reserved. *
* *
******************************************************************
H DFTACTGRP(*NO) Debug
FCvtSplWrk2IF F 382 DISK
FCvtSplWrk1UF A F 378 DISK
* Standard HTML header lines
D aaHeader S 80A DIM(2) CTDATA PERRCD(1)
* Standard HTML footer line
D aaFooter S 80A DIM(1) CTDATA PERRCD(1)
* Input spooled file data including control characters
D InputData DS
D saSkipLine 3A
D ssSkipLine 3S 0 OVERLAY(saSkipLine:1)
D saSpceLine 1A
D ssSpceLine 1S 0 OVERLAY(saSpceLine:1)
D saInput 378A
* Output HTML-format data
D OutputData DS
D saOutput 378A
* Program parameters - title and page length in lines
D paToFmt S 5A
D paTitle S 50A
D piPageLen S 10I 0
* Line counter variable
D wiLine S 10I 0
* Procedure prototypes
D HTMLHeader PR
D HTMLFooter PR
D Convert PR
D Merge PR LIKE(saOutput)
D iaOutput LIKE(saOutput)
D iaInput LIKE(saInput)
D SpceLines PR
D isSpceLine LIKE(ssSpceLine)
D SkipLines PR
D isSkipLine LIKE(ssSkipLine)
D ParseInput PR
**********************************************************************
* Program parameters
C *ENTRY PLIST
C PARM paToFmt
C PARM paTitle
C PARM piPageLen
* Output HTML header lines
C If paToFmt = '*HTML'
C CALLP HTMLHeader
C EndIf
* Convert spool file lines to HTML or Text
C EVAL wiLine = 1
C READ CvtSplWrk2 InputData LR
C DOW *INLR = *OFF
C CALLP ParseInput
C CALLP Convert
C READ CvtSplWrk2 InputData LR
C ENDDO
* Output HTML footer lines
C If paToFmt = '*HTML'
C CALLP HTMLFooter
C EndIf
C RETURN
**********************************************************************
* Procedure to create HTML header lines *
**********************************************************************
P HTMLHeader B
D HTMLHeader PI
C EVAL saOutput = aaHeader(1)
C WRITE CvtSplWrk1 OutputData
C IF paTitle <> '*NONE'
C EVAL saOutput = '< TITLE>'
C + %trim(paTitle)
C + ''
C WRITE CvtSplWrk1 OutputData
C ENDIF
C EVAL saOutput = aaHeader(2)
C WRITE CvtSplWrk1 OutputData
P HTMLHeader E
**********************************************************************
* Procedure to create HTML footer line *
**********************************************************************
P HTMLFooter B
D HTMLFooter PI
C EVAL saOutput = aaFooter(1)
C WRITE CvtSplWrk1 OutputData
P HTMLFooter E
**********************************************************************
* Procedure to convert spooled file data to HTML text *
**********************************************************************
P Convert B
D Convert PI
* If 'space' position is zero, 'overprint' previous line
C IF saSpceLine = '0'
C *HIVAL SETGT CvtSplWrk1
C READP CvtSplWrk1 OutputData 99
C EVAL saOutput = Merge(saOutput:saInput)
C UPDATE CvtSplWrk1 OutputData
C ELSE
* Skip to a line if specified
C IF saSkipLine <> *BLANKS
C CALLP SkipLines(ssSkipLine)
C ENDIF
* Space a number of lines if specified
C IF saSpceLine <> *BLANKS
C CALLP SpceLines(ssSpceLine)
C ENDIF
* 'Print' line
C EVAL saOutput = saInput
C WRITE CvtSplWrk1 OutputData
C EVAL wiLine = wiLine + 1
C ENDIF
C RETURN
P Convert E
**********************************************************************
* Procedure to merge two overlaid lines of text *
**********************************************************************
P Merge B
D Merge PI LIKE(saOutput)
D iaOutput LIKE(saOutput)
D iaInput LIKE(saInput)
D laOutput S LIKE(saOutput)
D i S 5I 0
C EVAL i = 1
C DOW i <= %size(iaInput )
C and i <= %size(iaOutput)
C and i <= %size(laOutput)
C IF %subst(iaInput:i:1) = *BLANK
C EVAL %subst(laOutput:i:1) = %subst(iaOutput:i:1)
C ELSE
C EVAL %subst(laOutput:i:1) = %subst(iaInput :i:1)
C ENDIF
C EVAL i = i + 1
C ENDDO
C RETURN laOutput
P Merge E
**********************************************************************
* Procedure to skip to a given line number *
**********************************************************************
P SkipLines B
D SkipLines PI
D isSkipLine LIKE(ssSkipLine)
C EVAL saOutput = *BLANKS
C IF wiLine > isSkipLine
C DOW wiLine <= piPageLen
C WRITE CvtSplWrk1 OutputData
C EVAL wiLine = wiLine + 1
C ENDDO
C If paToFmt = '*HTML'
C EVAL saOutput = '< hr>'
C WRITE CvtSplWrk1 OutputData
C EndIf
C EVAL saOutput = *BLANKS
C EVAL wiLine = 1
C EndIf
C DOW wiLine < isSkipLine
C WRITE CvtSplWrk1 OutputData
C EVAL wiLine = wiLine + 1
C ENDDO
C RETURN
P SkipLines E
**********************************************************************
* Procedure to space a number of lines *
**********************************************************************
P SpceLines B
D SpceLines PI
D isSpceLine LIKE(ssSpceLine)
D liCount S 5I 0
C* EVAL wiLine = wiLine + 1
C EVAL saOutput = *BLANKS
C DOW liCount < isSpceLine - 1
C WRITE CvtSplWrk1 OutputData
C EVAL wiLine = wiLine + 1
C EVAL liCount = liCount + 1
C ENDDO
C RETURN
P SpceLines E
**********************************************************************
P ParseInput B
D ParseInput PI
D Input S 2048
D InpLen S 5I 0
D DATA S 2048
D X0E C X'0E'
D X0F C X'0F'
C z-add 1 i 5 0
C z-add 1 J 5 0
C Clear Data
C Eval Input = InputData
C Eval InpLen= %len(%trimr(InputData))
C 1 Do InpLen
C If %SUBST(Input : i : 1) = X0E
C Eval %SubSt(Data : j : 1) = ' '
C Eval J = J + 1
C Eval %SubSt(Data : j : 1)
C = %SubSt(Input : i : 1)
C Else
C If %SUBST(Input : i : 1) = X0F
C Eval %SubSt(Data : j : 1)
C = %SubSt(Input : i : 1)
C Eval J = J + 1
C Eval %SubSt(Data : j : 1) = ' '
C Else
C Eval %SubSt(Data : j : 1)
C = %SubSt(Input : i : 1)
C EndIf
C EndIf
C Eval i = i + 1
C Eval j = j + 1
C If i > InpLen
C Leave
C EndIf
C EndDo
C Eval InputData = Data
C Eval InpLen = j -1
C
C RETURN
P ParseInput E
**
< html>< head>
< body>< pre>
**
< hr>
A blog about IBM i (AS/400), MQ and other things developers or Admins need to know.