Spool from SAP® to PDF format

by Carel Oberholzer

Print any spool file from SAP® in PDF format. Can be viewed/edited by using Acrobat. You need the full version of Acrobat to edit, but can view and print using the free version. This is a very simple but useful program and needs to be built on to make it into a real handy tool (put in your own code and change the SAPScript before downloading into PDF format).
-------------------------------------------------
report ZPDFPRNT no standard page heading.
TABLES: TST05.

DATA: BEGIN OF ITAB OCCURS 0, 
   TLINE(255),
END OF ITAB.

DATA: BEGIN OF ITAB2 OCCURS 0,
  TLINE(255),
END OF ITAB2.

DATA: BEGIN OF ITAB3 OCCURS 0,
  TLINE(255),
END OF ITAB3.

DATA: BEGIN OF OTF_TAB OCCURS 0,
  TLINE(255),
END OF OTF_TAB.

DATA: LEN_OUT LIKE SOOD-OBJLEN.

DATA: LEN_IN LIKE SOOD-OBJLEN.

DATA: BEGIN OF DATA_SET OCCURS 200,
  DATA_LENGTH(5),
  PRECOL(1),
  DATA_LINE(1000),
END OF DATA_SET.

DATA: BEGIN OF OTF_PAGE OCCURS 200.
  INCLUDE STRUCTURE ITCOO.
DATA: END OF OTF_PAGE,
OTF_PAGES TYPE P,
OTF_MAX_PAGES TYPE P VALUE 10.
DATA: BEGIN OF OTF_CONTROL.
  INCLUDE STRUCTURE ITCPP.
DATA: END OF OTF_CONTROL,
FORCE_RAW_OTF VALUE ' ',
L100_EXCLUDE(4) VALUE 'OTFJ',
BEGIN OF OTF_PAGE_INDEX OCCURS 20,
  LINE_NUM TYPE P,
END OF OTF_PAGE_INDEX,
CUR_OTF_PAGE VALUE 1.

DATA: DATA_SET_LINECOUNT TYPE P,
DATA_SET_MAX_LINES TYPE P VALUE 100000,
DATA_SET_VALID TYPE C VALUE ' ',
DATA_SET_IS_OTF TYPE C VALUE ' ',
DATA_SET_LENGTH(5) TYPE C,
LINE_SPECIAL LIKE DATA_SET-DATA_LINE,
NEED_LINE_SPECIAL TYPE C,
DSN_TYPE(8) TYPE C.

DATA: FCODE(4) TYPE C,
DATE TYPE D,
TIME TYPE T,
RC(10) TYPE C,
ERRMSG(100) TYPE C,
PRINTJOB_CREATED(1) TYPE C,
PRINTJOB_CLEARED(1) TYPE C,
PRINTJOB_LIST(1) TYPE C,
DISPLAY_MODE(1) TYPE C,
LINE_MAX TYPE P VALUE '100000',
NEW_SCREEN_300(1) TYPE C,
MULTI_PRINT_300(1) TYPE C,
PRINT_ALL_300(1) TYPE C,
PRINT_COUNT_300 TYPE I,
SHOW_USER_100 TYPE C VALUE ' ',
ERROR_DISPLAY_LEVEL TYPE C VALUE '9',
NEXT_ERROR_DISPLAY_LEVEL TYPE C,
PREV_ERROR_DISPLAY_LEVEL TYPE C,
START_300(5) TYPE C, END_300(5) TYPE C,
SEP LIKE SY-VLINE,
DEFAULT_PRI,
TSP01_BUF LIKE TSP01,
TSP01_CURLINE LIKE SY-STARO,
TSP01_CURCOL LIKE SY-CUCOL,
TSP01_CURROW LIKE SY-CUROW.

DATA: BEGIN OF DATA_SET_LINE,
  DATA_LENGTH(5),
  PRECOL(1),
DATA_LINE(1000),
END OF DATA_SET_LINE.

DATA: STATUS LIKE SY-SUBRC.
DATA: WGF_MESSAGE(80).
DATA: H_PATH(20) TYPE C.
DATA: H_MASK(20) TYPE C VALUE ',*.pdf ,*.pdf. '.
DATA: FILE_NAME(20).
DATA: FILENAME LIKE RLGRAP-FILENAME.
DATA: IMPORT(132).

