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.










Wednesday, 1 April 2026

Upload Logo on Dialog ( Module Pool ) Programming - SAP ABAP

Upload Logo on Module Pool Programming: 

Data declarations: 

DATA: lv_xstr    TYPE xstring,
      lv_len     TYPE i,
      lv_off     TYPE i.

DATA: go_cont    TYPE REF TO cl_gui_custom_container,
      go_logo    TYPE REF TO cl_gui_picture.

DATA: gv_url     TYPE LENGTH 255,
      gv_result  TYPE i.

DATAgt_graphic TYPE STANDARD TABLE OF x255,
      gv_size    TYPE i.

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

Step 1: Upload your BMAP photo in the SE78.
Step 2: Make a custom container on the modulepool screen and name it as 'CC_LOGO'
Step 3: Write this bottom code in PBO module on the screen which you like to display logo.

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

Program Code:

  IF go_cont IS INITIAL.
    CREATE OBJECT go_cont
      EXPORTING
        container_name 'CC_LOGO'.    "Name of Custom Container
  ENDIF.

  IF go_logo IS INITIAL.
    CREATE OBJECT go_logo
      EXPORTING
        parent go_cont.

    CALL METHOD go_logo->set_display_mode
      EXPORTING
        display_mode cl_gui_picture=>display_mode_fit_center.
  ENDIF.

  IF gv_url IS INITIAL.

    CALL METHOD cl_ssf_xsf_utilities=>get_bds_graphic_as_bmp
      EXPORTING
        p_object 'GRAPHICS'
        p_name   'ZAK_INFO'  "Name of the logo
        p_id     'BMAP'
        p_btype  'BCOL'
      RECEIVING
        p_bmp    lv_xstr
      EXCEPTIONS
        OTHERS   1.

    IF lv_xstr <> 0.
      MESSAGE 'Image not found in SE78' TYPE 'I'.
      RETURN.
    ENDIF.

    gv_size xstrlenlv_xstr ).
    lv_len  gv_size.
    lv_off  0.
    CLEAR gt_graphic.

    WHILE lv_len > 255.
      APPEND lv_xstr+lv_off(255TO gt_graphic.
      lv_off lv_off + 255.
      lv_len lv_len 255.
    ENDWHILE.

    IF lv_len > 0.
      APPEND lv_xstr+lv_off(lv_lenTO gt_graphic.
    ENDIF.

    CALL FUNCTION 'DP_CREATE_URL'
      EXPORTING
        type     'IMAGE'
        subtype  'BMP'
        size     gv_size
        lifetime 'T'
      TABLES
        data     gt_graphic
      CHANGING
        url      gv_url.

    CALL METHOD go_logo->load_picture_from_url
      EXPORTING
        url    gv_url
      IMPORTING
        result gv_result.

  ENDIF.

  cl_gui_cfw=>flush).



Monday, 2 March 2026

ALV Report with Custom Layout Selection - SAP ABAP

 *&---------------------------------------------------------------------*

*& Report ZAK_LAYOUT_SAVE
*&---------------------------------------------------------------------*
*& This code will show you how to use Enable Save Layout Functionality with Custom Layout in SALV ALV
*&---------------------------------------------------------------------*
report zak_layout_save.

include zak_layout_save_top.
include zak_layout_save_lcl.
include zak_layout_save_f01.

at selection-screen on value-request for p_layout.
  perform f4_layout.

start-of-selection.

  datago_report type ref to lcl_report.
  create object go_report.

  go_report->get_data).
  go_report->display_alv).


*&---------------------------------------------------------------------*
*&  Include           ZAK_LAYOUT_SAVE_TOP
*&---------------------------------------------------------------------*

tablesekkoekpo.

"""""""""Selection Screen""""""""""""""
select-optionss_ebeln for ekko-ebeln.
parametersp_layout type slis_vari.
"""""""""""""""""""""""""""""""""""""""

typesbegin of ty_final,
         ebeln type ebeln,
         bsart type esart,
         bedat type ebdat,
         matnr type matnr,
         menge type bstmg,
         meins type bstme,
         netpr type bprei,
       end of ty_final.

datagt_final type standard table of ty_final.

datago_alv  type ref to cl_salv_table,
      go_cols type ref to cl_salv_columns,
      go_col  type ref to cl_salv_column,
      go_lay  type ref to cl_salv_layout,
      ls_key  type salv_s_layout_key,
      gt_lay  type salv_t_layout_info,
      gs_lay  type salv_s_layout_info.

*&---------------------------------------------------------------------*
*&  Include           ZAK_LAYOUT_SAVE_LCL
*&---------------------------------------------------------------------*

class lcl_report definition.
  public section.
    methodsget_data,
      display_alv.
endclass.

class lcl_report implementation.

  method get_data.

    select a~ebeln,
           a~bsart,
           a~bedat,
           b~matnr,
           b~menge,
           b~meins,
           b~netpr from ekko as a inner join ekpo as on a~ebeln b~ebeln into table @gt_final
      where a~ebeln in @s_ebeln.

  endmethod.

  method display_alv.

    try.
        cl_salv_table=>factory(
          importing
            r_salv_table   go_alv    " Basis Class Simple ALV Tables
          changing
            t_table        gt_final
        ).
      catch cx_salv_msg into data(lx_msg).
        message lx_msg->get_texttype 'E'.
    endtry.

    go_cols go_alv->get_columns).
    go_cols->set_optimize'X' ).
    go_alv->get_functions)->set_all'X' ).

    go_lay go_alv->get_layout).

    ls_key-report sy-repid.
    go_lay->set_keyvalue ls_key ).

    go_lay->set_save_restriction(
        value if_salv_c_layout=>restrict_none
    ).

    if p_layout is not initial.
      go_lay->set_initial_layoutvalue p_layout ).
    endif.

    go_alv->display).

  endmethod.

endclass.

*&---------------------------------------------------------------------*
*&  Include           ZAK_LAYOUT_SAVE_F01
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  F4_LAYOUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form f4_layout .

  ls_key-report sy-repid.

  try.
      cl_salv_layout_service=>get_layouts(
        exporting
          s_key         ls_key    " Layout Key
        receiving
          t_layout      =  gt_lay   " Layout
      ).

      call function 'F4IF_INT_TABLE_VALUE_REQUEST'
        exporting
          retfield    'LAYOUT'
          dynpprog    sy-repid
          dynpnr      sy-dynnr
          dynprofield 'P_LAYOUT'
          value_org   'S'
        tables
          value_tab   gt_lay.
    catch cx_salv_msg into data(lx_msg2).
      message lx_msg2->get_texttype 'E'.
  endtry.

endform.