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

Custom pushbutton in the ALV Grid Control

Former Member
0 Likes
1,903

Hi,

I have a requirement of adding a Custom pushbutton in the ALV Grid control along with the other ALV buttons. Plesae provide me with the coding...

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,350

Harini,

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = ws_repid

i_callback_pf_status_set = 'GUI_STAT1'

i_callback_user_command = 'STAT'

is_layout = gs_layout

it_fieldcat = i_fieldcat[]

it_sort = wa_sort1

TABLES

t_outtab = i_zaw_pol_plan.

**--Setting Status of output screen

FORM gui_stat1 USING rt_extab TYPE slis_t_extab.

SET PF-STATUS 'STANDARD1' EXCLUDING rt_extab.

SET TITLEBAR text-005.

ENDFORM.

Here double click on "STANDARD1" there in Application toolbar you can add you own Buttons there.

Don't forget to reward if useful...

Hi,

I have a requirement of adding a Custom pushbutton in the ALV Grid control along with the other ALV buttons. Plesae provide me with the coding...

7 REPLIES 7
Read only

Former Member
0 Likes
1,351

Harini,

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = ws_repid

i_callback_pf_status_set = 'GUI_STAT1'

i_callback_user_command = 'STAT'

is_layout = gs_layout

it_fieldcat = i_fieldcat[]

it_sort = wa_sort1

TABLES

t_outtab = i_zaw_pol_plan.

**--Setting Status of output screen

FORM gui_stat1 USING rt_extab TYPE slis_t_extab.

SET PF-STATUS 'STANDARD1' EXCLUDING rt_extab.

SET TITLEBAR text-005.

ENDFORM.

Here double click on "STANDARD1" there in Application toolbar you can add you own Buttons there.

Don't forget to reward if useful...

Read only

Former Member
0 Likes
1,350

Hi,

Try this code,

Plzz reward points if it helps.

REPORT zcl_timesheet_approval MESSAGE-ID zcl_msg.

----


  • CLASS L_CL_EVENTS DEFINITION *

----


  • Class for inserting buttons on the toolbar *

----


CLASS l_cl_events DEFINITION.

PUBLIC SECTION.

METHODS:

toolbar FOR EVENT toolbar

OF cl_gui_alv_grid

IMPORTING e_object

e_interactive,

user_command FOR EVENT user_command

OF cl_gui_alv_grid

IMPORTING e_ucomm .

ENDCLASS. " L_CL_EVENTS DEFINITION

----


  • CLASS L_CL_EVENTS IMPLEMENTATION *

----


  • Implementation of class L_CL_EVENTS *

----


CLASS l_cl_events IMPLEMENTATION.

METHOD toolbar.

PERFORM event_toolbar USING e_object.

ENDMETHOD. " TOOLBAR

METHOD user_command.

PERFORM event_ucomm USING e_ucomm.

ENDMETHOD. " USER_COMMAND

ENDCLASS. " L_CL_EVENTS IMPLEMENTATION

CONSTANTS:

c_boolean_yes(1) TYPE c " Boolean - yes

VALUE 'X',

c_approve_status(1) TYPE c " Approval status

VALUE 'A',

c_rej_status(1) TYPE c " Rejected status

VALUE 'R',

c_save_status(1) TYPE c " Save status

VALUE 'S',

c_fcode_approve(7) TYPE c " Function code - APPROVE

VALUE 'APPROVE',

c_fcode_rej(6) TYPE c " Function code - REJECT

VALUE 'REJECT',

c_fcode_back(4) TYPE c " Function code - BACK

VALUE 'BACK',

c_fcode_onli(4) TYPE c " Function code - EXECUTE

VALUE 'ONLI',

c_fcode_exit(4) TYPE c " Function code - EXIT

VALUE 'EXIT',

c_fcode_cancel(6) TYPE c " Function code - CANCEL

VALUE 'CANCEL',

c_zero(1) TYPE c " Constant value 0

VALUE '0',

c_alv_scr(7) TYPE c " GUI status : ALV screen

VALUE 'ALV_SCR'.

  • For ALV ...........................................................

DATA:

  • To create instance for cl_gui_custom_container

g_grid TYPE REF TO cl_gui_custom_container,

  • To create instance for cl_gui_alv_grid

g_alv TYPE REF TO cl_gui_alv_grid,

  • To create instance for l_cl_events

g_events TYPE REF TO l_cl_events,

  • To assign name for custom container

