3
votes

I am updating value of my created SHARED MEMORY via JOB. I am deleting/freeing the SHARED MEMORY during initialization but seems like it is not deleting what's on the SHARED MEMORY because I still able to IMPORT data from the SHARED MEMORY during the first iteration of the loop below.

I have already tried researching and found some facts about shared memory like, share memory can be accessed by multiple users and sessions. I also suspected the different application server and also thought of username changing during background run which may affect the 'delete'--but still do not answer my issue because I cannot observe behavior during debug.

 "Program 1: Run via job
 DELETE FROM SHARED MEMORY vari(tl) ID 'MY' && sy-uname.

 DO 3 TIMES.
    SUBMIT program 2 WITH xxx VIA JOB AND RETURN.
 ENDDO.

 "Program 2: Run via Job
 START-OF-SELECTION.

 IF sy-calld EQ 'X'.
    IMPORT var TO var FROM SHARED MEMORY vari(tl) ID 'MY' && sy-uname.
 ENDIF.

 IF var IS INITIAL.
    SELECT fld1, fld2, fld3
      FROM table
      INTO TABLE var
      WHERE cond EQ value.

    IF sy-called EQ 'X'.
       EXPORT var FROM var TO SHARED MEMORY vari(tl) ID 'MY' && sy-uname.
       lt_var = var.
    ENDIF.

 ENDIF.

 IF lt_var IS INITIAL.
    "Raise error.
 ELSE.
    "Further processing...
 ENDIF.

In my 'program 2' above, I am expecting that 'var' IMPORTED from SHARED MEMORY will not have value when it passes the first iteration of my loop since I initialized it in 'program 1'.

I am expecting SHARED MEMORY to have data on it after the first iteration.

Are there any locking considerations during delete from shared memory or do multiple servers affect the delete. Please advise. Thank you so much.

1
It's about memory so yes it works only for the current application server! Shared memory can be accessed by multiple users and there are no locks. If you want to share information between jobs, you'd better get it before submitting the jobs and store it in the database for instance (or AMC if you prefer the complexity). - Sandra Rossi

1 Answers

3
votes

Your question can be devided into several issues:

Sharing memory between multiple users and sessions

It's indeed supported with shared memory.

Monitoring shared memory

There is a standard way to overview the shared area memory (transaction SHMM).

Sharing memory between application servers

Matthew Billingham answered a simillar question here:

The only way, except using the database, is to use one of the application servers to store the data, and allow access from the other application servers.

Let's say you've got three app servers - A, B and C. Create a destination for A in SM59. Create an RFC to handle the shared objects that you want, with logic like this:

If the function module is running on app server A - return the value of the shared object.

If the function module is running on B or C - call the function module, with DESTINATION A.

matt

My comments:

  • There are probably other ways.
  • Writing the shared memory could be done the same way.