Skip to Content
avatar image
Former Member

How to save data and file in one shot?


I have a requirement that user enters some data and attaches his file. I want to store file and other text data at one time.How to achieve it?


Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • avatar image
    Former Member
    Sep 29, 2015 at 04:31 AM
    Add comment
    10|10000 characters needed characters exceeded

    • Hi Narendra

      you can use create_stream method to save(create ) the attachment in sap .

      Please follow these steps

      1) Redine below mwthod in in zCL_VP_ORDER_DASH_MPC_EXT

      method DEFINE.         "

           super->define( ).

           data:lo_entity   type ref to /iwbep/if_mgw_odata_entity_typ,

                lo_property type ref to /iwbep/if_mgw_odata_property.

           lo_entity = model->get_entity_type( iv_entity_name = 'TWFileAttach' ).

           if lo_entity is bound.

             lo_property = lo_entity->get_property( iv_property_name = 'Mimetype' ).

             lo_property->set_as_content_type( ).




      2)Redifine Create_Stream method in zCL_VP_ORDER_DASH_DPC_EXT

      data:    mimetype          type char100,

                 filename          type char100,

                 ls_stream         type ty_s_media_resource,

                 filetype          type char3,

                 lo_facade         type ref to /iwbep/if_mgw_dp_int_facade,

                 lt_client_headers type tihttpnvp,

                 ev_message        type bapi_msg,

                is_data type "your structure

      case iv_entity_name.

      when 'Entityname'.

               clear :mimetype,filename,content,filetype.

               split iv_slug at '/' into filename filetype.

               mimetype = is_media_resource-mime_type.

               content  = is_media_resource-value.

      *      mimetype = filetype.

              is_data-content = content.

              is_data-mimetype = mimetype.

              is_data-filename = filename.

      move all coreresponding fields into your structure.

      modify or insert data base table


      Let me know if you get any problem