Wednesday, December 18, 2013

Creation of Global Class and Using it in Local Program

OOABAP-Tutorials-with-examples-4
OOABAP Tutorials-4 Creation of Global Class and Using it in Local Program, welcome to SAP ABAP Interview Questions. 



OOABAP Tutorials with Examples



sapabapiq.com presenting fourth post in the series of Object Oriented Programming Tutorials. This series of post very helpful for the novice ABAP programmers to learn OOABAP easily with topic wise examples.

Before going to read this article please read previous posts in this series of OOABAP tutorials.









Creation of Global Class and Using it in Local Program




 

Creation of Global class and using it in a local program




Theme


This example will show you how to create a class globally and use it in your local program



Program Description

There is a demand to create a global class which will furnish a list of materials along with their descriptions based on the material type.


Global class ZGET_MATERIALS will be created. Method LIST_MATERIALS will belong to this class which will take material type as an input and will furnish a list of material codes and their descriptions belonging to that material type.


Steps


Follow the steps outlined below to perform the task



Step 1. Create the class from SE24 TCode


abap-class-builder-screen


Go to transaction SE24.

*  Enter the name of the global class you want to create, with ‘Y’ or ‘Z’ at the beginning.

*  Press Create pushbutton.


abap-object-type


A dialog window shown above will appear. Check the radio button : Class.

*  Press Enter.

abap-class-creation


Another dialog window shown above will appear. Enter the description for the class.

*  Select from the Instantiation list box whether you want to create the class as PUBLIC/PROTECTED/PRIVATE/ABSTRACT.

*  Check the radio button for Usual ABAP Class.

*  Check the check box for Final.

*  Press Save push button.


abap-object-directory-entry


Enter the package name or save it as Local object.





Step 2 : Create the method : LIST_MATERIALS

abap-method-creation


Go to the tab-page : Methods.

*  Enter the details for the method – mention name, type of method(instance/static), in which visibility section the method will reside and a short description of the method.

*  Check –off/un check the check box to ensure that the method will be implemented.

sap-abap-methods-creation


Click the pushbutton for Parameters to navigate to the screen to enter parameters for the method.

abap-method-parameters


There will be one importing parameter : L_MTART and one exporting internal table : MATERIAL_LIST. Create entries for them as shown above.


abap-method-exceptions


Click the pushbutton : Exceptions to make entry for Exceptions to be raised by the method.

abap-exception-description


Enter the name and description for the exception .

Then, check and activate the class.



 

Step 3: Write code for method implementation

abap-method-exception-description


Click on the pushbutton : Code( blue colored button) to implement the method.

abap-method-implementation


An ABAP Editor will open up. Write the logic for code implementation.
Then, check and activate the code.

Your job of creating a global class is complete!!!






Step 4 : Use the global class created by you in a local program

REPORT  YSUBDEL.

TYPES : BEGIN OF typ_mat ,
          matnr LIKE mara-matnr ,
          maktg LIKE makt-maktg ,
       END OF typ_mat .

DATA : it_mat TYPE STANDARD TABLE OF typ_mat ,
        x_mat LIKE LINE OF it_mat.

PARAMETERS : p_mtart LIKE mara-mtart OBLIGATORY.

  START-OF-SELECTION.
* Create object from the global class
   DATA : oref TYPE REF TO zget_materials.
   CREATE OBJECT oref.
* Call the method to get list of material code and name
   CALL METHOD oref->list_materials
        EXPORTING l_mtart       = p_mtart
        IMPORTING material_list = it_mat
      EXCEPTIONS
        material_not_found = 2.

    if sy-subrc ne 0.
     write:/5 'Material not found'.
    else.
* Display the list
     loop at it_mat into x_mat.
      write:/5 x_mat-matnr ,
               x_mat-maktg.
     endloop.
    endif.



Output

Compile and run the program. There will be a parameter for material type in the selection screen. Enter a valid value and get the list of material codes and descriptions.


