RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Debunking a Persistent Myth in ABAP Objects

That SAP's ABAP Objects language lacks support for serializeable and persistent objects is such an enduring myth, we decided to lay it forever to rest with a host of simple examples of how to persist objects from a class.

ecently, I was talking with a Java developer who was fairly new to the SAP world but claimed to already be an ABAP expert. He was commenting on the ABAP programming language. In several of his comments he remarked that ABAP Objects didn't have persistent objects or an OO transactional system. I found this rather interesting considering that ABAP Objects has both of those things.

On the same day that I had the opportunity to set this poor misguided soul straight, I ran into another instance of persistence ignorance. There was a posting on the SAP Developer Network's (SDN) ABAP forum asking ABAP developers to fill out a survey for someone's master theses. One of the questions: "What are the weak points for ABAP Objects?" Among the choices given by the survey to answer the question: "No persistent objects or serializeable objects." ABAP Objects has both persistent and serializeable objects.

Five people out of 45 had selected this option as a weak point for ABAP Objects. I dedicate this solution to those five people and my Java friend.

A common misconception these days is that ABAP Objects has no support for serializeable and persistent objects. But it does.

Follow along to learn step-by-step how to create a serializeable data object class, a persistent object, and to use the Persistent Data Mapper.

Serializeable Objects
In defense of those who might have agreed with the statement that lack of persistence and serializeable objects in ABAP Objects is a weakness, it is true that this functionality is not present before the 6.X releases of SAP's WebAS. All the examples that I am going to share today were developed on a 620 WebAS.

In a moment I'll jump into the heart of persistent objects, but first I'll address serializeable objects. If you want an ABAP Object class to be serializeable, all you have to do is add the IF_SERIALIZABLE_OBJECT interface. That's it—pretty simple! Listing 1 is some sample ABAP code from which I have to serialize a data object class and write it out to an XML file on the presentation server:

The XML output looks like this:

<?xml version="1.0" encoding="utf-8" ?> 
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
      <ASAP_ISSUE href="#o13" /> 
   <asx:heap xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:abap="http://www.sap.com/abapxml/types/built-in"
xmlns:cls="http://www.sap.com/abapxml/classes/global" xmlns:dic="http://www.sap.com/abapxml/types/dictionary"> <cls:ZCL_ES_ASAP_ISSUE_OBJECT id="o13"> <ZCL_ES_ASAP_ISSUE_OBJECT> <ASSIGNMENTS> <ZESA_ISS_ASS> <MANDT /> <ID>0000000001</ID> <ASS_ID>00000</ASS_ID> <ASSIGN_BY>LSCHEU</ASSIGN_BY> <ASSIGN_TO>LSCHEU</ASSIGN_TO> <ASSIGN_DATE>2000-11-01</ASSIGN_DATE> <PRIORITY>00003</PRIORITY> <STATUS>00050</STATUS> <RESOLVE_DATE>2000-11-02</RESOLVE_DATE>

Editor's Note: This content was originally published on the SAP Developer Network. Reprinted with permission.

Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date