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 Spool to PDF

Former Member
0 Likes
485

Hi All,

wanted to convert list spool job to pdf format using any standard program. I have tried to convert spool # with standard program RSTXPDFT4, but unable to see the whole spool list in pdf. I want to fetch this using standard program only.

Thanks,

Sudheer

2 REPLIES 2
Read only

Former Member
0 Likes
427

Hi Sudheer

Use the following code

REPORT ZPDFFROMSPOOL2 .

TABLES: tsp01.

DATA:

mi_bytecount type i,

mtab_pdf like tline occurs 0 with header line,

mc_filename like rlgrap-filename.

DATA: objpack LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE.

DATA: objhead LIKE solisti1 OCCURS 1 WITH HEADER LINE.

DATA: objbin LIKE solisti1 OCCURS 10 WITH HEADER LINE.

DATA: objtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE.

DATA: reclist LIKE somlreci1 OCCURS 5 WITH HEADER LINE.

DATA: doc_chng LIKE sodocchgi1.

DATA: tab_lines LIKE sy-tabix.

DATA: lc_linea(5) TYPE c.

DATA: PDF_LINE(134),

STUFF(65000),

POS TYPE I,

LEN TYPE I.

PARAMETERS:

p_archi(20) type c OBLIGATORY,

p_dest(100) type c,

p_recip(10) type c,

id_spool LIKE tsp01-rqident,

nm_spool LIKE tsp01-RQ0NAME.

SELECTION-SCREEN BEGIN OF BLOCK dest_block WITH FRAME .

PARAMETER p_pc RADIOBUTTON GROUP uno.

PARAMETER p_server RADIOBUTTON GROUP uno.

PARAMETER p_email RADIOBUTTON GROUP uno DEFAULT 'X'.

SELECTION-SCREEN END OF BLOCK dest_block.

START-OF-SELECTION.

IF NOT p_pc IS INITIAL.

IF p_archi IS INITIAL.

  • DEBE Ingresar un nombre de archivo

ENDIF.

IF p_dest IS INITIAL.

  • DEBE Ingresar un DESTINO de archivo

ENDIF.

ENDIF.

IF NOT p_server IS INITIAL.

IF p_archi IS INITIAL.

  • DEBE Ingresar un nombre de archivo

ENDIF.

IF p_dest IS INITIAL.

  • DEBE Ingresar un DESTINO de archivo

ENDIF.

ENDIF.

IF NOT p_email IS INITIAL.

ENDIF.

IF id_spool IS INITIAL.

IF nm_spool IS INITIAL.

*ERROR DEBE CARGAR UN ID o NOMBRE DE SPOOL

ELSE.

  • BUSCA EL ID DEL SPOOL SEGUN EL NOMBRE Y USUARIO

perform get_spool_number using nm_spool

sy-uname

changing id_spool.

ENDIF.

ENDIF.

call function 'CONVERT_ABAPSPOOLJOB_2_PDF'

exporting

src_spoolid = id_spool

no_dialog = space

dst_device = 'LOCL'

importing

pdf_bytecount = mi_bytecount

tables

pdf = mtab_pdf

exceptions

err_no_abap_spooljob = 1

err_no_spooljob = 2

err_no_permission = 3

err_conv_not_possible = 4

err_bad_destdevice = 5

user_cancelled = 6

err_spoolerror = 7

err_temseerror = 8

err_btcjob_open_failed = 9

err_btcjob_submit_failed = 10

err_btcjob_close_failed = 11

others = 12.

IF sy-subrc <> 0.

ENDIF.

  • CLIENTE

IF NOT p_pc IS INITIAL.

CONCATENATE p_dest p_archi INTO mc_filename.

call function 'DOWNLOAD'

exporting

bin_filesize = mi_bytecount

filename = mc_filename

filetype = 'BIN'

importing

act_filename = mc_filename

tables

data_tab = mtab_pdf.

ENDIF.

  • Servidor

IF NOT p_server IS INITIAL.

CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'

EXPORTING

LINE_WIDTH_SRC = 134

LINE_WIDTH_DST = 255

TABLES

CONTENT_IN = mtab_pdf

CONTENT_OUT = OBJBIN

EXCEPTIONS

ERR_LINE_WIDTH_SRC_TOO_LONG = 1

