Skip to Content

  I was given a situation in a project to make F4 Search Help through the Object Value Selector. Although it seems to be having the same logic as in case we use a Remote Function Call (RFC) or a Bapi but still after I discover how to do it actually its somehow different in case of  a web service. the difference might be because the structure when we import a adaptive web service model or a Adaptive RFC Model is slightly different .Also the labels and the table headers come automatically from Bapi’s /RFC in case of a Adaptive RFC Model,But in Adaptive Web Service Model we need to manually write some lines of code to fulfil the requirement.

 So in an easy way I will explain you the simple steps in case you need to implement it through a web service.

Problem

The problem is to implement OVS value help through a Web service.The whole implementation is done in Web Dynpro for java CE SP03.

Prerequisites

I. Create Web Dynpro local development component.

II. Import the Web Service as Adaptive Web Service Model. Make sure you have created the metadata and modeldata destinations in the Net weaver Administrator in the Web Application Server(WAS) where you are going to deploy the whole application.

III. Create Web Dynpro Custom Controller in which the model is added in the using the template.

IV. Create a view with the input field for which the F4 is called.

I have used a web service in which a single method is there whose input is a search term (String) and output as User ID and User Name. The service provides a wild card ‘*’search .The service after importing in the custom controller the following context can be seen:

!https://weblogs.sdn.sap.com/weblogs/images/251836024/ContextOVSCC.gif|height=201|alt=image|width=481|src=https://weblogs.sdn.sap.com/weblogs/images/251836024/ContextOVSCC.gif|border=0!”

Where SearchTerm is request or input under the node Request_UserF4Help,

            UserID and UserName are the response attributes present in the Response node under the following hierarchy Response – UserList – UserListChild.

As per Web Dynpro guidelines, we cannot use the model nodes directly to the view. For this reason a value node “User”similar to the model node is made in the custom controller .The context Structure of the same is

!https://weblogs.sdn.sap.com/weblogs/images/251836024/Valuenode.gif|height=1|alt=|width=1|src=https://weblogs.sdn.sap.com/weblogs/images/251836024/Valuenode.gif|border=0!ValueNode

Where SearchTerm is for request and UserData is response node.

The same value node is dragged to the view controller context. The input field in view layout where the F4 help is required is binded with the SearchTerm attribute of the User value node.

View

Now the implementation of Custom Controller

Firstly add the following in the //begin —//others

private IWDOVSContextNotificationListener ovsListener =
        new OVSDemoContextNotificationListener(“searchTerm”);

Now add three methods in the Custom Controller

Methods

Add following code in

1. getOVSInputNode():
                         return wdContext.nodeUser();
2. getOVSListener():
                         return ovsListener;
3. getOVSOutputNode( ):
                        return wdContext.nodeUserData();

To implement an OVS Search help we need to implement the IWDOVSContextNotificationListener interface in a class and override three methods namely:

1. public void onQuery(IWDNodeElement queryInputNodeElement, IWDNode queryOutputNode)

{

}

2. public void applyResult(IWDNodeElement applicationNodeElement, IWDNodeElement queryOutputNodeElement)
{
}
3. public void applyInputValues(
            IWDNodeElement applicationNodeElement,
            IWDNodeElement queryInputNodeElement)
{
}

Add the following code in each of the three as follows:

