Hello,

Sign up to join our community!

Welcome Back,

Please sign in to your account!

Forgot Password,

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

You must login to ask a question.

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

SAP EWM Help Latest Questions

  • 0
  • 0
DPM125

What is a Persistence Class in SAP ABAP?

A Persistence Class is a special ABAP Objects class generated by the Persistence Service that maps database tables to ABAP objects, allowing you to read, modify, and save table data in an object-oriented way instead of writing SQL manually; it is always created from a Persistence Object (PO) in Class Builder (SE24) and acts like an ABAP ORM (Object Relational Mapping) layer.

 

How to Implement a Persistence Class

Step 1: Prepare a Database Table
  • Example: Table ZEMPLOYEES with fields EMPID, ENAME, DEPT.
  • Make sure it has a primary key (mandatory).
Step 2: Create a Persistence Object
  • Go to transaction SE24.
  • Create a new class → select Persistent Class type.
  • Enter database table name (e.g., ZEMPLOYEES).
  • Save and activate.

SAP will automatically generate:

  • Persistence Class (ZCL_EMPLOYEES)
  • Agent Class (ZCA_EMPLOYEES)

Step 3: Use in ABAP Program

DATA: lo_employee TYPE REF TO zcl_employees,
lo_agent TYPE REF TO zca_employees.

” Get the agent class
lo_agent = zca_employees=>agent.

” Create new employee object
CREATE OBJECT lo_employee.

” Set values
lo_employee->set_empid( ‘1001’ ).
lo_employee->set_ename( ‘John Doe’ ).
lo_employee->set_dept( ‘IT’ ).

” Save to DB
lo_employee->update( ).

” Fetch existing employee by key
lo_employee = lo_agent->get_persistent( ‘1001’ ).
WRITE: / ‘Employee:’, lo_employee->get_ename( ).

Advantages of Persistence Classes

  • Encapsulation – No need to expose SQL, use methods instead.
  • Consistency – Follows object-oriented principles.
  • Reusability – Same persistence class can be reused across programs.
  • Error Handling – Provided by framework methods (INSERT, UPDATE, DELETE).

Related Questions

Leave an answer

Leave an answer