"You found the information helpful and want to say thanks? Your donation is enough to inspire us to do more. Thanks a bunch!"

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Categories

ABAP (1) ABAP Interview Questions (112) ABAP Open SQL Statements (1) ABAP Syntax Rules (6) ABAP WORKBENCH (2) ABAP-Interview-Questions (52) ALE IDOC (6) ALE IDOC Interview Questions (6) ale-idoc (6) ALE-IDOC-Interview-Questions (19) ALV Interview Questions (5) ALV-Interview-Questions (22) BADI (2) BAPI (1) BAPI Interview Questions (1) BAPI-Interview-Questions (14) BDC (6) BDC Interview Questions (6) BDC-Interview-Questions (9) big data (2) big data interview questions (1) Classical Reports Interview Question (3) Classical-Reports-Interview-Questions (22) Conditional Statements (1) Cross Applications (3) Cross-Applications (14) Data Dictionary (22) Data Type Questins (1) Data types (1) Data-Dictionary (48) Data-Type-Questins (6) Dialog programming (5) Dialog Programming Interview Questions (4) Dialog-Programming (30) DOMAIN Interview Questions (1) Domain-Interview-Questions (8) Function Module (2) hadoop (2) hadoop interview questions (2) hdfs (1) IDoc Tutorials (6) Interactive Report Interview Questions (4) Interactive-Reports-Interview-Questions (22) Internal Tables (1) interview questions (1) Lock Object Interview Questions (1) Lock-Objects-Interview-Questions (10) Logical Database (1) Modularization Interview Questions (4) Modularization-Interview-Questions (25) Module Pool Programming (5) Module-Pool-Programming (39) modules in sap (1) Object Oriented ABAP (19) Object Oriented ABAP Interview Questions (15) object-oriented-abap (2) Object-Oriented-ABAP-Interview-Questions (34) OOABAP (9) Reports (14) Reports Interview Questions (9) Reports-Interview-Questions (19) RFC (1) RFC Interview Questions (1) RFC-Interview-Questions (14) RICEF (1) RICEF Objects (1) SAP (4) SAP ABAP (4) SAP ABAP Interview Questions (42) SAP ABAP Introduction (46) SAP ABAP Message Types (2) SAP BADI Interview Questions (2) SAP Basics (71) SAP Books (2) SAP Certification (1) SAP CONSULTANTS (5) SAP CRM (1) SAP ENHANCEMENTS (3) SAP EXITS (2) SAP EXITS ( SAP ENHANCEMENTS ) Interview Questions (1) SAP Free Books (1) SAP HR (2) SAP Lock Object (1) sap modules (2) SAP Open SQL Statements (1) SAP R/3 Architecture (4) SAP Search help (1) SAP Smartforms (1) SAP Smartforms Interview Questions (2) SAP Tables (5) SAP Tcodes (10) SAP Views (1) SAP Webdynpro ABAP (12) SAP Work Processors (2) SAP Workflow (3) SAP-BADI-Interview-Questions (11) SAP-Enhancements (39) SAP-Exits (39) SAP-Exits-Enhancements-Interview Questions (3) SAP-HANA (1) SAP-HANA-Interview-Questions (1) SAP-Smartforms-Interview-Questions (2) SAP-Workflow (3) Scripts (3) Scripts Interview Questions (2) Scripts-Interview-Questions (32) Search Help Interview Questions (1) Search-Help-Interview-Questions (9) Smartforms (1) Table Maintenance Generator (1) Table-Maintenance-Generator (4) Tables in SAP (2) Tables Interview Questions (3) Tables-Interview-Questions (3) Type Group Interview Questions (1) Type-Group-Interview-Questions (7) Variable Declaration (1) Views Interview Questions (1) Views-Interview-Questions (5) Webdynpro (12) what is big data (1)

Protected Blog

 
This blog is not affiliated to SAP AG |SAP is trademark of SAP AG |The information collected from various sources use information with your own risk.