Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

ALV Buttons

Former Member
0 Likes
2,100

How can you add your own button on the application toolbar in ALV? Tell each step.

How can you add your own button on the application toolbar in ALV? Tell each step.

6 REPLIES 6
Read only

Former Member
0 Likes
1,323

In the program which calls ALV using REUSE_ALV_LIST_DISPLAY,

I have to add a new button.

I saw the demo program BCALV_GRID_08, which is written using ABAP-Controls.

In that example, the button is added using TOOLBAR event of cl_gui_alv_grid.

Could you help me to implement the same logic using REUSE_ALV_LIST_DISPLAY parameters.

you should copy the 'STANDARD' GUI status from program SAPLKKBL using transaction SE90 >Programming SubObjects> Gui Status.

Execute this transaction to get to next screen. select status using checkbox. click on GUI Status --> Copy.

Enter your Z program name and the name you what for this status - you can keep it as 'STANDARD' to be simple.

Then you can edit the new status to add or delete buttons. This will also bring in the standard SAP ALV functionality such as sorting/subtotaling etc...

When you call 'REUSE_ALV_GRID_DISPLAY' make sure you pass it the new status name.

an example of one of mine:

call function 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = 'ZSDBOLST_REPORT'

i_callback_pf_status_set = 'STANDARD' <----


i_callback_user_command = 'USER_COMMAND'

i_structure_name = 'I_BOLACT'

i_grid_title = 'BOL Action Report'(031)

is_layout = gs_layout

it_fieldcat = gt_fieldcat[]

i_save = 'A'

is_variant = v_variant

TABLES

t_outtab = i_bolact

EXCEPTIONS

program_error = 1

others = 2.

I just tried the same procedure ,but my entire application toolbar disappeared and a lock icon appears next to the application toolbar in my copied pf-status.

Could you advice what might have gone wrong ?

As identified with the FM's help you can do the following.

1). Using SE80 (I think) you can copy a GUI status from one program to another. It mentions which one in the FM's help.

2). Create a form named like so:

Code:

Form Set_pf_status

Notes: Called by FM REUSE_ALV_GRID_DISPLAY

FORM set_pf_status USING rt_extab TYPE slis_t_extab.

SET PF-STATUS 'ZSTANDARD'.

ENDFORM. "Set_pf_status

In the above case the GUI status copied was named ZSTANDARD and adjusted accordingly, adding and removing the desired buttons. A button was added called '%DELETE'.

3). Create the following report:

Code:

Form User_command

Notes: Called by FM REUSE_ALV_GRID_DISPLAY

Detects whether the icon/button for

'Return Tag Deletion' has been pressed. If it has then

detect whether any rows have been highlighted and then

set the delete flag.

FORM user_command USING r_ucomm LIKE sy-ucomm

rs_selfield TYPE slis_selfield.

DATA: li_count TYPE I.

IF r_ucomm EQ '%DELETE'.

LOOP AT %g00 WHERE mark EQ 'X'.

ADD 1 TO li_count.

ENDLOOP.

IF li_count GT 0.

gc_delete_flag = 'X'.

r_ucomm = '&F03'. "Back arraow

ELSE.

MESSAGE W000 WITH 'Please highlight the rows to be deleted!'.

ENDIF.

ENDIF.

ENDFORM. "User_command

As I've added an extra button to indicate which records should be deleted I need to identify a form to be called to process when this button is chosen.

Then when you call the ALV function you to specify the following extra details:

Code:

call function 'REUSE_ALV_GRID_DISPLAY'

exporting i_callback_program = gc_repid

I_CALLBACK_PF_STATUS_SET = 'SET_PF_STATUS'

I_CALLBACK_USER_COMMAND = 'USER_COMMAND'

i_grid_title = lc_grid_title

is_layout = lc_layout

it_fieldcat = gt_fieldcat

it_sort = sort

i_save = l_save

is_reprep_id = l_bbs_id

is_variant = l_variant

tables t_outtab = %g00

exceptions program_error = 1

others = 2.

The parameters in capitals are the extra ones that need to be added.

