0% found this document useful (0 votes)
3 views2 pages

07 OIA With Aggregation Function

The document outlines an ABAP report named 'zdec_oia_aggregate' that calculates average open days and gross amounts for business partners based on invoice data. It retrieves data from various tables, processes it to compute averages, and applies thresholds for tagging. Finally, it displays the results along with the execution time of the report.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

07 OIA With Aggregation Function

The document outlines an ABAP report named 'zdec_oia_aggregate' that calculates average open days and gross amounts for business partners based on invoice data. It retrieves data from various tables, processes it to compute averages, and applies thresholds for tagging. Finally, it displays the results along with the execution time of the report.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

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

*& Report zdec_oia_simple


*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zdec_oia_aggregate.

types: begin of ty_avg_days,


bp_id type snwd_bpa-bp_id,
open_days type int4,
inv_count type int4,
end of ty_avg_days,
begin of ty_amount,
bp_id type snwd_bpa-bp_id,
company_name type snwD_bpa-company_name,
gross_amount type snwd_so_inv_head-gross_amount,
currency_code type snwd_so_inv_head-currency_code,
end of ty_amount,
begin of ty_oia,
bp_id type snwd_bpa-bp_id,
company_name type snwD_bpa-company_name,
gross_amount type snwd_so_inv_head-gross_amount,
currency_code type snwd_so_inv_head-currency_code,
avg_open_days type int4,
tagging type c,
end of ty_oia.

data: lt_days type table of ty_avg_days,


ls_Days type ty_avg_days,
lt_gross type table of ty_amount,
ls_gross type ty_amount,
lt_oia type table of ty_oia,
ls_oia type ty_oia.

data(lo_timer) = cl_abap_runtime=>create_hr_timer( ).
data(t1) = lo_timer->get_runtime( ).

select bp_id, head~changed_at, count( * ) as cnt


from snwd_so_inv_head as head
inner join snwd_bpa as bpa
on head~buyer_guid = bpa~node_key
where head~payment_status = ''
group by bp_id, head~changed_at
into @data(ls_head)
.

convert time stamp ls_head-changed_at time zone sy-zonlo into date


data(lv_date).
ls_Days-open_days = sy-datum - lv_date.
ls_Days-inv_count = ls_head-cnt.
ls_days-bp_id = ls_head-bp_id.
collect ls_days into lt_days.

ENDSELECT.

select single * into @data(ls_threshold) from zdp_cust where id = @sy-uname.

*Takt 2 developements
select bp_id, company_name, sum( item~gross_amount ) as gross_amount,
item~currency_code as currency_code
from snwd_so_inv_item as item inner join
snwd_so_inv_head as head on item~parent_key = head~node_key
inner join snwd_bpa as bpa
on bpa~node_key = head~buyer_guid where head~payment_status = ''
group by bp_id, company_name, item~currency_code
into @data(ls_amt).

ls_gross = CORRESPONDING #( ls_amt ).

call function 'CONVERT_TO_LOCAL_CURRENCY'


EXPORTING
date = sy-datum
foreign_amount = ls_amt-gross_amount
foreign_currency = ls_amt-currency_code
local_currency = ls_threshold-currency_code
IMPORTING
local_amount = ls_gross-gross_amount
.
ls_gross-currency_code = ls_threshold-currency_code.
collect ls_gross into lt_gross.

ENDSELECT.
loop at lt_days into ls_days.

MOVE-CORRESPONDING ls_days to ls_oia.


read table lt_gross into ls_gross with key bp_id = ls_days-bp_id.

ls_oia-avg_open_days = ls_days-open_days / ls_days-inv_count.


ls_oia-gross_amount = ls_gross-gross_amount.
ls_oia-currency_code = ls_gross-currency_code.
ls_oia-company_name = ls_gross-company_name.
if ls_oia-avg_open_days > ls_threshold-max_open_days and ls_oia-gross_amount >
ls_threshold-max_gross_amount.
ls_oia-tagging = 'X'.
else.
clear ls_oia-tagging.
ENDIF.
append ls_oia to lt_oia.

ENDLOOP.

data(t2) = lo_timer->get_runtime( ).
data(times) = ( t2 - t1 ) / 1000.

cl_demo_output=>write_text( text = |the total time taken was { times } ms| ).


cl_demo_output=>display_data(
EXPORTING
value = lt_oia
* name =
).

You might also like