ISU – 6 – Bankruptcy Overview and Write-Off Process using BAPI_CTRACDOCUMENT_WRITEOFF

ISU – 6 – Bankruptcy Overview and Write-Off Process using BAPI_CTRACDOCUMENT_WRITEOFF

Bankruptcy is another opportunity given by the government court to the shopper to get a “new beginning”. Liquidation additionally treats all lenders reasonably and all obligations should be incorporated and the purchaser doesn’t have the privilege to single out the obligations. ISU – 6 – Bankruptcy Overview and Write-Off Process using BAPI_CTRACDOCUMENT_WRITEOFF.

Insolvency are isolated by sections viz Part 7 (Liquidation), Part 11 (Revamping), Section 13 (For individual indebted person; Change of Obligations of a Person with Customary Pay). Section 13 is for the most part for individual borrower. Let’s get into ISU – 6 – Bankruptcy Overview and Write-Off Process using BAPI_CTRACDOCUMENT_WRITEOFF.

What happens when the customer files for bankruptcy?

It delivers the client/debt holder from individual risk for specific determined sorts of obligations. The client is not generally lawfully expected to pay the obligations and it likewise keeps the lenders from making any type of assortment move including legitimate activity and interchanges, for example, calls, letters or contacts of any sort.

What happens to ISU customer’s service when bankruptcy petition is field?

ISU (Administration viz power, water and so on) supplier can’t make any move to gather on obligations caused up to and including the day preceding the liquidation documenting date. For instance, the client has funds to be paid of $100.00 for Walk 1 to Walk 31 2019. He recorded the insolvency on twentieth Walk. Then, at that point, the client doesn’t have to pay for Walk 1 to Spring nineteenth help. It ought to get discounted. In any case, the client is as yet at risk to pay the levy from Walk 20 to Spring 31st. And every single future help.

The $100.00 surplus is similarly separated into 31 days and the client gets Discount for first to nineteenth schedule days.

For our model:

1-31 March = >31 days = $100
For 1 day = $100/31
1-19 March => 20 days = ($100/31)*20 = $64.52

So the client doesn’t have to pay $64.52. Yet, he is as yet responsible for any assistance after liquidation day. So he is obligated for (100 – 64.52) = $35.48.

Note: Assuming the client has another $175 due from earlier months (say Jan and Feb 2019), then, at that point, the clients get full discount of $175 on the grounds that, those obligations were caused before the liquidation document date.

Additionally Note: Chapter 11 is documented at Colleague (BP) level. Thus, all the relating Agreement Record (CA) numbers and Agreements (CO) attached to the BP would be qualified for chapter 11 discount.

Enough of basics. Allow us to investigate SAP and check how things are finished.

In SAP, Discount Reason can be Full or it very well may be Fractional as well. As the name proposes, in the event that the Discount Reason is set apart as Full, we can’t discount just $64.52 from the open due of $100 for the above model.

We have 2 options to Write-Off:

  1. Assuming the Chapter 11 Discount reason is Full. To compose of $64.52. Then, at that point, give a spurious credit of $35.48 to the client. This carries his due to $64.52. Presently, we can discount the full $64.52. Once the discount is given, the client has 0 due. However, we actually need to gather $35.48 from him. In this way, we really want to turn around the $35.48 credit we gave at first. Along these lines, $35.48 would be open surplus for the client and they need to pay the specialist organization.
  2. Arrange the Chapter 11 Discount reason as Halfway. All things considered, don’t bother giving a misleading credit to the client and opposite it eventually. You can straightforwardly discount $64.52 from the client’s obligation and $35.48 would stay open and client is at risk.

To control the Discount motivation to be Fractional or not, we really want keep up with the banner in the SPRO arrangement.

Write-Off Configuration Path:

Financial Accounting ->Contract Accounts Receivable and Payable -> Business Transactions -> Write-Offs

Check for Discount Reason, Liquidation, the PWO (Incomplete Discount) is Dynamic. This implies just for Chapter 11 explanation, we can do a halfway discount. Rest all reasons viz Collectable, Underpayment are not Fractional.

The exchange code for Discount is FP04.

Allow me to show you how the Incomplete Discount and Full Discount work.

For our Discount Liquidation Reason ‘Non Collectable’, Halfway Discount isn’t dynamic in the Setup.

Along these lines, let us attempt to discount utilizing this explanation.

The screen shows the open sum 80.59. Double tap on the Gross Sum.

The Gross Clearing is duplicated from Gross sum and the Gross Clearing isn’t EDITABLE. This implies, we can’t do fractional discount.

Presently, let us check, how it searches for Halfway Discount Liquidation Reason Code. We will take a similar client yet attempt to apply an alternate Discount reason.

