SAP ST TT APPLY
Get Example source ABAP code based on a different SAP table
ARTICLE
Syntax
[<(><<)>tt:with-root name='root1' [ref='node1'] />
<(><<)>tt:with-root name='root2' [ref='node2'] />
...]
[<(><<)>tt:with-parameter name='para1'
[ref='node1'|val='val1'|var='var1'] />
<(><<)>tt:with-parameter name='para2'
[ref='node2'|val='val2'|var='var2'] />
...]
<(><<)>/tt:apply>
Effect
A subtemplate
Examples Without Parameter Passing
The following Simple Transformation contains two templates: a main template
xmlns:tt='http://www.sap.com/transformation-templates'>
<(><<)>tt:root name='ROOT'/>
<(><<)>tt:template name='TEMP_MAIN'>
<(><<)>week>
<(><<)>day1 tt:ref='ROOT.DAY1'>
<(><<)>tt:apply name='TEMP_SUB' />
<(><<)>/day1>
<(><<)>day2 tt:ref='ROOT.DAY2'>
<(><<)>tt:apply name='TEMP_SUB' />
<(><<)>/day2>
<(><<)>day3 tt:ref='ROOT.DAY3'>
<(><<)>tt:apply name='TEMP_SUB' />
<(><<)>/day3>
<(><<)>day4 tt:ref='ROOT.DAY4'>
<(><<)>tt:apply name='TEMP_SUB' />
<(><<)>/day4>
<(><<)>day5 tt:ref='ROOT.DAY5'>
<(><<)>tt:apply name='TEMP_SUB' />
<(><<)>/day5>
<(><<)>day6 tt:ref='ROOT.DAY6'>
<(><<)>tt:apply name='TEMP_SUB' />
<(><<)>/day6>
<(><<)>day7 tt:ref='ROOT.DAY7'>
<(><<)>tt:apply name='TEMP_SUB' />
<(><<)>/day7>
<(><<)>/week>
<(><<)>/tt:template>
<(><<)>tt:template name='TEMP_SUB'>
<(><<)>name>
<(><<)>tt:value ref='$ref.name' />
<(><<)>/name>
<(><<)>work>
<(><<)>tt:value ref='$ref.work' />
<(><<)>/work>
<(><<)>/tt:template>
<(><<)>/tt:transform>
The following ABAP program can call the transformation:
name TYPE string,
work(1) TYPE c,
END OF day.
DATA: BEGIN OF week,
day1 TYPE day,
day2 TYPE day,
day3 TYPE day,
day4 TYPE day,
day5 TYPE day,
day6 TYPE day,
day7 TYPE day,
END OF week.
DATA xml_string TYPE string.
DATA result LIKE week.
week-day1-name = 'Monday'. week-day1-work = 'X'.
week-day2-name = 'Tuesday'. week-day2-work = 'X'.
week-day3-name = 'Wednesday'. week-day3-work = 'X'.
week-day4-name = 'Thursday'. week-day4-work = 'X'.
week-day5-name = 'Friday'. week-day5-work = 'X'.
week-day6-name = 'Saturday'. week-day6-work = ' '.
week-day7-name = 'Sunday'. week-day7-work = ' '.
CALL TRANSFORMATION ...
SOURCE root = week
RESULT XML xml_string.
CALL TRANSFORMATION ...
SOURCE XML xml_string
RESULT root = result.
The result of the serialization is the following:
<(><<)>day1>
<(><<)>name>Monday<(><<)>/name>
<(><<)>work>X<(><<)>/work>
<(><<)>/day1>
<(><<)>day2>
<(><<)>name>Tuesday<(><<)>/name>
<(><<)>work>X<(><<)>/work>
<(><<)>/day2>
<(><<)>day3>
<(><<)>name>Wednesday<(><<)>/name>
<(><<)>work>X<(><<)>/work>
<(><<)>/day3>
<(><<)>day4>
<(><<)>name>Thursday<(><<)>/name>
<(><<)>work>X<(><<)>/work>
<(><<)>/day4>
<(><<)>day5>
<(><<)>name>Friday<(><<)>/name>
<(><<)>work>X<(><<)>/work>
<(><<)>/day5>
<(><<)>day6>
<(><<)>name>Saturday<(><<)>/name>
<(><<)>work/>
<(><<)>/day6>
<(><<)>day7>
<(><<)>name>Sunday<(><<)>/name>
<(><<)>work/>
<(><<)>/day7>
<(><<)>/week>
After deserialization,
The simple transformation below has the same function as the previous one and can be called with the same result using the specified ABAP program. In contrast to the transformation in the previous example, subtemplate
xmlns:tt='http://www.sap.com/transformation-templates'>
<(><<)>tt:root name='ROOT'/>
<(><<)>tt:template name='TEMP_MAIN'>
<(><<)>week>
<(><<)>day1>
<(><<)>tt:apply name='TEMP_SUB'>
<(><<)>tt:with-root name='local' ref='ROOT.DAY1' />
<(><<)>/tt:apply>
<(><<)>/day1>
<(><<)>day2>
<(><<)>tt:apply name='TEMP_SUB'>
<(><<)>tt:with-root name='local' ref='ROOT.DAY2' />
<(><<)>/tt:apply>
<(><<)>/day2>
<(><<)>day3>
<(><<)>tt:apply name='TEMP_SUB'>
<(><<)>tt:with-root name='local' ref='ROOT.DAY3' />
<(><<)>/tt:apply>
<(><<)>/day3>
<(><<)>day4>
<(><<)>tt:apply name='TEMP_SUB'>
<(><<)>tt:with-root name='local' ref='ROOT.DAY4' />
<(><<)>/tt:apply>
<(><<)>/day4>
<(><<)>day5>
<(><<)>tt:apply name='TEMP_SUB'>
<(><<)>tt:with-root name='local' ref='ROOT.DAY5' />
<(><<)>/tt:apply>
<(><<)>/day5>
<(><<)>day6>
<(><<)>tt:apply name='TEMP_SUB'>
<(><<)>tt:with-root name='local' ref='ROOT.DAY6' />
<(><<)>/tt:apply>
<(><<)>/day6>
<(><<)>day7>
<(><<)>tt:apply name='TEMP_SUB'>
<(><<)>tt:with-root name='local' ref='ROOT.DAY7' />
<(><<)>/tt:apply>
<(><<)>/day7>
<(><<)>/week>
<(><<)>/tt:template>
<(><<)>tt:template name='TEMP_SUB'>
<(><<)>tt:context>
<(><<)>tt:root name='local' />
<(><<)>/tt:context>
<(><<)>name>
<(><<)>tt:value ref='local.name' />
<(><<)>/name>
<(><<)>work>
<(><<)>tt:value ref='local.work' />
<(><<)>/work>
<(><<)>/tt:template>
<(><<)>/tt:transform>
The Simple Transformation below also has the same function as the ones before. In this case, subtemplate
xmlns:tt='http://www.sap.com/transformation-templates'>
<(><<)>tt:root name='ROOT'/>
<(><<)>tt:template name='TEMP_MAIN'>
<(><<)>week>
<(><<)>day1>
<(><<)>tt:apply name='TEMP_SUB'>
<(><<)>tt:with-root name='local1' ref='ROOT.DAY1.NAME' />
<(><<)>tt:with-root name='local2' ref='ROOT.DAY1.WORK' />
<(><<)>/tt:apply>
<(><<)>/day1>
<(><<)>day2>
<(><<)>tt:apply name='TEMP_SUB'>
<(><<)>tt:with-root name='local1' ref='ROOT.DAY2.NAME' />
<(><<)>tt:with-root name='local2' ref='ROOT.DAY2.WORK' />
<(><<)>/tt:apply>
<(><<)>/day2>
<(><<)>day3>
<(><<)>tt:apply name='TEMP_SUB'>
<(><<)>tt:with-root name='local1' ref='ROOT.DAY3.NAME' />
<(><<)>tt:with-root name='local2' ref='ROOT.DAY3.WORK' />
<(><<)>/tt:apply>
<(><<)>/day3>
<(><<)>day4>
<(><<)>tt:apply name='TEMP_SUB'>
<(><<)>tt:with-root name='local1' ref='ROOT.DAY4.NAME' />
<(><<)>tt:with-root name='local2' ref='ROOT.DAY4.WORK' />
<(><<)>/tt:apply>
<(><<)>/day4>
<(><<)>day5>
<(><<)>tt:apply name='TEMP_SUB'>
<(><<)>tt:with-root name='local1' ref='ROOT.DAY5.NAME' />
<(><<)>tt:with-root name='local2' ref='ROOT.DAY5.WORK' />
<(><<)>/tt:apply>
<(><<)>/day5>
<(><<)>day6>
<(><<)>tt:apply name='TEMP_SUB'>
<(><<)>tt:with-root name='local1' ref='ROOT.DAY6.NAME' />
<(><<)>tt:with-root name='local2' ref='ROOT.DAY6.WORK' />
<(><<)>/tt:apply>
<(><<)>/day6>
<(><<)>day7>
<(><<)>tt:apply name='TEMP_SUB'>
<(><<)>tt:with-root name='local1' ref='ROOT.DAY7.NAME' />
<(><<)>tt:with-root name='local2' ref='ROOT.DAY7.WORK' />
<(><<)>/tt:apply>
<(><<)>/day7>
<(><<)>/week>
<(><<)>/tt:template>
<(><<)>tt:template name='TEMP_SUB'>
<(><<)>tt:context>
<(><<)>tt:root name='local1' />
<(><<)>tt:root name='local2' />
<(><<)>/tt:context>
<(><<)>name>
<(><<)>tt:value ref='.local1' />
<(><<)>/name>
<(><<)>work>
<(><<)>tt:value ref='.local2' />
<(><<)>/work>
<(><<)>/tt:template>
<(><<)>/tt:transform>
Example with Parameter Passing
The transformation below shows how parameters are passed to a subtemplate.
xmlns:tt='http://www.sap.com/transformation-templates'>
<(><<)>tt:variable name='VARI1' val='1'/>
<(><<)>tt:variable name='VARI2' val='2'/>
<(><<)>tt:variable name='VARI3' val='3'/>
<(><<)>tt:template>
<(><<)>tt:apply name='SUB'>
<(><<)>tt:with-parameter name='PARA1' var='VARI1'/>
<(><<)>tt:with-parameter name='PARA2' var='VARI2'/>
<(><<)>tt:with-parameter name='PARA3' var='VARI3'/>
<(><<)>/tt:apply>
<(><<)>X0>
<(><<)>X1>
<(><<)>tt:write var='VARI1'/>
<(><<)>/X1>
<(><<)>X2>
<(><<)>tt:write var='VARI2'/>
<(><<)>/X2>
<(><<)>X3>
<(><<)>tt:write var='VARI3'/>
<(><<)>/X3>
<(><<)>/X0>
<(><<)>/tt:template>
<(><<)>tt:template name='SUB'>
<(><<)>tt:context>
<(><<)>tt:parameter kind='in' name='PARA1' val='4'/>
<(><<)>tt:parameter kind='out' name='PARA2'/>
<(><<)>tt:parameter kind='in/out' name='PARA3'/>
<(><<)>/tt:context>
<(><<)>tt:assign to-var='PARA2' var='PARA3'/>
<(><<)>tt:assign to-var='PARA3' var='PARA1'/>
<(><<)>tt:assign to-var='PARA1' val='555'/>
<(><<)>/tt:template>
<(><<)>/tt:transform>
The result of the transformation is:
<(><<)>X1>1<(><<)>/X1>
<(><<)>X2>3<(><<)>/X2>
<(><<)>X3>1<(><<)>/X3>
<(><<)>/X0>
The input parameter
The output parameter
The input/output parameter