Standard service - a fixed amount of work that is performed at a fixed price.  Post Service

  

Thursday, 21 March 2019 16:01

ISU – Bankruptcy Overview and Write-Off Process using BAPI_CTRACDOCUMENT_WRITEOFF

Written by 
Rate this item
(0 votes)

Bankruptcy is a second chance provided by the federal court to the consumer to get a “fresh start”. Bankruptcy also treats all creditors fairly and all debts must

be included and the consumer does not have the luxury to pick and choose the debts.

Bankruptcy are segregated by chapters viz Chapter 7 (Liquidation), Chapter 11 (Reorganization), Chapter 13 (For individual debtor; Adjustment of Debts of an Individual with Regular Income). Chapter 13 is mostly for individual debtor.

What happens when the customer files for bankruptcy?

It releases the customer/debtor from personal liability for certain specified types of debts. The customer is no longer legally required to pay the debts and it also prevents the creditors from taking any form of collection action including legal action and communications such as phone calls, letters or contacts of any kind.

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

ISU (Service viz electricity, water etc) provider cannot take any action to collect on debts incurred up to and including the day prior to the bankruptcy filing date. For example, the customer has balance due of $100.00 for March 1 to March 31 2019. He filed the bankruptcy on 20th March. Then the customer does not need to pay for March 1 to March 19th service. It should get written off. But the customer is still liable to pay the dues from March 20 to March 31st. And all future services.

The $100.00 balance is equally divided into 31 days and the customer gets Write-Off for 1st to 19th calendar days.

For our example:

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

So the customer does not need to pay $64.52. But he is still liable for any service after bankruptcy day. So he is liable for (100 – 64.52) = $35.48.

Note: If the customer has another $175 due from previous months (say Jan and Feb 2019), then the customers get full write-off of $175 because, those debts were incurred before the bankruptcy file date.

Also Note: Bankruptcy is filed at Business Partner (BP) level. So, all the corresponding Contract Account (CA) numbers and Contracts (CO) tied to the BP would be eligible for bankruptcy write-off.

Also ReadMy First SAP ABAP Program in S/4HANA

Enough of fundamentals. Let us look into SAP and check how things are done.

In SAP, Write-Off Reason can be Full or it can be Partial too. As the name suggests, if the Write-Off Reason is marked as Full, then we cannot write off only $64.52 from the open due of $100 for the above example.

We have 2 options to Write-Off:

  1. If the Bankruptcy Write-Off reason is Full. If the customer has $100 due and we want to write of $64.52. Then give a dummy credit of $35.48 to the customer.  This brings his due to $64.52. Now, we can write-off the full $64.52. Once the write-off is given, the customer has 0 due. But we still want to collect $35.48 from him. So, we need to reverse the $35.48 credit we gave initially. This way, $35.48 would be open balance for the customer and they need to pay the service provider.
  2. Configure the Bankruptcy Write-Off reason as Partial. In that case, no need to give a false credit to the customer and reverse it in the end. You can directly write-off $64.52 from the customer’s debt and $35.48 would remain open and customer is liable.

In order to control the Write-Off reason to be Partial or not, we need maintain the flag in the SPRO configuration.

Write-Off Configuration Path:

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

Check for Write-Off Reason, Bankruptcy, the PWO (Partial Write-Off) is Active. This means only for Bankruptcy reason, we can do a partial write-off. Rest all reasons viz Collectable, Underpayment are not Partial.

The transaction code for Write Off is FP04.

Let me show you how the Partial Write-Off and Full Write-Off work.

For our Write-Off Bankruptcy Reason ‘Non Collectable’, Partial Write-Off is not active in the Configuration.

So, let us try to write off using this reason.

The screen shows the open amount 80.59. Double click on the Gross Amount.

The Gross Clearing is copied from Gross amount and the Gross Clearing is not EDITABLE. This means, we cannot do partial write-off.

Now, let us check, how it looks for Partial Write-Off Bankruptcy Reason Code. We will take the same customer but try to apply a different Write-Off reason.

Check, when I double click on Gross amount, the Gross Clearing field becomes EDITABLE and we can Write-Off full or partial amount. For our example, we want to write off only 10.59.

Also Read : Free Video Course on Debugging for Functional Consultants

How to do Write-Off in SAP ABAP Program?

The simplest way is to do a BDC recording. But the simplest way may not always be the only way or the right way. We can Write-Off using BAPI ‘BAPI_CTRACDOCUMENT_WRITEOFF’.

I am looking at an SAP ISU system which is more than a decade old if not 2 decades and to my surprise; this BAPI has never been used.

The reason might be:

  1. BAPI is too complex to be consumed
  2. Developers directly used the FM which might be called from within the BAPI
  3. Developers preferred the BDC way

Anyway, when we tried to use the BAPI, we had initial hiccups to pass the data and do a successfully write-off. To solve our problem, we planned to debug the standard FP04 t-code and checked how SAP is doing itself.

