Application Development 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: 

ALV OOP-ABAP

Former Member
0 Kudos
112

Hi,

I'm trying to create a report using ALV -OO ABAP. Here i have 2 screens. From the first I traverse to the 2nd screen. And in the 2 screens I'm creating custom buttons for the tool bar which will be different for both screens.

I'm using handle_toolbar,handle_user_command .

How do i have 2 different toolbars for both screens and how to write the events for both screens. Pls help

Thanks

4 REPLIES 4

Sandeep_Kumar
Product and Topic Expert
Product and Topic Expert
0 Kudos
63

Hi Prabha,

While implementing the method handle_toolbar for the first screen say u can add ur own custom buttons and for the screen screen implement another method say handle_toolbar_2.

See the below code for reference.

**Handle Toolbar

  • METHOD handle_toolbar.

  • DATA: ls_toolbar TYPE stb_button.

  • CLEAR ls_toolbar.

*

**add user button to the ALV toolbar

  • MOVE 'SAVE' TO ls_toolbar-function.

  • MOVE '@2L@' TO ls_toolbar-icon.

  • CLEAR ls_toolbar-disabled.

  • APPEND ls_toolbar TO e_object->mt_toolbar.

*

  • ENDMETHOD . "handle_toolbar

*

  • METHOD handle_user_command.

  • PERFORM validation USING gv_mgpln.

  • ENDMETHOD.

*reward if this helps.

Rgds,

Sandeep

Former Member
0 Kudos
63

HI Prabha

if you want to offer multiple functions on a single ALV row then these functions should not be assigned to specific columns of the ALV list because the user would need to memorize which column "allows" which function. Furthermore, this would not be according to SAP style guidelines.

The solution to your problem are context menus. The following sample report shows you how to add two functions to the context menu of the ALV list and how to execute these functions.

In addition, if you double-click on a row (= customer) the sales area details will be displayed in the second ALV list.

&----


*& Report ZUS_SDN_ALV_CONTEXT_MENU_1

*&

&----


*&

*&

&----


REPORT ZUS_SDN_ALV_CONTEXT_MENU_1.

DATA:

gd_okcode TYPE ui_func,

*

go_docking TYPE REF TO cl_gui_docking_container,

go_splitter TYPE REF TO cl_gui_splitter_container,

go_cell_top TYPE REF TO cl_gui_container,

go_cell_bottom TYPE REF TO cl_gui_container,

go_grid1 TYPE REF TO cl_gui_alv_grid,

go_grid2 TYPE REF TO cl_gui_alv_grid,

gs_layout TYPE lvc_s_layo.

DATA:

gt_knb1 TYPE STANDARD TABLE OF knb1,

gt_knvv TYPE STANDARD TABLE OF knvv.

----


  • CLASS lcl_eventhandler DEFINITION

----


*

----


CLASS lcl_eventhandler DEFINITION.

PUBLIC SECTION.

CLASS-METHODS:

handle_double_click FOR EVENT double_click OF cl_gui_alv_grid

IMPORTING

e_row

e_column

es_row_no

sender,

handle_context_menu_request FOR EVENT context_menu_request

OF cl_gui_alv_grid

IMPORTING

e_object

sender,

handle_user_command FOR EVENT user_command OF cl_gui_alv_grid

IMPORTING

e_ucomm

sender.

ENDCLASS. "lcl_eventhandler DEFINITION

----


  • CLASS lcl_eventhandler IMPLEMENTATION

----


*

----


CLASS lcl_eventhandler IMPLEMENTATION.

METHOD handle_double_click.

  • define local data

DATA:

ls_knb1 TYPE knb1.

CHECK ( sender = go_grid1 ).

READ TABLE gt_knb1 INTO ls_knb1 INDEX e_row-index.

CHECK ( ls_knb1-kunnr IS NOT INITIAL ).

CALL METHOD go_grid1->set_current_cell_via_id

EXPORTING

  • IS_ROW_ID =

  • IS_COLUMN_ID =

is_row_no = es_row_no.

  • Triggers PAI of the dynpro with the specified ok-code

CALL METHOD cl_gui_cfw=>set_new_ok_code( 'DETAIL' ).

ENDMETHOD. "handle_double_click

METHOD handle_context_menu_request.

e_object->add_separator( ).

CALL METHOD e_object->add_function

EXPORTING

fcode = 'XD03'

text = 'Call Transaction'.

*

CALL METHOD e_object->add_function

EXPORTING

fcode = 'DETAILS'

text = 'Display Details'.

ENDMETHOD. "handle_context_menu_request

METHOD handle_user_command.

  • define local data

DATA:

ls_knb1 TYPE knb1,

ls_row TYPE lvc_s_row,

ls_col TYPE lvc_s_col.

" NOTE: in case of CL_GUI_ALV_GRID the functions of a context menu

" are handled in method USER_COMMAND.

CHECK ( e_ucomm = 'XD03' OR

e_ucomm = 'DETAILS' ).

CALL METHOD sender->get_current_cell

IMPORTING

es_row_id = ls_row

es_col_id = ls_col.

CASE e_ucomm.

WHEN 'XD03'.

READ TABLE gt_knb1 INTO ls_knb1 INDEX ls_row-index.

SET PARAMETER ID 'BUK' FIELD ls_knb1-bukrs.