Check, when I double tap on Gross sum, the Gross Clearing field becomes EDITABLE and we can Discount full or halfway sum. For our model, we need to discount just 10.59.

 

How to do Write-Off in SAP ABAP Program?

The least complex way is to do a BDC recording. In any case, the least complex way may not generally be the main way or the correct way. We can Discount utilizing BAPI ‘BAPI_CTRACDOCUMENT_WRITEOFF’.

I’m taking a gander at a SAP ISU framework which is over 10 years old on the off chance that not twenty years and shockingly; this BAPI has never been utilized.

The reason might be:

  1. BAPI is excessively intricate to be consumed
  2. Designers straightforwardly utilized the FM which may be called from inside the BAPI
  3. Designers favored the BDC way

In any case, when we attempted to utilize the BAPI, we had starting hiccups to pass the information and do an effectively discount. To take care of our concern, we wanted to investigate the standard FP04 t-code and checked how SAP is doing itself.

Toward the finish of the examination, we found, SAP searches for Open Things and afterward Post the Discount. FM ‘FKK_OPEN_ITEM_SELECT’ is utilized for recovering the Open Things and BAPI ‘BAPI_CTRACDOCUMENT_WRITEOFF’ to make the Discount record.

Kindly check the underneath test program to get open things and post the discount utilizing the BAPI. You want to deal with the open sum and the clearing sum. What’s more, you likewise need to enact the open thing you need to discount. Detail is given in the code bit beneath.

Selection Screen

Output

Validation at t-code FPL9.

 

Sample Code Snippet to Write-Off

*&---------------------------------------------------------------------
*& Object :  zbankruptcy_writeoff
*&---------------------------------------------------------------------
*& Function: Write-Off Bankruptcy Debt
*&---------------------------------------------------------------------
REPORT  zbankruptcy_writeoff.
*---------------------------------------------------------------------*
* TABLES                                                              *
*---------------------------------------------------------------------*
TABLES: erdk.
*---------------------------------------------------------------------*
* TABLES                                                              *
*---------------------------------------------------------------------*
DATA:
     it_open_item        TYPE STANDARD TABLE OF fkkcl,
     gv_woff_amt         TYPE betrh_kk.
*---------------------------------------------------------------------*
* SELECTION SCREEN                                                    *
*---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS:
     p_ca    TYPE vkont_kk,    " CA
     p_bdate TYPE sy-datum OBLIGATORY DEFAULT sy-datum.  " Bankruptcy Date
SELECTION-SCREEN END OF BLOCK b1.
*---------------------------------------------------------------------*
* END-OF-SELECTION.                                                 *
*---------------------------------------------------------------------*
END-OF-SELECTION.

* Get Open Items
   PERFORM sub_get_open_item
                    TABLES   it_open_item
                    USING  p_ca.

* Calculate Write-Off
   PERFORM sub_cal_woff TABLES it_open_item
                        CHANGING gv_woff_amt.

* Create Write Off documents
   PERFORM sub_post_write_off TABLES   it_open_item
                              CHANGING gv_woff_amt.
*&---------------------------------------------------------------------*
*&      Form  SUB_GET_OPEN_ITEM
*&---------------------------------------------------------------------*
*       Get Open Items for the CA
*       Logic leveraged from standard program LFKA1F01
*       FORM openitem_read & stat_openitem_delete
*----------------------------------------------------------------------
FORM sub_get_open_item
     TABLES    lit_open_item STRUCTURE fkkcl
     USING     p_ca.

   DATA:
           lv_app_area          TYPE applk_kk VALUE 'R',   " Utility
           lwa_seltab           TYPE iseltab,
           lit_seltab           TYPE STANDARD TABLE OF iseltab.

   FIELD-SYMBOLS:
             <lfs_open_item>      TYPE fkkcl.
*---------------only write off items for given CA---------------*
   lwa_seltab-selcu = p_ca.
   lwa_seltab-selfn = 'VKONT'.
   lwa_seltab-selnr = '0001'.
   APPEND lwa_seltab TO lit_seltab.
*---------------only write off items with given currency--------------
   lwa_seltab-selcu = 'USD'.
   lwa_seltab-selfn = 'WAERS'.
   lwa_seltab-selnr = '0001'.
   APPEND lwa_seltab TO lit_seltab.

* Get Open Item
   CALL FUNCTION 'FKK_OPEN_ITEM_SELECT'
     EXPORTING
       i_applk             = lv_app_area
       i_payment_date      = sy-datum
