I am working on a RAP application and trying to call a BAPI. I am able to create the header and store this in a buffer class. But when I create the item by association, the class and buffer where I had the header data saved is no longer available. So the buffer is not retained.
How to proceed? I cannot find a single example online with a create by association using the buffer tables.
unmanaged;
//with draft;
define behavior for ZI_CUSTOMS_DOCUMENT alias CustomsDocument
implementation in class zbp_i_customs_document unique
//late numbering
lock master
etag master ChangedAtTimeStamp
//tag master <field_name>
//etag master ChangedAtTimeStamp
{
create;
update;
delete;
association _Item { create; }
association _Partner { create; }
field ( read only ) CustomsDeclarationUUID;
mapping for /sapsll/api6800_hdr_ref_s control zstr_sapsll_api6800_hdr_ref_s
{
ReferenceNumber = refno;
ReferenceQualifier = qual_refno;
ReferenceApplication = refapp;
LogicalSystem = org_logsystem;
ObjectType = objtp;
ReferenceDocumentCreatedOn = refdat;
ReferenceDocumentCreatedByUser = ernam;
ReferenceDocumentChangedByUser = aenam;
}
}
define behavior for ZI_CUSTOMS_DOCUMENT_ITEM alias Item
implementation in class zbp_i_customs_document_item unique
//late numbering
lock dependent by _CustomsDocument
etag dependent by _CustomsDocument
{
create;
update;
delete;
association _CustomsDocument;
// association _CustomsDocument { create; }
field ( read only ) CustomsDeclarationItemUUID, CustomsDeclarationUUID;
mapping for /sapsll/api6800_itm_s control zstr_sapsll_api6800_itm_s
{
// CustomsDeclarationItemUUID = guid_cuit;
CustomsDeclarationItem = item_number;
CustomsProduct = product_id;
.....
}
}
And here is code calling the buffer class on the create for the header entity:
* Instead call our class to set the header - and store this to the buffer
lcl_buffer_customsdocument=>get_instance( )->set_header_fields( EXPORTING is_hdr_data = hdr_data
is_hdr_reference_data = ls_api6800_hdr_ref_s
is_hdr_value_data = ls_api6800_hdr_val_s
is_hdr_duc_value_data = ls_api6800_hdr_cvl_s
And here is code calling the buffer class on the create by association for the item entity:
lcl_buffer_customsdocument=>get_instance( )->set_item_fields( EXPORTING is_itm_data = ls_api6800_itm_s
is_itm_reference_data = ls_api6800_itm_ref_s
is_itm_date_data = ls_api6800_itm_dat_s
is_itm_dimension_data = ls_api6800_itm_dim_s
is_itm_duc_value_data = ls_api6800_itm_cvl_s )
And in the saver class, we are trying to invoke the method to call the BAPI:
METHOD save.
lcl_buffer_customsdocument=>get_instance( )->call_customs_document_bapi( ).
ENDMETHOD.
However the issue is that when the saver class save method is invoked, the buffered header table entries are gone and we only have the buffered item entries.There is very little documentation online and the only two articles that I found in this topic don't show the create by association solution.
RAP( Restful ABAP programming) for OnPrem S4HANA