[go: up one dir, main page]

0% found this document useful (0 votes)
194 views9 pages

SAP RAP Purchase Order Guide

This document provides a step-by-step guide to create a Purchase Order application using SAP RAP in the Eclipse ADT environment. It covers prerequisites, creating ABAP packages and database tables, defining CDS views, behavior definitions, and service bindings. The final section includes an object name reference table and instructions for testing the OData service for managing Purchase Orders and their items.

Uploaded by

Jaya Sankar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
194 views9 pages

SAP RAP Purchase Order Guide

This document provides a step-by-step guide to create a Purchase Order application using SAP RAP in the Eclipse ADT environment. It covers prerequisites, creating ABAP packages and database tables, defining CDS views, behavior definitions, and service bindings. The final section includes an object name reference table and instructions for testing the OData service for managing Purchase Orders and their items.

Uploaded by

Jaya Sankar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd

# SAP RAP Purchase Order Example Using Eclipse ADT

## Prerequisites

- SAP S/4HANA (1909+) or SAP BTP ABAP Environment

- Eclipse IDE with ABAP Development Tools (ADT) installed

- ABAP developer access

---

## 1. Create an ABAP Package

1. In Eclipse, right-click your system → **New → ABAP Package**

2. Name: `Z_RAP_PO`

3. Add a description. Assign a transport request.

---

## 2. Create Database Tables

### 2.1 Purchase Order Header Table

1. Right-click package → **New → Other ABAP Repository Object → Database Table**

2. Name: `ZPO_HEADER`
3. Example fields:

- `PO_ID` (Key, NUMC10)

- `VENDOR` (CHAR20)

- `ORDER_DATE` (DATS)

```abap

PO_ID NUMC10 Key

VENDOR CHAR20

ORDER_DATE DATS

```

### 2.2 Purchase Order Item Table

1. Right-click package → **New → Database Table**

2. Name: `ZPO_ITEM`

3. Example fields:

- `PO_ID` (Key, NUMC10) - Foreign key to `ZPO_HEADER`

- `ITEM_NO` (Key, NUMC6)

- `MATERIAL` (CHAR20)

- `QUANTITY` (DEC10,2)

```abap

PO_ID NUMC10 Key

ITEM_NO NUMC6 Key

MATERIAL CHAR20
QUANTITY DEC10,2

```

---

## 3. Create CDS Views

### 3.1 Interface Views

#### Purchase Order Header Interface View (`ZI_PO_HEADER`)

```abap

@[Link]: 'ZVPOHDR'

@[Link]: 'Purchase Order Header'

@ObjectModel: { semanticKey: ['PO_ID'] }

define view entity ZI_PO_HEADER as select from ZPO_HEADER {

key PO_ID,

VENDOR,

ORDER_DATE

```

#### Purchase Order Item Interface View (`ZI_PO_ITEM`)

```abap
@[Link]: 'ZVPOITM'

@[Link]: 'Purchase Order Item'

@ObjectModel: { semanticKey: ['PO_ID', 'ITEM_NO'] }

define view entity ZI_PO_ITEM as select from ZPO_ITEM {

key PO_ID,

key ITEM_NO,

MATERIAL,

QUANTITY

```

### 3.2 Projection Views

#### Purchase Order Header Projection (`ZC_PO_HEADER`)

```abap

@[Link]: 'Purchase Order Header Projection'

define view entity ZC_PO_HEADER as projection on ZI_PO_HEADER {

key PO_ID,

VENDOR,

ORDER_DATE

```

#### Purchase Order Item Projection (`ZC_PO_ITEM`)


```abap

@[Link]: 'Purchase Order Item Projection'

define view entity ZC_PO_ITEM as projection on ZI_PO_ITEM {

key PO_ID,

key ITEM_NO,

MATERIAL,

QUANTITY

```

---

## 4. Define Composition (Header-Item)

- In the **ZI_PO_HEADER** view, add a composition to items:

```abap

define view entity ZI_PO_HEADER as select from ZPO_HEADER

composition [0..*] of ZI_PO_ITEM as _Items

key PO_ID,

VENDOR,

ORDER_DATE,

_Items
}

```

- In **ZI_PO_ITEM**, define association to header if needed.

---

## 5. Define Behavior Definitions

### 5.1 Purchase Order Header Behavior

```abap

managed implementation in class zbp_zi_po_header unique;

define behavior for ZI_PO_HEADER alias poheader

persistent table ZPO_HEADER

lock master

composition of ZI_PO_ITEM { items }

create;

update;

delete;

association _Items { create; }

```
### 5.2 Purchase Order Item Behavior

```abap

define behavior for ZI_PO_ITEM alias poitem

persistent table ZPO_ITEM

lock dependent by poheader

create;

update;

delete;

```

---

## 6. Implement Behavior Classes (Optional)

- Add custom business logic in the generated behavior implementation classes (`ZBP_ZI_PO_HEADER`).

---

## 7. Create Service Definition and Service Binding

### Service Definition


```abap

@[Link]: 'Purchase Order Service Definition'

define service ZUI_PO {

expose ZC_PO_HEADER;

expose ZC_PO_ITEM;

```

### Service Binding

- Right-click the service definition → **New Service Binding**

- Choose OData V4, name it (e.g., `ZUI_PO_O4`), and activate.

---

## 8. Test the Service

- Open the Service Binding object.

- Use “Preview” or test the OData endpoint.

- You will see the Purchase Order with items in a Fiori Elements app or OData client.

---

## Object Name Reference Table


| Object Type | Example Name |

|-------------------------|------------------|

| Package | Z_RAP_PO |

| Table | ZPO_HEADER |

| Table | ZPO_ITEM |

| CDS Interface View | ZI_PO_HEADER |

| CDS Interface View | ZI_PO_ITEM |

| CDS Projection View | ZC_PO_HEADER |

| CDS Projection View | ZC_PO_ITEM |

| Behavior Definition | ZI_PO_HEADER |

| Behavior Definition | ZI_PO_ITEM |

| Service Definition | ZUI_PO |

| Service Binding | ZUI_PO_O4 |

---

**You can now create, read, update, and delete Purchase Orders and their Items via OData!

Let me know if you need code snippets, screenshots, or have questions on a specific step.**

You might also like