Rap Document
Rap Document
Consultant
Email:[email protected] 1|P a g e
Prepared by Sagar Dhumal - SAP ABAP
Consultant
Email:[email protected] 2|P a g e
Prepared by Sagar Dhumal - SAP ABAP
Consultant
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,
_PO_items // Make association public
}
Email:[email protected] 3|P a g e
Prepared by Sagar Dhumal - SAP ABAP
Consultant
price_unit as PriceUnit,
local_last_changed_by as LocalLastChangedBy,
local_last_changed_at as LocalLastChangedAt,
_po_hd
}
@UI:{ headerInfo: {
typeName: 'Purchase Order',
typeNamePlural: 'Purchase Orders',
title: {
type: #STANDARD,
value: 'PoNum'
}
} }
define root view entity ZC_PO_HEAD provider contract transactional_query
as projection on ZI_PO_HEAD
{
@Search.defaultSearchElement: true
key PoNum,
DocCat,
Type,
CompCode,
Org,
Status,
/* @Consumption.valueHelpDefinition: [{
entity: {
name: 'ZI_VEND',
element: 'Vendor'
}}] */
Vendor,
Plant,
CreateBy,
CreatedDateTime,
ChangedDateTime,
LocalLastChangedBy,
/* Associations */
_PO_items : redirected to composition child ZC_PO_ITEMS
Email:[email protected] 4|P a g e
Prepared by Sagar Dhumal - SAP ABAP
Consultant
Email:[email protected] 5|P a g e
Prepared by Sagar Dhumal - SAP ABAP
Consultant
Email:[email protected] 6|P a g e
Prepared by Sagar Dhumal - SAP ABAP
Consultant
Uom = Uom;
Plant = Plant;
StorLoc = stor_loc;
Qty = Qty;
ProductPrice = product_price;
PriceUnit = price_unit;
LocalLastChangedAt = local_last_changed_at;
LocalLastChangedBy = local_last_changed_by;
}
}
Create a Behavior definition for the Purchase Order Header Projection View
projection;
//strict ( 2 ); //Uncomment this line in order to enable strict mode 2. The strict
mode has two variants (strict(1), strict(2)) and is prerequisite to be future proof
regarding syntax and to be able to release your BO.
Email:[email protected] 7|P a g e
Prepared by Sagar Dhumal - SAP ABAP
Consultant
Local Class-
CLASS lhc_PO_HD DEFINITION INHERITING FROM cl_abap_behavior_handler.
PRIVATE SECTION.
ENDCLASS .
METHOD get_instance_features.
Email:[email protected] 8|P a g e
Prepared by Sagar Dhumal - SAP ABAP
Consultant
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.
Email:[email protected] 9|P a g e
Prepared by Sagar Dhumal - SAP ABAP
Consultant
Email:[email protected] 10 | P a g e
Prepared by Sagar Dhumal - SAP ABAP
Consultant
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.
ENDMETHOD.
METHOD read.
ENDMETHOD.
METHOD lock.
ENDMETHOD.
METHOD rba_Po_items.
ENDMETHOD.
METHOD cba_Po_items.
Email:[email protected] 11 | P a g e
Prepared by Sagar Dhumal - SAP ABAP
Consultant
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.
Email:[email protected] 12 | P a g e
Prepared by Sagar Dhumal - SAP ABAP
Consultant
%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.
Email:[email protected] 13 | P a g e
Prepared by Sagar Dhumal - SAP ABAP
Consultant
ENDMETHOD.
ENDCLASS.
Local Class-
CLASS lhc_PO_IT DEFINITION INHERITING FROM cl_abap_behavior_handler.
PRIVATE SECTION.
ENDCLASS .
METHOD update.
Email:[email protected] 14 | P a g e
Prepared by Sagar Dhumal - SAP ABAP
Consultant
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.
Email:[email protected] 15 | P a g e
Prepared by Sagar Dhumal - SAP ABAP
Consultant
%update = 'X'
PoNum = <lfs_po_it>-PoNum
PoItem = <lfs_po_it>-PoItem )
TO reported-po_it.
ENDIF.
ENDMETHOD.
METHOD delete.
ENDMETHOD.
METHOD read.
ENDMETHOD.
METHOD rba_Po_hd.
ENDMETHOD.
METHOD create.
DATA : ls_po_items TYPE ztb_po_items.
Email:[email protected] 16 | P a g e
Prepared by Sagar Dhumal - SAP ABAP
Consultant
ELSE.
APPEND VALUE #( %cid = <lfs_po_items>-%cid
PoNum = <lfs_po_items>-PoNum
PoItem = <lfs_po_items>-PoItem )
TO failed-po_it.
ENDMETHOD.
ENDCLASS.
Email:[email protected] 17 | P a g e
Prepared by Sagar Dhumal - SAP ABAP
Consultant
{
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'
Email:[email protected] 18 | P a g e
Prepared by Sagar Dhumal - SAP ABAP
Consultant
},
{
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'
}
]
Email:[email protected] 19 | P a g e
Prepared by Sagar Dhumal - SAP ABAP
Consultant
@UI.selectionField: [{ position: 70 }]
@UI.identification: [{ position: 70, label: 'Plant' }]
// @UI.fieldGroup: [{ position: 70, label: 'Plant',qualifier: 'OrgGroup' }]
Plant;
id: 'BasicInfo',
purpose:#STANDARD,
parentId: 'ItemID',
position:10,
targetQualifier: 'BasicGroup',
type:#FIELDGROUP_REFERENCE,
label:'Item Details'
Email:[email protected] 20 | P a g e
Prepared by Sagar Dhumal - SAP ABAP
Consultant
} /*,
{
id:'Header1',
purpose: #HEADER,
type:#DATAPOINT_REFERENCE,
targetQualifier:'HD1',
position: 10
} ,
{
id:'Header2',
purpose: #HEADER,
type:#DATAPOINT_REFERENCE,
targetQualifier:'HD2',
position: 20
} */
]
Email:[email protected] 21 | P a g e
Prepared by Sagar Dhumal - SAP ABAP
Consultant
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;
}
Email:[email protected] 22 | P a g e
Prepared by Sagar Dhumal - SAP ABAP
Consultant
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
Email:[email protected] 23 | P a g e
Prepared by Sagar Dhumal - SAP ABAP
Consultant
Email:[email protected] 24 | P a g e
Prepared by Sagar Dhumal - SAP ABAP
Consultant
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.
Email:[email protected] 25 | P a g e
Prepared by Sagar Dhumal - SAP ABAP
Consultant
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.
Email:[email protected] 26 | P a g e
Prepared by Sagar Dhumal - SAP ABAP
Consultant
Now, add the annotation to the vendor field in the Purchase order projection view to get the input list of
vendors.
Email:[email protected] 27 | P a g e
Prepared by Sagar Dhumal - SAP ABAP
Consultant
Email:[email protected] 28 | P a g e
Prepared by Sagar Dhumal - SAP ABAP
Consultant
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',
Email:[email protected] 29 | P a g e
Prepared by Sagar Dhumal - SAP ABAP
Consultant
Email:[email protected] 30 | P a g e
Prepared by Sagar Dhumal - SAP ABAP
Consultant
Add the purchase order and item number with labels in header information.
Group the item details.
id: 'BasicInfo',
purpose:#STANDARD,
parentId: 'ItemID',
position:10,
targetQualifier: 'BasicGroup',
type:#FIELDGROUP_REFERENCE,
label:'Item Details'
},
Email:[email protected] 31 | P a g e
Prepared by Sagar Dhumal - SAP ABAP
Consultant
{
id:'Header1',
purpose: #HEADER,
type:#DATAPOINT_REFERENCE,
targetQualifier:'HD1',
position: 10
},
{
id:'Header2',
purpose: #HEADER,
type:#DATAPOINT_REFERENCE,
targetQualifier:'HD2',
position: 20
}
]
Email:[email protected] 32 | P a g e
Prepared by Sagar Dhumal - SAP ABAP
Consultant
Qty;
Email:[email protected] 33 | P a g e
Prepared by Sagar Dhumal - SAP ABAP
Consultant
Email:[email protected] 34 | P a g e
Prepared by Sagar Dhumal - SAP ABAP
Consultant
Email:[email protected] 35 | P a g e
Prepared by Sagar Dhumal - SAP ABAP
Consultant
Email:[email protected] 36 | P a g e
Prepared by Sagar Dhumal - SAP ABAP
Consultant
Update- Now, edit the Purchase Order Header and Items details
Email:[email protected] 37 | P a g e
Prepared by Sagar Dhumal - SAP ABAP
Consultant
Email:[email protected] 38 | P a g e
Prepared by Sagar Dhumal - SAP ABAP
Consultant
Email:[email protected] 39 | P a g e
Prepared by Sagar Dhumal - SAP ABAP
Consultant
Email:[email protected] 40 | P a g e
Prepared by Sagar Dhumal - SAP ABAP
Consultant
Email:[email protected] 41 | P a g e
Prepared by Sagar Dhumal - SAP ABAP
Consultant
Email:[email protected] 42 | P a g e
Prepared by Sagar Dhumal - SAP ABAP
Consultant
Click on save.
Email:[email protected] 43 | P a g e
Prepared by Sagar Dhumal - SAP ABAP
Consultant
Email:[email protected] 44 | P a g e
Prepared by Sagar Dhumal - SAP ABAP
Consultant
Email:[email protected] 45 | P a g e