SAP SD BAPI

From SapWiki
Revision as of 15:46, 4 April 2020 by WikiSysop (talk | contribs)

Crear Factura VF01

 FUNCTION z_sd_crea_factura.
 *"----------------------------------------------------------------------
 *"*"Interfase local
 *"  IMPORTING
 *"     REFERENCE(I_VBELN) TYPE  LIKP-VBELN
 *"     REFERENCE(I_FKART) TYPE  RV60A-FKART
 *"     REFERENCE(I_REF_DOC_CA) TYPE  VBTYP_V
 *"     REFERENCE(I_DOC_TYPE) TYPE  AUART
 *"  EXPORTING
 *"     REFERENCE(E_VBELN) TYPE  VBRK-VBELN
 *"     REFERENCE(E_RETURN) TYPE  BAPIRET2_T
 *"----------------------------------------------------------------------
   data lt_return1 type bapiret1_tab.
 
   DATA ld_mode(1) VALUE 'A'. " 'N'.
 
   DATA lt_mtxt LIKE TABLE OF bdcmsgcoll WITH HEADER LINE.
   DATA ls_return TYPE bapiret2.
   DATA ls_return1 TYPE bapiret1.
 
   CLEAR: e_return[],
          bdcdata[],
          lt_mtxt[],
          e_vbeln.
 
   PERFORM crea_factura USING i_fkart
                              i_vbeln
                              i_ref_doc_ca
                              i_doc_type
                       CHANGING e_vbeln
                                lt_return1[].
 
 loop at lt_return1 into ls_return1.
     MOVE-CORRESPONDING ls_return1 TO ls_return.
     APPEND ls_return TO e_return.
 ENDLOOP.
 
 ENDFUNCTION.
 
 FORM crea_factura USING p_fkart
                         p_vbeln
                         p_ref_doc_ca
                         p_doc_type
                CHANGING p_vbeln_factuta
                         p_return TYPE bapiret1_tab.
 
   DATA lt_datain TYPE STANDARD TABLE OF bapivbrk WITH HEADER LINE.
   DATA lt_return TYPE STANDARD TABLE OF bapiret1 WITH HEADER LINE.
   DATA lt_success TYPE STANDARD TABLE OF bapivbrksuccess WITH HEADER LINE.
 
   CLEAR: lt_datain, lt_datain[],
          lt_return, lt_return[],
          lt_success, lt_success[].
 
   lt_datain-ref_doc    = p_vbeln.
   lt_datain-ref_doc_ca = p_ref_doc_ca. " ls_likp-vbtyp.
   lt_datain-doc_type   = p_doc_type.    "ls_likp-lfart.
   lt_datain-ordbilltyp = p_fkart.
   APPEND lt_datain.
 
   CALL FUNCTION 'BAPI_BILLINGDOC_CREATEMULTIPLE'
     TABLES
       billingdatain = lt_datain
       return        = lt_return
       success       = lt_success.
   READ TABLE lt_success INDEX 1.
   IF sy-subrc = 0.
     p_vbeln_factuta = lt_success-bill_doc.
 
     CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        WAIT          = 'X'
               .
   endif.
     p_return[] = lt_return[].
 
 ENDFORM.