Skip to Content

Developing Web Dynpro Java callable object implementing the GP Interface in Netweaver CE has been significantly changed from Netweaver 7.0(04s). Unlike Netweaver 7.0 the Interface controller is not used anymore to implement the GP interface methods. Those are implemented in the component controller. I’ll explain here the steps to implement the callable object in a Web Dynpro application in Netweaver CE.

Create a new Web Dynpro DC (local or NWDI based). Select the project right-click and select Development Component -> Show in Component Navigator.

Component BrowserComponent Browser

Select the Web Dynpro component just created in the component navigator and right-click and select the option Add DC Dependency.

Add DC Dependency

Select com.sap.security.api.sda from SC ENGINEAPI and caf/eu/gp/api and caf/eu/gp/api/wd from GP-CORE.

Select Dependent DC

Click Next and select Design Time, Deploy Time and Run Time dependency for all the three DCs.

Select Dependency Type

Click on Finish. Now create a new component. Uncheck the options Default Windows and Views and select the option Implemented Interfaces.

Create Component

Click on Next. In the next screen click on Add on Implemented Component Interfaces section and select IGPWebDynproCO interface to implement.

Add Interface

A new window gets created which is mapped with the interface view WebDynproCOInterfaceView. Click on Finish. A dialog displays the objects created by implementing the GP interface.

Objects CreatedObjects Created

Click on Ok and open the component controller. Two methods of the GP interface execute() and getDescription() have got created there which should be implemented.

GP Interface Methods

To implement GP interface methods add the following declaration in the “others” section at the end of the component controller.

//@@begin others
   private IGPExecutionContext executionContext;
   private IWDTextAccessor textAccessor;
//@@end

In the getDescription() method the input and output parameters of the callable object should be declared.

public com.sap.caf.eu.gp.co.api.IGPTechnicalDescription getDescription(java.util.Locale locale)
  {
    //@@begin getDescription()





    try {
         this.textAccessor = wdComponentAPI.getTextAccessor();





         GPWebDynproResourceAccessor resourceAccessor = new GPWebDynproResourceAccessor(textAccessor);        
         IGPTechnicalDescription technicalDescription =  GPCallableObjectFactory.createTechnicalDescription("CO_NAME", "CO_DESCRIPTION",
                                                                                   resourceAccessor, locale);
          // Pre-existing input structure
         IGPStructureInfo input = technicalDescription.getInputStructureInfo();
         IGPAttributeInfo param1 = input.addAttribute("Param1", IGPAttributeInfo.BASE_STRING);
         param1.setMultiplicity(IGPAttributeInfo.MULITIPLICITY_1_1);
         //Pre-existing structure for output parameters
         IGPStructureInfo output = technicalDescription.getOutputStructureInfo();
          //Create the attributes in the output structure
         IGPStructureInfo outputStructure = output.addStructure("OutputStructure");
         outputStructure.addAttribute("OPParam1", IGPAttributeInfo.BASE_STRING);
         outputStructure.addAttribute("OPParam2", IGPAttributeInfo.BASE_STRING);
           //add result state
         IGPCOResultStateInfo approve = technicalDescription.addResultState("Approve");
         approve .setDescriptionKey("Request Approved");  
         IGPCOResultStateInfo reject = technicalDescription.addResultState("Reject");
         reject.setDescriptionKey("Request Rejected");  
         return technicalDescription;
      } catch (GPInvocationException e) {
         logger.logT(Severity.ERROR, Category.APPLICATIONS,  "Incorrect technical name");
         logger.traceThrowableT(Severity.ERROR, "Exception while creating technical description: ", e);
         return null;
      }
    //@@end
 }

In the above method the input and output structures of the GP callable object is defined. The input and output can have both single parameter or structure as well. The cardinality of the structure can also be specified here. For more details on how to define the multi-cardinality GP parameters refer this blog : How To Pass Multiple Line Items Data Between Web Dynpro Java Callable Objects in GP.

In the execute() method implement the logic for callable object execution in GP context.

public void execute( com.sap.caf.eu.gp.co.api.IGPExecutionContext executionContext )
  {
    //@@begin execute()
      String param1 = null;
      try {
         this.executionContext = executionContext;
 
         //Process the input parameters   
         IGPStructure input = executionContext.getInputStructure();
         param1 = (String) input.getAttributeAsString("Param1");
         wdContext.currentContextElement().setParam1(param1); 
 
         //implement any addtional logic
 
      } catch (GPInvocationException e) {
         String localizedMessage = textAccessor.getText("ERROR_GETTING_PARAMETERS"); 
         wdThis.wdFireEventTechnicalException(
            new GPTechnicalCallableObjectException(
               logger,
               localizedMessage,
               e));
      } 
     //@@end
 }

In the above method the input parameter is read from the GP context and set the values in the Web Dynpro context as required.

Also implement another method in the component controller to complete the step execution.

