SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

BAPI_ACC_DOCUMENT_POST



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Interfaces | Интерфейсы -> BAPI
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1636

PostPosted: Sun Feb 10, 2008 1:29 am    Post subject: BAPI_ACC_DOCUMENT_POST Reply with quote

BAPI_ACC_DOCUMENT_POST - Accounting: Posting
Code:
REPORT  acc_bapi_document                  .
 
selection-screen begin of block bl01 .
 
parameters:
  check_l             radiobutton group rb1,
  check_a default 'X' radiobutton group rb1,
  post                radiobutton group rb1.
selection-screen uline.
parameters:
  rev_c               radiobutton group rb1,
  rev_p               radiobutton group rb1.
selection-screen uline.
parameters:
  ref_key like bapiache01-obj_key default 'TEST000001BAPICALL',
  dest    like bdi_logsys-logsys  default '          '.
 
selection-screen end   of block bl01 .
 
data:
  gd_documentheader    like bapiache09,
  gd_customercpd       like bapiacpa09,
  gd_fica_hd           like bapiaccahd,
  it_accountreceivable like table of bapiacar09 with header line,
  it_accountgl         like table of bapiacgl09 with header line,
  it_accounttax        like table of bapiactx09 with header line,
  it_criteria          like table of bapiackec9 with header line,
  it_valuefield        like table of bapiackev9 with header line,
  it_currencyamount    like table of bapiaccr09 with header line,
  it_return            like table of bapiret2   with header line,
  it_receivers         like table of bdi_logsys with header line,
  it_fica_it           like table of bapiaccait with header line,
  it_accountpayable    like table of bapiacap09 with header line,
  it_paymentcard       like table of bapiacpc09 with header line,
  it_ext               like table of bapiacextc with header line.
*  it_re                LIKE TABLE OF bapiacre09 WITH HEADER LINE,
*  it_ext2              LIKE TABLE OF bapiparex  WITH HEADER LINE.
 
 
perform fill_internal_tables.
 
if check_l = 'X'.
 
  call function 'BAPI_ACC_DOCUMENT_CHECK'
       destination dest
       exporting
            documentheader    = gd_documentheader
            customercpd       = gd_customercpd
            contractheader    = gd_fica_hd
       tables
            accountgl         = it_accountgl
            accountreceivable = it_accountreceivable
            accountpayable    = it_accountpayable
            accounttax        = it_accounttax
*            currencyamount    = it_currencyamount
            criteria          = it_criteria
            valuefield        = it_valuefield
            extension1        = it_ext
            return            = it_return
            paymentcard       = it_paymentcard
            contractitem      = it_fica_it.
*            extension2        = it_ext2
*            realestate        = it_re.
  .
 
  write: / 'Result of check lines:'.                        "#EC NOTEXT
  perform show_messages.
 
endif.
 
if check_a = 'X'.
 
  call function 'BAPI_ACC_DOCUMENT_CHECK'
    destination dest
    exporting
      documentheader    = gd_documentheader
      customercpd       = gd_customercpd
      contractheader    = gd_fica_hd
    tables
      accountgl         = it_accountgl
      accountreceivable = it_accountreceivable
      accountpayable    = it_accountpayable
      accounttax        = it_accounttax
      currencyamount    = it_currencyamount
      criteria          = it_criteria
      valuefield        = it_valuefield
      extension1        = it_ext
      return            = it_return
      paymentcard       = it_paymentcard
      contractitem      = it_fica_it.
*      extension2        = it_ext2
*      realestate        = it_re.
 
  write: / 'Result of check all:'.                          "#EC NOTEXT
  perform show_messages.
 
endif.
 
if post = 'X'.
 
  data: l_type like gd_documentheader-obj_type,
        l_key  like gd_documentheader-obj_key,
        l_sys  like gd_documentheader-obj_sys.
 
  if dest = space or
     dest = gd_documentheader-obj_sys.
*    post synchron
 
    call function 'BAPI_ACC_DOCUMENT_POST'
      exporting
        documentheader    = gd_documentheader
        customercpd       = gd_customercpd
        contractheader    = gd_fica_hd
      importing
        obj_type          = l_type
        obj_key           = l_key
        obj_sys           = l_sys
      tables
        accountgl         = it_accountgl
        accountreceivable = it_accountreceivable
        accountpayable    = it_accountpayable
        accounttax        = it_accounttax
        currencyamount    = it_currencyamount
        criteria          = it_criteria
        valuefield        = it_valuefield
        extension1        = it_ext
        return            = it_return
        paymentcard       = it_paymentcard
        contractitem      = it_fica_it.
*        extension2        = it_ext2
*        realestate        = it_re.
 
    write: / 'Result of post:'.                             "#EC NOTEXT
    perform show_messages.
 
  else.
*   create Idoc
 
    it_receivers-logsys = dest.
    append it_receivers.
 
    call function 'ALE_ACC_DOCUMENT_POST'
      exporting
        documentheader    = gd_documentheader
        customercpd       = gd_customercpd
        contractheader    = gd_fica_hd
      tables
        accountgl         = it_accountgl
        accountreceivable = it_accountreceivable
        accountpayable    = it_accountpayable
        accounttax        = it_accounttax
        currencyamount    = it_currencyamount
        criteria          = it_criteria
        valuefield        = it_valuefield
        extension1        = it_ext
        paymentcard       = it_paymentcard
        contractitem      = it_fica_it
*        extension2        = it_ext2
*        realestate        = it_re
        receivers         = it_receivers
*       COMMUNICATION_DOCUMENTS =
*       APPLICATION_OBJECTS     =
      exceptions
        error_creating_idocs    = 1
        others                  = 2  .
 
    if sy-subrc = 0.
      write: / 'IDoc created'.                              "#EC NOTEXT
    else.
      write: sy-msgid.
    endif.
 
  endif.
endif.
 
if rev_p = 'X' or rev_c = 'X'.
  data: rev like bapiacrev,
        rev_key like ref_key.
 
  rev_key       = ref_key.
  rev_key(1)    = 'R'.
  rev-obj_type  = gd_documentheader-obj_type.
  rev-obj_key   = rev_key.
  rev-obj_sys   = gd_documentheader-obj_sys.
  rev-obj_key_r = ref_key.
 
  if rev_c is initial.
    if dest = space or
       dest = gd_documentheader-obj_sys.
 
      call function 'BAPI_ACC_DOCUMENT_REV_POST'
        exporting
          reversal = rev
          bus_act  = gd_documentheader-bus_act
        tables
          return   = it_return.
    else.
      it_receivers-logsys = dest.
      append it_receivers.
 
      call function 'ALE_ACC_DOCUMENT_REV_POST'
        exporting
          reversal                      = rev
          busact                        = gd_documentheader-bus_act
*         OBJ_TYPE                      = 'BUS6035'
*         SERIAL_ID                     = '0'
        tables
          receivers                     = it_receivers
*         COMMUNICATION_DOCUMENTS       =
*         APPLICATION_OBJECTS           =
        exceptions
          error_creating_idocs          = 1
          others                        = 2
                .
      if sy-subrc  0.
        message id sy-msgid type sy-msgty number sy-msgno
                with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      else.
        write: / 'IDoc created'.                            "#EC NOTEXT
      endif.
 
    endif.
  else.
    call function 'BAPI_ACC_DOCUMENT_REV_CHECK'
      exporting
        reversal = rev
        bus_act  = gd_documentheader-bus_act
      tables
        return   = it_return.
  endif.
 
  write: / 'Result of Reversal Posting:'.                   "#EC NOTEXT
  perform show_messages.
 
endif.
 
commit work.
 
 
 
 
*---------------------------------------------------------------------*
*      Form  fill_internal_tables
*---------------------------------------------------------------------*
form fill_internal_tables.
 
  perform fill_header.
  perform fill_accountgl.
*  perform fill_accountar.
  perform fill_accountap.
  perform fill_accounttax.
  perform fill_currencyamount.
*  perform fill_criteria.
*  perform fill_valuefield.
*  perform fill_re.
*  perform fill_cpd.
*  perform fill_contractitem.
*  perform fill_contractheader.
*  perform fill_paymentcard.
*  perform fill_extension.
 
endform.                               " fill_internal_tables
 
*---------------------------------------------------------------------*
*      Form  Show_messages
*---------------------------------------------------------------------*
form show_messages.
 
  if it_return[] is initial.
    write: / 'no messages'.
  else.
    skip 1.
    loop at it_return.
      write: /    it_return-type,
             (2)  it_return-id,
                  it_return-number,
             (80) it_return-message,
*                 IT_RETURN-LOG_NO
*                 IT_RETURN-LOG_MSG_NO
                  it_return-message_v1,
