In S/4 Accounting, G/L accounts can be defined as open items managed so as to differentiate the transaction status, e.g., invoice received and booked, invoiced cleared (or paid)
Open item-managed account bookings should be cleared so to correctly set the transaction status. It is possible to manually clear the open item via transactions or the Fiori app, e.g., when booking the payment, immediately clear the corresponding invoice, or use the automatic clearing job to clear the transactions in batch mode. Customers often have requests to clear the items in batch mode during the month-end closing phase.
Current solution: In automatic clearing program (F.13), it is possible to define up to 5 criteria for grouping an account's open items for automatic clearing. The program clears the open items that are grouped together if their total balance equals zero in local and foreign currency.
Limitations:
We would like to share an alternative solution that can help customers clear the items with a simple setup.
Use ICMR to define the flexible grouping rules to group the entries and to trigger the auto clearing via ABAP class.
ICMR is used for intercompany transaction mapping and reconciliation. However, it also provides a flexible framework for other transaction mapping and reconciliation cases. Below, we use an example to explain how the ICMR tool can be used for clearing two open item managed accounts bookings.
Account 790100 and 790200 are two open item-managed accounts. The business request is that if the entries of 790100 and 790200 have the same assignment and the total amount of entries is within tolerance, these entries should be cleared.
Step 1: (Tcode ICARC) Define a reason code that can trigger a clearing posting. In the reason code, the customer needs to define an ABAP class to call the clearing posting function module. The sample code is attached at the end.
Step 2: (Tcode ICADS) Define a data source that is used for intracompany transaction matching. The most important thing is that the leading and partner units should have the same organizational dimensions.
Define matching method ZF001 with data selected from company 0001 and accounts 790100 and 790200.
Define matching rules. Entries are sequentially checked against the rules. For example, in rule 1010, we define that if the entries of 790100 and 7902000 open items have the same assignment and the aggregated transaction currency amount is the same, then those entries are cleared. The clearing entries are triggered by assigned reason codes Z01 or Z02, which assign the ABAP class to call the clearing posting function.
Step 3: Define clearing difference tolerance and account
If it is also ok to clear the items within the difference tolerance, the customer needs to define the difference account that should be posted in IMG activities:
Step 1: Create sample data. Here, we post two items that need to be cleared
Step 2: Run the matching job. The system matches the line items according to matching rules. For matched items, the system triggers the clearing posting.
Step 3: Display created clearing document.
The above is just a simple example of how to use the ICMR to clear the open items. In practice, customers might have a much more complex process, which needs to use more flexible rules and more complex programs to achieve the desired process.
We hope this sample can inspire you.
--------------------------------------------------------------------------------------------------------------------------------
23.09.24 ERX ZCL_GL_DOCUMENT_CLEARING Page 1
--------------------------------------------------------------------------------------------------------------------------------
1 CLASS zcl_gl_document_clearing DEFINITION
2 PUBLIC
3 INHERITING FROM cl_ica_auto_adjustment
4 CREATE PUBLIC .
5
6 PUBLIC SECTION.
7
8 METHODS post
9 REDEFINITION .
10
11 TYPES:
12 t_ica_s_item TYPE TABLE OF ica_s_item.
13
14 PROTECTED SECTION.
15
16 METHODS convert_data
17 REDEFINITION .
18 PRIVATE SECTION.
19
20 METHODS get_dc_name
21 IMPORTING
22 !iv_method_id TYPE ica_method_id
23 !is_dim TYPE ica_s_dim
24 !is_dim_p TYPE ica_s_dim_p
25 !iv_rcode TYPE ica_rcode
26 RETURNING
27 VALUE(rv_dc_name) TYPE ica_dc_name .
28 METHODS insert_message
29 IMPORTING
30 !iv_msgty TYPE syst_msgty OPTIONAL
31 !iv_msgid TYPE syst_msgid OPTIONAL
32 !iv_msgno TYPE syst_msgno OPTIONAL
33 !iv_msgv1 TYPE syst_msgv OPTIONAL
34 !iv_msgv2 TYPE syst_msgv OPTIONAL
35 !iv_msgv3 TYPE syst_msgv OPTIONAL
36 !iv_msgv4 TYPE syst_msgv OPTIONAL
37 CHANGING
38 !ct_bapiret2 TYPE bapiret2_t .
39
40 ENDCLASS.
41
42
43
44 CLASS ZCL_GL_DOCUMENT_CLEARING IMPLEMENTATION.
45
46
47 * <SIGNATURE>---------------------------------------------------------------------------------------+
48 * | Instance Protected Method ZCL_GL_DOCUMENT_CLEARING->CONVERT_DATA
49 * +-------------------------------------------------------------------------------------------------+
50 * | [--->] IV_GRREF TYPE ICA_GRREF
51 * | [<-->] CT_DATA TYPE STANDARD TABLE
52 * | [!CX!] CX_ICA_MATCHING
53 * +--------------------------------------------------------------------------------------</SIGNATURE>
54 METHOD convert_data.
55 DATA lt_icadocm TYPE TABLE OF icadocm.
56 DATA lv_has_wsl TYPE abap_bool.
57 DATA lv_has_tsl TYPE abap_bool.
58 DATA ls_ica_s_item TYPE ica_s_item.
59
60 SELECT SINGLE method_id INTO @DATA(lv_method_id)
61 FROM ica_assign
--------------------------------------------------------------------------------------------------------------------------------
23.09.24 ERX ZCL_GL_DOCUMENT_CLEARING Page 2
--------------------------------------------------------------------------------------------------------------------------------
62 WHERE grref = @iv_grref.
63
64 SELECT * FROM icadocm INTO TABLE @LT_icadocm
65 WHERE method_id = @LV_method_id
66 AND grref = @iv_grref.
67
68 cl_ica_utility=>get_fields_by_method_id(
69 EXPORTING
70 iv_method_id = lv_method_id
71 RECEIVING
72 rt_fields = DATA(lt_cds_fields)
73 ).
74 IF line_exists( lt_cds_fields[ field_name = 'WSL' ] ).
75 lv_has_wsl = abap_true.
76 ELSEIF line_exists( lt_cds_fields[ field_name = 'TSL' ] ).
77 lv_has_tsl = abap_true.
78 ENDIF.
79
80 LOOP AT lt_icadocm INTO DATA(ls_icadocm).
81
82 CLEAR ls_ica_s_item.
83
84 ls_ica_s_item-bukrs = ls_icadocm-Rbukrs.
85 ls_ica_s_item-xref1_hd = ls_icadocm-blart.
86 ls_ica_s_item-rwcur = ls_icadocm-rwcur.
87 ls_ica_s_item-gjahr = ls_icadocm-gjahr.
88 ls_ica_s_item-bktxt = ls_icadocm-bktxt.
89 ls_ica_s_item-racct = ls_icadocm-racct.
90 ls_ica_s_item-xblnr = ls_icadocm-ref_belnr.
91 ls_ica_s_item-poper = ls_icadocm-buzei.
92 ls_ica_s_item-bschl = ls_icadocm-bschl.
93 ls_ica_s_item-lifnr = ls_icadocm-lifnr.
94 ls_ica_s_item-prctr = ls_icadocm-prctr.
95 ls_ica_s_item-wsl = ls_icadocm-wsl.
96 ls_ica_s_item-rhcur = ls_icadocm-rwcur.
97 ls_ica_s_item-hsl = ls_icadocm-hsl.
98 ls_ica_s_item-kunnr = ls_icadocm-kunnr.
99 ls_ica_s_item-mwskz = ls_icadocm-mwskz.
100
101 APPEND ls_ica_s_item TO ct_data.
102 ENDLOOP.
103
104 ENDMETHOD.
105
106
107 * <SIGNATURE>---------------------------------------------------------------------------------------+
108 * | Instance Private Method ZCL_GL_DOCUMENT_CLEARING->GET_DC_NAME
109 * +-------------------------------------------------------------------------------------------------+
110 * | [--->] IV_METHOD_ID TYPE ICA_METHOD_ID
111 * | [--->] IS_DIM TYPE ICA_S_DIM
112 * | [--->] IS_DIM_P TYPE ICA_S_DIM_P
113 * | [--->] IV_RCODE TYPE ICA_RCODE
114 * | [<-()] RV_DC_NAME TYPE ICA_DC_NAME
115 * +--------------------------------------------------------------------------------------</SIGNATURE>
116 METHOD get_dc_name.
117
118 DATA: lt_rcomp_r TYPE RANGE OF rcomp_d,
119 lt_rassc_r TYPE RANGE OF rassc,
120 lt_rbunit_r TYPE RANGE OF fc_bunit,
121 lt_rbuptr_r TYPE RANGE OF fc_buptr,
122 lt_rcode_r TYPE RANGE OF ica_rcode.
--------------------------------------------------------------------------------------------------------------------------------
23.09.24 ERX ZCL_GL_DOCUMENT_CLEARING Page 3
--------------------------------------------------------------------------------------------------------------------------------
123
124 CLEAR rv_dc_name.
125
126 SELECT ds_name INTO @DATA(lv_ds_name) UP TO 1 ROWS
127 FROM ica_method_ds
128 WHERE method_id = @iv_method_id.
129 ENDSELECT.
130 SELECT SINGLE * INTO @DATA(ls_ds) FROM ica_ds
131 WHERE ds_name = @LV_ds_name.
132
133 lt_rcode_r = VALUE #( ( sign = 'I' option = 'EQ' low = iv_rcode )
134 ( sign = 'I' option = 'EQ' low = '' ) ).
135 IF ls_ds-lunit_field = 'RCOMP' AND ls_ds-punit_field = 'RASSC'.
136 lt_rcomp_r = VALUE #( ( sign = 'I' option = 'EQ' low = is_dim-rcomp )
137 ( sign = 'I' option = 'EQ' low = '' ) ).
138 lt_rassc_r = VALUE #( ( sign = 'I' option = 'EQ' low = is_dim_p-rassc )
139 ( sign = 'I' option = 'EQ' low = '' ) ).
140 SELECT * INTO TABLE @DATA(lt_dc_comp)
141 FROM ica_dc_vaas_comp
142 WHERE method_id = @iv_method_id
143 AND rcomp IN @LT_rcomp_r
144 AND rassc IN @LT_rassc_r
145 AND rcode IN @LT_rcode_r
146 AND dc_name <> @space
147 ORDER BY rcomp DESCENDING,
148 rassc DESCENDING,
149 rcode DESCENDING.
150
151 READ TABLE lt_dc_comp INTO DATA(ls_dc_comp) INDEX 1.
152 IF sy-subrc = 0.
153 rv_dc_name = ls_dc_comp-dc_name.
154 ENDIF.
155
156 ELSEIF ls_ds-lunit_field = 'RBUNIT' AND ls_ds-punit_field = 'RBUPTR'.
157 lt_rbunit_r = VALUE #( ( sign = 'I' option = 'EQ' low = is_dim-rbunit )
158 ( sign = 'I' option = 'EQ' low = '' ) ).
159 lt_rbuptr_r = VALUE #( ( sign = 'I' option = 'EQ' low = is_dim_p-rbuptr )
160 ( sign = 'I' option = 'EQ' low = '' ) ).
161
162 SELECT * INTO TABLE @DATA(lt_dc_cu)
163 FROM ica_dc_vaas_cu
164 WHERE method_id = @iv_method_id
165 AND rbunit IN @LT_rbunit_r
166 AND rbuptr IN @LT_rbuptr_r
167 AND rcode IN @LT_rcode_r
168 AND dc_name <> @space
169 ORDER BY rbunit DESCENDING,
170 rbuptr DESCENDING,
171 rcode DESCENDING.
172
173 READ TABLE lt_dc_cu INTO DATA(ls_dc_cu) INDEX 1.
174 IF sy-subrc = 0.
175 rv_dc_name = ls_dc_cu-dc_name.
176 ENDIF.
177
178 ENDIF.
179
180 IF rv_dc_name IS INITIAL.
181 SELECT * INTO TABLE @DATA(lt_dc_vaas)
182 FROM ica_dc_vaas
183 WHERE method_id = @iv_method_id
--------------------------------------------------------------------------------------------------------------------------------
23.09.24 ERX ZCL_GL_DOCUMENT_CLEARING Page 4
--------------------------------------------------------------------------------------------------------------------------------
184 AND rcode IN @LT_rcode_r
185 AND dc_name <> @space
186 ORDER BY rcode DESCENDING.
187 READ TABLE lt_dc_vaas INTO DATA(ls_dc_vaas) INDEX 1.
188 IF sy-subrc = 0.
189 rv_dc_name = ls_dc_vaas-dc_name.
190 ENDIF.
191 ENDIF.
192 ENDMETHOD.
193
194
195 * <SIGNATURE>---------------------------------------------------------------------------------------+
196 * | Instance Private Method ZCL_GL_DOCUMENT_CLEARING->INSERT_MESSAGE
197 * +-------------------------------------------------------------------------------------------------+
198 * | [--->] IV_MSGTY TYPE SYST_MSGTY(optional)
199 * | [--->] IV_MSGID TYPE SYST_MSGID(optional)
200 * | [--->] IV_MSGNO TYPE SYST_MSGNO(optional)
201 * | [--->] IV_MSGV1 TYPE SYST_MSGV(optional)
202 * | [--->] IV_MSGV2 TYPE SYST_MSGV(optional)
203 * | [--->] IV_MSGV3 TYPE SYST_MSGV(optional)
204 * | [--->] IV_MSGV4 TYPE SYST_MSGV(optional)
205 * | [<-->] CT_BAPIRET2 TYPE BAPIRET2_T
206 * +--------------------------------------------------------------------------------------</SIGNATURE>
207 METHOD insert_message.
208 MESSAGE ID iv_msgid TYPE iv_msgty NUMBER iv_msgno
209 INTO DATA(lv_message)
210 WITH iv_msgv1 iv_msgv2 iv_msgv3 iv_msgv4.
211 APPEND VALUE bapiret2(
212 type = iv_msgty
213 id = iv_msgid
214 number = iv_msgno
215 message = lv_message
216 message_v1 = iv_msgv1
217 message_v2 = iv_msgv2
218 message_v3 = iv_msgv3
219 message_v4 = iv_msgv4
220 ) TO ct_bapiret2.
221 ENDMETHOD.
222
223
224 * <SIGNATURE>---------------------------------------------------------------------------------------+
225 * | Instance Public Method ZCL_GL_DOCUMENT_CLEARING->POST
226 * +-------------------------------------------------------------------------------------------------+
227 * | [--->] IV_GRREF TYPE ICA_GRREF
228 * | [!CX!] CX_ICA_MATCHING
229 * +--------------------------------------------------------------------------------------</SIGNATURE>
230 METHOD post.
231 DATA: ls_dim TYPE ica_s_dim,
232 ls_dim_p TYPE ica_s_dim_p,
233 lt_return TYPE bapiret2_t,
234 rv_subrc TYPE sy-subrc.
235
236 DATA: ls_header TYPE ica_s_header,
237 ls_item TYPE ica_s_item,
238 lt_item TYPE TABLE OF ica_s_item,
239
240 ls_clearing_header TYPE cl_fdc_clearing_document_inf=>ty_clearing_header,
241 lt_gl_item_to_be_clrd TYPE cl_fdc_clearing_document_inf=>tty_gl_item_to_be_clrd,
242 ls_gl_item_to_be_clrd TYPE cl_fdc_clearing_document_inf=>ty_gl_item_to_be_clrd,
243 rv_error_occured TYPE abap_bool,
244 ls_posted_document TYPE fdc_s_accdoc_hdr_key_odata,
--------------------------------------------------------------------------------------------------------------------------------
23.09.24 ERX ZCL_GL_DOCUMENT_CLEARING Page 5
--------------------------------------------------------------------------------------------------------------------------------
245 lv_test_run TYPE abap_bool.
246
247 me->get( EXPORTING iv_grref = iv_grref
248 CHANGING ct_data = lt_item ).
249
250 ls_clearing_header-bukrs = lt_item[ 1 ]-bukrs.
251 ls_clearing_header-blart = lt_item[ 1 ]-xref1_hd.
252 ls_clearing_header-bldat = sy-datum.
253 ls_clearing_header-budat = sy-datum.
254 ls_clearing_header-waers = lt_item[ 1 ]-rwcur.
255 ls_clearing_header-usnam = sy-uname.
256 LOOP AT lt_item INTO DATA(ls_ica_item).
257 ls_gl_item_to_be_clrd-bukrs = ls_ica_item-bukrs.
258
259 ls_gl_item_to_be_clrd-hkont = ls_ica_item-racct.
260 ls_gl_item_to_be_clrd-gjahr = ls_ica_item-gjahr.
261 ls_gl_item_to_be_clrd-belnr = ls_ica_item-xblnr.
262 ls_gl_item_to_be_clrd-buzei = ls_ica_item-poper.
263 APPEND ls_gl_item_to_be_clrd TO lt_gl_item_to_be_clrd.
264 ENDLOOP.
265
266 DATA(lo_clearing) = NEW cl_fdc_clearing_document_inf( ).
267
268 TRY.
269 rv_error_occured = lo_clearing->post(
270 EXPORTING
271 is_clearing_header = ls_clearing_header
272 it_gl_item_to_be_clrd = lt_gl_item_to_be_clrd
273 iv_test_run = lv_test_run
274 IMPORTING
275 es_posted_document = ls_posted_document
276 et_message = lt_return
277 ).
278
279
280 IF rv_subrc <> 0.
281
282 LOOP AT lt_return INTO DATA(ls_return).
283 WRITE: / 'Error:', ls_return-type, ls_return-id, ls_return-number, ls_return-message,
284 'Field:', ls_return-message_v1, 'Row:', ls_return-row.
285 ENDLOOP.
286 insert_message(
287 EXPORTING
288 iv_msgty = 'E'
289 iv_msgid = 'ZMSG'
290 iv_msgno = '001'
291 iv_msgv1 = 'Clearing failed'
292 CHANGING
293 ct_bapiret2 = lt_return
294 ).
295 ENDIF.
296
297 CATCH cx_root INTO DATA(lx_exception).
298 WRITE: / 'Exception occurred:', lx_exception->get_text( ).
299 ENDTRY.
300
301
302 SELECT SINGLE * INTO @DATA(ls_assign) FROM ica_assign
303 WHERE grref = @iv_grref.
304
305 READ TABLE lt_item INTO ls_item WITH KEY slice = 1.
--------------------------------------------------------------------------------------------------------------------------------
23.09.24 ERX ZCL_GL_DOCUMENT_CLEARING Page 6
--------------------------------------------------------------------------------------------------------------------------------
306 IF sy-subrc = 0.
307 MOVE-CORRESPONDING ls_item TO: ls_dim, ls_dim_p.
308 DATA(lv_dc_name) = get_dc_name(
309 EXPORTING
310 iv_method_id = ls_assign-method_id
311 is_dim = ls_dim
312 is_dim_p = ls_dim_p
313 iv_rcode = ls_assign-rcode
314 ).
315
316 ENDIF.
317
318 me->delete_appl_log( iv_grref ).
319 me->save_bapiret2_to_app_log( iv_grref = iv_grref it_bapiret2 = lt_return ).
320
321 READ TABLE lt_return WITH KEY type = 'E' TRANSPORTING NO FIELDS.
322 IF sy-subrc <> 0.
323 READ TABLE lt_return WITH KEY type = 'A' TRANSPORTING NO FIELDS.
324 IF sy-subrc <> 0.
325 me->update_processing_status( iv_grref = iv_grref iv_pstat = '29').
326 ELSE.
327 me->update_processing_status( iv_grref = iv_grref iv_pstat = '30').
328 ENDIF.
329 ENDIF.
330 ENDMETHOD.
331 ENDCLASS.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
9 | |
3 | |
2 | |
2 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |