Wilco Menge
Read all my blogsTrick 1: Use AET fields in Conditions
When you create additional fields with the AET you get a lot for free: The fields are automatically available in the Web UI, SAP GUI, reporting and other places.
But what if you also want to use an AET field in a Schedule Condition or Start Condition?
The Condition editor uses BOR objects and fortunately it is easy to add AET (and EEWB) fields to these objects. Suppose you have created the following field in the AET:
In order to use this field you have to add it to the relevant BOR object. Navigate to your (Schedule or Start) Condition to identify the correct BOR object type (in this case BUS2000126):
The newly created subtype is shown:
Go to the Change Mode, Click on Attributes and then on Create:
(Choose Yes)
Select the relevant table and field and confirm:
After release and activation, the attribute is available in the BOR object:
The final step is to mark the subtype ZTEST00126 as the default delegation type of the standard BUS2000126 object (see also http://blog.acorel.nl/2011/01/adding-attributes-to-bor-object.html):
The end result is that the new attribute is now available in the Condition Editor:
Now you can use the new attribute in a condition
Trick 2: Using Condition Badi’s
The Workflow-style conditions as shown above give you a lot of tools to express your start and schedule conditions, especially if you correctly enhance it by adding new attributes, relations and methods. However sometimes you just *need* the power of some real ABAP. For example: You need to perform a complex query or you need to able to determine the moon phase (by using the AERIS Weather API at http://www.aerisweather.com/develop/)
You can change the Rule Type on the action from Workflow Conditions to Conditions Using Business Addins:
There are two Badi definitions available:
- EVAL_SCHEDCOND_PPF For schedule conditions
- EVAL_STARTCOND_PPF For start conditions
Below is a sample implementation for a start condition that evaluates to true only during full moon:
cl_http_client
=>create_by_url(EXPORTING url = ‘http://api.aerisapi.com/sunmoon/moonphases/?client_id=fNX30mfEtYwcotdtukt2f&client_secret=U17uOcV7MN9AC2fvEPbETRBoHHNfOWLkpZ11xcj1’
IMPORTING client = DATA(lo_client)
).
lo_client
->send( ).lo_client->receive( ).
IF lo_client->response->get_cdata( ) CS ‘full moon’.
ep_rc = 0. ” Trigger condition
ELSE.
ep_rc = 1. ” Do not trigger condition
ENDIF.
lo_client
->close( ).ENDMETHOD.
This Badi can be assigned to the Condition set of an action:
When using Condition Badi’s, there are two important considerations:
- The rule type can only be defined on the level of the Action Definition. This means that both the Schedule condition and Start condition of an action must be of the same type. They are both either Workflow conditions or Badi condition. So for example: you cannot use a Workflow condition for the schedule condition and a Badi condition for the Start condition within the same action
- Keep the performance of the Badi’s in mind: The badi’s are executed more often than you’d think (during viewing, editing and saving of transactions, during bulk editing of transactions, during execution of SPPFP). This means that doing an actual web service call as in the example probably isn’t the best idea ever.