Parameterized constructor in ABAP
Page 1 of 1
Parameterized constructor in ABAP
Like normal methods constructor methods can import parameters ,but since the constructor
methods cannot be called like normal methods ,so how do we pass the parameters to
constructor methods??
We can pass the parameters to a constructor methods during the object creation i.e while
using “create object” statement. A point to note a constructor cannot export any parameter.
- Code:
CLASS test DEFINITION.
PUBLIC SECTION.
METHODS: print_private_data,
CONSTRUCTOR IMPORTING num TYPE I. “constructor importing parameter
PRIVATE SECTION.
DATA: private_num TYPE I.
ENDCLASS.
CLASS test IMPLEMENTATION.
METHOD print_private_data.
WRITE:/ private_num.
ENDMETHOD.
METHOD CONSTRUCTOR. “this constructor initializes the private member with the
private_num = num. “ constructor parameter
ENDMETHOD.
ENDCLASS.
************* main program ******************************
START-OF-SELECTION.
DATA: my_obj_ref TYPE REF TO test.
CREATE OBJECT : my_obj_ref EXPORTING num = 2.
CALL METHOD my_obj_ref->print_private_data.
Uma_ABAP- Posts : 56
Join date : 2012-03-31
Similar topics
» Constructor methods ABAP Objects
» Constructor and inheritance in ABAP Objects with example
» Static and instance constructor in ABAP Objects
» Difference between Procedural ABAP and ABAP Objects
» What is ABAP Objects?
» Constructor and inheritance in ABAP Objects with example
» Static and instance constructor in ABAP Objects
» Difference between Procedural ABAP and ABAP Objects
» What is ABAP Objects?
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
Mon Aug 20, 2012 4:37 pm by Admin
» Difference between Type and Like
Thu Jun 07, 2012 2:40 pm by Admin
» How to handle table control fields in Module Pool program?
Wed May 09, 2012 2:41 am by govind
» Three tables inner join in SAP
Thu May 03, 2012 4:47 pm by Uma_ABAP
» Creating table type in ABAP
Sat Apr 28, 2012 9:03 pm by Uma_ABAP
» Creating user defined types and structures in ABAP
Sat Apr 28, 2012 8:55 pm by Uma_ABAP
» Creating Dynamic Internal Table and Dynamic Field catalog in SAP-ABAP
Fri Apr 27, 2012 11:00 am by Admin
» Copy Custom PF-Status from Standard program to Custom Program in ALV
Thu Apr 26, 2012 9:52 pm by Uma_ABAP
» Calculate/find number of working days between two dates in SAP
Tue Apr 24, 2012 2:06 pm by Uma_ABAP