Apnuguyana.com

FINANCE NEWS, Global Trends in Technology, Business and All Information.

Abap Programming Basics One

Good thing nearly ABAP is that yous dont take a seperate IDE  or to cofigure 100s of things similar what we demand to make for Java or .Net for development  every bit the coding is done direct inwards the SAP environment . But this is an event besides  because sometimes getting concur of SAP organization is hard .
Welcome to the globe of SAP
Polymorphism: In simple price when yous over write approximately functionality it’s called polymorphism. In polymorphism, y'all can inherit methods from the raise course too tin can modify it past implementing it once again (which is naught simply implementation of the inherited method).
We will come across forthwith how we tin attain this inward ABAP ;
i. Go to transaction SE24 too build a form together with bring up whatsoever similar this ane: ZCL_POLYMORPHISM_SUPER
Good thing about ABAP is that you dont need a seperate IDE  or to cofigure  ABAP programming basics 1
Please remeber non to cheque the Final Checkbox. If you cheque this bank check box, any other class or sub-grade cannot inherit from this form.
ii. Go to Methods Tab too make a method under at that place:
Good thing about ABAP is that you dont need a seperate IDE  or to cofigure  ABAP programming basics 1
iii. Put cursor on Select_Method method in addition to press parameters button to get in parameters as shown:
Good thing about ABAP is that you dont need a seperate IDE  or to cofigure  ABAP programming basics 1
iv. Then click on the Methods alongside dorsum arrow push button too double click on select_method in addition to enter the required code equally shown:
Good thing about ABAP is that you dont need a seperate IDE  or to cofigure  ABAP programming basics 1
five. Put cursor on Display_Method method too press parameters push to move into parameters equally shown:
Good thing about ABAP is that you dont need a seperate IDE  or to cofigure  ABAP programming basics 1
six. Then get back to Methods past pressing the methods button, double click on the Display_Method and go in the required code as shown:
Good thing about ABAP is that you dont need a seperate IDE  or to cofigure  ABAP programming basics 1
We are done creating the Super Class. Now allow’second get together with create the Sub-Class.
Go to t-code se24 together with create the form: ZCL_POLYMORPHISM_SUB
Go to properties tab in addition to press the SuperClass button together with define the super course advert nosotros created:
Good thing about ABAP is that you dont need a seperate IDE  or to cofigure  ABAP programming basics 1   
When we relieve the course and so the methods along alongside parameters in addition to logic are inherited inward the sub course where the colour of the inherited methods changes to bluish colour. We cannot modify the methods,parameters and attributes of inherited course.
To redefine the existing functionality of the inherited methdod, nosotros will place cursor on that method too press the Redifne button equally shown:
Good thing about ABAP is that you dont need a seperate IDE  or to cofigure  ABAP programming basics 1
Enhance the existing method by adding any write argument or anything similar shown:
   CALL METHOD SUPER->SELECT_METHOD
  EXPORTING
    P_CARRID   =  P_CARRID
  IMPORTING
    WA_SFLIGHT = WA_SFLIGHT     .
choose single from sflights into wa_sflights where carrid = p_carrid.
Good thing about ABAP is that you dont need a seperate IDE  or to cofigure  ABAP programming basics 1
Create another method display_method1 with the exporting parameter wa_sflights, and then double click on the method and implement the logic.
Good thing about ABAP is that you dont need a seperate IDE  or to cofigure  ABAP programming basics 1
Create a programme in se38 too furnish the logic:
*Provide Object for Sub Class
data:obj1 type ref to ZCL_POLYMORPHISM_SUB.
*Provide Parameters
parameters: v_carrid type sflight-carrid.
*Provide Data Objects
information: wa_sflight type sflight.*     Wa1_sflights type sflights.
*Create Object caseCREATE OBJECT OBJ1.
CALL METHOD obj1->SELECT_METHOD
  
EXPORTING
    P_CARRID   = v_carrid
  
IMPORTING
    WA_SFLIGHT = wa_sflight
    .
write:/ wa_sflight-CARRID,
        wa_sflight-CONNID.
