Rap App For Purchase Order
Rap App For Purchase Order
2|Page
Populate and check the table data.
3|Page
2. Create CDS Views
Create a CDS Root View Entity for Purchase Order Header Table
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'CDS View for PO Head'
@Metadata.ignorePropagatedAnnotations: true
@Metadata.allowExtensions: true
define root view entity ZI_PO_HEAD
as select from ztb_po_head
//association [0..*] to ZI_PO_ITMS as _PO_items on $projection.PoNum =
_PO_items.PoNum
composition [0..*] of ZI_PO_ITMS as _PO_items
{
key po_num as PoNum, doc_cat as DocCat, type
as Type, comp_code as CompCode, org as Org,
status as Status, vendor as Vendor, plant as
Plant, create_by as CreateBy,
created_date_time as CreatedDateTime,
changed_date_time as ChangedDateTime,
local_last_changed_by as LocalLastChangedBy,
4|Page
price_unit as PriceUnit,
local_last_changed_by as LocalLastChangedBy,
local_last_changed_at as LocalLastChangedAt,
_po_hd
}
entity: {
name: 'ZI_VEND',
element: 'Vendor'
}}] */
Vendor,
Plant,
CreateBy,
CreatedDateTime,
ChangedDateTime,
LocalLastChangedBy,
/* Associations */
_PO_items : redirected to composition child ZC_PO_ITEMS
5|Page
Create a Projection view for Purchase order Items
@AbapCatalog.viewEnhancementCategory: [#NONE]
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Projection view for PO Items'
@Metadata.ignorePropagatedAnnotations: true
@Metadata.allowExtensions: true
@ObjectModel.usageType:{
serviceQuality: #X,
sizeCategory: #S,
dataClass: #MIXED
}
define view entity ZC_PO_ITEMS as projection on ZI_PO_ITMS
{
key PoNum,
key PoItem,
ItemText,
Material,
Plant,
StorLoc,
@Semantics.quantity.unitOfMeasure: 'uom'
Qty,
Uom,
@Semantics.amount.currencyCode: 'PriceUnit'
ProductPrice,
PriceUnit,
LocalLastChangedBy,
LocalLastChangedAt,
/* Associations */
_po_hd : redirected to parent ZC_PO_HEAD
}
6|Page
4. Create the Behavior Definitions
create;
update;
delete;
field ( readonly :update ) PoNum;
field ( mandatory ) DocCat, CompCode, Org, Status, Vendor;
action ( features : instance ) Change_status result [1] $self;
association _PO_items { create; }
mapping for ztb_po_head
{
PoNum = po_num;
DocCat = doc_cat;
Type = type;
CompCode = comp_code;
Org = org;
Status = status;
Vendor = vendor;
CreateBy = create_by;
CreatedDateTime = created_date_time;
ChangedDateTime = changed_date_time;
LocalLastChangedBy = local_last_changed_by;
}
}
Create a Behavior definition for the Purchase Order Header Projection View
use create;
use update;
use delete;
8|Page
5. Behavior Implementation to perform CRUD operations
Global class-
CLASS zbp_i_po_head DEFINITION PUBLIC ABSTRACT FINAL FOR BEHAVIOR OF zi_po_head.
ENDCLASS.
CLASS zbp_i_po_head IMPLEMENTATION.
ENDCLASS.
Local Class-
CLASS lhc_PO_HD DEFINITION INHERITING FROM cl_abap_behavior_handler.
PRIVATE SECTION.
ENDCLASS.
METHOD get_instance_features.
result =
VALUE #( FOR ls_po IN lt_po_result
( %key = ls_po-%key
%features-%action-Change_status = COND #( WHEN ls_po-status = 'B'
THEN if_abap_behv=>fc-o-
disabled ELSE if_abap_behv=>fc-o-
enabled )
) ).
ENDMETHOD.
METHOD create.
ENDIF.
ENDMETHOD.
METHOD update.
10 | P a g e
DATA : ls_po TYPE zi_po_head,
ls_po_hd TYPE ztb_po_head.
ls_po_hd-org = <lfs_po_hd>-Org.
ENDIF.
** IF <lfs_po_hd>-Plant IS NOT INITIAL.
ls_po_hd-plant = <lfs_po_hd>-Plant.
ENDIF.
** IF <lfs_po_hd>-PoNum IS NOT INITIAL.
ls_po_hd-po_num = <lfs_po_hd>-PoNum.
ENDIF.
* IF <lfs_po_hd>-Status IS NOT INITIAL.
ls_po_hd-status = <lfs_po_hd>-Status.
ENDIF.
* IF <lfs_po_hd>-Type IS NOT INITIAL.
ls_po_hd-type = <lfs_po_hd>-Type.
ENDIF.
* IF <lfs_po_hd>-Vendor IS NOT INITIAL.
ls_po_hd-vendor = <lfs_po_hd>-Vendor.
ENDIF.
*
ENDIF.
11 | P a g e
number = '001'
v1 = 'Invalid Details'
severity = if_abap_behv_message=>severity-
error )
%key-PoNum = <lfs_po_hd>-PoNum
%cid = <lfs_po_hd>-%cid_ref
%update = 'X'
PoNum = <lfs_po_hd>-PoNum )
TO reported-po_hd.
ENDIF.
ENDMETHOD.
METHOD delete.
METHOD read.
ENDMETHOD.
METHOD lock.
ENDMETHOD.
METHOD rba_Po_items.
ENDMETHOD.
METHOD cba_Po_items.
12 | P a g e
DATA : ls_po_items TYPE ztb_po_items.
ELSE.
APPEND VALUE #( %cid = <lfs_po_items>-%cid_ref
PoNum = lv_po
PoItem = ls_items-po_item
) TO failed-po_it.
ENDIF.
ENDMETHOD.
METHOD Change_status.
13 | P a g e
%control-Status = if_abap_behv=>mk-on ) )
FAILED failed
REPORTED reported.
ENDMETHOD.
ENDCLASS.
ENDCLASS.
METHOD finalize.
ENDMETHOD.
METHOD check_before_save.
ENDMETHOD.
METHOD save.
ENDMETHOD.
METHOD cleanup.
ENDMETHOD.
METHOD cleanup_finalize.
14 | P a g e
ENDMETHOD.
ENDCLASS.
Local Class-
CLASS lhc_PO_IT DEFINITION INHERITING FROM cl_abap_behavior_handler.
PRIVATE SECTION.
ENDCLASS.
METHOD update.
15 | P a g e
IF sy-subrc eq 0.
IF <lfs_po_it>-Material IS NOT INITIAL.
<lfs_items>-material = <lfs_po_it>-Material.
ENDIF.
IF <lfs_po_it>-ItemText IS NOT INITIAL.
<lfs_items>-item_text = <lfs_po_it>-ItemText.
ENDIF.
IF <lfs_po_it>-Plant IS NOT INITIAL.
<lfs_items>-plant = <lfs_po_it>-Plant.
ENDIF.
IF <lfs_po_it>-ProductPrice IS NOT INITIAL.
<lfs_items>-product_price = <lfs_po_it>-ProductPrice.
ENDIF.
IF <lfs_po_it>-PriceUnit IS NOT INITIAL.
<lfs_items>-price_unit = <lfs_po_it>-PriceUnit.
ENDIF.
IF <lfs_po_it>-Qty IS NOT INITIAL.
<lfs_items>-qty = <lfs_po_it>-Qty.
ENDIF.
IF <lfs_po_it>-Uom IS NOT INITIAL.
<lfs_items>-uom = <lfs_po_it>-Uom.
ENDIF. IF <lfs_po_it>-StorLoc IS NOT INITIAL.
<lfs_items>-stor_loc = <lfs_po_it>-StorLoc.
ENDIF.
endif.
ENDLOOP.
16 | P a g e
%update = 'X'
PoNum = <lfs_po_it>-PoNum
PoItem = <lfs_po_it>-PoItem )
TO reported-po_it.
ENDIF.
ENDMETHOD.
METHOD delete.
METHOD read.
ENDMETHOD.
METHOD rba_Po_hd.
ENDMETHOD.
METHOD create.
17 | P a g e
mapped-po_it = VALUE #( BASE mapped-po_it
( %cid = <lfs_po_items>-%cid
PoNum = ls_po_items-po_num
PoItem = ls_po_items-po_item
) ).
ELSE.
APPEND VALUE #( %cid = <lfs_po_items>-%cid
PoNum = <lfs_po_items>-PoNum
PoItem = <lfs_po_items>-PoItem )
TO failed-po_it.
ENDMETHOD.
ENDCLASS.
18 | P a g e
6. Create the Metadata Extensions
{
id: 'OrgInfo',
purpose:#STANDARD,
parentId: 'POHd',
position:20,
targetQualifier: 'OrgGroup',
type:#FIELDGROUP_REFERENCE,
label:'Organization Details'
},
{
id: 'MorDet',
purpose:#STANDARD,
parentId: 'POHd',
position:30,
targetQualifier: 'MoreDet',
type:#FIELDGROUP_REFERENCE,
label:'More Details'
19 | P a g e
},
{ id:'Header1', purpose:
#HEADER,
type:#DATAPOINT_REFERENCE,
targetQualifier:'HD',
position: 10
}, */
{
id: 'POItems',
purpose: #STANDARD,
type:#LINEITEM_REFERENCE,
position: 20,
targetElement: '_PO_items',
label: 'Purchase Order Items'
}
]
20 | P a g e
@UI.selectionField: [{ position: 70 }]
@UI.identification: [{ position: 70, label: 'Plant' }]
// @UI.fieldGroup: [{ position: 70, label: 'Plant',qualifier: 'OrgGroup' }]
Plant;
@UI.lineItem: [{ position: 80,label: 'Status'},{ type: #FOR_ACTION, dataAction:
'Change_status'
Status'}] ,
label: 'Change
with
{
@UI.facet: [{
id: 'ItemID',
purpose: #STANDARD,
position: 10,
type:#IDENTIFICATION_REFERENCE,
// type:#COLLECTION,
label: 'Item Information'
} /*,
{
id: 'BasicInfo',
purpose:#STANDARD,
parentId: 'ItemID',
position:10,
targetQualifier: 'BasicGroup',
type:#FIELDGROUP_REFERENCE,
label:'Item Details'
21 | P a g e
} /*,
{
id:'Header1',
purpose: #HEADER,
type:#DATAPOINT_REFERENCE,
targetQualifier:'HD1',
position: 10
} ,
{
id:'Header2',
purpose: #HEADER,
type:#DATAPOINT_REFERENCE,
targetQualifier:'HD2',
position: 20
} */
]
22 | P a g e
@UI.lineItem: [{ position: 70,label: 'Order Quantity'}]
@UI.identification: [{ position: 70,label: 'Order Quantity' }]
// @UI.fieldGroup: [{ position: 70, label: 'Order Quantity',qualifier:
'BasicGroup' }]
Qty;
@UI.lineItem: [{ position: 80,label: 'Order Unit'}]
@UI.identification: [{ position: 80,label: 'Order Unit' }]
// @UI.fieldGroup: [{ position: 80, label: 'Order Unit',qualifier: 'BasicGroup' }]
Uom;
@UI.lineItem: [{ position: 90,label: 'Product Price'}]
Create a Service definition and expose the Purchase order header and items projection views
@EndUserText.label: 'Service definition for PO'
define service ZUI_PO_HD_ITEMS {
expose ZC_PO_HEAD as PO_Hd;
expose ZC_PO_ITEMS as PO_Items;
}
23 | P a g e
8. Create the Service Binding
Create a Service Binding for the service definition, activate it and publish it.
9. Check the service URLS for metadata and Purchase order details
Click on Service URL-To check the metadata of Purchase order Header and items
URL:https://0e4e7bd0-339a-47c7-aae6-a8f0cb52cf77.abap-
web.us10.hana.ondemand.com/sap/opu/odata/sap/ZUI_PO_HD_ITEMS/$metadata?sap-client=100
Metadata for Purchase order header
24 | P a g e
To check the data for the Purchase order header -
https://0e4e7bd0-339a-47c7-aae6-a8f0cb52cf77.abap-
web.us10.hana.ondemand.com/sap/opu/odata/sap/ZUI_PO_HD_ITEMS/PO_Hd?sap-client=100
25 | P a g e
10. Preview the Purchase order Application
Now, select the Entity set in service binding and click on Preview
Select the purchase order, it’s navigate to the header and items details.
26 | P a g e
Select the item, it’s navigates to items details
11. Add the Input Help for the Field to show the list of possible values
Now add the input help check for the Vendor field, as there were no values for the vendor.
27 | P a g e
Populate and check the table data
Now, add the annotation to the vendor field in the Purchase order projection view to get the input list of
vendors.
28 | P a g e
Now, Vendor field has the input help list
29 | P a g e
purpose: #STANDARD,
position: 10,
//type:#IDENTIFICATION_REFERENCE,
type:#COLLECTION,
label: 'Purchase Order Header'
},
{
id: 'BasicInfo',
purpose:#STANDARD,
parentId: 'POHd',
position:10,
targetQualifier: 'BasicGroup',
type:#FIELDGROUP_REFERENCE,
label:'Basic Details'
},
{
id: 'OrgInfo',
purpose:#STANDARD,
parentId: 'POHd',
position:20,
targetQualifier: 'OrgGroup',
type:#FIELDGROUP_REFERENCE,
label:'Organization Details'
},
{
id: 'MorDet',
purpose:#STANDARD,
parentId: 'POHd',
position:30,
targetQualifier: 'MoreDet',
type:#FIELDGROUP_REFERENCE,
label:'More Details'
},
{
id:'Header1',
purpose: #HEADER,
type:#DATAPOINT_REFERENCE,
targetQualifier:'HD',
position: 10
},
{
id: 'POItems',
purpose: #STANDARD,
type:#LINEITEM_REFERENCE,
position: 20,
targetElement: '_PO_items',
30 | P a g e
label: 'Purchase Order Items'
} ]
31 | P a g e
Add the purchase order and item number with labels in header information.
Group the item details.
with
{
@UI.facet: [{
id: 'ItemID',
purpose: #STANDARD,
position: 10,
//type:#IDENTIFICATION_REFERENCE,
type:#COLLECTION,
label: 'Item Information'
},
{
id: 'BasicInfo',
purpose:#STANDARD,
parentId: 'ItemID',
position:10,
targetQualifier: 'BasicGroup',
type:#FIELDGROUP_REFERENCE,
label:'Item Details'
},
32 | P a g e
{
id:'Header1',
purpose: #HEADER,
type:#DATAPOINT_REFERENCE,
targetQualifier:'HD1',
position: 10
},
{
id:'Header2',
purpose: #HEADER,
type:#DATAPOINT_REFERENCE,
targetQualifier:'HD2',
position: 20
}
]
33 | P a g e
Qty;
34 | P a g e
13. Perform the CRUD Operations
35 | P a g e
Purchase order Header got created
36 | P a g e
Purchase order Item got created.
37 | P a g e
Update- Now, edit the Purchase Order Header and Items details
38 | P a g e
Change the details
39 | P a g e
Delete- Now, delete the Item
40 | P a g e
Now, delete the Purchase order
41 | P a g e
Change the item details
42 | P a g e
Add the new item to purchase order
43 | P a g e
Click on save.
44 | P a g e
New item got added to purchase order
45 | P a g e
46 | P a g e