cancel
Showing results for 
Search instead for 
Did you mean: 

How to get object id from EML created object in behavior implementation

Louis-Arnaud
Participant
0 Kudos

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

Louis-Arnaud
Participant
0 Kudos

Hello Julian,

unfortunately, the purchase order id is not availaible at that time. I think that I can only get it after the COMMIT ENTITIES.

Accepted Solutions (1)

Accepted Solutions (1)

Andre_Fischer
Product and Topic Expert
Product and Topic Expert
0 Kudos

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

abap-platform-rap-workshops/rap6xx/rap610/exercises/ex4/README.md at main · SAP-samples/abap-platfor...

Louis-Arnaud
Participant

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 🙂

Answers (0)