cancel
Showing results for 
Search instead for 
Did you mean: 

Trigger alert from a MACRO BADI

former_member196299
Active Contributor
0 Kudos

Hi All ,

    We have a requirement where in we need to trigger alerts from inside a MACRO BADI in one of the data views of a DP Planning Book .

    I tried to search in SDN for the same but did not get any appripriate answer for my query . Can anyone share some info on this ?

Regards,

Ranjita

Accepted Solutions (0)

Answers (1)

Answers (1)

rajkj
Active Contributor
0 Kudos

Hi Ranjita,

As explained in the thread http://scn.sap.com/thread/1211321, you can refer the function module /SAPAPO/ADV_ALERT_SET to transfer the alert to AMON.

Pl check the following code snippet (generated for an alert). The highlighted portion at last shows how to call the above function module. The rest of the program represent the std macro lines shown in the graphic below.

*&---------------------------------------------------------------------*
*&      Form  43ZJJZ4BZ16D0PZPF343AXRP0
*&---------------------------------------------------------------------*
*       #TR# Generated Form Routine for Macro
*       Macro ID  : 43ZJJR0FYI9FCXGN9CN4OV4HG
*       Macro Name: Projected Wastage Quantity (DB Alert)
*----------------------------------------------------------------------*
*      -->I_VRSIOID             Planning Version
*      -->I_S_ADV_OPTIONS       Macro Options
*      -->I_S_JOB_OPTIONS       Job Options
*      -->I_S_CLP_OPTIONS       Collaborative Planning Options
*      -->I_T_LINES             Lines (GT_LINES from Interactive Planning)
*      -->I_T_COLS              Columns (GT_COLS from Interactive Planning)
*      -->I_T_ADV_PLOB_VALUES   (Macro) Planning Objects derived from GT_PLOB_VALUES
*      -->I_T_ADV_LINES_OFFSET  (Macro) Offsets
*      -->I_T_DRILL_PATH        Drill-Down Path
*      -->I_T_GROUP_BY          Group-By
*      <--C_T_TAB               TAB (GT_TAB from Interactive Planning)
*      <--C_T_TAB_OLD           TAB_OLD (GT_TAB_OLD from Interactive Planning)
*      <--C_S_ACTVIEW           ACTVIEW (GS_ACTVIEW from Interactive Planning)
*      <--C_S_RESULT_OPTIONS    Macro result options
*----------------------------------------------------------------------*
form 43ZJJZ4BZ16D0PZPF343AXRP0
   using    i_vrsioid            type /SAPAPO/VRSIOID
            i_s_adv_options      type /SAPAPO/ADV_OPTIONS
            i_s_job_options      type /SAPAPO/ADV_JOB_OPTIONS
            i_s_clp_options      type /SAPAPO/ADV_CLP_OPTIONS
            i_t_lines            type /SAPAPO/MSDP_APP_LINES_TAB
            i_t_cols             type /SAPAPO/MSDP_APP_COLS_TAB
            i_t_adv_plob_values  type /SAPAPO/DM_T_PLOB_VALUES
            i_t_adv_lines_offset type /SAPAPO/OFFSETS_ADV_MACRO_TAB
            i_t_drill_path       type /SAPAPO/MSDP_DRILL_PATH_TAB
            i_t_group_by         type /SAPAPO/TS_GROUP_BY_TAB
   changing c_t_tab              type /SAPAPO/MSDP_APP_TAB_TAB
            c_t_tab_old          type /SAPAPO/MSDP_APP_TAB_TAB
            c_s_actview          type /SAPAPO/PB_ACT_VIEW_STR
            c_s_result_options   type /SAPAPO/ADV_RESULT_OPTION
   raising  /sapapo/cx_advx.


*&---------------------------------------------------------------------*
*& #TR# (M.1) Macro Debugging
*&---------------------------------------------------------------------*
   if g_s_advx_debug_flags-dbg_macro_off = abap_false.
     break-point id /SAPAPO/ADV__EXECUTION_DEBUG.
   endif.


*&---------------------------------------------------------------------*
*& #TR# (M.3) Data Declarations for macro coding
*&---------------------------------------------------------------------*
   constants:
     l_c_adv_alerts_text   type /SAPAPO/TXTLG value 'GENERATED FOR MACROALERTS',
     l_c_dummy_column_from type /SAPAPO/FINDEX value is initial,
     l_c_dummy_column_to   type /SAPAPO/TINDEX value is initial.

   data:
     l_vrsioid                type /SAPAPO/VRSIOID,
     l_s_adv_options          type /SAPAPO/ADV_OPTIONS,
     l_tmp_value              type /SAPAPO/MXVAL,
     l_hlp_tabix              type sytabix,
     l_calc_line              type sytabix,
     l_adv_alert_selid        type /SAPAPO/SELECTIONID2,
     l_adv_alert_selid_grid2  type /SAPAPO/SELECTIONID2,
     l_s_adv_plob_values2     like line of i_t_adv_plob_values,
     l_s_areako               type /SAPAPO/TS_AREAKO_STR,

     l_t_selection            type table of /SAPAPO/DM_INT_SELECTION,
     l_s_selection            like line of l_t_selection,
     l_t_selection_grid2      type table of /SAPAPO/DM_INT_SELECTION,

     l_s_lines_aux            type /SAPAPO/ADV_S_LINES_AUX,

     l_line_index_from        type i,
     l_line_index_to          type i,
     l_lines_times            type i,
     l_lines                  type i,
     l_tr_lines               type range of /SAPAPO/MXROW,
     l_sr_lines               like line of l_tr_lines,
     l_s_lines                like line of i_t_lines,
     l_s_adv_line_index       like line of g_t_adv_line_index,
     l_cols_times             type i,
     l_cols_counter           type i,
     l_tr_cols                type range of /SAPAPO/MXCOL,
     l_sr_cols                like line of l_tr_cols,
     l_s_cols                 like line of i_t_cols,

     l_s_fun_para             type /SAPAPO/ADV_PARA,
     l_s_alerts               type /SAPAPO/SDEMAND_PLANNING_ALERT,
     l_s_value_tab            type /SAPAPO/VALUE_TAB,
     l_t_value_tab            like table of l_s_value_tab,
     l_s_batch_message        type g_ty_s_batch_message,
     l_step_missing_values    type /SAPAPO/V_MISSING,              "Treatment when values are missing (see macro step definition)
     l_flg_cancel_calculation type /SAPAPO/FLAG,                   "Flag: Cancel calculation if values are missing
     l_advx_cols_left_border  type i,
     l_advx_cols_right_border type i,

     l_flg_advg_if            type /SAPAPO/FLAG,                   "Flag for generating IF...ELSEIF...ELSE...ENDIF macro statements

     l_t_adv_plob_values      type /SAPAPO/DM_T_PLOB_VALUES,       "Copy of I_T_ADV_PLOB_VALUES, needed to drill down/up
     l_t_adv_lines_offset     type /SAPAPO/OFFSETS_ADV_MACRO_TAB,  "Copy of I_T_ADV_LINES_OFFSET, needed to drill down/up

     l_o_advx_tab_access      type ref to lcl_advx_tab_access.     "Note 1026778: Access class to TAB

   field-symbols:
     <fs_s_adv_lines_offset> like line of i_t_adv_lines_offset,
     <fs_s_adv_plob_values>  like line of i_t_adv_plob_values,
     <fs_s_selection>        type /SAPAPO/DM_INT_SELECTION,
     <fs_s_adv_line_index>   like line of g_t_adv_line_index,
     <fs_s_cols>             like line of i_t_cols.

*#TR# Data Fields that correspond to macro functions and thus may not be changed or renamed
   data:
     act_plob       type /SAPAPO/PLOBJ,
     act_plob_grid2 type /SAPAPO/PLOBJ.


*#TR# (M.3.1) Dynamic Data Declaration for variables used to save grid values (e. g. if planning grid macro elements
*#TR# are used in a macro string)


