Skip to Content
0
Former Member
Feb 13, 2009 at 08:38 AM

Error in SO_NEW_DOCUMENT_ATT_SEND_API1. Unable to open the pdf attachment

569 Views

Hi all,

I'm currently using SO_NEW_DOCUMENT_ATT_SEND_API1 to send out the email and together with a pdf attachment. However when I tried to open the attachment, it has the decoded incorrectly error.

What am I missing?

Thanks.

Below is the code, this is just testing purposes. I apologized for the messy code.

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: l_functionmodule TYPE rs38l_fnam.

DATA: l_spoolid TYPE rspoid,

l_control_parameters TYPE ssfctrlop,

l_output_options TYPE ssfcompop,

l_user_settings TYPE tdbool VALUE ' ',

l_document_output_info TYPE ssfcrespd,

l_job_output_info TYPE ssfcrescl,

l_job_output_options TYPE ssfcresop,

l_spoolid_del TYPE rqident,

l_status TYPE sysubrc,

li_table01 TYPE TABLE OF YGLXX_PDF_S_TABLE,

lw_table01 LIKE YGLXX_PDF_S_TABLE,

bin TYPE xstring.

DATA: i_otfdata TYPE STANDARD TABLE OF itcoo INITIAL SIZE 0.

DATA: l_otfdata TYPE itcoo.

DATA: lv_bytes TYPE p,

lv_bin_file TYPE xstring,

gt_pdfdata TYPE STANDARD TABLE OF tline INITIAL SIZE 0,

CONTENT_OUT TYPE TABLE OF SOLISTI1.

data: begin of itab occurs 0,

line(255) type c,

end of itab.

Creating the document to be sent

DOC_CHNG-OBJ_NAME = 'OFFER'.

DOC_CHNG-OBJ_DESCR = 'Auction of a Picasso jr'.

OBJTXT = 'Reserve price : $250000'.

APPEND OBJTXT.

OBJTXT = 'A reproduction of the painting to be auctioned'.

APPEND OBJTXT.

OBJTXT = 'is enclosed as an attachment.'.

APPEND OBJTXT.

DESCRIBE TABLE OBJTXT LINES TAB_LINES.

READ TABLE OBJTXT INDEX TAB_LINES.

DOC_CHNG-DOC_SIZE = ( TAB_LINES - 1 ) * 255 + STRLEN( OBJTXT ).

Creating the entry for the compressed document

CLEAR OBJPACK-TRANSF_BIN.

OBJPACK-HEAD_START = 1.

OBJPACK-HEAD_NUM = 0.

OBJPACK-BODY_START = 1.

OBJPACK-BODY_NUM = TAB_LINES.

OBJPACK-DOC_TYPE = 'RAW'.

APPEND OBJPACK.

Creating the document attachment (PDF)

Get Function Module of Smartform

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

EXPORTING

formname = 'YGLPA_IDR'

IMPORTING

fm_name = l_functionmodule

EXCEPTIONS

no_form = 1

no_function_module = 2

OTHERS = 3.

Set Print Parameters

l_control_parameters-langu = 'EN'.

l_control_parameters-no_dialog = 'X'.

l_control_parameters-getotf = 'X'.

l_output_options-tddest = 'LOCL'.

LOOP AT li_table01 INTO lw_table01.

lw_table01-line = '0002'.

APPEND lw_table01 TO li_table01.

ENDLOOP.

Call Smartform Function Module

CALL FUNCTION l_functionmodule

EXPORTING

control_parameters = l_control_parameters

output_options = l_output_options

user_settings = l_user_settings

pernr = '20'

begda = sy-datum

endda = '99991231'

langu = sy-langu

audience = ''

data01 = ''

data02 = ''

data03 = ''

data04 = ''

data05 = ''

IMPORTING

document_output_info = l_document_output_info

job_output_info = l_job_output_info

job_output_options = l_job_output_options

TABLES

table01 = li_table01

EXCEPTIONS

formatting_error = 1

internal_error = 2

send_error = 3

user_canceled = 4

OTHERS = 5.

Populate OTF data table

LOOP AT l_job_output_info-otfdata INTO l_otfdata.

APPEND l_otfdata TO i_otfdata.

CLEAR l_otfdata.

ENDLOOP. " LOOP AT t_outtab-otfdata

Convert OTF into PDF

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

format = 'PDF'

IMPORTING

bin_filesize = lv_bytes

bin_file = bin

TABLES

otf = i_otfdata

lines = gt_pdfdata

EXCEPTIONS

err_max_linewidth = 1

err_format = 2

err_conv_not_possible = 3

OTHERS = 4.

CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'

EXPORTING

BUFFER = bin

TABLES

BINARY_TAB = itab

.

objbin = itab.

APPEND objbin.

DESCRIBE TABLE OBJBIN LINES TAB_LINES.

*OBJHEAD = 'attach.pdf'. APPEND OBJHEAD.

Creating the entry for the compressed attachment

OBJPACK-TRANSF_BIN = 'X'.

OBJPACK-HEAD_START = 1.

OBJPACK-HEAD_NUM = 1.

OBJPACK-BODY_START = 1.

OBJPACK-BODY_NUM = TAB_LINES.

OBJPACK-DOC_TYPE = 'PDF'.

OBJPACK-OBJ_NAME = 'ATTACHMENT'.

OBJPACK-OBJ_DESCR = 'Attachment'.

OBJPACK-DOC_SIZE = TAB_LINES * 255.

APPEND OBJPACK..

Entering names in the distribution list

RECLIST-RECEIVER = '<emailadd>'.

RECLIST-REC_TYPE = 'U'.

APPEND RECLIST.

RECLIST-RECEIVER = 'DLI-NEUREICH'.

RECLIST-REC_TYPE = 'P'.

APPEND RECLIST.

Sending the document

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

CONTENTS_HEX = itab

RECEIVERS = RECLIST

EXCEPTIONS

TOO_MANY_RECEIVERS = 1

DOCUMENT_NOT_SENT = 2

OPERATION_NO_AUTHORIZATION = 4

OTHERS = 99.

CASE SY-SUBRC.

WHEN 0.

WRITE: / 'Result of the send process:'.

LOOP AT RECLIST.

WRITE: / RECLIST-RECEIVER(48), ':'.

IF RECLIST-RETRN_CODE = 0.

WRITE 'sent successfully'.

ELSE.

WRITE 'not sent'.

ENDIF.

ENDLOOP.

WHEN 1.

WRITE: / 'no authorization to send to the specified number of recipients!'.

WHEN 2.

WRITE: / 'document could not be sent to any of the recipients!'.

WHEN 4.

WRITE: / 'no authorization to send !'.

WHEN OTHERS.

WRITE: / 'error occurred during sending !'.

ENDCASE.