Showing results for 
Search instead for 
Did you mean: 

ABAP RAP - Managed scenario - Create Supplier invoice by Action using EML and I_SUPPLIERINVOICETP

0 Kudos

Dear all,

I'm quite new in ABAP RAP, I love it I hate it 😀

I'm developing an application in RAP + UI, where users put some external additional informations about a business document. This application is developed in ABAP RAP, managed scenario.

I'd like to have following scenario:

User put some additional information into UI and create / update custom business object (let's say incomming supplier invoice - detail info.)

I have validation and determination there.

In validation I check if additional data are OK and in determination I change internal state code of this business object (this works)

Save data (this works)

After save, I'm using feature control to enable action for business object with some state code (for example '01' = data complete. (this works)

But here comes a problem.

I'd like to be able to create a Supplier invoice with purchase order reference by using EML using I_SUPPLIERINVOICETP in Action method of my BO.


  action ( features : instance ) createSupplierInvoice result [1] $self;
METHOD createSupplierInvoice.

DATA ls_invoice TYPE STRUCTURE FOR ACTION IMPORT i_supplierinvoicetp~create.
DATA lt_invoice TYPE TABLE FOR ACTION IMPORT i_supplierinvoicetp~create.
DATA ld_sinv_item_id TYPE n LENGTH 6 VALUE '1'.

  DATA(ld_cid_invo_hdr) = cl_uuid_factory=>create_system_uuid( )->create_uuid_x16( ).
  CATCH cx_uuid_error.

*lt_incinvappr = table with additional data
READ TABLE lt_incinvappr ASSIGNING FIELD-SYMBOL(<ls_incinvappr>) INDEX 1.

  ls_invoice-%cid = ld_cid_invo_hdr.
  ls_invoice-%param-supplierinvoiceiscreditmemo   = abap_false.
  ls_invoice-%param-companycode                   = <ls_incinvappr>-CompanyId.
  ls_invoice-%param-invoicingparty                = <ls_incinvappr>-SupplierId.
  ls_invoice-%param-postingdate                   = <ls_incinvappr>-IssueDate.
  ls_invoice-%param-documentdate                  = <ls_incinvappr>-IssueDate.
  ls_invoice-%param-documentcurrency              = <ls_incinvappr>-Currency.
  ls_invoice-%param-invoicegrossamount            = <ls_incinvappr>-GrossAmount.
  ls_invoice-%param-taxiscalculatedautomatically  = abap_true.                      
  ls_invoice-%param-SupplierInvoiceIDByInvcgParty = <ls_incinvappr>-ExternalId.
  ls_invoice-%param-DocumentHeaderText            = 'SAP RAP Action'.
  ls_invoice-%param-TaxDeterminationDate          = <ls_incinvappr>-TaxDate.
  ls_invoice-%param-DueCalculationBaseDate        = <ls_incinvappr>-DueDate.
  ls_invoice-%param-SupplierInvoiceStatus         = cl_mmiv_rap_ext_c=>supplierinvoicestatus-held.

* lt_purchaseorder_item = table with PO reference items
  LOOP AT lt_purchaseorder_item ASSIGNING FIELD-SYMBOL(<ls_pur_item>).

    APPEND VALUE #( supplierinvoiceitem = ld_sinv_item_id
                    purchaseorder       = <ls_incinvappr>-OrderNumber
                    purchaseorderitem   = <ls_pur_item>-PurchaseOrderItem
                    documentcurrency    = <ls_incinvappr>-Currency
                    supplierinvoiceitemamount   = <ls_pur_item>-NetAmount
                    purchaseOrderQuantityUnit   = <ls_pur_item>-PurchaseOrderQuantityUnit
                    quantityinpurchaseorderunit = <ls_pur_item>-OrderQuantity
                    taxcode                     = 'V1'

    TO ls_invoice-%param-_itemswithporeference.
          ld_sinv_item_id = ld_sinv_item_id + 1.

  INSERT ls_invoice INTO TABLE lt_invoice.

* Create BO - Supplier invoice with PO ref

    ENTITY SupplierInvoice
    EXECUTE Create FROM lt_invoice

    FAILED      DATA(ls_sinvoice_create_failed)
    REPORTED    DATA(ls_sinvoice_create_reported)
    MAPPED      DATA(ls_sinvoice_create_mapped).




It simply doesn't work. I'm doing my best, but there is something which i don't understand or don't see.

I know that there can not be any Commit Entities to not to corrupt LUW. But how should I create Supplier Invoice from UI using button with action?

How can i get number of created supplier invoice - there is late numbering and I know that i have to convert %pid to key. But what is uncleare to me where. Additional Save? 

Is there any key / best practise how to use EML? I can create sales order in action method by EML and I_SALESORDERTP. But not supplier invoice. Why? What is the best practise for this scenario? How should I create supplier invoice in RAP?

Best regards,









Accepted Solutions (0)

Answers (0)