Purpose Use the "expand" feature of the OData interface
WIth the "expand" parameter in "OData.Read" you can retrieve related entities (navigation properties) together with the main entity in a single OData call, instead of requiring separate requests for each related entity set. For example, expanding to_MaintenanceOrderOperation on a maintenance order returns the order together with all its operations in one response.
For each navigation property, the result list must contain a matching GuiXT table variable; only the columns defined in that table variable are read from the corresponding OData entity.
In "OData.Update" and "OData.Create" the analogous mechanism can be used to update or create related entities. In these calls the API parameter is called "navigation".
As a first example, we read a single purchase order. Use the ODataTool of the Script editor Pro to find the right service, to preview the live data, select the eight columns and generate the structure and table variables.
We use a structure variable for the purchase order header and a table variable for the items. Then we execute the "OData.Read" and display the result:
We now want add the supplier's number, name, city and country. This is another "expand" entity "PurchaseOrderSupplierAddress". We add it to our "OData.Read" and display the supplier info in the GuiXT Script:
Please observe that the expand property is "_SupplierAddress", starting with an underscore. The name of the corresponding GuiXT structure variable - in this case, "SupplierAddress" -can be chosen freely.
If there are errors, such as an invalid "expand" property, the Script Editor Pro displays the SAP error message for the service request:
For the payment terms, in the example "NT30," the API_PURCHASEORDER_2 service does not provide any descriptive text. However, we can use another OData service - I_PAYMENTTERMSTEXT - to retrieve the text. The best way to test this is to run a quick test in the OData Tool of Script Editor Pro and then have it generate the structure and access methods:
We now want add the supplier's number, name, city and country. This is another "expand" entity "PurchaseOrderSupplierAddress". We add it to our "OData.Read" and display the supplier info in the GuiXT Script: