Example of Using Simple Transformations in SAP

Example of Using Simple Transformations in SAP

In this note, I will walk through a simple example of using Simple Transformations in SAP. Alongside creating the transformation itself, we’ll also look at how to call it from an ABAP program.

What is Simple Transformation in SAP?

Simple Transformation (ST) is a proprietary programming language developed by SAP to describe the "inner workings" of SAP in XML. It's called a transformation because it converts SAP ABAP data into XML. Let’s leave the definition of “ABAP data” to the reader's discretion.

See: Simple Transformations

Simple Transformations, or ST, is a proprietary SAP language for transforming ABAP data to XML (serialization) and XML back into ABAP data (deserialization).

The process of converting ABAP data to XML is called serialization. The reverse process is called deserialization.

Example of Creating a Simple Transformation in SAP

In transaction SE80, go to the context menu: Create → Other (1) → Transformation

Alternatively, you can create a new transformation in transaction STRANS.

Define the structure of the future XML by writing the new transformation.

See: ST Program Structure

Don’t forget to activate the changes you've made.

Example of Calling a Simple Transformation from an ABAP Program

You can call an ST using the CALL TRANSFORMATION statement.

See: CALL TRANSFORMATION

Effect:
This statement calls the specified XSL transformation (XSLT) or simple transformation (ST). The data source is specified after SOURCE, and the output is assigned after RESULT. You can pass parameters via PARAMETERS, and use OPTIONS to define transformation options.

Here’s a demo program for this note:

REPORT ztsf_run_1.
DATA: lv_xml TYPE string,
      lt_zzz LIKE ztqualif.

FIELD-SYMBOLS: <fs_zzz> TYPE ztqualif.

SELECT * FROM ztqualif
  INTO TABLE @DATA(result1).

CALL TRANSFORMATION z_demo_tsf_1
  SOURCE qualifications = result1 "root element of your ST
  RESULT XML lv_xml.

cl_abap_browser=>show_xml( xml_string = lv_xml ). "serialization

LOOP AT result1 ASSIGNING <fs_zzz>. "deserialization
  WRITE: <fs_zzz>-qualification_id,
         <fs_zzz>-qualification_name,
         <fs_zzz>-qualification_scale.
ENDLOOP.


Let’s test it.

0:00
/0:27
See: Example

Note: When calling CALL TRANSFORMATION, be sure to use the root element of your transformation in the SOURCE parameter.

And here’s what happens if you don’t follow that rule…

0:00
/0:43

As always, with love. Yours, ignatov.