*                 IT_RETURN-MESSAGE_V2
*                 IT_RETURN-MESSAGE_V3
*                 IT_RETURN-MESSAGE_V4
             (20) it_return-parameter,
             (3)  it_return-row,
                  it_return-field.
*                 IT_RETURN-SYSTEM
    endloop.
  endif.
 
  uline.
 
endform.                               " Show_messages
 
 
*---------------------------------------------------------------------*
*       FORM fill_accountgl                                           *
*---------------------------------------------------------------------*
form fill_accountgl.
 
  clear it_accountgl.
  it_accountgl-itemno_acc     = 2.
  it_accountgl-gl_account     = '0021510201'.
  it_accountgl-item_text      = 'BAPI Test G/L line item'.  "#EC NOTEXT
 it_accountgl-bus_area       = '01'.
 it_accountgl-profit_ctr     = '0000010101'.
 it_accountgl-comp_code      = 'SLOC'.
  append it_accountgl.
 
 
  clear it_accountgl.
  it_accountgl-itemno_acc     = 3.
  it_accountgl-gl_account     = '0082000201'.
  it_accountgl-item_text      = 'BAPI Test G/L line item'.  "#EC NOTEXT
  it_accountgl-bus_area       = '01'.
  it_accountgl-profit_ctr     = '0000010101'.
  it_accountgl-comp_code      = 'SLOC'.
  it_accountgl-tax_code       = 'A3'.
  append it_accountgl.
 
 
  clear it_accountgl.
  it_accountgl-itemno_acc     = 5.
  it_accountgl-gl_account     = '0021510201'.
  it_accountgl-item_text      = 'BAPI Test G/L line item'.  "#EC NOTEXT
 it_accountgl-bus_area       = '01'.
 it_accountgl-profit_ctr     = '0000010301'.
 it_accountgl-comp_code      = 'SLOC'.
  append it_accountgl.
 
  clear it_accountgl.
  it_accountgl-itemno_acc     = 6.
  it_accountgl-gl_account     = '0082000201'.
  it_accountgl-item_text      = 'BAPI Test G/L line item'.  "#EC NOTEXT
  it_accountgl-bus_area       = '01'.
  it_accountgl-profit_ctr     = '0000010301'.
  it_accountgl-comp_code      = 'SLOC'.
  it_accountgl-tax_code       = 'A3'.
  append it_accountgl.
 
 
  clear it_accountgl.
  it_accountgl-itemno_acc     = 7.
*  it_accountgl-itemno_acc     = 8.
  it_accountgl-gl_account     = '0021510201'.
  it_accountgl-item_text      = 'BAPI Test G/L line item'.  "#EC NOTEXT
 it_accountgl-bus_area       = '90'.
 it_accountgl-profit_ctr     = '0000900008'.
 it_accountgl-comp_code      = 'CORP'.
  append it_accountgl.
 
 
  clear it_accountgl.
  it_accountgl-itemno_acc     = 8.
*  it_accountgl-itemno_acc     = 9.
  it_accountgl-gl_account     = '0082000201'.
  it_accountgl-item_text      = 'BAPI Test G/L line item'.  "#EC NOTEXT
  it_accountgl-bus_area       = '90'.
  it_accountgl-profit_ctr     = '0000900008'.
  it_accountgl-comp_code      = 'CORP'.
*  it_accountgl-tax_code       = 'A3'.
  append it_accountgl.
 
endform.                    "fill_accountgl
 
*---------------------------------------------------------------------*
*       FORM fill_header                                              *
*---------------------------------------------------------------------*
form fill_header.
 
*  CALL FUNCTION 'OWN_LOGICAL_SYSTEM_GET'
*    IMPORTING
*      own_logical_system = gd_documentheader-obj_sys.
 
* OBJ_TYPE has to be replaced by customers object key (Y* or Z*)
*  gd_documentheader-obj_type   = 'IDOC'.
*  gd_documentheader-obj_key    = ref_key.
  gd_documentheader-username   = sy-uname.
  gd_documentheader-header_txt = 'BAPI Test'.               "#EC NOTEXT
* gd_documentheader-obj_key_r  =
* GD_DOCUMENTHEADER-reason_rev =
 gd_documentheader-comp_code  = 'SLOC'.
* GD_DOCUMENTHEADER-AC_DOC_NO  =
  gd_documentheader-fisc_year  = sy-datum(4).
  gd_documentheader-doc_date   = sy-datum.
  gd_documentheader-pstng_date = sy-datum.
* GD_DOCUMENTHEADER-TRANS_DATE =
* GD_DOCUMENTHEADER-VALUE_DATE =
* GD_DOCUMENTHEADER-FIS_PERIOD =
 gd_documentheader-doc_type   = 'KR'.
 gd_documentheader-ref_doc_no = 'xxxx'.
* GD_DOCUMENTHEADER-COMPO_ACC  =
  gd_documentheader-bus_act    = 'RFBU'.
 
endform.                    "fill_header
 
*---------------------------------------------------------------------*
*       FORM fill_contractheader                                     *
*---------------------------------------------------------------------*
form fill_contractheader.
 
*  gd_fica_hd-doc_no           =
*  gd_fica_hd-doc_type_ca      =
*  gd_fica_hd-res_key          =
*  gd_fica_hd-fikey            =
*  gd_fica_hd-payment_form_ref =
 
endform.                    "fill_contractheader
 
*---------------------------------------------------------------------*
*       FORM fill_cpd                                                 *
*---------------------------------------------------------------------*
form fill_cpd.
 
*  gd_customercpd-name
*  gd_customercpd-name_2
*  gd_customercpd-name_3
*  gd_customercpd-name_4
*  gd_customercpd-postl_code
*  gd_customercpd-city
*  gd_customercpd-country
*  gd_customercpd-country_iso
*  gd_customercpd-street
*  gd_customercpd-po_box
*  gd_customercpd-pobx_pcd
*  gd_customercpd-pobk_curac
*  gd_customercpd-bank_acct
*  gd_customercpd-bank_no
*  gd_customercpd-bank_ctry
*  gd_customercpd-bank_ctry_iso
*  gd_customercpd-tax_no_1
*  gd_customercpd-tax_no_2
*  gd_customercpd-tax
*  gd_customercpd-equal_tax
*  gd_customercpd-region
*  gd_customercpd-ctrl_key
*  gd_customercpd-instr_key
*  gd_customercpd-dme_ind
*  gd_customercpd-langu_iso
 
endform.                    "fill_cpd
 
*---------------------------------------------------------------------*
*       FORM fill_ar                                                  *
*---------------------------------------------------------------------*
form fill_accountar.
 
* CLEAR it_accountreceivable.
* it_accountreceivable-itemno_acc =
* it_accountreceivable-customer   =
* IT_ACCOUNTRECEIVABLE-REF_KEY_1  =
* IT_ACCOUNTRECEIVABLE-REF_KEY_2  =
* IT_ACCOUNTRECEIVABLE-REF_KEY_3  =
* IT_ACCOUNTRECEIVABLE-PMNTTRMS   =
* IT_ACCOUNTRECEIVABLE-BLINE_DATE =
* IT_ACCOUNTRECEIVABLE-DSCT_DAYS1 =
* IT_ACCOUNTRECEIVABLE-DSCT_DAYS2 =
* IT_ACCOUNTRECEIVABLE-NETTERMS   =
* IT_ACCOUNTRECEIVABLE-DSCT_PCT1  =
* IT_ACCOUNTRECEIVABLE-DSCT_PCT2  =
* IT_ACCOUNTRECEIVABLE-PYMT_METH  =
* IT_ACCOUNTRECEIVABLE-DUNN_KEY   =
* IT_ACCOUNTRECEIVABLE-DUNN_BLOCK =
* IT_ACCOUNTRECEIVABLE-PMNT_BLOCK =
* IT_ACCOUNTRECEIVABLE-VAT_REG_NO =
* IT_ACCOUNTRECEIVABLE-ALLOC_NMBR =
* it_accountreceivable-item_text  =
* IT_ACCOUNTRECEIVABLE-PARTNER_BK =
* IT_ACCOUNTRECEIVABLE-GL_ACCOUNT =
* it_accountreceivable-comp_code
* it_accountreceivable-bus_area
* it_accountreceivable-pmtmthsupl
* it_accountreceivable-paymt_ref
* it_accountreceivable-scbank_ind
* it_accountreceivable-businessplace
* it_accountreceivable-sectioncode
* it_accountreceivable-branch
* it_accountreceivable-pymt_cur
* it_accountreceivable-pymt_cur_iso
* it_accountreceivable-pymt_amt
* it_accountreceivable-c_ctr_area
* it_accountreceivable-bank_id
* it_accountreceivable-supcountry
* it_accountreceivable-supcountry_iso
* it_accountreceivable-tax_code
* it_accountreceivable-taxjurcode
* it_accountreceivable-tax_date
* it_accountreceivable-sp_gl_ind
* it_accountreceivable-partner_guid = '1465464654'.
* APPEND it_accountreceivable.
 
