Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

bapi for MIRO

Former Member
0 Likes
898

hi,

I have to upload in MIRO documents, please tell me the BAPI to be used.

regards

prabhu

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
815

Hi,

For miro not necessarily you have to have a PO..you can create MIRO document just by adding the line items in the G/L ACCOUNT tab..

Check this example for creating a invoice for a given PO


TABLES: ekko.

PARAMETERS: p_ebeln TYPE ebeln OBLIGATORY.

DATA: itab             LIKE ekpo OCCURS 0 WITH HEADER LINE.
DATA: invoice_items    LIKE bapi_incinv_create_item OCCURS 0
                       WITH HEADER LINE.
DATA: return           LIKE bapiret2 OCCURS 0 WITH HEADER LINE.
DATA: invheader        TYPE bapi_incinv_create_header.
DATA: v_counter        TYPE rblgp.
DATA: v_amount         TYPE rbkp-rmwwr,
      v_invoice        TYPE bapi_incinv_fld-inv_doc_no,
      v_year           TYPE bapi_incinv_fld-fisc_year.


START-OF-SELECTION.

* Get ekko.
  SELECT SINGLE * FROM ekko
         WHERE ebeln = p_ebeln.

  IF sy-subrc <> 0.
    MESSAGE s208(00) WITH 'INVALID PO'.
    LEAVE LIST-PROCESSING.
  ENDIF.

* Get ekpo.
  SELECT * FROM ekpo
         INTO TABLE itab
         WHERE ebeln = p_ebeln.

  IF sy-subrc <> 0.
    MESSAGE s208(00) WITH 'INVALID PO'.
    LEAVE LIST-PROCESSING.
  ENDIF.

* Prepare the line items.
  LOOP AT itab.

* Increment the counter.
    v_counter = v_counter + 1.

* Populate the invoice line item details.
    invoice_items-invoice_doc_item = v_counter.
    invoice_items-po_number        = itab-ebeln.
    invoice_items-po_item          = itab-ebelp.
    invoice_items-item_amount      = itab-netpr *
                                        itab-menge.
    invoice_items-quantity         = itab-menge.
    invoice_items-po_unit          = itab-meins.

    APPEND invoice_items.

    v_amount = v_amount + invoice_items-item_amount.

  ENDLOOP.

* Prepare the header
  invheader-doc_date      = sy-datum.
  invheader-pstng_date    = sy-datum .
  invheader-comp_code     = ekko-bukrs.
  invheader-invoice_ind   = 'X'.
  invheader-currency      = ekko-waers.
  invheader-ref_doc_no    = 'Test Invoice'.
  invheader-gross_amount  = v_amount.



* Call the BAPI
  CALL FUNCTION 'BAPI_INCOMINGINVOICE_CREATE'
       EXPORTING
            headerdata       = invheader
       IMPORTING
            invoicedocnumber = v_invoice
            fiscalyear       = v_year
       TABLES
            itemdata         = invoice_items
            return           = return.


* Check the return code..
  LOOP AT return
          TRANSPORTING NO FIELDS
          WHERE type = 'E' OR type = 'A'.
    EXIT.
  ENDLOOP.


  IF sy-subrc = 0.
    WRITE: / 'Error in creating'.
  ELSE.
    COMMIT WORK.
    WRITE: / 'Invoice ', v_invoice, ' Year ', v_year, ' Created'.
  ENDIF.

Thanks

Naren

5 REPLIES 5
Read only

Former Member
0 Likes
815

Hi,

use the BAPI BAPI_INCOMINGINVOICE_CREATE

Thanks

Naren

Read only

0 Likes
815

hi naren,

I have to first upload the PO and then GR and then i have to do this right.

regards

prabhu

Read only

0 Likes
815

if possible send some sample code.

regards

prabhu

Read only

Former Member
0 Likes
816

Hi,

For miro not necessarily you have to have a PO..you can create MIRO document just by adding the line items in the G/L ACCOUNT tab..

Check this example for creating a invoice for a given PO


TABLES: ekko.

PARAMETERS: p_ebeln TYPE ebeln OBLIGATORY.

DATA: itab             LIKE ekpo OCCURS 0 WITH HEADER LINE.
DATA: invoice_items    LIKE bapi_incinv_create_item OCCURS 0
                       WITH HEADER LINE.
DATA: return           LIKE bapiret2 OCCURS 0 WITH HEADER LINE.
DATA: invheader        TYPE bapi_incinv_create_header.
DATA: v_counter        TYPE rblgp.
DATA: v_amount         TYPE rbkp-rmwwr,
      v_invoice        TYPE bapi_incinv_fld-inv_doc_no,
      v_year           TYPE bapi_incinv_fld-fisc_year.


START-OF-SELECTION.

* Get ekko.
  SELECT SINGLE * FROM ekko
         WHERE ebeln = p_ebeln.

  IF sy-subrc <> 0.
    MESSAGE s208(00) WITH 'INVALID PO'.
    LEAVE LIST-PROCESSING.
  ENDIF.

* Get ekpo.
  SELECT * FROM ekpo
         INTO TABLE itab
         WHERE ebeln = p_ebeln.

  IF sy-subrc <> 0.
    MESSAGE s208(00) WITH 'INVALID PO'.
    LEAVE LIST-PROCESSING.
  ENDIF.

* Prepare the line items.
  LOOP AT itab.

* Increment the counter.
    v_counter = v_counter + 1.

* Populate the invoice line item details.
    invoice_items-invoice_doc_item = v_counter.
    invoice_items-po_number        = itab-ebeln.
    invoice_items-po_item          = itab-ebelp.
    invoice_items-item_amount      = itab-netpr *
                                        itab-menge.
    invoice_items-quantity         = itab-menge.
    invoice_items-po_unit          = itab-meins.

    APPEND invoice_items.

    v_amount = v_amount + invoice_items-item_amount.

  ENDLOOP.

* Prepare the header
  invheader-doc_date      = sy-datum.
  invheader-pstng_date    = sy-datum .
  invheader-comp_code     = ekko-bukrs.
  invheader-invoice_ind   = 'X'.
  invheader-currency      = ekko-waers.
  invheader-ref_doc_no    = 'Test Invoice'.
  invheader-gross_amount  = v_amount.



* Call the BAPI
  CALL FUNCTION 'BAPI_INCOMINGINVOICE_CREATE'
       EXPORTING
            headerdata       = invheader
       IMPORTING
            invoicedocnumber = v_invoice
            fiscalyear       = v_year
       TABLES
            itemdata         = invoice_items
            return           = return.


* Check the return code..
  LOOP AT return
          TRANSPORTING NO FIELDS
          WHERE type = 'E' OR type = 'A'.
    EXIT.
  ENDLOOP.


  IF sy-subrc = 0.
    WRITE: / 'Error in creating'.
  ELSE.
    COMMIT WORK.
    WRITE: / 'Invoice ', v_invoice, ' Year ', v_year, ' Created'.
  ENDIF.

Thanks

Naren

Read only

0 Likes
815

hi naren,

thank you very much.

sorry,i dont have option to give more than 10 pts.

regards

prabhu