Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

CONVERT_ABAPSPOOLJOB_2_PDF

Former Member
0 Likes
3,152

Hi,

I am using above function module to convert spool output into pdf format.

Spool output has more than 99 pages. for this reason, above function module is reading the ABAP spooljob and converting to PDF, writing it into new spooljob by submitting the report RSTXPDF5. How to download this spool output as PDF file? I used RSPO_DOWNLOAD_SPOOLJOB for this. But no success. If anybody has any inputs, please let me know.

Thanks in advance.

Regards,

Naveen

Hi,

I am using above function module to convert spool output into pdf format.

Spool output has more than 99 pages. for this reason, above function module is reading the ABAP spooljob and converting to PDF, writing it into new spooljob by submitting the report RSTXPDF5. How to download this spool output as PDF file? I used RSPO_DOWNLOAD_SPOOLJOB for this. But no success. If anybody has any inputs, please let me know.

Thanks in advance.

Regards,

Naveen

6 REPLIES 6
Read only

Former Member
0 Likes
1,934

check the following Code

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

or

try these fun modules.

CONVERT_ITF_TO_RTF

LIST_CONVERT_TO_RTF

LIST_CONVERT_TO_RTF_FROM_LIST

SKTU_TEXT_GET_CONVERT_TO_RTF

reward if useful

Read only

Former Member
0 Likes
1,934

hi

good

pleae check this.

As of Release 4.6D, PDF format (Adobe Acrobat data format) can be created via the SAP spooler by using the device type "PDF1".

As a workaround, a report (RSTXPDFT4) is made available for the missing "direct PDF printing", which can read spool requests, convert to PDF and perform a frontend download.

Read OSS Note 317851 - Printing PDF files in 4.6C/4.6B/4.5B

Note the restrictions specified in Note 323736 with the print output with PDF.

Caution when modifying device type ZPDF1, see Note 437696.

Version < 4.6D

If you are in version less than 4.6D, you can configure an output type to convert the spool automatically into a PDF format into your local harddisk but not do a "direct PDF printing".

When you print to this PDF output type, it will prompt you to enter the file name of your PDF file to be stored into your local harddisk.

First you have to add a printer using

Windows -> Start -> Settings -> Printers -> Generic / Text Only -> Port : Print to File

Next create a new device type e.g. ZPDF -> Select device type ZPDF1

Options for HostSpoolAccMethod -> Host spool access method : F : Printing on Frontend Computer

Host Printer : __DEFAULT or Generic / Text Only

Save your entries.

When you print to the device type ZPDF, choose Generic / Text Only for the Frontend Computer if it is not the default type.

A user prompt Print to File will appear to let you specify the Output File Name.

thanks

mrutyun^

Read only

former_member404244
Active Contributor
0 Likes
1,934

Hi,

Check the below link

http://www.sapdev.co.uk/reporting/rep_spooltopdf.htm

Regards,

Nagaraj

Read only

Former Member
0 Likes
1,934

Hi,

My program output is not in OTF format. So any function modules related to OTF don't work. Its an ABAP Spool output.

I have used 'CONVERT_ABAPSPOOLJOB_2_PDF' function module to convert the ABAP spool output into PDF format and with 'GUI_DOWNLOAD' i am saving PDF file locally. This works if the spool output has less than 99 pages of output. If the spool output has more than 99 pages, then 'CONVERT_ABAPSPOOLJOB_2_PDF' function module submits program 'RSTXPDF5' in background internally. I will come to know about thsi job's spool id also. But question here is, how to download and save this spool output as PDF file. Because i can't use 'CONVERT_ABAPSPOOLJOB_2_PDF' to convert the second spool output into PDF as the second spool doesn't contain ABAP spool data. i guess it has PDF converted data.

Thanks in advance.

Regards,

Naveen

Read only

0 Likes
1,934

How did you solve this to get the converted SPOOL with PDF format to download it to a PDF file ?

Read only

vallisha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,934

Check this -->