ZF Check Xopvw

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 7

*&---------------------------------------------------------------------*

*& Report ZF_CHECK_XOPVW


*&
*&---------------------------------------------------------------------*
*&
*& Checks BSIS for items with incorrect XOPVW per account per year
*& and OI managed accounts for archived items in BSIS
*& (SKB1-XOPVW = 'X' => searches for BSIS-XOPVW = ' ' per year
*& SKB1-XOPVW = 'X' => searched for BSIS-XARCH = 'X' per year
*& SKB1-XOPVW = ' ' => searches for BSIS-XOPVW = 'X' per year)
*&
*&
*&*&--------------------------------------------------------------------
*-*
*& Change log:
*&
*& DB240914: Check OI managed accounts also for archived items in BSIS
*& UD020920: Determine YEARFROM directly via BSIS per account
*&
*&
*&---------------------------------------------------------------------*
*& Version: 3
*&---------------------------------------------------------------------*
*& Report in Q3A
*& Author: D028962
*&
*&
*&---------------------------------------------------------------------*

report zf_check_xopvw line-size 120.

tables: bkpf, skb1.


data: gs_skb1 type skb1.

include icons.
type-pools: slis.
data: lt_listheader type slis_t_listheader.
data: ls_listheader type slis_listheader.
data: lt_fcat type slis_t_fieldcat_alv with header line.
data: ls_layout type slis_layout_alv.
data: begin of lt_display occurs 0,
bukrs like skb1-bukrs,
saknr like skb1-saknr,
gjahr like bkpf-gjahr,
belnr like bkpf-belnr,
buzei like bseg-buzei,
xopvw like skb1-xopvw,
xarch like bsis-xarch,
comment like bseg-sgtxt,
icon(5).
data: end of lt_display.

types: begin of account,


bukrs type skb1-bukrs,
saknr type skb1-saknr,
gjahr type bkpf-gjahr,
belnr type bkpf-belnr,
buzei type bsis-buzei,
xbilk type ska1-xbilk,
* mitkz TYPE skb1-mitkz,
* xkres TYPE skb1-xkres,
xopvw type skb1-xopvw,
xarch type bsis-xarch, "DB240914
end of account.
data: gt_account type table of account with header line.

data: gt_error type table of account with header line.

types: begin of key,


bukrs type skb1-bukrs,
saknr type skb1-saknr,
end of key.
data: gt_key type sorted table of key with header line
with unique key bukrs saknr.

types: begin of bukrstab,


bukrs type t001-bukrs,
ktopl type t001-ktopl,
yearfrom type bkpf-gjahr,
yearto type bkpf-gjahr,
end of bukrstab.
data: gt_bukrstab type table of bukrstab with header line.

data: gs_xbilk type ska1-xbilk.

selection-screen begin of block 001 with frame title text_001.

selection-screen skip.
selection-screen begin of line.
selection-screen comment 1(18) text_002 for field s_bukrs.
selection-screen position 20.
select-options: s_bukrs for bkpf-bukrs.
selection-screen end of line.

selection-screen begin of line.


selection-screen comment 1(18) text_003 for field s_saknr.
selection-screen position 20.
select-options: s_saknr for skb1-saknr.
selection-screen end of line.

selection-screen begin of line.


selection-screen comment 1(18) text_004 for field yearfrom.
selection-screen position 23.
parameters: yearfrom type bkpf-gjahr.
selection-screen end of line.

selection-screen begin of line.


selection-screen comment 1(18) text_005 for field yearto.
selection-screen position 23.
parameters: yearto type bkpf-gjahr.
selection-screen end of line.

selection-screen end of block 001.

initialization.

text_001 = 'Account Selection'.


text_002 = 'Company Code'.
text_003 = 'GL Account'.
text_004 = 'From Year'.
text_005 = 'To Year'.

at selection-screen.
perform check_input.

start-of-selection.
*get bukrs master
perform get_bukrs.
*get GL master data
perform get_skb1.
*process accounts
perform process_accounts.
*output results.
perform output_alv.