*&---------------------------------------------------------------------*
*& #TR# (M.4) Initialize macro execution
*&---------------------------------------------------------------------*
*#TR# (M.4.1) We are not using I_S_ADV_OPTIONS but L_S_ADV_OPTIONS within this macro as some options may be temporarily
*#TR# overruled
   l_s_adv_options = i_s_adv_options.
*#TR# Check, if a dynamic alert is used withing this macro. If yes, set the flag L_S_ADV_OPTIONS-FLG_DYNAMIC to true.

*#TR# (M.4.2) Get Locking Flag G_FLG_KEYFS_LOCK_RO if planning area has changed
   if g_buf_pareaid <> g_c_pareaid.
     g_buf_pareaid = g_c_pareaid.

     call function '/SAPAPO/TS_PAREA_SINGLE_GET'
       exporting
         iv_pareaid = g_c_pareaid
       importing
         es_areako  = l_s_areako
       exceptions
         not_found  = 1
         others     = 2.
     assert id /SAPAPO/ADV__EXECUTION condition sy-subrc = 0.

     g_flg_keyfs_lock_ro = l_s_areako-keyfs_lock_ro.
   endif.

   perform get_flg_show_trans in program /SAPAPO/SAPLMSDP_SDP changing g_flg_show_trans.

*#TR# (M.4.3) Get user parameters
*#TR# User parameter /SAPAPO/ADV_CHK_FIX controls the error handling
*#TR# when a macro changes a fixed value
*#TR#  not set / 'A' : All checks and information popups are enabled
*#TR#  '0'           : Disable all checks and popups
*#TR#  '1'           : Disable all popups
   if g_user_parm_adv_chk_fix is initial.
     get parameter id '/SAPAPO/ADV_CHK_FIX' field g_user_parm_adv_chk_fix.
     if g_user_parm_adv_chk_fix is initial. g_user_parm_adv_chk_fix = gs_c_user_parm_adv_chk_fix-all_chks_on. endif.
   endif.

*#TR# (M.4.4) Set the global fields of structure G_S_COLS_PROPERTIES
   if sy-batch is initial. g_gui_infos_read = true. endif.
   if g_fun_buffer_clear = true. clear g_fun_buffer_clear. call function '/SAPAPO/FUN_BUFFERS_CLEAR'. endif.

   if sy-batch = true and g_flg_batch_initialized is initial.
*#TR# (M.4.4a) Set Flag G_FLG_BATCH_INITIALIZED and clear buffers with function module /SAPAPO/BUFFERS_ENTRIES_BATCH
*#TR# only in batch mode
     g_flg_batch_initialized = true. call function '/SAPAPO/BUFFERS_ENTRIES_BATCH'.
   endif.

   g_s_cols_properties-index_last_entry = lines( i_t_cols ).

   read table i_t_cols into l_s_cols index g_s_cols_properties-index_last_entry transporting column.
   if sy-subrc = 0. g_s_cols_properties-right_column = l_s_cols-column. endif.

   read table i_t_cols into l_s_cols index 1 transporting column.
   if sy-subrc = 0. g_s_cols_properties-left_column = l_s_cols-column. endif.

   read table i_t_cols into l_s_cols with key firstfuture = true transporting column.
   if sy-subrc <> 0. break-point id /SAPAPO/ADV__EXECUTION.
     g_s_cols_properties-right_history_column = g_s_cols_properties-right_column. g_s_cols_properties-index_last_history_entry = g_s_cols_properties-index_last_entry.
     g_s_cols_properties-left_future_column = g_s_cols_properties-right_column + 1.
   else.
     g_s_cols_properties-left_future_column = l_s_cols-column.
     g_s_cols_properties-index_last_history_entry = sy-tabix - 1.
     if g_s_cols_properties-index_last_history_entry > 0.
       read table i_t_cols into l_s_cols index g_s_cols_properties-index_last_history_entry transporting column.
       g_s_cols_properties-right_history_column = l_s_cols-column.
     else.
       clear: g_s_cols_properties-index_last_history_entry, g_s_cols_properties-right_history_column.
     endif.
   endif.

   loop at i_t_cols assigning <fs_s_cols> where readonly <> '1'.
     g_s_cols_properties-first_input_column = <fs_s_cols>-column. exit.
   endloop.

   read table i_t_cols with key tstfr = gc_mintime into l_s_cols transporting column.
   if sy-subrc = 0.
     g_s_cols_properties-initial_column = l_s_cols-column.
   endif.

*#TR# (M.4.5) Set the (macro) line index table that contains only the key figures of the grid
   if g_repid is initial.
     g_repid = sy-repid.
     l_s_adv_line_index-line = 7. append l_s_adv_line_index to g_t_adv_line_index.
     l_s_adv_line_index-line = 1. append l_s_adv_line_index to g_t_adv_line_index.
     l_s_adv_line_index-line = 18. append l_s_adv_line_index to g_t_adv_line_index.
     l_s_adv_line_index-line = 52. append l_s_adv_line_index to g_t_adv_line_index.
     l_s_adv_line_index-line = 11. append l_s_adv_line_index to g_t_adv_line_index.
     l_s_adv_line_index-line = 8. append l_s_adv_line_index to g_t_adv_line_index.
     l_s_adv_line_index-line = 16. append l_s_adv_line_index to g_t_adv_line_index.
     l_s_adv_line_index-line = 19. append l_s_adv_line_index to g_t_adv_line_index.
     l_s_adv_line_index-line = 54. append l_s_adv_line_index to g_t_adv_line_index.
     l_s_adv_line_index-line = 36. append l_s_adv_line_index to g_t_adv_line_index.
     l_s_adv_line_index-line = 21. append l_s_adv_line_index to g_t_adv_line_index.
     l_s_adv_line_index-line = 46. append l_s_adv_line_index to g_t_adv_line_index.
     l_s_adv_line_index-line = 31. append l_s_adv_line_index to g_t_adv_line_index.
     l_s_adv_line_index-line = 34. append l_s_adv_line_index to g_t_adv_line_index.
     l_s_adv_line_index-line = 20. append l_s_adv_line_index to g_t_adv_line_index.
     l_s_adv_line_index-line = 32. append l_s_adv_line_index to g_t_adv_line_index.
     l_s_adv_line_index-line = 63. append l_s_adv_line_index to g_t_adv_line_index.
     l_s_adv_line_index-line = 67. append l_s_adv_line_index to g_t_adv_line_index.
     l_s_adv_line_index-line = 68. append l_s_adv_line_index to g_t_adv_line_index.
     l_s_adv_line_index-line = 48. append l_s_adv_line_index to g_t_adv_line_index.
     l_s_adv_line_index-line = 82. append l_s_adv_line_index to g_t_adv_line_index.
     l_s_adv_line_index-line = 93. append l_s_adv_line_index to g_t_adv_line_index.
     l_s_adv_line_index-line = 94. append l_s_adv_line_index to g_t_adv_line_index.
     l_s_adv_line_index-line = 96. append l_s_adv_line_index to g_t_adv_line_index.
     l_s_adv_line_index-line = 95. append l_s_adv_line_index to g_t_adv_line_index.
     l_s_adv_line_index-line = 66. append l_s_adv_line_index to g_t_adv_line_index.
     l_s_adv_line_index-line = 64. append l_s_adv_line_index to g_t_adv_line_index.
     l_s_adv_line_index-line = 76. append l_s_adv_line_index to g_t_adv_line_index.
     l_s_adv_line_index-line = 58. append l_s_adv_line_index to g_t_adv_line_index.
     l_s_adv_line_index-line = 51. append l_s_adv_line_index to g_t_adv_line_index.
     l_s_adv_line_index-line = 59. append l_s_adv_line_index to g_t_adv_line_index.
     l_s_adv_line_index-line = 3. append l_s_adv_line_index to g_t_adv_line_index.
     l_s_adv_line_index-line = 2. append l_s_adv_line_index to g_t_adv_line_index.
     l_s_adv_line_index-line = 83. append l_s_adv_line_index to g_t_adv_line_index.
     l_s_adv_line_index-line = 85. append l_s_adv_line_index to g_t_adv_line_index.
     l_s_adv_line_index-line = 86. append l_s_adv_line_index to g_t_adv_line_index.
     l_s_adv_line_index-line = 97. append l_s_adv_line_index to g_t_adv_line_index.
     l_s_adv_line_index-line = 98. append l_s_adv_line_index to g_t_adv_line_index.
