Skip to Content
0
Oct 29, 2019 at 01:18 PM

Send invoice from archive as pdf attachement via email

243 Views

Hi, i have a problem with following report.

The report gets a invoice (pdf) from the archive and sends it via email.

I can open this pdf attachement in Adobe reader but i get the following warning message.

The pdf seems not to be fully converted? But the file is not broken.

But i can't see the mistake.

report Z_SD_SDMAIL4.

class CL_BCS definition load.

data: GO_SEND_REQUEST type ref to CL_BCS,
GO_DOCUMENT type ref to CL_DOCUMENT_BCS,
GO_SENDER type ref to IF_SENDER_BCS,
GO_RECIPIENT type ref to IF_RECIPIENT_BCS,
GT_MESSAGE_BODY type BCSY_TEXT,
GX_DOCUMENT_BCS type ref to CX_DOCUMENT_BCS,
GV_SEND type AD_SMTPADR value 'email@adress.de',
GO_EMAIL_ERROR type ref to CX_BCS,
GV_EMAIL_MESSAGE type STRING,
GV_INPUT_LENGTH type I.

data:
GT_CONNECTIONS type table of TOAV0,
GS_CONNECTIONS type TOAV0,
GV_LENGTH like SAPB-LENGTH,
GV_BINLENGTH like SAPB-LENGTH,
GT_ARCHIVOBJECT type table of DOCS,
GT_BINARCHIVOBJECT type table of TBL1024,
GV_BUFFER type XSTRING,
GT_SOLIX_TAB type SOLIX_TAB.

data : begin of GT_BINARY_TAB occurs 0,
LINE type X length 255,
end of GT_BINARY_TAB.

call function 'ARCHIV_GET_CONNECTIONS'
exporting
OBJECTTYPE = 'VBRK'
OBJECT_ID = '0010086208' " invoice number / Rechnungsnumer
tables
CONNECTIONS = GT_CONNECTIONS
exceptions
NOTHING_FOUND = 1
others = 2.

loop at GT_CONNECTIONS into GS_CONNECTIONS.
call function 'ARCHIVOBJECT_GET_TABLE'
exporting
ARCHIV_ID = GS_CONNECTIONS-ARCHIV_ID
DOCUMENT_TYPE = 'PDF' "oc_type " = connection-reserve
ARCHIV_DOC_ID = GS_CONNECTIONS-ARC_DOC_ID
importing
BINLENGTH = GV_BINLENGTH
tables
ARCHIVOBJECT = GT_ARCHIVOBJECT
BINARCHIVOBJECT = GT_BINARCHIVOBJECT
exceptions
ERROR_ARCHIV = 1
ERROR_COMMUNICATIONTABLE = 2
ERROR_KERNEL = 3
others = 4.

*is not working
call method CL_RMPS_GENERAL_FUNCTIONS=>CONVERT_1024_TO_255
exporting
IM_TAB_1024 = GT_BINARCHIVOBJECT
receiving
RE_TAB_255 = GT_SOLIX_TAB.

endloop.

"create send request
GO_SEND_REQUEST = CL_BCS=>CREATE_PERSISTENT( ).

"create message body and subject
append 'Dear Vendor,' to GT_MESSAGE_BODY.
append initial line to GT_MESSAGE_BODY.
append 'Please fill the attached .' to GT_MESSAGE_BODY.
append initial line to GT_MESSAGE_BODY.
append 'Thank You,' to GT_MESSAGE_BODY.

"put your text into the document
GO_DOCUMENT = CL_DOCUMENT_BCS=>CREATE_DOCUMENT(
I_TYPE = 'RAW'
I_TEXT = GT_MESSAGE_BODY
I_SUBJECT = 'Vendor Payment Form' ).
try.
GO_DOCUMENT->ADD_ATTACHMENT( " Hier sind wir schon bei CL_BCS !
exporting
I_ATTACHMENT_TYPE = 'PDF'
I_ATTACHMENT_SUBJECT = 'Test Mail'
I_ATT_CONTENT_HEX = GT_SOLIX_TAB ).

catch CX_DOCUMENT_BCS into GX_DOCUMENT_BCS.
endtry.

* Add attachment
* Pass the document to send request
GO_SEND_REQUEST->SET_DOCUMENT( GO_DOCUMENT ).

GO_RECIPIENT = CL_CAM_ADDRESS_BCS=>CREATE_INTERNET_ADDRESS( GV_SEND ).

*--------------------------------------------------------------------*
*Add the recipient
*--------------------------------------------------------------------*
try.
call method GO_SEND_REQUEST->ADD_RECIPIENT
exporting
I_RECIPIENT = GO_RECIPIENT.
catch CX_SEND_REQ_BCS.
endtry.

GO_SEND_REQUEST->SET_SENDER( CL_SAPUSER_BCS=>CREATE( SY-UNAME ) ).

GO_SEND_REQUEST->SET_SEND_IMMEDIATELY( 'X' ).

*--------------------------------------------------------------------*
*Send Mail
*--------------------------------------------------------------------*
try.
call method GO_SEND_REQUEST->SEND( ).

commit work.
message 'Send Successfully' type 'S'.
catch CX_BCS into GO_EMAIL_ERROR.
GV_EMAIL_MESSAGE = GO_EMAIL_ERROR->GET_TEXT( ).
endtry.

Attachments

error.png (19.9 kB)