Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Tree Control With Oops

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 23

Generate tree view with oops.

In this create a screen with custom control name as CST.


REPORT zrk_oop_treeview.
TYPE-POOLS: cntl.
TYPES: BEGIN OF ty_nodes.
INCLUDE STRUCTURE abdemonode.
TYPES END OF ty_nodes.
DATA : lt_nodes TYPE TABLE OF ty_nodes,
ls_nodes TYPE ty_nodes.
TYPES : BEGIN OF ty_events.
INCLUDE TYPE cntl_simple_event.
TYPES END OF ty_events.
DATA : lt_events TYPE TABLE OF ty_events,
ls_events TYPE ty_events.
DATA : cust_cont TYPE REF TO cl_gui_custom_container,
o_tree TYPE REF TO cl_gui_simple_tree.
CLASS lcl_eventreceiver DEFINITION.
PUBLIC SECTION.
METHODS handle_node_double_click FOR EVENT node_double_click
OF cl_gui_simple_tree IMPORTING node_key.
ENDCLASS.

"lcl_eventreceiver DEFINITION

CLASS lcl_eventreceiver IMPLEMENTATION.


METHOD handle_node_double_click.
CASE node_key.
WHEN 'CSO'.
CALL TRANSACTION 'VA01'.
WHEN 'CHSO'.

CALL TRANSACTION 'VA02'.


WHEN 'DSO'.
CALL TRANSACTION 'SE38'.
WHEN 'CPO'.
CALL TRANSACTION 'ME21'.
WHEN 'CHPO'.
CALL TRANSACTION 'ME22'.
ENDCASE.
ENDMETHOD.

"handle_node_double_click

ENDCLASS.

"lcl_eventreceiver IMPLEMENTATION

DATA ob TYPE REF TO lcl_eventreceiver.


START-OF-SELECTION.
CALL SCREEN 3000.
MODULE status_3000 OUTPUT.
SET PF-STATUS 'PF3000'. set pf status for back button.
* SET TITLEBAR 'xxx'.
IF cust_cont IS INITIAL.
CREATE OBJECT cust_cont
EXPORTING
container_name

= 'CST'.

CREATE OBJECT o_tree


EXPORTING
parent

= cust_cont

node_selection_mode

= cl_gui_simple_tree=>node_sel_mode_single.

PERFORM addnodes.
ENDIF.
ENDMODULE.

" STATUS_3000 OUTPUT

MODULE user_command_3000 INPUT.


CASE sy-ucomm.

WHEN 'BACK'.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE.

" USER_COMMAND_3000 INPUT

FORM addnodes .
CLEAR ls_nodes.
ls_nodes-node_key = 'RT'. """"root node'
ls_nodes-isfolder = 'X'.
ls_nodes-expander = 'X'.
ls_nodes-text = 'Transactions'.
APPEND ls_nodes TO lt_nodes.
CLEAR ls_nodes.
ls_nodes-node_key = 'SO'. """"root node'
ls_nodes-relatkey = 'RT'.
ls_nodes-isfolder = 'X'.
ls_nodes-expander = 'X'.
ls_nodes-text = 'Sales Order'.
APPEND ls_nodes TO lt_nodes.
CLEAR ls_nodes.
ls_nodes-node_key = 'PO'. """"root node'
ls_nodes-relatkey = 'RT'.
ls_nodes-isfolder = 'X'.
ls_nodes-expander = 'X'.
ls_nodes-text = 'PURCHASE Order'.
APPEND ls_nodes TO lt_nodes.
CLEAR ls_nodes.
ls_nodes-node_key = 'CSO'. """"root node'
ls_nodes-relatkey = 'SO'.
ls_nodes-n_image = '@15@'.

ls_nodes-text = 'CREATE SALES ORDER'.


