Financial Management Blogs by Members
Dive into a treasure trove of SAP financial management wisdom shared by a vibrant community of bloggers. Submit a blog post of your own to share knowledge.
cancel
Showing results for 
Search instead for 
Did you mean: 
former_member186338
Active Contributor
2,043
It's a common requirement to run some DM package each month with the current month selected as TIME dimension member. It can be done with a modified code of UJD_TEST_PACKAGE. You have to generate answer prompt with correct month selected as TIME dimension member ID.

The following code will run Clear package using month ID generated from SY-DATUM:
REPORT  ZUJD_TEST_PACKAGE.

DATA: LF_EXISTS TYPE UJ_FLG,
LF_DEBUG TYPE UJ_FLG,
LF_SCHEDULE TYPE UJ_FLG,
L_ERRORMSG TYPE UJ_STRING,
L_RESULT TYPE UJ_STRING,
L_STATUS_STR TYPE UJ_STRING,
L_LOG_CONTENT TYPE UJ_STRING,
L_LOG_FILE TYPE UJF_DOC-DOCNAME,
L_INSTANCE_ID TYPE RSPC_LOGID,
L_LOG_XCONTENT TYPE UJF_DOC-DOC_CONTENT,

LS_PACKAGE_STATUS TYPE UJD_STATUS,
LS_USER TYPE UJ0_S_USER,
LS_SCHEDULE_INFO TYPE UJD_S_SCHEDULE_INFO,
LS_SCHEDULE_INFO2 TYPE UJD_S_SCHEDULE_INFO2,
LTH_ANSWER_PROMPT TYPE UJD_TH_VALUE,
LS_ANSWER_PROMPT LIKE LINE OF LTH_ANSWER_PROMPT,
LT_MESSAGE TYPE UJ0_T_MESSAGE,

LO_FILE_MGR TYPE REF TO CL_UJF_FILE_SERVICE_MGR,
LO_CONTEXT TYPE REF TO IF_UJ_CONTEXT,
LO_PACKAGE TYPE REF TO CL_UJD_PACKAGE,
L_OX TYPE REF TO CX_ROOT,

LF_RAISE_MSG TYPE UJ_FLG VALUE ABAP_FALSE,
LT_LOG TYPE STRING_TABLE,
L_LOG TYPE STRING,
LV_BPCPERIOD(7) TYPE C,

LF_IF_SYNC TYPE UJ_BOOL,
L_USER TYPE UJ_USER_ID,
L_PACKAGE TYPE UJ_PACKAGE_ID,
L_APPSET TYPE UJ_APPSET_ID,
L_APPL TYPE UJ_APPL_ID,
L_TEAM TYPE UJ_TEAM_ID,
L_GROUP TYPE UJ_PACK_GRP_ID,
L_SCHEDULE TYPE STRING,
L_MEMBERS TYPE STRING,
LF_IF_MSG TYPE UJ_BOOL.

LF_IF_SYNC = UJ00_CS_BOOL-YES.
L_USER = 'SUPPORT_EXT'.
L_PACKAGE = 'Clear'.
L_APPSET = 'SHELLTEST'.
L_APPL = 'Planning'.
L_TEAM = ''. "Team Company is empty
L_GROUP = 'Data Management'.
L_SCHEDULE = '<SCHEDULING><IMMEDIATE>Y</IMMEDIATE><STATE>0</STATE><PERIOD>N</PERIOD></SCHEDULING>'. "end frp270312
LF_IF_MSG = UJ00_CS_BOOL-NO.
L_MEMBERS = '/SHELLTEST/Planning/PRIVATEPUBLICATIONS/SUPPORT_EXT/TempFiles/FROM.TMP@@@SAVE@@@@@@EXPAND@@@|DIMENSION:ACCOUNT|PL110|DIMENSION:AUDITTRAIL|Input|' &&
'DIMENSION:CATEGORY|Budget|DIMENSION:ENTITY|DE|DIMENSION:INTERCO|ThirdParty|DIMENSION:PRODUCT|ProductA|DIMENSION:RPTCURRENCY|LC|DIMENSION:TIME|'.

LV_BPCPERIOD = SY-DATUM(4) && '.' && SY-DATUM+4(2). "Convert system date to BPC period YYYY.MM

