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: 

Attachment not opening in FBV3 transaction

0 Kudos

Hi All,

I am trying to attach a supporting document in FBV3 using the below code and getting error while trying open the attachment. Please help.

Requirement is to pass binary file(PDF) from front end using FM and attach it to FI document.

FUNCTION ytest_ws_att_pc.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(LS_CONTENT) TYPE STRING OPTIONAL
*"----------------------------------------------------------------------
DATA: ls_folder_id TYPE soodk,
gv_obj_data TYPE sodocchgi1, ",sood1,
gv_obj_data1 TYPE sood1, ",sood1,
object_id TYPE soodk,
ls_object TYPE borident,
lv_object TYPE borident,
lv_objkey TYPE swo_typeid,
ls_document_id TYPE sood4,
ls_length TYPE i,
lv_title TYPE SO_OBJ_DES,
lv_url_id TYPE SAEURI.

DATA: gt_objhead TYPE TABLE OF SOLISTI1," soli,
gt_objhead1 TYPE TABLE OF soli," ,
ls_objhead LIKE LINE OF gt_objhead,
gv_object_id TYPE soodk,
lt_binary TYPE soli_tab,
lt_binary1 TYPE TABLE OF SOLIX,
wa_binary1 TYPE SOLIX,
lv_content TYPE xstring,
fp_i_uri_table TYPE TABLE OF toauri,
l_wa_uri_table LIKE LINE OF fp_i_uri_table,
l_document_info TYPE SOFOLENTI1.
data :documents type standard table of sood4,
lt_cont type SOLI_TAB.
* lv_content = ls_content.


CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
EXPORTING
text = ls_content
IMPORTING
buffer = lv_content
EXCEPTIONS
failed = 1
OTHERS = 2.

CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = lv_content
IMPORTING
output_length = ls_length
TABLES
binary_tab = lt_binary1
EXCEPTIONS
error_message = 1.
* lt_binary1 = lt_binary.


CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = lv_content
IMPORTING
output_length = ls_length
TABLES
binary_tab = lt_binary
EXCEPTIONS
error_message = 1.


** convert from raw type to text
* call function 'SO_SOLIXTAB_TO_SOLITAB'
* exporting
* ip_solixtab = lt_binary
* importing
* ep_solitab = lt_cont.
*
CALL FUNCTION 'SO_CONVERT_CONTENTS_BIN'
EXPORTING
it_contents_bin = lt_binary[]
IMPORTING
et_contents_bin = lt_binary[].


CALL FUNCTION 'SO_FOLDER_ROOT_ID_GET'" Gets root id
EXPORTING
region = 'B'
IMPORTING
folder_id = ls_folder_id
EXCEPTIONS
OTHERS = 1.

gv_obj_data-obj_name = 'ATTACHMENT'.
gv_obj_data-obj_descr = 'Test attachment'.
gv_obj_data-obj_langu = sy-langu.
gv_obj_data-SENSITIVTY = 'O'.
ls_length = LINES( lt_binary1 ) * 255.
gv_obj_data-doc_size = ls_length.


CONCATENATE '&SO_FILENAME=' 'test' '.' 'pdf' INTO ls_objhead.
APPEND ls_objhead TO gt_objhead.
ls_objhead = '&SO_FORMAT=BIN'.

APPEND ls_objhead TO gt_objhead.


call function 'SO_DOCUMENT_INSERT_API1'
exporting
folder_id = ls_folder_id
document_data = gv_obj_data
document_type = 'FAX'
importing
document_info = l_document_info
tables
OBJECT_HEADER = gt_objhead
CONTENTS_HEX = lt_binary1
exceptions
folder_not_exist = 1
document_type_not_exist = 2
operation_no_authorization = 3
parameter_error = 4
x_error = 5
enqueue_error = 6
others = 7.

if sy-subrc <> 0.
* message id sy-msgid type sy-msgty number sy-msgno
* with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
* into bw02_1327-error.
* bw02_1320-choice = bw02_1324-choice.
exit.
endif.

IF sy-subrc = 0.
ls_document_id-foltp = ls_folder_id-objtp.
ls_document_id-folyr = ls_folder_id-objyr.
ls_document_id-folno = ls_folder_id-objno.
ls_document_id-objtp = l_document_info-OBJECT_ID+0(3). "gv_object_id-objtp.
ls_document_id-objyr = l_document_info-OBJECT_ID+3(2) . "gv_object_id-objyr.
ls_document_id-objno = l_document_info-OBJECT_ID+5(12). "gv_object_id-objno.
* ls_document_id-objtp = gv_object_id-objtp.
* ls_document_id-objyr = gv_object_id-objyr.
* ls_document_id-objno = gv_object_id-objno.
ENDIF.

lv_object-objtype = 'MESSAGE'.
lv_object-objkey = ls_document_id.

lv_objkey = '110111010000092015'.
ls_object-objkey = lv_objkey." Object key
ls_object-objtype = 'BKPF'." Object type

CALL FUNCTION 'BINARY_RELATION_CREATE_COMMIT'
EXPORTING
obj_rolea = ls_object " Work Order information
obj_roleb = lv_object " Folder and Object iD
relationtype = 'ATTA'
EXCEPTIONS
error_message = 1.

1 ACCEPTED SOLUTION

0 Kudos

Hi,

I have resolved this issue, There was an issue with the binary file i passed. I can directly get the binary data from front end and pass that to

'SO_DOCUMENT_INSERT_API1' with folder data.

1 REPLY 1

0 Kudos

Hi,

I have resolved this issue, There was an issue with the binary file i passed. I can directly get the binary data from front end and pass that to

'SO_DOCUMENT_INSERT_API1' with folder data.