endform.                    "fill_accountar
 
*---------------------------------------------------------------------*
*       FORM fill_ap                                                  *
*---------------------------------------------------------------------*
form fill_accountap.
 
  clear it_accountpayable.
  it_accountpayable-itemno_acc = 1.
*  it_accountpayable-vendor_no  = '0000060259'.
  it_accountpayable-vendor_no  = '0000060693'.
* it_accountpayable-gl_account
* it_accountpayable-ref_key_1
* it_accountpayable-ref_key_2
* it_accountpayable-ref_key_3
 it_accountpayable-comp_code = 'SLOC'.
 it_accountpayable-bus_area = '01'.
 it_accountpayable-pmnttrms = 'A000'.
* it_accountpayable-bline_date
* it_accountpayable-dsct_days1
* it_accountpayable-dsct_days2
* it_accountpayable-netterms
* it_accountpayable-dsct_pct1
* it_accountpayable-dsct_pct2
* it_accountpayable-pymt_meth
* it_accountpayable-pmtmthsupl
* it_accountpayable-pmnt_block
* it_accountpayable-scbank_ind
* it_accountpayable-supcountry
* it_accountpayable-supcountry_iso
* it_accountpayable-bllsrv_ind
* it_accountpayable-alloc_nmbr
  it_accountpayable-item_text  = 'BAPI Test A/P line item'. "#EC NOTEXT
* it_accountpayable-po_sub_no
* it_accountpayable-po_checkdg
* it_accountpayable-po_ref_no
* it_accountpayable-w_tax_code
* it_accountpayable-businessplace
* it_accountpayable-sectioncode
* it_accountpayable-instr1
* it_accountpayable-instr2
* it_accountpayable-instr3
* it_accountpayable-instr4
* it_accountpayable-branch
* it_accountpayable-pymt_cur
* it_accountpayable-pymt_amt
* it_accountpayable-pymt_cur_iso
* it_accountpayable-sp_gl_ind
 
  append it_accountpayable.
 
endform.                    "fill_accountap
 
*---------------------------------------------------------------------*
*       FORM fill_tax                                                 *
*---------------------------------------------------------------------*
form fill_accounttax.
 
  clear it_accounttax.
  it_accounttax-itemno_acc = 4.
  it_accounttax-gl_account = '0011361502'.
  it_accounttax-tax_code   = 'A3'.
  it_accounttax-acct_key   = 'VST'.
  it_accounttax-cond_key   = 'MWVS'.
* it_accounttax-itemno_tax = 8.
  append it_accounttax.
 
*  clear it_accounttax.
*  it_accounttax-itemno_acc = 7.
*  it_accounttax-gl_account = '0011361502'.
*  it_accounttax-tax_code   = 'A3'.
*  it_accounttax-acct_key   = 'VST'.
*  it_accounttax-COND_KEY   = 'MWVS'.
*  append it_accounttax.
 
*  clear it_accounttax.
**  it_accounttax-itemno_acc = 10.
*  it_accounttax-itemno_acc = 9.
*  it_accounttax-gl_account = '0011361502'.
*  it_accounttax-tax_code   = 'A3'.
*  it_accounttax-acct_key   = 'VST'.
*  it_accounttax-cond_key   = 'MWVS'.
** it_accounttax-itemno_tax = 4.
*  append it_accounttax.
 
endform.                    "fill_accounttax
 
*---------------------------------------------------------------------*
*       FORM fill_currencyamount                                      *
*---------------------------------------------------------------------*
form fill_currencyamount.
 
  clear it_currencyamount.
  it_currencyamount-itemno_acc   = 1.
  it_currencyamount-curr_type    = '00'.
  it_currencyamount-currency     = 'MXN'.
  it_currencyamount-amt_doccur   = '-7408036.2'.
  append it_currencyamount.
 
  clear it_currencyamount.
  it_currencyamount-itemno_acc   = 2.
  it_currencyamount-curr_type    = '00'.
  it_currencyamount-currency     = 'MXN'.
  it_currencyamount-amt_doccur   = '5336472.00'.
  append it_currencyamount.
 
  clear it_currencyamount.
  it_currencyamount-itemno_acc   = 3.
  it_currencyamount-curr_type    = '00'.
  it_currencyamount-currency     = 'MXN'.
  it_currencyamount-amt_doccur   = '3840.00'.
  append it_currencyamount.
 
  clear it_currencyamount.
  it_currencyamount-itemno_acc   = 4.
  it_currencyamount-curr_type    = '00'.
  it_currencyamount-currency     = 'MXN'.
  it_currencyamount-amt_base   = '5548.00'.
  it_currencyamount-amt_doccur   = '832.2'.
*  it_currencyamount-amt_doccur   = '576.00'.
*  it_currencyamount-amt_base   = '3840.00'.
  append it_currencyamount.
 
  clear it_currencyamount.
  it_currencyamount-itemno_acc   = 5.
  it_currencyamount-curr_type    = '00'.
  it_currencyamount-currency     = 'MXN'.
  it_currencyamount-amt_doccur   = '2051279.00'.
  append it_currencyamount.
 
  clear it_currencyamount.
  it_currencyamount-itemno_acc   = 6.
  it_currencyamount-curr_type    = '00'.
  it_currencyamount-currency     = 'MXN'.
  it_currencyamount-amt_doccur   = '1690.00'.
  append it_currencyamount.
 
*  clear it_currencyamount.
*  it_currencyamount-itemno_acc   = 7.
*  it_currencyamount-curr_type    = '00'.
*  it_currencyamount-currency     = 'MXN'.
*  it_currencyamount-amt_base     = '1690.00'.
*  it_currencyamount-amt_doccur   = '253.5'.
*  append it_currencyamount.
 
  clear it_currencyamount.
*  it_currencyamount-itemno_acc   = 8.
  it_currencyamount-itemno_acc   = 7.
  it_currencyamount-curr_type    = '00'.
  it_currencyamount-currency     = 'MXN'.
  it_currencyamount-amt_doccur   = '13905.00'.
  append it_currencyamount.
 
  clear it_currencyamount.
*  it_currencyamount-itemno_acc   = 9.
  it_currencyamount-itemno_acc   = 8.
  it_currencyamount-curr_type    = '00'.
  it_currencyamount-currency     = 'MXN'.
*  it_currencyamount-amt_base     = '2.70'.
  it_currencyamount-amt_doccur   = '18.00'.
  append it_currencyamount.
 
*  clear it_currencyamount.
**  it_currencyamount-itemno_acc   = 10.
*  it_currencyamount-itemno_acc   = 9.
*  it_currencyamount-curr_type    = '00'.
*  it_currencyamount-currency     = 'MXN'.
*  it_currencyamount-amt_doccur   = '2.70'.
*  it_currencyamount-amt_base     = '18.00'.
*  append it_currencyamount.
endform.                    "fill_currencyamount
 
*---------------------------------------------------------------------*
*       FORM fill_criteria                                            *
*---------------------------------------------------------------------*
form fill_criteria.
 
* CLEAR it_criteria.
* it_criteria-itemno_acc = 2.
* it_criteria-fieldname = 'BZIRK'.
* it_criteria-character = '000001'.
* append it_criteria.
 
endform.                    "fill_criteria
 
*---------------------------------------------------------------------*
*       FORM fill_valuefield                                          *
*---------------------------------------------------------------------*
form fill_valuefield.
 
* CLEAR it_valuefield.
* it_valuefield-itemno_acc = 2.
* it_valuefield-fieldname = 'VV010'.
* it_valuefield-curr_type
* it_valuefield-currency = 'EUR'.
* it_valuefield-currency_iso
* it_valuefield-amt_valcom
* it_valuefield-base_uom
* it_valuefield-base_uom_iso
* it_valuefield-qua_valcom
* append it_valuefield.
 
endform.                    "fill_valuefield
 
*---------------------------------------------------------------------*
*       FORM fill_extension                                           *
*---------------------------------------------------------------------*
form fill_extension.
 
* CLEAR it_ext.
* it_ext-field1
* it_ext-field2
* it_ext-field3
* it_ext-field4
* APPEND it_ext.
 
* DATA: ls_zzz TYPE ZZZ_ACCIT.
* CLEAR it_ext2.
* it_ext2-structure = 'ZZZ_ACCIT'.
*  ls_zzz-posnr = 2.
*  ls_zzz-awref_reb = '123654'.
*  ls_zzz-aworg_reb = '654654'.
*  ls_zzz-grant_nbr = '0022002'.
* MOVE ls_zzz TO it_ext2-valuepart1.
* APPEND it_ext2.
 
endform.                    "fill_extension
 