APPEND ls_nodes TO lt_nodes.
CLEAR ls_nodes.
ls_nodes-node_key = 'CHSO'. """"root node'
ls_nodes-relatkey = 'SO'.
ls_nodes-n_image = '@15@'.
ls_nodes-text = 'CHANGE SALES ORDER'.
APPEND ls_nodes TO lt_nodes.
CLEAR ls_nodes.
ls_nodes-node_key = 'DSO'. """"root node'
ls_nodes-relatkey = 'SO'.
ls_nodes-n_image = '@15@'.
ls_nodes-text = 'GO TO ABAP EDITOR'.
APPEND ls_nodes TO lt_nodes.
CLEAR ls_nodes.
ls_nodes-node_key = 'CPO'. """"root node'
ls_nodes-relatkey = 'PO'.
ls_nodes-n_image = '@15@'.
ls_nodes-text = 'CREATE PURCHASE ORDER'.
APPEND ls_nodes TO lt_nodes.
CLEAR ls_nodes.
ls_nodes-node_key = 'CHPO'. """"root node'
ls_nodes-relatkey = 'PO'.
ls_nodes-n_image = '@15@'.
ls_nodes-text = 'CHANGE PURCHASE ORDER'.
APPEND ls_nodes TO lt_nodes.
PERFORM registerhandlers.
CALL METHOD o_tree->add_nodes
EXPORTING

table_structure_name = 'ABDEMONODE'
node_table

= lt_nodes[].

ENDFORM.

" ADDNODES

FORM registerhandlers .
CREATE OBJECT ob.
SET HANDLER ob->handle_node_double_click FOR o_tree.
CLEAR ls_events.
ls_events-eventid = cl_gui_simple_tree=>eventid_node_double_click.
APPEND ls_events TO lt_events.
CALL METHOD o_tree->set_registered_events
EXPORTING
events = lt_events.
ENDFORM.

" registerhandlers

OOPS ALV REPORT WITH TREE CONTROL:This is the sample code copied from web site its working fine.
Create screen no 100.
In PBO (please dont do any code changes in exiting code. like whatever it
is in comments just leave it as it is.) for PAI also.
Create a module with name as follows
Module pbo.
Create a module with name as follows in PAI
Module pai.
In screen layout create a custom control with name TREE1.
REPORT zrk_oop_treeview2.

CLASS cl_gui_column_tree DEFINITION LOAD.


CLASS cl_gui_cfw DEFINITION LOAD.
DATA tree1 TYPE REF TO cl_gui_alv_tree_simple.
*INCLUDE .
INCLUDE bcalv_simple_event_receiver.
DATA: gt_sflight TYPE sflight OCCURS 0, " Output-Table
gt_fieldcatalog TYPE lvc_t_fcat, " Field Catalog
gt_sort TYPE lvc_t_sort, " Sorting Table
ok_code LIKE sy-ucomm. " OK-Code
END-OF-SELECTION.
CALL SCREEN 100.
FORM build_fieldcatalog.
* get fieldcatalog
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = 'SFLIGHT'
CHANGING
ct_fieldcat

= gt_fieldcatalog.

* change fieldcatalog
DATA: ls_fieldcatalog TYPE lvc_s_fcat.
LOOP AT gt_fieldcatalog INTO ls_fieldcatalog.
CASE ls_fieldcatalog-fieldname.
WHEN 'CARRID' OR 'CONNID' OR 'FLDATE'.
ls_fieldcatalog-no_out = 'X'.
ls_fieldcatalog-key = ''.
WHEN 'PRICE' OR 'SEATSOCC' OR 'SEATSMAX' OR 'PAYMENTSUM'.
ls_fieldcatalog-do_sum = 'X'.
ENDCASE.
MODIFY gt_fieldcatalog FROM ls_fieldcatalog.

ENDLOOP.
ENDFORM. " BUILD_FIELDCATALOG
FORM build_outtab.
SELECT * FROM sflight INTO TABLE gt_sflight.
ENDFORM. " BUILD_OUTTAB
FORM build_sort_table.
DATA ls_sort_wa TYPE lvc_s_sort.
* create sort-table
ls_sort_wa-spos = 1.
ls_sort_wa-fieldname = 'CARRID'.
ls_sort_wa-up = 'X'.
ls_sort_wa-subtot = 'X'.
APPEND ls_sort_wa TO gt_sort.
ls_sort_wa-spos = 2.
ls_sort_wa-fieldname = 'CONNID'.
ls_sort_wa-up = 'X'.
ls_sort_wa-subtot = 'X'.
APPEND ls_sort_wa TO gt_sort.
ls_sort_wa-spos = 3.
ls_sort_wa-fieldname = 'FLDATE'.
ls_sort_wa-up = 'X'.
APPEND ls_sort_wa TO gt_sort.
ENDFORM. " BUILD_SORT_TABLE
MODULE pbo OUTPUT.
IF tree1 IS INITIAL.
PERFORM init_tree.
ENDIF.
SET PF-STATUS 'ZSTATUS'.
ENDMODULE. " PBO OUTPUT

