on 2025 Apr 17 7:26 AM - last edited 3 weeks ago
Hi ,I am working on RAP Application where I have Header and Item Entity with association 1 to many.
I tried with different ways, that are managed and unmanaged but i am not able to implement it successfully.
Please Suggest the correct way to handle both header crud and item crud also.
also, if we can implement file upload that can be handle in unmanaged class with looping the entity's (as per my knowledge).
Currently I have Header:
define root view zzhead_view as select from zzhead as _head
association[0..*] to zzitem_view as _item
on $projection.Headerid = _item.Headerid{
key headerid as Headerid,
headername as Headername,
_item
}
Item:
define root view zzitem_view as select from zzitem as _item
association[1..*] to zzhead_view as _head
on $projection.Headerid = _item.headerid
{
key headerid as Headerid,
key itemid as Itemid,
itemname as Itemname,
_head
}
i have developed projection views over the same and also define the behavior definition over header and item separate for interface and projection of both.
define service and expose the projection views in that and binding done over the service, but the actual problem come here,
i am able to create entities for header the create and delete and edit button is there for header but create button is missing for item.
I don't get why, i have implemented unmanaged classes for both.
Item:
Header:
Request clarification before answering.
Hi,
I'll add some steps I did for managed scenario, hope it helps you:
First : Define Root Entity ( in your case Header) with Composition (to define the parent-child relationship with Items) , something like:
define root view entity ZHEADER
as select from zheader_table
composition [0..*] of ZITEM as _Items // Composition for Items
{
key header_uuid as HeaderUuid,
description as Description,
// ... other fields ...
_Items // Composition of Items
}
Second: define the child entity ( item ) with association to header:
define view entity ZITEM
as select from zitem_table
association to parent ZHEADER as _Header
on $projection.header_uuid = _Header.header_uuid
{
key header_uuid as HeaderUuid,
key item_uuid as ItemUuid,
item_name as ItemName,
// other fields here
_Header // Association to Header
}
Then define the projections:
@Metadata.allowExtensions: true
define root view entity ZC_HEADER
as projection on ZHEADER
{
key HeaderUuid,
// other fields here
_Items : redirected to composition child ZC_ITEM
}
// For Itm :
@Metadata.allowExtensions: true
define view entity ZC_ITEM
as projection on ZITEM
{
key HeaderUuid,
key ItemUuid,
// other fields here
// Association to Header
_Header : redirected to parent ZC_HEADER
}
Add meta data extensions for both item and header.
For behavior definition you can also use draft functionality, in the managed scenario. I'll give you an example:
managed; // implementation in class xxx unique;
with draft;
define behavior for YBA_HEADER alias Header
implementation in class XXX unique
persistent table Zheader_table
draft table yheader_draft
lock master
authorization master ( instance )
etag master LastChangedAt
{
field ( readonly ) ....;
field ( numbering : managed )
HeaderUuid;
create;
update ( features : instance );
delete ( features : instance ); // could use feature instance or not, in
//case of using it should be implemented in
//the class, the instance method
draft action edit;
draft action activate;
draft action discard;
draft action resume;
association _Item { create ; }
mapping for zheader_table
{
.......
}
}
// Item
define behavior for for ZITEM alias Item
implementation in class ZBP_ITEM unique
persistent table zitem
draft table yitem
lock dependent by _Header
etag master LastChangedAt
authorization dependent by _Header
{
field ( readonly, numbering : managed ) itemUuid;
field ( readonly ) HeaderUuid;
association _Run { with draft; }
update;
delete;
}
}
and :
projection;
use draft;
define behavior for xxx alias Header
use etag
{
use create;
use update;
use delete;
use action Activate;
use action Discard;
use action Edit;
use action Resume;
use association _Item {create;}
}
define behavior for yyy alias Item
{
use update;
use delete;
use association _Header { with draft; }
}
The rest would be service definition and binding ....
Hope this helps.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have Implemented same scenario with unmanage implementation. But I was not able to implement Create operation in child entity. when I tried to create a child under header in behavior definition of interface view of header. it is
"create" is not allowed in entity "zzitemview". Instead, the activation or deactivation takes place in entity "ZZHEAD_" using association "_item".
there is another observation in one of implementation. there was an error called dependent entity cannot implement create operation.
Create should not be implemented in child entity on behavior definition, Below link has detailed example, please do a comparison to see what you have missed, in case you still have the issue, please share your behavior definition code.
Unmanage scenario example here
Hi @suzanne_alivand ,
I got your point that we cannot implement create operation in child entity.
but there any way out other than composition to implement crud operations in child and parent entity.
any example with manage / unmanaged ?
what i think is , it is not possible with manage anyway's because i have tried that and with unmanaged also,
i tried to implement but face same issue that dependent entity cannot implement create operation ?
do you have any way out from this ?
Hi @suzanne_alivand, thank you for helping out.
I am able to resolve the error same as suggested by you.
I was able to resolve using this approach.
unmanaged implementation in class zbp_zsalesheader unique;
//strict ( 2 );
define behavior for ZZSALESHEADER //alias <alias_name>
//late numbering
//lock master
//authorization master ( instance )
//etag master <field_name>
{
create;
update(features :instance);
delete(features :instance);
field ( readonly ) sales_doc_num , last_changed, date_created, block_status,person_created;
// association _item { create; }
mapping for zzvbak control zzsalesheader corresponding{
sales_doc_num = vbeln;
block_status = faksk;
sales_dist = vtweg;
sales_div = spart;
//total_cost = netwr;
cost_currency = waerk;
person_created = ernam;
date_created = erdat;
last_changed = last_changed_timestamp;
}
association _item { create(features :instance); }
action blockOrder result[1]$self;
action UnblockOrder result[1]$self;
}
define behavior for ZZSALESITEM //alias <alias_name>
//late numbering
//lock dependent by _Head
//authorization dependent by _Head
//etag master <field_name>
{
create;
update;
delete;
//field ( readonly ) sales_doc_num, item_position;
mapping for zzvbap control ZZSALESITEM corresponding{
sales_doc_num = vbeln;
item_position = posnr;
cost_currency = waerk;
mat_desc = arktx;
mat_num = matnr;
quantity = kpein;
total_item_cost = netwr;
unit_cost = netpr;
unit = kmein;
last_changed = last_changed_timestamp;
}
// association _Head;
}
whereas i have handle the creation of item in association of head only with handling deep entity of head.
CLASS lhc_ZZSALESHEADER DEFINITION INHERITING FROM cl_abap_behavior_handler.
PRIVATE SECTION.
METHODS get_instance_features FOR INSTANCE FEATURES
IMPORTING keys REQUEST requested_features FOR zzsalesheader RESULT result.
METHODS create FOR MODIFY
IMPORTING entities FOR CREATE zzsalesheader.
METHODS update FOR MODIFY
IMPORTING entities FOR UPDATE zzsalesheader.
METHODS delete FOR MODIFY
IMPORTING keys FOR DELETE zzsalesheader.
METHODS read FOR READ
IMPORTING keys FOR READ zzsalesheader RESULT result.
METHODS rba_Item FOR READ
IMPORTING keys_rba FOR READ zzsalesheader\_Item FULL result_requested RESULT result LINK association_links.
METHODS cba_Item FOR MODIFY
IMPORTING entities_cba FOR CREATE zzsalesheader\_Item.
METHODS blockOrder FOR MODIFY
IMPORTING keys FOR ACTION zzsalesheader~blockOrder RESULT result.
METHODS UnblockOrder FOR MODIFY
IMPORTING keys FOR ACTION zzsalesheader~UnblockOrder RESULT result.
ENDCLASS.
CLASS lhc_ZZSALESHEADER IMPLEMENTATION.
METHOD get_instance_features.
ENDMETHOD.
METHOD create.
loop at entities assigning field-symbol(<lfs_entity>).
data ls_data type zzvbak.
* ls_data-
ls_data-erdat = sy-datum.
select max( vbeln ) from zzvbak into @DATA(pvbeln).
ls_data-ernam = 'Sanket Gode'.
ls_data-faksk = <lfs_entity>-block_status.
ls_data-spart = <lfs_entity>-sales_div.
ls_data-vbeln = pvbeln + 1.
ls_data-vkorg = <lfs_entity>-sales_org.
ls_data-vtweg = <lfs_entity>-sales_dist.
ls_data-waerk = <lfs_entity>-cost_currency.
modify zzvbak from @ls_data.
endloop.
ENDMETHOD.
METHOD update.
ENDMETHOD.
METHOD delete.
loop at keys assigning field-symbol(<lfs_entity>).
DELETE from zzvbak where vbeln = @<lfs_entity>-sales_doc_num.
delete from zzvbap where vbeln = @<lfs_entity>-sales_doc_num.
endloop.
ENDMETHOD.
METHOD read.
ENDMETHOD.
METHOD rba_Item.
ENDMETHOD.
// here we have handle the creation of item with association of header.
// with handling the item with deep entity.
METHOD cba_Item.
DATA lt_data TYPE TABLE FOR CREATE zzsalesitem.
data ls_data type zzvbap.
loop at entities_cba assigning field-symbol(<lfs_entity>).
FIELD-SYMBOLS: <fs_salesitem> LIKE lt_Data.
lt_data = <lfs_entity>-%target.
lt_Data = <lfs_entity>-%target.
ls_data-matnr = lt_data[ 1 ]-mat_num.
ls_data-kmein = lt_data[ 1 ]-unit.
ls_data-kpein = lt_data[ 1 ]-quantity.
ls_data-mandt = sy-ucomm.
ls_data-netpr = lt_data[ 1 ]-unit_cost.
ls_data-netwr = lt_data[ 1 ]-total_item_cost.
ls_data-posnr = lt_data[ 1 ]-item_position.
ls_data-vbeln = lt_data[ 1 ]-sales_doc_num.
ls_data-waerk = lt_data[ 1 ]-cost_currency.
modify zzvbap from @ls_data.
endloop.
ENDMETHOD.
METHOD blockOrder.
ENDMETHOD.
METHOD UnblockOrder.
ENDMETHOD.
ENDCLASS.
CLASS lhc_ZZSALESITEM DEFINITION INHERITING FROM cl_abap_behavior_handler.
PRIVATE SECTION.
METHODS create FOR MODIFY
IMPORTING entities FOR CREATE zzsalesitem.
METHODS update FOR MODIFY
IMPORTING entities FOR UPDATE zzsalesitem.
METHODS delete FOR MODIFY
IMPORTING keys FOR DELETE zzsalesitem.
METHODS read FOR READ
IMPORTING keys FOR READ zzsalesitem RESULT result.
ENDCLASS.
CLASS lhc_ZZSALESITEM IMPLEMENTATION.
METHOD create.
ENDMETHOD.
METHOD update.
ENDMETHOD.
METHOD delete.
loop at keys assigning field-symbol(<lfs_entity>).
DELETE from zzvbap where vbeln = @<lfs_entity>-sales_doc_num and posnr = @<lfs_entity>-item_position.
endloop.
ENDMETHOD.
METHOD read.
ENDMETHOD.
ENDCLASS.
CLASS lsc_ZZSALESHEADER DEFINITION INHERITING FROM cl_abap_behavior_saver.
PROTECTED SECTION.
METHODS finalize REDEFINITION.
METHODS check_before_save REDEFINITION.
METHODS save REDEFINITION.
METHODS cleanup REDEFINITION.
METHODS cleanup_finalize REDEFINITION.
ENDCLASS.
CLASS lsc_ZZSALESHEADER IMPLEMENTATION.
METHOD finalize.
ENDMETHOD.
METHOD check_before_save.
ENDMETHOD.
METHOD save.
ENDMETHOD.
METHOD cleanup.
ENDMETHOD.
METHOD cleanup_finalize.
ENDMETHOD.
ENDCLASS.
User | Count |
---|---|
69 | |
21 | |
8 | |
7 | |
6 | |
6 | |
4 | |
4 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.