*#TR# (M.4.5a) If key figure specific locking logic is activated and read only key figures are not locked, we have
*#TR# to set the READONLY field to indicate, if the key figure has been set to read only in design mode
*#TR# We also add information, if the key figure is fixable or not
     loop at g_t_adv_line_index assigning <fs_s_adv_line_index>.
       if <fs_s_adv_line_index>-line >= gs_c_grid2_lines-start and <fs_s_adv_line_index>-line <= gs_c_grid2_lines-end.
         l_calc_line = <fs_s_adv_line_index>-line - gs_c_grid2_lines-start.
       else.
         l_calc_line = <fs_s_adv_line_index>-line.
       endif.
       read table i_t_lines with key line = l_calc_line into l_s_lines transporting readonly fix_zeros calc_init_flags neg_not_allowed keyfigure_type.
       assert id /SAPAPO/ADV__EXECUTION condition sy-subrc = 0.
       if l_s_lines-readonly = gc_lines_readonly_initial. <fs_s_adv_line_index>-readonly = l_s_lines-readonly. endif.
       <fs_s_adv_line_index>-fix_zeros       = l_s_lines-fix_zeros.
       <fs_s_adv_line_index>-calc_init_flags = l_s_lines-calc_init_flags.
       <fs_s_adv_line_index>-neg_not_allowed = l_s_lines-neg_not_allowed.
       <fs_s_adv_line_index>-keyfigure_type  = l_s_lines-keyfigure_type.
     endloop.
   endif.

   if sy-batch = true.
     l_s_batch_message-msgid = g_c_adv_msg_class.
     l_s_batch_message-msgty = 'W'.
     l_s_batch_message-msgno = '100'.
   endif.

*#TR# (M.4.6) Set constants and variables in dependent function groups
   g_flg_seasonal_level = l_s_adv_options-seasonal_level.
   g_flg_tb_changed     = l_s_adv_options-tb_changed.
   perform advx_set_global_fields using g_c_pareaid '1' g_flg_show_trans g_flg_keyfs_lock_ro g_flg_seasonal_level l_s_adv_options-enterprise_service g_s_cols_properties.

*#TR# (M.4.7) Clear all Flags G_S_ADVX_ERROR_FLAGS, G_FLG_VALUE_FIXED, G_FLG_INITIAL_SET, G_FLG_REDISAGG_SET
   clear g_s_advx_error_flags.
   perform advx_clear_global_flags.

   clear: g_flg_value_fixed, g_flg_initial_set, g_flg_redisagg_set.

*#TR# (M.4.8) Clear global Flags to overrule macro step definition always at macro startup
   clear: g_stop_column, g_start_column, g_end_column.


*#TR# (M.4.10) Copy the import parameters I_T_ADV_PLOB_VALUES and I_T_ADV_LINES_OFFSET to the corresponding local tables.
*#TR# We will then work on the local copies as the tables I_T_ADV_PLOB_VALUES and I_T_ADV_LINES_OFFSET might be changed
*#TR# during a drill-down or drill-up
   l_t_adv_plob_values  = i_t_adv_plob_values.
   l_t_adv_lines_offset = i_t_adv_lines_offset.

*#TR# (M.4.11) SCM 5.0 DP_009: Seasonality in Demand Planning
*#TR# It is not possible to execute macros containing macro steps with date related step intervall. Thus we need to
*#TR# check this and exit if necessary

*#TR# Check, if flag NO_EXEC_TB_CHA is set to prevent execution of macro, when time bucket profile was dynamically changed


*#TR# (M.4.12) Note 908800: Initialize fields SDP_BOOK and SDP_VIEW (supported only in compatibility mode)
   sdp_book = g_c_sdp_book.
   sdp_view = g_c_sdp_view.

*#TR# (M.4.13) Note 1026778: Instantiate access class to TAB
   create object l_o_advx_tab_access
     exporting
       i_flg_no_zero_values = 'X'
       i_flg_show_trans     = g_flg_show_trans
       i_flg_keyfs_lock_ro  = g_flg_keyfs_lock_ro.



*&---------------------------------------------------------------------*
*& #TR# (M.5) Macro execution: Process the planning objects
*&---------------------------------------------------------------------*
*#TR# In the macro definition we have defined, if the macro should be executed for "details only", "all planning objects"
*#TR# or for a certain level. Process the corresponding planning objects now

   clear l_hlp_tabix.

   loop at l_t_adv_lines_offset assigning <fs_s_adv_lines_offset> where flg_detail = true.
     check <fs_s_adv_lines_offset>-plobj = <fs_s_adv_lines_offset>-plobj2.

*#TR# (M.5.1) Initialize global fields for the processing of the current planning object
     add 1 to l_hlp_tabix.
     clear: g_act_product, g_act_location, g_act_resource, g_act_version,
       g_act_product2, g_act_location2, g_act_resource2, g_act_version2.

*#TR# (M.5.2) Determine selections and versions for first and second grid (if present)
*#TR# (M.5.2-a) Determine Selection of first grid
     read table l_t_adv_plob_values with key plobj = <fs_s_adv_lines_offset>-plobj assigning <fs_s_adv_plob_values>.
     if sy-subrc <> 0. break-point id /SAPAPO/ADV__EXECUTION. continue. endif.
     l_t_selection = <fs_s_adv_plob_values>-selection[].

*#TR# (M.5.2-b) If necessary, determine corresponding version
     read table l_t_selection assigning <fs_s_selection> with key iobjnm = gs_c_iobjnm-version.
     if sy-subrc <> 0.
       if i_vrsioid is not initial.
         l_s_selection-iobjnm = gs_c_iobjnm-version.
         l_s_selection-sign   = 'I'.
         l_s_selection-option = 'EQ'.
         l_s_selection-low    = i_vrsioid.
         append l_s_selection to l_t_selection.

         l_vrsioid = i_vrsioid.
       endif.
     else.
       l_vrsioid = <fs_s_selection>-low.
     endif.

     assert id /SAPAPO/ADV__EXECUTION condition l_vrsioid is not initial.
     perform version_to_vrsioex in program /SAPAPO/SAPLADV_GENER2 using l_vrsioid changing g_act_version.



*#TR# (M.5.3) Assign currently processed planning objects
     act_plob = <fs_s_adv_lines_offset>-plobj. act_plob_grid2 = <fs_s_adv_lines_offset>-plobj2.

*&---------------------------------------------------------------------*
*& #TR# (M.5.4) Macro execution: Alert-Handling
*&---------------------------------------------------------------------*

     clear: l_s_alerts, g_t_alerts.
     g_alert_step = 0.

*#TR# (M.5.4-a) Save selection and get selection ID
     call function '/SAPAPO/ADV_SAVE_SELECTION'
       exporting
         i_flg_used_for    = gs_c_sel_flg_used_for-macro_alerts
         i_txtlg           = l_c_adv_alerts_text
         i_planungsbereich = g_c_pareaid
         i_flg_dynamic     = l_s_adv_options-flg_dynamic
*        i_flg_locked      = l_s_adv_options-flg_locked "1248118
          i_flg_locked      = true                       "1248118
       importing
         e_selid           = l_adv_alert_selid
       tables
         t_i_selection     = l_t_selection.





