Создание и проводка документа FI (ABAP)

BAPI_ACC_DOCUMENT_POST - пример использования.

  1. **********************************************************************
  2. DATA ls_hdr TYPE bapiache09.
  3. DATA lt_acc TYPE TABLE OF bapiacgl09.
  4. DATA ls_acc TYPE bapiacgl09.
  5. DATA lt_amt TYPE TABLE OF bapiaccr09.
  6. DATA ls_amt TYPE bapiaccr09.
  7. DATA lt_ext TYPE TABLE OF bapiparex.
  8. DATA ls_ext TYPE bapiparex.
  9. DATA lt_ret TYPE TABLE OF bapiret2.
  10. DATA lt_ret_all TYPE TABLE OF bapiret2.
  11. DATA lv_obj_type TYPE bapiache09-obj_type.
  12. DATA lv_obj_key TYPE bapiache09-obj_key.
  13. DATA lv_test TYPE xfeld.
  14. DATA lv_error TYPE xfeld.
  15.  
  16. DO 2 TIMES. " Проверим создание кредиторского и дебиторского документа
  17. IF sy-index EQ 1.
  18. lv_test = 'X'.
  19. CHECK lv_error IS INITIAL AND i_test IS INITIAL.
  20. CLEAR lt_ret_all[].
  21. lv_test = ''.
  22.  
  23. LOOP AT g_tab ASSIGNING .
  24. * Создание корректирующей проводки – Проводка кредиторской задолженности
  25. CLEAR ls_hdr.
  26. CLEAR lt_acc[].
  27. CLEAR lt_amt[].
  28. CLEAR lt_ret[].
  29. CLEAR lt_ext[].
  30.  
  31. ls_hdr-username = sy-uname.
  32. ls_hdr-comp_code = -bukrs.
  33. ls_hdr-doc_date = date_doc.
  34. ls_hdr-pstng_date = date_post.
  35. ls_hdr-doc_type = blart.
  36.  
  37. CLEAR ls_acc.
  38. ls_acc-itemno_acc = 1.
  39. ls_acc-acct_type = 'S'.
  40. ls_acc-gl_account = -saknr1.
  41. INSERT ls_acc INTO TABLE lt_acc.
  42.  
  43. CLEAR ls_amt.
  44. ls_amt-itemno_acc = ls_acc-itemno_acc.
  45. ls_amt-currency = 'RUB'.
  46. ls_amt-amt_doccur = - -saldo.
  47. INSERT ls_amt INTO TABLE lt_amt.
  48.  
  49. ADD 1 TO ls_acc-itemno_acc.
  50. ls_acc-gl_account = -saknr2.
  51. INSERT ls_acc INTO TABLE lt_acc.
  52.  
  53. ls_amt-itemno_acc = ls_acc-itemno_acc.
  54. ls_amt-amt_doccur = - ls_amt-amt_doccur.
  55. INSERT ls_amt INTO TABLE lt_amt.
  56. *
  57. IF lv_test IS NOT INITIAL.
  58. CALL FUNCTION 'BAPI_ACC_DOCUMENT_CHECK'
  59. EXPORTING
  60. documentheader = ls_hdr
  61. accountgl = lt_acc
  62. currencyamount = lt_amt
  63. extension2 = lt_ext
  64. return = lt_ret.
  65. CLEAR lv_obj_key.
  66. CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
  67. EXPORTING
  68. documentheader = ls_hdr
  69. IMPORTING
  70. obj_type = lv_obj_type
  71. obj_key = lv_obj_key
  72. accountgl = lt_acc
  73. currencyamount = lt_amt
  74. extension2 = lt_ext
  75. return = lt_ret.
  76.  
  77. INSERT LINES OF lt_ret INTO TABLE lt_ret_all.
  78. LOOP AT lt_ret TRANSPORTING NO FIELDS WHERE type EQ 'E' OR type EQ 'A'.
  79. lv_error = 'X'.
  80. IF lv_error IS INITIAL AND lv_test IS INITIAL.
  81. ls_alv = .
  82. ls_alv-belnr = lv_obj_key+0(10).
  83. ls_alv-gjahr = lv_obj_key+14(4).
  84. INSERT ls_alv INTO TABLE lt_alv.
  85. *
  86. IF i_test IS INITIAL.
  87. IF lv_error IS NOT INITIAL.
  88. CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
  89. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
  90. EXPORTING
  91. wait = 'X'.
  92.  
  93. * Покажем лог, если были ошибки
  94. IF lv_error IS NOT INITIAL.
  95. CALL FUNCTION 'FINB_BAPIRET2_DISPLAY'
  96. EXPORTING
  97. it_message = lt_ret_all.
  98. ELSEIF i_test IS NOT INITIAL.
  99. MESSAGE 'Моделирование прошло без ошибок' TYPE 'I'.
  100. **********************************************************************

Комментарии