Simple RAP Demo Delivery application with draft, validation, action, and determination
Quick guide for RAP
development-
Sonal Kumar Singh
Simple RAP Demo Delivery application with draft, validation, action, and determination
- - -- - - - - - - - - - - - -- - - - - - - - -- - - - - - -
1. Behaviour definition
- - -- - - - - - - - - - - - -- - - - - - - - - - - - - - -
managed implementation in class zbp_c_delv_hdr_rap unique;
strict( 2 );
with draft;
define behavior for Z_C_DELV_HDR_RAP alias DeliveryHeader
persistent table zss_rap_delv_hdr
draft table zss_dr_delv_hdr
lock master
total etag Id
authorization master ( instance )
etag master Id
{
create;
update;
delete;
association _delivery_item { create; }
field( numbering : managed, readonly ) Id ;
draft action Resume ;
draft action Activate ;
draft action Edit ;
draft action Discard;
draft determine action Prepare;
action setstatus result [1] $self;
validation checkstatus on save{ field Gbstk ; create ; update; }
determination determine_status on modify{ field Lfart; }
//field ( readonly :update ) Gbstk ;
}
define behavior for Z_C_DELV_ITM_RAP alias DeliveryItem
draft table zss_dr_delv_itm
persistent table zss_rap_delv_itm
lock dependent by _header
authorization dependent by _header
etag master Id
{
field( readonly ) Id ;
field( numbering : managed, readonly ) Posnr ;
update;
delete;
association _header ;
}
Simple RAP Demo Delivery application with draft, validation, action, and determination
- - -- - - - - - - - - - - - -- - - - - - - - -- - - - - - -
2. Behaviour implementation
- - -- - - - - - - - - - - - -- - - - - - - - -- - - - - - -
CLASS lhc_DeliveryHeader DEFINITION INHERITING FROM
cl_abap_behavior_handler.
PRIVATE SECTION.
METHODS get_instance_authorizations FOR INSTANCE AUTHORIZATION
IMPORTING keys REQUEST requested_authorizations FOR DeliveryHeader
RESULT result.
METHODS setstatus FOR MODIFY
IMPORTING keys FOR ACTION DeliveryHeader~setstatus RESULT result.
METHODS determine_status FOR DETERMINE ON MODIFY
IMPORTING keys FOR DeliveryHeader~determine_status.
METHODS checkstatus FOR VALIDATE ON SAVE
IMPORTING keys FOR DeliveryHeader~checkstatus.
ENDCLASS.
CLASS lhc_DeliveryHeader IMPLEMENTATION.
METHOD get_instance_authorizations.
ENDMETHOD.
METHOD setstatus.
*&-Modifying BO z_c_delv_hdr_rap - Entity - DeliveryHeader and Field -
Gbstk
MODIFY ENTITIES OF z_c_delv_hdr_rap
ENTITY DeliveryHeader
UPDATE FIELDS ( Gbstk )
WITH VALUE #( for ls_keys in keys ( %tky = ls_keys-%tky Gbstk = 'C'
) )
FAILED DATA(lt_Failed)
REPORTED DATA(lt_reported).
**&-Return the data output to reflect the same at list page-
READ ENTITIES OF z_c_delv_hdr_rap
ENTITY DeliveryHeader
ALL FIELDS WITH CORRESPONDING #( keys )
RESULT DATA(lt_result).
result = VALUE #( for ls_result in lt_result ( %tky = ls_result-%tky
%param = ls_result ) ).
ENDMETHOD.
METHOD checkstatus.
*&-Read Delivery Entity-
READ ENTITIES OF z_c_delv_hdr_rap
ENTITY DeliveryHeader
ALL FIELDS WITH CORRESPONDING #( keys )
RESULT DATA(lt_status).
Simple RAP Demo Delivery application with draft, validation, action, and determination
*&-Check the status-
LOOP AT lt_status ASSIGNING FIELD-SYMBOL(<lfs_status>).
IF NOT ( <lfs_status>-Gbstk = 'A' OR <lfs_status>-Gbstk = 'C' ).
APPEND VALUE #( %tky = <lfs_status>-%tky ) TO failed-deliveryheader.
APPEND VALUE #( %tky = <lfs_status>-%tky
%msg = new_message_with_text( severity =
if_abap_behv_message=>severity-error
text = 'Overall status
not valid!'
)
) TO reported-deliveryheader.
ENDIF.
ENDLOOP.
ENDMETHOD.
METHOD determine_status.
*&- READ line for the entity
READ ENTITIES OF z_c_delv_hdr_rap
ENTITY DeliveryHeader
ALL FIELDS WITH CORRESPONDING #( keys )
RESULT DATA(lt_delv_status).
*&-Updating the value to the internal table
LOOP AT lt_delv_status ASSIGNING FIELD-SYMBOL(<lfs_delv_status>).
IF <lfs_delv_status>-Lfart = 'UB'.
<lfs_delv_status>-Gbstk = 'C'.
ENDIF.
*&-Modify operations-
MODIFY ENTITIES OF z_c_delv_hdr_rap
IN LOCAL MODE
ENTITY DeliveryHeader
UPDATE FIELDS ( Gbstk )
WITH VALUE #( for ls_delv IN lt_delv_status
( %tky = ls_delv-%tky
Gbstk = ls_delv-Gbstk )
).
ENDLOOP.
ENDMETHOD.
ENDCLASS.
Simple RAP Demo Delivery application with draft, validation, action, and determination
- - -- - - - - - - - - - - - -- - - - - - - - -- - - - - - -
3. Behaviour Projection
- - -- - - - - - - - - - - - -- - - - - - - - -- - - - - - -
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.
use draft;
define behavior for Z_C_DELV_HDR_PRJ //alias <alias_name>
{
use create;
use update;
use delete;
use action Resume ;
use action Activate ;
use action Edit ;
use action Discard;
//use determine action Prepare;
use action setstatus;
use association _delivery_item { create; }
}
define behavior for Z_C_DELV_ITM_PRJ //alias <alias_name>
{
use update;
use delete;
use association _header;
}
Simple RAP Demo Delivery application with draft, validation, action, and determination
- - -- - - - - - - - - - - - -- - - - - - - - -- - - - - - -
4. Service Definition
- - -- - - - - - - - - - - - -- - - - - - - - -- - - - - - -
@[Link]: 'Service definiation for Delivery Header Projection'
define service Z_C_SD_DELV_HDR_PRJ {
expose Z_C_DELV_HDR_PRJ;
expose Z_C_DELV_ITM_PRJ;
}
- - -- - - - - - - - - - - - -- - - - - - - - -- - - - - - -
5. Service Binding
- - -- - - - - - - - - - - - -- - - - - - - - -- - - - - - -
Simple RAP Demo Delivery application with draft, validation, action, and determination
- - -- - - - - - - - - - - - -- - - - - - - - -- - - - - - -
6. CDS entity definitions
- - -- - - - - - - - - - - - -- - - - - - - - -- - - - - - -
HEADER
--------------------------------------------------------------------------------------------------------------------------
a) Header core definition
@[Link]: #NOT_REQUIRED
@[Link]: 'RAP delivery header'
@[Link]: true
define root view entity Z_C_DELV_HDR_RAP as select from zss_rap_delv_hdr
composition[1..*] of Z_C_DELV_ITM_RAP as _delivery_item
{
key id as Id,
ernam as Ernam,
aenam as Aenam,
lfart as Lfart,
gbstk as Gbstk,
_delivery_item // Make association public
}
b) Metadata - Header core
@[Link]: #CORE
@UI:{
headerInfo : {
typeName: 'SalesData',
typeNamePlural: 'SalesData',
title:{ type : #STANDARD,
value: 'Lfart'
}
--description: { value: 'Lfart'
--}
},
presentationVariant: [{
sortOrder: [{
by: 'Id',
direction: #ASC
}],
visualizations: [{ type : #AS_LINEITEM }] }]
}
annotate entity Z_C_DELV_HDR_RAP
with
{
@[Link]: [{ id: 'HeaderInfo',
type : #COLLECTION,
label: 'Delivery Details' ,
position : 10
},
{ id : 'Header',
parentId: 'HeaderInfo',
type : #IDENTIFICATION_REFERENCE,
label: 'Sales',
position : 10
Simple RAP Demo Delivery application with draft, validation, action, and determination
},
{ id : 'Items',
type : #LINEITEM_REFERENCE,
label : 'Items',
position : 20,
targetElement: '_delivery_item'
}
@UI: { selectionField: [{ position: 10 }],
lineItem: [{ position : 10 },
{ type: #FOR_ACTION,
dataAction: 'setstatus' ,
label: 'Set Status'}],
identification: [{ position : 10 }]
}
Id;
@UI: { selectionField: [{ position: 20 }],
lineItem: [{ position : 20 }],
identification: [{ position : 20 }]
}
Ernam;
@UI: { selectionField: [{ position: 30 }],
lineItem: [{ position : 30 }],
identification: [{ position : 30 }]
}
Aenam;
@UI: { selectionField: [{ position: 40 }],
lineItem: [{ position : 40 }],
identification: [{ position : 40 }]
}
Lfart;
@UI: { selectionField: [{ position: 50 }],
lineItem: [{ position : 50 }],
identification: [{ position : 50 }]
}
Gbstk;
c) Header Projection
@[Link]: 'Projection view for Delivery Header'
@[Link]: #NOT_REQUIRED
@[Link]: true
define root view entity Z_C_DELV_HDR_PRJ as projection on
Z_C_DELV_HDR_RAP
{
key Id,
Ernam,
Aenam,
Lfart,
Gbstk,
/* Associations */
Simple RAP Demo Delivery application with draft, validation, action, and determination
_delivery_item : redirected to composition child Z_C_DELV_ITM_PRJ
}
d) Metadata – Header projection
@[Link]: #CORE
@UI:{
headerInfo : {
typeName: 'SalesData',
typeNamePlural: 'SalesData',
title:{ type : #STANDARD,
value: 'Lfart'
}
--description: { value: 'Lfart'
--}
},
presentationVariant: [{
sortOrder: [{
by: 'Id',
direction: #ASC
}],
visualizations: [{ type : #AS_LINEITEM }] }]
}
annotate entity Z_C_DELV_HDR_PRJ
with
{
@[Link]: [{ id: 'HeaderInfo',
type : #COLLECTION,
label: 'SO Details' ,
position : 10
},
{ id : 'Header',
parentId: 'HeaderInfo',
type : #IDENTIFICATION_REFERENCE,
label: 'Sales',
position : 10
},
{ id : 'Items',
type : #LINEITEM_REFERENCE,
label : 'Items',
position : 20,
targetElement: '_delivery_item'
}
@UI: { selectionField: [{ position: 10 }],
lineItem: [{ position : 10 },
{ type: #FOR_ACTION,
dataAction: 'setstatus' ,
label: 'Set Status'}],
identification: [{ position : 10 }]
}
Id;
@UI: { selectionField: [{ position: 20 }],
lineItem: [{ position : 20 }],
identification: [{ position : 20 }]
}
Ernam;
Simple RAP Demo Delivery application with draft, validation, action, and determination
@UI: { selectionField: [{ position: 30 }],
lineItem: [{ position : 30 }],
identification: [{ position : 30 }]
}
Aenam;
@UI: { selectionField: [{ position: 40 }],
lineItem: [{ position : 40 }],
identification: [{ position : 40 }]
}
Lfart;
@UI: { selectionField: [{ position: 50 }],
lineItem: [{ position : 50 }],
identification: [{ position : 50 }]
}
Gbstk;
ITEM
---------------------------------------------------------------------------------------------------------------------
e) Item core definition
@[Link]: [#NONE]
@[Link]: #NOT_REQUIRED
@[Link]: 'Delivery Item'
@[Link]: true
@[Link]:{
serviceQuality: #X,
sizeCategory: #S,
dataClass: #MIXED
}
@[Link]: true
define view entity Z_C_DELV_ITM_RAP as select from zss_rap_delv_itm
association to parent Z_C_DELV_HDR_RAP as _header on
$[Link] = _header.Id
{
key id as Id,
key posnr as Posnr,
matnr as Matnr,
aenam as Aenam,
_header
f) Metadata – Item core
@[Link]: #CORE
annotate entity Z_C_DELV_ITM_RAP
with
{
Simple RAP Demo Delivery application with draft, validation, action, and determination
@[Link]: [{
id : 'ItemDetails',
purpose: #STANDARD,
type : #COLLECTION,
label:'Item Details',
position : 10
},
{
id: 'Items',
label:'Items',
type:#IDENTIFICATION_REFERENCE,
purpose: #STANDARD,
parentId: 'ItemDetails',
position:10
}
]
@UI: { selectionField: [{ position: 10 }],
lineItem: [{ position : 10 }],
identification: [{ position : 10 }]
}
@[Link]: true
Id;
@UI: { selectionField: [{ position: 20 }],
lineItem: [{ position : 20 }],
identification: [{ position : 20 }]
}
Posnr;
@UI: { selectionField: [{ position: 30 }],
lineItem: [{ position : 30 }],
identification: [{ position : 30 }]
}
Matnr;
@UI: { selectionField: [{ position: 40 }],
lineItem: [{ position : 40 }],
identification: [{ position : 40 }]
}
Aenam;
g) Item Projection
@[Link]: [#NONE]
@[Link]: #NOT_REQUIRED
@[Link]: 'Projection View FOr Delivery Item'
@[Link]: true
@[Link]: true
Simple RAP Demo Delivery application with draft, validation, action, and determination
@[Link]:{
serviceQuality: #X,
sizeCategory: #S,
dataClass: #MIXED
}
define view entity Z_C_DELV_ITM_PRJ as projection on Z_C_DELV_ITM_RAP
{
key Id,
key Posnr,
Matnr,
Aenam,
/* Associations */
_header : redirected to parent Z_C_DELV_HDR_PRJ
}
h) Metadata – Item projection
@[Link]: #CORE
annotate entity Z_C_DELV_ITM_PRJ
with
{
@[Link]: [{
id : 'ItemDetails',
purpose: #STANDARD,
type : #COLLECTION,
label:'Item Details',
position : 10
},
{
id: 'Items',
label:'Items',
type:#IDENTIFICATION_REFERENCE,
purpose: #STANDARD,
parentId: 'ItemDetails',
position:10
}
]
@UI: { selectionField: [{ position: 10 }],
lineItem: [{ position : 10 }],
identification: [{ position : 10 }]
}
@[Link]: true
Id;
@UI: { selectionField: [{ position: 20 }],
lineItem: [{ position : 20 }],
identification: [{ position : 20 }]
}
Posnr;
Simple RAP Demo Delivery application with draft, validation, action, and determination
@UI: { selectionField: [{ position: 30 }],
lineItem: [{ position : 30 }],
identification: [{ position : 30 }]
}
Matnr;
@UI: { selectionField: [{ position: 40 }],
lineItem: [{ position : 40 }],
identification: [{ position : 40 }]
}
Aenam;
- - -- - - - - - - - - - - - -- - - - - - - - -- - - - - - -
7. Database tables
- - -- - - - - - - - - - - - -- - - - - - - - -- - - - - - -
a) Header
@[Link] : 'RAP SO Header'
@[Link] : #NOT_CLASSIFIED
@[Link] : #TRANSPARENT
@[Link] : #A
@[Link] : #ALLOWED
define table zss_rap_delv_hdr {
key mandt : mandt not null;
key id : sysuuid_x16 not null;
ernam : ernam;
aenam : aenam;
lfart : lfart;
gbstk : gbstk;
b) Item
@[Link] : 'RAP so items'
@[Link] : #NOT_CLASSIFIED
@[Link] : #TRANSPARENT
@[Link] : #A
@[Link] : #ALLOWED
define table zss_rap_delv_itm {
key mandt : mandt not null;
key id : sysuuid_x16 not null;
key posnr : sysuuid_x16 not null;
matnr : matnr;
aenam : aenam;
}
Simple RAP Demo Delivery application with draft, validation, action, and determination
Thank you:)
Sonal Kumar Singh