Você está na página 1de 20

Display more than one Internal Table in ALV using Object Oriented

ABAP Programming
By Ashwini Thoutireddy, Phifer Wire Products Inc

Applies to:

This document applies to SAP ECC 6.0, SAP Net weaver 2004s.

Scenario

Displaying more than one table in ALV grid report by splitting the custom container.

TABLE 2

TABLE 1
TABLE 3

Step by step Solution

Step 1: Creating Screen

Go to Screen painter Transaction Code SE51.

Create a screen with no 9010.

Provide description for the screen and click on the Layout Button.

Place a Custom container UI element and give name as CCONTAINER now you will have a screen with
custom container as below screen shot. Activate the Object.
Step 2: Flow Logic

Go to the Flow Logic Tab to write coding for PBO & PAI.

Step 3: Report
*&---------------------------------------------------------------------*
*& Report ZPC_CONTAINER_CONTROL *
*&---------------------------------------------------------------------*
REPORT zpc_container_control.
*Declaration
DATA: Splitter_1 TYPE REF TO cl_gui_splitter_container,
Splitter_2 TYPE REF TO cl_gui_splitter_container,
Container TYPE REF TO cl_gui_custom_container,
Container_1 TYPE REF TO cl_gui_container,
Container_2 TYPE REF TO cl_gui_container,
Container_3 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.
DATA: Gt_sflight_1 TYPE TABLE OF sflight,
Gt_sflight_2 TYPE TABLE OF sflight,
Gt_sflight_3 TYPE TABLE OF sflight,
G_container TYPE scrfname VALUE 'CCONTAINER'.
DATA: ok_code TYPE sy-ucomm.
* fetching data from table for different internal tables
SELECT * FROM sflight INTO TABLE gt_sflight_1. Itab 1
SELECT * FROM sflight INTO TABLE gt_sflight_2 UP TO 3 ROWS. Itab 2
SELECT * FROM sflight INTO TABLE gt_sflight_3 UP TO 2 ROWS. Itab 3
CALL SCREEN 9010.
*&---------------------------------------------------------------------*
*& Module STATUS_9010 OUTPUT *
*&---------------------------------------------------------------------*
MODULE status_9010 OUTPUT.
SET PF-STATUS 'TEST'.
*creating object reference for container
CREATE OBJECT container
EXPORTING
container_name = 'CCONTAINER'. Pass name of container created in Screen no
9010
*splitting the main container into 1 row & 2 coloum
CREATE OBJECT splitter_1
EXPORTING
Parent = container
Rows = 1
Columns = 2.
*getting the reference for the splited container (row 1 & col 1 container)
CALL METHOD splitter_1->get_container
EXPORTING
Row = 1
Column = 1
RECEIVING
Container = container_1.
*getting the reference for the splited container (row 1 & col 2 container)
CALL METHOD splitter_1->get_container
EXPORTING
Row = 1
Column = 2
RECEIVING
Container = container_2.
*splitting the 2nd coloum container in to 2 rows & 1 coloum
CREATE OBJECT splitter_2
EXPORTING
Parent = container_2
Rows = 2
Columns = 1.
*getting the reference for the splited container2 (row 1 & col 2 container)
CALL METHOD splitter_2->get_container
EXPORTING
Row = 1
Column = 1
RECEIVING
Container = container_2.
*getting the reference for the splited container2 (row 2 & col 1 container)
CALL METHOD splitter_2->get_container
EXPORTING
Row = 2
Column = 1
RECEIVING
Container = container_3.
*populating first internal table to the container
CREATE OBJECT container
EXPORTING
container_name = g_container.
CREATE OBJECT grid1
EXPORTING
i_parent = container_1.
CALL METHOD grid1->set_table_for_first_display
EXPORTING
i_structure_name = 'SFLIGHT'
CHANGING
it_outtab = gt_sflight_1.
*populating second internal table
CREATE OBJECT container
EXPORTING
container_name = g_container.
CREATE OBJECT grid2
EXPORTING
i_parent = container_2.
CALL METHOD grid2->set_table_for_first_display
EXPORTING
i_structure_name = 'SFLIGHT'
CHANGING
it_outtab = gt_sflight_2.
*populating third internal table
CREATE OBJECT container
EXPORTING
container_name = g_container.
CREATE OBJECT grid3
EXPORTING
i_parent = container_3.
CALL METHOD grid3->set_table_for_first_display
EXPORTING
i_structure_name = 'SFLIGHT'
CHANGING
it_outtab = gt_sflight_3.
ENDMODULE. STATUS_9010 OUTPUT
*&---------------------------------------------------------------------*
*& Module EXIT INPUT *
*&---------------------------------------------------------------------*
MODULE exit INPUT.
*free the container memory when exit
CALL METHOD container->free.
LEAVE PROGRAM.
ENDMODULE. EXIT INPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_9010 INPUT *
*&---------------------------------------------------------------------*
MODULE user_command_9010 INPUT.
CALL METHOD cl_gui_cfw=>dispatch.
CASE ok_code.
WHEN 'BACK'.
LEAVE SCREEN.
WHEN 'CANCEL'.
LEAVE PROGRAM.
WHEN 'EXIT'.
LEAVE SCREEN.
ENDCASE.
ENDMODULE. USER_COMMAND_9010 INPUT

