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

Adding a button on the ALV grid using OOPs

vinotha_m
Participant
0 Likes
7,663

Hi,

I have created a ALV grid using CL_GUI_ALV_GRID....i neeed to add a button on each...row..of the grid....i.e. a field in the table has to be displayed as a button..

How can this be done and a event also...has to be associated along with this.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
4,621

Hi Vinotha,

You can do that.

Do the style setting as to make it pushbutton.

<b>In the class CL_GUI_ALV_GRID, there are constants starting by the name MC_STYLE..... Just assign the STYLE attribute of Fieldcatalog to the style corresponding to the push button</b> .

That is it...problem solved.

Here is an example....

form PREPARE_CATALOG changing p_field_catalog type lvc_t_fcat.

DATA ls_fcat type lvc_s_fcat .

CLEAR LS_FCAT.

ls_fcat-fieldname = 'CARRID'.

ls_fcat-ref_table = 'SFLIGHT' .

<b>ls_fcat-style = cl_gui_alv_grid=>mc_style_button.</b>

ls_fcat-outputlen = '20' .

ls_fcat-coltext = 'Carrid' .

APPEND ls_fcat to p_field_catalog .

endform.

Regards,

SP.

Message was edited by: Sylendra Prasad

15 REPLIES 15
Read only

Former Member
0 Likes
4,621

Hi,

take a look at this prog.

BCALV_GRID_05

rgds,

latheesh

Message was edited by: Latheesh Kaduthara

Read only

Former Member
0 Likes
4,621

Hi,

You can achieve this functionality through LAYOUT by passing 'X' to the layout-sel_mode.Then the Grid looks like a table control.

Cheers,

Bujji

Read only

0 Likes
4,621

I want to add a button along with other fields in a row...<b>not a way to select the row</b>..<b>and not on the toolbar</b> but many buttons on a single row..with added functionality

Read only

0 Likes
4,621

Hi,

Check this image. the sample output.

http://img91.imageshack.us/img91/2963/button9fv.jpg

Regards

vijay

Read only

0 Likes
4,621

Hi Vinotha,

If the requirement is similar to the picture uploaded by Vijay, you can go through my previous post or Vijay's post. It is very simple.

Regards,

SP.

Read only

0 Likes
4,621

Thanks a lot...it worked...can u also..tell me how to disable the button...based on user entry.

Read only

0 Likes
4,621

Hi Vinotha,

You can disable the buttons in the standard toolbar in ALV using the method <b>hide_functions.</b>In that method, there is a parameter which should contain all the codes of the buttons you want to disable.

For more details, refer this document.

http://esnips.com/doc/2d953590-e8c5-490c-a607-d1ab7cf517d7/ALV.pdf

Regards,

SP.

Read only

0 Likes
4,621

No, I dont want to disable the standard buttons....i want to disable the buttons that i created on each row..using the style field of the fieldcatalg..

i.e a column entirely displayed as buttons.

Read only

0 Likes
4,621

Hi Vinotha,

You can disable the button style by setting the style as MC_STYLE_DISABLED.

for eg:

my_cat-style = CL_GUI_ALV_GRID=>MC_STYLE_DISABLED.

Regards,

SP.

Read only

Former Member
0 Likes
4,622

Hi Vinotha,

You can do that.

Do the style setting as to make it pushbutton.

<b>In the class CL_GUI_ALV_GRID, there are constants starting by the name MC_STYLE..... Just assign the STYLE attribute of Fieldcatalog to the style corresponding to the push button</b> .

That is it...problem solved.

Here is an example....

form PREPARE_CATALOG changing p_field_catalog type lvc_t_fcat.

DATA ls_fcat type lvc_s_fcat .

CLEAR LS_FCAT.

ls_fcat-fieldname = 'CARRID'.

ls_fcat-ref_table = 'SFLIGHT' .

<b>ls_fcat-style = cl_gui_alv_grid=>mc_style_button.</b>

ls_fcat-outputlen = '20' .

ls_fcat-coltext = 'Carrid' .

APPEND ls_fcat to p_field_catalog .

endform.

Regards,

SP.

Message was edited by: Sylendra Prasad

Read only

Former Member
0 Likes
4,621

hi,

<b>Pushbuttons on the List To make a cell to be displayed as a pushbutton</b>

we have two steps.

Firstly, insert a new inner table of type “LVC_T_STYL” into your list data table.

Fill this inner table for each field to be displayed as pushbutton.

Button click event is handled like hotspot click via the event “button_click” through its parameters “es_col_id” and “es_row_no” which contain the address of the clicked pushbutton cell.

This detail Is provided in

An Easy Reference for ALV Grid Control PDF page 32.

if u dont have the PDF .

Please give me ur Email address i will send u.

<b>

Please Mark Helpful Answers</b>

Read only

Former Member
0 Likes
4,621

You cannot declare it as a button, but as an ICON or CheckBox only.

Add a single character field in your table. And when you are inserting the field in your field cat, check the field

ICON or

SYMBOL or

CHECKBOX or

Or you can declare the lay out as lvc_s_layo-sel_mode = 'A'

The event you could use to capture the actions is lcl_event_receiver

See sample from SAP, search BCALV* in SE38

Read only

Former Member
0 Likes
4,621

Hi,

it is very well possible.Just check this Program.

and for responding you need the event BUTTON_CLICK

have a local class method, and implement that, and then set the handler for it to respond.

   <b> button_click         for event button_click
                         of cl_gui_alv_grid
                         importing es_col_id
                                   es_row_no</b>

i just used LVC fm, it is almost like using <b>CL_GUI_ALV_GRID</b> from this report take the bold alone, thats all.