MODULE pai INPUT.


CASE ok_code.
WHEN 'EXIT' OR 'BACK' OR 'CANC'.
PERFORM exit_program.
WHEN OTHERS.
CALL METHOD cl_gui_cfw=>dispatch.
ENDCASE.
CLEAR ok_code.
ENDMODULE. " PAI INPUT
FORM exit_program.
CALL METHOD tree1->free.
LEAVE PROGRAM.
ENDFORM. " exit_program
FORM register_events.
* define the events which will be passed to the backend
DATA: lt_events TYPE cntl_simple_events,
l_event TYPE cntl_simple_event.
* define the events which will be passed to the backend
l_event-eventid = cl_gui_column_tree=>eventid_node_context_menu_req.
APPEND l_event TO lt_events.
l_event-eventid = cl_gui_column_tree=>eventid_item_context_menu_req.
APPEND l_event TO lt_events.
l_event-eventid = cl_gui_column_tree=>eventid_header_context_men_req.
APPEND l_event TO lt_events.
l_event-eventid = cl_gui_column_tree=>eventid_expand_no_children.
APPEND l_event TO lt_events.
l_event-eventid = cl_gui_column_tree=>eventid_header_click.
APPEND l_event TO lt_events.
l_event-eventid = cl_gui_column_tree=>eventid_item_keypress.

APPEND l_event TO lt_events.


CALL METHOD tree1->set_registered_events
EXPORTING
events

= lt_events

EXCEPTIONS
cntl_error

=1

cntl_system_error

=2

illegal_event_combination = 3.

* set Handler
DATA: l_event_receiver TYPE REF TO lcl_tree_event_receiver.
CREATE OBJECT l_event_receiver.
SET HANDLER l_event_receiver->on_add_hierarchy_node
FOR tree1.
ENDFORM. " register_events
FORM build_comment USING
pt_list_commentary TYPE slis_t_listheader
p_logo TYPE sdydo_value.
DATA: ls_line TYPE slis_listheader.
* LIST HEADING LINE: TYPE H
CLEAR ls_line.
ls_line-typ = 'H'.
* LS_LINE-KEY: NOT USED FOR THIS TYPE
ls_line-info = 'RAJKUMAR SIRIPURAM'.
APPEND ls_line TO pt_list_commentary.
p_logo = 'ENJOYSAP_LOGO'.
ENDFORM. "build_comment
FORM init_tree.
PERFORM build_fieldcatalog.

PERFORM build_outtab.
PERFORM build_sort_table.
* create container for alv-tree
DATA: l_tree_container_name(30) TYPE c,
l_custom_container TYPE REF TO cl_gui_custom_container.
l_tree_container_name = 'TREE1'.
CREATE OBJECT l_custom_container
EXPORTING
container_name = l_tree_container_name
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5.
* create tree control
CREATE OBJECT tree1
EXPORTING
i_parent = l_custom_container
i_node_selection_mode =
cl_gui_column_tree=>node_sel_mode_multiple
i_item_selection = 'X'
i_no_html_header = ''
i_no_toolbar = ''
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4

illegal_node_selection_mode = 5
failed = 6
illegal_column_name = 7.
* create info-table for html-header
DATA: lt_list_commentary TYPE slis_t_listheader,
l_logo TYPE sdydo_value.
PERFORM build_comment USING
lt_list_commentary
l_logo.
* repid for saving variants
DATA: ls_variant TYPE disvariant.
ls_variant-report = sy-repid.
* register events
PERFORM register_events.
* create hierarchy
CALL METHOD tree1->set_table_for_first_display
EXPORTING
it_list_commentary = lt_list_commentary
i_logo

= l_logo

i_background_id

= 'ALV_BACKGROUND'

i_save

= 'A'

is_variant

= ls_variant

CHANGING
it_sort

= gt_sort

it_outtab
it_fieldcatalog

= gt_sflight
= gt_fieldcatalog.

* expand first level


CALL METHOD tree1->expand_tree
EXPORTING

i_level = 1.
* optimize column-width
CALL METHOD tree1->column_optimize
EXPORTING
i_start_column = tree1->c_hierarchy_column_name
i_end_column = tree1->c_hierarchy_column_name.
ENDFORM. " init_tree " registerhandlers
module STATUS_0100 output.
SET PF-STATUS 'ABC'.
* SET TITLEBAR 'xxx'.
endmodule.

