GL A/C posting using BAPI_ACC_GL_POSTING_POST.

本文介绍了一个用于批量上传日记账的接口开发方案,包括文件格式确定、路径配置、程序开发等步骤,并提供了ABAP代码示例。

Parameters Descrption
ACCOUNTGL : mention only G/L line items here
ACCOUNTTAX : mention the VAT items here only but with the same item number like in currencyamount, the amounts are not important here, simply zero...
CURRENCYAMOUNT : mention all items here, in case of normal posting the amount comes to field AMT_DOCCUR, in case of VAT posting the amount of VAT comes to AMT_DOCCUR, the base amount comes to AMT_BASE

Requirement:

An interface needs to be developed to upload large journals either from a tab delimited file. Currently it's being done manually using FB50 transaction. Various Cost of Capital & Operational Property journals have to be posted at month end. A file interface needs to be developed.

  Processing:

It involves following development/configurations:

  • File format determination (Required / optional fields and field checks).
  • Logical File Path configuration through transaction 'FILE'. A new physical file path should be created on operating system level or an existing one can be used if agreed. The Basis team member should create a new file path at operating system level, if required. The file path will have three directories: /GL_FILE /GL_Processed /GL_Error
  • Program Z_BAPI_GL_AC_DOC_POST needs to be developed to do the processing as described below:
    • The processing can be done in foreground as well as in background mode.
    • In case of background: File can only be read from Application Server.
    • In case of foreground: User will have an option to choose from Presentation or Application Server File.
    • Logical File Path / Name needs to be configured using FILE transaction for application server file processing. It is required to identify the Application server directory and file. Further it gives the flexibility to change the path and file name by using the transaction FILE, without making any changes to the program. It should not be hard-coded as directory structure might be different for Testing and production development servers.
    • Read the input file from presentation or application server as chosen.
    • Prepare Account doc header and detail internal tables.
    • Call 'BAPI_ACC_GL_POSTING_POST' to post the GL accounting document.
    • For application server case, Processed file can be flagged archived by using Function module DX_FILE_COPY and then it can be deleted using EPS_DELETE_FILE .
    • Error file can be created ( in /GL_Error directory for application server and with .err extension in case of PC processing ) for error records and can be re-processed after correction.
    • The list of successful and error transaction will be displayed after processing.

代码:
report z_test_bapi_gl_ac_doc LINE-SIZE 200.
*----------------------------------------------------------------------*
*       Written By: Ram Manohar Tiwari    
*----------------------------------------------------------------------*
*       Presented By: http://www.rmtiwari.com
*----------------------------------------------------------------------*

data:
      obj_type like bapiache02-obj_type,
      obj_key like bapiache02-obj_key,
      obj_sys like bapiache02-obj_sys,
      documentheader like bapiache08,

      accountgl like bapiacgl08
                  occurs 0 with header line,
      currencyamount like bapiaccr08
                  occurs 0 with header line,
      return like bapiret2
                  occurs 0 with header line,
      extension1 like bapiextc
                  occurs 0 with header line,

      t_edidd  like edidd occurs 0 with header line,
      bapi_retn_info  like bapiret2 occurs 0 with header line.
data: error_flag.


*documentheader-obj_type     = 'BKPFF'.
*documentheader-obj_key      = '18000000002002004'.
*documentheader-obj_type     = 'BKPFF'.
*documentheader-obj_key      = '180000000010002004'.

*documentheader-obj_sys      = 'RD1CLNT200'.


documentheader-username     = sy-uname.
documentheader-header_txt   = 'Test using BAPI'.
documentheader-comp_code    = '1000'.

*documentheader-ac_doc_no
*documentheader-fisc_year    = '2005'.

documentheader-doc_date     = sy-datum.
documentheader-pstng_date   = sy-datum.

*documentheader-trans_date
*documentheader-fis_period

documentheader-doc_type    = 'SA'.


*documentheader-ref_doc_no
*documentheader-compo_acc
*documentheader-reason_rev



accountgl-itemno_acc = '1'.
accountgl-gl_account = '0000160100'.
accountgl-comp_code = '1000'.
accountgl-pstng_date = sy-datum.
accountgl-doc_type   = 'SA'.
accountgl-profit_ctr = '0000010000'.
append accountgl.

accountgl-itemno_acc = '2'.
accountgl-gl_account = '0000160100'.
accountgl-comp_code = '1000'.
accountgl-pstng_date = sy-datum.
accountgl-doc_type   = 'SA'.
accountgl-profit_ctr = '0000010000'.
append accountgl.


*AC_DOC_NO
*FISC_YEAR
*FIS_PERIOD
*accountgl-STAT_CON = 'X'.
*REF_KEY_1
*REF_KEY_2
*REF_KEY_3
*CUSTOMER
*VENDOR_NO
*ALLOC_NMBR
*ITEM_TEXT
*BUS_AREA
*COSTCENTER
*ACTTYPE
*ORDERID
*ORIG_GROUP
*COST_OBJ
*PROFIT_CTR
*PART_PRCTR
*WBS_ELEMENT
*NETWORK
*ROUTING_NO
*ORDER_ITNO


currencyamount-itemno_acc = '1'.
currencyamount-currency = 'GBP'.
currencyamount-amt_doccur = '100.00'.
append currencyamount.

