SAP Virtual/Onsite Trainings

Document Categories:

What's New?

Contribute?

Sample Specs

What's Hot?

Web Dynpro for ABAP Tutorials 


Join the Mailing List
Enter name and email address below:
Name:
Email:
Subscribe  Unsubscribe 

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~
selectEXPORTING vbelnlow = s_vbeln-low
                                           vbelnhigh =  s_vbeln-high ).
  obj->sales~display( ).
 

Ouput:  

Please send us your feedback/suggestions at webmaster@SAPTechnical.COM 

HomeContribute About Us Privacy Terms Of Use • Disclaimer • SafeCompanies: Advertise on SAPTechnical.COM | Post JobContact Us  

Graphic Design by Round the Bend Wizards

footer image footer image