Using Generated External Proxy in Application
Service
The external generated proxy is automatically created code which can be used to call an external operation.
To be able to execute such an operation from a custom application service method, you need to add a dependency with the imported external service and call its methods through the generated proxy.
To use the generated proxy, do the following:
...
1. Import an external service into your project.
For more information, see Modeling External Services
2. Add the external service as a dependency to the application service.
For more information, see Dependencies Tab Page
3. Create a custom method in the application service and enter code for the generated proxy to execute the external function.
You import the external service BAPI_SALESORDER_CREATEFROMDAT2 and the created custom method is called method01().
To execute the external function, enter the following code:
// @@custom code start - method01()
// ...
/* Assign the local interface to the external service using the following syntax: * <formatted_externalservice_operation>Local xxx = get<formatted_externalservice_operation>(); */
BAPI__SALESORDER__CREATEFROMDAT2Local bapi = getBAPI__SALESORDER__CREATEFROMDAT2();
/* Set up the input: *<external_services_package>.<formatted_external_service_name>.input.Parameters.<formatted_externalservice_operation> */
com.sap.rfc_np_test.extsrv.bapi__salesorder__createfromdat2.input.Parameters.BAPI__SALESORDER__CREATEFROMDAT2 input = new com.sap.rfc_np_test.extsrv.bapi__salesorder__createfromdat2.input.Parameters.BAPI__SALESORDER__CREATEFROMDAT2();
/* Set up the output:
*<external_services_package>.<formatted_external_service_name>.output.Parameters.<formatted_externalservice_operation>_dot_Response output; */
com.sap.rfc_np_test.extsrv.bapi__salesorder__createfromdat2.output.Parameters.BAPI__SALESORDER__CREATEFROMDAT2_dot_Response output;
/* If the input parameter is a table/Collection, create it as an ArrayList */ ArrayList items = new ArrayList(); com.sap.rfc_np_test.extsrv.bapi__salesorder__createfromdat2.input.Parameters.BAPI__SALESORDER__CREATEFROMDAT2.ORDER__ITEMS__IN.BAPISDITM i = new com.sap.rfc_np_test.extsrv.bapi__salesorder__createfromdat2.input.Parameters.BAPI__SALESORDER__CREATEFROMDAT2.ORDER__ITEMS__IN.BAPISDITM();
/* To set parameters, use: */
i.setITM__NUMBER("010"); i.setMATERIAL("MaterialCode"); items.add(0, i); com.sap.rfc_np_test.extsrv.bapi__salesorder__createfromdat2.input.Parameters.BAPI__SALESORDER__CREATEFROMDAT2.ORDER__ITEMS__IN order = new com.sap.rfc_np_test.extsrv.bapi__salesorder__createfromdat2.input.Parameters.BAPI__SALESORDER__CREATEFROMDAT2.ORDER__ITEMS__IN();
order.setItem(items);
input.setORDER__ITEMS__IN(order);
/* Execution */ try{ output = bapi.BAPI__SALESORDER__CREATEFROMDAT2(input); }catch(Exception e){ throw new ServiceException(e); }
/* use the returned result as the logic requires */
// @@custom code end - method01()
|