sap:external-function

Use

Using the statement sap:external-function you can declare a function for ABAP calls from within XPath. In contrast to sap:call-external, only one single return value can be specified for the method call. For this purpose, the method to be called must be declared in the top level of the XSLT program as an external function.

Functions declared in this way can be used for method calls in XPath expressions.

Functions of this type always use their own namespace (not XSLT or SAP-XSLT namespace).

Declaration Syntax

... For instance methods:

<sap:external-function name="prefix:fName" method="instanceMethod" kind="instance">

   <sap:argument      param="PARAM_1"/>

   <sap:argument      param="PARAM_2"/>

      ...

   <sap:result        param="RESULT"      type="xslType"/>

</sap:external-function>

... For class methods:

<sap:external-function name="prefix:fName" "className" method="classMethod" kind="class">

   <sap:argument      param="PARAM_1"/>

   <sap:argument      param="PARAM_2"/>

      ...

   <sap:result        param="RESULT"      type="xslType"/>

</sap:external-function>

... For constructors:

<sap:external-function name="prefix:new" "className" kind="constructor">

   <sap:argument      param="PARAM_1"/>

   <sap:argument      param="PARAM_2"/>

      ...

</sap:external-function>

Description

With the exception of the constructor declaration, the attribute method outputs the name of the ABAP method to be called. The attribute kind defines, in addition, whether you have an instance or class method, or a constructor. For class methods and constructors, the name of the ABAP class is output using the attribute class.

The list of function arguments is declared using the sub-statement sap:argument (with consideration of the sequence). The names of the corresponding ABAP parameters are specified using the attribute param.

Calls of instance and class method can define a return value using the sub-statement sap:result. The name of the return parameter is specified through the attribute param. Optionally, you can assign a particular XSLT type (string, number, boolean, node-set, or external) to the result using the attribute type.

Syntax for Calls in XPath Expressions

Declared functions can be used in XPath expressions for ABAP calls. With instance methods, the first function argument must be identified using an ABAP object.

Example:

<xsl:value-of    select="prefix:f1($x,99,'abc')"/>

In the example given, the function with the name prefix:f1 defines an ABAP call using an instance method that passes the two values 99 and 'abc' as input parameters. The first function argument $x identifies the required ABAP object.

If you are using a suitable declared constructor function, this call can also be written alternatively as follows:

<xsl:value-of    select="prefix:f1(prefix:new('xyz'),99,'abc')"/>