When working with ABAP Persistent Classes in SAP, many developers come across confusing behavior that perhaps should be considered bugs. To get around some of these I’ll explain our leading practice for persistent class development that should simplify your work in this area.
Planning your classes
When planning your persistent classes, consider adding a database view to your architecture. Let me explain. When choosing fields in a persistent class for a table, SAP requires that all fields in the table must be linked. It’s confusing the way SAP handles this but, so you are not thrown off, here’s what happens. When you add fields to the persistence layer, nothing seems amiss. But when activating the class, you’ll see what appears to be a success message. If you read it closely, it’s actually an error and you’ll notice that your class is not activated. The solution is to link the missing field to your class and then you’re set. But what if you really don’t want these fields in your class? Or, in cases when there are changes to the underlying table, you’ll find that the next time you go to make a change, you’ll see this message below. The class will continue to work if you have not made any changes so, while frustrating, it is not a support issue.
So, because of the above situation, we recommend the addition of a database view to the overall design. This provides control over a limited field list and can help you avoid possible errors when using custom name spaces that seem to regularly encounter problems (I will explain this towards the end). The key here is that the database view is one-to-one with the table selected, and the maintenance status is set to “read and change” and display maintenance is allowed as shown below. (Note: you’ll know if you don’t set this properly, as the persistent class will fail when activating with maintenance status “not allowed”.)
You can see our guidelines for SAP object naming here (ABAP Development Guidelines), for persistent classes, we recommend the class is named ZCL_PERS XXX, with XXX being replaced with the name of the database table that is being persisted. Note: it is possible to create a persistent class that links multiple tables. In that case, you’ll want to use a different naming guideline.
Name space issue:
Occasionally, you may see the following error when attempting to link a custom namespace to your persistent class. This error may have already been resolved by an SAP note by the time you see this, but be aware that it is possible. We see it regularly in versions up to 7.02 but have not properly tested in more recent versions. The important point is that when using a view, you can just exclude these fields from the persistence class and ignore the issue.
Hope that helps. Feel free to comment with your thoughts and suggestions.
- ABAP Workbench Tools – Creating Persistent Classes at: https://help.sap.com/viewer/12aa7f056c531014aa5bca7aee037e55/7.0.37/en-US/06f23c3d638d11d4966d00a0c94260a5.html
Advanced Solutions is a leading provider of third party SAP support, our experts provide Application Management services , post implementation support and are considered experts in their respective practice areas of SAP. To learn more contact us today!