Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Sapscript converted to PDF throug spool and sent via email

Hello gurus, i have the following code for the requeriment and when trying to open file through transaction SOST, the system says that the file is corrupted.

What am I doing wrong please?

Help is very appreciated!!!!

CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'

EXPORTING

src_spoolid = w_spool

no_dialog = c_marca

dst_device = zcts_itcpo-tddest

IMPORTING

pdf_bytecount = w_numbytes

TABLES

pdf = i_pdf

EXCEPTIONS

err_no_otf_spooljob = 1

err_no_spooljob = 2

err_no_permission = 3

err_conv_not_possible = 4

err_bad_dstdevice = 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 eq 0.

PERFORM f_convert_pdf TABLES i_pdf

i_objbin.

PERFORM f_send_mail.

endif.

FORM f_convert_pdf TABLES i_source_tab STRUCTURE tline

i_target_tab STRUCTURE zcts_objbin.

DATA: l_hfeld(1600) TYPE c,

l_offset TYPE p,

l_tabix TYPE sy-tabix,

l_linecount_source TYPE i,

l_length_source TYPE i,

l_length_target TYPE i.

CLEAR: l_hfeld,

l_offset,

l_tabix,

l_linecount_source,

l_length_source,

l_length_target,

zcts_pdf,

zcts_objbin.

DESCRIBE FIELD i_source_tab LENGTH l_length_source IN BYTE MODE.

DESCRIBE FIELD i_target_tab LENGTH l_length_target IN BYTE MODE.

DESCRIBE TABLE i_source_tab LINES l_linecount_source.

CLEAR:

i_target_tab,

zcts_pdf.

LOOP AT i_source_tab INTO zcts_pdf.

l_tabix = sy-tabix.

MOVE zcts_pdf TO l_hfeld+l_offset.

IF l_tabix EQ l_linecount_source.

l_length_source = STRLEN( zcts_pdf ).

ENDIF.

l_offset = l_offset + l_length_source.

WHILE l_offset GE l_length_target.

zcts_objbin = l_hfeld(l_length_target).

APPEND zcts_objbin TO i_target_tab.

CLEAR zcts_objbin.

SHIFT l_hfeld BY l_length_target PLACES.

l_offset = l_offset - l_length_target.

ENDWHILE.

IF l_tabix EQ l_linecount_source.

IF l_offset GT 0.

zcts_objbin = l_hfeld(l_offset).

APPEND zcts_objbin TO i_target_tab.

CLEAR zcts_objbin.

ENDIF.

ENDIF.

CLEAR:

i_source_tab,

zcts_pdf.

ENDLOOP.

ENDFORM. " f_convert_pdf

FORM f_send_mail .

DATA: l_lines_txt TYPE i,

l_lines_bod TYPE i.

CLEAR: i_reclist,

i_objpack,

l_lines_txt,

l_lines_bod.

CLEAR i_objhead.

  • Create here the mail body

DATA: li_mess_bod LIKE solisti1 OCCURS 0 WITH HEADER LINE.

CLEAR li_mess_bod.

li_mess_bod = text-012.

APPEND li_mess_bod.

IF sy-subrc EQ 0.

CLEAR zcts_objtxt.

ENDIF.

CLEAR i_materials.

READ TABLE i_materials INDEX 1.

IF sy-subrc EQ 0.

CONCATENATE text-013 i_materials-maktx INTO li_mess_bod SEPARATED BY space.

ENDIF.

APPEND li_mess_bod.

IF sy-subrc EQ 0.

CLEAR li_mess_bod.

ENDIF.

IF p_deliv IS INITIAL.

CONCATENATE text-014 p_sales INTO li_mess_bod SEPARATED BY space.

ELSE.

CONCATENATE text-014 p_deliv INTO li_mess_bod SEPARATED BY space.

ENDIF.

APPEND li_mess_bod.

IF sy-subrc EQ 0.

CLEAR li_mess_bod.

ENDIF.

DESCRIBE TABLE li_mess_bod LINES l_lines_bod.

CLEAR li_mess_bod.

READ TABLE li_mess_bod INDEX l_lines_bod.

IF sy-subrc NE 0.

CLEAR li_mess_bod.

ENDIF.

zcts_doc_chng-obj_name = 'CERTIFICATE'.

  • Subject

IF p_deliv IS INITIAL.

CLEAR i_delivery.

READ TABLE i_delivery INDEX 1.

IF sy-subrc EQ 0.

CONCATENATE text-011 i_delivery-vbeln sy-datum INTO zcts_doc_chng-obj_descr SEPARATED BY space.

ENDIF.

ELSE.

CONCATENATE text-011 p_deliv sy-datum INTO zcts_doc_chng-obj_descr SEPARATED BY space.

ENDIF.

  • Fill the document data and get size of attachment

zcts_doc_chng-sensitivty = c_sens.

zcts_doc_chng-doc_size = ( l_lines_bod - 1 ) * 255 + STRLEN( li_mess_bod ).

  • Body mail

CLEAR zcts_objpack-transf_bin.

zcts_objpack-head_start = 1.

zcts_objpack-head_num = 0.

zcts_objpack-body_start = 1.

zcts_objpack-body_num = l_lines_bod.

zcts_objpack-doc_type = c_doc_type.

APPEND zcts_objpack TO i_objpack.

  • PDF attachment

zcts_objpack-transf_bin = c_marca.

zcts_objpack-head_start = 1.

zcts_objpack-head_num = 0.

zcts_objpack-body_start = 1.

DESCRIBE TABLE i_objbin LINES l_lines_txt.

zcts_objpack-doc_size = l_lines_txt * 255.

  • zcts_objpack-doc_size = w_numbytes.

zcts_objpack-doc_type = c_doc_type2.

zcts_objpack-obj_name = c_obj_name.

CONCATENATE text-010 sy-datum INTO zcts_objpack-obj_descr SEPARATED BY space.

APPEND zcts_objpack TO i_objpack.

  • Mail destinary

zcts_reclist-receiver = text-018.

zcts_reclist-rec_type = c_rec.

zcts_reclist-com_type = c_com_type.

APPEND zcts_reclist TO i_reclist.

  • Call function below to sending PDF object to internet email address

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = zcts_doc_chng

put_in_outbox = c_marca

commit_work = c_marca

TABLES

packing_list = i_objpack

object_header = i_objhead

contents_bin = i_objbin

contents_txt = li_mess_bod

receivers = i_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 NE 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

ENDFORM. " f_send_mail

Tags:
Former Member
Not what you were looking for? View more on this topic or Ask a question