MB5B bug fix for valuated stocks – Message M7 390 (FI document summarization is active / The results may be incorrect)

At month-end closing, MB5B transaction code is used to display the quantities, but also shows up the source of a material, stock summary, stock ledger or even the placement of a material in a warehouse. For the accounting team, it helps to report the valuated stocks.
Due to huge volume of items posted to accounting from stock movements, SAP offers a function of summarization for FI postings.
When you activate the FI summarization, SAP is displaying the warning message M7 390 when you run MB5B tcode: “FI document summarization is active / The results may be incorrect” which means the valuated stock report is no more consistent.
Here is the solution to fix this bug.
1. Analysis of the standard transaction MB5B

As MB5B selection screen offers different kind of selection to create its report, this warning message comes for the radiobutton “Valuated stock”.

When the FI summarization is activated, the totals displayed in “Valuated stock” are not correct anymore.
No OSS notes exist to solve it. We have contacted SAP support directly to have a solution and the answer was “The warning message displayed when you run MB5B is our solution”. Do a correction on your own if you want. Challenge accepted !

Since you have activated the FI summarization, the valuated stock report is splitting some lines when it shouldn’t. Normally you have 1 material document reconcilied with the corresponding accounting document, but now MB5B has splitted this information in two lines. Why ?

The FI summarization steps are:
1-    Sum up the items of the material document (from table MSEG)
2-    Insert the summarized items into the table BSIM
3-    Use the items summarized in BSIM table to build the items of the corresponding accounting document (BSEG table).
 
 
When MB5B program is checking the material document, it goes to the corresponding accounting document to check the consistency between the total amounts in MM and FI modules.
 
If the FI summarization is activated (view V_TTYPV), the MB5B program will go directly to BSIM table and, for each material document, it will take all items of the accounting document in BSIM and browse the items of the corresponding material document in MSEG table.
 
MB5B takes BSIM item amount, and it subtracts MSEG item amounts one by one until BSIM amount reaches the value 0.
When BSIM remaining amount = 0, MB5B set a consistency flag to the documents and only MSEG lines are displayed in the report.
 
When BSIM item remaining value is not 0, the program MB5B will save an inconsistency flag on BSIM lines, and BSIM lines with the inconsistency flag are added to MSEG lines. The amount is therefore doubled, and the report is wrong.

Example 1: Normal display of the report with material document 50000071088 2019 with material L8760400.

The 7 items from the table MSEG (material document) are summarized in 2 items into table BSIM (intermediate table to accounting document):


The report is showing all the material document items reconcilied correctly with the accounting document.

The MB5B logic is working like this: MB5B calculation starts with first item in BSIM (item 16 of the accounting document) which has an amount value 8011.04 EUR. It takes one by one the amounts from corresponding material document and susbtracts the amounts of the MSEG items. When the value 8011.04 reaches 0, the program is flagging BSIM item 16 as “OK”.
Then it takes the following BSIM item (item 31) with amount 56181.36 EUR, and it continues with the amounts not yet substracted it takes from MSEG table. When the BSIM item amount value 56181.36 reaches 0, the program is flagging BSIM item 31 as “OK”.
If all BSIM items are flagged “OK”, then the report for valuated stocks shows a normal display.

BSIM itemBSIM amountMSEG itemMSEG amountResultComments
168011.049-2801.065209.98
165209.9813-2801.062408.92
162408.9217-2408.920MB5B stops here and flags BSIM item 16 as OK
Next BSIM entry (item 31 of the accounting document) with amount 56181.36 EUR is now considered by the program which continues to substrat the remaining items of table MSEG.
BSIM itemBSIM amountMSEG itemMSEG amountResultComments
3156181.3635-14045.3442136.02
3142136.0244-14045.3428090.68
3128090.6847-14045.3414045.34
3114045.3453-14045.340MB5B stops here and flags BSIM item 31 as OK
Example 2 – Wrong display with material document 50000071088 2019 with material L4140106.
Here we have the issue generated by the FI summarization activation, when MB5B is no more able to reconcile the material document with its accounting document, due to the calculation logic in place in the program.

14 items in the material document (table MSEG) are summarized in 2 items in the table BSIM (accouting document).


Let’s check what happens in the calculation logic:
BSIM itemBSIM amountMSEG itemMSEG amountResultComments
5180198.592-16381.69163816.90
5163816.905-16381.69147435.21
5147435.218-7644.79139790.42
5139790.4212-7644.79132145.63
5132145.6316-6574.52125571.11
5125571.1120-16381.69109189.42
5109189.4223-16381.6992807.73
592807.7326-16381.6976426.04
576426.0429-16381.6960044.35
560044.3532-16381.6943662.66
543662.6638-16381.6927280.97
527280.9741-16381.6910899.28
510899.2850-16381.69-5482.41MB5B stops here and do not flag BSIM item 5 as OK
BSIM itemBSIM amountMSEG itemMSEG amountResultComments
1421864.1056-16381.695482.41MB5B stops here and do not flag BSIM item 14 as OK

