SAP4TECH

SAP and ABAP Free Tutorials
Menu
  • SAP Technical
    • ABAP Code Snippets
    • ABAP WebDynPro
    • SAP GW
    • SAP IDOC (ALE)
    • SAP PI (XI)
    • SAP Screen Personas
    • SAP Workflow
  • SAP Functional
    • SAP FI
    • SAP FSCM
    • SAP HR
    • SAP SD & SAP MM
    • SAP PM
    • SAP PP
    • SAP PS
    • SAP QM
    • SAP VIM
    • SAP WM
  • SAP Fiori
  • SAP HANA
  • SAP BW
  • SAP CRM
  • SAP SRM
  • SAP4TECH
    • About Us
    • Contact Us
    • Terms & Conditions
    • Privacy and Cookie Policy

SAP4TECH » How to Create Shared Memory Object Class in ABAP

ABAP Tutorials

How to Create Shared Memory Object Class in ABAP

July 24, 2017 John

Table of Contents

  • Create AREA ROOT Class for Shared Memroy Object Area
    • Go to SAP Transaction SE24 and create a new class.
    • Create 2 Instance Attributes
    • Create SET_DATA & GET_DATA Method
  • Create SAP Shared Memory Area ( SHMA )
  • SET_DATA and GET_DATA Implementation
    • Write data in Shared Memory Area (SET_DATA)
    • Read data in Shared Memory Area (GET_DATA)
    • List of Area Root Class Exception

Create AREA ROOT Class for Shared Memroy Object Area

The first step is to create an Area Rool class. ( let’s say ZCL_ROOT)

Go to SAP Transaction SE24 and create a new class.

Shared Memory Enabled Class

Make sure you checked “Shared Memory Enabled” under Class/Interface Propertiess Tab as following:

Create 2 Instance Attributes

The next step is to create, for example, 2 Instance Attributes within this class.
The Visibility has to be set to Private .

Create SET_DATA & GET_DATA Method

Both of these methods SET_DATA and GET_DATA with handle Shared Memory Object Write and Read operation. We will come back to these methods’ implementation later.

Check also How to use EXPORT or IMPORT data to / from ABAP Memory ID

Create SAP Shared Memory Area ( SHMA )

Launch the Transaction SHMA and create a new Area Name. (ZCL_MEM_AREA for sample)
Fill a short description for the Memory Shared Area. In the Root Class, put the class you have created above ( ZCL_ROOT ).

When saving, SAP will generate an area Class with the same name as the Area Name ( ZCL_MEM_AREA ). The new generated Area Class will contains all the methods needed to read, write and update the Shared Memory Object.

Shared Memory Object Area Class’s Methods

Method Visibility Description
ATTACH_FOR_READ Public Request a Read Lock
ATTACH_FOR_UPDATE Public Request a Change Lock
ATTACH_FOR_WRITE Public Request a Write Lock
BUILD Static Direct Call of Area Constructor
SET_ROOT Instanciate Sets Root Objects

SET_DATA and GET_DATA Implementation

Once you have created the area root class, the area class and generated the area class, you can implement the ABAP code for the SET_DATA and GET_DATA in order to read/Write the Shard Memory Object.

Write data in Shared Memory Area (SET_DATA)

In order to save data into an instance of Shared Memory Object, you can set the data as following :

ABAP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
    DATA: my_handle TYPE REF TO zcl_mem_area.
    DATA: my_root   TYPE REF TO zcl_area_root.
 
    TRY .
 
        CALL METHOD zcl_mem_area=>attach_for_write
          EXPORTING
            inst_name   = cl_shm_area=>default_instance
            attach_mode = cl_shm_area=>attach_mode_default
            wait_time   = 0
          RECEIVING
            handle      = my_handle.
 
        CREATE OBJECT my_root AREA HANDLE my_handle.
 
        CALL METHOD my_root->set_data
          EXPORTING
            name  = 'name_test'
            value = 'value_test'.
 
        CALL METHOD my_handle->detach_commit.
 
      CATCH cx_shm_exclusive_lock_active .
      CATCH cx_shm_version_limit_exceeded .
      CATCH cx_shm_change_lock_active .
      CATCH cx_shm_parameter_error .
      CATCH cx_shm_pending_lock_removed .
 
    ENDTRY.