" STATUS_0100 OUTPUT

oops alv interactive report.


This is the sample alv interactive.
Sir explained same example in class.
Creare 3 screens
Screen 100.
Create a custom control with name CST1.
Screen 200.
Create a custom control with name CST2.
Screen 300.
Create a custom control with name CST3.
Note : here you can mention custom container name for all the screens as CST also. Because
each screen have separate custom container.

REPORT zrk_oop_alv02.

TYPES : BEGIN OF ty_kna1,


kunnr TYPE kna1-kunnr,
land1 TYPE kna1-land1,

name1 TYPE kna1-name1,


END OF ty_kna1.
DATA : lt_kna1 TYPE TABLE OF ty_kna1,
ls_kna1 TYPE ty_kna1.
TYPES : BEGIN OF ty_vbak,
vbeln TYPE vbak-vbeln,
erdat TYPE vbak-erdat,
erzet TYPE vbak-erzet,
ernam TYPE vbak-ernam,
cellstyles TYPE lvc_t_styl,
END OF ty_vbak.
DATA : lt_vbak TYPE TABLE OF ty_vbak,
ls_vbak TYPE ty_vbak.
TYPES : BEGIN OF ty_vbap,
vbeln TYPE vbap-vbeln,
posnr TYPE vbap-posnr,
matnr TYPE vbap-matnr,
END OF ty_vbap.
DATA : lt_vbap TYPE TABLE OF ty_vbap,
ls_vbap TYPE ty_vbap.
DATA lv_kunnr TYPE kunnr.
DATA lv_vbeln TYPE vbeln.
DATA ls_styl TYPE lvc_s_styl.
SELECT-OPTIONS so_kunnr FOR lv_kunnr.
DATA : kna1_cont TYPE REF TO cl_gui_custom_container,
kna1_grid TYPE REF TO cl_gui_alv_grid.
DATA : vbak_cont TYPE REF TO cl_gui_custom_container,
vbak_grid TYPE REF TO cl_gui_alv_grid.
DATA : vbap_cont TYPE REF TO cl_gui_custom_container,

vbap_grid TYPE REF TO cl_gui_alv_grid.


DATA : lt_fcat TYPE lvc_t_fcat,
ls_fcat TYPE lvc_s_fcat.
DATA ls_layo TYPE lvc_s_layo.
CLASS lcl_eventreceiver DEFINITION.
PUBLIC SECTION.
METHODS handle_hotspot_click FOR EVENT hotspot_click OF
cl_gui_alv_grid
IMPORTING e_row_id.
METHODS handle_button_click FOR EVENT button_click
OF cl_gui_alv_grid IMPORTING es_row_no.
METHODS handle_double_click FOR EVENT double_click
OF cl_gui_alv_grid IMPORTING e_row e_column.
ENDCLASS.

"lcl_eventreceiver DEFINITION

CLASS lcl_eventreceiver IMPLEMENTATION.


METHOD handle_hotspot_click.
CLEAR ls_kna1.
READ TABLE lt_kna1 INTO ls_kna1
INDEX e_row_id-index TRANSPORTING kunnr.
IF sy-subrc EQ 0.
CLEAR lv_kunnr.
lv_kunnr = ls_kna1-kunnr.
IF lv_kunnr IS NOT INITIAL.
*

MESSAGE 'kUNNR VALUE RECEIVED' TYPE 'I'.


PERFORM getsalesorders.
IF lt_vbak[] IS NOT INITIAL.
CALL SCREEN 200.
ELSE.
MESSAGE 'No sales orders' TYPE 'I'.

ENDIF.
ENDIF.
ENDIF.
ENDMETHOD.

"handle_hotspot_click

METHOD handle_button_click.
READ TABLE lt_vbak INTO ls_vbak
INDEX es_row_no-row_id TRANSPORTING vbeln.
IF sy-subrc EQ 0.
CLEAR lv_vbeln.
lv_vbeln = ls_vbak-vbeln.
IF lv_vbeln IS NOT INITIAL.
PERFORM getsalesitems.
IF lt_vbap[] IS NOT INITIAL.
CALL SCREEN 300.
ELSE.
MESSAGE 'No sales items' TYPE 'I'.
ENDIF.
ENDIF.
ENDIF.
ENDMETHOD.

"handle_button_click

