Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Note able to open the FBV2 PDF attachment. Show error as in browser as 'file can't open'.

nihar_das
Discoverer
0 Kudos
327

I attached a PDF file from AL11(Application Server) to Parked Document. But while opening the Parked document in the attachment list the PDF file is displaying , but while trying to open, it is showing the the below error.

Below is the program and the source code i used it. Any error in that, Kindly suggest me.

OPEN DATASET lv_file FOR INPUT IN BINARY MODE.
READ DATASET lv_file INTO lv_xstring.
IF sy-subrc NE 0.
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = lv_xstring
* APPEND_TO_TABLE = ' '
IMPORTING
output_length = lv_length
TABLES
binary_tab = lt_pdfout .
EXIT.
ENDIF.

CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = lv_xstring "ls_pdfout-line
* APPEND_TO_TABLE = ' '
IMPORTING
output_length = lv_length
TABLES
binary_tab = lt_pdfout .

CLOSE DATASET lv_file.

CALL FUNCTION 'SO_FOLDER_ROOT_ID_GET'
EXPORTING
* OWNER = ' '
region = 'B'
IMPORTING
folder_id = ls_fol_id
EXCEPTIONS
communication_failure = 1
owner_not_exist = 2
system_failure = 3
x_error = 4
OTHERS = 5 .
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

DATA(ls_object) = VALUE borident( objkey = ls_files2-name && ls_files1-name+0(14) objtype = 'BKPF' )."'FIPP' ).
DATA(lv_filename) = ls_files1-name.
DATA(lv_filepath) = p_dir.
SPLIT lv_filename AT '.' INTO DATA(lv_strip) DATA(lv_extension).
DATA(ls_obj_data) = VALUE sood1( objsns = 'O' objla = sy-langu objdes = ls_files1-name file_ext = lv_extension objlen = lv_length )."lines( lt_pdfout ) * 255 ).

TRANSLATE ls_obj_data-file_ext TO UPPER CASE.

* Insert data
CALL FUNCTION 'SO_OBJECT_INSERT'
EXPORTING
folder_id = ls_fol_id
object_type = 'EXT'
object_hd_change = ls_obj_data
IMPORTING
object_id = ls_obj_id
TABLES
objhead = ls_objhead
objcont = lt_pdfout
EXCEPTIONS
active_user_not_exist = 1
communication_failure = 2
component_not_available = 3
dl_name_exist = 4
folder_not_exist = 5
folder_no_authorization = 6
object_type_not_exist = 7
operation_no_authorization = 8
owner_not_exist = 9
parameter_error = 10
substitute_not_active = 11
substitute_not_defined = 12
system_failure = 13
x_error = 14
OTHERS = 15.

IF sy-subrc = 0 AND
ls_object-objkey IS NOT INITIAL.

DATA(ls_folmem_k) = VALUE sofmk( foltp = ls_fol_id-objtp folyr = ls_fol_id-objyr folno = ls_fol_id-objno
doctp = ls_obj_id-objtp docyr = ls_obj_id-objyr docno = ls_obj_id-objno ).

DATA(lv_ep_note) = ls_folmem_k.
DATA(ls_note) = VALUE borident( objtype = 'MESSAGE' objkey = lv_ep_note ).

* Link it
CALL FUNCTION 'BINARY_RELATION_CREATE_COMMIT'
EXPORTING
obj_rolea = ls_object
obj_roleb = ls_note
relationtype = 'ATTA'
EXCEPTIONS
no_model = 1
internal_error = 2
unknown = 3
OTHERS = 4.
IF sy-subrc EQ 0.
COMMIT WORK.
WRITE:/ 'Attached successfully'.
ENDIF.
ELSE.
MESSAGE 'Error while opening file' TYPE 'I'.
LEAVE LIST-PROCESSING.
ENDIF.

3 REPLIES 3

Sandra_Rossi
Active Contributor
0 Kudos
261

Please edit your question, select your code and press the "CODE" button to make it correctly colorized/indented, so that it's easier for us to analyze it. Thank you.

Sandra_Rossi
Active Contributor
261

Sorry, we can't debug here. If you need assistance, please tell us more about what you checked in debug (like: what is length of input file, what is value in lv_length, what are hexadecimal values of first bytes in variable lt_pdfout - should be 25504446, number of lines of lt_pdfout, etc.)

dhirendra_pandit
Active Participant
0 Kudos
261

Hello Nihar Das,

Your file reading mechanism is not written properly. The binary data needs to be read until the complete file data is read.

Use below code to read complete data in your program.

DO.

READ DATASET FNAME INTO TEXT2.

IF SY-SUBRC <> 0.

EXIT.

else.

CONCATANATE lv_xstring TEXT2 into lv_xstring .

ENDIF.

ENDDO.

lv_length = strlen(lv_xstring).

------>>>> Continue your logic after that

CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = lv_xstring
* APPEND_TO_TABLE = ' '
IMPORTING
output_length = lv_length
TABLES
binary_tab = lt_pdfout .
EXIT.
ENDIF.

Regards,

Dhirendra Pandit