Ещё есть Ф.М. 'REUSE_DOUBLE_ALV'
вот пример использования:
Code:
REPORT ztest .
DATA:
gv_exit TYPE flag,
gt_fieldcat TYPE lvc_t_fcat,
gr_table TYPE REF TO data,
gv_tablename TYPE dd02l-tabname VALUE 'MARA'.
INITIALIZATION.
PERFORM data_upload.
CHECK gv_exit IS INITIAL.
PERFORM grid_display.
*&---------------------------------------------------------------------*
*& Form data_upload
*&---------------------------------------------------------------------*
FORM data_upload.
DATA:
lv_title_left TYPE sy-title,
lv_title_right TYPE sy-title,
lv_popup_title TYPE sy-title,
lv_col_pos TYPE lvc_s_fcat-col_pos,
lt_fieldcat_original TYPE lvc_t_fcat,
lt_fieldcat_to_popup TYPE lvc_t_fcat,
lt_included_fields TYPE STANDARD TABLE OF lvc_s_objs ,
lt_excluded_fields TYPE STANDARD TABLE OF lvc_s_objs .
FIELD-SYMBOLS:
<fieldcat> TYPE lvc_s_fcat,
<included_fields> TYPE lvc_s_objs.
* original fieldcatalog
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = gv_tablename
i_client_never_display = abap_on
i_bypassing_buffer = abap_on
CHANGING
ct_fieldcat = lt_fieldcat_original
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
gv_exit = abap_on.
EXIT.
ENDIF.
* prepare fieldcatalog with fields, will be able to select via popup
LOOP AT lt_fieldcat_original ASSIGNING <fieldcat>.
CHECK <fieldcat>-fieldname NE 'MANDT'. " -->> disable
ADD 1 TO lv_col_pos.
<fieldcat>-col_pos = lv_col_pos.
APPEND <fieldcat> TO lt_fieldcat_to_popup.
ENDLOOP.
LOOP AT lt_fieldcat_to_popup ASSIGNING <fieldcat> .
APPEND INITIAL LINE TO lt_included_fields ASSIGNING <included_fields>.
<included_fields>-id = <fieldcat>-col_pos.
<included_fields>-icon = icon_parameter_export.
<included_fields>-text = <fieldcat>-scrtext_m.
<included_fields>-sp_group = space.
ENDLOOP.
* popup to select fields that has to be uploaded
lv_title_left = text-i01. " -->> text: order of fields in Excel
lv_title_right = text-i02. " -->> text: exclude fields
lv_popup_title = text-i03. " -->> text: order of fields in a file to be uploaded
CALL FUNCTION 'REUSE_DOUBLE_ALV'
EXPORTING
i_title_left = lv_title_left
i_title_right = lv_title_right
i_popup_title = lv_popup_title
IMPORTING
e_cancelled = gv_exit
TABLES
t_leftx = lt_included_fields
t_rightx = lt_excluded_fields.
IF gv_exit IS NOT INITIAL
OR lt_included_fields[] IS INITIAL.
* MSG: action was canceled by the user
MESSAGE s000(lp) WITH text-m00.
EXIT.
ENDIF.
* target fieldcatalog (for upload data table)
LOOP AT lt_included_fields ASSIGNING <included_fields>.
READ TABLE lt_fieldcat_to_popup ASSIGNING <fieldcat>
WITH KEY col_pos = <included_fields>-id .
CHECK sy-subrc EQ 0.
APPEND <fieldcat> TO gt_fieldcat.
ENDLOOP.
* create a target table for data upload
* (it has a structure same Excel)
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = gt_fieldcat
IMPORTING
ep_table = gr_table
EXCEPTIONS
OTHERS = 4.
IF sy-subrc NE 0.
* MSG: Error while dynamic table create
MESSAGE s000(lp) WITH text-m01.
gv_exit = abap_on.
EXIT.
ENDIF.
* data upload process (including file select dialog)
FIELD-SYMBOLS <table> TYPE STANDARD TABLE.
ASSIGN gr_table->* TO <table> .
CALL FUNCTION 'FILE_READ_AND_GET_TAB'
TABLES
itab_receiver = <table>
EXCEPTIONS
upload_cancelled = 1
upload_error = 2
OTHERS = 3.
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE 'I' NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
gv_exit = abap_on.
EXIT.
ENDIF.
ENDFORM. "data_upload
*&---------------------------------------------------------------------*
*& Form data_display
*&---------------------------------------------------------------------*
FORM grid_display.
DATA:
ls_layout TYPE lvc_s_layo.
FIELD-SYMBOLS:
<table> TYPE STANDARD TABLE.
ls_layout-cwidth_opt = abap_on.
ls_layout-sel_mode = 'A'.
ASSIGN gr_table->* TO <table>.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_bypassing_buffer = abap_on
i_callback_program = sy-repid
i_save = 'A'
is_layout_lvc = ls_layout
it_fieldcat_lvc = gt_fieldcat
TABLES
t_outtab = <table>
EXCEPTIONS
OTHERS = 2.
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE 'I' NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
gv_exit = abap_on.
EXIT.
ENDIF.
ENDFORM. "grid_display