METHOD handle_double_click.
CASE e_column-fieldname.
WHEN 'MATNR'.
READ TABLE lt_vbap INTO ls_vbap
INDEX e_row-index TRANSPORTING matnr.
IF sy-subrc EQ 0.
SET PARAMETER ID 'MAT' FIELD ls_vbap-matnr.
ENDIF.
CALL TRANSACTION 'MM03'.

WHEN OTHERS.
MESSAGE 'Please click on material' TYPE 'I'.
ENDCASE.
ENDMETHOD.

"handle_double_click

ENDCLASS.

"lcl_eventreceiver IMPLEMENTATION

DATA ob TYPE REF TO lcl_eventreceiver.


INITIALIZATION.
so_kunnr-low = '1000'.
so_kunnr-high = '1020'.
APPEND so_kunnr.
START-OF-SELECTION.
CALL SCREEN 100.
MODULE status_0100 OUTPUT.
IF kna1_cont IS INITIAL.
SET PF-STATUS 'ABC'.
CREATE OBJECT kna1_cont
EXPORTING
container_name

= 'CST1'.

CREATE OBJECT kna1_grid


EXPORTING
i_parent

= kna1_cont.

PERFORM getcustomers.
IF lt_kna1[] IS NOT INITIAL.
PERFORM fldcatkna1.
PERFORM layoutkna1.
PERFORM registerhandlers.
PERFORM displaykna1.
ENDIF.
ENDIF.

ENDMODULE.

" STATUS_0100 OUTPUT

MODULE user_command_0100 INPUT.


CASE sy-ucomm.
WHEN 'BACK'.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE.

"USER_COMMAND_0100 INPUT

FORM displaykna1 .
CALL METHOD kna1_grid->set_table_for_first_display
EXPORTING
is_layout

= ls_layo

CHANGING
it_outtab

= lt_kna1[]

it_fieldcatalog = lt_fcat[].
ENDFORM.

" displaykna1

FORM fldcatkna1 .
CLEAR ls_fcat.
ls_fcat-fieldname = 'KUNNR'.
ls_fcat-col_pos = 1.
ls_fcat-coltext = 'Customer No'.
ls_fcat-hotspot = 'X'.
APPEND ls_fcat TO lt_fcat.
CLEAR ls_fcat.
ls_fcat-fieldname = 'LAND1'.
ls_fcat-col_pos = 2.
ls_fcat-coltext = 'Country'.
APPEND ls_fcat TO lt_fcat.
CLEAR ls_fcat.
ls_fcat-fieldname = 'NAME1'.

ls_fcat-col_pos = 3.
ls_fcat-coltext = 'Customer Name'.
ls_fcat-outputlen = 20.
APPEND ls_fcat TO lt_fcat.
ENDFORM.

" fldcatkna1

FORM getcustomers .
SELECT kunnr land1 name1 FROM kna1
INTO TABLE lt_kna1
WHERE kunnr IN so_kunnr.
ENDFORM.

" getcustomers

FORM layoutkna1 .
CLEAR ls_layo.
ls_layo-grid_title = 'CUSTOMER MASTER DATA'.
ENDFORM.

" layoutkna1

FORM getsalesorders .
SELECT vbeln erdat erzet ernam FROM vbak
INTO CORRESPONDING FIELDS OF TABLE lt_vbak
WHERE kunnr = lv_kunnr.

ENDFORM.

" getsalesorders

MODULE status_0200 OUTPUT.


IF vbak_cont IS INITIAL.
SET PF-STATUS 'XYZ'.
CREATE OBJECT vbak_cont
EXPORTING
container_name

= 'CST2'.

CREATE OBJECT vbak_grid


EXPORTING
i_parent

= vbak_cont.

PERFORM fldcatvbak.
PERFORM layoutvbak.
PERFORM cellstyles.
PERFORM reghandlers.
PERFORM displayvbak.
ENDIF.
ENDMODULE.

" STATUS_0200 OUTPUT

MODULE user_command_0200 INPUT.


CASE sy-ucomm.
WHEN 'BACK'.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE.

" USER_COMMAND_0200 INPUT

FORM displayvbak .
CALL METHOD vbak_grid->set_table_for_first_display
EXPORTING
is_layout

= ls_layo

CHANGING
it_outtab

= lt_vbak[]

it_fieldcatalog = lt_fcat[].
ENDFORM.

" displayvbak

FORM fldcatvbak .
REFRESH lt_fcat.
CLEAR ls_fcat.
ls_fcat-fieldname = 'VBELN'.
ls_fcat-col_pos = 1.
ls_fcat-coltext = 'Sales Doc'.
APPEND ls_fcat TO lt_fcat.
CLEAR ls_fcat.