g_container TYPE scrfname VALUE 'CONTAINER',

  • To assign layout

g_fcatlayo TYPE lvc_s_layo.

  • Selection screen elements............................................

SELECTION-SCREEN BEGIN OF BLOCK blck WITH FRAME TITLE text-000.

SELECT-OPTIONS:

s_group FOR zcl_groups-id " Group ID

NO INTERVALS,

s_prjid FOR zcl_projects-projectid, " Project ID

s_empid FOR zcl_emprecord-empid, " Employee ID

s_date FOR zcl_timesheet-workdate. " Date

SELECTION-SCREEN END OF BLOCK blck.

SELECTION-SCREEN BEGIN OF BLOCK blck1 WITH FRAME TITLE text-015.

PARAMETERS:

p_app RADIOBUTTON GROUP g1 USER-COMMAND app ,

" To approve timesheet

p_disp RADIOBUTTON GROUP g1, " To display timesheet

p_sdn RADIOBUTTON GROUP g1. " To display sdn status

SELECTION-SCREEN END OF BLOCK blck1.

----


  • AT SELECTION-SCREEN EVENT *

----


AT SELECTION-SCREEN.

  • To perform user actions on the selection screen

PERFORM user_command.

----


  • MODULE STATUS_0100 OUTPUT *

----


  • This module will create the objects for the instance and display *

  • the records *

----


MODULE status_0100 OUTPUT.

SET PF-STATUS c_alv_scr.

PERFORM set_titlebar USING w_display.

  • If program executed in foreground.

IF sy-batch IS INITIAL.

  • If g_grid is empty.

IF g_grid IS INITIAL.

  • To create object for instance grid

CREATE OBJECT g_grid

EXPORTING

container_name = g_container.

  • To create object for object grid

CREATE OBJECT g_alv

EXPORTING

i_parent = g_grid.

ELSE.

  • IF W_SUBMIT EQ

CALL METHOD g_alv->refresh_table_display.

ENDIF. " IF G_GRID IS INITIAL

ENDIF. " IF SY-BATCH IS INITIAL

REFRESH t_fcat.

  • If w_display eq 'X' .

IF w_display EQ c_boolean_yes.

  • To display all records except saved data

PERFORM display_allrecords.

ENDIF. " IF W_FLAG EQ C_BOOLEAN_YES

IF w_submit EQ c_boolean_yes.

  • To display submitted records

PERFORM submitted_records.

ENDIF. " IF W_SUBMIT EQ C_BOOLEAN_YES

ENDMODULE. " STATUS_0100 OUTPUT

----


  • MODULE USER_COMMAND_0100 INPUT *

----


  • To perform user actions in the screen 100 *

----


MODULE user_command_0100 INPUT.

  • To update the data in the ALV grid

PERFORM check_changed_data.

w_okcode = ok_code.

CLEAR ok_code.

CASE w_okcode.

WHEN c_fcode_back.

LEAVE TO SCREEN 0.

WHEN c_fcode_exit OR c_fcode_cancel.

LEAVE PROGRAM.

ENDCASE. " CASE W_OKCODE

ENDMODULE. " USER_COMMAND_0100

----


  • FORM BUILD_FCAT *

----


  • To build the field catalog giving managers comment in editable mode *

----


  • -->PR_Tabname type lvc_tname *

  • -->PR_Fieldname type lvc_fname *

  • -->PR_Coltext type lvc_txtcol *

  • -->PR_Colpos type lvc_colpos *

----


FORM build_fcat USING pr_tabname TYPE lvc_tname

pr_fieldname TYPE lvc_fname

pr_coltext TYPE lvc_txtcol

pr_colpos TYPE lvc_colpos.

CLEAR fs_fcat.

fs_fcat-tabname = pr_tabname.

fs_fcat-fieldname = pr_fieldname.

fs_fcat-coltext = pr_coltext.

fs_fcat-col_pos = pr_colpos.

IF fs_fcat-fieldname EQ 'MNGCOMMENT'.

fs_fcat-edit = c_boolean_yes.

fs_fcat-lowercase = c_boolean_yes.

fs_fcat-dd_outlen = 60.

ELSE.

fs_fcat-edit = space.

ENDIF. " IF FS_FCAT-FIELDNAME...

APPEND fs_fcat TO t_fcat.

ENDFORM. " BUILD_FCAT

----


  • FORM ALV_DISPLAY *

----


  • To display data in ALV *

