This is number 6 in a series of blogs on ABAP OO for workflow, so you it would be a really good idea to make sure you have worked through the first 5 blogs. The examples we'll use here continue on from those we used in the earlier blogs.
Here's the list of the earlier blogs:
A functional method is a method that returns a single result, i.e. a method that has a Returning parameter. Typically a functional method calculates a value, e.g. you might use a functional method to return the number of entries in a table, or the formatted name of an employee or whatever. The method can have importing parameters, but does not have any other exporting parameters.
Here's a simple example using the same ABAP Class we used for the exercises in the previous blogs. This is a static method that retrieves a list of plants relevant for a nominated country. Here are the parameters:
And the method code - as you can see it's a very simple example.
METHOD plants_of_country. SELECT werks FROM t001w INTO TABLE et_plants WHERE land1 = iv_country. ENDMETHOD.
One advantage of functional methods over virtual attributes is that you can pass importing parameters. You can derive your calculation from the class instance (assuming you are using an instance method of course) and the importing parameters. However its a fairly simple mechanism so its easy to use this for simple parameters that can be hardcoded into the workflow, but you may still need to call the functional method as the main method of a normal task if you want to dynamically set the parameters.
You can use a functional method in much the same way as an object attribute. For example: in a container operation, or as the source of a binding.
Here's an example where a functional method is used in container operation:
When selecting your functional method from the drop down look for the "methods" or "functional methods" section within the object. For example this is what the drop down on the Expression field of the Container Operation above looks like:
This is the format for passing importing parameters.
&ZCL_PLANT.PLANTS_OF_COUNTRY(IV_COUNTRY='DE')&
If you have multiple parameters, just separate them with an ampersand (&).
Note: You can't use functional methods with importing parameters directly in logical expressions as yet (you can select them but an error is returned) - as the condition editor does not provide a way to enter the parameter values. So in this case, use your functional method in a container operation first, then use the derived container element in your logical expression.
You can use a functional method in much the same way as an object attribute in a task, for example in the subject text of a task or in the binding to a method, with one exception:
You can't call a functional method directly from the long text of a task.
This is a SAPScript restriction not a workflow restriction - i.e. SAPScript doesn't know how to call a functional method to build the text. However this is not a major problem as you can always create an import container element to hold the result of the functional method in your task, and then in the binding source the container element from your functional method. The example below gives an idea of what such a binding would look like.
Yes of course you can use a functional method as the main method of a task, and then it behaves exactly like any other method called from a task. This could be helpful if you need to handle exceptions for that particular workflow, or if it's simply easier to build that way as for this particular workflow you need to pass many/complex importing parameters.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
13 | |
10 | |
10 | |
9 | |
7 | |
6 | |
5 | |
5 | |
5 | |
4 |