This document provides steps to write a first SAP class using transaction code SE24 and ABAP programming. It describes how to create a simple class with an attribute, save the class, and then use it in an ABAP program by declaring class reference variables, creating class objects, and accessing the class attribute. It also shows how to create and use multiple objects of the same class.
This document provides steps to write a first SAP class using transaction code SE24 and ABAP programming. It describes how to create a simple class with an attribute, save the class, and then use it in an ABAP program by declaring class reference variables, creating class objects, and accessing the class attribute. It also shows how to create and use multiple objects of the same class.
This document provides steps to write a first SAP class using transaction code SE24 and ABAP programming. It describes how to create a simple class with an attribute, save the class, and then use it in an ABAP program by declaring class reference variables, creating class objects, and accessing the class attribute. It also shows how to create and use multiple objects of the same class.
This document provides steps to write a first SAP class using transaction code SE24 and ABAP programming. It describes how to create a simple class with an attribute, save the class, and then use it in an ABAP program by declaring class reference variables, creating class objects, and accessing the class attribute. It also shows how to create and use multiple objects of the same class.
Download as DOCX, PDF, TXT or read online from Scribd
Download as docx, pdf, or txt
You are on page 1of 3
Write First SAP class
Last Updated: August 9th 2017 by Ashok Kumar Reddy
Writing first SAP Class using transaction code SE24 with SAP ABAP Programming
A+ A-
Create a simple class for using attributes
Go to SE24( Class Builder).
Give the class name ZCL_SAPN1 and create.
Provide short description, save.
Save it in a Local Object or in your test package.
Go to attributes tab and define an attribute as below.
AV_NAME-INSTANCE-PUBLIC-TYPE-CHAR25. Save and Activate.
Now class is created, we have to use this in our program.
Create a ABAP program in SE38 and add below code
DATA : LR_CLASS TYPE REF TO ZCL_SAPN1 . "STEP1--WE DECLARE CLASSES USING
REF TO BECAUSE THEY ARE OBJECTS CREATE OBJECT LR_CLASS. "STEP2--CREATE OBJECT FOR THE CLASS *CALL CLASS COMPONENT WITH THE INSTANCE LR_CLASS->AV_NAME = 'ATTRIBUTE NAME'. "USE CLASS COMPONENTS WRITE:/ LR_CLASS->AV_NAME. *OUT PUT WILL BE 'ATTRIBUTE NAME' Using multiple objects of class
DATA : LR_CLASS1 TYPE REF TO ZCL_SAPN1 . "Declare first class object
DATA : LR_CLASS2 TYPE REF TO ZCL_SAPN1 . "Declare second class object
CREATE OBJECT LR_CLASS1. "Create a first object
CREATE OBJECT LR_CLASS2. "Create a second object *CALL CLASS COMPONENT WITH THE INSTANCE LR_CLASS1->AV_NAME = 'FIRST ATTRIBUTE NAME'. "Assign value to first object
LR_CLASS2->AV_NAME = 'SECOND ATTRIBUTE NAME'. "Assign value to second
object WRITE:/ LR_CLASS1->AV_NAME. "OUT PUT WILL BE 'FIRST ATTRIBUTE NAME'
WRITE:/ LR_CLASS2->AV_NAME. "OUT PUT WILL BE 'SECOND ATTRIBUTE NAME'