Giter Site home page Giter Site logo

s-rtti's Introduction

S-RTTI

S-RTTI is a set of Serializable classes which wrap the classes of Run Time Type Services (RTTS).

Objective: if your program has to write the values of variables created at run time via RTTS (CREATE DATA <data reference> TYPE HANDLE <type description object>) into a persistent storage or into a XSTRING (and read them), you may also probably want to write and read the types of these variables so that you can restore the variables exactly as they were when you saved the values.

Principle to serialize:

  1. Wrap the type description object into a serializable type description object, via either create_by_rtti:
    DATA(srtti) = zcl_srtti_typedescr=>create_by_rtti( <type description object> ).
    or via create_by_data_object (with an existing data object, i.e. variable, structure, internal table and so on):
    DATA(srtti) = zcl_srtti_typedescr=>create_by_data_object( <variable> ).
  2. Serialize the serializable type description object into a XSTRING variable:
    CALL TRANSFORMATION ID SOURCE srtti = srtti RESULT XML DATA(xstring).

Principle to deserialize:

  1. Deserialize the XSTRING variable into a serializable type description object:
    CALL TRANSFORMATION ID SOURCE XML xstring RESULT srtti = srtti.
  2. Retrieve the type description object from the serializable type description object:
    DATA(rtti) = srtti->get_rtti( ).
  3. Create the data object (no S-RTTI implied here) and manipulate via a field symbol:
    TYPES ty_ref_to_data TYPE REF TO DATA.
    DATA(ref_to_data) = VALUE ty_ref_to_data( ).
    
    CREATE DATA ref_to_data TYPE HANDLE rtti.
    ASSIGN ref_to_data->* TO FIELD-SYMBOL(<any>).

If a type description object has some of its parts based on ABAP Dictionary objects, its deserialization can only work (well) if these objects have not been changed since they were serialized.

Demo program:

REPORT zdemo.
" Serialization of both type and value
DATA variable TYPE c LENGTH 20.
variable = 'Hello world'.
DATA(srtti) = zcl_srtti_typedescr=>create_by_data_object( variable ).
CALL TRANSFORMATION ID SOURCE srtti = srtti
                              dobj  = variable
                       RESULT XML DATA(xstring).

" HERE, XSTRING CONTAINS BOTH THE VARIABLE VALUE (DOBJ) AND ITS SERIALIZABLE RTTS TYPE DESCRIPTION OBJECT (SRTTI).

" Deserialization of type
DATA: srtti2       TYPE REF TO zcl_srtti_typedescr,
      ref_variable TYPE REF TO DATA.
CALL TRANSFORMATION ID SOURCE XML xstring RESULT srtti = srtti2.
DATA(rtti) = CAST cl_abap_datadescr( srtti2->get_rtti( ) ).

" Deserialization of value
CREATE DATA ref_variable TYPE HANDLE rtti.
ASSIGN ref_variable->* TO FIELD-SYMBOL(<variable>).
CALL TRANSFORMATION ID SOURCE XML xstring RESULT dobj = <variable>.

" Verify
ASSERT <variable> = 'Hello world'.

S-RTTI is known to be used by these repositories:

s-rtti's People

Contributors

larshp avatar sandraros avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.