After you display editable ALV report by using REUSE_ALV_GRID_DISPLAY or REUSE_ALV_GRID_DISPLAY_LVC function. And you would like to get any changed data from the ALV such as selected checkbox or other input.
*You can see all source code at Appendix A.
You need to prepare PF-STATUS and USER_COMMAND like these.
Subroutine: PF_STATUS
Subroutine: USER_COMMAND
Block 1 – To get changed data from editable ALV report. [i.e. CHECK and PRDQTY fields.]
Block 2 – To set update data to display on ALV report. [i.e. TOTPRC field.]
Result
First execution. =>
Checked the second row and change Quantity to 3. =>
Press Calculate button. =>
Appendix A
REPORT zget_changed_data_fr_alv.
TYPES:
BEGIN OF gy_data,
check TYPE char01,
prdnam TYPE char40,
prdqty TYPE i,
untprc TYPE p DECIMALS 2,
totprc TYPE p DECIMALS 2,
END OF gy_data.
DATA:
gt_data TYPE TABLE OF gy_data,
gt_fcat TYPE lvc_t_fcat.
DATA:
gw_data TYPE gy_data,
gw_fcat TYPE lvc_s_fcat,
gw_layout TYPE lvc_s_layo.
“Set data
gw_data-prdnam = ‘Sofa’.
gw_data-prdqty = 5.
gw_data-untprc = 100.
APPEND gw_data TO gt_data.
CLEAR: gw_data.
gw_data-prdnam = ‘Table’.
gw_data-prdqty = 2.
gw_data-untprc = 300.
APPEND gw_data TO gt_data.
CLEAR: gw_data.
“Set field catalog
gw_fcat-fieldname = ‘CHECK’.
gw_fcat-checkbox = abap_true.
gw_fcat-edit = abap_true.
APPEND gw_fcat TO gt_fcat.
CLEAR: gw_fcat.
gw_fcat-fieldname = ‘PRDNAM’.
gw_fcat-coltext = ‘Product Name’.
APPEND gw_fcat TO gt_fcat.
CLEAR: gw_fcat.
gw_fcat-fieldname = ‘PRDQTY’.
gw_fcat-coltext = ‘Quantity’.
gw_fcat-edit = abap_true.
APPEND gw_fcat TO gt_fcat.
CLEAR: gw_fcat.
gw_fcat-fieldname = ‘UNTPRC’.
gw_fcat-coltext = ‘Unit Price’.
APPEND gw_fcat TO gt_fcat.
CLEAR: gw_fcat.
gw_fcat-fieldname = ‘TOTPRC’.
gw_fcat-coltext = ‘Total Price’.
APPEND gw_fcat TO gt_fcat.
CLEAR: gw_fcat.
“Set layout
gw_layout-cwidth_opt = abap_true.
gw_layout-no_rowmark = abap_true.
gw_layout-edit_mode = ‘B’.
gw_layout-box_fname = ‘CHECK’.
“Display ALV
CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY_LVC’
EXPORTING
i_callback_program = sy-repid
i_callback_pf_status_set = ‘PF_STATUS’
i_callback_user_command = ‘USER_COMMAND’
is_layout_lvc = gw_layout
it_fieldcat_lvc = gt_fcat
i_default = ‘X’
i_save = ‘A’
TABLES
t_outtab = gt_data
EXCEPTIONS
program_error = 1
OTHERS = 2.
*&———————————————————————*
*& Form pf_status
*&———————————————————————*
FORM pf_status USING rt_extab TYPE slis_t_extab.
SET PF-STATUS ‘ST001’.
ENDFORM.
*&———————————————————————*
*& Form user_command
*&———————————————————————*
FORM user_command USING pv_ucomm TYPE sy-ucomm
pw_selfield TYPE slis_selfield.
DATA:
lo_alv TYPE REF TO cl_gui_alv_grid.
CALL FUNCTION ‘GET_GLOBALS_FROM_SLVC_FULLSCR’
IMPORTING
e_grid = lo_alv.
CALL METHOD lo_alv->check_changed_data.
CASE pv_ucomm.
WHEN ‘CALC’. “Calculate
LOOP AT gt_data ASSIGNING FIELD-SYMBOL(<lfs_data>)
WHERE check IS NOT INITIAL.
<lfs_data>-totprc = <lfs_data>-prdqty * <lfs_data>-untprc.
ENDLOOP.
WHEN ‘BACK’ OR ‘EXIT’ OR ‘CANC’.
LEAVE TO SCREEN 0.
WHEN OTHERS.
ENDCASE.
pw_selfield-refresh = abap_true.
ENDFORM.
I have created an editable ALV. User can make some changes in the displayed record and press Submit button (custom button on application toolbar), the program should validate the data and write the file on application server if validations are successful otherwise controls stay on the same screen.
thanks, very interesting 🙂