Application Development 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: 

How to synchronize concurrent access to static data in ABAP Objects

Former Member
0 Kudos

Hi,

1) First of all I mwould like to know the scope of static (class-data) data of an ABAP Objects Class: If changing a static data variable is that change visible to all concurrent processes in the same Application Server?

2) If that is the case. How can concurrent access to such data (that can be shared between many processes) be controlled. In C one could use semaphores and in Java Synchronized methods and the monitor concept. But what controls are available in ABAP for controlling concurrent access to in-memory data?

Many thanks for your help!

Regards,

Christian

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

I believe the scope of the static data of an ABAP object is only for that session..

Check this definition.

The contents of static attributes define the state of the class that is valid for all instances of the class. Static attributes exist once for each class. You declare them using the CLASS-DATA statement. They are accessible for the entire runtime of the class.

Thanks,

Naren

8 REPLIES 8

Former Member
0 Kudos

Hi,

I believe the scope of the static data of an ABAP object is only for that session..

Check this definition.

The contents of static attributes define the state of the class that is valid for all instances of the class. Static attributes exist once for each class. You declare them using the CLASS-DATA statement. They are accessible for the entire runtime of the class.

Thanks,

Naren

0 Kudos

I'm thinking the same, but I really am not sure.

I think the functionality that you are referring to would be closeer to shared objects.

Regards,

Rich Heilman

0 Kudos

Ok. Thanks I obviously have to investigate this a bit. But what is shared object - how can these be used?

/ Christian

0 Kudos

Christian, here is some lite reading on shared objects.

http://help.sap.com/saphelp_nw2004s/helpdata/en/c5/85634e53d422409f0975aa9a551297/frameset.htm

Regards,

Rich Heilman

0 Kudos

Hello Christian

Have a look at the Weblog by Thomas Jung on

<a href="/people/thomas.jung3/blog/2005/05/15/abap-46c-to-640-delta-training 46C to 640 Delta Training</a>

There you find a link to download a transport request with sample objects including shared objects.

Regards

Uwe

0 Kudos

Hi,

Thomas even wrote a standalone blog about shared objects. Get it here: /people/thomas.jung3/blog/2004/12/09/netweaver-for-the-holidays-a-lession-in-sharing-abap-shared-memory

cheers

Thomas

uwe_schieferstein
Active Contributor
0 Kudos

Hello Christian

Here is an example that shows that the static attributes of a class are not shared between two reports that are linked via SUBMIT statement.

*&---------------------------------------------------------------------*
*& Report  ZUS_SDN_OO_STATIC_ATTRIBUTES
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  zus_sdn_oo_static_attributes.


DATA:
  gt_list        TYPE STANDARD TABLE OF abaplist,
  go_static      TYPE REF TO zcl_sdn_static_attributes.

<i>* CONSTRUCTOR method of class ZCL_SDN_STATIC_ATTRIBUTES:
**METHOD constructor.
*** define local data
**  DATA:
**    ld_msg    TYPE bapi_msg.
**
**  ADD id_count TO md_count.
**
**ENDMETHOD.

* Static public attribute MD_COUNT (type i), initial value = 1</i>



PARAMETERS:
  p_called(1)  TYPE c  DEFAULT ' ' NO-DISPLAY.




START-OF-SELECTION.


<b>* Initial state of static attribute:
*    zcl_sdn_static_attributes=>md_count = 0</b>
  syst-index = 0.
  WRITE: / syst-index, '. object: static counter=',
           zcl_sdn_static_attributes=>md_count.

  DO 5 TIMES.
<b>*   Every time sy-index is added to md_count</b>
    CREATE OBJECT go_static
      EXPORTING
        id_count = syst-index.

    WRITE: / syst-index, '. object: static counter=',
             zcl_sdn_static_attributes=>md_count.

<b>*   After the 3rd round we start the report again (via SUBMIT)
*   and return the result via list memory.
*   If the value of the static attribute is not reset we would
*   start with initial value of md_count = 7 (1+1+2+3).</b>
    IF ( p_called = ' '  AND
         syst-index = 3 ).
      SUBMIT zus_sdn_oo_static_attributes EXPORTING LIST TO MEMORY
        WITH p_called = 'X'
      AND RETURN.

      CALL FUNCTION 'LIST_FROM_MEMORY'
        TABLES
          listobject = gt_list
        EXCEPTIONS
          not_found  = 1
          OTHERS     = 2.
      IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.

      CALL FUNCTION 'DISPLAY_LIST'
*       EXPORTING
*         FULLSCREEN                  =
*         CALLER_HANDLES_EVENTS       =
*         STARTING_X                  = 10
*         STARTING_Y                  = 10
*         ENDING_X                    = 60
*         ENDING_Y                    = 20
*       IMPORTING
*         USER_COMMAND                =
        TABLES
          listobject                  = gt_list
        EXCEPTIONS
          empty_list                  = 1
          OTHERS                      = 2.
      IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.

    ENDIF.

  ENDDO.

<b>* Result: in the 2nd run of the report (via SUBMIT) we get
*         the same values for the static counter.</b>

END-OF-SELECTION.

Regards

Uwe

Former Member
0 Kudos

Hi Christian,

you can always create a logic enqueue object for your static fields using the ID of the object as enqueue field of a table. That table does not need to exist really. But for creating the lock object, it makes life easier. In fact you only need enqueue and dequeue FMs.

Regards,

Thomas