PARAMETERS: IDENT(5) TYPE C.

PERFORM GET_OTF_TAB.

LOOP AT OTF_PAGE.
   OTF_TAB-TLINE = OTF_PAGE.
   APPEND OTF_TAB.
ENDLOOP.


CALL FUNCTION 'SX_OBJECT_CONVERT_OTF_PDF'
EXPORTING
  FORMAT_SRC = 'OTF'
  FORMAT_DST = 'PDF'
  DEVTYPE = 'ASCIIPRI'
  LEN_IN = LEN_IN
IMPORTING
  LEN_OUT = LEN_OUT
TABLES
  CONTENT_IN = OTF_TAB
  CONTENT_OUT = ITAB2
EXCEPTIONS
  ERR_CONV_FAILED = 1
  OTHERS = 2.

PERFORM GET_PATH USING 'PDF_FILE'.

CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
  FILENAME = FILENAME
  FILETYPE = 'BIN'
  BIN_FILESIZE = LEN_OUT
TABLES
  DATA_TAB = ITAB2
EXCEPTIONS
  FILE_OPEN_ERROR = 1
  FILE_WRITE_ERROR = 2
  INVALID_FILESIZE = 3
  INVALID_TABLE_WIDTH = 4
  INVALID_TYPE = 5
  NO_BATCH = 6
  UNKNOWN_ERROR = 7
  OTHERS = 8.

*&---------------------------------------------------------------------*
*& Form GET_OTF_TAB
*&---------------------------------------------------------------------*
FORM GET_OTF_TAB.

DATA: PART(4) VALUE '0001',
BEGIN OF MSG,
  A(40),
  B(40),
  C(40),
END OF MSG.

REFRESH DATA_SET.
DATA_SET_LINECOUNT = 0.
DATA_SET_IS_OTF = ' '.
OTF_PAGES = 0.
REFRESH OTF_PAGE_INDEX.
CALL 'RSPOACSD'.

SELECT * FROM TST05 WHERE DTHREAD = 'X'.

CALL 'RSPOAOSD'
ID 'ID' FIELD IDENT
ID 'TYPE' FIELD TST05-DTYPE
ID 'RECTYP' FIELD 'VYL----'
ID 'RC' FIELD RC
ID 'ERRMSG' FIELD ERRMSG.

STATUS = SY-SUBRC.
IF STATUS = 0.
  DSN_TYPE = TST05-DTYPE.
  IF DSN_TYPE(3) = 'OTF'.
    DATA_SET_IS_OTF = 'X'.
  ENDIF.
ENDIF.

IF STATUS <> 24. EXIT. ENDIF.
ENDSELECT.

DATA_SET_VALID = 'X'.
DATA_SET_MAX_LINES = ( LINE_MAX * '1.1' ) + 100.
DO.
CLEAR: DATA_SET_LINE, DATA_SET_LENGTH.
CALL 'RSPOARSD'
ID 'BUFF' FIELD DATA_SET_LINE+5
ID 'DATALEN' FIELD DATA_SET_LENGTH
ID 'RC' FIELD RC
ID 'ERRMSG' FIELD ERRMSG.
STATUS = SY-SUBRC.
IF STATUS = 36.

WHILE STATUS = 36.
CALL 'RSPOACSD'
ID 'RC' FIELD RC
ID 'ERRMSG' FIELD ERRMSG.
ADD 1 TO PART.
IF DATA_SET_IS_OTF = ' '.
CALL 'RSPOAOSD'
ID 'ID' FIELD IDENT
ID 'TYPE' FIELD DSN_TYPE
ID 'PART' FIELD PART
ID 'RECTYP' FIELD 'VYL----'
ID 'RC' FIELD RC
ID 'ERRMSG' FIELD ERRMSG.
ELSE.
CALL 'RSPOAOSD'
ID 'ID' FIELD IDENT
ID 'PART' FIELD PART
ID 'TYPE' FIELD DSN_TYPE
ID 'RECTYP' FIELD 'VYL----'
ID 'RC' FIELD RC
ID 'ERRMSG' FIELD ERRMSG.
ENDIF.
IF SY-SUBRC NE 0. EXIT. ENDIF.

