Skip to Content

Instance updates attribute of different calling instance

The issue is happening within the context of Badi development for SAP BPC.

In the method of the Badi where we can develop our code, we use an exising

standard SAP class (which is CL_UJO_WRITE_BACK) to save data to the

database. We create an instance of that class, and call a method passing some

parameters. Within that method an attribute of the class is updated. Somehow, it

also updates the attribute of the calling instance.

I will explain this again schematically :

Class X , Instance Xa

Instance Xa holds attribute y

Instance Xa calls method which calls a Badi.

In the Badi method, Instance Xb is created of

the same class. Attribute y is updated in method of

Instance Xb. Somehow, it also updates attribute y

of Instance Xa.

Is this the normal behaviour of Abap objects ?

Add comment
10|10000 characters needed characters exceeded

  • Hi Vadim,


    this is a complicated business logic which is already live for a period of time. I cannot explain this on this forum,

    and it is not really relevant for this issue. The problem arises now because the question has come that the

    saved data need to be audited, and because of this issue the data is not saved in the audit log. It is an ABAP

    technical issue, that's why I posted it in the ABAP forum.

  • I am using the write back badi. Because I am calling the write back method of that class, an attribute of the

    standard program is updated (and as a consequence the audit log is not updated, I was able to see this

    in debugging). I assume that a Badi should never update class attributes of the standard

    SAP program. I now wonder whether this could be a bug in the kernel.

  • Try what I've suggested in my answer, then get back to us.

  • Follow
  • Get RSS Feed

4 Answers

  • Best Answer
    Aug 09, 2018 at 10:28 AM

    Works as documented.

    https://help.sap.com/doc/abapdocu_752_index_htm/7.52/en-US/abapprivate.htm?file=abapprivate.htm

    The smallest encapsulation unit of ABAP Objects is the class, not the object.

    Add comment
    10|10000 characters needed characters exceeded

  • Aug 08, 2018 at 09:56 AM

    This would be easier to answer if you posted the actual code. Use the "code" button in the editor.

    Run in debugger and look at the instance numbers of Xa and Xb. Are they the same?

    Add comment
    10|10000 characters needed characters exceeded

  • Aug 08, 2018 at 04:41 PM

    "this is a complicated business logic which is already live for a period of time. I cannot explain this on this forum" - top secret! :)

    I have written write back badi many times for different systems and never have the issues like you have.

    But I never set ls_wb_param-update_audit = abap_false. and disable work status check in my badi - to my mind it's a bad practice in general.

    All data written to the cube (by input form, script logic, badi etc) has to be reflected in audit log. Same for work status lock.

    Add comment
    10|10000 characters needed characters exceeded

  • Aug 09, 2018 at 05:51 AM
    -1

    Yes, unfortunately this is a normal behaviour of ABAP Objects.

    A private attribute of an instance of class X can be changed by every other Instance of class X.

    Add comment
    10|10000 characters needed characters exceeded

    • A private attribute of an instance of class X can be changed by every other Instance of class X.

      Ahh, now i see what you meant by the statement. Sorry for the misunderstanding.

      CLASS lcl_x DEFINITION CREATE PUBLIC.
        PUBLIC SECTION.
          DATA state TYPE string READ-ONLY.
          METHODS:
            constructor,
            main.
        PROTECTED SECTION.
        PRIVATE SECTION.
          DATA: output TYPE REF TO if_demo_output.
          METHODS: call_badi.
      ENDCLASS.
      
      CLASS lcl_x IMPLEMENTATION.
        METHOD constructor.
          me->output  = cl_demo_output=>new( ).
          me->state   = |Initial State|.
          me->output->write( |State of the current: "{ me->state }"|  ).
        ENDMETHOD.
        METHOD call_badi.
          DATA(xb)  = NEW lcl_x( ).
          xb->state = |Changed in the BAdI|.
          me->output->write( |State of the new instance: "{ xb->state }"|  ).
          
          ASSERT me->state <> xb->state. " <<< This is what i meant by the violation >>> 
        ENDMETHOD.
        METHOD main.
          me->call_badi( ).
          me->output->write( |Current State: "{ me->state }"|  ).
          me->output->display( ).
        ENDMETHOD.
      ENDCLASS.
      START-OF-SELECTION.
        NEW lcl_x( )->main( ).
      

      When i said,

      It is not true, unless:

      • the attribute is static, or
      • the instances of the class X are the same, i.e., class X is a singleton!

      This is what i meant -

      ASSERT me->state <> xb->state.

      I hope this clarifies the misunderstanding.

      Anyway i found another interesting thread -> https://archive.sap.com/discussions/thread/3482419