Show TOC Start of Content Area

Procedure documentation Creating Actions  Locate the document in its SAP Library structure

Use

You can create your own actions using the GP design time API. The interface also allows you to assign callable objects for display and execution to the actions you implement and to define input and output parameter structures for them.

Prerequisites

You have instantiated the IGPDesigntimeUpdateManager. For more information, see Instantiating the Design Time Manager.

Procedure

       1.      Implement the action by providing its basic data:

Note

You need to specify a category for the newly-created action. For this purpose, you can create a new category or provide the Id of an existing one.

Example

Creating an Action

import com.sap.caf.eu.gp.process.api.IGPCategory;

import com.sap.caf.eu.gp.process.api.GPProcessFactory;

import java.util.Locale;

import com.sap.caf.eu.gp.context.api.IGPUserContext;

import com.sap.caf.eu.gp.process.api.IGPModifiableAction;

import com.sap.caf.eu.gp.process.dt.api.IGPDesigntimeManager;

import com.sap.caf.eu.gp.process.dt.api.IGPDesigntimeUpdateManager;

 

// instantiate the design time manager to get the root category

IGPDesigntimeManager dtManager = GPProcessFactory.getDesigntimeManager();

IGPCategory root = dtManager.getRootCategory(userContext);

 

// create a new category “test” in the root category

IGPCategory cat = manager.createCategory("test", "A test category", root);

String aName = "Action";

String aDescription = "A test action";

 

// create an action in the “test” category

IGPModifiableAction a = manager.createAction(

                                    Locale.getDefault(),

                                    aName,

                                    aDescription,

                                    cat.getID()

                                    );

 

       2.      Assign callable objects to the action.

You can assign two separate objects to one action:

       Callable object for execution (mandatory)

       Callable object for display

You should explicitly copy the input and output parameters of the object for execution to:

       The input and output parameter context of the action

       The local parameter context of the action

Once you have a copy of the parameters, you should also map them. Make sure that you also define the appropriate mappings between the existing callable objects. For more information, see Implementing Parameter Mapping.

Example

Assigning Execution Callable Object to an Action

import com.sap.caf.eu.gp.structure.api.IGPStructureInfo;

import com.sap.caf.eu.gp.co.api.IGPCallableObject;

 

IGPModifiableAction a = null;

IGPCallableObject co = null;

     

try {

   // create the callable object and the action

   ...

   // save and activate the callable object     

   manager.save(co);

   manager.activate(co);

  

   // assign execution object to the action  

   a.setExecuteCallableObject(co);

 

   // copy object’s input parameters to action’s input

   IGPStructureInfo in = co.getInputParameters();

   a.setInputParameters(in);

  

   // copy object’s output parameters to action’s output     

   IGPStructureInfo out = co.getOutputParameters();

   a.setOutputParameters(out);

  

   // retrieve action’s local context

   IGPStructureInfo local = a.getLocalParameters();

  

   // copy object’s input and output to action’s local context

   ...

        

   // save changes to local context      

   a.setLocalParameters(local);

   // save the action      

   manager.save(a);        

} finally {

   if (a != null) {

      // release the action

      manager.release(a);

   }

   if (co != null) {

      // release the callable object

      manager.release(co);

   }

}

Note

For more information on how to create callable objects, see Creating Callable Objects.

The result states and exceptions of the callable object for execution are automatically copied from the object to the action. You can obtain information about them using the following methods:

Example

Accessing Action’s Result States and Exceptions

import com.sap.caf.eu.gp.process.api.IGPResultStateInfo;

import com.sap.caf.eu.gp.process.api.IGPProcessExceptionInfo;

 

IGPResultStateInfo[] rs = a.getResultStates();

IGPProcessExceptionInfo[] pe = a.getProcessExceptions();

 

 

The callable object for display is used to provide information about the action after it is completed. Unlike the execution callable object, the display callable object cannot change the state of the action, that is, modify its output parameters. Therefore, you only need to map its input parameters to the output of the callable object for execution.

Example

Assigning Display Callable Object to an Action

    

// assign display object to the action

a.setDisplayCallableObject(dco);

 

Note

The methods setExecuteCallableObject()and setDisplayCallableObject()remove any previously defined mappings for the callable objects.

       3.      Optionally, you can replace the callable objects for execution and display using the following methods:

Example

Replacing Callable Objects in an Action

 

a.replaceExecuteCallableObject(exco);

a.replaceDisplayCallableObject(dco);

 

Note

The methods replaceExecuteCallableObject()and replaceDisplayCallableObject()preserve the mappings defined for the callable objects.

       4.      If the callable objects have been assigned and are not null, they can be accessed through the action in the following way:

Example

Accessing the Callable Objects for Execution and Display

 

IGPCallableObject exco =

a.getExecuteCallableObject().getCallableObject();

IGPCallableObject dispco =

a.getDisplayCallableObject().getCallableObject();

 

       5.      Define additional input and output parameters for the action:

Example

Defining Input and Output Parameters

import com.sap.caf.eu.gp.structure.api.IGPAttributeInfo;

 

// get input parameters structure

IGPStructureInfo in = a.getInputParameters();

  

// add structure “customer” and set its multiplicity

IGPStructureInfo customer = in.addStructure("customer", a.getTitle() + "_input");

customer.setMultiplicity(IGPAttributeInfo.MULITIPLICITY_1_1);

 

// add attributes to the structure  

customer.addAttribute("first_name", IGPAttributeInfo.BASE_STRING);

customer.addAttribute("last_name", IGPAttributeInfo.BASE_STRING);

customer.addAttribute("address", IGPAttributeInfo.BASE_STRING);

customer.addAttribute("organization_id", IGPAttributeInfo.BASE_UNSIGNED_INT);

     

// save the input structure

a.setInputParameters(in);

     

// get output parameters structure

IGPStructureInfo out = a.getOutputParameters();

  

// add structure “order” and set its multiplicity

IGPStructureInfo order = out.addStructure("order", a.getTitle() + "_output");

order.setMultiplicity(IGPAttributeInfo.MULITIPLICITY_0_N);

 

// add attributes to the structure        

order.addAttribute("product_id", IGPAttributeInfo.BASE_UNSIGNED_INT);

order.addAttribute("quantity", IGPAttributeInfo.BASE_UNSIGNED_INT);

order.addAttribute("price", IGPAttributeInfo.BASE_FLOAT);

 

// save the output structure        

a.setOutputParameters(out);

 

 

       6.      Make sure you save and release the action after you have created and modified it.

   

manager.save(a);

manager.release(a);

 

 

Result

Once you have created an action, you can:

      Include it in a block. See Creating Blocks.

      Open it for editing. See Editing GP Development Objects.

      Delete it from the database if you no longer need it. See Deleting GP Development Objects.

      Include it in the process flow as an ad-hoc item. For more information, refer to Including Additional Functionality.

 

End of Content Area