SET PARAMETER ID 'KUN' FIELD ls_knb1-kunnr.

CALL TRANSACTION 'XD03' AND SKIP FIRST SCREEN.

WHEN 'DETAILS'.

" NOTE: only for the sake of simplicity the event handler method

" is called

CALL METHOD lcl_eventhandler=>handle_double_click

EXPORTING

e_row = ls_row

sender = go_grid1.

WHEN OTHERS.

ENDCASE.

ENDMETHOD. "handle_user_command

ENDCLASS. "lcl_eventhandler IMPLEMENTATION

START-OF-SELECTION.

SELECT * FROM knb1 INTO TABLE gt_knb1

WHERE bukrs = '1000'.

  • Create docking container

CREATE OBJECT go_docking

EXPORTING

parent = cl_gui_container=>screen0

ratio = 90

EXCEPTIONS

OTHERS = 6.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

  • Create splitter container

CREATE OBJECT go_splitter

EXPORTING

parent = go_docking

rows = 2

columns = 1

  • NO_AUTODEF_PROGID_DYNNR =

  • NAME =

EXCEPTIONS

cntl_error = 1

cntl_system_error = 2

OTHERS = 3.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

  • Get cell container

CALL METHOD go_splitter->get_container

EXPORTING

row = 1

column = 1

RECEIVING

container = go_cell_top.

CALL METHOD go_splitter->get_container

EXPORTING

row = 2

column = 1

RECEIVING

container = go_cell_bottom.

  • Create ALV grids

CREATE OBJECT go_grid1

EXPORTING

i_parent = go_cell_top

EXCEPTIONS

OTHERS = 5.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

  • Set event handler

SET HANDLER:

lcl_eventhandler=>handle_double_click FOR go_grid1,

lcl_eventhandler=>handle_context_menu_request FOR go_grid1,

lcl_eventhandler=>handle_user_command FOR go_grid1.

CREATE OBJECT go_grid2

EXPORTING

i_parent = go_cell_bottom

EXCEPTIONS

OTHERS = 5.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

  • Display data

gs_layout-grid_title = 'Customers'.

CALL METHOD go_grid1->set_table_for_first_display

EXPORTING

i_structure_name = 'KNB1'

is_layout = gs_layout

CHANGING

it_outtab = gt_knb1

EXCEPTIONS

OTHERS = 4.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

gs_layout-grid_title = 'Customers Details (Sales Areas)'.

CALL METHOD go_grid2->set_table_for_first_display

EXPORTING

i_structure_name = 'KNVV'

is_layout = gs_layout

CHANGING

it_outtab = gt_knvv " empty !!!

EXCEPTIONS

OTHERS = 4.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

  • Link the docking container to the target dynpro

CALL METHOD go_docking->link

EXPORTING

repid = syst-repid

dynnr = '0100'

  • CONTAINER =

EXCEPTIONS

OTHERS = 4.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

  • NOTE: dynpro does not contain any elements

CALL SCREEN '0100'.

  • Flow logic of dynpro (does not contain any dynpro elements):

*

*PROCESS BEFORE OUTPUT.

  • MODULE STATUS_0100.

**

*PROCESS AFTER INPUT.

  • MODULE USER_COMMAND_0100.

END-OF-SELECTION.

&----


*& Module STATUS_0100 OUTPUT

&----


  • text

----


MODULE status_0100 OUTPUT.

SET PF-STATUS 'STATUS_0100'. " contains push button "DETAIL"

  • SET TITLEBAR 'xxx'.

  • Refresh display of detail ALV list

CALL METHOD go_grid2->refresh_table_display

  • EXPORTING

  • IS_STABLE =

  • I_SOFT_REFRESH =

EXCEPTIONS

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.

ENDMODULE. " STATUS_0100 OUTPUT

&----


*& Module USER_COMMAND_0100 INPUT

&----


  • text

----


MODULE user_command_0100 INPUT.

CASE gd_okcode.

WHEN 'BACK' OR

'END' OR

'CANC'.

SET SCREEN 0. LEAVE SCREEN.

  • User has pushed button "Display Details"

WHEN 'DETAIL'.

PERFORM entry_show_details.

WHEN OTHERS.

ENDCASE.

CLEAR: gd_okcode.

ENDMODULE. " USER_COMMAND_0100 INPUT

&----


*& Form ENTRY_SHOW_DETAILS

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM entry_show_details .

  • define local data

DATA:

ld_row TYPE i,

ls_knb1 TYPE knb1.

CALL METHOD go_grid1->get_current_cell

IMPORTING

e_row = ld_row.

READ TABLE gt_knb1 INTO ls_knb1 INDEX ld_row.

CHECK ( syst-subrc = 0 ).

SELECT * FROM knvv INTO TABLE gt_knvv

WHERE kunnr = ls_knb1-kunnr.

ENDFORM. " ENTRY_SHOW_DETAILS

reward points to all helpful answers

kiran.M

Former Member
0 Kudos
63

Hi,

Check this program BCALV_GRID_01

Regards

Arun

Former Member
0 Kudos
63

hi prabha...

refer this progra.. BCALV_GRID_05...its using oop-alv...having to screens.

as u click on any record and clcik on detail button.

.the next alv pop-up without detail button ..so both alvs have different toolbar...

hopefully,

will be useful

.rewardif useful.

thx...

vivek