*&---------------------------------------------------------------------*
*& #TR# (M.5.5) Macro execution: Macro Auxiliary Rows Handling
*&---------------------------------------------------------------------*

     clear g_t_lines_aux.
     clear l_s_lines_aux. l_s_lines_aux-line = 1. append l_s_lines_aux to g_t_lines_aux.
     clear l_s_lines_aux. l_s_lines_aux-line = 2. append l_s_lines_aux to g_t_lines_aux.
     clear l_s_lines_aux. l_s_lines_aux-line = 3. append l_s_lines_aux to g_t_lines_aux.
     clear l_s_lines_aux. l_s_lines_aux-line = 6. append l_s_lines_aux to g_t_lines_aux.
     clear l_s_lines_aux. l_s_lines_aux-line = 7. append l_s_lines_aux to g_t_lines_aux.
     clear l_s_lines_aux. l_s_lines_aux-line = 8. append l_s_lines_aux to g_t_lines_aux.
     clear l_s_lines_aux. l_s_lines_aux-line = 9. append l_s_lines_aux to g_t_lines_aux.
     clear l_s_lines_aux. l_s_lines_aux-line = 10. append l_s_lines_aux to g_t_lines_aux.
     clear l_s_lines_aux. l_s_lines_aux-line = 11. append l_s_lines_aux to g_t_lines_aux.
     clear l_s_lines_aux. l_s_lines_aux-line = 12. append l_s_lines_aux to g_t_lines_aux.
     clear l_s_lines_aux. l_s_lines_aux-line = 16. append l_s_lines_aux to g_t_lines_aux.


*&---------------------------------------------------------------------*
*& #TR# (M.5.6) Macro execution: Get values of planning grid elements
*&---------------------------------------------------------------------*


*&---------------------------------------------------------------------*
*& #TR# (M.5.7) Macro execution: Process Macro Step Elements
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& #TR# (M.5.8) Macro execution: Call Step Form Routine
*&---------------------------------------------------------------------*
     if sy-batch is initial and l_hlp_tabix = 1. g_gui_infos_read = true. endif.

     perform 43ZJJRFT0FGUE6JJL0RT8Z1X0                                *********************
Step Name : Determine Conversion Factor ******************
       using
         l_vrsioid
         l_s_adv_options
         i_s_job_options
         i_s_clp_options
         i_t_lines
         i_t_cols
         l_t_adv_plob_values
         g_t_adv_line_index
         l_t_adv_lines_offset
         <fs_s_adv_lines_offset>
         <fs_s_adv_plob_values>
         l_s_adv_plob_values2
         l_adv_alert_selid
         l_adv_alert_selid_grid2
         l_o_advx_tab_access
       changing
         c_t_tab
         c_t_tab_old
         c_s_actview
         c_s_result_options.

*&---------------------------------------------------------------------*
*& #TR# (M.5.8) Macro execution: Call Step Form Routine
*&---------------------------------------------------------------------*
     if sy-batch is initial and l_hlp_tabix = 1. g_gui_infos_read = true. endif.

     perform 43ZJJUFCDVWRMY3TUPOL5QJXW                               *********************
Step Name : Values in display unit ******************


       using
         l_vrsioid
         l_s_adv_options
         i_s_job_options
         i_s_clp_options
         i_t_lines
         i_t_cols
         l_t_adv_plob_values
         g_t_adv_line_index
         l_t_adv_lines_offset
         <fs_s_adv_lines_offset>
         <fs_s_adv_plob_values>
         l_s_adv_plob_values2
         l_adv_alert_selid
         l_adv_alert_selid_grid2
         l_o_advx_tab_access
       changing
         c_t_tab
         c_t_tab_old
         c_s_actview
         c_s_result_options.

*&---------------------------------------------------------------------*
*& #TR# (M.5.8) Macro execution: Call Step Form Routine
*&---------------------------------------------------------------------*
     if sy-batch is initial and l_hlp_tabix = 1. g_gui_infos_read = true. endif.

     perform 43ZJJTKMA1HXKFY17DF81IP2S    *********************
Step Name : Delete Existing alerts ******************


       using
         l_vrsioid
         l_s_adv_options
         i_s_job_options
         i_s_clp_options
         i_t_lines
         i_t_cols
         l_t_adv_plob_values
         g_t_adv_line_index
         l_t_adv_lines_offset
         <fs_s_adv_lines_offset>
         <fs_s_adv_plob_values>
         l_s_adv_plob_values2
         l_adv_alert_selid
         l_adv_alert_selid_grid2
         l_o_advx_tab_access
       changing
         c_t_tab
         c_t_tab_old
         c_s_actview
         c_s_result_options.

*&---------------------------------------------------------------------*
*& #TR# (M.5.8) Macro execution: Call Step Form Routine
*&---------------------------------------------------------------------*
     if sy-batch is initial and l_hlp_tabix = 1. g_gui_infos_read = true. endif.

     perform 43ZJJVX42M4Q9BVYZK4Z44AYC         *********************
Step Name : Write alerts ******************


       using
         l_vrsioid
         l_s_adv_options
         i_s_job_options
         i_s_clp_options
         i_t_lines
         i_t_cols
         l_t_adv_plob_values
         g_t_adv_line_index
         l_t_adv_lines_offset
         <fs_s_adv_lines_offset>
         <fs_s_adv_plob_values>
         l_s_adv_plob_values2
         l_adv_alert_selid
         l_adv_alert_selid_grid2
         l_o_advx_tab_access
       changing
         c_t_tab
         c_t_tab_old
         c_s_actview
         c_s_result_options.



*&---------------------------------------------------------------------*
*& #TR# (M.5.9) Macro execution: Alert-Handling
*&---------------------------------------------------------------------*
     if sy-batch = true.
       append lines of g_t_alerts to g_t_total_alerts.
       if c_s_result_options-combi_counter is initial or c_s_result_options-combi_counter >= 50
         or c_s_result_options-flg_alerts_send = true.
         c_s_result_options-combi_counter = 1.

         call function '/SAPAPO/ADV_ALERT_SET'
           exporting
             ct_alerts      = g_t_total_alerts

             iv_flg_locked  = l_s_adv_options-flg_locked
             iv_flg_dynamic = l_s_adv_options-flg_dynamic
             iv_planlayout  = '4RM7J08VB0E'
             iv_planview    = '92XDA6B9NXP'
             iv_makro       = '43ZJJR0FYI9FCXGN9CN4OV4HG'
             iv_selid       = l_adv_alert_selid
             iv_selid2      = l_adv_alert_selid_grid2
             iv_flg_async   = ' '.
         clear g_t_total_alerts.
       endif.
     else.
       call function '/SAPAPO/ADV_ALERT_SET'
         exporting
           ct_alerts      = g_t_alerts
           iv_flg_locked  = l_s_adv_options-flg_locked
           iv_flg_dynamic = l_s_adv_options-flg_dynamic
           iv_planlayout  = '4RM7J08VB0E'
           iv_planview    = '92XDA6B9NXP'
           iv_makro       = '43ZJJR0FYI9FCXGN9CN4OV4HG'
           iv_selid       = l_adv_alert_selid
           iv_selid2      = l_adv_alert_selid_grid2.
     endif.
     clear: l_s_alerts, g_t_alerts.
   endloop.