*---------------------------------------------------------------------*
*       FORM fill_paymentcard                                         *
*---------------------------------------------------------------------*
form fill_paymentcard.
 
*  CLEAR it_paymentcard.
*  it_paymentcard-itemno_acc = 1.
*  it_paymentcard-cc_glaccount
*  it_paymentcard-cc_type
*  it_paymentcard-cc_number
*  it_paymentcard-cc_seq_no
*  it_paymentcard-cc_valid_f
*  it_paymentcard-cc_valid_t
*  it_paymentcard-cc_name
*  it_paymentcard-dataorigin
*  it_paymentcard-authamount = '100'.
*  it_paymentcard-currency = 'EUR'.
*  it_paymentcard-currency_iso
*  it_paymentcard-cc_autth_no
*  it_paymentcard-auth_refno
*  it_paymentcard-auth_date
*  it_paymentcard-auth_time
*  it_paymentcard-merchidcl
*  it_paymentcard-point_of_receipt
*  it_paymentcard-terminal
*  it_paymentcard-cctyp = '1'.
*  APPEND it_paymentcard.
 
endform.                    "fill_paymentcard
 
*---------------------------------------------------------------------*
*       FORM fill_contractitem                                        *
*---------------------------------------------------------------------*
form fill_contractitem.
 
* CLEAR it_fica_it.
*  it_fica_it-itemno_acc
*  it_fica_it-cont_acct
*  it_fica_it-main_trans
*  it_fica_it-sub_trans
*  it_fica_it-func_area
*  it_fica_it-fm_area
*  it_fica_it-cmmt_item
*  it_fica_it-funds_ctr
*  it_fica_it-fund
* append it_fica_it.
 
endform.                    "fill_contractitem
 
*&---------------------------------------------------------------------*
*&      Form  fill_re
*&---------------------------------------------------------------------*
form fill_re .
 
*  CLEAR it_re.
*  it_re-itemno_acc      =
*  it_re-business_entity =
*  it_re-building        =
*  it_re-property        =
*  it_re-rental_object   =
*  it_re-serv_charge_key =
*  it_re-settlement_unit =
*  it_re-contract_no     =
*  APPEND it_re.
*
 
endform.                    "fill_re
Back to top
View user's profile Send private message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1636

PostPosted: Mon Jun 23, 2008 1:32 pm    Post subject: Reply with quote

Code:
    LOOP AT gt_data INTO gw_data.
      MOVE gw_data TO lw_data.
      AT NEW posnr.
        MOVE sy-tabix TO from_row.
        gw_header-comp_code = lw_data-bukrs.
        gw_header-doc_type  = lw_data-blart.
        gw_header-pstng_date = lw_data-budat.
        gw_header-doc_date = lw_data-bldat.
        gw_header-username = sy-uname.
        gw_header-bus_act  = 'RFBU'.
        gw_header-ref_doc_no = lw_data-xblnr.
        gw_header-header_txt = lw_data-bktxt.
      ENDAT.
      MOVE sy-tabix TO to_row.
      APPEND lw_data TO lt_errdata.
      gw_acgl-itemno_acc = gw_acgl-itemno_acc + 1.
      IF gw_data-koart = 'C'.
        gw_acre-itemno_acc = gw_acgl-itemno_acc.
        WRITE gw_data-hkont TO gw_acre-customer.
        gw_acre-comp_code = lw_data-bukrs.
        gw_acre-bus_area    = gw_data-gsber.
        gw_acre-item_text  = gw_data-sgtxt.
        gw_acre-alloc_nmbr  = gw_data-zuonr.
        gw_acre-tax_code    = gw_data-mwskz.
        APPEND gw_acre TO gt_acre.
      ELSEIF gw_data-koart = 'V'.
        gw_acpa-itemno_acc = gw_acgl-itemno_acc.
        WRITE gw_data-hkont TO gw_acpa-vendor_no.
        gw_acpa-comp_code = lw_data-bukrs.
        gw_acpa-bus_area    = gw_data-gsber.
        gw_acpa-item_text  = gw_data-sgtxt.
        gw_acpa-alloc_nmbr  = gw_data-zuonr.
        gw_acpa-tax_code    = gw_data-mwskz.
        APPEND gw_acpa TO gt_acpa.
      ELSEIF gw_data-koart = 'G'.
        WRITE gw_data-hkont TO gw_acgl-gl_account.
        gw_acgl-bus_area    = gw_data-gsber.
        IF gw_data-kostl IS INITIAL.
          CLEAR gw_acgl-costcenter.
        ELSE.
          WRITE gw_data-kostl TO gw_acgl-costcenter.
        ENDIF.
        gw_acgl-tax_code    = gw_data-mwskz.
        gw_acgl-orderid     = gw_data-vbel2.
        IF gw_data-projk IS INITIAL.
          CLEAR gw_acgl-wbs_element.
        ELSE.
          gw_acgl-wbs_element = gw_data-projk.
        ENDIF.
        gw_acgl-item_text  = gw_data-sgtxt.
        gw_acgl-alloc_nmbr  = gw_data-zuonr.
        APPEND gw_acgl TO gt_acgl.
      ENDIF.
      gw_amt-itemno_acc = gw_acgl-itemno_acc.
      gw_amt-currency   = gw_data-waers.
      gw_amt-amt_doccur = gw_data-wrbtr.
      gw_amt-amt_base   = gw_data-wmwst.
      APPEND gw_amt TO gt_amt.

        CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
          EXPORTING
            documentheader    = gw_header
          TABLES
            accountgl         = gt_acgl
            accountreceivable = gt_acre
            accountpayable    = gt_acpa
            currencyamount    = gt_amt
            return            = gt_ret.
Back to top
View user's profile Send private message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1636

PostPosted: Tue Jun 24, 2008 4:52 pm    Post subject: Reply with quote

Fragment from Sapfans by RosieBrent

Code:
REPORT yrb_test_boc_postng_via_bapi.

DATA: doc_header LIKE bapiache08,
      doc_item   LIKE bapiacgl08 OCCURS 0 WITH HEADER LINE,
      doc_values LIKE bapiaccr08 OCCURS 0 WITH HEADER LINE,
      return     LIKE bapiret2 OCCURS 0 WITH HEADER LINE,
      extension1 like BAPIEXTC occurs 0 with header line,
      obj_type   LIKE bapiache08-obj_type,
      obj_key    LIKE bapiache02-obj_key,
      obj_sys    LIKE bapiache02-obj_sys,
      docnum     LIKE bkpf-belnr.

* Fill Document Header
doc_header-username = sy-uname.
doc_header-header_txt = 'TEST BOC BAPI POSTING'.
doc_header-comp_code = '1500'.
doc_header-doc_date = '20040901'.
doc_header-pstng_date = sy-datlo.
doc_header-doc_type = 'SA'.
* Fill Line 1 of Document Item
doc_item-itemno_acc = '1'.
doc_item-gl_account = '0000084600'.
doc_item-pstng_date = sy-datlo.
doc_item-item_text = 'TEST POSTING DEBIT ITEM'.
doc_item-costcenter = '0000006300'.
doc_item-orderid = 'M5253'.
APPEND doc_item.
CLEAR doc_item.
* Fill Line 2 of Document Item
doc_item-itemno_acc = '2'.
doc_item-gl_account = '0000021960'.
doc_item-pstng_date = sy-datlo.
doc_item-item_text = 'TEST POSTING CREDIT ITEM'.
APPEND doc_item.
CLEAR doc_item.
* Fill Line 1 of Document Value.
doc_values-itemno_acc = '1'.
doc_values-currency_iso = 'GBP'.
doc_values-amt_doccur = '0.02-'.
APPEND doc_values.
CLEAR doc_values.
* Fill Line 2 of Document Value
doc_values-itemno_acc = '2'.
doc_values-currency_iso = 'GBP'.
doc_values-amt_doccur = '0.02'.
APPEND doc_values.
CLEAR doc_values.
* Add tax code in extension1 table.
extension1-field1 = 'BAPI CALL'.
APPEND EXTENSION1.
* All tables filled - now call BAPI.
CALL FUNCTION 'BAPI_ACC_GL_POSTING_POST'
  EXPORTING
    documentheader       = doc_header
  IMPORTING
    OBJ_TYPE             = doc_header-obj_type
    OBJ_KEY              = doc_header-obj_key
    OBJ_SYS              = doc_header-obj_sys
  TABLES
    accountgl            = doc_item
    currencyamount       = doc_values
    return               = return
    EXTENSION1           = EXTENSION1.
LOOP AT return WHERE type = 'E'.
  EXIT.
ENDLOOP.
IF sy-subrc EQ 0.
  WRITE: / 'BAPI call failed - debug and fix!'.
ELSE.
  CLEAR return.
  REFRESH return.
  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