LS_ANSWER_PROMPT-FIELDNAME = '%SELECTION%'.
LS_ANSWER_PROMPT-VALUE = L_MEMBERS && LV_BPCPERIOD.
INSERT LS_ANSWER_PROMPT INTO TABLE LTH_ANSWER_PROMPT.
LS_ANSWER_PROMPT-FIELDNAME = '%SELECTION_KEYDATE%'.
LS_ANSWER_PROMPT-VALUE = ''.
INSERT LS_ANSWER_PROMPT INTO TABLE LTH_ANSWER_PROMPT.
LS_ANSWER_PROMPT-FIELDNAME = '%ENABLETASK%'.
LS_ANSWER_PROMPT-VALUE = '1'.
INSERT LS_ANSWER_PROMPT INTO TABLE LTH_ANSWER_PROMPT.
LS_ANSWER_PROMPT-FIELDNAME = '%CHECKLCK%'.
LS_ANSWER_PROMPT-VALUE = '1'.
INSERT LS_ANSWER_PROMPT INTO TABLE LTH_ANSWER_PROMPT.

LS_USER-USER_ID = L_USER.

CALL METHOD CL_UJ_CONTEXT=>SET_CUR_CONTEXT
EXPORTING
I_APPSET_ID = L_APPSET
IS_USER = LS_USER
I_APPL_ID = L_APPL.

IF LF_IF_SYNC = UJ00_CS_BOOL-YES.
LF_DEBUG = ABAP_TRUE.
ELSE.
LF_DEBUG = ABAP_FALSE.
ENDIF.

TRY.

CL_UJD_SCHEDULE_PARSE=>PARSE_7X_FORMAT( EXPORTING I_SCHEDULE_STR = L_SCHEDULE
IMPORTING ES_SCHEDULE_INFO = LS_SCHEDULE_INFO
ES_SCHEDULE_INFO_NEW = LS_SCHEDULE_INFO2 ).
IF LS_SCHEDULE_INFO-IFIMMEDIATE = UJ00_CS_BOOL-YES.
LF_SCHEDULE = ABAP_FALSE.
ELSE.
LF_SCHEDULE = ABAP_TRUE.
LS_SCHEDULE_INFO2-MODULE_ID = UJD0_CS_MODULE_ID-PACKAGE.
ENDIF.

CREATE OBJECT LO_PACKAGE.

CALL METHOD LO_PACKAGE->RUN_PACKAGE
EXPORTING
I_APPSET_ID = L_APPSET
I_APPL_ID = L_APPL
I_TEAM_ID = L_TEAM
I_GROUP_ID = L_GROUP
I_PACKAGE_ID = L_PACKAGE
ITH_ANSWER_PROMPT = LTH_ANSWER_PROMPT
IS_SCHEDULE_INFO = LS_SCHEDULE_INFO2
IF_SCHEDULE = LF_SCHEDULE
IF_DEBUG = LF_DEBUG.

cl_uja_actvty_mgr=>record_logon_activity(
exporting
i_appset_id = L_APPSET
i_activity = cl_uja_actvty_mgr=>gc_act_report_ujd_test_package ).

CATCH CX_ROOT INTO L_OX. "#EC CATCH_ALL
CALL FUNCTION 'UJ0_CONV_EX2MSG'
EXPORTING
IO_EXCEPTION = L_OX
IMPORTING
ET_MESSAGE_LINES = LT_MESSAGE.

CALL FUNCTION 'UJ0_CONV_MSG2STR'
EXPORTING
IT_MSG = LT_MESSAGE
IMPORTING
E_STR = L_ERRORMSG.

CALL FUNCTION 'DB_ROLLBACK'.
RETURN.
ENDTRY.
CALL FUNCTION 'DB_COMMIT'.

IF L_ERRORMSG IS NOT INITIAL.
WRITE:/ L_ERRORMSG.
ELSE.
WRITE:/ L_RESULT.
ENDIF.

TRY.
CL_UJD_PACKAGE_CONTEXT=>GET_INSTANCE_ID(
IMPORTING E_INSTANCE_ID = L_INSTANCE_ID ).

CL_UJD_PACKAGE_STATUS_DAO=>GET_PACKAGE_STATUS(
EXPORTING I_LOG_ID = L_INSTANCE_ID
IMPORTING ES_PACKAGE_STATUS = LS_PACKAGE_STATUS ).