*&---------------------------------------------------------------------*
*&      Form  43ZJJVX42M4Q9BVYZK4Z44AYC
*&---------------------------------------------------------------------*
*       #TR# Generated Form Routine for Macro Step
*       Macro ID  : 43ZJJR0FYI9FCXGN9CN4OV4HG
*       Macro Name: Projected Wastage Quantity (DB Alert)
*       Step ID   : 43ZJJVPFJNJ0QPCITQ2MU2C8K
*       Step Name : Write Alerts
*----------------------------------------------------------------------*
*      -->I_VRSIOID               Planning Version
*      -->I_S_ADV_OPTIONS         Macro Options
*      -->I_S_JOB_OPTIONS         Job Options
*      -->I_S_CLP_OPTIONS         Collaborative Planning Options
*      -->I_T_LINES               Lines (GT_LINES from Interactive Planning)
*      -->I_T_COLS                Columns (GT_COLS from Interactive Planning)
*      -->I_T_ADV_PLOB_VALUES     (Macro) Planning Objects derived from GT_PLOB_VALUES
*      -->I_T_ADV_LINE_INDEX      (Macro) Lines, containing only the key figures
*      -->I_T_ADV_LINES_OFFSET    (Macro) Offsets
*      -->I_S_ADV_LINES_OFFSET
*      -->I_S_ADV_PLOB_VALUES2
*      -->I_ADV_ALERT_SELID
*      -->I_ADV_ALERT_SELID_GRID2
*      -->I_O_ADVX_TAB_ACCESS
*      <--C_T_TAB                 TAB (GT_TAB from Interactive Planning)
*      <--C_T_TAB_OLD             TAB_OLD (GT_TAB_OLD from Interactive Planning)
*      <--C_S_ACTVIEW             ACTVIEW (GS_ACTVIEW from Interactive Planning)
*      <--C_S_RESULT_OPTIONS      Macro result options
*----------------------------------------------------------------------*
form 43ZJJVX42M4Q9BVYZK4Z44AYC
   using    i_vrsioid               type /SAPAPO/VRSIOID
            i_s_adv_options         type /SAPAPO/ADV_OPTIONS
            i_s_job_options         type /SAPAPO/ADV_JOB_OPTIONS
            i_s_clp_options         type /SAPAPO/ADV_CLP_OPTIONS
            i_t_lines               type /SAPAPO/MSDP_APP_LINES_TAB
            i_t_cols                type /SAPAPO/MSDP_APP_COLS_TAB
            i_t_adv_plob_values     type /SAPAPO/DM_T_PLOB_VALUES
            i_t_adv_line_index      type /SAPAPO/MSDP_APP_LINES_TAB
            i_t_adv_lines_offset    type /SAPAPO/OFFSETS_ADV_MACRO_TAB
            i_s_adv_lines_offset    type /SAPAPO/OFFSETS_ADV_MACRO
            i_s_adv_plob_values     type /SAPAPO/DM_PLOB_VALUES
            i_s_adv_plob_values2    type /SAPAPO/DM_PLOB_VALUES
            i_adv_alert_selid       type /SAPAPO/SELECTIONID2
            i_adv_alert_selid_grid2 type /SAPAPO/SELECTIONID2
            i_o_advx_tab_access     type ref to lcl_advx_tab_access
   changing c_t_tab                 type /SAPAPO/MSDP_APP_TAB_TAB
            c_t_tab_old             type /SAPAPO/MSDP_APP_TAB_TAB
            c_s_actview             type /SAPAPO/PB_ACT_VIEW_STR
            c_s_result_options      type /SAPAPO/ADV_RESULT_OPTION
   raising  /sapapo/cx_advx.


   data:
     l_hlp_date_from          type dats,
     l_hlp_date_to            type dats,
     l_prev_index             type i,

     l_step_iterations        type i,
     l_step_counter           type i,
     l_loop_counter           type i,
     l_value                  type f,
     l_tmp_value              type f,
     l_calc_line              type i,
     l_tmp_calc_line          type f,
     l_tmp_act_column         type f,

     l_s_lines_aux            type /SAPAPO/ADV_S_LINES_AUX,

     l_s_adv_line_index       like line of i_t_adv_line_index,
     l_line_index_from        type i,
     l_line_index_to          type i,
     l_lines_times            type i,
     l_lines                  type i,
     l_tr_lines               type range of /SAPAPO/MXROW,
     l_sr_lines               like line of l_tr_lines,
     l_cols_times             type i,
     l_cols_counter           type i,
     l_tr_cols                type range of /SAPAPO/MXCOL,
     l_sr_cols                like line of l_tr_cols,
     l_s_cols                 like line of i_t_cols,
     l_s_special_results      type g_ty_s_special_results,
     l_t_special_results      like table of l_s_special_results,
     l_act_column_special     type i,
     l_index_for_read         type i,

     l_offset                 type i,
     l_gen_offset             type i,
     l_gen_offset_left        type i,
     l_gen_offset_right       type i,
     l_alert_text(160)        type c,
     l_s_alert_message        type g_ty_s_alert_message,
     l_message_text(160)      type c,
     l_msg_type               type /SAPAPO/MSG_TYPE,                "n 1331066
     l_tmp_string(160)        type c,
     l_tmp_string1(160)       type c,
     l_s_fun_para             type /SAPAPO/ADV_PARA,
     l_mail_argument          type /SAPAPO/FUNSTRING,
     l_s_mail_options         type /SAPAPO/ADV_S_SEND_DOC_MAILREC,
     l_s_doc_options          type /SAPAPO/ADV_S_SEND_DOC_SIG,
     l_debug_msg_line         type /SAPAPO/MSG_LINE,
     l_debug_i(3)             type c,

     l_s_alerts               type /SAPAPO/SDEMAND_PLANNING_ALERT,
     l_s_value_tab            type /SAPAPO/VALUE_TAB,
     l_t_value_tab            like table of l_s_value_tab,
     l_s_batch_message        type g_ty_s_batch_message,
     l_flg_cancel_calculation type /SAPAPO/FLAG,                   "Flag: Cancel calculation if values are missing
     l_step_missing_values    type /SAPAPO/V_MISSING,              "Treatment when values are missing (see macro step definition)

     l_flg_advg_if            type /SAPAPO/FLAG,                   "Flag for generating IF...ELSEIF...ELSE...ENDIF macro statements
     l_flg_readonly_indicator type c.                              "Read-Only Indicator used for key figure specific locking


*#TR# Data Fields that correspond to macro functions and thus may not be changed or renamed
   data:
     act_column     type i,
     column_from    type /SAPAPO/FINDEX,
     column_to      type /SAPAPO/TINDEX,
     act_plob       type /SAPAPO/PLOBJ,
     act_plob_grid2 type /SAPAPO/PLOBJ.

*#TR# Data Fields used for the communication with ABAP macros _ADVX*
   data:
     l_advx_cols_left_border  type i,
     l_advx_cols_right_border type i.

   field-symbols:
     <fs_s_lines>           like line of i_t_lines,
     <fs_s_cols>            like line of i_t_cols,
     <fs_s_value_tab>       like line of l_t_value_tab,
     <fs_s_special_results> like line of l_t_special_results.


*#TR# (S.1.1) Dynamic Data Declaration for variables used to save grid values (e. g. if planning grid macro elements
*#TR# are used in a macro string)
   data: 43ZJJYHAE5D8GUDCXKX2GRVJO type /SAPAPO/MXVAL.
   data: 43ZJJXMKAAYEEC7KA8NPCK0OK type /SAPAPO/MXVAL.

*#TR# (S.1.2) Local ABAP Macro Definitions
   define _advx_step_end_of_iteration.
     clear l_flg_cancel_calculation.

     act_column = act_column + 1.
     add 1 to l_step_counter.

*    clear g_gui_infos_read.        " note 1502964
   end-of-definition.

*#TR# (S.1.3) Macro step debugging
   if g_s_advx_debug_flags-dbg_macro_step_on = abap_true.
     break-point id /SAPAPO/ADV__EXECUTION_DEBUG.
   endif.




   act_plob       = i_s_adv_plob_values-plobj.
   act_plob_grid2 = i_s_adv_plob_values2-plobj.


*#TR# (S.2.1) Set Start Column of macro step.
   column_from = g_s_cols_properties-left_column.

*#TR# (S.2.2) Set End Column of macro step.
   column_to = g_s_cols_properties-right_column.


