2016 Jan 29 8:08 AM
Hi experts,
Being a novice in Accounting , I need your help.
I am designing an interface to upload and park journal entries into SAP.
However , there is a constraint here.
If the the number of line items in the journal exceeds 950, we need to create several SAP documents using a clearing account.
The clearing account must contain the total amount of the items (upto 950 again ) with the opposite sign, in-order to balance to zero the SAP document.
Subsequent SAP docs must follow the same procedure until the document in excel has been completely posted. In the end , the balance in the clearing account must be zero.
Can anyone explain what this means and how this works with a simple example?
Any help would be highly appreciated.
2016 Jan 29 4:46 PM
Well, it works exactly as you have explained. If you search the ABAP space in SCN, you will find plenty of threads related to this.
Rob
2016 Jan 29 5:03 PM
Try this code:
w_count = 1.
* Check if the number of line items in the file are less than 950.
DESCRIBE TABLE t_excel_data LINES l_lines.
IF l_lines LT 952.( Including Header ).
l_flag = 'X'.
ELSE.
CLEAR l_flag.
ENDIF.
LOOP AT t_excel_data.
IF sy-tabix EQ 1.
* Fill header structure.
PERFORM fill_header.
* If the record is Line Item record.
ELSEIF sy-tabix GT 1.
IF w_count EQ 951.
PERFORM create_gl_offset.
* Check the data if test run is chose.
IF NOT po_test IS INITIAL.
PERFORM check_data.
ELSE.
* Post the data if its not a test run.
PERFORM post_data.
ENDIF.
w_count = 1.
ENDIF.
* Split the file if the line item number doesnt exceed 950.
PERFORM fill_glaccount_item.
PERFORM fill_currency_item.
w_count = w_count + 1.
ENDIF.
IF w_count LT c_951.
* Create offset record if total number of line items in excel are more than 800.
IF l_flag IS INITIAL.
PERFORM create_gl_offset.
ENDIF.
* Check the data if test run is chose.
IF NOT po_test IS INITIAL.
PERFORM check_data.
ELSE.
* Post the data if its not a test run.
PERFORM post_data.
ENDIF.
ENDIF.
ENDLOOP.
*&---------------------------------------------------------------------*
*& Form FILL_HEADER
*&---------------------------------------------------------------------*
* Writes the Header Line
*----------------------------------------------------------------------*
FORM fill_header .
DATA: l_date(8) TYPE c.
* If the data is a header record.
SPLIT t_excel_data AT ',' INTO
l_date
wa_header-doc_type
wa_header-comp_code
wa_header-pstng_date
wa_header-fis_period
w_currency
wa_header-header_txt.
IF wa_header-header_txt CA c_tab.
REPLACE ALL OCCURENCES OF c_tab IN wa_header-header_txt WITH space.
ENDIF.
* Get logical system details.
CALL FUNCTION 'OWN_LOGICAL_SYSTEM_GET'
IMPORTING
own_logical_system = wa_header-obj_sys.
wa_header-obj_type = 'FOTP'.
wa_header-bus_act = c_rfbu.
wa_header-username = sy-uname.
wa_header-doc_date = l_date.
CLEAR l_date.
IF wa_header-pstng_date IS INITIAL.
wa_header-pstng_date = sy-datum.
ELSE.
w_date = wa_header-pstng_date.
ENDIF.
IF wa_header-fis_period EQ space. " Fiscal Period
wa_header-fis_period = w_date+4(2).
ENDIF
IF wa_header-doc_type EQ space. " Document Type
wa_header-doc_type = 'SA'.
ENDIF.
ENDFORM. " FILL_HEADER
*&---------------------------------------------------------------------*
*& Form CREATE_GL_OFFSET
*&---------------------------------------------------------------------*
* Creating GL Account Offset Item
*----------------------------------------------------------------------*
FORM create_gl_offset .
PERFORM fill_gloffset_item.
PERFORM fill_currency_offset.
ENDFORM. " CREATE_GL_OFFSET
*&---------------------------------------------------------------------*
*& Form FILL_GLOFFSET_ITEM
*&---------------------------------------------------------------------*
* Filling the Offset GL Account Details into t_gl_acc_item table
*----------------------------------------------------------------------*
FORM fill_gloffset_item .
CLEAR t_gl_acc_item.
t_gl_acc_item-gl_account = " Offsetting GL account
t_gl_acc_item-profit_ctr = " Offsetting profit center.
* t_gl_acc_item-costcenter = "Offsetting cost center.
CLEAR t_gl_acc_item-costcenter.
t_gl_acc_item-item_text = 'Offsetting record'. " Item text
t_gl_acc_item-itemno_acc = w_count.
IF w_amount1 GT 0. " Posting key
t_gl_acc_item-de_cre_ind = c_c.
ELSE.
t_gl_acc_item-de_cre_ind = c_d.
ENDIF.
t_gl_acc_item-comp_code = wa_header-comp_code. " Company Code
t_gl_acc_item-fis_period = wa_header-fis_period. " fiscal Period
t_gl_acc_item-pstng_date = wa_header-pstng_date. " Posting date
t_gl_acc_item-doc_type = wa_header-doc_type. " Document Type
APPEND t_gl_acc_item.
CLEAR t_gl_acc_item.
ENDFORM. " FILL_GLOFFSET_ITEM
*&---------------------------------------------------------------------*
*& Form FILL_CURRENCY_OFFSET
*&---------------------------------------------------------------------*
* Filling the offset currency details into t_curr_item table
*----------------------------------------------------------------------*
FORM fill_currency_offset .
* Populate currency structure.
SHIFT w_amount LEFT DELETING LEADING space.
t_curr_item-itemno_acc = w_count.
t_curr_item-currency = w_currency.
IF NOT w_amount1 IS INITIAL.
t_curr_item-amt_doccur = w_amount1.
ENDIF.
t_curr_item-amt_doccur = t_curr_item-amt_doccur * ( -1 ).
CLEAR: w_amount1,
w_amount.
APPEND t_curr_item.
CLEAR t_curr_item.
ENDFORM. " FILL_CURRENCY_OFFSET
*&---------------------------------------------------------------------*
*& Form CHECK_DATA
*&---------------------------------------------------------------------*
* Checking the data using BAPI and display error messages
*----------------------------------------------------------------------*
FORM check_data .
CLEAR t_return.
REFRESH t_return.
* Obtain the Document Number
PERFORM get_doc_number USING w_date.
CALL FUNCTION 'BAPI_ACC_DOCUMENT_CHECK'
EXPORTING
documentheader = wa_header
TABLES
accountgl = t_gl_acc_item
currencyamount = t_curr_item
return = t_return.
* Clearing and refreshing the internal tables.
CLEAR : t_gl_acc_item,
t_curr_item,
w_obj_key.
REFRESH:t_gl_acc_item,
t_curr_item.
* Displays error messages as output to the program
WRITE: / 'Result of post:'.
PERFORM show_messages.
ENDFORM. " CHECK_DATA
*&---------------------------------------------------------------------*
*& Form POST_DATA
*&---------------------------------------------------------------------*
* Posting the data into SAP tables using BAPI.
*----------------------------------------------------------------------*
FORM post_data .
AUTHORITY-CHECK OBJECT 'F_BKPF_BUK'
ID 'BUKRS' FIELD wa_header-comp_code
ID 'ACTVT' FIELD '01'.
IF sy-subrc = 4.
MESSAGE e999(zfi_ap_gl) WITH text-t99 wa_header-comp_code.
ELSEIF sy-subrc <> 0.
MESSAGE e999(zfi_ap_gl) WITH text-t98 'F_BKPF_BUK; return code=' sy-subrc.
ENDIF.
CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
EXPORTING
documentheader = wa_header
IMPORTING
obj_key = w_obj_key
TABLES
accountgl = t_gl_acc_item
currencyamount = t_curr_item
return = t_return.
CLEAR : t_gl_acc_item,
t_curr_item,
w_obj_key.
REFRESH:t_gl_acc_item,
t_curr_item.
LOOP AT t_return.
IF t_return-type EQ c_s AND
t_return-number EQ c_605.
* If not test run commit data.
IF po_test IS INITIAL.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
ENDIF.
ENDIF.
ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FILL_GLACCOUNT_ITEM
*&---------------------------------------------------------------------*
* Filling the t_gl_acc_item internal table with GL Account Details
*----------------------------------------------------------------------*
FORM fill_glaccount_item .
CLEAR: w_posting_key,
w_amount.
DATA: l_orderid(10) TYPE c.
* Split the data in the file and populate into GL account.
SPLIT t_excel_data AT c_tab INTO
w_posting_key
t_gl_acc_item-gl_account
w_amount
t_gl_acc_item-costcenter
t_gl_acc_item-profit_ctr
t_gl_acc_item-orderid
t_gl_acc_item-func_area
t_gl_acc_item-trade_id
t_gl_acc_item-item_text.
IF t_gl_acc_item-item_text CA c_tab.
REPLACE ALL OCCURENCES OF c_tab IN t_gl_acc_item-item_text WITH space.
ENDIF.
IF t_gl_acc_item-profit_ctr CA c_tab.
REPLACE ALL OCCURENCES OF c_tab IN t_gl_acc_item-profit_ctr WITH space.
ENDIF.
IF t_gl_acc_item-costcenter CA c_tab.
REPLACE ALL OCCURENCES OF c_tab IN t_gl_acc_item-costcenter WITH space.
ENDIF.
IF t_gl_acc_item-gl_account CA c_tab.
REPLACE ALL OCCURENCES OF c_tab IN t_gl_acc_item-gl_account WITH space.
ENDIF.
IF w_amount CA c_tab.
REPLACE ALL OCCURENCES OF c_tab IN w_amount WITH space.
ENDIF.
IF w_posting_key CA c_tab.
REPLACE ALL OCCURENCES OF c_tab IN w_posting_key WITH space.
ENDIF.
* item no of the gl account.
t_gl_acc_item-itemno_acc = w_count.
* Posting Key
IF w_posting_key EQ c_01 OR
w_posting_key EQ c_21 OR
w_posting_key EQ c_40 OR
w_posting_key EQ c_25 OR
w_posting_key EQ c_70.
t_gl_acc_item-de_cre_ind = c_d.
w_amount1 = w_amount1 + w_amount.
CLEAR w_flag.
ELSEIF w_posting_key EQ c_50 OR
w_posting_key EQ c_31 OR
w_posting_key EQ c_11 OR
w_posting_key EQ c_75.
t_gl_acc_item-de_cre_ind = c_c.
w_flag = 'X'.
w_amount1 = w_amount1 - w_amount.
ENDIF.
t_gl_acc_item-comp_code = wa_header-comp_code. " Company Code
t_gl_acc_item-fis_period = wa_header-fis_period. " fiscal Period
t_gl_acc_item-pstng_date = wa_header-pstng_date. " Posting date
t_gl_acc_item-doc_type = wa_header-doc_type. " Document Type
APPEND t_gl_acc_item.
CLEAR t_gl_acc_item.
ENDFORM. " FILL_GLACCOUNT_ITEM
*&---------------------------------------------------------------------*
*& Form FILL_CURRENCY_ITEM
*&---------------------------------------------------------------------*
* Filling the t_curr_item internal table with Currency details.
*----------------------------------------------------------------------*
FORM fill_currency_item .
* Populate currency structure.
SHIFT w_amount LEFT DELETING LEADING space.
t_curr_item-itemno_acc = w_count.
t_curr_item-currency = w_currency.
* Add negtive sign to the credit amount.
IF NOT w_amount IS INITIAL.
IF w_flag EQ 'X'.
IF NOT w_amount CS '-'.
SHIFT w_amount LEFT DELETING LEADING space.
CONCATENATE '-' w_amount INTO w_amount.
ENDIF.
ENDIF.
t_curr_item-amt_doccur = w_amount.
ENDIF.
CLEAR w_amount.
* w_amount1 = w_amount1 + t_curr_item-amt_doccur.
APPEND t_curr_item.
CLEAR t_curr_item.
ENDFORM. " FILL_CURRENCY_ITEM