Reward Points if useful

Read only

Former Member
0 Likes
1,323

Hi

1) Copy existing gui or creat your own (better to copy for standart buttons).

2) In se80 double open gui status and open your status.

3) Open application tool bar and enter a name for your button in free cell

4) Choose static text

5)Enter texts and choose an icon for your button.

6)Assign your button

7) Activate gui status.

😎 in your program check sy-subrc for code entered in (3) (upper case)

9) enter logic in program.

Regards

Yossi

Read only

Former Member
0 Likes
1,323

hi sulakshana,

here are the steps..

1) OPEN SE41

2) TYPE IN YOUR PROGRAM NAME FOR WHICH YOU NEED ALV MENU

3) on the application tolbar you would see a button named 'STATUS', click it

4) now it would say copy status FROM AND TO....

type:

FROM:

PROGRAM: SAPLSLVC_FULLSCREEN

STATUS: STANDARD_FULLSCREEN

TO

PROGRAM: TYPE YOuR PROGRAM NAME

STATUS : TYPE YOUR CUSTOM MENU NAME

5) PRESS COPY..and again till it says a message 'COPIED SUCCESSFULLY

6)in you ALV PROGRAM IN EVEN SET_PF_STATUS,

TYPE THIS ALV STATUS AND DOUBLE CLICK UR STATUS NAME

AND THEN YOU WILL HAVE YOUR ALV STANDARD MENU..AND

YOU CAN HAVE YOUR BUTTON ON IT, BY MAKING YOU OWN COMMAND SAY '&MAT' name it as MAterial info

6) ACTIVATE IT

AND YOUR ALV MENU IS MADE

reward points if helpful

Rohan malik

Read only

Former Member
0 Likes
1,323

Hi...

You can go thru this code,...

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = ws_repid

i_callback_pf_status_set = 'GUI_STAT'

i_callback_user_command = 'STAT'

is_layout = gs_layout

it_fieldcat = i_fieldcat[]

TABLES

t_outtab = i_zaw_pol_plan.

FORM gui_stat USING rt_extab TYPE slis_t_extab.

SET PF-STATUS 'STANDARD' EXCLUDING rt_extab.

SET TITLEBAR text-005.

ENDFORM.

Double click on 'STANDARD' and set the status.

Here you will loose the standard ALV toolbar.

If you want to get STANDARD ALV tool bar...you need to do this navigations.

SE80 ->give Function Group as SALV -> right click on GUI status -> copy STANDARD menu to your program ->go to SE41 -> Activate the menu -> now you will get the menu in your program -> if you want to add any buttons or want to do any changes in the menu, you can do using SE41-> save and activate.

Regards

sandeep.

Read only

0 Likes
1,323

Thanks Sandeep,

Your code help me. I get the Standard ALV buttons in my program.

But I want the Standard ALV buttons as well as my own Customized buttons simultaneouly which I cant get till now..

Can u pls help me.

Read only

Former Member
0 Likes
1,323

Oh dear me -- You guys make this stuff FAR TOO COMPLICATED.

FIRST FORGET the SLIS / FM method of ALV. It's OBSOLETE COMPLICATED and not easy to program.

Use CL_SALV_table* for simple non editable grids or cl_gui_alv_grid for more complicated stuff.

Here's a complete SIMPLE OO program which adds a user function to the toolbar and when you press it the routine calls your on_user_command function.

This grid is also editable.

I've made a simple application here rather than that stupid airline one - -of all the applications you can use SAP for Airline reservation isn't likely to be one of them.

The double click and hotspot functions are active so you can do stuff when you double click a cell such as display sales order etc etc.

Before you start create a standard screen 100 with just a custom control on it called CCONTAINER1 and a standard SE41 status 000 with just BACK, EXIT and CANCEL standard functions..

the screen logic just needs



process before output.
 module status_0100.
*
process after input.
 module user_command_0100.

Once you get used to ALV OO you don't even need a screen anymore as you can build this in anyway. For non editable grids you can also use the new salv table class but this has fairly limited functionality.

anyway here's the rest of the code. There's break-points in it as well to show the relevant processes.