*#TR# (S.2.3) Check macro step interval, calculate number of iterations and set start res. end column
*#TR# Adjust start column if necessary
   if g_start_column is not initial.
     act_column = g_start_column.
   else.
     act_column = column_from.
   endif.
   l_step_iterations = column_to - column_from + 1.
   if g_start_column is not initial. l_step_iterations = l_step_iterations - ( g_start_column - column_from ). endif.
   if g_end_column is not initial.   l_step_iterations = l_step_iterations + ( g_end_column - column_to ).     endif.
   clear g_stop_column.
   l_step_counter = 1.

   if sy-batch = true.
     l_s_batch_message-msgid = g_c_adv_msg_class.
     l_s_batch_message-msgty = 'W'.
     l_s_batch_message-msgno = '100'.
   endif.




*&---------------------------------------------------------------------*
*& #TR# (S.3) Macro Step execution: Process the Columns
*&---------------------------------------------------------------------*
   do l_step_iterations times.
     if act_column > column_to and g_end_column is initial or act_column > g_end_column and g_end_column is not initial . exit. endif.
     if act_column < column_from and g_start_column is initial or act_column < g_start_column and g_start_column is not initial. exit. endif.
     if g_stop_column is not initial.
       if act_column > g_stop_column or act_column < g_stop_column. exit. endif.
     endif.

*&---------------------------------------------------------------------*
*& #TR# (S.3.1) Macro Step execution: Debugging
*&---------------------------------------------------------------------*


*&---------------------------------------------------------------------*
*& #TR# (S.3.2) Macro Step execution: Get values of planning grid elements
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& *#TR# (S.3.2-g) Macro Auxiliary Row
*&---------------------------------------------------------------------*
     l_advx_cols_left_border  = g_s_cols_properties-left_column.
     l_advx_cols_right_border = g_s_cols_properties-right_column.

     i_o_advx_tab_access->get_value(
       exporting
         i_row                    = 0000000008
         i_column                 = act_column
         i_column_offset          = 0
         i_border                 = 'R'
         i_cols_left_border       = l_advx_cols_left_border
         i_cols_right_border      = l_advx_cols_right_border
         i_step_missing_values    = '0'
         i_t_tab                  = g_t_tab_aux
       importing
         e_value                  = 43ZJJYHAE5D8GUDCXKX2GRVJO
       changing
         c_flg_cancel_calculation = l_flg_cancel_calculation
           ).





*&---------------------------------------------------------------------*
*& #TR# (S.3.2-a) Planning Grid Row
*&---------------------------------------------------------------------*
     l_calc_line = 0000000094 + i_s_adv_lines_offset-line_offset.
*#TR# (S.3.2-b) Set parameters for method GET_[F_]VALUE
     l_advx_cols_left_border  = g_s_cols_properties-left_column.
     l_advx_cols_right_border = g_s_cols_properties-right_column.

     i_o_advx_tab_access->get_value(
       exporting
         i_row                    = l_calc_line
         i_column                 = act_column
         i_column_offset          = 0
         i_border                 = 'R'
         i_cols_left_border       = l_advx_cols_left_border
         i_cols_right_border      = l_advx_cols_right_border
         i_step_missing_values    = '0'
         i_t_tab                  = c_t_tab
       importing
         e_value                  = 43ZJJXMKAAYEEC7KA8NPCK0OK
       changing
         c_flg_cancel_calculation = l_flg_cancel_calculation
           ).





*#TR# (S.3.2-l) Calculate results and save in TAB res. Auxiliary TAB

*#TR# (S.3.2-m) Condition String

*#TR# (S.3.2-o) Condition or Action Box
     if g_gui_infos_read = true.
       clear l_s_fun_para.
       l_s_fun_para-gui_infos_read = true.
     else.
       clear l_s_fun_para.
     endif.



*#TR# (S.3.2-o19): Interprete function arguments
     CLEAR
     L_FLG_ADVG_IF.
     IF
     43ZJJXMKAAYEEC7KA8NPCK0OK
     >
     0
     .



*&---------------------------------------------------------------------*
*& #TR# (S.3.3) Macro Step Execution: Alert
*&---------------------------------------------------------------------*
     if l_flg_cancel_calculation is initial.
*#TR# (S.3.3-a) Alert Text
       case sy-langu.
         when 'D'.
           l_alert_text = 'Projizierte Abfallmenge &'.
         when 'E'.
           l_alert_text = 'Projected Wastage Quantity &'.
         when 'F'.
           l_alert_text = 'Quantité de déjets prévue &'.
         when others.
           l_alert_text = 'Quantité de déjets prévue &'.
       endcase.
       read table i_t_cols assigning <fs_s_cols> with key column = act_column binary search.
       if sy-subrc = 0.
         concatenate <fs_s_cols>-perdy ':' l_alert_text into l_alert_text separated by space.
       endif.

*#TR# (S.3.3-b) Substituting all placeholders (&)
*#TR# Reset offset for string search
       clear l_offset.
*#TR# find first occurance of & for substitution
       find '&' in section offset l_offset of l_alert_text match offset l_offset.

       if sy-subrc = 0.
         write 43ZJJYHAE5D8GUDCXKX2GRVJO to l_tmp_string exponent 0 decimals 3 left-justified.
         replace section offset l_offset length 1 of l_alert_text with l_tmp_string.
       endif.
       l_s_alert_message-param1 = l_alert_text. shift l_alert_text by 40 places.
       l_s_alert_message-param2 = l_alert_text. shift l_alert_text by 40 places.
       l_s_alert_message-param3 = l_alert_text. shift l_alert_text by 40 places.
       l_s_alert_message-param4 = l_alert_text.
       add 1 to g_alert_step.

*#TR# (S.3.3-c) Save the Alert
       clear l_s_alerts.
       l_s_alerts-step        = g_alert_step.
*#TR# Provide threshold
       if 43ZJJYHAE5D8GUDCXKX2GRVJO < 10000000000.
         l_s_alerts-uni_gw    = 43ZJJYHAE5D8GUDCXKX2GRVJO.
       else.
         l_s_alerts-uni_gw    = 9999999999.
       endif.
       l_s_alerts-type        = 'M'.
       l_s_alerts-plver       = i_vrsioid.
       l_s_alerts-selectionid = i_adv_alert_selid.
       l_s_alerts-vrsio       = g_act_version.
       l_s_alerts-jobnr       = i_s_job_options-jobnr.
       l_s_alerts-jobcnt      = i_s_job_options-jobcount.
       if i_s_job_options-jobtime is initial.
         l_s_alerts-jobtime   = sy-uzeit.
       else.
         l_s_alerts-jobtime   = i_s_job_options-jobtime.
       endif.
       if i_s_job_options-jobdate is initial.
         l_s_alerts-jobdate   = sy-datum.
       else.
         l_s_alerts-jobdate   = i_s_job_options-jobdate.
       endif.
       l_s_alerts-at_id       = '0201'.
       l_s_alerts-aot         = '4000'.
*#TR# DP : Do not convert time zones, because currently no time zones are supported in DP
*#TR# SNP: Do not convert time zones
       read table i_t_cols with key column = act_column into l_s_cols transporting tstfr tstto. assert id /SAPAPO/ADV__EXECUTION condition sy-subrc = 0.
       l_s_alerts-vfrom       = l_s_cols-tstfr.
       l_s_alerts-vto         = l_s_cols-tstto.
       l_s_alerts-priority    = 1.
       l_s_alerts-param1      = l_s_alert_message-param1.
       l_s_alerts-param2      = l_s_alert_message-param2.
       l_s_alerts-param3      = l_s_alert_message-param3.
       l_s_alerts-param4      = l_s_alert_message-param4.
       l_s_alerts-pllayout    = '*'.
       l_s_alerts-planview    = '*'.
       l_s_alerts-makro       = '*'.
       l_s_alerts-mview       = 'Z_PREPMEATS_SNP'.
       l_s_alerts-dview       = 'ZPM_SNP_PROD_PLAN'.
       l_s_alerts-faction     = gs_c_adv_alert_faction-delete.
