1

I want to define an object for BAdI implementation that will not initialize the BAdI by its name in declaration.

Example of what I don't want:

DATA l_split_badi TYPE REF TO fieb_get_bank_stmts_x.

Question 1 : I want something like:

DATA l_split_badi TYPE REF TO object.
lv_class_name = 'fieb_get_bank_stmts_x'.
create object l_split_badi type (lv_class_name).

If I declare like above, I get the following syntax error:

"L_SPLIT_BADI" is not a valid BAdI handle here.

The reason why I need to perform such implementation is, while importing the Change request to a system which has an older SAP version, the import fails because of BAdI declaration with TYPE REF TO (because that BAdI doesn't exist in the system).

My idea is with dynamic declaration to avoid the pre-check on importing the Change request.

Any idea is welcome ! Thanks to all !


EDIT Question 2 : after solution proposed by Sandra Rossi to use DATA l_split_badi TYPE REF TO cl_badi_base and GET BADI l_split_badi TYPE ('FIEB_GET_BANK_STMTS_X'), I get the same syntax error at line CALL BADI l_split_badi->split below:

CALL BADI l_split_badi->split
  EXPORTING
    i_string           = lv_cont
  IMPORTING
    et_string          = lt_xml_string
  EXCEPTIONS
    split_not_possible = 1
    wrong_format       = 2.
Suncatcher
  • 10,355
  • 10
  • 52
  • 90
  • I moved the complementary question as a distinct EDIT so that to not put the initial solution proposed out of context. Please edit or let's discuss if you don't agree. – Sandra Rossi Oct 05 '21 at 03:41

1 Answers1

3

Question 1

For BAdIs which are part of an Enhancement Spot (display the BAdI via the transaction code SE18 and you will know), you must not use CREATE OBJECT, but instead GET BADI which has a dynamic variant:

DATA badi TYPE REF TO cl_badi_base.
TRY.
    GET BADI badi TYPE ('FIEB_GET_BANK_STMTS_X')...
  CATCH cx_badi_unknown_error INTO DATA(lx).
    " The BAdI doesn't exist, handle the case...
ENDTRY.

EDIT: notice that the instance declaration is referencing CL_BADI_BASE, the super class of all BAdI definitions.

Question 2

Calling the method SPLIT statically is invalid because SPLIT doesn't exist in CL_BADI_BASE. You must use the dynamic variant of CALL BADI:

CALL BADI l_split_badi->('SPLIT')
  EXPORTING
    i_string           = lv_cont
  IMPORTING
    et_string          = lt_xml_string
  EXCEPTIONS
    split_not_possible = 1
    wrong_format       = 2.
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
  • Hi Sandra. Thanks for you answer and explanation. I extended only FILTERS part to filter for FORMAT_GROUP_X. At the end i'm still seeing that annoying error while activating saying that "l_split_badi is not a valid BAdI handle here.", I've checked in debugger both badi elements ( fixed defined/dynamic defined ) look totally same. They have main badi class, badi definition, interface and so on... I can't understand what is sitll wrong. – OrdinaryPerson Oct 03 '21 at 20:03
  • Did you reference `cl_badi_base` instead of `object`? If yes, please edit your question and paste the reproducible code in an "EDIT" section. – Sandra Rossi Oct 04 '21 at 08:18
  • Dear Sandra. I have updated all my declarations in the initial issue described above. Any ideas are welcomed! :) – OrdinaryPerson Oct 04 '21 at 11:25
  • 1
    Please don't change your original question such as making the answers incoherent. Just add it in a new "EDIT" section at the bottom of the question. Moreover, could you clarify which line has the syntax error? NB: calling the method PARSE statically is invalid because PARSE doesn't exist in `CL_BADI_BASE`, you must call it dynamically (`CALL BADI l_split_badi->('PARSE') ...`) – Sandra Rossi Oct 04 '21 at 12:43
  • Many thanks Sandra! It works now! :) As you said in prevous comment we can't access them directly because they are not defined in the super class (CL_BADI_BASE). In suggested way they are accessed based on BADI type and thus functional. No further issues :) – OrdinaryPerson Oct 04 '21 at 20:10
  • 1
    For information, I have completed my answer so that to help future visitors, and edited the question to make the question and answer coherent. – Sandra Rossi Oct 05 '21 at 03:47