You are on page 1of 7

REPORT zshow_man_fi_docs_on_stock_acc.

* Specifications:
* This report checks whether there exists
* manual postings on stock accounts (table t_non_bsx)
************************************************************************
*
DEFINITION PART
************************************************************************
* tables
TABLES:
bseg,
bkpf,
mbew,
t001,
t001k,
t030,
t030r,
t025.
* types
TYPES:
BEGIN OF ty_account_det,
bwkey LIKE t001k-bwkey,
bklas LIKE mbew-bklas,
konto LIKE t030-konth,
waers LIKE t001-waers,
END OF ty_account_det.

"type for account information


"only one account, konth = konts

* internal tables and structures


DATA:
t_account_det TYPE ty_account_det OCCURS 0,
ls_account_det TYPE ty_account_det.
DATA:
BEGIN OF itabw OCCURS 0,
matnr
LIKE mbew-matnr,
bwtar
LIKE mbew-bwtar,
bwkey
LIKE mbew-bwkey,
bklas
LIKE mbew-bklas,
hkont
LIKE bseg-hkont,
current_account LIKE bseg-hkont,
dmbtr
LIKE bseg-dmbtr,
END OF itabw,
BEGIN OF t_non_bsx OCCURS 0,
hkont LIKE bseg-hkont,
belnr LIKE bseg-belnr,
buzei LIKE bseg-buzei,
gjahr LIKE bseg-gjahr,
ktosl LIKE bseg-ktosl,
dmbtr LIKE bseg-dmbtr,
shkzg LIKE bseg-shkzg,
END OF t_non_bsx.
* parameters
DATA:
f_num_bseg

TYPE i,

"table for materials with


"wrong val.clss

"account of t030

"table for non-bsx-postings

"number of bseg entries checked

f_no_material TYPE i,
f_summarization TYPE c.

"number of bseg with missing material


"set,if one doc. found w/o matnr

* ranges
RANGES:
r_saknr FOR bseg-hkont.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(33) co_ccode FOR FIELD p_bukrs.
PARAMETER: p_bukrs LIKE bseg-bukrs MEMORY ID buk OBLIGATORY.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
*SELECTION-SCREEN COMMENT 1(33) co_saknr FOR FIELD p_saknr.
PARAMETER: p_saknr LIKE bseg-hkont MEMORY ID sak no-display.
SELECTION-SCREEN END OF LINE.
SELECT-OPTIONS: r_gjahr FOR bseg-gjahr NO-EXTENSION.
************************************************************************
*
INITIALIZATION
************************************************************************
INITIALIZATION.
co_ccode = 'Company code'.
************************************************************************
*
START-OF-SELECTION
************************************************************************
START-OF-SELECTION.
PERFORM
PERFORM
PERFORM
PERFORM

get_accounts.
clear_data.
get_bseg_data.
output_data.

************************************************************************
*
FORM ROUTINES
************************************************************************
***********************************************************************
* get accounts
***********************************************************************
FORM get_accounts.
DATA:
BEGIN OF lt_t030 OCCURS 0,
bklas LIKE t030-bklas,
bwmod LIKE t030-bwmod,
konts LIKE t030-konts,
konth LIKE t030-konth,
END OF lt_t030.
REFRESH lt_t030.
CLEAR r_saknr.
REFRESH r_saknr.
r_saknr-option = 'EQ'.
r_saknr-sign = 'I'.
* account entered? if not, use all accounts in company with processing
* key 'BSX'

*
*
*

*
*

IF NOT p_saknr IS INITIAL.


r_saknr-low = p_saknr.
APPEND r_saknr.
ELSE.
get chart of account of table T001
SELECT SINGLE * FROM t001 WHERE bukrs = p_bukrs.
get entries of table T030 with chart of account and processing key
'BSX' and save them in an internal table lt_t030
SELECT * FROM t030 INTO CORRESPONDING FIELDS OF TABLE lt_t030
WHERE ktopl = t001-ktopl
AND ktosl = 'BSX'.
fill range r_saknr with credit accounts of lt_t030
LOOP AT lt_t030.
warning if credit account <> debit account
IF lt_t030-konth <> lt_t030-konts.
WRITE:/ '!!Attention credit account <> debit account in t030'.
WRITE:/ lt_t030.
ENDIF.
r_saknr-low = lt_t030-konth.
COLLECT r_saknr.
ENDLOOP.
ENDIF.

