What does it do? A subtemplate tmpl> (defined with tt:template>>) can be called in any other template using the ST statement tt:apply>. The subtemplate is processed at this point when the including template is executed.
If custom data roots are declared using tt:root>> in the called subtemplate, they can be set with the ST statement tt:with-root>. The optional attribute ref> can then not be specified in the statement tt:apply>. tt:with-root> sets the data root of the name specified in name> to the node specified in ref> or binds the data root to the ABAP data object currently bound to the specified node. If ref> is not specified, the current node of the calling template is used. Local data roots to which no node is bound remain undefined, that is, they do not refer to an ABAP data object. At the beginning of a subtemplate of this type, the current node is undefined.
If no custom data roots are declared using tt:root>> in a subtemplate tmpl >, the root node of the tree structure of the called subtemplate is set either explicitly with the optional attribute ref> or implicitly to the current node of the calling template at the call position.
If formal parameters are declared using tt:parameter>> in the called subtemplate, the statement tt:with-parameter> can be used to associate them with actual parameters. As actual parameters, ref> can be used to specify data roots, var> to specify variables, and val> to specify values>. Depending on the type of formal parameter, the values of the specified actual parameters are either passed in the call or copied when the subtemplate ends (see example below). In this case, pass by parameter can be seen as a special case of assignment, which means that the same principle applies as to tt:assign>>:
An assignment with data nodes as the target is possible only in deserializations.
An assignment with data nodes as the source is possible only in serializations.
ABAP_EXAMPLE_VX5 - Without Pass by Parameter The following Simple Transformation contains two templates: a main template TEMP_MAIN> and a subtemplate TEMP_SUB> without its own data roots. The subtemplate is bound to the main template seven times with tt:apply>. The current node previously set with tt:ref> is passed. This ST program DEMO_ST_APPLY1>> can transform a nested structure symmetrically. TRNS DEMO_ST_APPLY1 The following ABAP program can call the transformation: ABEXA 01713 The result of the serialization is the following: < week> < 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, result> has the same content as struc >. The Simple Transformation below DEMO_ST_APPLY2>> 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 TEMP_SUB> has its own data root here, local>, to which another data node tt.apply> is passed in each include. TRNS DEMO_ST_APPLY2 The Simple Transformation below DEMO_ST_APPLY3>> also has the same function as the ones before. In this case, subtemplate TEMP_SUB> has two separate data roots, local1> and local2>, to which data nodes are passed in statement tt.apply >. This example demonstrates local data roots and their addressing. In a real case, subtemplates are used reuse code and make Simple Transformations clearer. TRNS DEMO_ST_APPLY3 ABAP_EXAMPLE_END
ABAP_EXAMPLE_VX5 - With Pass by Parameter The transformation below DEMO_ST_APPLY4 >> shows how parameters are passed to a subtemplate. TRNS DEMO_ST_APPLY4 The result of the transformation is: < X0> < X1>1 < /X1> < X2>3 < /X2> < X3>1 < /X3> < /X0>> The input parameter PARA1> is changed in the subtemplate, but the changed value is not returned to the actual parameter VARI1>. The output parameter PARA2> is set to the value of actual parameter VARI3>, which is passed to the subtemplate, and this value is returned to the actual parameter VARI2>. The input/output parameter PARA3> is set to the value of actual parameter VARI1>, which is passed to the subtemplate, and this value is returned to the actual parameter VARI3>. ABAP_EXAMPLE_END