Skip to Content
0
Former Member
Apr 17, 2008 at 11:18 PM

ALV report for 5 Grids using Objects and Method

29 Views

I have few questions in ALV 5Grids ,could you please correct me in the following program logic...

Using this program logic i am able to generate the five Grids and able to populate Header details from VBAK into Grid1,If you click in the Grid 1 and it is populating item details in Grid2 from VBAP,parallally populating the customer data in Grid5 from KNA1.

Now the pending issue is ,

if you click in the Grid2 then we should populate the shipping details in Grid3 and

if you click in the Grid3 then we should populate the billing details in Grid4.

Program Logic;

REPORT ZAREPAS20.

Tables : vbak,vbap,likp,lips,vbrk,vbrp,kna1.

DATA : OK_CODE LIKE SY-UCOMM,

G_CONTAINER TYPE SCRFNAME VALUE 'BCALV7_GRID_DEMO_0100_VASU',

DOCKING TYPE REF TO CL_GUI_DOCKING_CONTAINER,

SPLITTER_1 TYPE REF TO CL_GUI_SPLITTER_CONTAINER,

SPLITTER_2 TYPE REF TO CL_GUI_SPLITTER_CONTAINER,

splitter_3 TYPE REF TO CL_GUI_SPLITTER_CONTAINER,

CELL_TOP1 TYPE REF TO CL_GUI_CONTAINER,

CELL_BOTTOM1 TYPE REF TO CL_GUI_CONTAINER,

CELL_TOP2 TYPE REF TO CL_GUI_CONTAINER,

CELL_BOTTOM2 TYPE REF TO CL_GUI_CONTAINER,

CELL_LEFT TYPE REF TO CL_GUI_CONTAINER,

CELL_middle TYPE REF TO CL_GUI_CONTAINER,

CELL_RIGHT TYPE REF TO CL_GUI_CONTAINER,

GRID1 TYPE REF TO CL_GUI_ALV_GRID,

GRID2 TYPE REF TO CL_GUI_ALV_GRID,

GRID3 TYPE REF TO CL_GUI_ALV_GRID,

GRID4 TYPE REF TO CL_GUI_ALV_GRID,

GRID5 TYPE REF TO CL_GUI_ALV_GRID.

DATA : GT_VBAK TYPE STANDARD TABLE OF VBAK,

GT_VBAP TYPE STANDARD TABLE OF VBAP,

GT_LIKP TYPE STANDARD TABLE OF likp,

GT_LIPS TYPE STANDARD TABLE OF lips,

GT_VBRK TYPE STANDARD TABLE OF vbrk,

GT_VBRP TYPE STANDARD TABLE OF vbrp,

GT_KNA1 TYPE STANDARD TABLE OF kna1.

DATA:begin of itab1 occurs 0,

vbeln type likp-VBELN,

erzet type likp-ERZET,

lfart type likp-LFART,

posnr type lips-POSNR,

END OF ITAB1.

DATA:begin of itab2 occurs 0,

vbeln like vbrk-vbeln,

posnr like vbrk-fktyp,

fkart like vbrk-fkart,

fklmg like vbrp-fklmg,

end of itab2.

*selection screen for selecting range of values

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE text-001.

select-options: S_vbeln for VBAK-vbeln.

selection-screen end of block b1.

----


  • 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. " sending control, i.e. ALV grid that raised event

ENDCLASS. "lcl_eventhandler DEFINITION

----


  • CLASS lcl_eventhandler IMPLEMENTATION

----


CLASS lcl_eventhandler IMPLEMENTATION.

METHOD HANDLE_DOUBLE_CLICK.

*DEFINE LOCAL DATA.

DATA : itab_vbak type VBAK,

itab_vbap type VBAP,

itab_likp type likp,

itab_lips type lips,

itab_vbrk type vbrk,

itab_vbrp type vbrp,

itab_kna1 type kna1.

*DISTINGUISH ACCORDING TO SENDING GRID INSTANCE

CASE SENDER.

WHEN GRID1.

READ TABLE gt_VBAK INTO itab_vbak INDEX e_row-index.

CHECK ( itab_vbak-vbeln IS NOT INITIAL ).

CALL METHOD 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( 'ORDER_DETAILS' ).

WHEN GRID2.

READ TABLE gt_VBAP INTO itab_vbap INDEX e_row-index.

CHECK ( itab_vbap-vbeln IS NOT INITIAL ).

CALL METHOD GRID2->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( 'ORDER_DETAILS' ).

WHEN GRID3.

READ TABLE gt_LIPS INTO itab_LIPS INDEX e_row-index.

CHECK ( itab_lips-vgbel IS NOT INITIAL ).

CALL METHOD GRID3->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( 'DELIVERY_DETAILS' ).

WHEN GRID4.

READ TABLE gt_VBRP INTO itab_VBRP INDEX e_row-index.

CHECK ( itab_vbrp-vgbel IS NOT INITIAL ).

CALL METHOD GRID4->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( 'BILLING_DETAILS' ).

WHEN GRID5.