----


  • --> pr_table type standard table *

  • --> pr_fcat type lvc_t_fcat *

----


FORM alv_display USING pr_table TYPE STANDARD TABLE

pr_fcat TYPE lvc_t_fcat .

  • Local data declaration....

DATA: lt_exclude TYPE ui_functions.

  • To exclude buttons on the ALV grid

PERFORM exclude_tb_functions CHANGING lt_exclude.

  • To display ALV

CALL METHOD g_alv->set_table_for_first_display

EXPORTING

i_default = space

is_layout = g_fcatlayo

it_toolbar_excluding = lt_exclude

CHANGING

it_outtab = pr_table[]

it_fieldcatalog = pr_fcat[].

ENDFORM. " ALV_DISPLAY

----


  • FORM EVENT_TOOLBAR *

----


  • Setting toolbar in the alv grid *

----


  • -->E_OBJECT TYPE REF TO CL_ALV_EVENT_TOOLBAR_SET *

----


FORM event_toolbar USING e_object

TYPE REF TO cl_alv_event_toolbar_set.

  • Local declaration for the button.

DATA: ls_toolbar TYPE stb_button.

  • To add Approve button

ls_toolbar-function = c_fcode_approve.

ls_toolbar-butn_type = c_zero.

ls_toolbar-text = text-001.

APPEND ls_toolbar TO e_object->mt_toolbar.

  • To add Reject button

CLEAR ls_toolbar.

ls_toolbar-function = c_fcode_rej.

ls_toolbar-butn_type = c_zero.

ls_toolbar-text = text-013.

APPEND ls_toolbar TO e_object->mt_toolbar.

ENDFORM. " EVENT_TOOLBAR

----


  • FORM EXCLUDE_TB_FUNCTIONS *

----


  • To exclude buttons from ALV grid *

----


  • <--> PR_EXCLUDE TYPE UI_FUNCTIONS *

----


FORM exclude_tb_functions CHANGING pr_exclude TYPE ui_functions.

  • Local data declaration...

DATA ls_exclude TYPE ui_func.

  • To remove the buttons on the ALV grid.

ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy_row.

APPEND ls_exclude TO pr_exclude.

ls_exclude = cl_gui_alv_grid=>mc_fc_loc_delete_row.

APPEND ls_exclude TO pr_exclude.

ls_exclude = cl_gui_alv_grid=>mc_fc_loc_append_row.

APPEND ls_exclude TO pr_exclude.

ls_exclude = cl_gui_alv_grid=>mc_fc_loc_insert_row.

APPEND ls_exclude TO pr_exclude.

ls_exclude = cl_gui_alv_grid=>mc_fc_loc_move_row.

APPEND ls_exclude TO pr_exclude.

ENDFORM. " EXCLUDE_TB_FUNCTIONS

----


  • FORM EVENT_UCOMM *

----


  • After Input in the ALV grid,if user select record and press *

  • approve or reject then the record will get updated *

----


  • --> PR_ucomm type sy-ucomm *

----


FORM event_ucomm USING pr_ucomm LIKE sy-ucomm.

CASE pr_ucomm.

  • If e_ucomm contains 'APP' i.e.function code for Approve button

WHEN c_fcode_approve. " To approve selected record

PERFORM app_timesheet USING c_approve_status.

  • If e_ucomm contains 'REJ' i.e. function code for Reject

WHEN c_fcode_rej. " To reject selected record

PERFORM app_timesheet USING c_rej_status.

ENDCASE. " CASE E_UCOMM

ENDFORM. " EVENT_UCOMM

----


  • FORM CHECK_CHANGED_DATA *

----


  • To change the data *

----


  • No parameters are passsed to this subroutine *

----


FORM check_changed_data .

  • To change the data.

CALL METHOD g_alv->check_changed_data.

ENDFORM. " CHECK_CHANGED_DATA

----


  • FORM REFFRESH_TABLE *

----


  • To refresh output table and issue message according p_status *

----


  • -->PR_STATUS TYPE CHAR01 *

----


FORM refresh_table USING pr_status TYPE char01.

  • To refresh output table.

CALL METHOD g_alv->refresh_table_display.

  • Depending upon pr_status message is given.

IF pr_status EQ c_approve_status.

MESSAGE s001.

ELSE.

MESSAGE s002.

ENDIF. " IF P_STATUS EQ C_APPROVE_STATUS

ENDFORM. " REFRESH_TABLE

