Quantcast
Channel: SCN : All Content - ABAP Development
Viewing all articles
Browse latest Browse all 8332

Persistent Class - problem with inheritance

$
0
0

Hi.

 

According to SAP Help, I want to develop persistent classes with inheritance.

 

I have a DB table, which is structured very similar to system table INDX. This table contents two kinds of records, which are differed by the field RELID. This means, I have records with RELID = SO and records with RELID = SP. In the current, very procedural coding, there are many IFs (IF RELID = SO....elseif RELID = SP .... endif). I want to get rid of them and in addition to that, there are many reasons to make an object oriented application of this program. Maybe in the future, there will be more RELIDs and each ELSEIF has to be extended.


So let's get to object orientation - down to the persistence layer.


Because there is some coding, which is depending on this difference, I want to have two kinds of persistent objects (= two different classes), both classes are inheriting from the same superclass. In the superclass, I want to code the coding, that has to be proceeded by all records, in the subclasses the coding, which is special for this RELID (means: the coding with the IF and ELSEIF-Coding).

 

So I defined the superclass ZCL_XYZ and the inheriting subclasses ZCL_XYZ_SO and ZCL_XYZ_SP.


If there is another RELID in the future, I would make another class only with the special coding, related to the new RELID. This makes sense!

 

At First, I read all the relevant records into an static internal table, which saves the key fields of the table and the object (I think, this is called a "Multiton Design Pattern"). In particular, this internal table stores all persistent objects and assigns them to the related DB record. The columns of this internal table are: The key fields of my DB-table (let's call the table XYZ, same structure like INDX) and an additional column for the objects (type ref to ZCL_XYZ). In column ZCL_XYZ are all objects of a subtype of ZCL_XYZ. Each object stores the content of the relating database record in his attributes.

 

The problem is: If I want to set one of the DB fields (i. e. XYZ-LOEKZ), I call the SET_LOEKZ-method of my persistent subclass. For instance:

 

READ TABLE instances assigning field-symbol.....

index ....

 

<instance>-persistent_object->SET_LOEKZ( ABAP_TRUE ).

 

This works fine. I can see in my persistent object, that the field has been filled with an 'X'. To get this X into the record on the database, I have to do a commit work. And this is the problem. After commit work, all attributes (RELID, LOEKZ, etc.) of ALL of my persistent objects are empty. In my internal table "instances" I can see all objects, but they do have all empty attributes.

 

I don't know, why. I searched and debugged for days without finding a reason. It seems, that all objects are rebuilt, but why - and why with empty attributes?

 

Today I read the linked document in the SAP Help (see above, at the beginning of this posting), and that I need atype identifier field in my DB table. I added this type identifier field, added it into the mapping rules as type identifier field, but when I want to activate the persistent class, I get the following syntax error:


The component TABLE_LINE is not contained in key "PRIMARY_KEY" of table "KEY_TAB_FOUND_LOCAL", or the key is not statically known.


The coding line with the syntax error is in IF_OS_CA_PERSISTENCY~GET_PERSISTENT_BY_KEY_TAB is this statement:


            read table key_tab_found_local
                  transporting no fields
                  with table key table_line = business_key.


This is a statement in the generated coding of my persistent class. KEY_TAB_FOUND_LOCAL is an internal table - type standard table of BUSINESS_KEY with default key!


I don't know, what kind of problem causes the syntax error in the automatically generated coding. If I delete the type identifier field from my DB-table XYZ, the activation process works fine, but I have the problem with the deleted object attributes after COMMIT WORK.


What I am doing wrong???? How can I get my application running with inheriting persistent classes???


There is just ONE answer, I don't want to hear: "Don't use persistent classes".   I want to use them, the SAP Help says it works. I don't want to rebuild my application. I just want to make it working.


Viewing all articles
Browse latest Browse all 8332

Trending Articles