Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

delete option in alv grid

Hi all

my requirement in this program is that when i select multiple checkboxes in the output and press delete butoon in the toolbar then it shuld delete the records from ouput as well as delete records from the database table.

so when i can run the ouput again then the deleted records shuld not come in the output again.

below i am giving my code, if anyone can help me in getting my problem solved.

<code>

&----


*& Report Z_50804_TRANS_SUBMIT

*&

&----


*&

*&

&----


REPORT Z_demo.

TABLES : ZDATA_12.

DATA :OK_CODE LIKE SY-UCOMM,

save_ok like sy-ucomm,

G_CONTAINER TYPE SCRFNAME VALUE 'GRID_CON',

IT_GRID1 TYPE REF TO CL_GUI_ALV_GRID,

IT_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,

it_fieldcat type lvc_t_fcat,

wa_fieldcat like line of it_fieldcat,

gs_layout type lvc_s_layo.

  • delete_button type ref to cl_gui_toolbar.

types : begin of ty_EMPO ,

checkbox type c,

EMP type zdata_12-EMP,

SUBJECT type zdata_12-SUBJECT,

DATE1 type zdata_12-DATE1,

  • include structure zdata_12.

end of ty_empo.

data : it_empo type standard table of ty_empo,

wa_empo type ty_empo.

          • Handling delete button in the toolbar.

DATA: ds_disposal_toolbar TYPE stb_button,

dt_disposal_toolbar TYPE ttb_button.

select-options : s_emp for zdata_12-emp.

class vend_details definition.

public section.

methods : get_data,

handle_hotspot_click for event hotspot_click of cl_gui_alv_grid importing e_row_id,

display_data,

handle_toolbar for event toolbar of cl_gui_alv_grid importing e_object e_interactive,

handle_user_command for event user_command of cl_gui_alv_grid importing e_ucomm.

endclass.

  • IMPLEMENTATION OF THE CLASS vend_details

class vend_details implementation.

method get_data.

SELECT EMP

SUBJECT

DATE1

FROM zdata_12

INTO CORRESPONDING FIELDS OF TABLE IT_EMPO

where emp in s_emp.

endmethod.

method handle_hotspot_click.

if not e_row_id is initial.

read table it_empo into wa_empo index e_row_id-index.

if sy-subrc = 0.

set parameter id 'PER' field wa_empo.

call transaction 'Z_CHANGE_COMENT' and skip first screen.

endif.

endif.

endmethod.

method display_data.

if not IT_EMPO is initial.

perform build_fldcat.

call screen 300.

endif.

endmethod.

method handle_toolbar.

  • wa_button type stb_button.

*

  • IF NOT DT_TOOLBAR[] IS INITIAL.

  • MOVE DT_TOOLBAR TO E_OBJECT->MT_TOOLBAR.

  • ENDIF.

*

**-ADD SPACE BETWEEN BUTTONS

  • clear wa_button.

  • move '&&SEP00' to wa_button-function.

  • move 3 to wa_button-butn_type.

  • append wa_button to e_object->mt_toolbar.

  • CLEAR DT_TOOLBAR.

  • MOVE E_OBJECT->MT_TOOLBAR TO DT_TOOLBAR.

  • clear wa_button.

*

**-add Delete Button on the toolbar

  • move 'DELE' to wa_button-function.

  • move icon_delete to wa_button-icon.

  • move 3 to wa_button-butn_type.

  • move ' ' to wa_button-disabled.

  • move 'DELETE'(001) to WA_BUTTON-TEXT.

  • append wa_button to e_object->mt_toolbar.

  • MOVE E_OBJECT->MT_TOOLBAR TO DT_TOOLBAR.

DATA: ds_toolbar TYPE stb_button.

IF NOT dt_disposal_toolbar[] IS INITIAL.

CLEAR: e_object->mt_toolbar[].

MOVE dt_disposal_toolbar TO e_object->mt_toolbar.

ENDIF.

READ TABLE e_object->mt_toolbar INTO ds_toolbar

WITH KEY function = 'DELETE'.

IF sy-subrc <> 0.

  • Add separator

CLEAR ds_toolbar.

MOVE '&&SEP00' TO ds_toolbar-function.

move '3' to ds_toolbar-butn_type.

APPEND ds_toolbar TO e_object->mt_toolbar.

CLEAR: dt_disposal_toolbar[].

MOVE e_object->mt_toolbar TO dt_disposal_toolbar.

*Add DELETE button

CLEAR ds_toolbar.

MOVE 'DELETE' TO ds_toolbar-function.

MOVE 'Delete' TO ds_toolbar-text.

MOVE 'Delete' TO ds_toolbar-quickinfo.

MOVE ' ' TO ds_toolbar-disabled.

MOVE icon_delete TO ds_toolbar-icon.

APPEND ds_toolbar TO e_object->mt_toolbar.

ENDIF.

CLEAR: dt_disposal_toolbar[].

MOVE e_object->mt_toolbar TO dt_disposal_toolbar.

endmethod.

method handle_user_command.

case e_ucomm.

when 'DELETE'.

PERFORM DELETE_FROM_TABLE.

endcase.

endmethod.

endclass.

start-of-selection.

data : obj_empo type ref to vend_details.

create object obj_empo.

call method obj_empo->get_data.

call method obj_empo->display_data.

  • call screen 300.

&----


*& Module STATUS_0300 OUTPUT

&----


  • text

----


module STATUS_0300 output.

