How to Multi Copy/Paste from Excel to GUIBB’s List ATS in FPM Application
Tags:
Overview :
This document describe how to multi copy/paste from excel to GUIBB’s List ATS works as of NW 7.31 SP05 and how it can be used in FPM applications.
In the earlier version of NW 7.02 SP12, it doesn’t support the copied clipboard data into list GUIBB directly. From NW releases 7.31 SP05, you can paste the copied clipboard data at any position of the selected cell (In beginning, In between , At Last) in the list.
Prerequisites:
SAP NetWeaver 7.31 SP05.
Step By Step Guide:
Step 1: Creation of feeder class for the GUIBB’s List ATS.
Go to SE24 transaction and create a usual ABAP class.
Choose the interface tab and implement the Generic User Interface BuildingBlock for list UIBB “IF_FPM_GUIBB_LIST “(Which is given by FPM framework for the LIST) and press Enter.It will automatically implement the interface for the Generic UIBB “IF_FPM_GUIBB”.
Now if you will go to the methods tab you will see some default methods implemented by these two interfaces.
Make sure you go inside each and every method and activate all the them so it will not give any short dump.
Because each implemented method is participate in event loop.
Create a structure by taking some field from sflight table and some fields to make all the displayed column in a list as input enabled.
Choose Attributes tab and define the private attribute MT_LIST of table type of structure ZTS_SFLIGHT.
Choose methods tab and double click on IF_FPM_GUIBB_LIST~GET_DEFINITION method of feeder class and paste below code for defining the field catalogue of list.
******************************* Data Declaration ***************************************
DATA: lo_field_catalog TYPE REF TO cl_abap_tabledescr,
lt_field_description TYPE fpmgb_t_listfield_descr,
lt_sflight TYPE TABLE OF ZTS_SFLIGHT.
FIELD-SYMBOLS: <fs_field_description> TYPE fpmgb_s_listfield_descr.
**-- Define Field Catalogue
lo_field_catalog ?= cl_abap_tabledescr=>describe_by_data( lt_sflight ).
**-- Define field description for the field catalogue
**--Adding all the refrence field into the field description
APPEND INITIAL LINE TO lt_field_description ASSIGNING <fs_field_description>.
<fs_field_description>-name = 'CARRID'.
<fs_field_description>-read_only = abap_true.
<fs_field_description>-read_only_ref = 'CARRID_READONLY'.
UNASSIGN <fs_field_description>.
APPEND INITIAL LINE TO lt_field_description ASSIGNING <fs_field_description>.
<fs_field_description>-name = 'CONNID'.
<fs_field_description>-read_only = abap_true.
<fs_field_description>-read_only_ref = 'CONNID_READONLY'.
UNASSIGN <fs_field_description>.
APPEND INITIAL LINE TO lt_field_description ASSIGNING <fs_field_description>.
<fs_field_description>-name = 'FLDATE'.
<fs_field_description>-read_only = abap_true.
<fs_field_description>-read_only_ref = 'FLDATE_READONLY'.
UNASSIGN <fs_field_description>.
APPEND INITIAL LINE TO lt_field_description ASSIGNING <fs_field_description>.
<fs_field_description>-name = 'PRICE'.
<fs_field_description>-read_only = abap_true.
<fs_field_description>-read_only_ref = 'PRICE_READONLY'.
UNASSIGN <fs_field_description>.
APPEND INITIAL LINE TO lt_field_description ASSIGNING <fs_field_description>.
<fs_field_description>-name = 'CARRID_READONLY'.
<fs_field_description>-technical_field = abap_true.
UNASSIGN <fs_field_description>.
APPEND INITIAL LINE TO lt_field_description ASSIGNING <fs_field_description>.
<fs_field_description>-name = 'CONNID_READONLY'.
<fs_field_description>-technical_field = abap_true.
UNASSIGN <fs_field_description>.
APPEND INITIAL LINE TO lt_field_description ASSIGNING <fs_field_description>.
<fs_field_description>-name = 'FLDATE_READONLY'.
<fs_field_description>-technical_field = abap_true.
UNASSIGN <fs_field_description>.
APPEND INITIAL LINE TO lt_field_description ASSIGNING <fs_field_description>.
<fs_field_description>-name = 'PRICE_READONLY'.
<fs_field_description>-technical_field = abap_true.
UNASSIGN <fs_field_description>.
**--Fill exporting parameter
eo_field_catalog = lo_field_catalog.
et_field_description = lt_field_description.
Put the below code into the GET_DATA method of list feeder.
***************************** Data Declaration **************************
DATA: lt_list TYPE ztt_sflight,
lt_param_list TYPE wdr_event_parameter_list,
lt_table TYPE wdui_table_paste_data,
lv_cur_col TYPE i,
lv_tol_row TYPE i,
lv_row TYPE i VALUE 1,
lv_col_name TYPE string,
lr_rtti TYPE REF TO cl_abap_typedescr,
lv_paste_index TYPE sytabix,
lv_paste_rows TYPE i,
lv_add_row TYPE i.
FIELD-SYMBOLS: <fs_list> LIKE LINE OF mt_list,
<fs_param_list> LIKE LINE OF lt_param_list,
<ft_table> TYPE wdui_table_paste_data,
<fs_table> TYPE wdui_table_line_paste_data,
<table_col> TYPE any,
<fs_field_usage> TYPE fpmgb_s_fieldusage.
**--Which event raise
CASE iv_eventid->mv_event_id.
WHEN cl_fpm_event=>gc_event_start.
DO iv_visible_rows TIMES.
APPEND INITIAL LINE TO lt_list.
ENDDO.
WHEN if_fpm_guibb_list=>gc_event_multi_value_paste.
**--Get event parameter
iv_eventid->mo_event_data->get_value( EXPORTING iv_key = 'WDEVENT_PARAMS'
IMPORTING ev_value = lt_param_list ).
READ TABLE lt_param_list ASSIGNING <fs_param_list> WITH KEY name = 'TABLE'.
IF sy-subrc EQ 0.
**--Adding extra row to the table (If user have copied rows more than the visible rows)
ASSIGN <fs_param_list>-value->* TO <ft_table>.
lt_list = mt_list.
lv_paste_index = lines( <ft_table> ).
READ TABLE <ft_table> ASSIGNING <fs_table> INDEX lv_paste_index.
IF sy-subrc EQ 0.
lv_paste_rows = <fs_table>-row.
ENDIF.
IF lv_paste_rows GT lines( lt_list ) AND cv_lead_index LE 1.
lv_add_row = lv_paste_rows - lines( lt_list ).
DO lv_add_row TIMES.
APPEND INITIAL LINE TO lt_list.
ENDDO.
ELSEIF cv_lead_index GT 1.
READ TABLE lt_list ASSIGNING <fs_list> INDEX cv_lead_index.
IF sy-subrc EQ 0 AND <fs_list> IS ASSIGNED AND NOT <fs_list> IS INITIAL.
cv_lead_index = cv_lead_index + 1.
DO lv_paste_rows TIMES.
APPEND INITIAL LINE TO lt_list.
ENDDO.
ELSE.
lv_tol_row = cv_lead_index + lv_paste_rows - 1.
lv_add_row = lv_tol_row - lines( lt_list ).
IF lv_tol_row GT lines( lt_list ).
DO lv_add_row TIMES.
APPEND INITIAL LINE TO lt_list.
ENDDO.
ENDIF.
ENDIF.
ENDIF.
LOOP AT lt_list ASSIGNING <fs_list> FROM cv_lead_index.
lv_cur_col = 1.
LOOP AT <ft_table> ASSIGNING <fs_table> WHERE row = lv_row.
READ TABLE ct_field_usage ASSIGNING <fs_field_usage> INDEX lv_cur_col.
ASSERT sy-subrc = 0.
lv_col_name = <fs_field_usage>-name.
ASSIGN COMPONENT lv_col_name OF STRUCTURE <fs_list> TO <table_col>.
lr_rtti = cl_abap_typedescr=>describe_by_data( <table_col> ).
CASE lr_rtti->type_kind.
WHEN cl_abap_typedescr=>TYPEKIND_PACKED.
REPLACE ALL OCCURRENCES OF '.' IN <fs_table>-data WITH ''.
REPLACE ALL OCCURRENCES OF ',' IN <fs_table>-data WITH '.'.
<table_col> = <fs_table>-data.
WHEN cl_abap_typedescr=>typekind_date.
CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL' " Convert date to internal
EXPORTING
date_external = <fs_table>-data
IMPORTING
date_internal = <fs_table>-data
EXCEPTIONS
date_external_is_invalid = 1
OTHERS = 2.
<table_col> = <fs_table>-data.
WHEN OTHERS.
<table_col> = <fs_table>-data.
ENDCASE.
ADD 1 TO lv_cur_col.
ENDLOOP.
ADD 1 TO lv_row.
ENDLOOP.
ENDIF.
ENDCASE.
**--Filling exporting parameter
ct_data = lt_list.
mt_list = lt_list.
ev_data_changed = abap_true.
Step 2. Create FPM Application.
Go to transaction SE80 and create Webdynpro Application as follows.
Change the component and View in the properties of WD Application. In this application we use are using OVP,
so that we use component name “FPM_OVP_COMPONENT” and interface view “FPM_WINDOW”. Then save the application.
Right click on application and choose create/change configuration to configure the application through FPM configuration editor.
It will open the browser window, Enter the application configuration name for your application and press enter,
It will give you a error because application configuration for the application doesn’t exist.
So click on Create New. A new pop up will open, enter the description and click on ok ,
application configuration is created.
Now you have to create component configuration for your application, click on Assign Configuration Name button for the above selected application configuration and enter the configuration id in popup and click on ok.
It will display a error message same like previously we got for application configuration. So click on Create New.
A new pop up will open, enter the description and click on ok.
Now you will be redirect to the Main Screen of the OVP application. In this page you have to define your Main page in the Navigation panel.After that choose the list component from the UIBB choose button with in the Overview Page Schema.
After that, enter the component configuration id for the list and configure the UIBB by clicking on the Configure UIBB button in the right side of the Overview Page Schema tab. Savethe component configuration.
Again one another popup will ask you to give the feeder class name for configuring the GUIBB’s List.Enter the feeder class name and click on edit parameter list and now you can configure your list with the defined field catalogue structure in feeder class.
Now configure the list column by clicking on column button in the List UIBB Schema.
A pop will open with all the available field, select all and click on ok.
Set the display type property of elements as input field in List GUIBB Schema tab and also set the initial rows count 10 in the General Settings Group of list GUIBB.
Step 3: Run Application
Go to transaction SE80 and enter your package name and choose your application configuration with in webdynpro.Click on execute button.
A browser window will open with result screen like as below snapshot. Initially List will be empty with 10 Visible Rows which we had configured in list component configuration.
Place the cursor in the first row and first column of the list and then copy the records from the excel sheet, it will copy the data into clipboard and then press Ctrl + V. All the copied data will be pasted in appropriate cell.
You can paste the clipboard data into the selected row for example (2nd Row, Last row, In between Rows).
In below snap shot you can see 1st row is remain blank and data is pasted on 2nd row.
If copied data is greater than the visible row then it will add that many rows which you copied from excel sheet.
For achiving this functionality coding has been done in GET_DATA method. You can change this logic as per your business requirement.