READ TABLE gt_KNA1 INTO itab_KNA1 INDEX e_row-index.

CHECK ( itab_kna1-kunnr IS NOT INITIAL ).

  • SET PARAMETER ID 'KUN' FIELD itab_KNA1-KUNNR.

  • CALL TRANSACTION 'MM02' AND SKIP FIRST SCREEN.

WHEN OTHERS.

RETURN.

ENDCASE.

endmethod.

endclass. "lcl_eventhandler IMPLEMENTATION

start-of-selection.

*write :/ 'FEDEX INT''''L' .

SELECT * FROM vbak INTO TABLE gt_VBAK

where vbeln IN S_VBELN.

  • creating docking container

create object docking

exporting

parent = cl_gui_container=>screen0

ratio = 90

exceptions

others = 6.

if sy-subrc eq 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 splitter_1

EXPORTING

parent = docking

rows = 1

columns = 3

  • NO_AUTODEF_PROGID_DYNNR =

  • NAME =

EXCEPTIONS

cntl_error = 1

cntl_system_error = 2

OTHERS = 3.

IF sy-subrc eq 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 splitter_1->get_container

EXPORTING

row = 1

column = 1

RECEIVING

container = cell_left.

CALL METHOD splitter_1->get_container

EXPORTING

row = 1

column = 2

RECEIVING

container = cell_middle.

CALL METHOD splitter_1->get_container

EXPORTING

row = 1

column = 3

RECEIVING

container = cell_right.

  • Create 2nd splitter container

CREATE OBJECT splitter_2

EXPORTING

parent = cell_left

rows = 2

columns = 1

  • NO_AUTODEF_PROGID_DYNNR =

  • NAME =

EXCEPTIONS

cntl_error = 1

cntl_system_error = 2

OTHERS = 3.

IF sy-subrc eq 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 splitter_2->get_container

EXPORTING

row = 1

column = 1

RECEIVING

container = cell_top1.

CALL METHOD splitter_2->get_container

EXPORTING

row = 2

column = 1

RECEIVING

container = cell_bottom1.

  • Create 3rd splitter container

CREATE OBJECT splitter_3

EXPORTING

parent = cell_middle

rows = 2

columns = 1

  • NO_AUTODEF_PROGID_DYNNR =

  • NAME =

EXCEPTIONS

cntl_error = 1

cntl_system_error = 2

OTHERS = 3.

IF sy-subrc eq 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 splitter_3->get_container

EXPORTING

row = 1

column = 1

RECEIVING

container = cell_top2.

CALL METHOD splitter_3->get_container

EXPORTING

row = 2

column = 1

RECEIVING

container = cell_bottom2.

  • Create ALV grids

CREATE OBJECT grid1

EXPORTING

i_parent = cell_top1

EXCEPTIONS

OTHERS = 5.

IF sy-subrc eq 0.

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

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

ENDIF.

CREATE OBJECT grid2

EXPORTING

i_parent = cell_bottom1

EXCEPTIONS

OTHERS = 5.

IF sy-subrc eq 0.

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

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

ENDIF.

CREATE OBJECT grid3

EXPORTING

i_parent = cell_top2

EXCEPTIONS

OTHERS = 5.

IF sy-subrc eq 0.

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

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

ENDIF.

CREATE OBJECT grid4

EXPORTING

i_parent = cell_bottom2

EXCEPTIONS

OTHERS = 5.

IF sy-subrc eq 0.

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

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

ENDIF.

CREATE OBJECT grid5

EXPORTING

i_parent = cell_right

EXCEPTIONS

OTHERS = 5.

IF sy-subrc eq 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 grid1.

SET HANDLER: lcl_eventhandler=>handle_double_click FOR grid2.

SET HANDLER: lcl_eventhandler=>handle_double_click FOR grid3.

SET HANDLER: lcl_eventhandler=>handle_double_click FOR grid4.

SET HANDLER: lcl_eventhandler=>handle_double_click FOR grid5.

----


----


  • Display data

CALL METHOD grid1->set_table_for_first_display

EXPORTING

i_structure_name = 'VBAK'

CHANGING

it_outtab = gt_VBAK

EXCEPTIONS

OTHERS = 4.

IF sy-subrc eq 0.

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

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

ENDIF.

REFRESH: gt_vbap.

CALL METHOD grid2->set_table_for_first_display

EXPORTING

i_structure_name = 'VBAP'

CHANGING

it_outtab = gt_VBAP " empty !!!

EXCEPTIONS

OTHERS = 4.

IF sy-subrc eq 0.

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

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

ENDIF.

REFRESH: gt_LIPS.

CALL METHOD grid3->set_table_for_first_display

EXPORTING

i_structure_name = 'LIPS'

CHANGING

it_outtab = gt_LIPS " empty !!!

EXCEPTIONS

OTHERS = 4.

IF sy-subrc eq 0.

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

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

ENDIF.

REFRESH: gt_VBRP.

CALL METHOD grid4->set_table_for_first_display

EXPORTING

i_structure_name = 'VBRP'

CHANGING

it_outtab = gt_VBRP " empty !!!

EXCEPTIONS

OTHERS = 4.

IF sy-subrc eq 0.

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

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

ENDIF.

REFRESH: gt_KNA1.

CALL METHOD grid5->set_table_for_first_display

EXPORTING

i_structure_name = 'KNA1'

CHANGING

it_outtab = gt_KNA1 " empty !!!

EXCEPTIONS

OTHERS = 4.

IF sy-subrc eq 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 docking->link

EXPORTING

repid = syst-repid

dynnr = '0100'

  • CONTAINER =

EXCEPTIONS

OTHERS = 4.

IF sy-subrc eq 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 (ok_code -> GD_OKCODE)

CALL SCREEN '0100'.

  • Flow logic of dynpro:

*

*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'.

  • SET TITLEBAR 'xxx'.

  • Refresh display of detail ALV list

CALL METHOD grid2->refresh_table_display

  • EXPORTING

  • IS_STABLE =

  • I_SOFT_REFRESH =

EXCEPTIONS

OTHERS = 2.

IF sy-subrc eq 0.

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

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

ENDIF.

  • Refresh display of detail ALV list

CALL METHOD grid3->refresh_table_display

  • EXPORTING

  • IS_STABLE =

  • I_SOFT_REFRESH =

EXCEPTIONS

OTHERS = 2.

IF sy-subrc eq 0.

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

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

ENDIF.

  • Refresh display of detail ALV list

CALL METHOD grid4->refresh_table_display

  • EXPORTING

  • IS_STABLE =

  • I_SOFT_REFRESH =

EXCEPTIONS

OTHERS = 2.

IF sy-subrc eq 0.

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

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

ENDIF.

  • Refresh display of detail ALV list

CALL METHOD grid5->refresh_table_display

  • EXPORTING

  • IS_STABLE =

  • I_SOFT_REFRESH =

EXCEPTIONS

OTHERS = 2.

IF sy-subrc eq 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 SY-UCOMM.

WHEN 'BACK' OR

'EXIT' OR

'CANCEL'.

SET SCREEN 0.LEAVE SCREEN.

  • USER HAS PUSHED BUTTON "DISPLAY OREDERS"

*

WHEN 'ORDER_DETAILS'.

PERFORM ORDER_SHOW_DETAILS.

when 'DELIVERY_DETAILS'.

PERFORM DELIVERY_SHOW_DETAILS.

WHEN 'BILLING_DETAILS'.

PERFORM BILLING_SHOW_DETAILS.

WHEN OTHERS.

ENDCASE.

CLEAR : OK_CODE.

ENDMODULE. " USER_COMMAND_0100 INPUT

&----


*& Form ORDER_SHOW_DETAILS

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM order_show_details .

  • define local data

DATA:

ld_row TYPE i,

itab_VBAK TYPE VBAK.

CALL METHOD grid1->get_current_cell

IMPORTING

e_row = ld_row.

READ TABLE gt_VBAK INTO itab_VBAK INDEX ld_row.

CHECK ( syst-subrc = 0 ).

SELECT * FROM KNA1 INTO TABLE gt_KNA1

WHERE KUNNR = itab_VBAK-KUNNR.

SELECT * FROM VBAP INTO TABLE gt_VBAP

WHERE VBELN = ITAB_VBAK-VBELN.

*REFRESH: gt_LIPS.

ENDFORM. " ORDER_SHOW_DETAILS

&----


*& Form DELIVERY_SHOW_DETAILS

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM DELIVERY_SHOW_DETAILS .

  • define local data

DATA:

ld_row TYPE i,

itab_VBAP TYPE VBAP.

CALL METHOD grid1->get_current_cell

IMPORTING

e_row = ld_row.

READ TABLE gt_VBAP INTO itab_VBAP INDEX ld_row.

CHECK ( syst-subrc = 0 ).

SELECT LIKPVBELN LIKPERZET LIKPLFART LIPSVBELN

INTO CORRESPONDING FIELDS OF TABLE ITAB1

FROM ( LIKP INNER JOIN LIPS ON LIKPVBELN = LIPSVBELN )

WHERE LIKP~VBELN IN S_VBELN.

*REFRESH: gt_LIPS.

ENDFORM. " DELIVERY_SHOW_DETAILS

&----


*& Form BILLING_SHOW_DETAILS

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM BILLING_SHOW_DETAILS .

  • define local data

DATA:

ld_row TYPE i,

itab_LIPS TYPE LIPS.

CALL METHOD grid1->get_current_cell

IMPORTING

e_row = ld_row.

READ TABLE gt_LIPS INTO itab_LIPS INDEX ld_row.

CHECK ( syst-subrc = 0 ).

SELECT VBRKVBELN VBRKFKTYP VBRKFKART VBRPFKLMG

INTO CORRESPONDING FIELDS OF TABLE ITAB2

FROM ( VBRK INNER JOIN VBRP ON VBRKVBELN = VBRPVBELN )

WHERE VBRK~VBELN IN S_VBELN.

ENDFORM. " BILLING_SHOW_DETAILS