* EXPORTING
*   WAIT          =
   IMPORTING
     return        = return.
  WRITE: / 'BAPI call worked!!'.
  WRITE: / doc_header-obj_key, ' posted'.
ENDIF.
Back to top
View user's profile Send private message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1636

PostPosted: Sat Nov 01, 2008 4:40 pm    Post subject: Reply with quote

Code:
data: gs_DOCUMENTHEADER like BAPIACHE09.

data: gs_accountgl like BAPIACGL09.
data: begin of gt_accountgl occurs 0.
include structure BAPIACGL09.
data: end of gt_accountgl.

data: gs_accountpayable like BAPIACAP09.
data: begin of gt_accountpayable occurs 0.
include structure BAPIACAP09.
data: end of gt_accountpayable.

DATA: gs_currencyamount like BAPIACCR09.
data: begin of gt_currencyamount occurs 0.
include structure BAPIACCR09.
data: end of gt_currencyamount.

data: begin of gt_return occurs 0.
include structure BAPIRET2.
data: end of gt_return.

DATA: gv_obj_type LIKE BAPIACHE09-OBJ_TYPE,
gv_obj_key LIKE BAPIACHE09-OBJ_KEY,
gv_obj_sys LIKE BAPIACHE09-OBJ_SYS.

gs_documentheader-bus_act = 'RFBU'.
gs_documentheader-username = sy-uname.
gs_documentheader-header_txt = 'test'.
gs_documentheader-comp_code = '3100'.
gs_documentheader-doc_date = '08282006'.
gs_documentheader-pstng_date = '08282006'.
gs_documentheader-doc_type = 'KA'.

gs_accountpayable-itemno_acc = '2'.
gs_accountpayable-vendor_no = '0060001439'.
APPEND gs_accountpayable TO gt_accountpayable.

gs_accountgl-itemno_acc = '1'.
gs_accountgl-gl_account = '0000825100'.
gs_accountgl-costcenter = '0000010500'.
APPEND gs_accountgl TO gt_accountgl.

gs_currencyamount-itemno_acc = '1'.
gs_currencyamount-currency = 'USD'.
gs_currencyamount-amt_doccur = '350.00'. "i_tab-repval.
APPEND gs_currencyamount TO gt_currencyamount.

gs_currencyamount-itemno_acc = '2'.
gs_currencyamount-currency = 'USD'.
gs_currencyamount-amt_doccur = '-350.00'. "i_tab-repval.
APPEND gs_currencyamount TO gt_currencyamount.

CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
EXPORTING
documentheader = gs_documentheader
IMPORTING
obj_type = gv_obj_type
obj_key = gv_obj_key
obj_sys = gv_obj_sys
TABLES
accountgl = gt_accountgl
accountpayable = gt_accountpayable
currencyamount = gt_currencyamount
return = gt_return.
Back to top
View user's profile Send private message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1636

PostPosted: Sat Nov 01, 2008 4:42 pm    Post subject: Reply with quote

By Florian Kemmer.

Code:
PERFORM build_documentheader
     USING        ls_data
     CHANGING ls_documentheader.
 
PERFORM build_documentpositions
    TABLES   lt_currencyamount
                   lt_accountgl
                   lt_accounttax
     USING    ls_data.
 
CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
            EXPORTING
              documentheader = ls_documentheader
            TABLES
              accountgl      = lt_accountgl
              currencyamount = lt_currencyamount
              accounttax     = lt_accounttax
              return         = lt_return.
 
NOW the code for the routines:
 
FORM build_documentheader
  USING    ls_data           LIKE LINE OF gt_data
  CHANGING ls_documentheader TYPE bapiache09.
 
 
  ls_documentheader-bus_act     = 'RFBU'.
  ls_documentheader-username    = sy-uname.
  ls_documentheader-pstng_date  = ls_cpudt.
  ls_documentheader-header_txt  = 'Vertreterprovision'.
  ls_documentheader-comp_code   = ls_data-vkorg.
  ls_documentheader-doc_date    = sy-datum.
  ls_documentheader-doc_type    = 'DG'.
 
 
ENDFORM.
 
FORM build_documentpositions
  TABLES   lt_currencyamount    TYPE tt_currencyamount
           lt_accountgl         TYPE tt_acountlg
           lt_accounttax        TYPE tt_accounttax
  USING    ls_data              LIKE LINE OF gt_data.
 
  DATA:    ls_accountgl         LIKE LINE OF lt_accountgl,
           ls_currencyamount    LIKE LINE OF lt_currencyamount,
           ls_accounttax        LIKE LINE OF lt_accounttax,
           ls_vbrp              TYPE vbrp.
 
  DATA:    lv_debitor           TYPE kunnr,
           lv_akont             TYPE knb1-akont,
           lv_swap_vbeln        TYPE char20,
           lv_swap_posnr        TYPE char20,
           lv_swap_vbelv        TYPE char20,
           lv_swap_posnv        TYPE char20,
           lv_swap_vtrnr        TYPE char20,
           lv_lkz               TYPE adrc-country,
           lv_land              TYPE t005t-landx,
           lv_tax_code          TYPE c LENGTH 2,
           lv_tax_rate          TYPE fwste.
 
 
  CLEAR: lt_currencyamount, lt_accountgl.
 
  SELECT SINGLE aubel aupos vbelv posnv prctr  "ermittle Auftrag zur Faktura
  FROM   vbrp
  INTO   CORRESPONDING FIELDS OF ls_vbrp
  WHERE  vbeln = ls_data-vbeln
  AND    posnr = ls_data-posnr.
 
 
  SELECT SINGLE akont
  FROM   knb1
  INTO   lv_akont
  WHERE  kunnr = ls_data-vtrnr
  AND    bukrs = ls_data-bukrs.
 
 
*
* 04.02.2008 FIS/pb
* Korrektur : Land steht schon in der KNA1
*
 
  SELECT SINGLE land1
  FROM   kna1
  INTO   lv_lkz
  WHERE  kunnr = ls_data-vtrnr.
 
*  break fis-kemmer.
 
  IF ls_data-vtrnr EQ '0000900021' OR ls_data-vtrnr EQ '0000900008'.
    lv_tax_code = '46'.
    ls_accounttax-itemno_acc = '03'.
    ls_accounttax-tax_code   = lv_tax_code.
    ls_accounttax-gl_account   = '0000263110'.
    ls_accounttax-direct_tax = 'X'.
    ls_accounttax-cond_key    = 'MWVS'.
    ls_accounttax-acct_key    = 'VST'.
    APPEND ls_accounttax TO lt_accounttax.
    CLEAR  ls_accounttax.
    ls_currencyamount-amt_base = ls_data-prov.
  ELSE.
    CASE lv_lkz.
      WHEN 'DE'.
        lv_tax_code = 'V1'.
      WHEN OTHERS.
        lv_tax_code = 'U7'.
    ENDCASE.
  ENDIF.
 
  ls_accountgl-itemno_acc = '01'.
  ls_accountgl-gl_account = lv_akont.
  ls_accountgl-tax_code   = lv_tax_code.
  ls_accountgl-customer   = ls_data-vtrnr.
  ls_accountgl-acct_type  = 'D'.
 
  WRITE ls_data-vbeln TO lv_swap_vbeln LEFT-JUSTIFIED NO-ZERO.
  WRITE ls_data-posnr TO lv_swap_posnr LEFT-JUSTIFIED NO-ZERO.
  WRITE ls_data-vtrnr TO lv_swap_vtrnr LEFT-JUSTIFIED NO-ZERO.
  WRITE ls_vbrp-vbelv TO lv_swap_vbelv LEFT-JUSTIFIED NO-ZERO.
  WRITE ls_vbrp-posnv TO lv_swap_posnv LEFT-JUSTIFIED NO-ZERO.
 
  CONDENSE: lv_swap_vbeln, lv_swap_posnr, lv_swap_vtrnr, lv_swap_vbelv, lv_swap_posnv.
 
  CONCATENATE lv_swap_vbeln ';'
              lv_swap_posnr ';'
              lv_swap_vtrnr ';'
              lv_swap_vbelv ';'
              lv_swap_posnv ';'
              ls_data-name1
  INTO ls_accountgl-item_text.
 
  APPEND ls_accountgl TO lt_accountgl.
  CLEAR  ls_accountgl.
 
  ls_currencyamount-itemno_acc = '01'.
  ls_currencyamount-curr_type  = '00'.
  ls_currencyamount-currency   = ls_data-waers.
  ls_currencyamount-amt_doccur = ls_data-prov * -1.
 
  APPEND ls_currencyamount TO lt_currencyamount.
  CLEAR ls_currencyamount.
 
  ls_accountgl-itemno_acc = '02'.
  ls_accountgl-gl_account = p_konto.
  ls_accountgl-tax_code   = lv_tax_code.
  CONCATENATE ls_data-vbeln ls_data-posnr INTO ls_accountgl-item_text.
  ls_accountgl-profit_ctr = ls_vbrp-prctr.
  ls_accountgl-sales_ord  = ls_vbrp-vbelv.
  ls_accountgl-s_ord_item = ls_vbrp-posnv.
 
  APPEND ls_accountgl TO lt_accountgl.
  CLEAR  ls_accountgl.
 
  CALL FUNCTION 'RECP_FI_TAX_CALCULATE'
    EXPORTING
      ic_bukrs    = '1000'
      ic_mwskz    = lv_tax_code
      ic_waers    = 'EUR'
    IMPORTING
      ep_tax_rate = lv_tax_rate
    EXCEPTIONS
      not_found   = 1
      OTHERS      = 2.
 
  IF sy-subrc  0.
 
  ENDIF.
 
  ls_currencyamount-itemno_acc = '02'.
  ls_currencyamount-curr_type  = '00'.
  ls_currencyamount-currency   = ls_data-waers.
  ls_currencyamount-amt_doccur = ls_data-prov - ( ls_data-prov / 100 * lv_tax_rate ).
 
  APPEND ls_currencyamount TO lt_currencyamount.
  CLEAR ls_currencyamount.
 
  IF ls_data-vtrnr EQ '0000900021' OR ls_data-vtrnr EQ '0000900008'.
    ls_currencyamount-itemno_acc = '03'.
    ls_currencyamount-curr_type  = '00'.
    ls_currencyamount-currency   = ls_data-waers.
    ls_currencyamount-amt_base   = ls_data-prov .
    ls_currencyamount-amt_doccur = ls_data-prov / 100 * lv_tax_rate.
 
    APPEND ls_currencyamount TO lt_currencyamount.
    CLEAR  ls_currencyamount.
  ENDIF.