ls_fcat-fieldname = 'ERDAT'.
ls_fcat-col_pos = 2.
ls_fcat-coltext = 'Date'.
APPEND ls_fcat TO lt_fcat.
CLEAR ls_fcat.
ls_fcat-fieldname = 'ERZET'.
ls_fcat-col_pos = 3.
ls_fcat-coltext = 'Time'.
APPEND ls_fcat TO lt_fcat.
CLEAR ls_fcat.
ls_fcat-fieldname = 'ERNAM'.
ls_fcat-col_pos = 4.
ls_fcat-coltext = 'Person'.
APPEND ls_fcat TO lt_fcat.
ENDFORM.

" fldcatvbak

FORM layoutvbak .
CLEAR ls_layo.
ls_layo-grid_title = 'SALES DOCUMENT HEADER DATA'.
ls_layo-stylefname = 'CELLSTYLES'.
ENDFORM.

" layoutvbak

FORM cellstyles .
DATA lv_date TYPE d.
CLEAR ls_vbak.
LOOP AT lt_vbak INTO ls_vbak.
lv_date = ls_vbak-erdat+0(4).
IF lv_date >= '2000'.
ls_styl-fieldname = 'VBELN'.
ls_styl-style = cl_gui_alv_grid=>mc_style_button.
INSERT ls_styl INTO TABLE ls_vbak-cellstyles.

MODIFY lt_vbak FROM ls_vbak


TRANSPORTING cellstyles.
ENDIF.
CLEAR ls_vbak.
ENDLOOP.
ENDFORM.

" cellstyles

FORM getsalesitems .
SELECT vbeln posnr matnr FROM vbap
INTO TABLE lt_vbap
WHERE vbeln = lv_vbeln.
ENDFORM.

" getsalesitems

MODULE status_0300 OUTPUT.


IF vbap_cont IS INITIAL.
SET PF-STATUS 'PQR'.
CREATE OBJECT vbap_cont
EXPORTING
container_name

= 'CST3'.

CREATE OBJECT vbap_grid


EXPORTING
i_parent

= vbap_cont.

PERFORM fldcatvbap.
PERFORM layoutvbap.
PERFORM reg_handlers.
PERFORM displayvbap.
ENDIF.
ENDMODULE.

" STATUS_0300 OUTPUT

MODULE user_command_0300 INPUT.


CASE sy-ucomm.

WHEN 'BACK'.
LEAVE TO SCREEN 200.
ENDCASE.
ENDMODULE.

" USER_COMMAND_0300 INPUT

FORM reghandlers .
create object ob.
set handler ob->handle_button_click for vbak_grid.
ENDFORM.

" reghandlers

FORM registerhandlers .
CREATE OBJECT ob.
SET HANDLER ob->handle_hotspot_click FOR kna1_grid.
ENDFORM.

" registerhandlers

FORM fldcatvbap .
REFRESH lt_fcat.
CLEAR ls_fcat.
ls_fcat-fieldname = 'VBELN'.
ls_fcat-col_pos = 1.
ls_fcat-coltext = 'Sales Doc'.
APPEND ls_fcat TO lt_fcat.
CLEAR ls_fcat.
ls_fcat-fieldname = 'POSNR'.
ls_fcat-col_pos = 2.
ls_fcat-coltext = 'Item no'.
APPEND ls_fcat TO lt_fcat.
CLEAR ls_fcat.
ls_fcat-fieldname = 'MATNR'.
ls_fcat-col_pos = 3.
ls_fcat-coltext = 'Material'.
APPEND ls_fcat TO lt_fcat.

ENDFORM.

" fldcatvbap

FORM layoutvbap .
CLEAR ls_layo.
ls_layo-grid_title = 'SALES DOCUMENT ITEM DATA'.
ENDFORM.

" layoutvbap

FORM reg_handlers .
CREATE OBJECT ob.
SET HANDLER ob->handle_double_click FOR vbap_grid.
ENDFORM.

" reg_handlers

FORM displayvbap .
CALL METHOD vbap_grid->set_table_for_first_display
EXPORTING
is_layout

= ls_layo

CHANGING
it_outtab

= lt_vbap[]

it_fieldcatalog = lt_fcat[].
ENDFORM.

" displayvbap..

You might also like