Skip to Content
0
Jul 28, 2015 at 03:52 PM

how to attach file(attachment) in MIRO tcode using Function Module

1049 Views

Hi Experts,

My requirement is attach an a image(.TIF format ) and a text file(.TIF format) in MIRO code attachment. In mycode it updating into table but NOT in tcode, can anybody check my code where i am doing mistake .

My code is here...

_______________________________________________________________________________________________________________________________

FUNCTION /wits/apiv_fm_miroattach .

*"----------------------------------------------------------------------

*"*"Local Interface:

*" IMPORTING

*" REFERENCE(IM_DOCNO) TYPE /WITS/APIV_QHEAD-QUEID

*" REFERENCE(IM_MIRO) TYPE RBKP-BELNR

*" TABLES

*" ET_RETURN TYPE BAPIRETTAB

*"----------------------------------------------------------------------

DATA lv_object_id TYPE /inowits/p_object_id.

DATA lo_attach TYPE REF TO /inowits/p_cl_dms.

DATA ls_bapiret TYPE bapiret2.

DATA lt_files TYPE /inowits/p_t_attchments.

DATA ls_files LIKE LINE OF lt_files.

DATA lv_offset TYPE i.

DATA result_tab TYPE match_result_tab.

DATA ls_result_tab LIKE LINE OF result_tab.

DATA lt_return TYPE bapirettab.

DATA ls_return TYPE bapiret2.

DATA lv_ext TYPE string.

DATA lv_xstring TYPE xstring.

*** DATA lo_save TYPE REF TO /inowits/cl_fitv_gos.

DATA lv_string TYPE string.

DATA lv_count TYPE i.

DATA lv_file TYPE string.

DATA iv_file_name TYPE string.

DATA filefullname TYPE string.

DATA mime_type TYPE string.

DATA size TYPE i.

DATA offset TYPE i.

DATA offset_old TYPE i.

DATA temp_len TYPE i.

DATA objname TYPE string.

DATA l_obj_type TYPE so_obj_tp.

DATA hex_null TYPE x LENGTH 1 VALUE '20'.

DATA l_document_title TYPE so_text255.

DATA lt_objcont TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 6.

DATA objcont LIKE LINE OF lt_objcont.

DATA lt_ls_doc_change TYPE STANDARD TABLE OF sodocchgi1.

DATA ls_doc_change LIKE LINE OF lt_ls_doc_change.

DATA lt_data TYPE soli_tab.

DATA ls_data TYPE soli.

DATA lt_xdata TYPE solix_tab.

DATA ls_xdata TYPE solix.

DATA l_folder_id TYPE sofdk.

DATA ls_object_id TYPE soodk.

DATA l_object_id_fol TYPE so_obj_id.

DATA l_object_id TYPE so_obj_id.

DATA l_doc_info TYPE sofolenti1.

DATA l_object_hd_change TYPE sood1.

DATA l_tab_size TYPE int4.

DATA l_retype TYPE breltyp-reltype.

DATA lt_urltab TYPE STANDARD TABLE OF sood-objdes.

DATA lt_obj_header TYPE STANDARD TABLE OF solisti1.

DATA ls_header TYPE solisti1.

DATA l_obj_rolea TYPE borident.

DATA l_obj_roleb TYPE borident.

DATA iv_app_name TYPE string .

DATA iv_object_id TYPE string.

DATA iv_key TYPE string.

DATA iv_objkey TYPE swo_typeid.

DATA iv_objtype TYPE swo_objtyp.

iv_app_name = 'abc'.

iv_objkey = 51056015622015. "5105601541.

iv_object_id = 69.

iv_objtype = 'BUS2081'.

DATA : queid TYPE /wits/apiv_qhead-queid.

DATA : xblnr TYPE bkpf-xblnr .

CREATE OBJECT lo_attach.

******** Get the files data based on the Object id ********

**

TRANSLATE iv_app_name TO UPPER CASE.

CONCATENATE iv_app_name iv_object_id iv_key INTO lv_object_id SEPARATED BY '/'.

DATA : ls_qhead TYPE /wits/apiv_qhead,

lt_qhead TYPE TABLE OF /wits/apiv_qhead.

CALL METHOD /wits/apiv_cl_dms=>read

EXPORTING