*&---------------------------------------------------------------------*
*& Form GET_SKB1
*&---------------------------------------------------------------------*
form get_skb1 .

loop at gt_bukrstab.
select * from skb1 into gs_skb1
where bukrs eq gt_bukrstab-bukrs
and saknr in s_saknr
*exclude recon accounts
and mitkz eq space.
select single xbilk from ska1 into gs_xbilk
where ktopl = gt_bukrstab-ktopl
and saknr = gs_skb1-saknr.
*only balance sheet accounts
check gs_xbilk = 'X'.
*only accounts with line item display
check gs_skb1-xkres = 'X'.
clear gt_account.
move-corresponding gs_skb1 to gt_account.
append gt_account.
endselect.
endloop.

endform. " GET_SKB1

*&---------------------------------------------------------------------*
*& Form PROCESS_ACCOUNTS
*&---------------------------------------------------------------------*
form process_accounts .

data: ls_gjahr type bkpf-gjahr.


data: ls_bsis type bsis.

loop at gt_account.
read table gt_bukrstab with key
bukrs = gt_account-bukrs.
*************************************************************UD020920
*** determine lowest year directly from BSIS per account "UD020920
select min( gjahr ) from bsis into gt_bukrstab-yearfrom "UD020920
where bukrs = gt_account-bukrs "UD020920
and hkont = gt_account-saknr. "UD020920
*************************************************************UD020920
ls_gjahr = gt_bukrstab-yearto.
do.
if gt_account-xopvw = 'X'.
*search BSIS with XOPVW = space
select single * from bsis into ls_bsis
where bukrs = gt_account-bukrs
and hkont = gt_account-saknr
and gjahr = ls_gjahr
and xopvw = space
and xarch = space. "DB240914
if sy-subrc = 0.
clear gt_error.
move-corresponding gt_account to gt_error.
gt_error-gjahr = ls_gjahr.
gt_error-belnr = ls_bsis-belnr.
gt_error-buzei = ls_bsis-buzei.
insert gt_error into table gt_error.
*save key
clear gt_key.
move-corresponding gt_account to gt_key.
insert gt_key into table gt_key.
endif.
*search BSIS with XARCH = 'X' "DB240914
select single * from bsis into ls_bsis "DB240914
where bukrs = gt_account-bukrs "DB240914
and hkont = gt_account-saknr "DB240914
and gjahr = ls_gjahr "DB240914
and xarch = 'X'. "DB240914
if sy-subrc = 0. "DB240914
clear gt_error. "DB240914
move-corresponding gt_account to gt_error. "DB240914
gt_error-gjahr = ls_gjahr. "DB240914
gt_error-belnr = ls_bsis-belnr. "DB240914
gt_error-buzei = ls_bsis-buzei. "DB240914
gt_error-xarch = 'X'. "DB240914
insert gt_error into table gt_error. "DB240914
*save key
clear gt_key. "DB240914
move-corresponding gt_account to gt_key. "DB240914
insert gt_key into table gt_key. "DB240914
endif. "DB240914

else.
*search BSIS with XOPVW = X
select single * from bsis into ls_bsis
where bukrs = gt_account-bukrs
and hkont = gt_account-saknr
and gjahr = ls_gjahr
and xopvw = 'X'.
if sy-subrc = 0.
clear gt_error.
move-corresponding gt_account to gt_error.
gt_error-gjahr = ls_gjahr.
gt_error-belnr = ls_bsis-belnr.
gt_error-buzei = ls_bsis-buzei.
insert gt_error into table gt_error.
*save key
clear gt_key.
move-corresponding gt_account to gt_key.
insert gt_key into table gt_key.
endif.
endif.
ls_gjahr = ls_gjahr - 1.
if ls_gjahr < gt_bukrstab-yearfrom.
exit.
endif.
enddo.
endloop.

endform. " PROCESS_ACCOUNTS

*&---------------------------------------------------------------------*
*& Form GET_BUKRS
*&---------------------------------------------------------------------*
form get_bukrs .
data: ls_bkpf type bkpf.
data: ls_gjahr type bkpf-gjahr.