PROGRAM zzz_simple_editable_grid.
include <icon>.
CLASS LCL_EVENT_HANDLER DEFINITION .
  PUBLIC SECTION .
    METHODS:
**Hot spot Handler
    HANDLE_HOTSPOT_CLICK FOR EVENT HOTSPOT_CLICK OF CL_GUI_ALV_GRID
                      IMPORTING E_ROW_ID E_COLUMN_ID ES_ROW_NO,
**Double Click Handler
    HANDLE_DOUBLE_CLICK FOR EVENT DOUBLE_CLICK OF CL_GUI_ALV_GRID
                                    IMPORTING E_ROW E_COLUMN ES_ROW_NO,
** Toolbar handler.
 handle_toolbar
        FOR EVENT toolbar OF cl_gui_alv_grid
            IMPORTING e_object e_interactive,
* button press
    handle_user_command
        FOR EVENT user_command OF cl_gui_alv_grid
            IMPORTING e_ucomm.

ENDCLASS.                    "lcl_event_handler DEFINITION
CLASS LCL_EVENT_HANDLER IMPLEMENTATION.
*Handle Hotspot Click
  METHOD HANDLE_HOTSPOT_CLICK .
    break-point 1.
  ENDMETHOD.                    "lcl_event_handler

*Handle Double Click
  METHOD  HANDLE_DOUBLE_CLICK.
break-point 2.
  ENDMETHOD.

  METHOD handle_toolbar.
  DATA: ls_toolbar  TYPE stb_button.
break-point 1.
* append a separator to normal toolbar
    CLEAR ls_toolbar.
    MOVE 3 TO ls_toolbar-butn_type.
    APPEND ls_toolbar TO e_object->mt_toolbar.
* append an icon for your function
    CLEAR ls_toolbar.
    MOVE 'FUNC' TO ls_toolbar-function.
    MOVE icon_railway TO ls_toolbar-icon.
    MOVE 'Your Function' TO ls_toolbar-quickinfo.
    MOVE 'Your user function' TO ls_toolbar-text.
    MOVE ' ' TO ls_toolbar-disabled.
    APPEND ls_toolbar TO e_object->mt_toolbar.

  ENDMETHOD.
  method handle_user_command.
  break-point 1.
  case e_ucomm.
  when 'FUNC'.    "Your button
* Perform what you need to do.
  when others.
  endcase.
  endmethod.

  endclass.

* Define any structure
TYPES:  BEGIN OF s_elements,
  vbeln   TYPE vapma-vbeln,
  posnr   TYPE vapma-posnr,
  matnr   TYPE vapma-matnr,
  kunnr   TYPE vapma-kunnr,
  werks   TYPE vapma-werks,
  vkorg   TYPE vapma-vkorg,
  vkbur   TYPE vapma-vkbur,
  status  TYPE c,

END OF  s_elements.

* end of your structure

DATA lr_rtti_struc TYPE REF TO cl_abap_structdescr .
DATA:
    zog                     LIKE LINE OF lr_rtti_struc->components .
DATA:
  zogt                    LIKE TABLE OF zog,
wa_it_fldcat TYPE lvc_s_fcat,
it_fldcat TYPE lvc_t_fcat ,
dy_line            TYPE REF TO data,
dy_table           TYPE REF TO data.


DATA:  dref               TYPE REF TO data.
FIELD-SYMBOLS: <fs> TYPE ANY,
   <dyn_table>    TYPE  STANDARD TABLE,
   <dyn_wa>.

DATA grid_container1 TYPE REF TO cl_gui_custom_container .
DATA: G_HANDLER TYPE REF TO LCL_EVENT_HANDLER. "handler

DATA grid1 TYPE REF TO cl_gui_alv_grid .
DATA: ok_code TYPE sy-ucomm.
DATA: struct_grid_lset TYPE lvc_s_layo.
start-of-selection.
*now I want to build a field catalog
* First get your data structure into a field symbol

CREATE DATA dref TYPE s_elements.
ASSIGN dref->* TO <fs>.