public void complete( )
  {
    //@@begin complete()
      try {
         IGPStructure output = executionContext.getOutputStructure();
 
         //Set the values of the output parameters
         IGPStructure opStructure = output.addStructure("OutputStructure");            
         opStructure.setAttributeValue("OPParam1", wdContext.currentContextElement().getOPParam1());
         opStructure.setAttributeValue("OPParam2", wdContext.currentContextElement().getOPParam2());
         executionContext.setResultState("Approve");
         executionContext.processingComplete();
 
      } catch (GPInvocationException e) {
         String localizedMessage = textAccessor.getText("ERROR_SETTING_PARAMETERS"); 
         wdThis.wdFireEventTechnicalException(
            new GPTechnicalCallableObjectException(
               logger,
               localizedMessage,
               e));
      } catch (GPEngineException e) {
         String localizedMessage = textAccessor.getText("INTERNAL_ERROR"); 
         wdThis.wdFireEventTechnicalException(
            new GPTechnicalCallableObjectException(
               logger,
               localizedMessage,
               e));
      }
    //@@end
 }
 

In the above method the output structure of the GP context is set with the values from the Web Dynpro context node and the resultstate of the callable object is also set. Call this method from an action of the Web Dynpro view e.g. a complete button when the step execution needs to be completed.

Once a Web Dynpro Java component is implemented as a GP callable object implementing the GP interface it cannot be tested as a stand-alone application as no interface views are available. To test the Web Dynpro application create a new callable object in GP design time of type Web Dynpro Java (GP Interface) and select the Web Dynpro component after build and deploy. Test it from the callable object test environment in GP design time.

To report this post you need to login first.

8 Comments

You must be Logged on to comment or reply to a post.

  1. Pablo Lopez
    Good one, I was thinking about where the “Used DCs” were but now I see this has changed a bit.

    One think, you forgot to specify the creation of the context attributes:

    Param1
    OPParam1
    OPParam2

    Cheers

    (0) 
    1. Dipankar Saha Post author
      Hi,
      Thanks for the comment.
      I’ haven’t shown the creation of Web Dynpro context attribute in blog explicitly, as the feature remains same in CE 7.1 as in the previous release of Netweaver.

      Thanks,
      Dipankar

      (0) 
  2. Christiaan Pistorius
    Hi Dipankar,

    Thank you for the excellent blog.

    Just one question:

    I am having troubles with caf/eu/gp/api/wd. I cannot use it as a DC dependancy!  I keep getting errors when I try to add it as a DC dependancy.  When I have a look at this DC in the Component Explorer I see it has a Warning message saying “Dependancies to Depricated components exist”.  This is true, because when I have a look at the Dependancies of the DC itself, most of its Dependancies have little red crosses pictures associated with them…  I am using NWDS 7.1 SP01.  Was this a known error with this SP??  ALso, I am not currently using NWDI so all my DCs lie in “My COmponents”.

    Please advise.

    Christiaan

    (0) 
    1. Dipankar Saha Post author
      Hi,
      It seems to be there are some issues with the installation of NWDS in your local environment. You can try to Sync Used DCs from the context menu option in Component Navigator. If that doesn’t work may you can reinstall NWDS or upgrade to a higher SP such as SP5/6 which are more stable.
      Thanks,
      Dipankar
      (0) 
  3. Alex Lau
    Hi Dipankar,

    Your blog on CE7.1 is really helpful. The recent release of CE7.1 EhP1 seems to be a even better implementation. It seems that we don’t need to code so much to handle the GP context and the CAF context. (I found that most of the code needed in CE7.1 is gone.) Will you try to summarize up these new changes in a new blog? It will be very helpful to developers worldwide. Thanks in advance.

    Regards,
    Alex

    (0) 
    1. Dipankar Saha Post author
      Hi,
      Implementing Web Dynpro callable object for GP remains same as well in CE 7.1 EHP1. There is no change whatsoever according to the help documentation and what I’ve tried out myself.
      However, implementing Web Dynpro component for using as Human Activity in NW BPM is different and it needs very minimal coding compared to GP callable object. It just requires an event to be present in the interface controller along with the required context node which are used in the process. I’ll document that soon in a blog.

      Thanks,
      Dipankar

      (0) 
  4. Christiaan Pistorius
    Hi there,

    Tks for an excellent blog.  But, I have one problem.

    I do not seem to get the GP input parameters when I do :
             IGPStructure input = executionContext.getInputStructure();
             param1 = (String) input.getAttributeAsString(“Param1”);
             wdContext.currentContextElement().setParam1(param1);

    More specifically, when I query wdContext.currentContextElement after setting the Param1 value to it – it appears to be empty..

    I know this because I try to use its contents later on before I submit a BAPI call.  The BAPI call returns nothing with the following code:

    wdContext.currentHeaderElement().setIncident(wdContext.currentContextElement().getParam1());

    I know the BAPI works because if I hard code a Param1 value I get data to my View.

    Please advise.

    Christiaan

    (0) 
    1. Dipankar Saha Post author
      This can happen due to lot of reasons. First check whether you have defined the GP parameter mapping correctly in GP design time and whether the values are available in the GP context from the GP Monitor in NWA. If that’s okay you can check the context node in Web Dynpro whether it’s instantiated properly. Also check whether you have defined the GP context attribute in the callable object just under the root or you have defined a wrapper structure. In the sample code only the root GP context is accessed.

      Thanks,
      Dipankar

      (0) 

Leave a Reply