SQL Server administration and T-SQL development, Web Programming with ASP.NET, HTML5 and Javascript, Windows Phone 8 app development, SAP Smartforms and ABAP Programming, Windows 7, Visual Studio and MS Office software SAP ABAP Programming and HANA Database Tutorials
Development resources, articles, tutorials, samples, codes and tools for .Net, SQL Server, Windows, Windows Phone, SAP and ABAP, like SAP UI5, Screen Personas, etc.




CRM Companies List
Web Based CRM Software


ABAP Shared Memory Objects Tutorial with Sample ABAP Code

This ABAP Shared Memory Objects tutorial includes sample ABAP code showing how to code to store data in shared memory objects and read data from shared memory object. By following the instructions in this step by step ABAP tutorial, developers can create a shared memory object in SAP. Given sample ABAP codes and sample programs will help developers to write data or read data from shared memory objects using shared memory programming.

ABAP developers can use following SAP transaction codes for Shared Memory Object development, debugging and monitoring:
SE80 or SE24 transaction for ABAP Workbench Class Builder editor to create root class for data structure.
SHMA SAP transaction for creating Shared Object Area class interface.
SHMM to monitor Shared Memory Areas objects, their memory consumption, and view and display data contained in shared memory object

Of course ABAP developers can use transaction SE38 to create two ABAP programs where they set the shared memory object value and read back from shared memory area object.

Steps to Implement ABAP Shared Object Solution

1.) Create a class that represents data structure. (I'll refer this class as root class). Use SE80 or SE24 tcode

2.) Create a shared memory area class to wrap data class for standard shared memory object methods. (I'll refer this class as handle class). Use SHMA transaction

3.) ABAP code to write data to shared memory object. For example you can build a simple ABAP program using SE38 to set shared memory object value.

4.) ABAP code to read data from shared memory object. A similar ABAP report can be written to read data from shared memory object using SE38.

Naming of the root class and the shared memory area is important. The first part of the names of both classes should be same. On the other hand root class name should be ending with "_root" and the shared memory area class name should end with "_area"

In fact this naming simpifies the work of ABAP developer. ABAP programmers will have a better understanding about the objects they're using to build a SAP shared memory object solution.


Root Class for Shared Memory Object

In this section of the ABAP tutorial, we will create a class with Shared Memory-Enabled option is selected.
The class name is Z_VBRK_SHM_TABLE_ROOT for the sake of naming standards.

First of all, call SE80 Workbench transaction code and choose Class / Interface as object type. Then type the name of the new root class for your shared memory object as seen in below screen shot.

SE80 SAP transaction to create shared memory root class

Press Enter key for next dialog

create shared memory object root class

When your approval is requested to create the mentioned class since it does not exist, click Yes to continue to create the new root class for shared memory object.

Choose Class option instead of Interface to indicate that you're creating a class not an interface

create class for shared memory object

Press Enter or OK icon button

Provide class description for the shared memory object root class.
Choose instantiation as Public.
Class type is Usual ABAP class and mark Final checkbox.

usual ABAP class properties for shared memory object

When you are finished with basic class properties, click Save to continue for the SAP Class Builder screen.
Be sure that you do not forget to mark Shared Memory-Enabled checkbox on class properties screen general data section.

ABAP Class Builder screen for Shared-Memory object root class

Now after we mark the class as shared memory-enabled, we will now create an attribute where data will be stored and two class methods to set and get shared data in the class attribute.

Now switch to Attributes tab and define a private attribute where data will be stored.
For example we can create an attribute where ABAP developers can store a list of SAP document numbers in VBELN data type.

When I searched the ABAP dictionary for an existing table type for VBELN data type, I found VBELN_VL_T table type. I'll use VBELN_VL_T table type in this tutorial to create a class attribute for storing SAP document numbers like invoice numbers or order numbers in a shared memory object.

SAP shared memory object attribute definition

After attribute is created, ABAP developers can continue with next step.
In this step, we will create two public methods.
These methods will be used to set data to private attribute and get data (read) from private attribute of the shared memory object.

SAP Shared Memory-Enabled class Set and Get methods

SET_VBELN method has import parameter P_VBELN of type VBELN_VL_T which is a table type for VBELN data element. This method takes internal table of table type VBELN_VL_T to set as shared memory object data content.

Set method parameter for ABAP shared memory class

GET_VBELN method has export parameter P_VBELN_TBL of type VBELN_VL_T which is a table type for document numbers. Using the export method Get_Vbeln, ABAP users will be able to return shared memory object table for all stored document numbers.