To get rid of this error, we need to collect all amounts and quantities from BSIM and do the same collect for all amounts and quantities from MSEG.
When we do the difference between total amounts and total quantities it must give 0 if all is OK. If the result is 0, then we use the same logic as the standard MB5B is doing. We flag the documents with a deletion mark ‘D’ (bsim_lean-accessed = ‘D’). It means this document has been checked OK against its corresponding MSEG entries.

2. Custom solution

Go to the Abap editor (transaction SE38) and open the program RM07MLBD.
activate the implicit enhancement in the form BELEGE_ERGAENZEN_SEVERAL_DOCS.

FORM belege_ergaenzen_several_docs USING p_bsim_key TYPE c. “2963312
“””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””$”$\SE:(1)
Form BELEGE_ERGAENZEN_SEVERAL_DOCS, Start A

$$-Start: (1)———————————————————————————$$
ENHANCEMENT 1 ZMB5B. “active version

DATA: BEGIN OF lt_bsim_collect OCCURS 0,
bukrs LIKE bkpf-bukrs,
bwkey LIKE bsim-bwkey,
matnr LIKE bsim-matnr,
menge LIKE bsim-menge,
dmbtr LIKE bsim-dmbtr,
END OF lt_bsim_collect.

DATA: BEGIN OF lt_mseg_collect OCCURS 0,
mblnr LIKE mkpf-mblnr,
mjahr LIKE mkpf-mjahr,
matnr LIKE mseg-matnr,
werks LIKE mseg-werks,
dmbtr LIKE mseg-dmbtr,
waers LIKE mseg-waers,
menge LIKE mseg-menge,
meins LIKE mseg-meins,
belnr LIKE bkpf-belnr,
gjahr LIKE bkpf-gjahr,
END OF lt_mseg_collect.

DATA: lv_diff_dmbtr LIKE bsim-dmbtr,
lv_diff_menge LIKE bsim-menge,
lv_line_mseg TYPE i,
lv_line_bsim TYPE i.

CLEAR: lt_bsim_collect[], lt_bsim_collect[].

LOOP AT g_t_bsim_work INTO g_s_bsim_work.
MOVE-CORRESPONDING g_s_bsim_work TO lt_bsim_collect.
COLLECT lt_bsim_collect.
ENDLOOP.

CLEAR: lt_mseg_collect[], lt_mseg_collect[].

LOOP AT g_t_mseg_work INTO g_s_mseg_work.
MOVE-CORRESPONDING g_s_mseg_work TO lt_mseg_collect.
COLLECT lt_mseg_collect.
ENDLOOP.

CLEAR: lv_line_mseg, lv_line_bsim.
DESCRIBE TABLE lt_mseg_collect LINES lv_line_mseg.
DESCRIBE TABLE lt_bsim_collect LINES lv_line_bsim.

IF lv_line_mseg = 1 AND lv_line_bsim = 1.

CLEAR: lv_diff_dmbtr, lv_diff_menge.

LOOP AT lt_bsim_collect.
LOOP AT lt_mseg_collect.
lv_diff_dmbtr = lv_diff_dmbtr + ( lt_bsim_collect-dmbtr – lt_mseg_collect-dmbtr ).
lv_diff_menge = lv_diff_menge + ( lt_bsim_collect-menge – lt_mseg_collect-menge ).
ENDLOOP.
ENDLOOP.

IF lv_diff_dmbtr = 0 AND lv_diff_menge = 0.

LOOP AT g_t_mseg_work INTO g_s_mseg_work.
LOOP AT g_t_bsim_work INTO g_s_bsim_work.
ADD 1 TO g_cnt_mseg_done.
MOVE : g_s_bsim_work-belnr TO g_s_mseg_work-belnr,
g_s_bsim_work-gjahr TO g_s_mseg_work-gjahr.

IF gv_switch_ehp6ru = abap_true.
MOVE: g_s_bsim_work-buzei TO g_s_mseg_work-buzei.
MOVE-CORRESPONDING g_s_bsim_work TO g_t_bseg_key.
APPEND g_t_bseg_key.
ENDIF.
MODIFY g_t_mseg_work FROM g_s_mseg_work TRANSPORTING belnr gjahr buzei.

* mark the entries for deletion
MOVE ‘D’ TO g_s_bsim_work-accessed.
MODIFY g_t_bsim_work FROM g_s_bsim_work TRANSPORTING accessed.

LOOP AT g_t_bsim_lean INTO g_s_bsim_lean
Where belnr = g_s_bsim_work-belnr
And gjahr = g_s_bsim_work-gjahr
And menge = g_s_bsim_work-menge
And dmbtr = g_s_bsim_work-dmbtr.
MOVE : ‘D’ TO g_s_bsim_lean-accessed.
MODIFY g_t_bsim_lean FROM g_s_bsim_lean TRANSPORTING accessed.
ENDLOOP.
ENDLOOP.
ENDLOOP.

ENDIF.
ENDIF.

ENDENHANCEMENT.
$$-End: (1)———————————————————————————$$

ENHANCEMENT-POINT EHP605_RM07MLBD_17 SPOTS ES_RM07MLBD STATIC. “n443935
*first step : the entries must hit quantity and value “n443935
LOOP AT g_t_mseg_work INTO g_s_mseg_work. “n443935

You can find your enhancement with the transaction code SE19 with the enhancement name.
Share Tweet Share Email