Quantcast
Channel: SCN : All Content - SAP Gateway
Viewing all articles
Browse latest Browse all 2823

ODATA SERVICE FOR PURCHASE ORDER using RFC

$
0
0

Let discuss the PO creation steps using gateway services in detail.

Step1. Open Tcode SEGW and create a project as shown in below.

1.png

Give the details as shown  below .

2.png

Step 2. Create the first entity by importing an RFC interface. For this right-click on Data Model and choose Import -> RFC/BOR Interface.

3.png

Step 3. Enter the following values in the wizard and then choose next:

 

Entity Type Name

PurchaseOrder

Target System

Local

Data Source Type

Remote Function Calls

Data Source Name

bapi_po_getdetail

4.png

Step 4. Expand the PO_HEADER node and select the following fields:
POHEADER,COMPANYCODE,DOC_CAT,DOC_TYPE,STATUS,VENDOR,PURCH_ORG,PUR_GROUP and Choose Next.



5.png

Step 5. In the first line, PO_NUMBER, select the field Is Key and choose Finish:

6.png

Step 6. Create the second entity again by importing an RFC interface. Right-click Data Model and choose Import -> RFC/BOR Interface

7.png

Step 7. Enter the following values in the wizard and choose next:

 

Entity Type Name

PurchaseOrderItem

Target System

Local

Data Source Type

Remote Function Calls

Data Source Name

BAPI_PO_GETITEMS   

8.png

Step 8. Expand the PO_ITEMS node and select the following fields:
po_item,material,pur_mat,mat_grp,net_price,price_unit,disp_quan
Choose Next.

     9.png

10.png

Step 9.Now our project has 2 entities – one for the Purchase Order and one for the Purchase Order Item. As a next step we create entity-sets out of these entities. Expand the node Data Model and double-click Entity Sets:

Name

Entity Type Name

PurchaseOrderSet

PurchaseOrder

PurchaseOrderItemSet

PurchaseOrderItem

11.png

Step 10.Now the basic definition of the Model is done. As a next step we can generate the necessary runtime artifacts.

a.     Click on the Generate pushbutton:

b.     Leave the default values and choose Enter:

12.png

Please note the Technical Service Name ZPURCHASEORDER_SRV is equal to the External Service Name required to consume this service later on. 

c .Choose Local Object.

d. Runtime objects have been generated successfully now.

  Step 11.Now we can Register and Activate the Service.

a. Double-click Service Maintenance

13.png

b. Select system EC7 and click on the Register button. Please note that the entries listed here depend on the System Alias configuration you have done in the SAP Net Weaver Gateway Implementation Guide (IMG). In a local deployed environment (Backend and Hub components deployed on the same box) you might also find “LOCAL” with the RFC destination “NONE” here

14.png

c. Confirm the warning message displayed in the popup: click yes

d.Press F4 to select the system alias. Select LOCAL from the input held.

e.Confirm the Select System Alias popup: click ok

f. Leave the default values and enter $tmp as the package and choose Enter:

15.png

The External Service Name is defaulted with the Technical Service Name from the Generation Step

g. Verify that the service has been registered and activated successfully:

16.png

Step 12.Now we can run our service the first time. Please note that we’ve only maintained the basic model data so far. As a consequence we can access the metadata of the service,

a. Open a new window, start transaction /IWFND/GW_CLIENT.

b. Enter URI:  /sap/opu/odata/sap/ ZPURCHASEORDER_SRV/$metadata and choose Execute

17.png

Step 13.ZPURCHASEORDER_SRV is External Service Name that was registered before.

We have created a Service Builder Project with two entities and two entity-sets. We have generated the runtime artifacts and registered and activated our OData service.

Step 14.Now we will map the data provider to bring life into our OData service.

(i)Get the PO header data

  • We will start with the Query method for the PurchaseOrderSet entity-set. Expand the node Service Implementation -> PurchaseOrderSet and right-click GetEntity (Read) and select Map to Data Source:

18.png

  • In the map to data source window, enter the following values and choose Enter:

Target System

Local

Data Source Type

Remote Function Call

Data Source Name

bapi_po_getdetail

19.png

  • Map the output parameters by dragging the fields from the model on right side. Also create an input parameter for providing the PO to the RFC. Choose Enter:

Mapping will look like,

20.png

Then Save.

We are done with getting the PO header details.

(ii). Now, we need to get the lines item based on given purchase order number.

For this, we will create operation in entity set PurchaseOrderItemSet.

  • We will start with the Query method for the PurchaseOrderItemSet entity-set.
  • Expand the node Service Implementation - PurchaseOrderItemSet and right-click GetEntitySet (Query) and select Map to Data Source:

21.png

  • Provide Data source name as ‘BAPI_PO_GETITEMS’ and Data source type as ‘Remote Function Call’.
  • Map the output parameters by dragging the fields from the model on right side. Also create an input parameter for providing the PO to the RFC. Choose Enter:

22.png

  • Regenerate the artifacts.

Testing the Service:

Select the registered service and click on gateway client.

23.png

Sample Case 1: For getting PO HEADER DATA provide

/sap/opu/odata/SAP/ZPURCHASEORDER_SRV/PurchaseOrderSet('3000000004') and click on execute.

24.png

25.png

Sample Case 2: For getting PO ITEM DATA provide /sap/opu/odata/SAP/ZPURCHASEORDER_SRV/PurchaseOrderItemSet?$filter=PoNumber eq '3000000004' and click on execute

26.png

27.png


Viewing all articles
Browse latest Browse all 2823

Trending Articles