Question

SAP rather sensibly prohibits you from including deep structures in database tables. For a new project however I have a deeply nested structure that I want to store persistently. This structure includes another dozen structures with each of those possibly being further nested. This structure is basically a snapshot of the data contained in dozens of standard SAP tables for a given Business Partner. I don't currently foresee issues with constructing this structure, filling it with data and sending it on its way as an XML.

However, I'm at a loss as to how I should go about saving the whole deal to the database. Since I can't just dump this nested mess into a single table, I'd have to basically recreate every underlying table relationship in Z-tables. As this seems altogether too much work, in addition to being tedious and error prone, I'm looking for an alternative solution to storing this data.

I've encountered this scenario in other programming languages where I would just store a data dump of the entire object to XML, flat file or whatever was the format du jour. This data dump could then just be loaded in when the table is queried and the object rebuilt and loaded into memory. Is this a valid approach for ABAP development? Are there existing classes or Function modules for (de)constructing generic nested structures or will I have to write my own logic from scratch? Or is there an alternative that I'm missing?

Was it helpful?

Solution

This is a common requirement, and there are several ways to achieve this. The most commonly used methods are these:

  • You could transform the entire data structure to XML, or rather asXML which is ABAP data serialized in XML format. It's fairly easy, just use CALL TRANSFORMATION with the built-in transformation named id. The downside of this is that XML can be very verbose - this can easily blow up your dataset by a factor of 2-4 (YMMV).

  • You can use a so-called data cluster. This stores the data in a binary format which can optionally be compressed as well via an internal undocumented ABAP compression algorithm. This is an efficient process regarding both execution time and storage size, but it has the disadvantage that you can't read the data without using the ABAP statements for decompressing. While you can always dump some XML file for further investigation, the internal storage format of data clusters is virtually illegible.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top