Skip to Content

I tried searching a lot on sdn for getting some step by step procedure for consuming an external service like RFC or webservice in CAF. I got some help from here and there so I thought of putting it together at one place so that it could help the beginners in CAF. Rather than putting in words I thought of putting it in the form of video as we always say “ACTION SPEAKS MORE THAN WORDS.”

Code to be added in getUserDetails method of the application service.

java.lang.String CAF_user = sessionContext.getCallerPrincipal().getName();

java.lang.String CAF_methodHeader = ESAppServiceBean.JARM_REQUEST + “:” + “getUserDetails(java.lang.String)”; Object[] CAF_parameters = new Object[] {id};

com.sap.caf.rt.util.CAFPublicLogger.entering(CAF_user, ESAppServiceBean.JARM_REQUEST, CAF_methodHeader, ESAppServiceBean.location, CAF_parameters);

com.sap.esproj1.appsrv.datatypes.UserData retValue;

try {

//@@custom code start – getUserDetails(java.lang.String)

retValue = null;

// Create data container for Input-Parameter and fill it.

BAPI__USER__GET__DETAIL

params = new BAPI__USER__GET__DETAIL();

params.setUSERNAME(id);

 

// Get reference to the object representing the external service call.

 

BAPI__USER__GET__DETAILLocal bapi_local = this.getBAPI__USER__GET__DETAIL();

try {

// Call the BAPI.

// Return value of this method call contains all the data that the BAPI returns.

BAPI__USER__GET__DETAIL_dot_Response result = bapi_local.BAPI__USER__GET__DETAIL(params);

 

// Retrieve the address structure out of the result data container.

BAPIADDR3 addr =

result.getADDRESS();

 

// Fill the application services return structure.

retValue = new UserData();

retValue.setFirstName(addr.getFIRSTNAME());

retValue.setLastName(addr.getLASTNAME());

 

} catch (Exception e) {

e.printStackTrace();

throw new ServiceException(e);

}

//@@custom code end – getUserDetails(java.lang.String)

return retValue;} finally {

com.sap.caf.rt.util.CAFPublicLogger.exiting(CAF_user, ESAppServiceBean.JARM_REQUEST, CAF_methodHeader, ESAppServiceBean.location, CAF_parameters);

}

 

Code to be added to the webdynpro’s Submit action for the view.

QESAppServiceGetUserDetails element = ESAppServiceProxy.createGetUserDetailsQuery();

com.sap.tc.col.client.generic.api.IStructure inputparameter = element.getInputParameterStructure();

inputparameter.setAttributeValue(“id”,wdContext.currentContextElement().getId());

wdContext.nodeQESAppServiceGetUserDetails().bind(element);

element.execute();

wdContext.nodeResult().invalidate();

 

Regards,

Murtuza

To report this post you need to login first.

1 Comment

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

Leave a Reply