*     i_payment_date      = p_bdate
       i_withhtax_out      = ' '
       i_withhtax_in       = ' '
     TABLES
       t_seltab            = lit_seltab
       t_fkkcl             = lit_open_item
     EXCEPTIONS
       concurrent_clearing = 1
       payment_orders      = 2
       OTHERS              = 3.
   IF sy-subrc = 0.
* Do not write off statistical or credit
     LOOP AT lit_open_item ASSIGNING <lfs_open_item>.
       IF <lfs_open_item>-stakz <> ' ' OR <lfs_open_item>-betrh < 0.
* Mark them to delete outside loop
         CLEAR: <lfs_open_item>-opbel, <lfs_open_item>-gpart, <lfs_open_item>-vkont.
       ENDIF.
     ENDLOOP.

* Marked in Loop. Deleted here
     DELETE lit_open_item WHERE opbel IS INITIAL AND
                                gpart IS INITIAL AND
                                vkont IS INITIAL.
* Delete Statistical Items except fees
     DELETE lit_open_item WHERE stakz EQ 'A'
                    OR    stakz EQ 'B'
                    OR    stakz EQ 'R'
                    OR    stakz EQ 'P'
                    OR    stakz EQ 'Z'
                    OR    stakz EQ 'I'
                    OR    stakz EQ 'J'.

   ENDIF.
ENDFORM.                    " SUB_GET_OPEN_ITEM
*&---------------------------------------------------------------------*
*&      Form  SUB_CAL_WOFF
*&---------------------------------------------------------------------*
*       Extrapolate the Write-Off for Bankruptcy date - 1
*----------------------------------------------------------------------
FORM sub_cal_woff  TABLES    lit_open_item STRUCTURE fkkcl
                    CHANGING lv_write_off_amt.
   DATA:
        lv_bdate             TYPE sy-datum,
        lv_cal_write_off     TYPE betrh_kk,
        lv_write_off_cr      TYPE betrh_kk,
        lv_running_bal       TYPE betrh_kk,
        lv_writeoff_days  TYPE i,
        lv_total_days        TYPE i.

   FIELD-SYMBOLS:
         <lfs_open_item>    TYPE fkkcl.

* Remove all open items which are for periods after bankruptcy date
* Customer would be responsible for those bill after bankruptcy date.
   DELETE lit_open_item[] WHERE  abrzu GE p_bdate.

* Bankruptcy Day - 1 is the date, customer is not responsible

   LOOP AT lit_open_item ASSIGNING <lfs_open_item>.

*   Only for the current bill, we need to extrapolate it
     IF <lfs_open_item>-abrzu LE lv_bdate AND <lfs_open_item>-abrzo GE lv_bdate.

*     Calculate write-off days between the start period and bankruptcy date
       lv_writeoff_days =  p_bdate - <lfs_open_item>-abrzu.

*     Calculate total days between the period.
       lv_total_days    = <lfs_open_item>-abrzo - <lfs_open_item>-abrzu.

*     Need to include all days. 01/31/2019 - 01/01/2019 = 30. We need 31
*     Hence adding 1
       lv_total_days    = lv_total_days + 1.

*     Do the mathematics
       lv_cal_write_off = ( <lfs_open_item>-betrw / lv_total_days ) * lv_writeoff_days.

*     Total Write Off
       lv_write_off_amt = lv_write_off_amt + lv_cal_write_off.

       CLEAR:  lv_total_days, lv_writeoff_days, lv_cal_write_off.

     ELSE.

*     For all other open items prior to bankruptcy date, add them. These need to be waived off
       lv_running_bal =  lv_running_bal + <lfs_open_item>-betrw.

     ENDIF.

   ENDLOOP.

* Final Write-Off = WriteOff for previous balance + Current Period Calculated WriteOff
   lv_write_off_amt = lv_running_bal + lv_write_off_amt.