REPORT ZTESTALV.

TYPE-POOLS: SLIS.

*- Fieldcatalog
DATA: IT_FIELDCAT  TYPE LVC_T_FCAT,
      IT_FIELDCAT1  TYPE SLIS_T_FIELDCAT_ALV..
*- For Events
DATA:IT_EVENTS TYPE SLIS_T_EVENT.

DATA:  X_FIELDCAT  TYPE LVC_S_FCAT,
        X_FIELDCAT1  TYPE SLIS_FIELDCAT_ALV.
DATA:X_LAYOUT TYPE LVC_S_LAYO.
"{ FOR DISABLE
DATA: LS_EDIT TYPE LVC_S_STYL,
      LT_EDIT TYPE LVC_T_STYL.
"} FOR DISABLE
DATA: BEGIN OF IT_VBAP OCCURS 0,
      VBELN LIKE VBAP-VBELN,
      POSNR LIKE VBAP-POSNR,
      HANDLE_STYLE TYPE LVC_T_STYL, "FOR DISABLE
   <b>   BUTTON(10),</b>
     END OF IT_VBAP.
DATA: LS_OUTTAB LIKE LINE OF IT_VBAP.
SELECT VBELN
       POSNR
       UP TO 10 ROWS
      INTO CORRESPONDING FIELDS OF TABLE IT_VBAP
      FROM VBAP.


DATA:L_POS TYPE I VALUE 1.
CLEAR: L_POS.
L_POS = L_POS + 1.

<b>X_FIELDCAT-SELTEXT = 'Button'.
x_fieldcat-fieldname = 'BUTTON'.
X_FIELDCAT-TABNAME = 'ITAB'.
X_FIELDCAT-COL_POS    = L_POS.
X_FIELDCAT-OUTPUTLEN = '10'.

X_FIELDCAT-style = X_FIELDCAT-style bit-xor
                  cl_gui_alv_grid=>MC_STYLE_BUTTON bit-xor
                  cl_gui_alv_grid=>MC_STYLE_ENABLEd.
APPEND X_FIELDCAT TO IT_FIELDCAT.
CLEAR X_FIELDCAT.</b>

L_POS = L_POS + 1.


X_FIELDCAT-SELTEXT = 'VBELN'.
X_FIELDCAT-FIELDNAME = 'VBELN'.
X_FIELDCAT-TABNAME = 'ITAB'.
X_FIELDCAT-COL_POS    = L_POS.
X_FIELDCAT-EDIT = 'X'.
X_FIELDCAT-OUTPUTLEN = '10'.
x_fieldcat-ref_field = 'VBELN'.
x_fieldcat-ref_table = 'VBAK'.
APPEND X_FIELDCAT TO IT_FIELDCAT.
CLEAR X_FIELDCAT.
L_POS = L_POS + 1.

X_FIELDCAT-SELTEXT = 'POSNR'.
X_FIELDCAT-FIELDNAME = 'POSNR'.
X_FIELDCAT-TABNAME = 'ITAB'.
X_FIELDCAT-COL_POS    = L_POS.
X_FIELDCAT-EDIT = 'X'.
X_FIELDCAT-OUTPUTLEN = '5'.
APPEND X_FIELDCAT TO IT_FIELDCAT.
CLEAR X_FIELDCAT.
L_POS = L_POS + 1.
"{FOR DISABLE HERE 6ROW IS DISABLED
SY-TABIX = 6.
LS_EDIT-FIELDNAME = 'VBELN'.
LS_EDIT-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_DISABLED.
LS_EDIT-STYLE2 = SPACE.
LS_EDIT-STYLE3 = SPACE.
LS_EDIT-STYLE4 = SPACE.
LS_EDIT-MAXLEN = 10.
INSERT LS_EDIT INTO TABLE LT_EDIT.
*LS_EDIT-FIELDNAME = 'POSNR'.
*LS_EDIT-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_DISABLED.
*LS_EDIT-STYLE2 = SPACE.
*LS_EDIT-STYLE3 = SPACE.
*LS_EDIT-STYLE4 = SPACE.
*LS_EDIT-MAXLEN = 6.
*INSERT LS_EDIT INTO TABLE LT_EDIT.
INSERT LINES OF LT_EDIT INTO TABLE LS_OUTTAB-HANDLE_STYLE.
MODIFY IT_VBAP INDEX SY-TABIX FROM LS_OUTTAB  TRANSPORTING
                                  HANDLE_STYLE .

X_LAYOUT-STYLEFNAME = 'HANDLE_STYLE'.
"} UP TO HERE
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
  EXPORTING
    I_CALLBACK_PROGRAM = SY-REPID
    IS_LAYOUT_LVC      = X_LAYOUT
    IT_FIELDCAT_LVC    = IT_FIELDCAT
  TABLES
    T_OUTTAB           = IT_VBAP[]
  EXCEPTIONS
    PROGRAM_ERROR      = 1
    OTHERS             = 2.
IF SY-SUBRC <> 0.
  MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
          WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

to check the Button you copy paste and see the above code.

for button using cl_gui_alv_grid try the fieldcat which i marked as bold.

Regards

vijay

Read only

0 Likes
4,621

@Vijay Babu Dudla

Hi Vijay or anybody else that wants to answer me

I tried the program ZTESTALV. What I don't get is how to set the handler for the event BUTTON_CLICK. Do you have a code example how to create the handler when using the FM REUSE_ALV_GRID_DISPLAY_LVC?

Thanks and regards,

Stefan

Read only

0 Likes
4,621

I've the same problem. The field is shown as button but no event is triggerd.