WRITE: / obj1->wa_sflights-CARRID.
We are done amongst Polymorphism hither.
Lets become together with run across what is Encapsulation.
Encapsulation : Wrapping upward of data into single unit. Or, restriction on visibility of attributes in addition to methods in the class. We take 3 levels of visibility:
     ane. Private
     two. Protected
     three. Public
Methods or attributes defined every bit private are solely visible as well as available to the form inwards which they are defined.
Methods or attributes defined equally protected are visible to the course defined in together with to the grade which inherits from the course they are defined inward.
Similarly the methods or attributes defined equally world are available to all.
Lets start with an example again:
SE24 -> Create a Super form alongside name: ZCL_ENCAPSULATION
Good thing about ABAP is that you dont need a seperate IDE  or to cofigure  ABAP programming basics 1
Good thing about ABAP is that you dont need a seperate IDE  or to cofigure  ABAP programming basics 1
Create a Subclass ZCL_ENCAPSULATION_SUB by assigning super class
Good thing about ABAP is that you dont need a seperate IDE  or to cofigure  ABAP programming basics 1
Now if yous become as well as expect inwards the attribute department, you lot volition only live able to meet the Public in addition to Protected attribute. Private attaribute defined above is non visible equally shown:
Good thing about ABAP is that you dont need a seperate IDE  or to cofigure  ABAP programming basics 1
Similarly y'all volition live able to run across the methods of the super course just only the ane which were declared equally public together with protected every bit shown:
Good thing about ABAP is that you dont need a seperate IDE  or to cofigure  ABAP programming basics 1
THIS IS JUST A HIGH LEVEL VIEW ON HOW WE CAN SEE THE THINGS IN OO ABAP. DETAILED LEVEL WILL BE EXPLAINED LATER.
Now as we are done with Encapsulation, lets move on to Inheritance.
Inheritance: This can be defined from the give-and-take itself. That is to inherit properties from some raise class. Anything inherited volition exclusively live cisible if that is declared equally public or protected inward the super form.
Normally the OBJECT ORIENTED ABAp does not support the many to 1 inheritance, only this is made possible past using interfaces.
Interface is besides a sort of form which incorporate the definitions alone. Implementation of those defined methods will have function in the deriving classes only.
Lets goto SE24 and make as well as interface amongst mention ZIF_INTERFACE.
Create a method SELECT_METHOD too define parameters for it equally shown:
Good thing about ABAP is that you dont need a seperate IDE  or to cofigure  ABAP programming basics 1
Now nosotros will create a course named ZCL_INTERFACE too inward the Interface tab of that grade will position our interface refer equally shown:
Good thing about ABAP is that you dont need a seperate IDE  or to cofigure  ABAP programming basics 1
The method will automatically be generated in the Methods tab equally shown:
Good thing about ABAP is that you dont need a seperate IDE  or to cofigure  ABAP programming basics 1
Double click on this method and write some logic similar:
Good thing about ABAP is that you dont need a seperate IDE  or to cofigure  ABAP programming basics 1
Now lets make an ABAP program too write the next code inward that only to sympathize;
  DATA:sflight TYPE sflight,
     wa_sflight TYPE sflight,
     it_sflight TYPE z_sflight.
*providing data objects
DATA:obj TYPE REF TO zcl_interface.
*providing choice-screen
SELECT-OPTIONS:s_carrid FOR sflight-carrid.
START-OF-SELECTION.
  CREATE OBJECT obj.
  CALL METHOD obj->zif_interface select_method
    EXPORTING
      p_carrid_low  = s_carrid-depression
      p_carrid_high = s_carrid-high
    IMPORTING
      wa_sflight    = wa_sflight
      it_sflight    = it_sflight.
  DELETE ADJACENT DUPLICATES FROM it_sflight COMPARING carrid.
  LOOP AT it_sflight INTO wa_sflight.
    WRITE:/ wa_sflight-carrid,wa_sflight-connid,sflight-seatsmax.
  ENDLOOP.
The output come upsecond every bit
Good thing about ABAP is that you dont need a seperate IDE  or to cofigure  ABAP programming basics 1
So this is all, If I go approximately time, ane volition come up up amongst ane more than document explaining something else.

Post a Comment

Copyright © 2021