ENDFORM.

" GET_ACCOUNTS

************************************************************************
* fill table t_account_det with acount determination info
************************************************************************
FORM account_determination.
CLEAR ls_account_det.
* find all possible combinations of valuation area/valuation class
SELECT * FROM t001k WHERE bukrs = p_bukrs.
* ls_account_det-bukrs = p_bukrs.
ls_account_det-bwkey = t001k-bwkey.
* all defined valuation classes
SELECT * FROM t025.
ls_account_det-bklas = t025-bklas.
APPEND ls_account_det TO t_account_det.
ENDSELECT.
ENDSELECT.
* make account determination for all entries in t_account_det
LOOP AT t_account_det INTO ls_account_det.
SELECT SINGLE * FROM t001k WHERE bwkey = ls_account_det-bwkey.
SELECT SINGLE * FROM t001 WHERE bukrs = p_bukrs.
ls_account_det-waers = t001-waers.
SELECT SINGLE * FROM t030r WHERE ktopl = t001-ktopl
AND ktosl = 'BSX'.
* If no valuation modification, delete BWMOD of valuation key
IF t030r-xbwmo IS INITIAL AND NOT t001k-bwmod IS INITIAL.
CLEAR t001k-bwmod.
ENDIF.
* If valuation class irrelevant, clear valuation class.
IF t030r-xbkla IS INITIAL.
CLEAR ls_account_det-bklas.
ENDIF.
* main account determination
SELECT SINGLE * FROM t030 WHERE ktopl = t001-ktopl
AND ktosl = 'BSX'
AND bwmod = t001k-bwmod

AND komok = space


AND bklas = ls_account_det-bklas.
IF sy-subrc <> 0.
* no account found, leave account field empty
CONTINUE.
ELSE.
* assume konth = konts, otherwise error in RM07MMFI
ls_account_det-konto = t030-konth.
MODIFY t_account_det FROM ls_account_det.
ENDIF.
ENDLOOP.
SORT t_account_det BY bwkey bklas konto.
ENDFORM.

" ACCOUNT_DETERMINATION

************************************************************************
* clear flags and counters
************************************************************************
FORM clear_data.
CLEAR:
f_summarization,
f_num_bseg,
f_no_material.
ENDFORM.

" CLEAR_DATA

************************************************************************
* get entries of table BSEG
************************************************************************
FORM get_bseg_data.
DATA: c1 TYPE cursor.
OPEN CURSOR WITH HOLD c1 FOR
SELECT gjahr shkzg dmbtr belnr buzei ktosl
matnr bwkey bwtar hkont
FROM bseg WHERE bukrs = p_bukrs
AND hkont IN r_saknr
AND gjahr IN r_gjahr.
DO.
FETCH NEXT CURSOR c1 INTO
(bseg-gjahr, bseg-shkzg, bseg-dmbtr, bseg-belnr,
bseg-buzei, bseg-ktosl,
bseg-matnr, bseg-bwkey, bseg-bwtar, bseg-hkont).
IF sy-subrc <> 0.
EXIT.
ENDIF.
PERFORM check_fimm.
ENDDO.
CLOSE CURSOR c1.
ENDFORM.

" GET_BSEG_DATA

************************************************************************
* checks on bseg for check FI-MM
* fill table itabw with total value posted per material
* and t_non_bsx with non BSX postings
* seg f_summarization if document with missing material found