lr_rtti_struc ?= cl_abap_structdescr=>describe_by_data( <fs> ).

* Now get the structure details into a table.
* table zogt[] contains the structure details
* From which we can build the field catalog

zogt[]  = lr_rtti_struc->components.
LOOP AT zogt INTO zog.
  CLEAR wa_it_fldcat.
  wa_it_fldcat-fieldname = zog-name .
  wa_it_fldcat-datatype = zog-type_kind.
  wa_it_fldcat-inttype = zog-type_kind.
  wa_it_fldcat-intlen = zog-length.
  wa_it_fldcat-decimals = zog-decimals.
  wa_it_fldcat-coltext = zog-name.
  wa_it_fldcat-lowercase = 'X'.
  if wa_it_fldcat-fieldname = 'VBELN'.
  wa_it_fldcat-hotspot = 'X'.
  ENDIF.
  APPEND wa_it_fldcat TO it_fldcat.

ENDLOOP.
*
* You can perform any modifications / additions to your field catalog
* here such as your own column names etc.

* Now using the field catalog created above we can
* build a dynamic table
* and populate it

* First build the dynamic table
* the table will contain entries for
* our structure defined at the start of the program

CALL METHOD cl_alv_table_create=>create_dynamic_table
       EXPORTING
            it_fieldcatalog = it_fldcat
       IMPORTING
            ep_table = dy_table.


ASSIGN dy_table->* TO <dyn_table>.
CREATE DATA dy_line LIKE LINE OF <dyn_table>.
ASSIGN dy_line->* TO <dyn_wa>.

* Now fill our table with data

SELECT vbeln posnr matnr kunnr werks vkorg vkbur
       UP TO 200 ROWS
       FROM vapma
       INTO  CORRESPONDING FIELDS OF TABLE <dyn_table>.

* Call the screen to display the grid
CALL SCREEN 100.

* PBO module

MODULE status_0100 OUTPUT.
data: off type int4.
break-point 1.
if sy-batch = 'X'.
 CALL METHOD cl_gui_alv_grid=>offline
RECEIVING
e_offline = off.
endif.

if sy-batch = 'X'.
 IF ( off IS INITIAL ).
    CREATE OBJECT grid_container1
            EXPORTING
               container_name = 'CCONTAINER1'.
    CREATE OBJECT  grid1
       EXPORTING
          i_parent = grid_container1.
ENDIF.
endif.
if sy-batch ne 'X'.

   IF grid_container1 IS INITIAL.
     CREATE OBJECT grid_container1
             EXPORTING
                container_name = 'CCONTAINER1'.
  endif.
    CREATE OBJECT  grid1
       EXPORTING
          i_parent = grid_container1.
   if sy-batch ne 'X'.
    struct_grid_lset-edit = 'X'.    "To enable editing in ALV
  endif.
  endif.

  CREATE OBJECT G_HANDLER.
  SET HANDLER G_HANDLER->HANDLE_DOUBLE_CLICK FOR Grid1.
  SET HANDLER G_HANDLER->HANDLE_HOTSPOT_CLICK FOR Grid1.
  set handler g_handler->handle_toolbar for grid1.
  set handler g_handler->handle_user_command for grid1.
   call method grid1->register_edit_event
        exporting
           i_event_id = cl_gui_alv_grid=>mc_evt_enter.


    CALL METHOD grid1->set_table_for_first_display
      EXPORTING is_layout =  struct_grid_lset
      CHANGING
                 it_outtab       = <dyn_table>
                 it_fieldcatalog = it_fldcat.



  SET PF-STATUS '001'.
  SET TITLEBAR '000'.

ENDMODULE.

* PAI module

MODULE user_command_0100 INPUT.
  CASE sy-ucomm.
    WHEN 'BACK'.
      LEAVE PROGRAM.
    WHEN 'EXIT'.
      LEAVE PROGRAM.
    WHEN 'RETURN'.
      LEAVE PROGRAM.
    WHEN OTHERS.
  ENDCASE.
ENDMODULE.

cheers

and please no more old SLIS stuff.

jimbo