* Note #1641125 ->
       append l_s_alerts to g_t_alerts.

       add 1 to g_alert_step.
* Note #1641125 <-
       l_s_alerts-step        = g_alert_step.
       l_s_alerts-pllayout    = '4RM7J08VB0E'.
       l_s_alerts-planview    = '92XDA6B9NXP'.
       l_s_alerts-makro       = '43ZJJR0FYI9FCXGN9CN4OV4HG'.
       l_s_alerts-faction     = 'U'.
       l_s_alerts-step        = g_alert_step.
* Note #1641125 ->
* <note 1524393 SEBOK>
       APPEND l_s_alerts to g_t_alerts.
       ADD 1 to g_alert_step.
* </note 1524393 SEBOK>
* Note #1641125 <-
     endif.



*#TR# (S.3.2-m) Condition String
*#TR# (S.3.2-n)
     ENDIF
     .

     _advx_step_end_of_iteration.
   enddo.

endform.

*&---------------------------------------------------------------------*
*&      Form  43ZJJTKMA1HXKFY17DF81IP2S
*&---------------------------------------------------------------------*
*       #TR# Generated Form Routine for Macro Step
*       Macro ID  : 43ZJJR0FYI9FCXGN9CN4OV4HG
*       Macro Name: Projected Wastage Quantity (DB Alert)
*       Step ID   : 43ZJJTCXR2W81TEL1JCVRGQD0
*       Step Name : Delete Existing Alerts
*----------------------------------------------------------------------*
*      -->I_VRSIOID               Planning Version
*      -->I_S_ADV_OPTIONS         Macro Options
*      -->I_S_JOB_OPTIONS         Job Options
*      -->I_S_CLP_OPTIONS         Collaborative Planning Options
*      -->I_T_LINES               Lines (GT_LINES from Interactive Planning)
*      -->I_T_COLS                Columns (GT_COLS from Interactive Planning)
*      -->I_T_ADV_PLOB_VALUES     (Macro) Planning Objects derived from GT_PLOB_VALUES
*      -->I_T_ADV_LINE_INDEX      (Macro) Lines, containing only the key figures
*      -->I_T_ADV_LINES_OFFSET    (Macro) Offsets
*      -->I_S_ADV_LINES_OFFSET
*      -->I_S_ADV_PLOB_VALUES2
*      -->I_ADV_ALERT_SELID
*      -->I_ADV_ALERT_SELID_GRID2
*      -->I_O_ADVX_TAB_ACCESS
*      <--C_T_TAB                 TAB (GT_TAB from Interactive Planning)
*      <--C_T_TAB_OLD             TAB_OLD (GT_TAB_OLD from Interactive Planning)
*      <--C_S_ACTVIEW             ACTVIEW (GS_ACTVIEW from Interactive Planning)
*      <--C_S_RESULT_OPTIONS      Macro result options
*----------------------------------------------------------------------*
form 43ZJJTKMA1HXKFY17DF81IP2S
   using    i_vrsioid               type /SAPAPO/VRSIOID
            i_s_adv_options         type /SAPAPO/ADV_OPTIONS
            i_s_job_options         type /SAPAPO/ADV_JOB_OPTIONS
            i_s_clp_options         type /SAPAPO/ADV_CLP_OPTIONS
            i_t_lines               type /SAPAPO/MSDP_APP_LINES_TAB
            i_t_cols                type /SAPAPO/MSDP_APP_COLS_TAB
            i_t_adv_plob_values     type /SAPAPO/DM_T_PLOB_VALUES
            i_t_adv_line_index      type /SAPAPO/MSDP_APP_LINES_TAB
            i_t_adv_lines_offset    type /SAPAPO/OFFSETS_ADV_MACRO_TAB
            i_s_adv_lines_offset    type /SAPAPO/OFFSETS_ADV_MACRO
            i_s_adv_plob_values     type /SAPAPO/DM_PLOB_VALUES
            i_s_adv_plob_values2    type /SAPAPO/DM_PLOB_VALUES
            i_adv_alert_selid       type /SAPAPO/SELECTIONID2
            i_adv_alert_selid_grid2 type /SAPAPO/SELECTIONID2
            i_o_advx_tab_access     type ref to lcl_advx_tab_access
   changing c_t_tab                 type /SAPAPO/MSDP_APP_TAB_TAB
            c_t_tab_old             type /SAPAPO/MSDP_APP_TAB_TAB
            c_s_actview             type /SAPAPO/PB_ACT_VIEW_STR
            c_s_result_options      type /SAPAPO/ADV_RESULT_OPTION
   raising  /sapapo/cx_advx.


   data:
     l_hlp_date_from          type dats,
     l_hlp_date_to            type dats,
     l_prev_index             type i,

     l_step_iterations        type i,
     l_step_counter           type i,
     l_loop_counter           type i,
     l_value                  type f,
     l_tmp_value              type f,
     l_calc_line              type i,
     l_tmp_calc_line          type f,
     l_tmp_act_column         type f,

     l_s_lines_aux            type /SAPAPO/ADV_S_LINES_AUX,

     l_s_adv_line_index       like line of i_t_adv_line_index,
     l_line_index_from        type i,
     l_line_index_to          type i,
     l_lines_times            type i,
     l_lines                  type i,
     l_tr_lines               type range of /SAPAPO/MXROW,
     l_sr_lines               like line of l_tr_lines,
     l_cols_times             type i,
     l_cols_counter           type i,
     l_tr_cols                type range of /SAPAPO/MXCOL,
     l_sr_cols                like line of l_tr_cols,
     l_s_cols                 like line of i_t_cols,
     l_s_special_results      type g_ty_s_special_results,
     l_t_special_results      like table of l_s_special_results,
     l_act_column_special     type i,
     l_index_for_read         type i,

     l_offset                 type i,
     l_gen_offset             type i,
     l_gen_offset_left        type i,
     l_gen_offset_right       type i,
     l_alert_text(160)        type c,
     l_s_alert_message        type g_ty_s_alert_message,
     l_message_text(160)      type c,
     l_msg_type               type /SAPAPO/MSG_TYPE,                "n 1331066
     l_tmp_string(160)        type c,
     l_tmp_string1(160)       type c,
     l_s_fun_para             type /SAPAPO/ADV_PARA,
     l_mail_argument          type /SAPAPO/FUNSTRING,
     l_s_mail_options         type /SAPAPO/ADV_S_SEND_DOC_MAILREC,
     l_s_doc_options          type /SAPAPO/ADV_S_SEND_DOC_SIG,
     l_debug_msg_line         type /SAPAPO/MSG_LINE,
     l_debug_i(3)             type c,

     l_s_alerts               type /SAPAPO/SDEMAND_PLANNING_ALERT,
     l_s_value_tab            type /SAPAPO/VALUE_TAB,
     l_t_value_tab            like table of l_s_value_tab,
     l_s_batch_message        type g_ty_s_batch_message,
     l_flg_cancel_calculation type /SAPAPO/FLAG,                   "Flag: Cancel calculation if values are missing
     l_step_missing_values    type /SAPAPO/V_MISSING,              "Treatment when values are missing (see macro step definition)

     l_flg_advg_if            type /SAPAPO/FLAG,                   "Flag for generating IF...ELSEIF...ELSE...ENDIF macro statements
     l_flg_readonly_indicator type c.                              "Read-Only Indicator used for key figure specific locking


*#TR# Data Fields that correspond to macro functions and thus may not be changed or renamed
   data:
     act_column     type i,
     column_from    type /SAPAPO/FINDEX,
     column_to      type /SAPAPO/TINDEX,
     act_plob       type /SAPAPO/PLOBJ,
     act_plob_grid2 type /SAPAPO/PLOBJ.

*#TR# Data Fields used for the communication with ABAP macros _ADVX*
   data:
     l_advx_cols_left_border  type i,
     l_advx_cols_right_border type i.

   field-symbols:
     <fs_s_lines>           like line of i_t_lines,
     <fs_s_cols>            like line of i_t_cols,
     <fs_s_value_tab>       like line of l_t_value_tab,
     <fs_s_special_results> like line of l_t_special_results.


