[SAP-BPC-ABAP] Cheat Sheet
*&---------------------------------------------------------------------*
*& Env. : BPC_PIHC
*& Model : OPEX
*&---------------------------------------------------------------------*
*& Revision Log:
*& Ver# Date Dev Descr
*& ----- ----- ----- -----
*& 0001 02.04.2015 Rijdzuan Initial
*&---------------------------------------------------------------------*
*& Information:
*& Engine untuk membuat journal dari opex ke financial
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Declaration
*&---------------------------------------------------------------------*
DATA: ld_log TYPE string,
ld_log_flag TYPE flag.
DATA: ld_line TYPE i,
ld_linet(50).
DATA: lx_cv TYPE ujk_s_cv,
lt_member TYPE uja_t_dim_member,
lx_member TYPE uj_dim_member.
DATA: LX_MESSAGES TYPE UJ0_S_MESSAGE,
LT_MESSAGES TYPE UJ0_T_MESSAGE,
LS_WB_STATUS TYPE UJO_S_WB_STATUS,
L_SUCCESS TYPE UJ_FLG,
LT_ERRORS TYPE UJA_T_MEMBERS_ERROR.
** TYPE REF
DATA: LT_FINAL TYPE REF TO DATA,
LR_FINAL TYPE REF TO DATA.
FIELD-SYMBOLS: <LT_FINAL> TYPE STANDARD TABLE,
<LS_FINAL> TYPE ANY.
** Create final data
CREATE DATA LT_FINAL LIKE CT_DATA.
ASSIGN LT_FINAL->* TO <LT_FINAL>.
CREATE DATA LR_FINAL LIKE LINE OF CT_DATA.
ASSIGN LR_FINAL->* TO <LS_FINAL>.
FIELD-SYMBOLS: <LT_RECORD> TYPE STANDARD TABLE,
<LT_RECORD_DEL> TYPE STANDARD TABLE,
<LS_RECORD> TYPE ANY,
<LS_RECORD_DEL> TYPE ANY,
<LS_SIGNEDDATA> TYPE ANY.
*&---------------------------------------------------------------------*
*& RANGE DEFINE
*&---------------------------------------------------------------------*
LX_SELECTION TYPE UJ0_S_RANGE.
LT_SELECTION TYPE UJ0_T_RANGE.
LX_SELECTION_DIM TYPE UJ0_S_SEL.
LT_SELECTION_DIM TYPE UJ0_T_SEL.
"Range Dimension
DEFINE MC_SEL_DIMENSION.
&1-DIMENSION = &2.
&1-ATTRIBUTE = &3.
&1-SIGN = 'I'.
&1-OPTION = 'EQ'.
&1-LOW = &4.
APPEND &1 TO &5.
END-OF-DEFINITION.
"Range Model
DEFINE MC_SEL_MODEL.
CLEAR &1.
&1-sign = 'I'.
&1-option = 'EQ'.
&1-dimension = &2.
&1-low = &3.
APPEND &1 to &4.
END-OF-DEFINITION.
"Range of Member
DEFINE MC_SEL_RANGE.
CLEAR &1.
&1-sign = 'I'.
&1-option = 'EQ '.
&1-low = &2.
APPEND &1 to &3.
END-OF-DEFINITION.
*&---------------------------------------------------------------------*
*& GET DIMENSION WITH SELECTION
*&---------------------------------------------------------------------*
DATA: LT_POSTRULE TYPE ZBPC_TT_POSTING_RULE_DIM,
LX_POSTRULE TYPE ZBPC_TY_POSTING_RULE_DIM.
DATA: LT_R_POSTRULE TYPE UJ0_T_SEL,
LX_R_POSTRULE TYPE UJ0_S_SEL.
LX_R_POSTRULE-DIMENSION = 'POSTING_RULE'.
LX_R_POSTRULE-ATTRIBUTE = 'MODEL'.
LX_R_POSTRULE-SIGN = 'I'.
LX_R_POSTRULE-OPTION = 'EQ'.
LX_R_POSTRULE-LOW = 'CONSOLIDATION'.
APPEND LX_R_POSTRULE TO LT_R_POSTRULE.
CALL METHOD ZBPC_CL_GET_DIMENSION_MEMBER=>READ_MBR_DATA
EXPORTING
I_APPSET_ID = I_APPSET_ID "'BPC_PIHC'
I_DIMENSION = 'POSTING_RULE'
IT_SEL = LT_R_POSTRULE
IMPORTING
ET_POSTING_RULE = LT_POSTRULE.
IF LT_POSTRULE[] IS INITIAL.
** Raise exception
CLEAR: CT_DATA.
LD_LOG = 'Please maintain appropiate Posting Rule'.
CL_UJK_LOGGER=>LOG( I_OBJECT = LD_LOG ).
RAISE EXCEPTION TYPE CX_UJ_CUSTOM_LOGIC.
EXIT.
ENDIF.
*&---------------------------------------------------------------------*
*& GET INPUT MEMBER
*&---------------------------------------------------------------------*
DATA: lx_cv TYPE ujk_s_cv,
lt_member TYPE uja_t_dim_member,
lx_member TYPE uj_dim_member.
DEFINE mc_selection_dim.
CLEAR &1.
&1-sign = 'I'.
&1-option = 'EQ'.
&1-low = &2.
&1-dimension = &3.
APPEND &1 to &4.
END-OF-DEFINITION.
CLEAR: lt_selection_dim.
LOOP AT it_cv INTO lx_cv
WHERE user_specified = 'X'.
lt_member = lx_cv-member.
LOOP AT lt_member INTO lx_member.
mc_selection_dim lx_selection_dim
lx_member lx_cv-dimension lt_selection_dim.
ENDLOOP.
ENDLOOP.
*&---------------------------------------------------------------------*
*& GET MODEL WITH SELECTION
*&---------------------------------------------------------------------*
DEFINE mc_dim_selection.
CLEAR &1.
&1-sign = 'I'.
&1-option = 'EQ'.
&1-dimension = &2.
&1-low = &3.
APPEND &1 to &4.
END-OF-DEFINITION.
** "Category
LOOP AT LT_CATEGORY ASSIGNING <LS_CATEGORY>.
MC_DIM_SELECTION LX_ASSUMPTION_SEL 'CATEGORY'
<LS_CATEGORY>-ID LT_ASSUMPTION_SEL.
ENDLOOP.
** "Cycle
LOOP AT LT_CYCLE ASSIGNING <LS_CYCLE>.
MC_DIM_SELECTION LX_ASSUMPTION_SEL 'CYCLE'
<LS_CYCLE>-ID LT_ASSUMPTION_SEL.
ENDLOOP.
** "Rptcurrency
MC_DIM_SELECTION LX_ASSUMPTION_SEL 'RPTCURRENCY'
'USD' LT_ASSUMPTION_SEL.
"fetch into format model
CALL METHOD ZBPC_CL_GET_MODEL_RECORD=>FETCH
EXPORTING
I_APPSET_ID = I_APPSET_ID
I_APPL_ID = 'Assumption'
IT_SELECTION = LT_ASSUMPTION_SEL
IMPORTING
T_ASSUMPTION = LT_ASSUMPTION_ICP.
"fetch into format data object
CALL METHOD zbpc_cl_get_model_record=>fetch2
EXPORTING
i_appset_id = i_appset_id
i_appl_id = <ls_uja_appl>-application_id
it_selection = lt_selection_dim
IMPORTING
er_data = lr_data.
*&---------------------------------------------------------------------*
*& DECLARATION & INITIALIZE
*&---------------------------------------------------------------------*
DATA: ld_log TYPE string,
ld_log_flag TYPE flag.
DATA: ld_line TYPE i,
ld_linet(50).
DATA: LX_MESSAGES TYPE UJ0_S_MESSAGE,
LT_MESSAGES TYPE UJ0_T_MESSAGE,
LS_WB_STATUS TYPE UJO_S_WB_STATUS,
L_SUCCESS TYPE UJ_FLG,
LT_ERRORS TYPE UJA_T_MEMBERS_ERROR.
** TYPE REF
DATA: LT_FINAL TYPE REF TO DATA,
LR_FINAL TYPE REF TO DATA.
FIELD-SYMBOLS: <LT_FINAL> TYPE STANDARD TABLE,
<LS_FINAL> TYPE ANY.
** Create final data
CREATE DATA LT_FINAL LIKE CT_DATA.
ASSIGN LT_FINAL->* TO <LT_FINAL>.
CREATE DATA LR_FINAL LIKE LINE OF CT_DATA.
ASSIGN LR_FINAL->* TO <LS_FINAL>.
FIELD-SYMBOLS: <LT_RECORD> TYPE STANDARD TABLE,
<LT_RECORD_DEL> TYPE STANDARD TABLE,
<LS_RECORD> TYPE ANY,
<LS_RECORD_DEL> TYPE ANY,
<LS_SIGNEDDATA> TYPE ANY.
*&---------------------------------------------------------------------*
*& INPUT VALIDATION for IT_CV
*&---------------------------------------------------------------------*
CALL METHOD ZBPC_CL_GET_DIMENSION_MEMBER=>READ_CV_DATA
EXPORTING
IT_CV = IT_CV
IMPORTING
ET_CYCLE = LT_CYCLE
ET_CATEGORY = LT_CATEGORY
ET_ENTITY = LT_ENTITY
ET_TIME = LT_TIME.
"Category
LOOP AT LT_CATEGORY TRANSPORTING NO FIELDS
WHERE ID EQ 'Actual'.
** Raise exception
LD_LOG = 'Input Actual Category is not allowed'.
CL_UJK_LOGGER=>LOG( I_OBJECT = LD_LOG ).
RAISE EXCEPTION TYPE CX_UJ_CUSTOM_LOGIC.
ENDLOOP.
"Cycle
IF LT_CYCLE[] IS INITIAL.
** Raise exception
LD_LOG = 'Please input one CYCLE'.
CL_UJK_LOGGER=>LOG( I_OBJECT = LD_LOG ).
RAISE EXCEPTION TYPE CX_UJ_CUSTOM_LOGIC.
ELSE.
READ TABLE LT_CYCLE ASSIGNING <LS_CYCLE> INDEX 2.
IF SY-SUBRC EQ 0.
** Raise exception
LD_LOG = 'Please input one CYCLE'.
CL_UJK_LOGGER=>LOG( I_OBJECT = LD_LOG ).
RAISE EXCEPTION TYPE CX_UJ_CUSTOM_LOGIC.
ENDIF.
ENDIF.
*&---------------------------------------------------------------------*
*& GET MODEL FROM CT_DATA
*&---------------------------------------------------------------------*
BREAK-POINT.
CALL METHOD ZBPC_CL_BADI=>TRANSFORM_CT_DATA
EXPORTING
IT_DATA = CT_DATA
IMPORTING
ET_DATA_MODEL = LT_SOURCE.
DEFINE MC_SELECTION_DIM.
CLEAR &1.
&1-sign = 'I'.
&1-option = 'EQ'.
&1-low = &2.
&1-dimension = &3.
APPEND &1 to &4.
END-OF-DEFINITION.
*&---------------------------------------------------------------------*
*& WRITE DATA TO OPEX MODEL
*&---------------------------------------------------------------------*
"Zero-ing target model according input parameter
CLEAR: LT_SELECTION_DIM.
LOOP AT IT_CV INTO LX_CV
WHERE USER_SPECIFIED = 'X'.
LT_MEMBER = LX_CV-MEMBER.
LOOP AT LT_MEMBER INTO LX_MEMBER.
MC_SELECTION_DIM LX_SELECTION_DIM
LX_MEMBER LX_CV-DIMENSION LT_SELECTION_DIM.
ENDLOOP.
ENDLOOP.
MC_SELECTION_DIM LX_SELECTION_DIM 'Cash'
'AUDITTRAIL' LT_SELECTION_DIM.
CALL METHOD ZBPC_CL_GET_MODEL_RECORD=>FETCH2
EXPORTING
I_APPSET_ID = I_APPSET_ID
I_APPL_ID = 'Opex'
IT_SELECTION = LT_SELECTION_DIM
IMPORTING
ER_DATA = LR_DATA.
ASSIGN LR_DATA->* TO <LT_RECORD_DEL>.
LOOP AT <LT_RECORD_DEL> ASSIGNING <LS_RECORD_DEL>.
ASSIGN COMPONENT 'SIGNEDDATA'
OF STRUCTURE <LS_RECORD_DEL> TO <LS_SIGNEDDATA>.
<LS_SIGNEDDATA> = 0.
MOVE-CORRESPONDING <LS_RECORD_DEL> TO LX_OPEX_RATE.
COLLECT LX_OPEX_RATE INTO LT_OPEX_RATE.
ENDLOOP.
CALL METHOD ZBPC_CL_BADI=>WRITE_BACK
EXPORTING
I_APPSET_ID = I_APPSET_ID
I_APPL_ID = 'Opex'
IT_RECORD = LT_OPEX
IT_RECORD_DEL = <LT_RECORD_DEL>
IMPORTING
ES_WB_STATUS = LS_WB_STATUS
ET_MESSAGE = LT_MESSAGES.
*&---------------------------------------------------------------------*
*& FINAL
*&---------------------------------------------------------------------*
** Overwrite callback
IF <LT_FINAL> IS INITIAL.
** Raise exception
CLEAR: CT_DATA.
LD_LOG = 'No final data to be processed'.
CL_UJK_LOGGER=>LOG( I_OBJECT = LD_LOG ).
RAISE EXCEPTION TYPE CX_UJ_CUSTOM_LOGIC.
EXIT.
ELSE.
CT_DATA[] = <LT_FINAL>.
ENDIF.