Output

The report will display as below screen shot.

Displaying ALV using a Docking Container


By Sandeep Patel, I-novate Technologies

Objective

This program is used to display Docking Container. Sometimes we get the requirement to place the
container at any corner as resizable Ex: ALV and selection parameters in same Screen. To serve
purpose we will go for docking container.

Introduction

As we know that a SAP Container is a control that accommodates other controls, such as the SAP Tree
Control, SAP Picture Control, SAP Text edit Control, SAP Splitter Control, and so on. It manages these
controls logically in a collection, and provides a physical area in which they are displayed. All controls live
in a container. Since containers are themselves controls, you can nest them. There are five kinds of SAP
Containers:

SAP Custom Container: display controls in an area defined on a normal screen using the Screen
Painter. Class: CL_GUI_CUSTOM_CONTAINER

SAP Dialog Box Container: display controls in a modal dialog box or full screen.

Class: CL_GUI_DIALOGBOX_CONTAINER

SAP Docking Container: The SAP Docking Container allows you to attach a control to any of the four
edges of a screen as a resizable screen area. You can also detach it so that it becomes an independent
modal dialog box. Class: CL_GUI_DOCKING_CONTAINER

SAP Splitter Container: to display more than one control in a given area by dividing it into cells. Class:
CL_GUI_SPLITTER_CONTAINER

SAP Easy Splitter Container: this container allows us to divide an area into two cells with a control in
each. The cells are separated by a moveable splitter bar.

Class: CL_GUI_EASY_SPLITTER_CONTAINER.

Here we display the functionality of docking container.

SAP Docking container can be attached on or more areas of screen. To reattach the docking container to
a different edge of the screen we use DOCK_AT method. To switch the status of the Docking Container
between fixed (docking) and free (floating) we use the method FLOAT.

We can use docking container in web Dynpro and sub screen also.

Below is the Example of Docking Container.

Code Snippet

REPORT z75_docking MESSAGE-ID yxnmc.

TABLES: mara.
*---------------------------------------------------------------------*
* WORK AREAS *
*---------------------------------------------------------------------*
DATA:
* Material Data
BEGIN OF wa_mara,
matnr TYPE mara-matnr, " Material No.
mtart TYPE mara-mtart, " Material Type
bismt TYPE mara-bismt, " Old material No.
matkl TYPE mara-matkl, " Material group
meins TYPE mara-meins, " Base Unit of Measure
brgew TYPE mara-brgew, " Gross Weight
ntgew TYPE mara-ntgew, " Net Weight
gewei TYPE mara-gewei, " Weight Unit
END OF wa_mara,

* Field Catalog

wa_fieldcat TYPE lvc_s_fcat.

*---------------------------------------------------------------------*
* INTERNAL TABLES *
*---------------------------------------------------------------------*
DATA:
* For Material Data
t_mara LIKE STANDARD TABLE OF wa_mara,
* For Field Catalog
t_fieldcat TYPE lvc_t_fcat.

*---------------------------------------------------------------------*
* WORK VARIABLES *
*---------------------------------------------------------------------*
DATA:
* User Command
ok_code TYPE sy-ucomm,
* Reference Variable for Docking Container
r_dock_container TYPE REF TO cl_gui_docking_container,
* Reference Variable for alv grid
r_grid TYPE REF TO cl_gui_alv_grid.

*---------------------------------------------------------------------*
* START OF SELECTION *
*---------------------------------------------------------------------*
START-OF-SELECTION.
* To Display the Data
PERFORM display_output.
*&--------------------------------------------------------------------*
*& Form display_output *
*&--------------------------------------------------------------------*
* To Call the screen & display the output *
*---------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine.*
*---------------------------------------------------------------------*
FORM display_output .
* To fill the Field Catalog
PERFORM fill_fieldcat USING :
'MATNR' 'T_MARA' 'Material No.',
'MTART' 'T_MARA' 'Material Type',
'BISMT' 'T_MARA' 'Old Material No.',
'MATKL' 'T_MARA' 'Material Group',
'MEINS' 'T_MARA' 'Base Unit of Measure',
'BRGEW' 'T_MARA' 'Gross Weight',
'NTGEW' 'T_MARA' 'Net Weight',
'GEWEI' 'T_MARA' 'Weight Unit'.
CALL SCREEN 500.
ENDFORM. " Display_output

*&--------------------------------------------------------------*
*& Form FILL_FIELDCAT *
*&--------------------------------------------------------------*
* To Fill the Field Catalog *
*---------------------------------------------------------------*
* Three Parameters are passed *
* pv_field TYPE any for Field *
* pv_tabname TYPE any for Table Name *
* pv_coltext TYPE any for Header Text *
*---------------------------------------------------------------*
FORM fill_fieldcat USING pv_field TYPE any
pv_tabname TYPE any
pv_coltext TYPE any .

wa_fieldcat-fieldname = pv_field.
wa_fieldcat-tabname = pv_tabname.
wa_fieldcat-coltext = pv_coltext.

APPEND wa_fieldcat TO t_fieldcat.


CLEAR wa_fieldcat.
ENDFORM. " FILL_FIELDCAT

Create the Screen 0500.

Flow Logic for Screen 500.

*&---------------------------------------------------------------------*
*& Module STATUS_0500 OUTPUT *
*&---------------------------------------------------------------------*
* To Set GUI Status & Title *
*----------------------------------------------------------------------*
MODULE status_0500 OUTPUT.

SET PF-STATUS 'STATUS'.


SET TITLEBAR 'TITLE'.

ENDMODULE. " STATUS_0500 OUTPUT

*&---------------------------------------------------------------------*
*& Module CREATE_OBJECTS OUTPUT *
*&---------------------------------------------------------------------*
* To Call the Docking Container & Display Method *
*----------------------------------------------------------------------*
MODULE create_objects OUTPUT.
* Create a Docking container and dock the control at right side of screen
CHECK r_dock_container IS INITIAL.
CREATE OBJECT r_dock_container
EXPORTING
side = cl_gui_docking_container=>dock_at_right
extension = 780
caption = 'Materials'
EXCEPTIONS
cntl_error =1
cntl_system_error =2
create_error =3
lifetime_error =4
lifetime_dynpro_dynpro_link = 5
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. " IF sy-subrc <> 0.

* To Create the Grid Instance


CREATE OBJECT r_grid
EXPORTING
i_parent = r_dock_container
EXCEPTIONS
error_cntl_create = 1
error_cntl_init = 2
error_cntl_link = 3
error_dp_create = 4
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. " IF sy-subrc <> 0.

* Formatted Output Table is Sent to Control


CALL METHOD r_grid->set_table_for_first_display
CHANGING
it_outtab = t_mara
it_fieldcatalog = t_fieldcat
* it_sort =
* it_filter =
EXCEPTIONS
invalid_parameter_combination = 1
program_error =2
too_many_lines =3
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. " IF sy-subrc <> 0.
ENDMODULE. " CREATE_OBJECTS OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0500 INPUT *
*&---------------------------------------------------------------------*
* To Fetch the Material Data & Refresh Table after get User Command*
*----------------------------------------------------------------------*
MODULE user_command_0500 INPUT.
CASE ok_code.
WHEN 'EXECUTE'.
SELECT matnr " material no.
mtart " material type
bismt " old material no.
matkl " material group
meins " base unit of measure
brgew " gross weight
ntgew " net weight
gewei " weight unit
FROM mara
INTO TABLE t_mara
WHERE mtart = mara-mtart.
IF sy-subrc <> 0.
ENDIF. " IF sy-subrc EQ 0.
CALL METHOD r_grid->refresh_table_display.
WHEN 'BACK' OR 'CANCEL' OR 'EXIT'.
LEAVE TO SCREEN 0.
ENDCASE. " CASE ok_code.
ENDMODULE. " USER_COMMAND_0500 INPUT

Demo program on interactive ALV using OOPS


By Swarna S, Tata Consultancy Services

*&---------------------------------------------------------------------*
*& Report ZALV_OOINTERACTIVE *
*& Author Swarna.S. *
*& Published at SAPTechnical.com *
*&---------------------------------------------------------------------*
*& AS : Simple Interactive ALV report developed using OOPS *
*& *
*&---------------------------------------------------------------------*
REPORT ZALV_OOINTERACTIVE.
*Class definition for handling double click
CLASS event_class DEFINITION DEFERRED.
*Internal table and work area declarations for dd02l and dd03l
DATA : it_dd02l TYPE TABLE OF dd02l,
wa_dd02l TYPE dd02l,
it_dd03l TYPE TABLE OF dd03l,
wa_dd03l TYPE dd03l.
*data declarations for ALV Main list
DATA : ty_lay1 TYPE lvc_s_layo,
it_fieldcat TYPE lvc_t_fcat ,
ty_fieldcat TYPE lvc_s_fcat ,
c_alv1 TYPE REF TO cl_gui_alv_grid,
c_cont1 TYPE REF TO cl_gui_custom_container,
event_receiver TYPE REF TO event_class.
*data declarations for ALV Interactive list
DATA : ty_lay2 TYPE lvc_s_layo,
it_fcat TYPE lvc_t_fcat ,
ty_fcat TYPE lvc_s_fcat ,
c_alv2 TYPE REF TO cl_gui_alv_grid,
c_cont2 TYPE REF TO cl_gui_custom_container.
**Select options for multiple values and NOT ranges
SELECT-OPTIONS : s_table FOR wa_dd02l-tabname NO INTERVALS.
* Initialization event
INITIALIZATION.
*Start of selection event
START-OF-SELECTION.
*fetch data into table and field characteristics
PERFORM fetch_data.
*ALV display for output
PERFORM alv_output.
*&---------------------------------------------------------------------*
*& Form FETCH_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM fetch_data .
*Select the table details
SELECT * FROM dd02l INTO CORRESPONDING FIELDS OF TABLE it_dd02l
WHERE tabname IN s_table
AND tabclass = 'TRANSP'.
ENDFORM. " FETCH_DATA
*----------------------------------------------------------------------*
* CLASS lcl_event_receiver DEFINITION
*----------------------------------------------------------------------*
CLASS event_class DEFINITION.
*Handling double click
PUBLIC SECTION.
METHODS:
handle_double_click
FOR EVENT double_click OF cl_gui_alv_grid IMPORTING e_row .
ENDCLASS. "lcl_event_receiver DEFINITION
*----------------------------------------------------------------------*
* CLASS lcl_event_receiver IMPLEMENTATION
*----------------------------------------------------------------------*
CLASS event_class IMPLEMENTATION.
METHOD handle_double_click.
DATA : ls_dd02l LIKE LINE OF it_dd02l.
*Reading the selected data into a variable
READ TABLE it_dd02l INDEX e_row-index INTO ls_dd02l.
* *Select the field details of the selected table
SELECT * FROM dd03l INTO CORRESPONDING FIELDS OF TABLE it_dd03l
WHERE tabname EQ ls_dd02l-tabname.
*calling the ALV containing the field values
CALL SCREEN 101.
ENDMETHOD. "handle_double_click
ENDCLASS. "lcl_event_receiver IMPLEMENTATION
*&---------------------------------------------------------------------*
*& Module pbo_100 OUTPUT
*&---------------------------------------------------------------------*
MODULE pbo_100 OUTPUT.
*set pf-status 'XXX'.
*set titlebar 'XXX'.
ENDMODULE. " PBO_100 OUTPUT
*&---------------------------------------------------------------------*
*& Module alv_100 OUTPUT
*&---------------------------------------------------------------------*
MODULE alv_100 OUTPUT.
*Check if there is no custom container in screen 100
IF c_cont1 IS INITIAL.
*Creating object of container
CREATE OBJECT c_cont1
EXPORTING
container_name = 'CCONT'.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*Creating object of alv
CREATE OBJECT c_alv1
EXPORTING
i_parent = c_cont1.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*alv layout
PERFORM alv_100_layout.
*alv field catalogue
PERFORM alv_100_fieldcat.
*Displaying the ALV grid
CALL METHOD c_alv1->set_table_for_first_display
EXPORTING
is_layout = ty_lay1
CHANGING
it_outtab = it_dd02l[]
it_fieldcatalog = it_fieldcat.
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 object of the event class and setting handler for double click
CREATE OBJECT event_receiver.
SET HANDLER event_receiver->handle_double_click FOR c_alv1.
ENDIF.
ENDMODULE. " ALV_100 OUTPUT
*&---------------------------------------------------------------------*
*& Module pai_100 INPUT
*&---------------------------------------------------------------------*
MODULE pai_100 INPUT.
ENDMODULE. " pai_100 INPUT
*----------------------------------------------------------------------*
* MODULE PBO_101 OUTPUT
*----------------------------------------------------------------------*
MODULE pbo_101 OUTPUT.
* SET PF-STATUS 'XXX'.
* SET TITLEBAR 'XXX'.
ENDMODULE. " PBO_101 INPUT
*----------------------------------------------------------------------*
* MODULE ALV_101 OUTPUT
*----------------------------------------------------------------------*
MODULE alv_101 OUTPUT.
*Check if the Custom container exists.
IF c_cont2 IS INITIAL.
*Creating container object
CREATE OBJECT c_cont2
EXPORTING
container_name = 'CDCONT'.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*creating ALV grid for interactive list
CREATE OBJECT c_alv2
EXPORTING
i_parent = c_cont2.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*ALV layout
PERFORM alv_101_layout.
*ALV fieldcatalogue
PERFORM alv_101_fieldcat.
*Sorting the output by field position
SORT it_dd03l BY position.
*ALV for display field details
CALL METHOD c_alv2->set_table_for_first_display
EXPORTING
is_layout = ty_lay2
CHANGING
it_outtab = it_dd03l[]
it_fieldcatalog = it_fcat.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDIF.
ENDMODULE. " ALV_101 OUTPUT
*&---------------------------------------------------------------------*
*& Module PAI_101 INPUT
*&---------------------------------------------------------------------*
MODULE pai_101 INPUT.
ENDMODULE. " PAI_101 INPUT
*&---------------------------------------------------------------------*
*& Form ALV_OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM alv_output .
CALL SCREEN 100.
ENDFORM. " ALV_OUTPUT
*&---------------------------------------------------------------------*
*& Form ALV_100_LAYOUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM alv_100_layout .
ty_lay1-grid_title = 'TABLES'.
ty_lay1-zebra = 'X'.
ty_lay1-no_toolbar = 'X'.
ENDFORM. " ALV_100_LAYOUT
*&---------------------------------------------------------------------*
*& Form ALV_100_FIELDCAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM alv_100_fieldcat .

CLEAR ty_fieldcat.
ty_fieldcat-row_pos = 1.
ty_fieldcat-col_pos = 1.
ty_fieldcat-fieldname = 'TABNAME'.
ty_fieldcat-tabname = 'GT_DD02L'.
ty_fieldcat-coltext = 'TableName'.
ty_fieldcat-outputlen = 10.
APPEND ty_fieldcat TO it_fieldcat.
CLEAR ty_fieldcat.
ty_fieldcat-row_pos = 1.
ty_fieldcat-col_pos = 2.
ty_fieldcat-fieldname = 'TABCLASS'.
ty_fieldcat-tabname = 'GT_DD02L'.
ty_fieldcat-coltext = 'CATEGORY'.
ty_fieldcat-outputlen = 10.
APPEND ty_fieldcat TO it_fieldcat.
CLEAR ty_fieldcat.
ty_fieldcat-row_pos = 1.
ty_fieldcat-col_pos = 3.
ty_fieldcat-fieldname = 'AS4USER'.
ty_fieldcat-tabname = 'GT_DD02L'.
ty_fieldcat-coltext = 'CREATED'.
ty_fieldcat-outputlen = 10.
APPEND ty_fieldcat TO it_fieldcat.
CLEAR ty_fieldcat.
ty_fieldcat-row_pos = 1.
ty_fieldcat-col_pos = 4.
ty_fieldcat-fieldname = 'AS4DATE'.
ty_fieldcat-tabname = 'GT_DD02L'.
ty_fieldcat-coltext = 'DATE'.
ty_fieldcat-outputlen = 10.
APPEND ty_fieldcat TO it_fieldcat.
CLEAR ty_fieldcat.
ty_fieldcat-row_pos = 1.
ty_fieldcat-col_pos = 5.
ty_fieldcat-fieldname = 'AS4TIME'.
ty_fieldcat-tabname = 'GT_DD02L'.
ty_fieldcat-coltext = 'TIME'.
ty_fieldcat-outputlen = 10.
APPEND ty_fieldcat TO it_fieldcat.
CLEAR ty_fieldcat.
ty_fieldcat-row_pos = 1.
ty_fieldcat-col_pos = 6.
ty_fieldcat-fieldname = 'CONTFLAG'.
ty_fieldcat-tabname = 'GT_DD02L'.
ty_fieldcat-coltext = 'Delivery Class'.
ty_fieldcat-outputlen = 15.
APPEND ty_fieldcat TO it_fieldcat.
CLEAR ty_fieldcat.
ENDFORM. " ALV_100_FIELDCAT
*&---------------------------------------------------------------------*
*& Form ALV_101_LAYOUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM alv_101_layout .
ty_lay2-grid_title = 'FIELDS'.
ty_lay2-zebra = 'X'.
ty_lay2-no_toolbar = 'X'.
ENDFORM. " ALV_101_LAYOUT
*&---------------------------------------------------------------------*
*& Form ALV_101_FIELDCAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM alv_101_fieldcat .
REFRESH it_fieldcat.
REFRESH it_fcat.
CLEAR ty_fcat.
ty_fcat-row_pos = 1.
ty_fcat-col_pos = 1.
ty_fcat-fieldname = 'FIELDNAME'.
ty_fcat-tabname = 'GT_DD03L'.
ty_fcat-coltext = 'Fieldname'.
ty_fcat-outputlen = 10.
APPEND ty_fcat TO it_fcat.
ty_fcat-row_pos = 1.
ty_fcat-col_pos = 2.
ty_fcat-fieldname = 'CHECKTABLE'.
ty_fcat-tabname = 'GT_DD03L'.
ty_fcat-coltext = 'CHECKTABLE'.
ty_fcat-outputlen = 10.
APPEND ty_fcat TO it_fcat.
ty_fcat-row_pos = 1.
ty_fcat-col_pos = 3.
ty_fcat-fieldname = 'KEYFLAG'.
ty_fcat-tabname = 'GT_DD03L'.
ty_fcat-coltext = 'Key Flag'.
ty_fcat-outputlen = 10.
APPEND ty_fcat TO it_fcat.
ENDFORM. " ALV_101_FIELDCAT

Selection screen

First Basic Output.


On double clicking the table name we get the fields in the table as

Use of Abstract methods from Interface


By Sravanthi

General Explanation:

This program will demonstrate the way by which a method from an interface can be used as an abstract
method for a class.

Abstract methods can only be implemented by the subclasses.

A class containing an abstract method should be abstracts itself.

Description:

This program contains interface sales with two methods, Select and Display.
Class Sales_a includes and implements methods of interface sales, declaring method Display as an
abstract method. Hence, class sales_a was also declared as an abstract class.
Class sales_a implements method sales~select , but not sales~display as this is an abstract
method.
Class sales_b is a subclass of sales_a, which defines sales~display.
In the START-OF-SELECTION block,object obj is created from class sales_b( class sales_a cannot
be instantiated, as this is an abstract class) and both the methods : sales~select and sales~dsiplay
are called.

Code Dump:

REPORT zabstract_interface NO STANDARD PAGE HEADING.

*----------------------------------------------------------------------*
* INTERFACE sales
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
INTERFACE sales .
METHODS : select IMPORTING vbelnlow TYPE vbak-vbeln
vbelnhigh TYPE vbak-vbeln,
display .
ENDINTERFACE. "sales

*----------------------------------------------------------------------*
* CLASS sales_a DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS sales_a DEFINITION ABSTRACT.
PUBLIC SECTION.
DATA tab TYPE TABLE OF vbak.
DATA wa TYPE vbak.
INTERFACES : sales ABSTRACT METHODS display.
ENDCLASS. "sales_a DEFINITION

*----------------------------------------------------------------------*
* CLASS sales_a IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS sales_a IMPLEMENTATION.
METHOD sales~select.
SELECT * FROM vbak INTO CORRESPONDING FIELDS OF TABLE tab
WHERE vbeln >= vbelnlow AND
vbeln <= vbelnhigh.
ENDMETHOD. "sales~select
ENDCLASS. "sales_a IMPLEMENTATION

*----------------------------------------------------------------------*
* CLASS sales_b DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS sales_b DEFINITION INHERITING FROM sales_a.
PUBLIC SECTION.
METHODS : sales~display REDEFINITION.
ENDCLASS. "sales_b DEFINITION
*----------------------------------------------------------------------*
* CLASS sales_b IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS sales_b IMPLEMENTATION.
METHOD : sales~display.
LOOP AT tab INTO wa.
WRITE : / wa-vbeln, wa-erdat, wa-erzet, wa-ernam.
ENDLOOP.
ENDMETHOD. ":
ENDCLASS. "sales_b IMPLEMENTATION

START-OF-SELECTION.
TABLES : vbak.
SELECT-OPTIONS s_vbeln FOR vbak-vbeln.
DATA : obj TYPE REF TO sales_b.
CREATE OBJECT obj.
obj->sales~select( EXPORTING vbelnlow = s_vbeln-low
vbelnhigh = s_vbeln-high ).
obj->sales~display( ).

Ouput:

Você também pode gostar