ERR_LINE_WIDTH_DST_TOO_LONG = 2

ERR_CONV_FAILED = 3

OTHERS = 4

.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

CONCATENATE p_dest p_archi INTO mc_filename.

OPEN DATASET mc_filename FOR INPUT IN BINARY MODE.

LOOP AT OBJBIN.

TRANSFER OBJBIN-LINE TO mc_filename.

ENDLOOP.

CLOSE DATASET mc_filename.

ENDIF.

  • email

IF NOT p_email IS INITIAL.

  • Creación del documento a enviar

doc_chng-obj_name = p_archi.

doc_chng-obj_descr = ' '.

objtxt-line = 'Archivo Adjunto'.

APPEND objtxt.

CLEAR objtxt.

DESCRIBE TABLE objtxt LINES tab_lines.

READ TABLE objtxt INDEX tab_lines.

doc_chng-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objtxt-line )

.

  • Creación de la entrada del documentot

CLEAR objpack-transf_bin.

objpack-head_start = 1.

objpack-head_num = 0.

objpack-body_start = 1.

objpack-body_num = tab_lines.

objpack-doc_type = 'TXT'.

APPEND objpack.

CLEAR objpack.

  • Creación del Attachment

CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'

EXPORTING

LINE_WIDTH_SRC = 134

LINE_WIDTH_DST = 255

TABLES

CONTENT_IN = mtab_pdf

CONTENT_OUT = OBJBIN

EXCEPTIONS

ERR_LINE_WIDTH_SRC_TOO_LONG = 1

ERR_LINE_WIDTH_DST_TOO_LONG = 2

ERR_CONV_FAILED = 3

OTHERS = 4

.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

OBJPACK-DOC_TYPE = 'PDF'.

  • LOOP AT mtab_pdf INTO PDF_LINE.

  • STUFF+POS(134) = PDF_LINE.

  • ADD 134 TO POS.

  • ENDLOOP.

  • POS = 0.

  • LEN = STRLEN( STUFF ).

  • WHILE LEN > 0.

  • SUBTRACT 255 FROM LEN.

  • OBJBIN = STUFF+POS(255).

  • APPEND OBJBIN.

  • ADD 255 TO POS.

  • ENDWHILE.

DESCRIBE TABLE OBJBIN LINES TAB_LINES.

OBJHEAD = 'advice'.

APPEND OBJHEAD.

OBJPACK-TRANSF_BIN = 'X'.

OBJPACK-HEAD_START = 1.

OBJPACK-HEAD_NUM = 1.

OBJPACK-BODY_START = 1.

OBJPACK-BODY_NUM = TAB_LINES.

OBJPACK-OBJ_NAME = p_archi.

OBJPACK-OBJ_DESCR = 'PDF Adjunto'.

OBJPACK-DOC_SIZE = TAB_LINES * 255.

APPEND OBJPACK.

  • Lista de destinatarios

reclist-receiver = p_recip.

reclist-rec_type = 'B'.

reclist-express = 'X'.

APPEND reclist.

DESCRIBE TABLE reclist LINES tab_lines.

  • Envío del documento

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = doc_chng

put_in_outbox = 'X'

commit_work = 'X'

TABLES

packing_list = objpack

object_header = objhead

contents_bin = objbin

contents_txt = objtxt

receivers = reclist

EXCEPTIONS

too_many_receivers = 1

document_not_sent = 2

document_type_not_exist = 3

operation_no_authorization = 4

parameter_error = 5

x_error = 6

enqueue_error = 7

OTHERS = 8.

IF sy-subrc <> 0.

ENDIF.

ENDIF.

form get_spool_number using f_rqname f_uname

changing f_rqident.

data:

lc_rq2name like tsp01-rq2name.

select * from tsp01 where

RQ0NAME = f_rqname AND

RQOWNER = f_uname

order by rqcretime descending.

f_rqident = tsp01-rqident.

exit.

endselect.

if sy-subrc ne 0.

clear f_rqident.

endif.

endform." get_spool_number

Please reward if useful

Read only

Former Member
0 Likes
427

hi,

try this function module:

<b>CONVERT_ABAPSPOOLJOB_2_PDF</b>

convert abap spool output to PDF

hope it helps.

reward if helpful.

Regards,

Sipra