CASE LS_PACKAGE_STATUS-STATUS.
WHEN UJD0_CS_PACKAGE_STATUS-EXCUTE OR
UJD0_CS_PACKAGE_STATUS-SUCCEED.
L_STATUS_STR = 'Success'. "#EC NOTEXT
WHEN UJD0_CS_PACKAGE_STATUS-WARNING.
L_STATUS_STR = 'Warning'. "#EC NOTEXT
WHEN UJD0_CS_PACKAGE_STATUS-FAILED.
L_STATUS_STR = 'Error'. "#EC NOTEXT
LF_RAISE_MSG = ABAP_TRUE.
WHEN OTHERS.
L_STATUS_STR = 'Cancel'. "#EC NOTEXT
LF_RAISE_MSG = ABAP_TRUE.
ENDCASE.

CONCATENATE 'Package status =>' L_STATUS_STR INTO L_STATUS_STR.
"#EC NOTEXT
WRITE:/ L_STATUS_STR.

L_LOG_FILE = LS_PACKAGE_STATUS-LOG_FILE.
IF L_LOG_FILE IS INITIAL.
RETURN.
ENDIF.

LO_CONTEXT = CL_UJ_CONTEXT=>GET_CUR_CONTEXT( ).

CONCATENATE UJ00_C_WEB_ROOT LO_CONTEXT->D_APPSET_ID
UJD0_CS_FILE_PATH_SLASH LO_CONTEXT->D_APPL_ID
UJD0_CS_FILE_PATH_SLASH UJ00_C_PRIV_PUBLICATION
UJD0_CS_FILE_PATH_SLASH LO_CONTEXT->DS_USER-USER_ID
UJD0_CS_FILE_PATH_SLASH UJ00_C_TEMPFILES
UJD0_CS_FILE_PATH_SLASH L_LOG_FILE INTO L_LOG_FILE.

LO_FILE_MGR = CL_UJF_FILE_SERVICE_MGR=>FACTORY(
IS_USER = LO_CONTEXT->DS_USER
I_APPSET = LO_CONTEXT->D_APPSET_ID ).

TRY.
LO_FILE_MGR->CHECK_DOCUMENT_EXIST(
EXPORTING I_DOCNAME = L_LOG_FILE
IMPORTING E_RESULT = LF_EXISTS ).
CATCH CX_UJF_FILE_SERVICE_ERROR.
RETURN.
ENDTRY.

IF LF_EXISTS = ABAP_TRUE.
LO_FILE_MGR->GET_DOCUMENT(
EXPORTING I_DOCNAME = L_LOG_FILE
I_RETZIP = ABAP_FALSE
IMPORTING E_DOCUMENT_CONTENT = L_LOG_XCONTENT ).

L_LOG_CONTENT = CL_UJ_UTL_CONV=>XSTRING_TO_STRING( I_XSTR = L_LOG_XCONTENT ).

"WRITE:/ L_LOG_CONTENT.
REPLACE ALL OCCURRENCES OF '&lt;' IN L_LOG_CONTENT WITH '<'.
REPLACE ALL OCCURRENCES OF '&gt;' IN L_LOG_CONTENT WITH '>'.
SPLIT L_LOG_CONTENT AT CL_ABAP_CHAR_UTILITIES=>CR_LF INTO TABLE LT_LOG.
LOOP AT LT_LOG INTO L_LOG.
WRITE:/ L_LOG.
ENDLOOP.
ENDIF.

CATCH CX_ROOT. "#EC CATCH_ALL
LF_RAISE_MSG = ABAP_TRUE.
ENDTRY.
IF LF_IF_SYNC = UJ00_CS_BOOL-YES AND LF_IF_MSG = UJ00_CS_BOOL-YES AND LF_RAISE_MSG = ABAP_TRUE.
MESSAGE A001(00) ##MG_MISSING
WITH 'Package Failed'. "#EC NOTEXT
ENDIF.

Result of execution:

Before running:



Current date is 2018.11.24

After running:



DM log:



Result in SAP GUI:



The chain for ZUJD_TEST_PACKAGE can be created and scheduled.

P.S. The same approach can be used to read base members of some parent or members with some property for each DM package launch (useful when new members are added). You select members in ABAP code and pass the list of members to DM prompt.

Questions? Comments?
Labels in this area