Get method for shared memory object class

After the developer defines class attribute and set/get methods of the root class, within the methods following ABAP codes can be used.

METHOD SET_VBELN.
 SHM_VBELN_TBL = P_VBELN.
ENDMETHOD.

METHOD GET_VBELN.
 P_VBELN_TBL = SHM_VBELN_TBL.
ENDMETHOD.

Set method assigns the input parameter value as the value of shared memory object attribute. And the Get method returns the attribute value as export parameter. We will see how we will call these shared memory enabled class methods within other ABAP programs later in this ABAP tutorial.


Create Shared Memory Area: Handle Class

This tutorial step demonstrates the creation of the shared memory area.
To create a Shared Memory Area ABAP developers can use SHMA SAP transaction code. Area name should be Z_VBRK_SHM_TABLE_AREA according to the naming rules which will help the developers to reference it without any confusion later

SAP SHMA tcode to create shared memory area

When you press Create button, following Create Area screen will be displayed.
Enter the root class name we have created as shared memory root class in Attributes tab basic properties section. In our tutorial, we have defined the root class name as Z_VBRK_SHM_TABLE_ROOT in previous steps.

shared memory area in ABAP development

If you look at the details of the above Create Area screen, you will realize that an ABAP developer can enable versioning with a Shared Area object. It is also possible to define the maximum shared area object size that will keep on memory in kByte and maximum number of allowed versions.

After you complete Shared Memory Area properties like deciding if you want to use it with Versioning is enabled or not, first press Save icon and then press Release button at top icons menu.

The class category is Area Class (Shared Objects) when you display the shared memory area using SE80. The Root attribute of the handle class is automatically set to previously created root class at step 1.


ABAP Programs

The below ABAP report whose source code is given reads shared memory object value.
Root class attach_for_read method must be called before reading shared memory data using our custom Get_Vbeln method. At the end of the read process, ABAP developers must call detach() method to free shared memory object.

REPORT Z_READ_SHARED_MEMORY_OBJECT.

DATA lt_vbeln type VBELN_VL_T.
DATA ls_vbeln like LINE OF lt_vbeln.

DATA lr_handle TYPE REF TO Z_VBRK_SHM_TABLE_AREA.

lr_handle = Z_VBRK_SHM_TABLE_AREA=>attach_for_read( ).
lr_handle->root->get_vbeln( IMPORTING P_VBELN_TBL = lt_vbeln ).
lr_handle->detach( ).

In order to update data stored in memory using shared memory objects, developers must consider using one of attach_for_write() or attach_for_update() methods.
Following ABAP report is demonstrating how to assign shared memory object value.
First of all, using below ABAP a check is done to see if an active version of the shared memory object exists or not. This check is done by reading the shared memory object.
If cx_shm_no_active_version exception is catched in the ABAP TRY and CATCH syntax, then ABAP developer should use attach_for_write method while creating the root class object handle. Otherwise, attach_for_update method can be used during root creation of the root class handle.

REPORT z_shared_memory_object_sample.

PARAMETERS: pr_vbeln LIKE vbrk-vbeln DEFAULT '1111111111'.
* ABAP program appends p_VBELN parameter value TO Shared Memory Object

DATA lt_vbeln type VBELN_VL_T.
DATA ls_vbeln like LINE OF lt_vbeln.

DATA lr_handle TYPE REF TO z_vbrk_shm_table_area. " Area Class
DATA lr_root TYPE REF TO z_vbrk_shm_table_root. " Root attribute of handle class. SHM: Model of a Data Clas

******************************************************
* First Try to Read
data excp type ref to cx_shm_no_active_version.
data lf_readerror type c1.

try.
 lr_handle = z_vbrk_shm_table_area=>attach_for_read( ).
 lr_handle->root->get_vbeln( IMPORTING P_VBELN_TBL = lt_vbeln ).
 lr_handle->detach( ).
catch cx_shm_no_active_version into excp.
 lf_readerror = 'X'.
endtry.
******************************************************

APPEND pr_vbeln to lt_vbeln. " append input parameter value to internal table

IF lf_readerror = 'X'.
 lr_handle = z_vbrk_shm_table_area=>attach_for_write( ).
ELSE.
 lr_handle = z_vbrk_shm_table_area=>attach_for_update( ).
ENDIF.

CREATE OBJECT lr_root AREA HANDLE lr_handle.
lr_handle->set_root( lr_root ).

lr_root->set_vbeln( p_vbeln = lt_vbeln ). " custom SET method is executed

lr_handle->detach_commit( ).