At the end of the analysis, we found, SAP looks for Open Items and then Post the Write-Off. FM ‘FKK_OPEN_ITEM_SELECT’ is used for retrieving the Open Items and BAPI ‘BAPI_CTRACDOCUMENT_WRITEOFF’ to create the Write-Off document.

Please check the below sample program to get open items and post the write-off using the BAPI. You need to take care of the open amount and the clearing amount. And, you also need to activate the open item you want to write off. Detail is provided in the code snippet below.

Selection Screen

Output

Validation at t-code FPL9.

Also Check: My First OData Service in SAP

Sample Code Snippet to Write-Off

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
<code>*&amp;---------------------------------------------------------------------
*&amp; Object : zbankruptcy_writeoff
*&amp;---------------------------------------------------------------------
*&amp; Function: Write-Off Bankruptcy Debt
*&amp;---------------------------------------------------------------------
REPORTzbankruptcy_writeoff.
*---------------------------------------------------------------------*
* TABLES *
*---------------------------------------------------------------------*
TABLES:erdk.
*---------------------------------------------------------------------*
* TABLES *
*---------------------------------------------------------------------*
DATA:
it_open_itemTYPESTANDARD TABLE OFfkkcl,
gv_woff_amtTYPEbetrh_kk.
*---------------------------------------------------------------------*
* SELECTION SCREEN *
*---------------------------------------------------------------------*
SELECTION-SCREENBEGIN OF BLOCKb1WITHFRAMETITLEtext-001.
PARAMETERS:
p_caTYPEvkont_kk," CA
p_bdateTYPEsy-datumOBLIGATORYDEFAULTsy-datum." Bankruptcy Date
SELECTION-SCREENEND OF BLOCKb1.
*---------------------------------------------------------------------*
* END-OF-SELECTION. *
*---------------------------------------------------------------------*
END-OF-SELECTION.
* Get Open Items
PERFORMsub_get_open_item
TABLESit_open_item
USINGp_ca.
* Calculate Write-Off
PERFORMsub_cal_woffTABLESit_open_item
CHANGINGgv_woff_amt.
* Create Write Off documents
PERFORMsub_post_write_offTABLESit_open_item
CHANGINGgv_woff_amt.
*&amp;---------------------------------------------------------------------*
*&amp; Form SUB_GET_OPEN_ITEM
*&amp;---------------------------------------------------------------------*
* Get Open Items for the CA
* Logic leveraged from standard program LFKA1F01
* FORM openitem_read &amp; stat_openitem_delete
*----------------------------------------------------------------------
FORMsub_get_open_item
TABLESlit_open_itemSTRUCTUREfkkcl
USINGp_ca.
DATA:
lv_app_areaTYPEapplk_kkVALUE'R'," Utility
lwa_seltabTYPEiseltab,
lit_seltabTYPESTANDARD TABLE OFiseltab.
FIELD-SYMBOLS:
&lt;lfs_open_item>TYPEfkkcl.
*---------------only write off items for given CA---------------*
lwa_seltab-selcu=p_ca.
lwa_seltab-selfn='VKONT'.
lwa_seltab-selnr='0001'.
APPENDlwa_seltabTOlit_seltab.
*---------------only write off items with given currency--------------
lwa_seltab-selcu='USD'.
lwa_seltab-selfn='WAERS'.
lwa_seltab-selnr='0001'.
APPENDlwa_seltabTOlit_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.
IFsy-subrc=0.
* Do not write off statistical or credit
LOOP ATlit_open_itemASSIGNING&lt;lfs_open_item>.
IF&lt;lfs_open_item>-stakz&lt;>' 'OR&lt;lfs_open_item>-betrh&lt;0.
* Mark them to delete outside loop
CLEAR:&lt;lfs_open_item>-opbel,&lt;lfs_open_item>-gpart,&lt;lfs_open_item>-vkont.
ENDIF.
ENDLOOP.
* Marked in Loop. Deleted here
DELETElit_open_itemWHEREopbelISINITIALAND
gpartISINITIALAND
vkontISINITIAL.
* Delete Statistical Items except fees
DELETElit_open_itemWHEREstakzEQ'A'
ORstakzEQ'B'
ORstakzEQ'R'
ORstakzEQ'P'
ORstakzEQ'Z'
ORstakzEQ'I'
ORstakzEQ'J'.
ENDIF.
ENDFORM." SUB_GET_OPEN_ITEM
*&amp;---------------------------------------------------------------------*
*&amp; Form SUB_CAL_WOFF
*&amp;---------------------------------------------------------------------*
* Extrapolate the Write-Off for Bankruptcy date - 1
*----------------------------------------------------------------------
FORMsub_cal_woffTABLESlit_open_itemSTRUCTUREfkkcl
CHANGINGlv_write_off_amt.
DATA:
lv_bdateTYPEsy-datum,
lv_cal_write_offTYPEbetrh_kk,
lv_write_off_crTYPEbetrh_kk,
lv_running_balTYPEbetrh_kk,
lv_writeoff_daysTYPEi,
lv_total_daysTYPEi.
FIELD-SYMBOLS:
&lt;lfs_open_item>TYPEfkkcl.
* Remove all open items which are for periods after bankruptcy date
* Customer would be responsible for those bill after bankruptcy date.
DELETElit_open_item[]WHEREabrzuGEp_bdate.
* Bankruptcy Day - 1 is the date, customer is not responsible
LOOP ATlit_open_itemASSIGNING&lt;lfs_open_item>.
* Only for the current bill, we need to extrapolate it
IF&lt;lfs_open_item>-abrzuLElv_bdateAND&lt;lfs_open_item>-abrzoGElv_bdate.
* Calculate write-off days between the start period and bankruptcy date
lv_writeoff_days=p_bdate-&lt;lfs_open_item>-abrzu.
* Calculate total days between the period.
lv_total_days=&lt;lfs_open_item>-abrzo-&lt;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=(&lt;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+&lt;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
*&amp;---------------------------------------------------------------------*
*&amp; Form SUB_POST_WRITE_OFF
*&amp;---------------------------------------------------------------------*
* Call BAPI to Write Off
*----------------------------------------------------------------------
FORMsub_post_write_off
TABLESlit_open_itemSTRUCTUREfkkcl
CHANGINGlv_write_off.
DATA:
lwa_open_itemTYPEfkkcl,
lv_bpTYPEgpart_kk,
lwa_returnTYPEbapiret2,
lwa_bapi_app_fieldTYPEbapirfka1,
lwa_bapi_openitemTYPEbapidfkkcl,
lv_write_off_docTYPEopbel_kk,
lv_write_off_amtTYPEbetrh_kk,
lv_running_amtTYPEbetrh_kk,
lv_doc_noTYPEopbel_kk,
lv_message(100)TYPEc,
lv_bankruptcy_typeTYPEc,
li_bapi_openitemTYPESTANDARD TABLE OFbapidfkkcl.
REFRESH:li_bapi_openitem[].
CLEAR:lv_doc_no,lv_running_amt,lv_write_off_amt.
SELECTSINGLEgpartINTOlv_bpFROMfkkvkpWHEREvkont=p_ca.
lv_running_amt=lv_write_off.
LOOP ATlit_open_itemINTOlwa_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.
IFlv_running_amtGT0.
* If the Open Item is less than the Write-Off Amount
* Then write-off the whole Open Item
IFlwa_open_item-betrwLElv_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.
CLEARlv_running_amt.
ENDIF.
* Activate the Item for Write Off
lwa_bapi_openitem-item_activated='X'.
ELSE.
CLEARlwa_bapi_openitem-item_activated.
ENDIF.
* Important :- Do not append the items which are NOT activated for write-off
IFlwa_bapi_openitem-item_activated='X'.
APPENDlwa_bapi_openitemTOli_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.
IFlv_write_off_docISNOTINITIAL.
COMMIT WORKANDWAIT.
WRITE:/'Write-Off Document Created Successfully - '(004),lv_write_off_docCOLORCOL_POSITIVE.
ELSE.
ROLLBACK WORK."#EC CI_ROLLBACK
WRITE:/'Error Creating Write-Off Document'(005)COLORCOL_NEGATIVE.
ENDIF.
ENDAT.
ENDLOOP.
ENDFORM." SUB_POST_WRITE_OFF</code>

In the above program take note of the CLEARING_AMOUNT value. It is bit tricky. The AMOUNT for the BAPI would come from OPEN_ITEM, but the CLEARING_AMOUNT is coming from the calculated WRITE-OFF Amount. Also the CLEARING_AMOUNT cannot be greater than the AMOUNT.

If you have Full Write-Off configured, then the AMOUNT and CLEARING_AMOUNT would be same and equal to OPEN_ITEM-BETRW.

Write-Off process is a simple program for ABAPers. But since the BAPI was never used in my current client’s SAP ISU Landscape, therefore I thought of sharing the code snippet here. Please note I am not an ISU developer. I am just your next door normal ABAP guy. ?

We have a very active Telegram (App) SAP Technical Group with more than 4330+ SAP Technical Practitioners from 6 Continents of the SAP World. Please join it using below link.
Telegram SAP Technical Discuss Group. You need to install the Telegram App first on your mobile device. Once you have it on your mobile, you can join the group and also access it from the Web on your computer and laptop.

Free SAP ABAP for HANA Training Tutorials Exercises.

Read 34 times

Leave a comment

Make sure you enter all the required information, indicated by an asterisk (*). HTML code is not allowed.