Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
Xiao-fei_Song
Product and Topic Expert
Product and Topic Expert
0 Kudos
511

In the previous blog post, we have demonstrated how to execute complex OData queries against a mobile destination of SAP Mobile Services using Mobile Backend Tools in a Visual Studio Code Environment. As a mobile developer, one of the major responsibilities of coding the mobile app is to code the OData access using programming languages like swift, kotlin and Java, etc. In this blog post, we will demonstrate how to generate OData client code directly from OData queries.

In SAP Mobile Backend Tools, open the mobile destination metadata document using OData CSDL Modeler, and then click the "Generate Test Client" toolbar button like below:

2024-06-04_12-15-50.png

Choose a directory to hold the test client:

2024-06-04_12-18-27.png

Click "Generate" button in the dialog, Mobile Backend Tools will generate the test client for this OData services:

2024-06-04_12-20-35.png

After the generation has been complete, click "Open" button to open the test client in the specified directory:

2024-06-04_12-22-53.png

You can open a test client called "PurchaseOrderFindByQuery" like below, you will be able to see the generate client code:

2024-06-04_12-23-44.png

Inside Mobile Backend Tools environment, you can directly execute the test client. You can do that by clicking the "Execute" button:

2024-06-04_12-25-11.png

And you will see the response from the backend system in the console after execution of the test client is complete:

2024-06-04_12-25-53.png

You can also create a test client by supplying an OData query. In order to do that, click the "Add" button in the top right corner:

2024-06-04_12-28-47.png

For example In the popup dialog, we can use below OData query as the input.

"PurchaseOrder?$filter=CreatedByUser eq 'CB9980000026' and PurchasingOrganization eq '1710' and Supplier eq '17300001' and PricingDocument eq '1000000340'&$expand=_PurchaseOrderItem($expand=_DeliveryAddress,_PurchaseOrderInvoicingPlan,_PurchaseOrderItemNote),_PurchaseOrderNote".

In case you want to generate mobile client code for the above OData query, copy the OData URL and paste it to the Visual Studio information window:

2024-06-04_12-30-18.png

Press enter key to accept the test case name, Mobile Backend Tools will generate the test client for this OData query in swift, kotlin and Java:

2024-06-04_12-32-05.png2024-06-04_12-33-43.png2024-06-04_12-34-15.png

Click the "Execute" button to execute the test case, and you will be able to see the response from the backend system:

2024-06-04_12-35-54.png

In summary, as a mobile developer, if you need to code a mobile app that needs to access the backend system through SAP Mobile Services using OData queries, you can generate the client code directly using SAP Mobile Services Mobile Backend Tools as well as OData CSDL Tools and test the generated code directly in the Visual Studio Code environment.