At the end of the ABAP code block for storing data in shared memory object, COMMIT in database must be executed. Since the ABAP developer should free the SAP shared memory objects, the DETACH process must be executed too.
To detach from shared memory area with saving data in memory variables, detach_commit() method can be called.


Monitor Shared Memory Area using SHMM Transaction

SAP transaction SHMM is used for monitoring shared memory areas for memory consumption and to display data stored in shared memory objects.

When you call SHMM tcode, SAP Shared Memory: Areas screen will be displayed. On the screen on Areas tab which is the default displayed tab, you will see shared memory areas created on the related SAP system.

Highlight the shared memory area which you want to monitor in detail as follows.

monitor shared memory area in SAP system

When you double click the shared memory area, instances of the shared area will be displayed as a list on a new screen.

ABAP share memory area instances

Choose the default instance by highlighting it and click on Read Active Version icon to display shared memory object contents.

In a new SAP screen, we will be displayed root object data in different tabs. The default tab is Explorer. You will see the shared memory object attribute we have created earlier in this tutorial.

display ABAP shared memory object data

Highlight the SAP shared memory class attribute SHM_VBELN_TBL which is a table storing document numbers. Then double click it to view its stored row values.

You see below, tutorial sample shared memory object has two document numbers stored in its class attribute.

ABAP shared memory object storing data


To summarize, in this ABAP tutorial I tried to give brief information about SAP shared memory object and how to use shared memory in your ABAP programs. Using the transaction codes and step by step guide, an ABAP developer can create a sample shared memory root class and the shared memory area for this class. Then given ABAP reports can be used to write, update or read shared memory objects.

ABAP developers can read a more detailed guide for working with ABAP Shared Memory Objects at SAP Community Network portal.






SAP Tutorials

SAP Tutorial

SAP Forums

SAP Tools

SAP Transaction Codes Table






