2023 May 10 5:10 PM
Good day
I'm starting with abap, I have a problem opening a PDF file received by mail.
I'm reading a pdf file from the server to send it by mail, to read it I'm using DATASET.
This is the error that I get when trying to open the PDF file “Error opening the document. The file is damaged and cannot be recovered”
This is the code used:
DATA: st_pdf TYPE solix,
ti_pdf TYPE TABLE OF solix,
lv_filename TYPE c LENGTH 50.
lv_filenameConst = '/usr/sap/tmp/filepdf.pdf'.
TRY .
OPEN DATASET lv_filename FOR INPUT IN BINARY MODE.
DO.
READ DATASET lv_filename INTO st_pdf.
IF sy-subrc NE 0.
EXIT.
ENDIF.
APPEND st_pdf to ti_pdf.
ENDDO.
CLOSE DATASET lv_filename.
CATCH cx_root INTO DATA(e_txt).
CLOSE DATASET lv_filename.
ENDTRY.
Can anyone see if I'm doing something wrong with the use of the DATASET or if there is some abap function that allows me to read the file from the server?
Thanks in advance
2023 May 10 5:36 PM
Please edit your question (Actions > Edit), select your code and press the button [CODE], which makes the code appear colored/indented, it will be easier for people to look at it. Thank you!
2023 May 10 8:03 PM
With BINARY MODE, remove the DO/ENDDO wrapping of the read dataset (check sample of online help)
But I don't think your code is related to your problem, it would be better to post the code that attaches the document to the email (wrong data length is a frequent error, so look for this READ DATASET option: [ACTUAL] LENGTH alen and use alen when attaching the mail.
OPEN DATASET dset FOR INPUT in BINARY MODE.
READ DATASET dset INTO xstr ACTUAL LENGTH FINAL(bytes).
CLOSE DATASET dset.
Also, hHow was the pdf generated
2023 May 10 9:31 PM
Thank you very much for your support
Your answer worked for me, apparently the way I was reading the PDF didn't get all the file information.
This is how the DATASET was implemented:
DATA: ti_pdf TYPE TABLE OF solix,
lv_content TYPE xstring,
lv_filename TYPE c LENGTH 50.
lv_filenameConst = '/usr/sap/tmp/filepdf.pdf'.
OPEN DATASET lv_filename FOR INPUT IN BINARY MODE.
READ DATASET lv_filename INTO lv_content.
IF sy-subrc NE 0.
EXIT.
ENDIF.
CLOSE DATASET lv_filename.
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = lv_content
IMPORTING
output_length = bytes
TABLES
binary_tab = ti_pdf.
I hope it will be you useful
2023 May 12 6:44 AM
2023 May 11 9:03 AM