select * from t001 into corresponding fields of gt_bukrstab


where bukrs in s_bukrs.
*no fiscal year entered at selection screen => determine years
if yearfrom eq space.
if yearto = space.
*determine current fiscal year
call function 'GET_CURRENT_YEAR'
exporting
bukrs = gt_bukrstab-bukrs
date = sy-datum
importing
curry = gt_bukrstab-yearto.
else.
gt_bukrstab-yearto = yearto.
endif.
*set YEARFROM to CURRY
gt_bukrstab-yearfrom = gt_bukrstab-yearto.
*determine oldest fiscal year
do.
select single * from bkpf into ls_bkpf
where bukrs = gt_bukrstab-bukrs
and gjahr = ls_gjahr.
if sy-subrc = 0.
gt_bukrstab-yearfrom = ls_gjahr.
ls_gjahr = ls_gjahr - 1.
else.
exit.
endif.
enddo.
*fiscal year range entered at selection screen
else.
gt_bukrstab-yearfrom = yearfrom.
if yearto = space.
gt_bukrstab-yearto = yearfrom.
else.
gt_bukrstab-yearto = yearto.
endif.
endif.
*save bukrs
append gt_bukrstab.
endselect.

endform. " GET_BUKRS

*&---------------------------------------------------------------------*
*& Form CHECK_INPUT
*&---------------------------------------------------------------------*
form check_input .

if yearfrom ne space and yearto ne space.


if yearto < yearfrom.
message e016(gu)
with 'Yearto less than Yearfrom'.
endif.
endif.

endform. " CHECK_INPUT

*---------------------------------------------------------------------*
* Form OUTPUT_ALV
*---------------------------------------------------------------------*
form output_alv .

* No affected accounts => INFO message


if gt_error[] is initial.
message i208(00) with 'No affected accounts found'.
endif.
check not gt_error[] is initial.

* Add comments => table LT_DISPLAY


refresh lt_display.
loop at gt_error.
clear lt_display.
move-corresponding gt_error to lt_display.
if gt_error-xopvw = 'X'.
if gt_error-xarch eq space.
write 'BSIS with XOPVW not set' to lt_display-comment.
write icon_led_yellow as icon to lt_display-icon.
else.
write '!!! Archived item in BSIS !!!' to lt_display-comment.
write icon_led_red as icon to lt_display-icon.
endif.
else.
write 'BSIS with XOPVW set' to lt_display-comment.
write icon_led_yellow as icon to lt_display-icon.
endif.
append lt_display.
endloop.

* Built fieldcatalog
refresh lt_fcat.
call function 'REUSE_ALV_FIELDCATALOG_MERGE'
exporting
i_program_name = sy-repid
i_internal_tabname = 'LT_DISPLAY'
i_inclname = sy-repid
changing
ct_fieldcat = lt_fcat[]
exceptions
others = 1.

check not lt_fcat[] is initial.

* Remove column 'XARCH'


loop at lt_fcat where fieldname eq 'XARCH'.
lt_fcat-no_out = 'X'.
modify lt_fcat index sy-tabix.
endloop.

* Layout settings
ls_layout-colwidth_optimize = 'X'.

* List display of table LT_DISPLAY


call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = sy-repid
i_save = 'A'
i_callback_top_of_page = 'TOP_OF_PAGE'
is_layout = ls_layout
it_fieldcat = lt_fcat[]
tables
t_outtab = lt_display
exceptions
others = 1.
endform. " OUTPUT_ALV

*---------------------------------------------------------------------*
* FORM TOP_OF_PAGE *
*---------------------------------------------------------------------*
form top_of_page.
refresh lt_listheader.
clear ls_listheader.
ls_listheader-typ = 'H'.
ls_listheader-info = 'ZF_CHECK_XOPVW'.
append ls_listheader to lt_listheader.
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
it_list_commentary = lt_listheader.
endform. "top_of_page

You might also like