ENDFORM.                    " SUB_CAL_WOFF
*&---------------------------------------------------------------------*
*&      Form  SUB_POST_WRITE_OFF
*&---------------------------------------------------------------------*
*       Call BAPI to Write Off
*----------------------------------------------------------------------
FORM sub_post_write_off
     TABLES    lit_open_item STRUCTURE fkkcl
     CHANGING  lv_write_off.
   DATA:
         lwa_open_item      TYPE fkkcl,
         lv_bp              TYPE gpart_kk,
         lwa_return         TYPE bapiret2,
         lwa_bapi_app_field TYPE bapirfka1,
         lwa_bapi_openitem  TYPE bapidfkkcl,
         lv_write_off_doc   TYPE opbel_kk,
         lv_write_off_amt   TYPE betrh_kk,
         lv_running_amt     TYPE betrh_kk,
         lv_doc_no          TYPE opbel_kk,
         lv_message(100)    TYPE c,
         lv_bankruptcy_type TYPE c,
         li_bapi_openitem   TYPE STANDARD TABLE OF bapidfkkcl.

   REFRESH: li_bapi_openitem[].
   CLEAR: lv_doc_no, lv_running_amt, lv_write_off_amt.

   SELECT SINGLE gpart INTO lv_bp FROM fkkvkp WHERE vkont = p_ca.
   lv_running_amt = lv_write_off.

   LOOP AT lit_open_item INTO lwa_open_item.

     lv_doc_no = lwa_open_item-opbel.

     lwa_bapi_openitem-doc_no    = lwa_open_item-opbel .
     lwa_bapi_openitem-item      = lwa_open_item-opupk .
     lwa_bapi_openitem-sub_item  = lwa_open_item-opupz .
     lwa_bapi_openitem-doc_date  = lwa_open_item-bldat .
     lwa_bapi_openitem-post_date = lwa_open_item-budat .
     lwa_bapi_openitem-net_date  = lwa_open_item-faedn .
     lwa_bapi_openitem-currency  = 'USD'.
     lwa_bapi_openitem-currency_iso  = 'USD' .
     lwa_bapi_openitem-amount        = lwa_open_item-betrw .
     lwa_bapi_openitem-tax_amount    = lwa_open_item-sbetw.

     IF lv_running_amt GT 0.
*     If the Open Item is less than the Write-Off Amount
*     Then write-off the whole Open Item
       IF lwa_open_item-betrw LE lv_running_amt.

         lwa_bapi_openitem-clearing_amount  = lwa_open_item-betrw.

*       Deduct the write-off and keep the balance for next Open Item
         lv_running_amt = lv_running_amt - lwa_open_item-betrw.

       ELSE.
*       If the write-off balance amount is less than Open Item
*       Do the write-off with that balance
         lwa_bapi_openitem-clearing_amount  = lv_running_amt.
         CLEAR lv_running_amt.

       ENDIF.
*     Activate the Item for Write Off
       lwa_bapi_openitem-item_activated = 'X'.
     ELSE.
       CLEAR lwa_bapi_openitem-item_activated.
     ENDIF.
*   Important :- Do not append the items which are NOT activated for write-off
     IF lwa_bapi_openitem-item_activated = 'X'.
       APPEND lwa_bapi_openitem TO li_bapi_openitem.
     ENDIF.

     AT LAST.
       lwa_bapi_app_field-cont_acct  = p_ca.
       lwa_bapi_app_field-buspartner = lv_bp.
       lwa_bapi_app_field-charge_off_reason = '03'.

*     BAPI to WriteOff
       CALL FUNCTION 'BAPI_CTRACDOCUMENT_WRITEOFF'
         EXPORTING
           documentnumber     = lv_doc_no
           posting_date       = sy-datum
           currency           = 'USD'
           doc_type           = 'ZW'
           charge_off_reason  = '03'     " Bankruptcy
           no_checks          = ' '
           application_fields = lwa_bapi_app_field
         IMPORTING
           return             = lwa_return
           ret_documentnumber = lv_write_off_doc
         TABLES
           openitems          = li_bapi_openitem.

       IF lv_write_off_doc IS NOT INITIAL.
         COMMIT WORK AND WAIT.

         WRITE:/ 'Write-Off Document Created Successfully - '(004), lv_write_off_doc COLOR COL_POSITIVE.

       ELSE.
         ROLLBACK WORK.                                 "#EC CI_ROLLBACK
         WRITE:/ 'Error Creating Write-Off Document'(005) COLOR COL_NEGATIVE.

       ENDIF.
     ENDAT.
   ENDLOOP.
ENDFORM.                    " SUB_POST_WRITE_OFF

In the above program observe the CLEARING_AMOUNT esteem. It is bit precarious. The Sum for the BAPI would come from OPEN_ITEM, yet the CLEARING_AMOUNT is coming from the determined Discount Sum. Likewise the CLEARING_AMOUNT can’t be more prominent than the Sum.

In the event that you have Full Discount designed, the Sum and CLEARING_AMOUNT would be same and equivalent to OPEN_ITEM-BETRW.

Discount process is a basic program for ABAPers. Yet, since the BAPI was never utilized in my ongoing client’s SAP ISU Scene, consequently I considered sharing the code bit here. If it’s not too much trouble, note I’m not an ISU designer. I’m only your nearby ordinary ABAP fellow.

 

YOU MAY LIKE THIS

ALV with an Editable Row

EDI INTEGRATION WITH SAP IDOC

Is data element WDY_BOOLEAN and Flag (Char1) same for Web Dynpro ALV?

 

WhatsApp WhatsApp us