Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Constrructor method in implementation class

Former Member
0 Likes
1,011

Can we write the method constructor for a BADI implementation class?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
779

Hi

Theorically you can do it, but why?

Max

4 REPLIES 4
Read only

Former Member
0 Likes
780

Hi

Theorically you can do it, but why?

Max

Read only

0 Likes
779

My requirement is to write a seperate prg (with no selection screen) for doing a batch job. So I was trying this peice of code :-

 

REPORT  zur_eng_masterdelete.

*DATA: g_report TYPE REF TO ZCL_IM_IMPL_ENG_CHG.
CREATE OBJECT g_report 
  EXPORTING
    if_repid = sy-repid .

IF g_report ->auth_check( ) = 'X'.
  CALL METHOD g_report ->get_data( ).
ENDIF.

when I try to activate this code, it said the class has no constructor defined.

Read only

0 Likes
779

Hi

*DATA: g_report TYPE REF TO ZCL_IM_IMPL_ENG_CHG.
CREATE OBJECT g_report 
  EXPORTING
    if_repid = sy-repid .

I don't know the class ZCL_IM_IMPL_ENG_CHG, and I don't know which interface is the base for that class.

Anyway if some data is transfered while the object is being created, it means the class of the object has to have a constructor method.

Now the question is why you create the object by the following code?

CREATE OBJECT g_report 
  EXPORTING
    if_repid = sy-repid .

Max

Read only

alex_cook
Active Participant
0 Likes
779

Howdy,

You could just split it into two calls by creating a method eg set_syrepid on the badi implementing class:



create object g_report.

g_report->set_syrepid( exporting i_repid = sy-repid ).

" Do the rest of the code

Edit: Having said that, it's just as easy to create a constructor on the implementing class.

Cheers

Alex