
SAP CRM Technical Consultants sometimes comes across a requirement from the clients on business scenarios where they are asked to upload a File from the Presentation Server ( e.g Desktop, PC, Laptop, etc. ) into Application Server i.e SAP CRM System. This may be due a wide range of business requirements ranging from Mass Operations like bulk upload of Business Partners in the system and mass upload of data from external sources for Lead Generation. Based on the business case either a plain and simple flat file is used or a CSV File can also be fed into. Text File has the flexibility of platform independence and can be used and downloaded across multiple environments.
In the sample code below, either a CSV File can be used or a text file can also be used. I have created my own Z Component and have used the SAP Standard Component - GS_FILE_UPLOAD as a component usage in my component. Here the only intention is to upload a table of Business Partners into the system.
Assumptions
I have made the following assumptions regarding the technical skill which I feel is a prerequisite in order to execute the sample example provided in this document.
If you don't have extensive skills in the above mentioned topics still you can proceed with this document. But you may need to refer some document on basics of SAP CRM Web UI programming.
I guess there must be some existing component in the system. If you don't have an existing component then you can create a sample component with any model node. This is just for your reference and will brush up your old skills of component creation.
Execute the CRM Web UI workbench Transaction Code : BSP_WD_CMPWB. Create a component here and toggle off the enhancement set button as we will not be enhancing any standard component here.
Next step is to create a new View as shown below :
Add or create a New Node with the structure already defined as shown below and then complete the subsequent steps to complete the view creation. Then add the view into the Runtime Repository.
Then complete the configuration by adding the fields in the result list.
Add two buttons for upload and clearing the uploaded data as shown below:
If you have an already existing Web UI Component, then in order to upload Text/CSV Excel Files in SAP CRM Web Client UI the following steps needed to be performed. We will be using an already existing Web UI Component as component usage and there is no further requirement of JavaScript Coding. The excel files that need to be uploaded must be of type CSV – comma separated values excel. In additional plain text files can also be used. The uploaded data is stored as content in a string.
Use an already existing SAP CRM Web UI component
Create a New View
Add the following 2 Events in the View
In the Upload method add the following piece of code
Define the following Popup Access Interface in the Implementation Class of the View
In the other Method – EH_ONUPLOAD_POPUP_CLOSED put the following piece of code. Here based on the content we need to classify the data into appropriate structure.
METHOD eh_onupload_popup_closed.
TYPES: BEGIN OF l_ty_attr_struct,
businesspartner TYPE bu_partner,
partnerdescription TYPE bu_descrip_long,
END OF l_ty_attr_struct.
DATA:l_v_file_content TYPE string,
l_i_file_content TYPE stringtab,
l_v_file_type TYPE string,
l_v_file_name TYPE string,
l_o_outputnode TYPE REF TO cl_bsp_wd_context_node,
l_o_collection_wrapper TYPE REF TO cl_bsp_wd_collection_wrapper,
l_if_property TYPE REF TO if_bol_bo_property_access,
l_o_msg_service TYPE REF TO cl_bsp_wd_message_service,
l_i_bp TYPE zbupa_desc,
l_wa_bp TYPE zbupa_desc,
l_v_status TYPE zmember_status,
l_o_entity TYPE REF TO cl_crm_bol_entity,
l_i_return TYPE bapiret2_t,
l_wa_return TYPE bapiret2,
l_v_struct_ref TYPE REF TO zaccount_upload1,
l_o_value_node TYPE REF TO cl_bsp_wd_value_node,
l_if_bo_coll TYPE REF TO if_bol_bo_col,
l_v_fired_plug TYPE seocmpname.
FIELD-SYMBOLS: <fs_file_content> TYPE string,
<l_fs_wa_data> TYPE zaccount_upload1.
l_v_fired_plug = ci_if_popup->get_fired_outbound_plug( ).
CASE l_v_fired_plug.
WHEN 'leave'.
* get results of popup
l_o_outputnode ?= ci_if_popup->get_context_node( 'FILE' ). "#EC NOTEXT
l_o_collection_wrapper = l_o_outputnode->get_collection_wrapper( ).
l_if_property = l_o_collection_wrapper->get_current( ).
CALL METHOD l_if_property->get_property_as_value
EXPORTING
iv_attr_name = 'FILE_CONTENT_TYPE' "#EC NOTEXT
IMPORTING
ev_result = l_v_file_type.
CALL METHOD l_if_property->get_property_as_value
EXPORTING
iv_attr_name = 'FILE_NAME' "#EC NOTEXT
IMPORTING
ev_result = l_v_file_name.
* Check the MIME file type and the file extension
IF ( l_v_file_type CP 'text/plain' )
OR ( l_v_file_type CP 'text/comma-separated-values' )
OR ( l_v_file_type CP 'application/vnd.ms-excel' AND l_v_file_name CP '*.csv' ). "#EC NOTEXT
CALL METHOD l_if_property->get_property_as_value
EXPORTING
iv_attr_name = 'FILE_CONTENT_STRING' "#EC NOTEXT
IMPORTING
ev_result = l_v_file_content.
IF l_v_file_content IS INITIAL.
l_o_msg_service ?= me->view_manager->get_message_service( ).
l_o_msg_service->add_message( iv_msg_type = 'E'
iv_msg_id = 'CRM_UI'
iv_msg_number = '030' ). "#EC NOTEXT
EXIT.
ENDIF.
IF me->typed_context->exupd2->collection_wrapper IS BOUND.
me->typed_context->exupd2->collection_wrapper->clear( ).
ENDIF.
* Split filecontent into separate lines and store them in table
SPLIT l_v_file_content AT cl_abap_char_utilities=>cr_lf INTO TABLE l_i_file_content.
CLEAR l_v_file_content.
* Remove empty lines from filecontent table and store on value node
LOOP AT l_i_file_content ASSIGNING <fs_file_content>.
IF NOT <fs_file_content> IS INITIAL.
l_wa_bp-partner = <fs_file_content>.
APPEND l_wa_bp TO l_i_bp.
ENDIF.
ENDLOOP.
IF l_i_bp[] IS NOT INITIAL.
CREATE OBJECT l_if_bo_coll TYPE cl_crm_bol_bo_col.
IF l_if_bo_coll IS BOUND.
l_if_bo_coll->set_multi_select( abap_true ).
ENDIF.
LOOP AT l_i_bp INTO l_wa_bp.
REFRESH l_i_return.
CALL FUNCTION 'BUPA_DESCRIPTION_GET'
EXPORTING
iv_partner = l_wa_bp-partner
IMPORTING
ev_description_long = l_wa_bp-partner_desc
TABLES
et_return = l_i_return.
IF l_i_return IS NOT INITIAL.
CLEAR l_wa_return.
READ TABLE l_i_return INTO l_wa_return WITH KEY type = 'E'.
IF sy-subrc = 0.
l_wa_bp-partner_desc = l_wa_return-message.
ENDIF.
ENDIF.
CREATE DATA l_v_struct_ref.
ASSIGN l_v_struct_ref->* TO <l_fs_wa_data>.
<l_fs_wa_data>-partner_id = l_wa_bp-partner.
<l_fs_wa_data>-partner_descr = l_wa_bp-partner_desc.
CREATE OBJECT l_o_value_node
EXPORTING
iv_data_ref = l_v_struct_ref.
l_if_bo_coll->add( l_o_value_node ).
l_if_bo_coll->if_bol_bo_col_multi_sel~mark( EXPORTING iv_bo = l_o_value_node ).
UNASSIGN <l_fs_wa_data>.
ENDLOOP.
ENDIF.
* ENDIF.
me->typed_context->exupd2->collection_wrapper->set_collection( l_if_bo_coll ).
me->typed_context->exupd2->collection_wrapper->publish_current( ).
ELSE.
* We assume an incorrect file type: it's neither a plain text file nor a .csv file
* Therefore -> raise an error message
l_o_msg_service ?= me->view_manager->get_message_service( ).
l_o_msg_service->add_message( iv_msg_type = 'E'
iv_msg_id = 'CRM_UI'
iv_msg_number = '018' ). "#EC NOTEXT
ENDIF.
WHEN OTHERS.
ENDCASE.
ENDMETHOD.
Add the following lines of code in the HTML file of the view
In the Component a new component Usage needs to be added
Now run the component
Click on Upload
Click the Upload File
Upload the File
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
10 | |
9 | |
7 | |
6 | |
4 | |
4 | |
3 | |
3 | |
3 | |
2 |