Read data in Shared Memory Area (GET_DATA)

here an example how to use the GET_DATA in order to read an instance of Shared Memory Object:

ABAP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
    DATA: my_handle TYPE REF TO zcl_mem_area.
    DATA: my_root   TYPE REF TO zcl_area_root.
 
 
    TRY .
 
        CALL METHOD zcl_mem_area=>attach_for_read
          EXPORTING
            inst_name = zcl_mem_area=>attach_for_write
          RECEIVING
            handle    = my_handle.
 
        CREATE OBJECT my_root AREA HANDLE my_handle.
 
        CALL METHOD my_root->get_data
          IMPORTING
            name  = lv_name
            value = lv_value.
 
        CALL METHOD my_handle->detach_commit.
 
       CATCH cx_shm_inconsistent .
       CATCH cx_shm_no_active_version .
       CATCH cx_shm_read_lock_active .
       CATCH cx_shm_exclusive_lock_active .
       CATCH cx_shm_parameter_error .
       CATCH cx_shm_change_lock_active .
 
    ENDTRY.

Note that NAME and VALUE are the attribute of the Area Root Class.

List of Area Root Class Exception

Here the list of the main exception Class for Area Root:

Prev Article
Next Article
Tags:Class Object Shared Memory Object

Related Articles

SAP Classification Tables
This article will cover How Sap Classification is handled. It …

SAP Classification and Characteristics : Customizing & Tables (AUSP)

SAP Process Integration
SAP PI Tcodes ‘post list the main important Transaction Codes …

Important SAP PI Tcodes (Process Integration Transaction Codes) – SAP XI Tcodes

Search on SAP4TECH

The Most Populars

  • The Most Important SAP ISU Tables
    The Most Important SAP ISU Tables
  • SAP Users Tables
    SAP Users Tables (for Personal, Logon, and Address Data)
  • List of SAP Purchase Order Tables in SAP MM SAP PO Tables
    SAP Purchase Order Tables: Main PO tables in SAP MM – SAP PO Tables
  • Full list of SAP Movement Types
    SAP Good Movement Types – Full list of SAP Movement Types
  • The Main SAP GL Account Tcodes SAP GL Account Tables
    The Main SAP G/L Account Tcodes & SAP GL Account Tables
  • SAP BOM Tables
    SAP BOM Tables for BOM Header, Items and components and Category

Related Posts

  • chrysler invoice 46370 o e1442487543248
    IDoc Reduced Segment Check
  • SAP Process Integration
    Important SAP PI Tcodes (Process Integration Transaction Codes) – SAP XI Tcodes
  • SAP Users Tables
    SAP Users Tables (for Personal, Logon, and Address Data)
  • SAP ABAP
    ABAP Add SearchHelp on Parameter
  • SAP UI Theme Designer
    SAP UI Theme Designer PDF Ressources: Step by Step Started Guides

SAP4TECH

SAP and ABAP Free Tutorials

Trending Posts

  • The Most Important SAP ISU Tables
  • SAP Users Tables (for Personal, Logon, and Address Data)
  • SAP Purchase Order Tables: Main PO tables in SAP MM – SAP PO Tables
  • SAP Good Movement Types – Full list of SAP Movement Types
  • The Main SAP G/L Account Tcodes & SAP GL Account Tables
  • SAP BOM Tables for BOM Header, Items and components and Category

The Most Recents

  • The Most Important SAP ISU Tables
  • SAP Fiori 3 UX and Design of SAP Fiori Apps for SAP S/4HANA, SAP TechEd Lecture
  • The Main SAP Dunning Transaction Codes
  • SAP Accounts Payable Tcodes & Accounts Receivable Tcodes ( SAP AP Tcodes & SAP AR Tcodes)
  • The Most Important SAP Payment Terms Tables (ZTERM, Text…)

Search

SAP Tutorials by Topics

  • SAP Tables
  • SAP Tcodes
  • SAP BAPI
  • ABAP Snippets
  • Top SAP Courses
  • Top SAP Books
Copyright © 2021 SAP4TECH

Ad Blocker Detected

Our website is made possible by displaying online advertisements to our visitors. Please consider supporting us by disabling your ad blocker.

Refresh
This website uses cookies to improve your experience. We'll assume you accept this policy as long as you are using this websiteAcceptView Policy