Sei sulla pagina 1di 7

class ZCL_PL_CUR_RESTATE_AMDP definition

public
final
create public .

public section.

interfaces IF_AMDP_MARKER_HDB .
interfaces IF_RSPLFA_SRVTYPE_IMP_EXEC .
interfaces IF_RSPLFA_SRVTYPE_TREX_EXEC .

types:
* Type for aggregation level ZFIPLAL07
BEGIN OF y_s_zfiplal07,
fiscper TYPE /bi0/oifiscper,
fiscper3 TYPE /bi0/oifiscper3,
fiscvarnt TYPE /bi0/oifiscvarnt,
fiscyear TYPE /bi0/oifiscyear,
chrt_accts TYPE /bi0/oichrt_accts,
comp_code TYPE /bi0/oicomp_code,
costcenter TYPE /bi0/oicostcenter,
co_area TYPE /bi0/oico_area,
division TYPE /bi0/oidivision,
func_area TYPE /bi0/oifunc_area,
gl_account TYPE /bi0/oigl_account,
infoprov TYPE rsinfoprov,
profit_ctr TYPE /bi0/oiprofit_ctr,
sold_to TYPE /bi0/oisold_to,
version TYPE /bi0/oiversion,
vtype TYPE /bi0/oivtype,
zaggrlvl TYPE /bic/oizaggrlvl,
zamnflag TYPE /bic/oizamnflag,
zarea1 TYPE /bic/oizarea1,
zcatclass TYPE /bic/oizcatclass,
zcostctr TYPE /bic/oizcostctr,
zdatasrc TYPE /bic/oizdatasrc,
zinfoprov TYPE /bic/oizinfoprov,
zplantyp TYPE /bic/oizplantyp,
zplanyear TYPE /bic/oizplanyear,
zrate_typ TYPE /bic/oizrate_typ,
zres_flag TYPE /bic/oizres_flag,
zryear TYPE /bic/oizryear,
zsftver TYPE /bic/oizsftver,
currency TYPE /bi0/oicurrency,
zcurrency TYPE /bic/oizcurrency,
amount TYPE /bi0/oiamount,
zramount TYPE /bic/oizramount,
END OF y_s_zfiplal07 .
types:
y_t_zfiplal07 TYPE STANDARD TABLE OF y_s_zfiplal07 .

* Insert in Public Section of your Class (ZCL_PL_CUR_RESTATE_AMDP)


* VALUE(i_version) TYPE NUMC3
* VALUE(i_plan_type) TYPE char10
* VALUE(i_plan_year) TYPE numc4
class-methods MY_HANA_PROCEDURE
importing
value(I_VIEW) type Y_T_ZFIPLAL07
value(I_RATE_YEAR) type NUMC4
value(I_RATE_TYPE) type CHAR4
value(I_ZINFOPROV) type CHAR30
exporting
value(E_VIEW) type Y_T_ZFIPLAL07 .
PROTECTED SECTION.
PRIVATE SECTION.
* CONSTANTS c_dim_name_plantyp TYPE rsdiobj-iobjnm VALUE 'ZPLANTYP' ##NO_TEXT.
* CONSTANTS c_dim_name_planyear TYPE rsdiobj-iobjnm VALUE 'ZPLANYEAR' ##NO_TEXT.
* CONSTANTS c_dim_name_infoprov TYPE rsdiobj-iobjnm VALUE '0INFOPROV' ##NO_TEXT.
* CONSTANTS c_dim_name_version TYPE rsdiobj-iobjnm VALUE '0VERSION' ##NO_TEXT.

* DATA gv_plan_type TYPE char10 .


* DATA gv_plan_year TYPE numc4 .
DATA gv_rate_type TYPE char4 .
DATA gv_rate_year TYPE numc4 .
DATA gv_zinfoprov TYPE char30.
* DATA gv_version TYPE numc4 .
* DATA gv_inpcur TYPE /bic/oizrate_typ .
* DATA gv_zinfoprov TYPE char30 .

ENDCLASS.

CLASS ZCL_PL_CUR_RESTATE_AMDP IMPLEMENTATION.

METHOD IF_RSPLFA_SRVTYPE_IMP_EXEC~EXECUTE.
ENDMETHOD.

METHOD IF_RSPLFA_SRVTYPE_IMP_EXEC~FINISH_EXECUTION.
ENDMETHOD.

METHOD IF_RSPLFA_SRVTYPE_IMP_EXEC~INIT_EXECUTION.

DATA: lt_keyfig TYPE rsplf_t_keyfnm,


ls_data_charsel LIKE LINE OF i_t_data_charsel.

LOOP AT i_t_data_charsel INTO ls_data_charsel.