iv_queid = 69

iv_texts = 'X'

iv_image = 'X'

IMPORTING

es_qhead = ls_qhead.

LOOP AT lt_qhead INTO ls_qhead.

******** Upload the files in Standard *******

CALL FUNCTION 'SO_FOLDER_ROOT_ID_GET'

EXPORTING

owner = sy-uname

region = 'B'

IMPORTING

folder_id = l_folder_id

.

size = xstrlen( lv_xstring ).

ls_doc_change-obj_name = '123.tif'. "lv_file.

ls_doc_change-obj_descr = '123.tif'. "lv_file.

ls_doc_change-obj_langu = sy-langu.

ls_doc_change-sensitivty = 'F'.

ls_doc_change-doc_size = size.

l_retype = 'ATTA'.

l_obj_type = 'RAW'."'EXT'.

l_object_hd_change-objdes = 'miro attachment' ."ls_doc_change-obj_descr.

l_object_hd_change-file_ext = 'TIF' ."lv_ext.

l_object_hd_change-ownnam = 'WITS'."lv_ext.

lv_file = '123.tif'.

*save object

CALL FUNCTION 'SO_OBJECT_INSERT'

EXPORTING

folder_id = l_folder_id

* object_fl_change = 'object_fl_change'

object_hd_change = l_object_hd_change

object_type = l_obj_type

* originator_id = 'owner_id'

owner = sy-uname

IMPORTING

* object_fl_display = object_fl_display

* object_hd_display = object_hd_display

object_id = ls_object_id

TABLES

objcont = lt_data "lt_data

objhead = lt_obj_header

* objpara = object_para

* objparb = object_parb

EXCEPTIONS

component_not_available = 01

folder_not_exist = 06

folder_no_authorization = 05

object_type_not_exist = 17

operation_no_authorization = 21

parameter_error = 23

OTHERS = 1000.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 INTO ls_return-message.

ls_return-type = sy-msgty.

ls_return-id = sy-msgid.

ls_return-number = sy-msgno.

ls_return-message_v1 = sy-msgv1.

ls_return-message_v2 = sy-msgv2.

ls_return-message_v3 = sy-msgv3.

ls_return-message_v4 = sy-msgv4.

APPEND ls_return TO lt_return.

RETURN.

ENDIF.

*create relation

* l_obj_rolea-objkey = QUEID.

l_obj_rolea-objkey = iv_objkey . "'xblnr'.

l_obj_rolea-objtype = iv_objtype . "'BUS2081'.

l_object_id_fol = l_folder_id.

l_object_id = ls_object_id.

CONCATENATE l_object_id_fol l_object_id INTO l_obj_roleb-objkey RESPECTING BLANKS.

l_obj_roleb-objtype = 'MESSAGE'.

CLEAR l_obj_roleb-logsys.

CALL FUNCTION 'BINARY_RELATION_CREATE'

EXPORTING

obj_rolea = l_obj_rolea

obj_roleb = l_obj_roleb

relationtype = l_retype

EXCEPTIONS

OTHERS = 1.

IF sy-subrc = 0.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

wait = 'X'

.

*** COMMIT WORK AND WAIT.

ELSE.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 INTO ls_return-message.

ls_return-type = sy-msgty.

ls_return-id = sy-msgid.

ls_return-number = sy-msgno.

ls_return-message_v1 = sy-msgv1.

ls_return-message_v2 = sy-msgv2.

ls_return-message_v3 = sy-msgv3.

ls_return-message_v4 = sy-msgv4.

APPEND ls_return TO lt_return.

RETURN.

ENDIF.

IF lt_return IS NOT INITIAL.

APPEND LINES OF lt_return TO et_return.

ENDIF.

CLEAR : ls_files,ls_result_tab,lv_ext,lv_xstring,lv_file,l_folder_id,

lv_file,lv_ext,lv_xstring,l_obj_rolea,l_obj_roleb,l_retype.

REFRESH : result_tab,lt_return,lt_data,lt_obj_header,lt_xdata.

ENDLOOP.

IF et_return IS INITIAL.

ls_return-type = 'S'.

ls_return-message = 'File(s) uploaded successfully'.

APPEND ls_return TO et_return.

CLEAR ls_return.

ENDIF.

ENDFUNCTION.