Penalty Post Method – Functional & Technical Explanation

Purpose

The penalty_post method is used to post a penalty document in SAP FI-CA for an existing open item using BAPI_CTRACDOCUMENT_CREATE.


High-Level Process Flow

  • Read the open FI-CA document using FBNUM
  • Determine Business Partner, Contract Account, and Contract
  • Calculate or accept penalty amount
  • Create a penalty document using BAPI
  • Commit the transaction if successful

1. Constant and Variable Initialization

The method initializes constants such as:

  • Currency: BHD
  • Company Code: BAH
  • Application Area: P (FI-CA)
  • Posting keys, document source, and BAPI extension structure

2. Input Parameter Handling

If provided, the following values are taken from input parameters:

  • Business Partner (GPART)
  • Contract Account (VKONT)
  • Contract (VTREF)

If not provided, these values are derived from the open document.


3. Fetch Open Item

The method reads DFKKOP and DFKKKO tables to fetch an open item using:

  • FBNUM
  • AUGST = space (open item)

4. Document Header Preparation

The FI-CA document header is populated with:

  • Document type and application area
  • Posting, entry, and document dates
  • Currency and reference document number
  • FIKEY generated using a utility method

5. Penalty Amount Calculation

  • If penalty amount is not passed, 10% of the open amount is calculated
  • The calculated amount is posted as a negative value
  • If penalty amount is passed, it is used directly

6. Line Item Preparation

The line item contains:

  • Main and Sub transaction
  • Penalty amount
  • Due date
  • Business Partner, Contract, and Contract Account
  • Reference text using original FBNUM

7. BAPI Extension Handling

The structure BAPI_TE_DFKKOP is filled to store:

  • Original FBNUM
  • Manual posting reference

8. Document Creation

The method calls BAPI_CTRACDOCUMENT_CREATE with:

  • Document header
  • Partner positions
  • BAPI extension data

9. Commit & Output

  • If successful, transaction is committed
  • Posted document number is returned
  • Business Partner, Contract Account, and Contract are exported
  • In case of error, an error flag is set

Key Highlights

  • FI-CA compliant penalty posting
  • Supports automatic and manual penalty calculation
  • Uses BAPI extension correctly
  • Clean commit and error handling

ABAP Method: penalty_post


METHOD penalty_post.
  " Penalty Post

Importing Parameters

The following image shows the importing parameters for the method:

Importing Parameters for penalty_post

Figure: Importing Parameters for penalty_post

CONSTANTS: lc_waers TYPE waers VALUE 'BHD', lc_testrun TYPE flag VALUE '', lc_applk_p TYPE applk_kk VALUE 'P'. DATA: lv_fikey TYPE fkkko-fikey, lv_fbnum TYPE fbnum_ps, lv_gpart TYPE gpart_kk, lv_vkont TYPE vkont_kk, lv_vtref TYPE vtref_kk. " Check input parameters IF iv_gpart IS SUPPLIED AND iv_gpart IS NOT INITIAL. lv_gpart = iv_gpart. ENDIF. IF iv_vkont IS SUPPLIED AND iv_vkont IS NOT INITIAL. lv_vkont = iv_vkont. ENDIF. " Fetch open item SELECT SINGLE op~*, ko~* FROM dfkkop AS op INNER JOIN dfkkko AS ko ON op~opbel = ko~opbel INTO @DATA(ls_dfkkop_open) WHERE op~fbnum = @iv_fbnum AND augst = @space. IF sy-subrc NE 0. CLEAR ls_dfkkop_open. ENDIF. " Prepare header and line item ls_fkkko-appl_area = lc_applk_p. ls_fkkko-doc_type = iv_doc_type. ls_fkkko-currency = lc_waers. CALL METHOD zdcl_utility=>get_fikey IMPORTING ev_fikey = ls_fkkko-fikey. " Calculate penalty amount IF iv_penalty_amount IS INITIAL. lv_penalty_amt = (ls_dfkkop_open-op-betrw) / 10. lv_penalty_amt = -1 * lv_penalty_amt. ELSE. lv_penalty_amt = iv_penalty_amount. ENDIF. " Append line item ls_fkkop-item = '000001'. ls_fkkop-amount = lv_penalty_amt. APPEND ls_fkkop TO lt_fkkop. " Call BAPI to create document CALL FUNCTION 'BAPI_CTRACDOCUMENT_CREATE' EXPORTING testrun = lc_testrun documentheader = ls_fkkko completedocument = abap_true IMPORTING documentnumber = lv_doc_posted return = ls_return TABLES partnerpositions = lt_fkkop extensionin = lt_ext. " Commit if posted IF lv_doc_posted IS NOT INITIAL. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'. ENDIF. ENDMETHOD.