----


  • FORM USER_COMMAND *

----


  • According to sy-ucomm the action is performed in the screen 100 *

----


  • No parameters are passsed to this subroutine *

----


FORM user_command .

CASE sy-ucomm.

  • If p_app is selected, submitted data will be displayed for approval

WHEN c_fcode_onli OR c_fcode_approve.

CLEAR sy-ucomm.

  • To display the submitted records.

IF p_app EQ c_boolean_yes.

w_submit = c_boolean_yes.

  • To get submitted records

PERFORM get_data.

ENDIF. " IF P_APP EQ C_BOOLEAN_YES

  • To display all records according to selection.

IF p_disp EQ c_boolean_yes.

w_display = c_boolean_yes.

  • To display

PERFORM display_all.

CLEAR w_display.

ENDIF. " IF P_DISP EQ C_BOOLEAN_YES

IF p_sdn EQ c_boolean_yes.

PERFORM GET_GRAPH.

ENDIF.

ENDCASE. " CASE SY-UCOMM

ENDFORM. " USER_COMMAND

----


  • FORM DISPLAY_ALLRECORDS *

----


  • To display all the records in the display mode *

----


  • No parameters are passsed to this subroutine *

----


FORM display_allrecords .

CLEAR w_display.

PERFORM build_fcatd USING 'T_TIME' 'WORKDATE' text-002 '1'.

PERFORM build_fcatd USING 'T_TIME' 'EMPID' text-009 '2'.

PERFORM build_fcatd USING 'T_TIME' 'PROJECTID' text-003 '3'.

PERFORM build_fcatd USING 'T_TIME' 'PROJECTNAME' text-004 '4'.

PERFORM build_fcatd USING 'T_TIME' 'OBJECTID' text-005 '5'.

PERFORM build_fcatd USING 'T_TIME' 'OBJECTNAME' text-006 '6'.

PERFORM build_fcatd USING 'T_TIME' 'ACTIVITYID' text-007 '7'.

PERFORM build_fcatd USING 'T_TIME' 'ACTIVITYNAME' text-008 '8'.

PERFORM build_fcatd USING 'T_TIME' 'TIMEWORKED' text-010 '9'.

PERFORM build_fcatd USING 'T_TIME' 'DESCRIPTION' text-011 '10'.

PERFORM build_fcatd USING 'T_TIME' 'APPSTATUS' text-012 '11'.

PERFORM build_fcatd USING 'T_TIME' 'BILLSTATUS' text-016 '12'.

PERFORM build_fcatd USING 'T_TIME' 'SDNSTATUS' text-019 '13'.

PERFORM build_fcatd USING 'T_TIME' 'MNGCOMMENT' text-014 '14'.

PERFORM alv_display USING t_time t_fcat.

ENDFORM. " DISPLAY_ALLRECORDS

----


  • FORM SUBMITTED_RECORDS *

----


  • To display submitted records for the manager to approve *

----


  • No parameters are passsed to this subroutine *

----


FORM submitted_records .

CLEAR w_submit.

  • To create object for instance g_events

CREATE OBJECT g_events.

  • If w_first equal to space

IF w_first IS INITIAL.

SET HANDLER g_events->toolbar

FOR g_alv.

w_first = c_boolean_yes.

ENDIF. " IF W_FIRST IS INITIAL..

SET HANDLER g_events->user_command

FOR g_alv.

g_fcatlayo-sel_mode = c_approve_status.

REFRESH t_fcat.

PERFORM build_fcat USING 'T_TIMESHEET' 'WORKDATE' text-002 '1'.

PERFORM build_fcat USING 'T_TIMESHEET' 'EMPID' text-009 '2'.

PERFORM build_fcat USING 'T_TIMESHEET' 'PROJECTID' text-003 '3'.

PERFORM build_fcat USING 'T_TIMESHEET' 'PROJECTNAME' text-004 '4'.

PERFORM build_fcat USING 'T_TIMESHEET' 'OBJECTID' text-005 '5'.

PERFORM build_fcat USING 'T_TIMESHEET' 'OBJECTNAME' text-006 '6'.

PERFORM build_fcat USING 'T_TIMESHEET' 'ACTIVITYID' text-007 '7'.

PERFORM build_fcat USING 'T_TIMESHEET' 'ACTIVITYNAME' text-008 '8'.

PERFORM build_fcat USING 'T_TIMESHEET' 'TIMEWORKED' text-010 '9'.

