function Z_REFX_GET_ASSET_VALUES.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(IV_BUKRS) TYPE BUKRS
*" REFERENCE(IV_GJAHR) TYPE GJAHR OPTIONAL
*" REFERENCE(IV_CERULE) TYPE RECECERULE
*" REFERENCE(IV_AFABE) TYPE AFABE_D DEFAULT '99'
*" REFERENCE(IV_WAERS) TYPE WAERS
*" EXPORTING
*" REFERENCE(ET_ANLC) TYPE FAA_T_ANLC
*" REFERENCE(ET_ANLP) TYPE AA_T_ANLP
*" REFERENCE(ET_ANEP) TYPE FAA_T_ANEP
*" EXCEPTIONS
*" UNKNOWN_TRANSACTION
*"----------------------------------------------------------------------
data: LT_INTRENO type RE_T_INTRENO,
LT_CE_CASHFLOW type BAPI_RE_T_CE_CASHFLOW_INT,
LS_ANLC type ANLC,
LS_ANLP type ANLP,
LS_ANEP type ANEP,
LV_ASSETOBJ type RECEASOBJNR,
LV_DEPPOST type D,
LV_DETAILVALIDTO type RECADETAILVALIDTO,
LV_ANBTR type ANBTR.
clear: ET_ANLC, ET_ANLP, ET_ANEP.
*
* get relevant contracts
*
concatenate `AN` IV_BUKRS into LV_ASSETOBJ.
LV_ASSETOBJ+6(1) = '%'.
* after the latest update the currency is recorded in the cash flow items
select distinct INTRENO
from VICERULE
where ASSETOBJNR like @LV_ASSETOBJ
and RULECURR eq @IV_WAERS
union
* old valuation runs may have the currency not available in the cash flow
select distinct VICNCN~INTRENO
from VICERULE
inner join VICNCN
on VICERULE~INTRENO eq VICNCN~INTRENO
where VICERULE~ASSETOBJNR like @LV_ASSETOBJ
and VICERULE~RULECURR eq ''
and VICNCN~RECNCNCURR eq @IV_WAERS
order by INTRENO
into table @LT_INTRENO.
* any contract found
check sy-dbcnt gt 0.
* get date of last depreciation run
select AFBLGJ, AFBLPE up to 1 rows
from TABA
into @data(LS_TABA)
where BUKRS eq @IV_BUKRS
order by AFBLGJ descending, AFBLPE descending.
endselect.
concatenate LS_TABA-AFBLGJ LS_TABA-AFBLPE+1(2) '01' into LV_DEPPOST.
LV_DEPPOST = CL_RECA_DATE=>SET_TO_END_OF_MONTH( LV_DEPPOST ).
* get highest open year for asset postings
select single T093C~LGJAHR
from T093C
where BUKRS eq @IV_BUKRS
into @data(LV_LGJAHR).
if SY-SUBRC eq 0.
LV_DETAILVALIDTO(4) = LV_LGJAHR.
LV_DETAILVALIDTO+4(4) = '1231'.
else.
* if not defined select all available values
LV_DETAILVALIDTO = RECA0_DATE-MAX.
endif.
*
* loop through all relevant contracts
*
loop at LT_INTRENO into data(LV_INTRENO).
call function 'API_RE_CE_GET_CASHFLOW'
exporting
* ID_BUKRS =
* ID_RECNNR =
ID_INTRENO = LV_INTRENO
* IO_OBJECT =
* ID_DETAIL_DATA_FROM =
* ID_DETAIL_DATA_TO =
* ID_TERMNO =
ID_CERULE = IV_CERULE
* ID_CFTYPE =
* ID_CFSTATUS =
* IF_CFNEWEST = ABAP_TRUE
importing
ET_CE_CASHFLOW = LT_CE_CASHFLOW
exceptions
ERROR = 1
others = 2.
if SY-SUBRC ne 0.
continue.
endif.
* collect values for each year.
loop at LT_CE_CASHFLOW assigning field-symbol(<LS_CE_CASHFLOW>)
where ASSETOBJNR cp 'AN*'.
LS_ANLC = value #( BUKRS = <LS_CE_CASHFLOW>-ASSETOBJNR+2(4)
ANLN1 = <LS_CE_CASHFLOW>-ASSETOBJNR+6(12)
ANLN2 = <LS_CE_CASHFLOW>-ASSETOBJNR+18(4) ).
* use identifier for the pseudeo 'depreciation area' from import parameter
LS_ANLC-AFABE = IV_AFABE.
LS_ANLC-GJAHR = cond #( when <LS_CE_CASHFLOW>-POSTINGDATE is initial
then <LS_CE_CASHFLOW>-DFAELL(4)
else <LS_CE_CASHFLOW>-POSTINGDATE(4) ).
LV_ANBTR = cond #( when CL_RECDC_FLOW_TYPE=>GET_DETAIL( ID_FLOWTYPE = <LS_CE_CASHFLOW>-BOOK_FLOWTYPE )-SSOLHAB eq 'S'
then - <LS_CE_CASHFLOW>-BBWHR
else <LS_CE_CASHFLOW>-BBWHR ).
case <LS_CE_CASHFLOW>-CFTYPE.
when RECE2_CFTYPE-ACQUISITION.
if <LS_CE_CASHFLOW>-REFFLOWREL eq RECE3_REFFLOWREL-UNPLANNED_DEPRECIATION or
<LS_CE_CASHFLOW>-REFFLOWREL eq RECE3_REFFLOWREL-UNPLANNED_APPRECIATION.
* Impairment
LS_ANLP = corresponding #( LS_ANLC ).
LS_ANLP-AFABER = LS_ANLC-AFABE.
LS_ANLP-PERAF = <LS_CE_CASHFLOW>-DFAELL+4(2).
LS_ANLP-AAFAP = LV_ANBTR.
LS_ANLC-AAFAP = LV_ANBTR.
if <LS_CE_CASHFLOW>-DFAELL le LV_DEPPOST.
LS_ANLP-AAFAG = LS_ANLP-AAFAP.
LS_ANLC-AAFAG = LS_ANLC-AAFAP.
endif.
collect LS_ANLP into ET_ANLP. " collect periodic value changes
else.
* APC change
LS_ANLC-ANSWL = LV_ANBTR.
endif.
* Only transactions in the current are of any interest
if IV_GJAHR is initial or
IV_GJAHR eq <LS_CE_CASHFLOW>-DFAELL(4).
LS_ANEP = corresponding #( LS_ANLC ).
LS_ANEP-BZDAT = <LS_CE_CASHFLOW>-DFAELL.
LS_ANEP-ANBTR = LV_ANBTR.
* get original asset transaction type
select single ANEP~LNRAN, ANEP~BELNR, ANEP~BUZEI, ANEP~BZDAT, ANEP~BWASL
from ANEP inner join ANEK
on ANEP~BUKRS eq ANEK~BUKRS
and ANEP~ANLN1 eq ANEK~ANLN1
and ANEP~ANLN2 eq ANEK~ANLN2
and ANEP~LNRAN eq ANEK~LNRAN
inner join VIRADOC
on VIRADOC~PROCESSID eq ANEK~XBLNR
inner join VIRADOCITEM
on VIRADOC~DOCGUID eq VIRADOCITEM~DOCGUID
inner join TIVCERULECC
on TIVCERULECC~BUKRS eq ANEP~BUKRS
and TIVCERULECC~DEPRAREA eq ANEP~AFABE
where VIRADOCITEM~REFGUID eq @<LS_CE_CASHFLOW>-CFGUID
and ANEP~BUKRS eq @LS_ANLC-BUKRS
and ANEP~ANLN1 eq @LS_ANLC-ANLN1
and ANEP~ANLN2 eq @LS_ANLC-ANLN2
and VIRADOCITEM~OBJNR eq @<LS_CE_CASHFLOW>-ASSETOBJNR
and TIVCERULECC~CERULE eq @IV_CERULE
into ( @LS_ANEP-LNRAN, @LS_ANEP-BELNR, @LS_ANEP-BUZEI, @LS_ANEP-BZDAT, @LS_ANEP-BWASL ).
* skip if no transaction type was found
if SY-SUBRC ne 0.
CONTINUE.
endif.
append LS_ANEP to ET_ANEP.
endif.
when RECE2_CFTYPE-DEPRECIATION.
* Ordinary Depreciation
LS_ANLP = corresponding #( LS_ANLC ).
LS_ANLP-AFABER = LS_ANLC-AFABE.
LS_ANLP-PERAF = <LS_CE_CASHFLOW>-DFAELL+4(2).
LS_ANLP-NAFAP =
LS_ANLC-NAFAP = - LV_ANBTR.
if <LS_CE_CASHFLOW>-DFAELL le LV_DEPPOST.
LS_ANLP-NAFAG = LS_ANLP-NAFAP.
LS_ANLC-NAFAG = LS_ANLC-NAFAP.
endif.
collect LS_ANLP into ET_ANLP. " collect periodic value changes
when others.
* should never happen
raise UNKNOWN_TRANSACTION.
endcase.
collect LS_ANLC into ET_ANLC. " collect value changes
endloop.
endloop.
* ensure values are properly sorted for the periodic summarization
sort ET_ANLP by BUKRS ANLN1 ANLN2 AFABER GJAHR PERAF.
* calculate periodic values
loop at ET_ANLP into LS_ANLP.
loop at ET_ANLP assigning field-symbol(<LS_ANLP>)
where BUKRS eq LS_ANLP-BUKRS
and ANLN1 eq LS_ANLP-ANLN1
and ANLN2 eq LS_ANLP-ANLN2
and AFABER eq LS_ANLP-AFABER
and GJAHR eq LS_ANLP-GJAHR.
if <LS_ANLP>-PERAF gt LS_ANLP-PERAF.
add LS_ANLP-NAFAZ to -NAFAG.
endif.
add LS_ANLP-NAFAZ to <LS_ANLP>-NAFAP.
endloop.
endloop.
* calculate cumulated values
loop at ET_ANLC into LS_ANLC.
loop at ET_ANLC assigning field-symbol(<LS_ANLC>)
where BUKRS eq LS_ANLC-BUKRS
and ANLN1 eq LS_ANLC-ANLN1
and ANLN2 eq LS_ANLC-ANLN2
and AFABE eq LS_ANLC-AFABE
and GJAHR gt LS_ANLC-GJAHR.
add LS_ANLC-ANSWL to <LS_ANLC>-KANSW.
add LS_ANLC-NAFAP to <LS_ANLC>-KNAFA.
add LS_ANLC-AAFAP to <LS_ANLC>-KAAFA.
endloop.
endloop.
* restrict values to selected fiscal year
if IV_GJAHR is not initial.
delete ET_ANLC where GJAHR ne IV_GJAHR.
endif.
sort: ET_ANLC, ET_ANLP, ET_ANEP.
endfunction.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
5 | |
4 | |
3 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |