Skip to Content
0
Former Member
Aug 29, 2012 at 09:09 AM

Error while sending spool as PDF attachment in background

30 Views

Hi Expers,

I'm trying to use some Function Modules to download spool as an PDF attachment and send that attachment as a mail

I'm using the below mentioned logic.
But the PDF is not getting opened.

DATA : g_f_spool_nr TYPE tsp01-rqident,

g_it_spool TYPE TABLE OF soli WITH HEADER LINE,

g_f_real_type TYPE soodk-objtp.

DATA: BEGIN OF it_pdf_output OCCURS 0.

INCLUDE STRUCTURE tline.

DATA: END OF it_pdf_output.

DATA : gd_buffer TYPE string.

TYPES: BEGIN OF g_ty_objpack,

rqnumber TYPE rspotype-rqnumber, " Spool request number

head_start TYPE sopcklsti1-head_start, " Start line of obj. hdr

head_num TYPE sopcklsti1-head_num, " Number of lines

body_start TYPE sopcklsti1-body_start, " Start ln. of obj. cnts

body_num TYPE sopcklsti1-body_num, " Number of lines

no_lines TYPE i,

END OF g_ty_objpack.

DATA: g_f_no_lines TYPE i,

g_it_objbin TYPE TABLE OF solisti1.

DATA: g_it_objpack TYPE STANDARD TABLE OF g_ty_objpack,

g_wa_objpack TYPE g_ty_objpack,

g_wa_document_data TYPE sodocchgi1,

g_wa_docsize TYPE sy-index,

g_it_message TYPE TABLE OF solisti1 WITH HEADER LINE.

DATA : g_it_objtxt TYPE TABLE OF solisti1 WITH HEADER LINE,

g_wa_lines TYPE sy-tabix,

g_it_packing_list TYPE TABLE OF sopcklsti1 WITH HEADER LINE.

SELECT MAX( rqident ) INTO g_f_spool_nr FROM tsp01

WHERE rqclient = sy-mandt

AND rqowner = sy-uname.

CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'

EXPORTING

SRC_SPOOLID = g_f_spool_nr

* NO_DIALOG =

* DST_DEVICE =

TABLES

PDF = it_pdf_output

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.

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

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

ENDIF.

LOOP AT it_pdf_output INTO it_pdf_output .

TRANSLATE it_pdf_output USING ' ~'.

CONCATENATE gd_buffer it_pdf_output INTO gd_buffer IN CHARACTER MODE.

ENDLOOP.

TRANSLATE gd_buffer USING '~ ' .

IF NOT it_pdf_output[] IS INITIAL.

g_it_objbin[] = it_pdf_output[].

DESCRIBE TABLE it_pdf_output LINES g_f_no_lines.

ENDIF.

*Building table g_lt_objpack internal table for creating attachments

g_wa_objpack-rqnumber = g_f_spool_nr.

g_wa_objpack-head_start = 1.

g_wa_objpack-head_num = 0.

g_wa_objpack-body_start = 1.

g_wa_objpack-no_lines = g_f_no_lines.

g_wa_objpack-body_num = g_wa_objpack-no_lines.

APPEND g_wa_objpack TO g_it_objpack.

*To format the text of the mail content

g_wa_document_data-doc_size = g_wa_docsize.

g_wa_document_data-obj_langu = sy-langu.

g_wa_document_data-obj_name = 'Message'.

MOVE 'LIABILITY REPORT' TO

g_wa_document_data-obj_descr.

REFRESH g_it_message.

g_it_message = 'Please find the attached list'.

APPEND g_it_message .

" POPULATE_EMAIL_MESSAGE_BODY

" descr_content_message .

LOOP AT g_it_message .

g_it_objtxt = g_it_message-line.

APPEND g_it_objtxt.

ENDLOOP.

DESCRIBE TABLE g_it_objtxt LINES g_wa_lines.

IF g_wa_lines GE 0.

READ TABLE g_it_objtxt INTO g_it_objtxt INDEX g_wa_lines.

g_wa_document_data-doc_size = ( g_wa_lines - 1 ) * 255 + STRLEN(

g_it_objtxt ).

g_wa_document_data-obj_langu = sy-langu.

g_wa_document_data-sensitivty = 'F'.

ELSE.

g_wa_document_data = 0.

ENDIF.

g_it_packing_list-head_start = 1.

g_it_packing_list-head_num = 1.

g_it_packing_list-body_start = 0.

g_it_packing_list-body_num = g_wa_lines.

g_it_packing_list-doc_type = 'RAW'.

g_it_packing_list-transf_bin = ' '.

APPEND g_it_packing_list.

DESCRIBE TABLE it_pdf_output LINES g_wa_lines.

IF NOT g_it_objpack[] IS INITIAL.

* Create attachment notification

LOOP AT g_it_objpack INTO g_wa_objpack.

g_it_packing_list-transf_bin = 'X'.

g_it_packing_list-head_start = g_wa_objpack-head_start.

g_it_packing_list-head_num = g_wa_objpack-head_num.

g_it_packing_list-body_start = g_wa_objpack-body_start.

g_it_packing_list-doc_type = 'PDF'.

g_it_packing_list-body_num = g_wa_objpack-body_num.

g_it_packing_list-obj_name = 'Attach'..

g_it_packing_list-obj_descr = 'LIABILITY Report'.

g_it_packing_list-doc_size = g_it_packing_list-body_num * 255.

APPEND g_it_packing_list.

ENDLOOP.

ENDIF.

*---Send attachment

CALL FUNCTION 'SO_DOCUMENT_SEND_API1'

EXPORTING

DOCUMENT_DATA = g_wa_document_data

PUT_IN_OUTBOX = 'X'

SENDER_ADDRESS_TYPE = 'B'

COMMIT_WORK = 'X'

TABLES

PACKING_LIST = g_it_packing_list

CONTENTS_BIN = g_it_objbin

CONTENTS_TXT = g_it_objtxt

RECEIVERS = t_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.

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

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

ENDIF.

Any kind of help would be appreciated and rewarded.
Thanks in advance.