PERFORM build_fcat USING 'T_TIMESHEET' 'DESCRIPTION' text-011 '10'.

PERFORM build_fcat USING 'T_TIMESHEET' 'APPSTATUS' text-012 '11'.

PERFORM build_fcat USING 'T_TIMESHEET' 'BILLSTATUS' text-016 '12'.

PERFORM build_fcat USING 'T_TIMESHEET' 'SDNSTATUS' text-019 '13'.

PERFORM build_fcat USING 'T_TIMESHEET' 'MNGCOMMENT' text-014 '13'.

PERFORM alv_display USING t_timesheet t_fcat.

ENDFORM. " SUBMITTED_RECORDS

Read only

Former Member
0 Likes
1,350

hi,

goto se41.....give this pgm name SAPLSLVC_FULLSCREEN

give this status name STANDARD_FULLSCREEN.....click copy status button.....copy to ur pgm name......go into ur new copied pf-ststus.........add ur new button ...assign a Fcode............activate...............

now see the foll links............

1) [http://www.sapdev.co.uk/reporting/alv/alvgrid_pfstatus.htm]

2) [http://www.sapdev.co.uk/reporting/alv/alvgrid_ucomm.htm]

Cheers,

jose.

Read only

Former Member
0 Likes
1,350

Hi,

I dont want to add a button in the application toolbar, so i dont require PF status. I would like to add a Pushbutton in the ALV grid toolbar.

I have used the following Code but it throws a runtime error.

MOVE 'DELIMIT1' TO ls_toolbar1-function.

MOVE 0 TO ls_toolbar1-butn_type.

MOVE ' ' TO LS_TOOLBAR1-ICON.

MOVE 'Delimit Date'(201) TO ls_toolbar1-quickinfo.

MOVE 'Delimit Date'(201) TO ls_toolbar1-text.

MOVE ' ' TO LS_TOOLBAR1-DISABLED.

APPEND ls_toolbar1 TO i_object1->mt_toolbar.

CALL METHOD grid1->set_toolbar_interactive.

Read only

0 Likes
1,350

Hi,

This is the code i used for adding the custom buttons on the alv grid toolbar.

i did not get any runtime error can u give brief description of ur error if the code does not works.

Plzz reward points if it helps.

-


FORM EVENT_TOOLBAR *

-


Setting toolbar in the alv grid *

-


-->E_OBJECT TYPE REF TO CL_ALV_EVENT_TOOLBAR_SET *

-


FORM event_toolbar USING e_object

TYPE REF TO cl_alv_event_toolbar_set.

Local declaration for the button.

DATA: ls_toolbar TYPE stb_button.

To add Approve button

ls_toolbar-function = c_fcode_approve.

ls_toolbar-butn_type = c_zero.

ls_toolbar-text = text-001.

APPEND ls_toolbar TO e_object->mt_toolbar.

To add Reject button

CLEAR ls_toolbar.

ls_toolbar-function = c_fcode_rej.

ls_toolbar-butn_type = c_zero.

ls_toolbar-text = text-013.

APPEND ls_toolbar TO e_object->mt_toolbar.

ENDFORM. " EVENT_TOOLBAR

Read only

0 Likes
1,350

I used the code without forms.

I am getting a runtime error,

Access via null object reference not possible.

This is my coding.

DATA : E_OBJECT1 TYPE REF TO CL_ALV_EVENT_TOOLBAR_SET.

DATA: ls_toolbar TYPE stb_button.

ls_toolbar-function = 'DELIMIT1'.

ls_toolbar-butn_type = '0'.

ls_toolbar-text = 'Delimit Entries'.

APPEND ls_toolbar TO e_object1->mt_toolbar.

Please help me

Read only

Former Member
0 Likes
1,350

Hi Harini,

check the below code....

DATA: gs_toolbar TYPE stb_button,

In the method implementation you need to write the below code...to add new button...

CLEAR gs_toolbar.

MOVE 3 TO gs_toolbar-butn_type.

APPEND gs_toolbar TO e_object->mt_toolbar.

CLEAR gs_toolbar.

MOVE 'CLICK' TO gs_toolbar-function.

MOVE 'CLICK' TO gs_toolbar-text.

  • --> This function code is evaluated in 'handle_menu_button'

MOVE 0 TO gs_toolbar-butn_type.

MOVE space TO gs_toolbar-disabled.

APPEND gs_toolbar TO e_object->mt_toolbar.

Rgds,

Bujji