Skip to Content

Simple OO Cluster ABAP

cluster database can store data “variables, structures, tables”
permanently in a table.

For example Indx table in the system that has different
purposes depending on the need for storage of program that you use.

The basic idea is to use the Cluster database so simple.





this class was created YCL_INDX_Z1 , this class will use the table INDX and the Area



statements Import, Export and Delete … database not allow the dynamic
specification of the table or area. For this class can re implement or create a
copy so you can specify other standard or proprietary Cluster.

Class YCL_DRIVE_CLUSTER allows the use of the specific

class for the Cluster. You could create a method of a class that could return

the Cluster class specified for any given business situation.

With this tool you can manage a complex data type

specified by the pdata parameter in the Import and Export methods, if your

program know the complex data type can handle it, not knowing if the data type

method may be invoked and GET_DATA_TYPE create a variable to manage the structure.


class YCL_DRIVER_CLUSTER definition



  create public .

 public components of class YCL_DRIVER_CLUSTER

 do not include other source files here!!!

public section.



      !NAMECLASS type ANY optional

      !TABLE type ANY optional

      !REGION type ANY optional

    preferred parameter NAMECLASS



  methods DELETE_DATA


      !PID type ANY .

  methods SET_DATA


      !PID type ANY

      !PDATA type ANY

      !PWA type ANY optional .

  methods GET_DATA


      !PID type ANY


      !PDATA type ANY

      !PWA type ANY

      !PTYPE type ANY .

  class-methods DET_CLUSTER_TABLE_AREA


      !TABLE type ANY

      !REGION type ANY


      value(R) type ref to [YIF_CLDB_0001 | #IF]


      NO_FOUND .

  methods GET_DATA_TYPE


      !PID type ANY .

private section.

  data M_TYPE type STRING .

  data R_ID type STRING .

  data M_DATA type ref to DATA .

  data MCLUSTER type ref to [YIF_CLDB_0001 | #IF].

  methods DETERM_TYPE


      !PDATA type ANY .

  methods CLEAR_ALL .

Code Methods

 components of interface YIF_CLDB_0001

interface YIF_CLDB_0001

  public .

  methods R_EXPORT


      !PID type ANY

      !PDATA type ANY

      !PWA type ANY

      !PINFO type ANY .

  methods R_IMPORT


      !PID type ANY


      !PDATA type ANY

      !PINFO type ANY

      !PWA type ANY .

  methods R_DELETE


      !PID type ANY .

  methods R_DDIC


      !PID type ANY


      value(PINFO) type STRING .


<a name=”_YCL_INDX_Z1″ title=”_YCL_INDX_Z1″></a>YCL_INDX_Z1

class YCL_INDX_Z1 definition



  create public .

 public components of class YCL_INDX_Z1

 do not include other source files here!!!

public section.

  interfaces [YIF_CLDB_0001 | #IF].

Code Methods

METHOD yif_cldb_0001~r_export.

  DATA: st_wa TYPE indx,      “Just Change this by redefining

            sid   TYPE indx-relid.“Just Change this by redefining

  MOVE pwa TO st_wa.

  EXPORT str   FROM pinfo

         datos FROM pdata TO   DATABASE

              indx(z1) “Just Change this by redefining

              FROM st_wa

              ID sid.


METHOD yif_cldb_0001~r_import.

  DATA: st_wa TYPE indx,      “Just Change this by redefining

          sid   TYPE indx-relid.“Just Change this by redefining

  IMPORT str   TO pinfo

         datos TO pdata FROM DATABASE

              indx(z1) “Just Change this by redefining

              TO st_wa

              ID sid.

  MOVE st_wa TO pwa.


METHOD yif_cldb_0001~r_delete.

  DATA sid   TYPE indx-relid. “Just Change this by redefining

  MOVE pid TO sid.


               indx(z1)    “Just Change this by redefining

               ID sid.


METHOD yif_cldb_0001~r_ddic.

  DATA: sid   TYPE indx-relid. “Just Change this by redefining

  EXPORT str  FROM pinfo

      TO DATABASE indx(z1) ID sid.“Just Change this by redefining


h1. PROGRAM ytest_cluster_01.

PROGRAM ytest_cluster_01.




     BEGIN OF superstrc,

       str1   TYPE sy,

       table1 TYPE tdd02l,

     END OF superstrc.

  DATA int_wa TYPE indx.

  DATA cluster TYPE REF TO [ycl_driver_cluster | #_YCL_DRIVER_CLUSTER].

  int_wa-loekz = ‘X’.

  int_wa-sperr = ‘A’.

  int_wa-aedat = sy-datum.

  int_wa-usera = sy-uname.

  int_wa-pgmid = sy-repid.



      nameclass = ‘YCL_INDX_Z1’.

  DATA save TYPE superstrc.

  SELECT * INTO TABLE save-table1 UP TO 100 ROWS FROM dd02l.

  save-str1 = sy.


  cluster->set_data( EXPORTING pid   = ‘ZTEST’

                               pdata = save

                               pwa   = int_wa ).



  DATA load TYPE superstrc.

  DATA rec_wa TYPE indx.

  cluster->get_data( EXPORTING pid   = ‘ZTEST’

                     IMPORTING pdata = load

                               pwa   = rec_wa ).


You must be Logged on to comment or reply to a post.
  • and your idea may also apply to variables saved with other means (I can only think to XML medium using CALL TRANSFORMATION ‘ID’).

    Note: instead of using EXPORT TO DATABASE, you may use EXPORT TO DATA BUFFER xstring (since 6.20) then write it to a normal database table with a RAWSTRING field. That simplifies the reading.

    • Thanks for the tip about export to data buffer. Never thought about that before. But is you want to serialize abap data in XML (xml -> abap) I’d advise to use simple transformation (much, much faster):

      < ?sap.transform simple?>



      called :
      “CALL TRANSFORMATION yglui_xslt_st_id
                   SOURCE root = my_data
                   RESULT XML my_serialized_data.”

      • You may just use the “ID” transformation: faster as it doesn’t even call the transformation object (whatever it is simple transformation or XSLT)
        • I did some testing and the ST above is 10 times faster than CALL TRANSFORMATION ID.

          I call it this way:
                SOURCE root = lt_data
                RESULT XML lv_str.

          is there a way for the transformation object not to be loaded?

          • Jerome, I forgot that ID is an existing transformation object, and just saw that it was defined as XSLT type (thought it was like a Kernel call). So I made a test on my 7.0 SP 13, by transforming 1 million lines of T100 table. ST: 27.2 seconds; XSLT: 27.4 seconds (I always get this slight difference). How do you get 10 times faster?
    • I’m not clear on what you ask me.

      But seeing the theme of ‘Transformation’, I ocurreo following.
      The problem with the instructions ABAP EXPORT / IMPORT are somewhat inflexible. But if you carry the data as XML would be a good solution, the complex would create apartir dynamic XML data. Save in the Cluster would not matter.
      It would be very interesting to implement it.

  • that would be best I think to centralize type definition in the dedicated class (YCL_INDX_Z1), so that you may use it from different programs
    • The structure is superstrc example you can use any structure to work.

      ycl_driver_cluster class uses a single data variable, but this can include almost any complex data estructuta. if this structure is in the dictionary would be best that could be created to handle any data variable.

      • I meant we can move the SUPERSTRC type in your example from program to class, so that the type is defined at one place and can be used by any program that needs to access that cluster.

        class YCL_INDX_Z1 definition

        public section.
        interfaces YIF_CLDB_0001.
             BEGIN OF superstrc,
               str1   TYPE sy,
               table1 TYPE tdd02l,
             END OF superstrc.

        In the program:
          DATA save TYPE YCL_INDX_Z1=>superstrc.

        • It is not necessary that Class conosca superstrc type.

          Who must know the type superstrc are programs.

          Por Ejemplo:
          BEGIN OF superstrc,
            str1 TYPE sy,
            table1 TYPE tdd02l,
          END OF superstrc.

          BEGIN OF sUBstrc,
            SIZE TYPE I,
          END OF superstrc.

          BEGIN OF superstrc2,
             INFO  TYPE  superstrc
             DOC1  TYPE  sUBstrc,
             DOC2  TYPE  sUBstrc,
          END OF superstrc.

          DATA SAVE1 TYPE TABLE OF superstrc2.

          DATA SAVE2 TYPE superstrc.

            cluster->set_data( EXPORTING pid   = ‘TABDOC1’ ” Anything
                                         pdata = SAVE1 ).

            cluster->set_data( EXPORTING pid   = ‘INFO’ ” Anything
                                         pdata = SAVE2 ).

          … OTHER PROGRAM

          BEGIN OF TLOAD,
            str1 TYPE sy,
            table1 TYPE tdd02l,
          END OF TLOAD.


          cluster->get_data( EXPORTING pid   = ‘TABDOC1’
                               IMPORTING pdata = LOAD
                                         pwa   = rec_wa ).