*#TR# (S.1.1) Dynamic Data Declaration for variables used to save grid values (e. g. if planning grid macro elements
*#TR# are used in a macro string)

*#TR# (S.1.2) Local ABAP Macro Definitions
   define _advx_step_end_of_iteration.
     clear l_flg_cancel_calculation.

     act_column = act_column + 1.
     add 1 to l_step_counter.

*    clear g_gui_infos_read.        " note 1502964
   end-of-definition.

*#TR# (S.1.3) Macro step debugging
   if g_s_advx_debug_flags-dbg_macro_step_on = abap_true.
     break-point id /SAPAPO/ADV__EXECUTION_DEBUG.
   endif.




   act_plob       = i_s_adv_plob_values-plobj.
   act_plob_grid2 = i_s_adv_plob_values2-plobj.


*#TR# (S.2.1) Set Start Column of macro step.
   column_from = 1.

*#TR# (S.2.2) Set End Column of macro step.
   column_to = 1.


*#TR# (S.2.3) Check macro step interval, calculate number of iterations and set start res. end column
   check column_from <= column_to and column_to >= g_s_cols_properties-left_column and column_from <= g_s_cols_properties-right_column.
   if column_from < g_s_cols_properties-left_column.  column_from = g_s_cols_properties-left_column.  endif.
   if column_to   > g_s_cols_properties-right_column. column_to   = g_s_cols_properties-right_column. endif.
*#TR# Adjust start column if necessary
   if g_start_column is not initial.
     act_column = g_start_column.
   else.
     act_column = column_from.
   endif.
   l_step_iterations = column_to - column_from + 1.
   if g_start_column is not initial. l_step_iterations = l_step_iterations - ( g_start_column - column_from ). endif.
   if g_end_column is not initial.   l_step_iterations = l_step_iterations + ( g_end_column - column_to ).     endif.
   clear g_stop_column.
   l_step_counter = 1.

   if sy-batch = true.
     l_s_batch_message-msgid = g_c_adv_msg_class.
     l_s_batch_message-msgty = 'W'.
     l_s_batch_message-msgno = '100'.
   endif.




*&---------------------------------------------------------------------*
*& #TR# (S.3) Macro Step execution: Process the Columns
*&---------------------------------------------------------------------*
   do l_step_iterations times.
     if act_column > column_to and g_end_column is initial or act_column > g_end_column and g_end_column is not initial . exit. endif.
     if act_column < column_from and g_start_column is initial or act_column < g_start_column and g_start_column is not initial. exit. endif.
     if g_stop_column is not initial.
       if act_column > g_stop_column or act_column < g_stop_column. exit. endif.
     endif.

*&---------------------------------------------------------------------*
*& #TR# (S.3.1) Macro Step execution: Debugging
*&---------------------------------------------------------------------*


*&---------------------------------------------------------------------*
*& #TR# (S.3.2) Macro Step execution: Get values of planning grid elements
*&---------------------------------------------------------------------*

*#TR# (S.3.2-l) Calculate results and save in TAB res. Auxiliary TAB

*&---------------------------------------------------------------------*
*& #TR# (S.3.3) Macro Step Execution: Alert
*&---------------------------------------------------------------------*
     if l_flg_cancel_calculation is initial.
*#TR# (S.3.3-a) Alert Text
       case sy-langu.
       endcase.
       read table i_t_cols assigning <fs_s_cols> index g_s_cols_properties-index_last_entry.
       if sy-subrc = 0.
         concatenate <fs_s_cols>-perdy ':' l_alert_text into l_alert_text separated by space.
       endif.
       read table i_t_cols assigning <fs_s_cols> index 1.
       if sy-subrc = 0.
         concatenate <fs_s_cols>-perdy '-' l_alert_text into l_alert_text separated by space.
       endif.

*#TR# (S.3.3-b) Substituting all placeholders (&)
*#TR# Reset offset for string search
       clear l_offset.
       l_s_alert_message-param1 = l_alert_text. shift l_alert_text by 40 places.
       l_s_alert_message-param2 = l_alert_text. shift l_alert_text by 40 places.
       l_s_alert_message-param3 = l_alert_text. shift l_alert_text by 40 places.
       l_s_alert_message-param4 = l_alert_text.
       add 1 to g_alert_step.

*#TR# (S.3.3-c) Save the Alert
       clear l_s_alerts.
       l_s_alerts-step        = g_alert_step.
*#TR# Provide threshold
       l_s_alerts-type        = 'M'.
       l_s_alerts-plver       = i_vrsioid.
       l_s_alerts-selectionid = i_adv_alert_selid.
       l_s_alerts-vrsio       = g_act_version.
       l_s_alerts-jobnr       = i_s_job_options-jobnr.
       l_s_alerts-jobcnt      = i_s_job_options-jobcount.
       if i_s_job_options-jobtime is initial.
         l_s_alerts-jobtime   = sy-uzeit.
       else.
         l_s_alerts-jobtime   = i_s_job_options-jobtime.
       endif.
       if i_s_job_options-jobdate is initial.
         l_s_alerts-jobdate   = sy-datum.
       else.
         l_s_alerts-jobdate   = i_s_job_options-jobdate.
       endif.
       l_s_alerts-at_id       = '0201'.
       l_s_alerts-aot         = '4000'.
*#TR# DP : Do not convert time zones, because currently no time zones are supported in DP
*#TR# SNP: Do not convert time zones
* -> 1282162
       if  g_s_cols_properties-INITIAL_COLUMN  = 0.
         read table i_t_cols index 1 into l_s_cols transporting tstfr.
       else.
         read table i_t_cols index 2 into l_s_cols transporting tstfr.
       endif.
* <- 1282162
       assert id /SAPAPO/ADV__EXECUTION condition sy-subrc = 0.
       if sy-subrc = 0.
         l_s_alerts-vfrom     = l_s_cols-tstfr.
       endif.
       read table i_t_cols index g_s_cols_properties-index_last_entry into l_s_cols transporting tstto. assert id /SAPAPO/ADV__EXECUTION condition sy-subrc = 0.
       l_s_alerts-vto         = l_s_cols-tstto.
       l_s_alerts-priority    = 2.
       l_s_alerts-param1      = l_s_alert_message-param1.
       l_s_alerts-param2      = l_s_alert_message-param2.
       l_s_alerts-param3      = l_s_alert_message-param3.
       l_s_alerts-param4      = l_s_alert_message-param4.
       l_s_alerts-pllayout    = '*'.
       l_s_alerts-planview    = '*'.
       l_s_alerts-makro       = '*'.
       l_s_alerts-mview       = 'Z_PREPMEATS_SNP'.
       l_s_alerts-dview       = 'ZPM_SNP_PROD_PLAN'.
       l_s_alerts-faction     = 'D'.
       l_s_alerts-step        = g_alert_step.
* Note #1641125 ->
* <note 1524393 SEBOK>
       READ TABLE g_t_alerts TRANSPORTING NO FIELDS
           WITH KEY  selectionid = i_adv_alert_selid
                     aot         = l_s_alerts-aot
                     at_id       = l_s_alerts-at_id
                     makro       = l_s_alerts-makro
                     vto         = l_s_alerts-vto
                     faction     = 'D'
                     param1      = l_s_alerts-param1
                     param2      = l_s_alerts-param2
                     param3      = l_s_alerts-param3
                     param4      = l_s_alerts-param4.
       IF sy-subrc NE 0.
         APPEND l_s_alerts to g_t_alerts.
         ADD 1 to g_alert_step.
       ENDIF.
* </note 1524393 SEBOK>
* Note #1641125 <-
     endif.



     _advx_step_end_of_iteration.
   enddo.

endform.

Thanks,

Rajesh