public void onQuery(IWDNodeElement queryInputNodeElement, IWDNode queryOutputNode) {
                  IPublicUserModelController.IUserElement input =  (IPublicUserModelController.IUserElement) queryInputNodeElement;      
            IPublicUserModelController.IUserDataNode output =   (IPublicUserModelController.IUserDataNode) queryOutputNode;
            Request_UserF4Help bapiInput = new Request_UserF4Help(model);
             wdContext.nodeRequest_UserF4Help().bind(bapiInput);
              bapiInput.setSearchTerm(input.getSearchTerm());
            try {
              bapiInput.execute();
              usermodel.UserList outputList = bapiInput.getResponse().getUserList();
                          for(int i=0;i<wdContext.nodeUserListChild().size();i++){
                  IPublicUserModelController.IUserListChildElement userListElem = (IPublicUserModelController.IUserListChildElement)wdContext
.nodeUserListChild().getElementAt(i);
                  IUserDataElement ul = (IUserDataElement)wdContext.nodeUserData().createElement();
                        ul.setUserID(userListElem.getUserID());
                        ul.setUserName(userListElem.getUserName());
                        wdContext.nodeUserData().addElement(ul);
              }
                         } catch (Exception e) {
              IWDMessageManager msgMgr = wdComponentAPI.getMessageManager();
msgMgr.reportException(e.getLocalizedMessage(), false);        
            }
                public void applyResult(IWDNodeElement applicationNodeElement, IWDNodeElement queryOutputNodeElement) {
                        IPrivateOvs_erepCompView.IUserElement ovsCallerNodeElement =
                    (IPrivateOvs_erepCompView.IUserElement) applicationNodeElement;
                        IPublicUserModelController.IUserDataElement output = (IPublicUserModelController.IUserDataElement)queryOutputNodeElement;
                        ovsCallerNodeElement.setSearchTerm(output.getUserName());
                    }
          public void applyInputValues(
            IWDNodeElement applicationNodeElement,
            IWDNodeElement queryInputNodeElement) {
            Object initialValue = applicationNodeElement.getAttributeValue(“searchTerm”);
            queryInputNodeElement.setAttributeValue(“searchTerm”, initialValue);
          }
        }

The implementation of custom controller is now done. Finally add the following code in the View controller

      wdInit():

IWDAttributeInfo[] ovsStartUpAttributes = {
                      wdContext.nodeUser().getNodeInfo().getAttribute(“searchTerm”)};
                    IWDOVSContextNotificationListener listener =
                wdThis.wdGetUserModelControllerController().getOVSListener();
                        WDValueServices.addOVSExtension(“UserData”,
                        ovsStartUpAttributes,
                      wdThis.wdGetUserModelControllerController().getOVSInputNode(),
                      wdThis.wdGetUserModelControllerController().getOVSOutputNode(),
                      listener);

When you run this application you are now able to see the F4 symbol attchaed to the input field,But still you are unable to see a window title and fields labels and column headers in the popup when you click the icon .For this add the following code in the wdInit() of the custom controller:

IWDAttributeInfo info = wdContext.nodeUser()
       .getNodeInfo()
       .getAttribute(IUserElement.SEARCH_TERM);
info.getModifiableSimpleType().setFieldLabel(“User Name”);
IWDAttributeInfo infoout = wdContext.nodeUserData()
                        .getNodeInfo()
            .getAttribute(IUserDataElement.USER_ID);
IWDAttributeInfo infoout1 = wdContext.nodeUserData()
.getNodeInfo()
.getAttribute(IUserDataElement.USER_NAME);
infoout.getModifiableSimpleType().setColumnLabel(“User ID”);
infoout1.getModifiableSimpleType().setColumnLabel(“User Name”);

After running the applications you are now able to see the F4 symbol attached with the input field and on click of it a popup can be seen.

The running application :!https://weblogs.sdn.sap.com/weblogs/images/251836024/output.gif|height=39|alt=Output|width=264|src=https://weblogs.sdn.sap.com/weblogs/images/251836024/output.gif|border=0!

which on click will show you a popup

!https://weblogs.sdn.sap.com/weblogs/images/251836024/outputpopup.gif|height=308|alt=Popup|width=269|src=https://weblogs.sdn.sap.com/weblogs/images/251836024/outputpopup.gif|border=0!</body>

To report this post you need to login first.

1 Comment

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

  1. Ridouan Taibi
    Hi,

    Thanks for sharing.

    Could you please explain the next line?
    usermodel.UserList outputList = bapiInput.getResponse().getUserList();

    Is usermodel a reference to the Response Node?

    Thanks,
    Ridouan

    (0) 

Leave a Reply