CLEAR: DATA_SET_LINE, DATA_SET_LENGTH.
CALL 'RSPOARSD'
ID 'BUFF' FIELD DATA_SET_LINE+5
ID 'DATALEN' FIELD DATA_SET_LENGTH
ID 'RC' FIELD RC
ID 'ERRMSG' FIELD ERRMSG.
STATUS = SY-SUBRC.
ENDWHILE.
ENDIF.
IF STATUS <> 0 AND STATUS <> 40. EXIT. ENDIF.

DATA_SET = DATA_SET_LINE.
IF NOT ( DATA_SET_LENGTH IS INITIAL ).
DATA_SET-DATA_LENGTH = DATA_SET_LENGTH - 1.
ENDIF.
APPEND DATA_SET.
ADD 1 TO DATA_SET_LINECOUNT.
IF DATA_SET_IS_OTF = ' '.
IF DATA_SET_LINECOUNT >= DATA_SET_MAX_LINES.
CLEAR DATA_SET.
APPEND DATA_SET.
MOVE '----------' TO DATA_SET-DATA_LINE.
APPEND DATA_SET.
CLEAR DATA_SET.
APPEND DATA_SET.
WRITE: 'Abbruch nach'(029) TO MSG-A.
WRITE: DATA_SET_MAX_LINES TO MSG-B.
WRITE: 'Zeilen.'(030) TO MSG-C.
CONDENSE MSG.
DATA_SET-DATA_LINE = MSG.
APPEND DATA_SET.
EXIT.
ENDIF.
ELSE.
MOVE DATA_SET_LINE-DATA_LINE TO OTF_PAGE.
APPEND OTF_PAGE.
IF OTF_PAGE(2) = 'EP'.
  ADD 1 TO OTF_PAGES.
  IF OTF_PAGES >= OTF_MAX_PAGES.
    MESSAGE S229(PO) WITH OTF_MAX_PAGES.
    EXIT.
  ENDIF.
ELSEIF OTF_PAGE(2) = 'OP'.
  OTF_PAGE_INDEX-LINE_NUM = DATA_SET_LINECOUNT.
  APPEND OTF_PAGE_INDEX.
ENDIF.
ENDIF.
ENDDO.
IF STATUS <> 0 AND STATUS <> 12.
  CALL 'RSPOACSD'.
  MESSAGE E112(PO) WITH STATUS RC ERRMSG.
ENDIF.
CALL 'RSPOACSD'.
STATUS = SY-SUBRC.
IF STATUS <> 0.
  MESSAGE E112(PO) WITH STATUS RC ERRMSG.
ENDIF.
ENDFORM. " GET_OTF_TAB

*&---------------------------------------------------------------------*
*& Form GET_PATH
*&---------------------------------------------------------------------*
FORM GET_PATH USING P_FILENAME.

CLEAR: H_PATH, FILE_NAME.

FILE_NAME = P_FILENAME.
CALL FUNCTION 'WS_QUERY'
EXPORTING
QUERY = 'CD' "// Current Directory
IMPORTING
RETURN = H_PATH.

CONCATENATE FILE_NAME '.pdf' INTO FILE_NAME.

CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
  DEF_FILENAME = FILE_NAME
  DEF_PATH = H_PATH
  MASK = H_MASK
  MODE = 'O'
IMPORTING
  FILENAME = FILENAME"dbname
EXCEPTIONS
  INV_WINSYS = 1
  NO_BATCH = 2
  SELECTION_CANCEL = 3
  SELECTION_ERROR = 4
  OTHERS = 5.

ENDFORM. " GET_PATH
-------------------------------------------------

 

Please send us your feedback/suggestions at webmaster@SAPTechnical.COM 

HomeContribute About Us Privacy Terms Of Use • Disclaimer • SafeCompanies: Advertise on SAPTechnical.COM | Post JobContact Us  

Graphic Design by Round the Bend Wizards

footer image footer image