ENDFORM.
Back to top
View user's profile Send private message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1636

PostPosted: Sat Nov 01, 2008 4:47 pm    Post subject: Reply with quote

BAPI_ACC_DOCUMENT_POST and tax posting through the BAPI
By Nicolai marco.

I use this function in some program i try to give to u how to set the minimum value in the structure/tables of the bapi.

DOCUMENTHEADER
Code:
 
BUS_ACT = 'RFBU' "for FI document
USERNAME = sy-uname
HEADER_TXT = your text
COMP_CODE = Company code
DOC_DATE = Document date
PSTNG_DATE = Posting date
FISC_YEAR(1) = The year of posting date
FIS_PERIOD(1) = the period of posting date
DOC_TYPE = document type


if you set a different year or period from the value that you have in the posting date the bapi trigger an error

ACCOUNT GL
Code:
ITEMNO_ACC = progessive number
GL_ACCOUNT = G/L Account
ITEM_TEXT = item text
DOC_TYPE = document type (the same of the header for all item)
COMP_CODE = company code (the same of the header for all item)
BUS_AREA = business area
TAX_CODE = tax code


if you set a different doc_type or company code for each item the bapi trigger an error

ACCOUNTTAX
Code:
ITEMNO_ACC = progressive number
GL_ACCOUNT = G/L Account referred to TAX CODE
TAX_CODE = TAX CODE
TAX_RATE = TAX RATE
ITEMNO_TAX = progressive number which tax item is referred


CURRENCYAMOUNT
Code:
ITEMNO_ACC = progressive number
CURRENCY = currency
CURRENCY_ISO = iso currency that you find in TCURC-ISOCD table
AMT_DOCCUR = amount with sign the sign +/- identify Debit/Credit Indicator


this field only for tax record
AMT_BASE = is the AMT_DOCCUR of the line which ypu want to calculate the tax with sign
TAX_AMT = tax amount

usually for calculate the correct value i use these functions 'CALCULATE_TAX_FROM_GROSSAMOUNT' or 'CALCULATE_TAX_FROM_NET_AMOUNT' it depends if i have the net or gross amount.

for example:

DOCUMENTHEADER
Code:
BUS_ACT = 'RFBU'
USERNAME = sy-uname
HEADER_TXT = 'my_text'
COMP_CODE = '0001'
DOC_DATE = '20080115'
PSTNG_DATE = '20080115'
FISC_YEAR(1) = '2008'
FIS_PERIOD(1) = '01'
DOC_TYPE = 'SA'


ACCOUNT GL
Code:
*Record 1
ITEMNO_ACC = 0000000001
GL_ACCOUNT = 0290111010
ITEM_TEXT = ITEM_TEXT
DOC_TYPE = SA
COMP_CODE = 0001
BUS_AREA = GS1

*Record 2
ITEMNO_ACC = 0000000002
GL_ACCOUNT = 0500103900
ITEM_TEXT = ITEM_TEXT
DOC_TYPE = SA
COMP_CODE = 0001
TAX_CODE = V2


ACCOUNTTAX
Code:
* Record 3
ITEMNO_ACC = 0000000003
GL_ACCOUNT = 0221103001
TAX_CODE = V2
TAX_RATE = 20.000
ITEMNO_TAX = 0000000002


CURRENCYAMOUNT
Code:
*Record 1
ITEMNO_ACC = 0000000001
CURRENCY = EUR
CURRENCY_ISO = EUR
AMT_DOCCUR = 150.00
AMT_BASE = 0.00
TAX_AMT = 0.00

*Record 2
ITEMNO_ACC = 0000000002
CURRENCY = EUR
CURRENCY_ISO = EUR
AMT_DOCCUR = -125.00
AMT_BASE = 0.00
TAX_AMT = 0.00

*Record 3
ITEMNO_ACC = 0000000003
CURRENCY = EUR
CURRENCY_ISO = EUR
AMT_DOCCUR = -25.00
AMT_BASE = -125.00
TAX_AMT = -25.00
Back to top
View user's profile Send private message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1636

PostPosted: Sat Nov 01, 2008 4:49 pm    Post subject: Reply with quote

Code:
DATA: it_acc_gl LIKE bapiacgl09 OCCURS 0 WITH HEADER LINE,
      it_acc_ap LIKE bapiacap09 OCCURS 0 WITH HEADER LINE,
      it_return LIKE bapiret2 OCCURS 0 WITH HEADER LINE,
      it_curr_amt LIKE bapiaccr09 OCCURS 0 WITH HEADER LINE,
      it_doc_header LIKE bapiache09 OCCURS 0 WITH HEADER LINE,
      it_acc_tax LIKE bapiactx09 OCCURS 0 WITH HEADER LINE,
      obj_type LIKE bapiache09-obj_type,
      obj_key LIKE bapiache09-obj_key,
      obj_sys LIKE bapiache09-obj_sys,
      pstng_date LIKE it_doc_header-pstng_date,
      doc_date LIKE it_doc_header-doc_date,
      loop_cnt TYPE i VALUE 0,
      gv_vendor(10) TYPE c,
      gv_gl_acc(10) TYPE c.

LOOP AT bdc_source.
* First line of table is heading so don't do anything
  IF bdc_layout IS INITIAL.
    MOVE bdc_source TO bdc_layout.
    TRANSLATE bdc_layout TO UPPER CASE.
    CONTINUE.
  ENDIF.
  bdc_out = bdc_source.
  CLEAR: obj_type, obj_sys, obj_key, pstng_date, doc_date, gv_vendor,
  gv_gl_acc.
* Setup the dates in correct format
  CONCATENATE bdc_source-col_c+6(4) bdc_source-col_c(2)
  bdc_source-col_c+3(2) INTO pstng_date.
  CONCATENATE bdc_source-col_b+6(4) bdc_source-col_b(2)
  bdc_source-col_b+3(2) INTO doc_date.
* Padding zeros, very important otherwise bunch of stuff is missing
  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
       EXPORTING
            input  = bdc_source-col_e
       IMPORTING
            output = gv_vendor.
  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
       EXPORTING
            input  = bdc_source-col_j
       IMPORTING
            output = gv_gl_acc.
* Header
  REFRESH it_doc_header.
  it_doc_header-bus_act = 'RFBU'.
  it_doc_header-username = sy-uname.
  it_doc_header-header_txt = bdc_source-col_h. " Invoice Text
  it_doc_header-comp_code = bdc_source-col_a. " Company Code
  it_doc_header-doc_date = doc_date. " Invoice Date
  it_doc_header-pstng_date = pstng_date. " Posting Date
  it_doc_header-doc_type = 'KR'. " Return Order...?
  it_doc_header-ref_doc_no = bdc_source-col_d. " Invoice Number
  APPEND it_doc_header.