Related Articles and Tutorials(http://www.kodyaz.com/sap-abap/abap-shared-memory-objects-tutorial.aspx)
Check Existence using ABAP SELECT
ABAP LOOP Statement with At New and At End
How to Set Start Transaction in SAP GUI
ABAP Tutorial - SAP Split and ABAP Split String Function
Connect SAP from Eclipse using ABAP Project
Convert Smartform to PDF in Print Preview Mode
Create Business Object in SAP
Main program for include RV61Bxxx not found
Export Table Contents into Text File and Download File
ABAP Tutorial for SET and GET PARAMETER ID Command
Complete List of SAP Modules
Free Adobe LiveCycle Designer Download
CALL_FUNCTION_NOT_FOUND ABAP Run Time Error
Web Dynpro Text Translation using Assistance Class
Code Inspector: Unsecure use of FOR ALL ENTRIES
How to Upload Data to SAP from Excel File using alsm_excel_to_internal_table Function Module
ABAP - Create Hierarchy Tree List using rs_tree_construct, rs_tree_list_display and snodetext
ABAP Tutorial - ABAP String Split Example Code
Upload Data from Excel File in ABAP using TEXT_CONVERT_XLS_TO_SAP
Create CL_GUI_ALV_GRID ALV Grid Column Header using ABAP Data Element
Email Spool Request using SAPOffice - Spool to PDF
How to Create SAPScript Text using SO10 Transaction Code
How to Display SAP Graphics using SE78 Transaction Code
ALV Grid Color - Table Row Background Color in ALV List
SAP ABAP Tutorial - ALV Grid Example with cl_gui_alv_grid and Screen Painter
SAP Smartforms - How to Call Smartform within ABAP Program
SAP Tutorial - Convert Spool Request to PDF File using RSTXPDFT4 ABAP Report
Set Default Single Values List for SAP Selection Screen Parameter
ABAP Debugging using Log Point and Break Point
ABAP RegEx for ABAP Regular Expression to fetch Date from String
ABAP Runtime Error ST22 Transaction using Short Dump Analysis
ABAP Shared Memory Objects Tutorial with Sample ABAP Code
ABAP Try Catch for exception is neither caught Code Inspector Error
Add Year, Month or Day to Date Variable in ABAP using RP_CALC_DATE_IN_INTERVAL
Add Web Dynpro Applications to SAP Favorites Menu
Read Address Data using FM ADDR_GET instead of Querying ADRC Table
ABAP Authority-Check Object For User Other Than Current
SAP Code Inspector for ABAP Break-Point Statement
Call Function Module using RFC Destination in ABAP
Change Fields for Selection in SE11 ABAP Data Browser
Compare Code in ABAP using SE39 SplitScreen Editor
How to Spell Numbers using ABAP Spell_Amount Function Module
Convert the table using the Database Utility (SE14)
Convert Sales Unit into Text using Function Module in Target Language
ABAP Code Inspector Check Variants for HANA Migration Optimization
Create SAP Dynamic Variant using Date Calculation
Create Scheduled Job using SAP SM36 Transaction
Create Search Help in ABAP for Web Dynpro Component
Create Transaction Code for Web Dynpro Application
Create SAP Transaction to Maintain ABAP Table using SM30
Create Transport Request for Text Translations using RS_LXE_RECORD_TORDER
Database Hint Pseudo-Comment for SAP Code Inspector
Delete Entries in NAST Table using RSCLNAST ABAP Program
Delete All Data from SAP Database Table
List Locks in SAP system using SM12 Transaction Code
Dynamic Programming using Field Symbols in ABAP Reports
Prevent DYNPRO_SEND_IN_BACKGROUND Error in Background Process
Enable Remote Debugging in ABAP using RSRDEBUG
Execute ABAP Program Automatically After Transport Request Import
How to Execute SAP Program in Background Task
Export Graphics from SE78 SAP Form Graphics Administration using ABAP program
How to Find Internal Table Row Count in ABAP
Export SAP Data to Fixed Length Text File
How to Debug Popup Screen in ABAP
How to Export IDOC as Excel and Save as Local File from WE02 Transaction
Export SAP Spool Requests as PDF using SP01 Transaction
How to Find SAP Role Users Assigned for Transaction Code
Get Fullname of SAP user using Function Module in ABAP Program
How to Delete Standard Text using SO10 SAP Transaction
How to Find User Exits in ABAP Codes of SAP Transaction
Read Integer and Decimals of a Numeric Value in ABAP Programming
How to Transport SAP Graphics using SE78 Transaction
Import and Export SO10 Standard Text using RSTXSCRP ABAP Program
Move Minus Sign from Right to Left of Negative Number in SAP Smartform
Primary key change not permitted for value table
Business Document Service Error: Error when accessing graphic (BDS), RC = 5
Read Pricing Condition Text using ABAP in SAP Sales Document Output
Read Text Symbols in Specific Language using ABAP RS_TEXTPOOL_READ
Get SAP Document Flow using SD_DOCUMENT_FLOW_GET ABAP Function Module
SAP Purchase Order Tables, Transaction Codes and Output
Graphics White Background Displayed Grey on SAP Smartform Output
SE63 Smartform Translation and Export using SLXT Program
Search and Find SAP Transaction Code using SE93 or SEARCH_SAP_MENU
SAP Code Inspector Error: Select For Cluster Table Without Order By
ABAP Select Statement using Space instead of Null or Initial
SAP Code Inspector: Select-Statement can be Transformed
ABAP CONVT_NO_NUMBER Error on SP01 due SP01_WARN Parameter
How to find string length using STRLEN ABAP string function
ABAP Submit Report to Run Another ABAP Program within Code
Unicode Character Problem in IFS File Interface
Transport Variants of an ABAP Program into Workbench Request
TVAP Item Category and SAP Table TVAPT for Text Translations
Unlock Objects Locked in Request or Task using Transport Organizer Tools
Update Multiple Variables in ABAP Select Single Statement
Update Database Table Data using ABAP SE16N_INTERFACE
VF31 SAP Transaction to Reprocess Billing Output Messages
Function module is not released for the Internet
Activate Fixed Point Arithmetic Flag for Open SQL Statement
Activate Fixed Point Arithmetic Flag for Open SQL Statement
Switch ABAP Variable Value with Translate using Mask
Switch ABAP Variable Value with Translate using Mask
Activate Fixed Point Arithmetic Flag for Open SQL Statement
Activate Fixed Point Arithmetic Flag for Open SQL Statement
Activate Fixed Point Arithmetic Flag for Open SQL Statement
Activate Fixed Point Arithmetic Flag for Open SQL Statement
Activate Fixed Point Arithmetic Flag for Open SQL Statement
Activate Fixed Point Arithmetic Flag for Open SQL Statement
Activate Fixed Point Arithmetic Flag for Open SQL Statement
Activate Fixed Point Arithmetic Flag for Open SQL Statement
Activate Fixed Point Arithmetic Flag for Open SQL Statement
Activate Fixed Point Arithmetic Flag for Open SQL Statement


Copyright © 2004 - 2017 Eralper YILMAZ. All rights reserved.
Community Server by Telligent Systems