IF ls_data_charsel-iobjnm EQ 'ZRATE_TYP'.
gv_rate_type = ls_data_charsel-low.
ENDIF.
IF ls_data_charsel-iobjnm EQ 'ZRYEAR'.
gv_rate_year = ls_data_charsel-low.
ENDIF.
IF ls_data_charsel-iobjnm EQ 'ZPLANTYP'.
ls_data_charsel-low = 'ACT'.
ENDIF.
IF ls_data_charsel-iobjnm EQ '0VERSION'.
ls_data_charsel-low = '100'.
ENDIF.
IF ls_data_charsel-iobjnm EQ '0INFOPROV' AND ls_data_charsel-low <>
'ZPLAD04'.
gv_zinfoprov = ls_data_charsel-low.
ENDIF.
ENDLOOP.

ENDMETHOD.

METHOD IF_RSPLFA_SRVTYPE_TREX_EXEC~INIT_AND_CHECK.
e_trex_supported = rs_c_true.
ENDMETHOD.

METHOD IF_RSPLFA_SRVTYPE_TREX_EXEC~TREX_EXECUTE.

DATA: l_r_sql_script TYPE REF TO if_rspls_sql_script,


l_procedure_name TYPE string,
l_t_iobj_param TYPE if_rsr_pe_adapter=>tn_t_iobj_param.

l_r_sql_script =
cl_rspls_session_store_manager=>get_sql_script_instance( i_r_store = i_r_store ).

* The method if_rspls_sql_script~get_parameter_values returns a table of


parameters
* with the values given in the function definition
l_r_sql_script->get_parameter_values(
EXPORTING
i_r_param_set = i_r_param_set
i_para_name_for_procedure = 'HANA_PROCEDURE_NAME'
IMPORTING
e_procedure_name = l_procedure_name
e_t_iobj_param = l_t_iobj_param ).
* The function parameter given mehtod paramenter i_para_name_for_procedure
* will not be returned in the table e_t_iobj_param but the value of this
* function parameter will be returned int the mehtod parameter e_procedure_name
* This mechanisme can e.g. be used to define function specific SAP-HANA-procedure
names.
* Other examples to get the name of the SAP-HANA-procedure name which will be
called can be
* - you use the technical name of the planning function type:
* - or you simply give the SAP-HANA procedure name in a string:
l_procedure_name = 'ZCL_PL_CUR_RESTATE_AMDP=>MY_HANA_PROCEDURE'.

l_t_iobj_param[ name = 'I_RATE_TYPE' ]-value = gv_rate_type.


l_t_iobj_param[ name = 'I_RATE_YEAR' ]-value = gv_rate_year.
l_t_iobj_param[ name = 'I_ZINFOPROV' ]-value = gv_zinfoprov.

r_s_view-view = l_r_sql_script->execute_sql_script(
i_view = i_view
i_t_iobj_param = l_t_iobj_param
i_proc_name = l_procedure_name
* i_sql_script_returns_ai = abap_true
i_r_msg = i_r_msg ).
ENDMETHOD.

METHOD MY_HANA_PROCEDURE BY DATABASE PROCEDURE FOR HDB LANGUAGE SQLSCRIPT


* For Options and declarations check the AMDP
documentiation (ABAP Managed Database Procedure)
OPTIONS READ-ONLY
* OPTIONS SUPPRESS SYNTAX ERRORS READ-ONLY.
USING t009b /bic/mzplantyp zpl_hgh_inf_cur.

conv_dates = select distinct fiscyear,


fiscper3,
zplantyp,
to_date (fiscyear||substr(fiscper3,2,2)||(select
butag from t009b
where
periv = 'Z1' AND

bdatj = fiscyear and

bumon = substr(fiscper3,2,2) and

reljr = '0') ) as date,


b."/BIC/ZRATETYP" as ZRATETYP
from :i_view as a
inner join "/BIC/MZPLANTYP" as b
on a.zplantyp = b."/BIC/ZPLANTYP"
where b.OBJVERS = 'A';

calc1 = select FISCPER,