* GL Account
  REFRESH it_acc_gl.
  it_acc_gl-itemno_acc = '1'.
  it_acc_gl-gl_account = gv_gl_acc. " GL Account
  it_acc_gl-item_text = bdc_source-col_o. " Line Item Text
  it_acc_gl-doc_type = 'KR'. " Return Order...?
  it_acc_gl-comp_code = bdc_source-col_a. " Company Code
  it_acc_gl-pstng_date = pstng_date. " Posting Date
  it_acc_gl-vendor_no = gv_vendor. " Vendor Number
  it_acc_gl-costcenter = bdc_source-col_k. " Cost Center
  it_acc_gl-wbs_element = bdc_source-col_q. " WBS Element
  "it_acc_gl-tax_code = bdc_source-col_m. " Tax Code
  it_acc_gl-network = bdc_source-col_p. " Internal Order
  conv_s_amt = bdc_source-col_f. " Invoice Amount
  REPLACE all occurrences of ',' in conv_s_amt WITH ''.
  IF conv_s_amt < 0.
    it_acc_gl-de_cre_ind = 'H'. " H-Credit
    conv_s_amt = - conv_s_amt.
  ELSE.
    it_acc_gl-de_cre_ind = 'S'. " S-Debit
  ENDIF.
  CONDENSE conv_s_amt.
  APPEND it_acc_gl.
* AP Account
  REFRESH it_acc_ap.
  it_acc_ap-itemno_acc = '2'. " Invoice Number
  it_acc_ap-vendor_no = gv_vendor. " Vendor Number
  it_acc_ap-comp_code = bdc_source-col_a. " Company Code
  it_acc_ap-item_text = bdc_source-col_o. " Line Item Text
  APPEND it_acc_ap.
* Currancy
  REFRESH it_curr_amt.
  it_curr_amt-itemno_acc = '1'. " Invoice Number
  it_curr_amt-curr_type = '00'.
  it_curr_amt-currency = bdc_source-col_g. " Currancy
  it_curr_amt-amt_doccur = conv_s_amt. " Line Item Amount
  APPEND it_curr_amt.
  it_curr_amt-itemno_acc = '2'. " Invoice Number
  it_curr_amt-curr_type = '00'.
  it_curr_amt-currency = bdc_source-col_g. " Currancy
  it_curr_amt-amt_doccur = conv_s_amt * -1. " Line Item Amount
  APPEND it_curr_amt.
  REFRESH it_return.
* Do the post to GL Account and AP
  CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
       EXPORTING
            documentheader = it_doc_header
       IMPORTING
            obj_type       = obj_type
            obj_key        = obj_key
            obj_sys        = obj_sys
       TABLES
            accountgl      = it_acc_gl
            currencyamount = it_curr_amt
            accountpayable = it_acc_ap
            return         = it_return.
  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
       EXPORTING
            wait = 'X'.
* Check for any errors
  loop_cnt = 0.
  LOOP AT it_return.
    IF it_return-type = 'E'.
      bdc_out-code = 'E'.
      error_count = error_count + 1.
    ELSE.
      bdc_out-code = 'S'.
    ENDIF.
    loop_cnt = loop_cnt + 1.
    IF loop_cnt = 1.
      bdc_out-mesg1 = it_return-message.
    ELSE.
      IF loop_cnt = 2.
        bdc_out-mesg2 = it_return-message.
      ENDIF.
    ENDIF.
  ENDLOOP.
  APPEND bdc_out.
  cur_line = cur_line + 1.
ENDLOOP.
Back to top
View user's profile Send private message
vga
Мастер
Мастер


Age: 48
Joined: 04 Oct 2007
Posts: 1218
Location: Питер

PostPosted: Wed Apr 03, 2013 9:34 am    Post subject: Reply with quote

Code:
*---------------------------------------------------------------------*
*       FORM post_addition_acc_document                                    *
*---------------------------------------------------------------------*
FORM post_addition_acc_document
        TABLES   pt_item   STRUCTURE bapi_incinv_create_item
                 pt_mseg   STRUCTURE mseg
        USING    ps_ekko   TYPE ekko
        CHANGING ps_header TYPE bapi_incinv_create_header.

  CONSTANTS:
    c_taklv_0 TYPE mara-taklv VALUE '0',
    c_taklv_1 TYPE mara-taklv VALUE '1',
    c_taklv_2 TYPE mara-taklv VALUE '2'.

  DATA: ls_header TYPE bapiache09,
        lt_return TYPE TABLE OF bapiret2,
        ls_return TYPE bapiret2.
  DATA: l_message TYPE text120.

  DATA: l_itemno_acc TYPE posnr_acc,
        l_itemno_tax TYPE taxps,
        lt_glacc TYPE TABLE OF bapiacgl09,
        ls_glacc TYPE bapiacgl09,
        lt_extension TYPE TABLE OF bapiacextc,
        ls_extension TYPE bapiacextc,
        lt_accounttax TYPE TABLE OF bapiactx09,
        ls_accounttax TYPE bapiactx09,
        lt_accountpayable TYPE TABLE OF bapiacap09,
        ls_accountpayable TYPE bapiacap09,
        lt_currencyamount TYPE TABLE OF bapiaccr09,
        ls_currencyamount TYPE bapiaccr09.

  DATA: BEGIN OF ls_obj_key,
        belnr  TYPE bkpf-belnr,
        bukrs  TYPE bkpf-bukrs,
        gjahr  TYPE bkpf-gjahr,
        END OF ls_obj_key.
  DATA: l_flag TYPE as4flag,
        l_obj_type TYPE  bapiache09-obj_type,
        l_obj_key  TYPE  bapiache09-obj_key,
        l_obj_sys  TYPE  bapiache09-obj_sys.

  TYPES: BEGIN OF ty_mwskz,
        taklv TYPE mara-taklv,
        mwskz TYPE ekpo-mwskz,
        dmbtr TYPE mseg-dmbtr,
        ebeln TYPE ekpo-ebeln,
        ebelp TYPE ekpo-ebelp,
        lifn2 TYPE ekpa-lifn2,
        bstmg TYPE mseg-bstmg,
        bstme TYPE mseg-bstme,
        bprme TYPE ekpo-bprme,
        bpmng TYPE mseg-bpmng,
        wmwst TYPE rtax1u15-wmwst,
        kbetr TYPE rtax1u15-kbetr,
        hkont TYPE rtax1u15-hkont,
        kawrt TYPE rtax1u15-kawrt,
        ktosl TYPE rtax1u15-ktosl,
        kschl TYPE rtax1u15-kschl,
        msatz TYPE rtax1u15-msatz,
        END OF ty_mwskz.
  DATA: lr_ebeln TYPE RANGE OF mseg-ebeln,
        ls_ebeln LIKE LINE OF lr_ebeln.
  DATA: lt_taklv TYPE TABLE OF mara-taklv,
        l_taklv  TYPE mara-taklv,
        lt_lifn2 TYPE TABLE OF ekpa-lifn2,
        l_lifn2  TYPE ekpa-lifn2,
        lt_ekpo  TYPE TABLE OF ekpo,
        ls_ekpo  TYPE ekpo,
        lt_ekpa  TYPE TABLE OF ekpa,
        ls_ekpa  TYPE ekpa,
        ls_mseg  TYPE mseg,
        lt_mwskz TYPE TABLE OF ty_mwskz,
        ls_mwskz TYPE ty_mwskz,
        lt_mwdat TYPE TABLE OF rtax1u15,
        ls_mwdat TYPE rtax1u15.

  ls_ebeln-sign = 'I'.
  ls_ebeln-option = 'EQ'.
  LOOP AT pt_mseg.
    ls_ebeln-low = pt_mseg-ebeln.
    COLLECT ls_ebeln INTO lr_ebeln.
  ENDLOOP.
  CHECK NOT lr_ebeln IS INITIAL.

* Infosammlung aus EKPA (Partnerrollen im Einkauf)
  SELECT *
  INTO TABLE lt_ekpa
  FROM ekpa
  WHERE ebeln IN lr_ebeln.

* Infosammlung aus EKPO (Einkaufsbelegposition)
* Positionstab auslesen (Nettobetrag, Menge)
  SELECT *
  INTO TABLE lt_ekpo
  FROM ekpo
  WHERE ebeln IN lr_ebeln.

  LOOP AT pt_mseg INTO ls_mseg.
    READ TABLE lt_ekpo INTO ls_ekpo
      WITH KEY ebeln = ls_mseg-ebeln
               ebelp = ls_mseg-ebelp.
    CHECK sy-subrc IS INITIAL.
    CHECK NOT ls_ekpo-matnr IS INITIAL.

