SAP ABAP - ALV Activate Checkbox With Condition Value
*&---------------------------------------------------------------------*
*& Report YALV_CKBOX*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT yalv_ckbox.
TYPES:
BEGIN OF ty_data,
rbukrs TYPE acdoca-rbukrs,
belnr TYPE acdoca-belnr,
gjahr TYPE acdoca-gjahr,
matnr TYPE acdoca-matnr,
sgtxt TYPE acdoca-sgtxt,
zckbx TYPE char1,
celltab TYPE lvc_t_styl,
END OF ty_data.
DATA:
ob_container TYPE REF TO cl_gui_custom_container,
ob_grid TYPE REF TO cl_gui_alv_grid.
DATA:
it_fieldcat TYPE lvc_t_fcat,
wa_fieldcat LIKE LINE OF it_fieldcat,
is_lyout TYPE lvc_s_layo.
DATA:
lt_data TYPE TABLE OF ty_data,
ls_celltab TYPE lvc_s_styl.
DATA :
w_valid TYPE char01,
l_valid TYPE c,
lt_row_no TYPE lvc_t_roid,
ls_row_no TYPE lvc_s_roid.
START-OF-SELECTION.
REFRESH lt_data.
SELECT rbukrs belnr gjahr matnr sgtxt FROM acdoca
INTO CORRESPONDING FIELDS OF TABLE lt_data
UP TO 10 ROWS WHERE matnr <> '' AND rbukrs = 'IT'.
sort lt_data by rbukrs belnr gjahr.
LOOP AT lt_data ASSIGNING FIELD-SYMBOL(<fs_data>).
IF <fs_data>-matnr = 'FGA009553'.
REFRESH <fs_data>-celltab.
CLEAR ls_celltab.
ls_celltab-fieldname = 'ZCKBX'.
ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled.
INSERT ls_celltab INTO TABLE <fs_data>-celltab.
<fs_data>-zckbx = '-'.
ENDIF.
ENDLOOP.
CALL SCREEN 100.
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
SET PF-STATUS 'PF100'.
SET TITLEBAR 'TL100' WITH 'Test Alv CkBox'.
PERFORM initial_screen.
ENDMODULE.
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
CASE sy-ucomm.
WHEN 'BACK' OR 'EXIT' OR 'CNCL'.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE.
FORM initial_screen.
IF ob_container IS INITIAL.
CREATE OBJECT ob_container
EXPORTING
container_name = 'CONTAINER'.
CREATE OBJECT ob_grid
EXPORTING
i_parent = ob_container.
* CREATE OBJECT g_event_handler.
ENDIF.
PERFORM set_fieldcat.
PERFORM set_lyout.
PERFORM alv_displ_out.
CALL METHOD ob_grid->check_changed_data
IMPORTING
e_valid = w_valid.
CALL METHOD ob_grid->register_edit_event
EXPORTING
i_event_id = cl_gui_alv_grid=>mc_evt_enter.
CALL METHOD ob_grid->refresh_table_display.
CALL METHOD ob_grid->set_ready_for_input
EXPORTING
i_ready_for_input = 1.
ENDFORM.
FORM set_fieldcat.
REFRESH it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'RBUKRS'.
wa_fieldcat-col_pos = 1.
wa_fieldcat-ref_table = 'ACDOCA'.
wa_fieldcat-key = 'X'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'BELNR'.
wa_fieldcat-col_pos = 2.
wa_fieldcat-ref_table = 'ACDOCA'.
wa_fieldcat-key = 'X'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'GJAHR'.
wa_fieldcat-col_pos = 3.
wa_fieldcat-key = 'X'.
wa_fieldcat-ref_table = 'ACDOCA'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'MATNR'.
wa_fieldcat-col_pos = 4.
wa_fieldcat-ref_table = 'ACDOCA'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'SGTXT'.
wa_fieldcat-col_pos = 9.
wa_fieldcat-ref_table = 'ACDOCA'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'ZCKBX'.
wa_fieldcat-scrtext_l = 'Select'.
wa_fieldcat-col_pos = 10.
wa_fieldcat-edit_mask = 'X'.
wa_fieldcat-edit = 'X'.
wa_fieldcat-checkbox = 'X'.
APPEND wa_fieldcat TO it_fieldcat.
ENDFORM.
FORM set_lyout .
CLEAR is_lyout.
is_lyout-zebra = 'X'.
is_lyout-cwidth_opt = 'X'.
is_lyout-stylefname = 'CELLTAB'.
ENDFORM.
FORM alv_displ_out.
CALL METHOD ob_grid->set_table_for_first_display
EXPORTING
* is_variant = is_varnt "DISVARIANT
i_save = 'A' "CHAR1 - X:Global - U:User - A:All - Space:No
i_default = 'X' "CHAR1 - X:Allowed - Space:not
is_layout = is_lyout "LVC_S_LAYO
* is_print = is_print "LVC_S_PRNT
* it_toolbar_excluding = it_excld "UI_FUNCTIONS
CHANGING
it_outtab = lt_data
it_fieldcatalog = it_fieldcat "LVC_T_FCAT
* it_sort = it_sort "LVC_T_SORT
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4.
ENDFORM.
Comments
Post a Comment