a.FISCPER3,
FISCVARNT,
b.FISCYEAR,
CHRT_ACCTS,
COMP_CODE,
COSTCENTER,
CO_AREA,
DIVISION,
FUNC_AREA,
GL_ACCOUNT,
'ZPLAD04' as INFOPROV,
PROFIT_CTR,
SOLD_TO,
VERSION,
VTYPE,
ZAGGRLVL,
ZAMNFLAG,
ZAREA1,
ZCATCLASS,
ZCOSTCTR,
ZDATASRC,
:i_zinfoprov as ZINFOPROV,
a.ZPLANTYP,
:i_rate_type as ZRATE_TYP,
ZPLANYEAR,
'X' as ZRES_FLAG,
:i_rate_year as ZRYEAR,
ZSFTVER,
CURRENCY,
'USD' as ZCURRENCY,
amount,
CONVERT_CURRENCY( amount=>amount,
SOURCE_UNIT_COLUMN =>CURRENCY,
SCHEMA => 'SAPEPM',
TARGET_UNIT_COLUMN =>'USD',
REFERENCE_DATE => b.date,
CONVERSION_TYPE =>b.ZRATETYP,
ERROR_HANDLING=>'set to null',
CLIENT => '400') as zramount
from :i_view as a inner join :conv_dates as b
on A.fiscyear = B.fiscyear AND
A.fiscper3 = B.fiscper3
where infoprov <> 'ZPLAD04' and
( gl_account <> '0004000000' or
gl_account <> 'IF0263' ) and
zcurrency not in ( select currency from zpl_hgh_inf_cur
where currency = a.currency ) and
amount is not null;

calc2 = select FISCPER,


FISCPER3,
FISCVARNT,
FISCYEAR,
CHRT_ACCTS,
COMP_CODE,
COSTCENTER,
CO_AREA,
DIVISION,
FUNC_AREA,
GL_ACCOUNT,
INFOPROV,
PROFIT_CTR,
SOLD_TO,
VERSION,
VTYPE,
ZAGGRLVL,
ZAMNFLAG,
ZAREA1,
ZCATCLASS,
ZCOSTCTR,
CASE
when ZDATASRC = 'INPUT' then 'CONV'
when ZDATASRC = 'ALLOC' then 'CONV_ALLOC'
when ZDATASRC = 'CATEG' then 'CONV_CATEG'
when ZDATASRC = 'CATEG_ALLOC' then 'CONV_CATEG_ALLOC'
end as ZDATASRC,
ZINFOPROV,
ZPLANTYP,
ZRATE_TYP,
ZPLANYEAR,
ZRES_FLAG,
ZRYEAR,
ZSFTVER,
CURRENCY,
ZCURRENCY,
'0' as amount,
zramount
from :calc1
where amount is not null and
zdatasrc in ('INPUT','ALLOC','CATEG','CATEG_ALLOC');

e_view = select * from

( select FISCPER,
FISCPER3,
FISCVARNT,
FISCYEAR,
CHRT_ACCTS,
COMP_CODE,
COSTCENTER,
CO_AREA,
DIVISION,
FUNC_AREA,
GL_ACCOUNT,
INFOPROV,
PROFIT_CTR,
SOLD_TO,
VERSION,
VTYPE,
ZAGGRLVL,
ZAMNFLAG,
ZAREA1,
ZCATCLASS,
ZCOSTCTR,
ZDATASRC,
ZINFOPROV,
ZPLANTYP,
ZPLANYEAR,
ZRATE_TYP,
ZRES_FLAG,
ZRYEAR,
ZSFTVER,
CURRENCY,
ZCURRENCy,
amount,
zramount
from :calc1
where zramount is not NULL

UNION ALL

select FISCPER,
FISCPER3,
FISCVARNT,
FISCYEAR,
CHRT_ACCTS,
COMP_CODE,
COSTCENTER,
CO_AREA,
DIVISION,
FUNC_AREA,
GL_ACCOUNT,
INFOPROV,
PROFIT_CTR,
SOLD_TO,
VERSION,
VTYPE,
ZAGGRLVL,
ZAMNFLAG,
ZAREA1,
ZCATCLASS,
ZCOSTCTR,
ZDATASRC,
ZINFOPROV,
ZPLANTYP,
ZPLANYEAR,
ZRATE_TYP,
ZRES_FLAG,
ZRYEAR,
ZSFTVER,
CURRENCY,
ZCURRENCy,
amount,
zramount
from :calc2
where zramount is not NULL )

order by FISCPER,
FISCPER3,
FISCVARNT,
FISCYEAR,
CHRT_ACCTS,
COMP_CODE,
COSTCENTER,
CO_AREA,
DIVISION,
FUNC_AREA,
GL_ACCOUNT,
INFOPROV,
PROFIT_CTR,
SOLD_TO,
VERSION,
VTYPE,
ZAGGRLVL,
ZAMNFLAG,
ZAREA1,
ZCATCLASS,
ZCOSTCTR,
ZDATASRC,
ZINFOPROV,
ZPLANTYP,
ZPLANYEAR,
ZRATE_TYP,
ZRES_FLAG,
ZRYEAR,
ZSFTVER,
CURRENCY,
ZCURRENCy;

ENDMETHOD.
ENDCLASS.