3
9/23/2015 Working with constructors (Global Class) http://www.saptechnical.com/Tutorials/OOPS/Constructor/Index.htm 1/3 Search Home Trainings Quiz Tips Tutorials Functional Cert Q's Interview Q's Jobs Testimonials Advertise Contact Us SAP Virtual/Onsite Trainings Document Categories: ABAP TM Adobe Forms ABAPHR ALE & IDocs ALV BAPI BASIS BSP Business Objects Business Workflow CRM NEW LSMW SAP Script/Smart Forms BI/BW eXchange Infrastructure (XI) Enterprise Portals (EP) eCATT Object Oriented Programming SAP Query Userexits/BADIs WebDynpro for Java/ABAP TM Others What's New? ABAP Test Cockpit HOT SAP ABAP Pragmas Understanding SE32 (ABAP Text Element Maintenance) Creating an IDoc File on SAP Application Server Understanding “Advance with dialog” option of SAP Workflow SAP Workflow Scenario: Maintenance Notification Approval Enhancements to a standard class Working with Floating Field in Adobe Forms Inserting data from Internal Table into the step “Send Mail” Display GL Account long text using enhancement framework Differences between polymorphism in JAVA and ABAP Passing multiline parameters from an ABAP Class event to a Workflow container Concept of Reevaluate agents for active work items in SAP Workflow Dynamic creation of component usage in ABAP WebDynpro Adobe Forms: Display symbols like copyright and others Deactivate Hold functionality in Purchase order (ME21N) Quiz on OOABAP Add fields in FBL5N using BADIs Tutorial on Wide casting Defining a Range in Module Pool Program Copy fields from one structure/table into another structure/table Side Panel Usage in NWBC Contribute? Sample Specs Working with constructors (Global Class) By Sravanthi 1. Constructors are special methods that cannot be called using CALL METHOD. Instead, they are called automatically by the system to set the starting state of a new object or class. 2. Constructors are methods with a predefined name. To use them, you must declare them explicitly in the class. 3. There are two types of constructors Instance constructors and Static constructors. The Instance constructor of a class is the predefined instance method CONSTRUCTOR. The constructor's signature can have only importing parameters or exceptions. Instance Constructor is a special instance method can access the Instance Variables and Static Variables. This method is used to set the default values in a class. The Static constructor of a class is the predefined static method CLASS_CONSTRUCTOR. The constructor's signature cannot have importing parameters or exceptions. The static constructor is as special static method can access the static variables. These are used to set default values for the global attributes irrespective of instances. Multiple Instance and Static Constructors cannot be used in one class. Creating the Instance Constructor and Static Constructor using SE24 (Global class) Step1 : Go to SE24 Create Global Class ZCONSTRUCTOR_SALES Step2 : Select the Class and Click on Continue. Step3 : Continue with the default settings Step4 : Go to Methods Create Methods.

Working With Constructors (Global Class)

Embed Size (px)

DESCRIPTION

constructor

Citation preview

Page 1: Working With Constructors (Global Class)

9/23/2015 Working with constructors (Global Class)

http://www.saptechnical.com/Tutorials/OOPS/Constructor/Index.htm 1/3

  Search

Home   •  Tra inings  •  Quiz   •  Tips  •  Tutoria ls  •  Functiona l   •  Cert Q's  •   Inte rview  Q's  •  Jobs  •  Testimonia ls  •  Adve rtise   •  Contact Us

SAP Virtual/Onsite Trainings

Document Categories:

ABAPTM

Adobe FormsABAP­HRALE & IDocsALVBAPIBASISBSPBusiness Objects Business WorkflowCRM NEWLSMWSAP Script/Smart FormsBI/BWeXchange Infrastructure (XI)Enterprise Portals (EP)eCATTObject Oriented ProgrammingSAP QueryUserexits/BADIsWebDynpro for Java/ABAPTM

Others

What's New?

ABAP Test Cockpit HOTSAP ABAP PragmasUnderstanding SE32 (ABAP TextElement Maintenance)Creating  an  IDoc  File  on  SAPApplication ServerUnderstanding  “Advance  withdialog” option of SAP WorkflowSAP  Workflow  Scenario:Maintenance  NotificationApprovalEnhancements  to  a  standardclassWorking  with  Floating  Field  inAdobe FormsInserting  data  from  InternalTable into the step “Send Mail”Display  GL  Account  long  textusing enhancement frameworkDifferences  betweenpolymorphism  in  JAVA  andABAPPassing  multiline  parametersfrom  an  ABAP  Class  event  to  aWorkflow containerConcept  of  Re­evaluate  agentsfor  active  work  items  in  SAPWorkflowDynamic creation of componentusage in ABAP WebDynproAdobe  Forms:  Display  symbolslike copyright and othersDeactivate  Hold  functionality  inPurchase order (ME21N)Quiz on OOABAPAdd fields in FBL5N using BADIsTutorial on Wide castingDefining  a  Range  in  ModulePool ProgramCopy  fields  from  onestructure/table  into  anotherstructure/tableSide Panel Usage in NWBC

Contribute?

Sample Specs

Working with constructors (Global Class)

By Sravanthi

1.     Constructors are special methods that cannot be called using CALL METHOD. Instead, they are calledautomatically by the system to set the starting state of a new object or class.

2.     Constructors are methods with a predefined name. To use them, you must declare them explicitly in theclass.

3.     There are two types of constructors ­ Instance constructors and Static constructors.  

         The Instance constructor of a class is the predefined instance method CONSTRUCTOR.

         The constructor's signature can have only importing parameters or exceptions.

         Instance Constructor  is a special  instance method can access the Instance Variables and StaticVariables. 

         This method is used to set the default values in a class.         

         The Static constructor of a class is the predefined static method CLASS_CONSTRUCTOR.

         The constructor's signature cannot have importing   parameters or exceptions.         The static constructor is as special static method can access the static variables.         These are used to set default values for the global attributes irrespective of instances.

         Multiple Instance and Static Constructors cannot be used in one class.  

Creating the Instance Constructor and Static Constructor using SE24 (Global class)

Step1: Go to SE24  Create Global Class ZCONSTRUCTOR_SALES

  

Step2: Select the Class and Click on Continue.

  

Step3: Continue with the default settings

  

Step4: Go to Methods  Create Methods.

Page 2: Working With Constructors (Global Class)

9/23/2015 Working with constructors (Global Class)

http://www.saptechnical.com/Tutorials/OOPS/Constructor/Index.htm 2/3

What's Hot?

Web Dynpro for ABAP Tutorials 

Join the Mailing List

Enter name and email address below :

Name: 

Email: 

Subscribe   Unsubscribe 

GO

 

Step5: Constructor Method can be created 2 ways.

1)     Go to Menu  Edit  Create Constructor

2)     Click on Constructor as shown below  

 

Step6: As soon click on Constructor  Constructor Method is automatically defaulted in the Methods.

This method is used o initial the values for the object

 

Step7: Create another method Select to fetch the data from the VBAK table

 

Step8: Select the Constructor Method  Select the Parameters and Create the Parameter

 

Step9: The parameter IM_VBELN is used to importing into Constructor Method. Used to initialize the value

 

Step10: For the Constructor, parameter type is always importing. No other Parameter type can be assigned

Page 3: Working With Constructors (Global Class)

9/23/2015 Working with constructors (Global Class)

http://www.saptechnical.com/Tutorials/OOPS/Constructor/Index.htm 3/3

  

Step11: Go to Type Tab  Create Structure ty_vbak and Visibility (Public)

 

Step12: Click on Direct Type Entry

 

Step13: To declare the Structure (with required fields) and Table

Click here to continue...

Please send us your feedback/suggestions at [email protected] 

Home • Contribute • About Us • Privacy • Terms Of Use • Disclaimer • Safe • Companies: Advertise on SAPTechnical.COM | Post Job • Contact Us  

© SAPTechnical.COM. All rights reserved.All product names are trademarks of their respective companies. SAPTechnical.COM is in no way affi l iated with SAP AG.

SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver, and and any other SAP trademarks are registered trademarks of SAP AG in Germany and in several other countries.Every effort is made to ensure content integrity. Use information on this site at your own risk.

Graphic Design by Round the Bend Wizards