case study global class
DESCRIPTION
Case Study Global ClassTRANSCRIPT
Case Study: OOABAP-Global Class.
Business Requirement:
To create a global class and display the customer details using global class.
To have a very simple scenario on this, Lets enter customer numbers on selection screen.
Based on the input ,The customer details will be displayed.
Solution:
Go to se24 Tcode
Provide the global class name as ZCL_GLOBAL_CLASS.
Click on the Create Button.
Provide the Description.
Press Save button .Then we can view the scree like this
Provide method name as GET_DATA.
Goto Attributes and provide the values.
In Above screen ZSTR_KNA1 is structure
and ZTT_KNA1 is table type.
Go to methods tab and double click on the method GET_DATA and provide the bellow logic.
method GET_DATA .
SELECT KUNNR
LAND1
NAME1
ORT01
FROM KNA1 INTO TABLE IT_KNA1
WHERE KUNNR BETWEEN S_KUNNR_LOW AND S_KUNNR_HIGH.
endmethod.
Save Check and Activate .
Provide another method as DISPLAY_DATA.
Double click on the DISPLAY_DATA and provide the bellow logic.
method DISPLAY_DATA .
LOOP AT IT_KNA1 INTO WA_KNA1.
WRITE:/ WA_KNA1-KUNNR,
WA_KNA1-LAND1,
WA_KNA1-NAME1,
WA_KNA1-ORT01.
ENDLOOP.
endmethod.
Save Check and Activate .
Go to SE38 and create program with name ZGLOBAL_CLASS.
Provide the description.
Provide the bellow logic.
DATA:KNA1 TYPE KNA1.
*Select Options
SELECT-OPTIONS:S_KUNNR FOR KNA1-KUNNR.
*Declaration of object reference variable
DATA:OBJ TYPE REF TO ZCL_GLOBAL_CLASS.
START-OF-SELECTION.
*Create Object
CREATE OBJECT OBJ.
*Provide attribute values
OBJ->S_KUNNR_LOW = S_KUNNR-LOW.
OBJ->S_KUNNR_HIGH = S_KUNNR-HIGH.
*Calling the method to get data.
CALL METHOD OBJ->GET_DATA.
*Calling the method to display data.
CALL METHOD OBJ->DISPLAY_DATA.
Save Check and Activate .
Execute the program.
Provide the customer numbers in selection screen.
Execute it.
Output:
Author: NageswarPage 1101/30/2011