Friday, 17 April 2026

Custom Button in ALV Output - SAP ABAP

 

 1. Create a Local Event Handler Class

  • Define a class to handle ALV button actions
  • Use FOR EVENT added_function OF cl_salv_events
  CLASS lcl_handler DEFINITION .

    PUBLIC SECTION.
     METHODSon_user_command
                  FOR EVENT added_function OF cl_salv_events
      IMPORTING e_salv_function.

  ENDCLASS.

 2. Add Custom PF-STATUS to ALV

  • Create a GUI status in SE41 (e.g., ZALV_STATUS)
  • Add custom buttons (like POST, CANCEL)
  • Assign function codes (same names used in code)

      My usage:

  • go_alv->set_screen_status( pfstatus = 'ZALV_STATUS' )

 3. Bind Event Handler to ALV

  • Get ALV event object
  • Attach your handler method

      My implementation:

    DATA(lo_eventsgo_alv->get_event).
    DATA(lo_handlerNEW lcl_handler).
     SET HANDLER lo_handler->on_user_command FOR lo_events.

 4. Handle Custom Button Logic

  • Use CASE e_salv_function
  • Match function codes from PF-STATUS

      My logic:

  • 'POST' → call posting logic + refresh ALV
  • 'CANCEL' / 'EXIT' → leave program
 METHOD on_user_command.

    CASE e_salv_function.
      WHEN 'POST'.
        go_gm->post_gm).
        go_gm->display_posted_alv).
      WHEN 'CANCEL' OR 'EXIT'.
        LEAVE PROGRAM.
    ENDCASE.

  ENDMETHOD.










No comments:

Post a Comment