currencyamount-itemno_acc = '2'.
currencyamount-currency = 'GBP'.
currencyamount-amt_doccur = '-100.00'.
append currencyamount.


*   call BAPI-function in this system   
call function 'BAPI_ACC_GL_POSTING_POST'
     exporting
          documentheader = documentheader
*     importing
*          obj_type       = obj_type
*          obj_key        = obj_key
*          obj_sys        = obj_sys

     tables
          accountgl      = accountgl
          currencyamount = currencyamount
          return         = return
          extension1     = extension1
     exceptions
          others         = 1.
if sy-subrc <> 0.
  message e999(re) with  'Problem occured'.
else.
      loop at return.
          if not return is initial.
          clear bapi_retn_info.
          move-corresponding return to bapi_retn_info.
          if return-type = 'A' or return-type = 'E'.
            error_flag = 'X'.
          endif.
          append bapi_retn_info.
        endif.
      endloop.
  if error_flag = 'X'.
     message e999(re) with  'Problem occured'.
     rollback work.
  else.
  commit work.
  endif.
endif.
来源:http://www.geocities.com/rmtiwari/main.html?http://www.geocities.com/rmtiwari/Resources/Management/SAPCaseStudies.html

### 示例程序结构 在 SE38 中创建使用 `BAPI_ACC_GL_POSTING_POST` 的示例程序时,需要定义凭证头信息、总账科目行项目、货币金额以及返回值等数据结构。以下是一个完整的示例程序框架,适用于 SAP ABAP 环境。 ```abap REPORT zgl_posting_example. DATA: wa_header TYPE bapiache09, it_accountgl TYPE STANDARD TABLE OF bapiacgl09, wa_accountgl TYPE bapiacgl09, it_currencyamount TYPE STANDARD TABLE OF bapiaccurr, wa_currencyamount TYPE bapiaccurr, it_return TYPE STANDARD TABLE OF bapiret2, wa_return TYPE bapiret2. " 凭证头信息 wa_header-doc_date = '20231001'. wa_header-pstng_date = '20231001'. wa_header-doc_type = 'SA'. wa_header-comp_code = '1000'. wa_header-fisc_year = '2023'. " 总账科目行项目 1 wa_accountgl-itemno_acc = '10'. wa_accountgl-gl_account = '110000'. wa_accountgl-item_text = 'Debit Entry'. APPEND wa_accountgl TO it_accountgl. " 总账科目行项目 2 wa_accountgl-itemno_acc = '20'. wa_accountgl-gl_account = '120000'. wa_accountgl-item_text = 'Credit Entry'. APPEND wa_accountgl TO it_accountgl. " 货币金额 wa_currencyamount-itemno_acc = '10'. wa_currencyamount-amt_doccur = '1000.00'. wa_currencyamount-currency = 'USD'. APPEND wa_currencyamount TO it_currencyamount. wa_currencyamount-itemno_acc = '20'. wa_currencyamount-amt_doccur = '-1000.00'. wa_currencyamount-currency = 'USD'. APPEND wa_currencyamount TO it_currencyamount. " 调用 BAPI CALL FUNCTION 'BAPI_ACC_GL_POSTING_POST' EXPORTING documentheader = wa_header TABLES accountgl = it_accountgl currencyamount = it_currencyamount return = it_return. " 处理返回信息 LOOP AT it_return INTO wa_return WHERE type = 'E' OR type = 'A'. WRITE: / 'Error:', wa_return-message. ENDLOOP. READ TABLE it_return INTO wa_return WITH KEY type = 'S'. IF sy-subrc = 0. WRITE: / 'GL Posting successful.'. ENDIF. ``` ### 数据结构说明 - **凭证头(`documentheader`)**:用于定义会计凭证的基本信息,如凭证日期、过账日期、公司代码、凭证类型和会计年度等。这些字段决定了凭证的全局属性,例如会计期间和公司范围[^2]。 - **总账科目行项目(`accountgl`)**:每个条目对应一个总账科目,并包含行项目编号、科目编号和行项目描述。该结构允许用户定义多个借方和贷方的 G/L 科目行项目,通过 `itemno_acc` 字段区分不同的行项目。 - **货币金额(`currencyamount`)**:用于定义每条 G/L 科目行项目的金额和货币类型。金额可以为正(借方)或负(贷方),并需与 `accountgl` 中的 `itemno_acc` 字段匹配,以确保金额正确分配到对应的科目行项目[^2]。 - **返回值(`return`)**:记录 BAPI 执行后的返回信息,包括成功、警告或错误消息。通过检查 `return` 表可以确认凭证是否成功过账,并获取错误信息以便调试。 ### 使用注意事项 - 在调用 `BAPI_ACC_GL_POSTING_POST` 之前,必须确保所有输入数据的完整性,例如凭证头信息、G/L 科目和金额是否正确。 - 程序中应包含适当的错误处理逻辑,例如检查返回表中的错误信息,并在出现错误时输出提示。 - 若需扩展字段,由于 `BAPI_ACC_GL_POSTING_POST` 不支持 `EXTENSION2` 参数,因此需通过其他方式实现字段扩展,例如自定义表或附加字段。 ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值