Skip to Content

A
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.

 

image

Help
SAP…

For

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

‘Z1’.

!https://weblogs.sdn.sap.com/weblogs/images/251794841/image002.jpg|height=252|alt=Export|align=middle|width=369|src=https://weblogs.sdn.sap.com/weblogs/images/251794841/image002.jpg!

The ABAP
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.

<a name=”DRIVER” title=”DRIVER”></a><a name=”_YCL_DRIVER_CLUSTER” title=”_YCL_DRIVER_CLUSTER”></a>YCL_DRIVER_CLUSTER

class YCL_DRIVER_CLUSTER definition

  public

  final

  create public .

 public components of class YCL_DRIVER_CLUSTER

 do not include other source files here!!!

public section.

  methods CONSTRUCTOR

    importing

      !NAMECLASS type ANY optional

      !TABLE type ANY optional

      !REGION type ANY optional

    preferred parameter NAMECLASS

    exceptions

      ERROR_CREATE .

  methods DELETE_DATA

    importing

      !PID type ANY .

  methods SET_DATA

    importing

      !PID type ANY

      !PDATA type ANY

      !PWA type ANY optional .

  methods GET_DATA

    importing

      !PID type ANY

    exporting

      !PDATA type ANY

      !PWA type ANY

      !PTYPE type ANY .

  class-methods DET_CLUSTER_TABLE_AREA

    importing

      !TABLE type ANY

      !REGION type ANY

    returning

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

    exceptions

      NO_FOUND .

  methods GET_DATA_TYPE

    importing

      !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

    importing

      !PDATA type ANY .

  methods CLEAR_ALL .

Code Methods

 components of interface YIF_CLDB_0001

interface YIF_CLDB_0001

  public .

  methods R_EXPORT

    importing

      !PID type ANY

      !PDATA type ANY

      !PWA type ANY

      !PINFO type ANY .

  methods R_IMPORT

    importing

      !PID type ANY

    exporting

      !PDATA type ANY

      !PINFO type ANY

      !PWA type ANY .

  methods R_DELETE

    importing

      !PID type ANY .

  methods R_DDIC

    importing

      !PID type ANY

    returning

      value(PINFO) type STRING .

endinterface.

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

class YCL_INDX_Z1 definition

  public

  final

  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.

ENDMETHOD.

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.

ENDMETHOD.

METHOD yif_cldb_0001~r_delete.

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

  MOVE pid TO sid.

  DELETE FROM DATABASE

               indx(z1)    “Just Change this by redefining

               ID sid.

ENDMETHOD.

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

ENDMETHOD. 

h1. PROGRAM ytest_cluster_01.

PROGRAM ytest_cluster_01.

START-OF-SELECTION.

  TYPES:

    tdd02l TYPE STANDARD TABLE OF dd02l WITH DEFAULT KEY,

     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.

  CREATE OBJECT cluster

    EXPORTING

      nameclass = ‘YCL_INDX_Z1’.

  DATA save TYPE superstrc.

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

  save-str1 = sy.

  BREAK-POINT.

  cluster->set_data( EXPORTING pid   = ‘ZTEST’

                               pdata = save

                               pwa   = int_wa ).

  BREAK-POINT.

*************************************************************

  DATA load TYPE superstrc.

  DATA rec_wa TYPE indx.

  cluster->get_data( EXPORTING pid   = ‘ZTEST’

                     IMPORTING pdata = load

                               pwa   = rec_wa ).

  BREAK-POINT.

To report this post you need to login first.

10 Comments

You must be Logged on to comment or reply to a post.

  1. Sandra Rossi
    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.

    (0) 
    1. Jerome Proost
      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.”

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

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

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

          (0) 
          1. Sandra Rossi
            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?
            (0) 
    2. Daniel Esteves Post author
      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.

      (0) 
  2. Sandra Rossi
    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
    (0) 
    1. Daniel Esteves Post author
      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.

      (0) 
      1. Sandra Rossi
        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.

        Result:
        class YCL_INDX_Z1 definition

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

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

        (0) 
        1. Daniel Esteves Post author
          It is not necessary that Class conosca superstrc type.

          Who must know the type superstrc are programs.

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

          BEGIN OF sUBstrc,
            SIZE TYPE I,
            FILE TYPE TABLE OF SUCHAR20,
            FILENAME TYPE STRING,
          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

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

          DATA SAVE2 TYPE TLOAD.

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

          (0) 

Leave a Reply