10-29-2019 1:18 PM
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.
10-29-2019 2:20 PM
from a quick view, I think when you add a doc to an email you have to specify the size of the attachment
there is also a class to help you converting all kind of table format: CL_BCS_CONVERT
10-29-2019 2:39 PM
Ah ok Thank you you are right.This solved my question:
Code for adding document size.
DATA: prc_lines TYPE i VALUE 0,
prc_line_len TYPE i VALUE 0,
prc_bin_filesize TYPE i VALUE 0,
gv_size TYPE SOOD-OBJLEN.
FIELD-SYMBOLS: <f> TYPE ANY.
DESCRIBE TABLE GT_BINARCHIVOBJECT LINES prc_lines.
LOOP AT GT_BINARCHIVOBJECT ASSIGNING <f>.
DESCRIBE FIELD <f> LENGTH prc_line_len IN BYTE MODE.
EXIT.
ENDLOOP.
prc_bin_filesize = prc_lines * prc_line_len.
gv_size = prc_bin_filesize.
And the second what could be is for file types which are with more than 3 decimal places:
Like the new Office formats: .docx, .xlsx, etc
data: lt_add_header TYPE SOLI_TAB,
lv_header type string.
CONCATENATE '&SO_FILENAME=' 'TEST.PDF' INTO lv_header.
APPEND lv_header TO lt_add_header.
And then at the class (inclusive the language):
try.
GO_DOCUMENT->ADD_ATTACHMENT( " Hier sind wir schon bei CL_BCS !
exporting
I_ATTACHMENT_TYPE = 'PDF'
I_ATTACHMENT_SUBJECT = 'Test Mail'
I_ATTACHMENT_LANGUAGE = 'D' "new optional
I_ATT_CONTENT_HEX = GT_SOLIX_TAB
I_ATTachment_size = gv_size
I_ATTachment_header = lt_add_header "new optional
).
catch CX_DOCUMENT_BCS into GX_DOCUMENT_BCS.
endtry.
10-29-2019 2:57 PM
Good news
thank for the feedback (and do not forget to close your question)