Quantcast
Channel: SCN : All Content - All Communities
Viewing all articles
Browse latest Browse all 3184

Attach File to Services to Object in VA03 (GOS) from Program

$
0
0

Hello All,

 

I am trying to upload an attachment to services to Object (GOS) in VA03 from custom program. I can see the attachment added in the attachment list but when i try to open it I get below error.

error.PNG

 

below is the program written.

FUNCTION z_dbill_create_attach.

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

*"*"Local Interface:

*"  IMPORTING

*"     REFERENCE(IM_VBELN) TYPE  VBELN

*"     REFERENCE(IM_PATH) TYPE  LOCALFILE OPTIONAL

*"     REFERENCE(IM_FNAME) TYPE  STRING

*"     REFERENCE(IM_XSTRING) TYPE  FPCONTENT

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

   DATA :         ls_fol_id     TYPE soodk,

                  ls_obj_id     TYPE soodk,

                  ls_obj_data   TYPE sood1,

                  ls_objhead    TYPE soli,

                  lv_key        TYPE swo_typeid,

                  lv_type       TYPE swo_objtyp,

                  ls_object     TYPE borident,

                  ls_folmem_k   TYPE sofmk,

                  lv_ep_note    TYPE borident-objkey,

                  ls_note       TYPE borident,

                  lv_name       TYPE string,

                  lv_extension  TYPE string,

                  lv_offset     TYPE i,

                  lv_size       TYPE i,

                  lv_temp_len   TYPE i,

                  lv_offset_old TYPE i.

 

   DATA: lt_doc_content TYPE solix_tab,

         lt_cont        TYPE soli_tab,

         lt_objhead     TYPE STANDARD TABLE OF soli.

 

*-----Folder Root

   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.

 

 

   CHECK sy-subrc = 0.

 

   CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'

     EXPORTING

       buffer          = im_xstring

       append_to_table = c_x

     TABLES

       binary_tab      = lt_doc_content.

 

   CALL FUNCTION 'SO_SOLIXTAB_TO_SOLITAB'

     EXPORTING

       ip_solixtab = lt_doc_content

     IMPORTING

       ep_solitab  = lt_cont.

 

   SPLIT im_fname AT '.' INTO lv_name lv_extension.

   TRANSLATE lv_extension TO UPPER CASE .

 

   ls_obj_data-objsns    = 'O'.

   ls_obj_data-objla     = sy-langu.

   ls_obj_data-objdes    = lv_name .

   ls_obj_data-file_ext  = lv_extension.

 

   ls_obj_data-objlen    = lines( lt_doc_content ) * 255.

*  ls_obj_data-objlen  = xstrlen( im_xstring ).

 

   CONCATENATE '&SO_FILENAME=' lv_name '.' lv_extension INTO ls_objhead-line.

   APPEND ls_objhead TO lt_objhead.

 

   ls_objhead-line = '&SO_FORMAT=BIN'.

   APPEND ls_objhead TO lt_objhead.

 

 

   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               = lt_objhead

       objcont               = lt_cont

     EXCEPTIONS

       active_user_not_exist = 35

       folder_not_exist      = 6

       object_type_not_exist = 17

       owner_not_exist       = 22

       parameter_error       = 23

       OTHERS                = 1000.

 

   IF sy-subrc EQ 0 .

 

* attach document as GOS attacment to realted bussiness object

     ls_object-objkey  = im_vbeln.

     ls_object-objtype = 'BUS2096'.

 

     ls_folmem_k-foltp = ls_fol_id-objtp.

     ls_folmem_k-folyr = ls_fol_id-objyr.

     ls_folmem_k-folno = ls_fol_id-objno.

     ls_folmem_k-doctp = ls_obj_id-objtp.

     ls_folmem_k-docyr = ls_obj_id-objyr.

     ls_folmem_k-docno = ls_obj_id-objno.

 

     lv_ep_note        = ls_folmem_k.

     ls_note-objtype   = 'MESSAGE'.

     ls_note-objkey    = lv_ep_note.

 

     CALL FUNCTION 'BINARY_RELATION_CREATE_COMMIT'

       EXPORTING

         obj_rolea    = ls_object

         obj_roleb    = ls_note

         relationtype = 'ATTA'

       EXCEPTIONS

         OTHERS       = 1.

     IF sy-subrc = 0.

 

       CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

         EXPORTING

           wait = c_x.

 

       COMMIT WORK.

       WAIT UP TO 10 SECONDS.

     ENDIF.

   ENDIF.

 

ENDFUNCTION.



Please suggest where I am going wrong.


Regards

Ujwal


Viewing all articles
Browse latest Browse all 3184

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>