cancel
Showing results for 
Search instead for 
Did you mean: 

How to save data and file in one shot?

0 Kudos

Hi,

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?

Thanks.

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member184867
Active Contributor
0 Kudos
hussain_p
Participant
0 Kudos

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( ).

     endif.

endmethod.

--------------------------------------------------------------------------------------------------------------------

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


endcase.


Let me know if you get any problem