************************************************************************
FORM check_fimm.
* number of documents checked
f_num_bseg = f_num_bseg + 1.
* Summarization active?
IF bseg-matnr = space AND bseg-ktosl = 'BSX'.
f_summarization = 'X'.
f_no_material = f_no_material + 1.
ENDIF.
* documents from R/2 have no ktosl! matnr should be filled
IF bseg-ktosl = 'BSX' OR
( bseg-matnr <> space AND bseg-ktosl = space ).
* one document with summarization found, no sense to collect data
CHECK f_summarization IS INITIAL.
* collect total of values per material
MOVE-CORRESPONDING bseg TO itabw.
IF bseg-shkzg = 'H'.
itabw-dmbtr = 0 - itabw-dmbtr.
ENDIF.
COLLECT itabw.
ENDIF.
* non-bsx posting:
IF bseg-ktosl <> 'BSX'.
MOVE-CORRESPONDING bseg TO t_non_bsx.
APPEND t_non_bsx.
ENDIF.
ENDFORM.

" CHECK_FIMM

***********************************************************************
* output data
***********************************************************************
FORM output_data.
* input data
PERFORM out_input_data.
* checked accounts
SUMMARY.
WRITE: / 'Account checked:'.
DETAIL.
LOOP AT r_saknr.
WRITE: / r_saknr-low.
ENDLOOP.
SKIP 1.
ULINE.
* Number of BSEG entries
SUMMARY.
WRITE:/'Number of BSEG-entries checked:', f_num_bseg.
SKIP 1.
ULINE.
* non BSX-postings
PERFORM out_non_bsx_posting.
ENDFORM.

" OUTPUT_DATA

************************************************************************

* output of input data


************************************************************************
FORM out_input_data.
SUMMARY.
WRITE:/'Input-parameters:'.
SKIP 1.
WRITE:/ 'company code ', p_bukrs.
WRITE:/ 'stock account ', p_saknr.
WRITE:/ 'fiscal year ', r_gjahr-low, ' - ', r_gjahr-high.
SKIP 1.
WRITE:/ 'with document list'.
SKIP 1.
ULINE.
ENDFORM.

" OUT_INPUT_DATA

************************************************************************
* output of postings without processing key 'BSX'
************************************************************************
FORM out_non_bsx_posting.
DATA:
total_dif LIKE mbew-salk3,
total_s LIKE mbew-salk3,
total_h LIKE mbew-salk3,
l_index_z LIKE sy-tabix,
f_euro(1) type c.
DESCRIBE TABLE t_non_bsx LINES l_index_z.
IF l_index_z > 0.
SORT t_non_bsx BY hkont.
SUMMARY.
WRITE:/ 'Postings with processing key <> BSX'.
SKIP 1.
WRITE: / 'Acc.Doc',
14 'Year',
20 'Line',
25 'Post.key',
40 'Amount',
49 'Debit/credit'.
LOOP AT t_non_bsx.
AT NEW hkont.
SKIP 1.
WRITE:/ 'Account', t_non_bsx-hkont.
CLEAR: total_h, total_s, l_index_z.
ENDAT.
l_index_z = l_index_z + 1.
clear f_euro.
* sum debit/credit values
IF t_non_bsx-shkzg = 'H' and f_euro is initial.
total_h = total_h + t_non_bsx-dmbtr.
ELSEIF t_non_bsx-shkzg = 'S' and f_euro is initial.
total_s = total_s + t_non_bsx-dmbtr.
ENDIF.
DETAIL.
WRITE: / t_non_bsx-belnr,
14 t_non_bsx-gjahr,

20 t_non_bsx-buzei,
25 t_non_bsx-ktosl.
write:

30 t_non_bsx-dmbtr CURRENCY t001-waers,


49 t_non_bsx-shkzg.
AT END OF hkont.
SUMMARY.
WRITE:/5 'Number of manual postings for this account:',
l_index_z.
SKIP 1.
* difference between sum of credit and debit values
total_dif = total_s - total_h.
WRITE:/ 'Total debit :', total_s CURRENCY t001-waers,
/ 'Total credit:', total_h CURRENCY t001-waers,
/ 'Account', t_non_bsx-hkont,
"17052006
'Difference ',
total_dif CURRENCY t001-waers.
ENDAT.
ENDLOOP.
ELSE.
SUMMARY.
WRITE:/ 'No manual postings found.'.
ENDIF.
ENDFORM.

" OUT_NON_BSX_POSTING

You might also like