on 06-19-2023 3:35 PM
Hello,
In a managed RAP implementation, I created an action like this :
action ( features : instance ) create_po result [1] $self;
This action is supposed to create a purchase order.
After this function, I would like to get the purchase order id in order to add it to my entity (in result). But It is not possible to call the COMMIT ENTITIES in a behavior implementation. How is it suppose to work ?
DATA create_po_header TYPE TABLE FOR CREATE I_PurchaseOrderTP_2.
DATA create_po_items TYPE TABLE FOR CREATE i_purchaseordertp_2\_purchaseorderitem.
DATA cid TYPE abp_behv_cid.
READ ENTITIES OF ZI_Project IN LOCAL MODE
ENTITY ProjectItem
FIELDS ( Project ProjectItem Product Quantity QuantityUnit Supplier DeliveryDate )
WITH CORRESPONDING #( keys )
RESULT DATA(project_items).
IF project_items IS INITIAL.
RETURN.
ENDIF.
LOOP AT project_items REFERENCE INTO DATA(project_item).
cid = |PO_{ project_item->projectitem }|.
create_po_header = VALUE #( ( %cid = cid
purchaseordertype = 'NB'
companycode = 'FR01'
purchasingorganization = 1000
purchasinggroup = 001
supplier = project_item->Supplier
%control = VALUE #( purchaseordertype = cl_abap_behv=>flag_changed
companycode = cl_abap_behv=>flag_changed
purchasingorganization = cl_abap_behv=>flag_changed
purchasinggroup = cl_abap_behv=>flag_changed
supplier = cl_abap_behv=>flag_changed ) ) ).
create_po_items = VALUE #( ( %cid_ref = cid
%target = VALUE #( ( %cid = 'PO_ITEM1'
material = project_item->Product
plant = 1000
orderquantity = project_item->Quantity
purchaseorderitem = '00010'
taxcode = 'V2'
%control = VALUE #( material = cl_abap_behv=>flag_changed
plant = cl_abap_behv=>flag_changed
orderquantity = cl_abap_behv=>flag_changed
purchaseorderitem = cl_abap_behv=>flag_changed
taxcode = cl_abap_behv=>flag_changed ) ) ) ) ).
MODIFY ENTITIES OF I_PurchaseOrderTP_2
ENTITY PurchaseOrder
CREATE
SET FIELDS WITH VALUE #(
( %cid = cid
purchaseordertype = 'NB'
companycode = 'FR01'
purchasingorganization = '1000'
purchasinggroup = '001'
supplier = project_item->Supplier ) )
CREATE BY \_PurchaseOrderItem
FROM create_po_items
MAPPED DATA(mapped_po_headers)
REPORTED DATA(reported_po_headers)
FAILED DATA(failed_po_headers).
READ ENTITIES OF I_PurchaseOrderTP_2
ENTITY PurchaseOrder
FROM VALUE #( FOR po_header IN mapped_po_headers-purchaseorder (
%pid = po_header-%pid
%control = VALUE #( PurchaseOrder = if_abap_behv=>mk-on ) ) )
RESULT DATA(created_po_s).
ENDLOOP.
Thanks
When the API that you are calling uses late numbering you have to use the convert key statement in the save sequence to convert the PID (preliminary id) you get back from the API to retrieve the semantic key of your newly created object.
Check out our script of RAP610, exercise 4
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks ! This is the exact same example (with PR instead of PO but I will be able to handle it 😛 ).
I was used to BOPF but RAP is not really easy to understand... What if I want to use early numbering 🙂
User | Count |
---|---|
65 | |
8 | |
7 | |
7 | |
6 | |
5 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.