* обрабатывать только позиции, у которых роль партнера Z8
    READ TABLE lt_ekpa INTO ls_ekpa
      WITH KEY ebeln = ls_ekpo-ebeln
               parvw = 'Z8'.
    CHECK sy-subrc IS INITIAL.

    ls_mwskz-mwskz = ls_ekpo-mwskz.
    ls_mwskz-ebeln = ls_ekpo-ebeln.
    ls_mwskz-ebelp = ls_ekpo-ebelp.

    ls_mwskz-lifn2 = ls_ekpa-lifn2.
    l_lifn2 = ls_ekpa-lifn2.
    COLLECT l_lifn2 INTO lt_lifn2.

    SELECT SINGLE taklv INTO ls_mwskz-taklv
      FROM mara
      WHERE matnr = ls_ekpo-matnr
        AND taklv IN (c_taklv_0,c_taklv_1,c_taklv_2).

    IF sy-subrc IS INITIAL.
      l_taklv = ls_mwskz-taklv.
      COLLECT l_taklv INTO lt_taklv.
    ELSE.
      CONTINUE.
    ENDIF.

    IF NOT ls_mseg-dmbtr IS INITIAL.
      ls_mwskz-dmbtr = ls_mseg-dmbtr.
    ELSE.
      ls_mwskz-dmbtr = ls_ekpo-netwr.
    ENDIF.
    ls_mwskz-bstmg = ls_mseg-bstmg.
    ls_mwskz-bstme = ls_mseg-bstme.
    ls_mwskz-bprme = ls_ekpo-bprme.
    ls_mwskz-bpmng = ls_mseg-bpmng.

    REFRESH lt_mwdat.
    CALL FUNCTION 'CALCULATE_TAX_FROM_NET_AMOUNT'
      EXPORTING
        i_bukrs           = ps_header-comp_code
        i_mwskz           = ls_ekpo-mwskz
        i_waers           = ps_ekko-waers
        i_wrbtr           = ls_mwskz-dmbtr
      TABLES
        t_mwdat           = lt_mwdat
      EXCEPTIONS
        bukrs_not_found   = 1
        country_not_found = 2
        mwskz_not_defined = 3
        mwskz_not_valid   = 4
        OTHERS            = 5.
    READ TABLE lt_mwdat INTO ls_mwdat WITH KEY kschl = 'MWVS'.
    IF sy-subrc IS INITIAL.
      ls_mwskz-wmwst = ls_mwdat-wmwst.
      ls_mwskz-kbetr = ls_mwdat-kbetr.
      ls_mwskz-hkont = ls_mwdat-hkont.
      ls_mwskz-kawrt = ls_mwdat-kawrt.
      ls_mwskz-ktosl = ls_mwdat-ktosl.
      ls_mwskz-kschl = ls_mwdat-kschl.
      ls_mwskz-msatz = ls_mwdat-msatz.
      APPEND ls_mwskz TO lt_mwskz.
    ENDIF.
  ENDLOOP.

  LOOP AT lt_lifn2 INTO l_lifn2.
    LOOP AT lt_taklv INTO l_taklv.

      ls_header-doc_date = ps_header-doc_date.
      ls_header-pstng_date = ps_header-pstng_date.
      ls_header-trans_date = ps_header-pstng_date.
      ls_header-comp_code = ps_header-comp_code.
      ls_header-ref_doc_no = ps_header-ref_doc_no.
      ls_header-header_txt = ps_header-header_txt.
      ls_header-doc_type = 'KR'.
      ls_header-username = sy-uname.
      ls_header-bus_act = 'RFBU'.

      CLEAR:  ls_glacc,
              l_itemno_tax,
              l_itemno_acc,
              ls_currencyamount,
              ls_accounttax,
              ls_currencyamount.

      REFRESH: lt_glacc,
               lt_extension,
               lt_accounttax,
               lt_accountpayable,
               lt_currencyamount,
               lt_return.

      ADD 1 TO l_itemno_acc.
      ls_accountpayable-itemno_acc = l_itemno_acc.
      ls_accountpayable-vendor_no = l_lifn2.
      ls_accountpayable-tax_code   = ls_mwskz-mwskz.
      ls_accountpayable-comp_code = ps_header-comp_code.
      ls_accountpayable-bline_date = ps_header-pstng_date.
      APPEND ls_accountpayable TO lt_accountpayable.

      CLEAR ls_currencyamount.
      ls_currencyamount-itemno_acc = l_itemno_acc.
      ls_currencyamount-currency = ps_header-currency.
      ls_currencyamount-curr_type = '00'.

      LOOP AT lt_mwskz INTO ls_mwskz WHERE lifn2 = l_lifn2
                                       AND taklv = l_taklv.

        SUBTRACT ls_mwskz-wmwst FROM ls_currencyamount-amt_doccur.
*        SUBTRACT ls_mwskz-kawrt FROM ls_currencyamount-amt_base.
*        SUBTRACT ls_mwskz-wmwst FROM ls_currencyamount-tax_amt.

      ENDLOOP.

      APPEND ls_currencyamount TO lt_currencyamount.

      ls_extension-field1 = l_itemno_acc.
      ls_extension-field2 = 'CALL_FROM_FM_ZXXX_BAPI'.
      ls_extension-field3 = 'X'.
      APPEND ls_extension TO lt_extension.

      LOOP AT lt_mwskz INTO ls_mwskz WHERE lifn2 = l_lifn2
                                       AND taklv = l_taklv.

        ADD 1 TO l_itemno_acc.

        l_itemno_tax = l_itemno_acc.

        ls_glacc-itemno_acc = l_itemno_acc.
        ls_glacc-gl_account = ls_mwskz-hkont.
        ls_glacc-comp_code = ps_header-comp_code.
        ls_glacc-tax_code   = ls_mwskz-mwskz.
        APPEND ls_glacc TO lt_glacc.

        CLEAR ls_currencyamount.
        ls_currencyamount-itemno_acc = l_itemno_acc.
        ls_currencyamount-currency = ps_header-currency.
        ls_currencyamount-amt_doccur = ls_mwskz-wmwst.
        ls_currencyamount-amt_base = ls_mwskz-kawrt.
        ls_currencyamount-tax_amt = ls_mwskz-wmwst.
        ls_currencyamount-curr_type = '00'.
        APPEND ls_currencyamount TO lt_currencyamount.

        ADD 1 TO l_itemno_acc.

        ls_accounttax-itemno_acc = l_itemno_acc.
        ls_accounttax-gl_account = ls_mwskz-hkont.
        ls_accounttax-tax_code   = ls_mwskz-mwskz.
*        ls_accounttax-acct_key   = ls_mwskz-ktosl.
*        ls_accounttax-cond_key   = ls_mwskz-kschl.
*        ls_accounttax-tax_rate   = ls_mwskz-msatz.
        ls_accounttax-itemno_tax  = l_itemno_tax. "Note: 1799957
        APPEND ls_accounttax TO lt_accounttax.

        CLEAR ls_currencyamount.
        ls_currencyamount-itemno_acc = l_itemno_acc.
        ls_currencyamount-currency = ps_header-currency.
        ls_currencyamount-amt_doccur = ls_mwskz-wmwst.
        ls_currencyamount-amt_base = ls_mwskz-kawrt.
*        ls_currencyamount-tax_amt = ls_mwskz-wmwst.
        APPEND ls_currencyamount TO lt_currencyamount.
      ENDLOOP.

      LOOP AT lr_ebeln INTO ls_ebeln.
        PERFORM po_check_lock USING ls_ebeln-low
            CHANGING sy-subrc.
      ENDLOOP.

      CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
        EXPORTING
          documentheader = ls_header
        IMPORTING
          obj_type       = l_obj_type
          obj_key        = l_obj_key
          obj_sys        = l_obj_sys
        TABLES
          accountgl      = lt_glacc
          accounttax     = lt_accounttax
          accountpayable = lt_accountpayable
          currencyamount = lt_currencyamount
          extension1     = lt_extension
          return         = lt_return.

      LOOP AT lt_return INTO ls_return WHERE type CA 'EAX'.
      ENDLOOP.
      IF sy-subrc IS INITIAL.
        CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
      ELSE.
        CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
          EXPORTING
            wait = 'X'.

        ls_obj_key-belnr = l_obj_key(10).
        ls_obj_key-bukrs = l_obj_key+10(4).
        ls_obj_key-gjahr = l_obj_key+14(4).

        CONCATENATE 'Предварительный документ'(300)
                     ls_obj_key-belnr
                     ls_obj_key-gjahr
                     'для кредитора'(201)
                     l_lifn2
                     'создан.'(202) INTO l_message
                     SEPARATED BY space.
        CONDENSE l_message.
        WRITE: / l_message.
      ENDIF.

      PERFORM send_error_message
        TABLES lt_return
        USING ls_mseg.

      LOOP AT lr_ebeln INTO ls_ebeln.
        PERFORM po_check_lock USING ls_ebeln-low
            CHANGING sy-subrc.
      ENDLOOP.

    ENDLOOP.
  ENDLOOP.

ENDFORM.                    "post_addition_acc_document

_________________
Молитва - это запрос разработчику на изменение кода программы.
Back to top
View user's profile Send private message Blog
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Interfaces | Интерфейсы -> BAPI All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.