SET PF-STATUS 'EMP'.

  • SET TITLEBAR 'xxx'.

IF IT_CONTAINER IS INITIAL.

create object it_container

exporting

  • PARENT =

container_name = G_CONTAINER

  • STYLE =

  • LIFETIME = lifetime_default

  • REPID =

  • DYNNR =

  • NO_AUTODEF_PROGID_DYNNR =

  • EXCEPTIONS

  • CNTL_ERROR = 1

  • CNTL_SYSTEM_ERROR = 2

  • CREATE_ERROR = 3

  • LIFETIME_ERROR = 4

  • LIFETIME_DYNPRO_DYNPRO_LINK = 5

  • others = 6

.

if sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

endif.

create object it_grid1

exporting

  • I_SHELLSTYLE = 0

  • I_LIFETIME =

i_parent = IT_CONTAINER

  • I_APPL_EVENTS = space

  • I_PARENTDBG =

  • I_APPLOGPARENT =

  • I_GRAPHICSPARENT =

  • I_NAME =

  • I_FCAT_COMPLETE = SPACE

  • EXCEPTIONS

  • ERROR_CNTL_CREATE = 1

  • ERROR_CNTL_INIT = 2

  • ERROR_CNTL_LINK = 3

  • ERROR_DP_CREATE = 4

  • others = 5

.

if sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

endif.

set handler obj_empo->handle_hotspot_click for it_grid1.

set handler obj_empo->handle_toolbar for it_grid1.

call method it_grid1->set_table_for_first_display

  • EXPORTING

  • I_BUFFER_ACTIVE =

  • I_BYPASSING_BUFFER =

  • I_CONSISTENCY_CHECK =

  • I_STRUCTURE_NAME = 'ZDATA_12'

  • IS_VARIANT =

  • I_SAVE =

  • I_DEFAULT = 'X'

  • IS_LAYOUT = gs_layout

  • IS_PRINT =

  • IT_SPECIAL_GROUPS =

  • IT_TOOLBAR_EXCLUDING =

  • IT_HYPERLINK =

  • IT_ALV_GRAPHICS =

  • IT_EXCEPT_QINFO =

  • IR_SALV_ADAPTER =

changing

it_outtab = IT_EMPO

IT_FIELDCATALOG = it_fieldcat

  • IT_SORT =

  • IT_FILTER =

EXCEPTIONS

INVALID_PARAMETER_COMBINATION = 1

PROGRAM_ERROR = 2

TOO_MANY_LINES = 3

others = 4

.

if sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

endif.

ENDIF.

*call method it_grid1->set_toolbar_interactive.

*

*call method cl_gui_control=>set_focus

  • exporting

  • control = it_grid1

    • EXCEPTIONS

    • CNTL_ERROR = 1

    • CNTL_SYSTEM_ERROR = 2

    • others = 3

  • .

*if sy-subrc <> 0.

    • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

    • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

*endif.

endmodule. " STATUS_0300 OUTPUT

&----


*& Module USER_COMMAND_0300 INPUT

&----


  • text

----


module USER_COMMAND_0300 input.

save_ok = sy-ucomm.

case save_ok.

when 'EXIT'.

perform exit_program.

when 'BACK' or 'CANCEL'.

leave to screen 0.

endcase.

clear ok_code.

endmodule. " USER_COMMAND_0300 INPUT

&----


*& Form exit_program

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form exit_program .

leave program.

endform. " exit_program

&----


*& Form build_fldcat

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form build_fldcat .

clear wa_fieldcat.

wa_fieldcat-col_pos = 1.

wa_fieldcat-fieldname = 'CHECKBOX'.

wa_fieldcat-checkbox = 'X'.

wa_fieldcat-EDIT = 'X'.

wa_fieldcat-tabNAME = 'IT_EMPO'.

append wa_fieldcat to It_fieldcat.

clear wa_fieldcat.

wa_fieldcat-col_pos = 2.

wa_fieldcat-fieldname = 'EMP'.

wa_fieldcat-tabNAME = 'IT_EMPO'.

wa_fieldcat-coltext = 'EMP'.

wa_fieldcat-seltext = 'EMP'.

wa_fieldcat-hotspot = 'X'.

wa_fieldcat-outputlen = 8.

append wa_fieldcat to It_fieldcat.

clear wa_fieldcat.

wa_fieldcat-col_pos = 3.

wa_fieldcat-fieldname = 'SUBJECT'.

wa_fieldcat-tabNAME = 'IT_EMPO'.

wa_fieldcat-coltext = 'SUBJECT'.

wa_fieldcat-seltext = 'SUBJECT'.

wa_fieldcat-hotspot = 'X'.

wa_fieldcat-outputlen = 20.

append wa_fieldcat to It_fieldcat.

clear wa_fieldcat.

wa_fieldcat-col_pos = 4.

wa_fieldcat-fieldname = 'DATE1'.

wa_fieldcat-tabNAME = 'IT_EMPO'.

wa_fieldcat-coltext = 'DATE'.

wa_fieldcat-seltext = 'DATE'.

wa_fieldcat-outputlen = 12.

append wa_fieldcat to It_fieldcat.

endform. " build_fldcat

&----


*& Form DELETE_FROM_TABLE

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form DELETE_FROM_TABLE .

if wa_empo-checkbox is not initial.

delete zdata_12 from wa_empo .

endif.

endform. " DELETE_FROM_TABLE

</code>

Thanks,

satya

Tags:
Former Member
Not what you were looking for? View more on this topic or Ask a question