Wednesday, November 18, 2009

Note 418801 - Creating a user exit macro

Summary

Symptom

You cannot use a standard macro.

Other terms

Macro
Macro/SAPAPO/SDP94
/SAPAPO/SNP94

Reason and Prerequisites

Possible causes:

  • Parameters required to calculate the line entries are not available in the macrobuilder and must first be generated from database tables.
  • More complicated calculations are necessary to determine the line entries.
Solution

You can create a user exit macro to correct the problem. We shall outline the exact procedure for this below.

As of SCM Release 5.0, we recommend that you use a Business Add-In (BAdI) macro instead of a user exit macro (see SAP online documentation).

Creating the macro
  • Use Transaction /SAPAPO/ADVM to call the macrobuilder.
  • Select a macro book.
  • Use Drag and Drop to move the icon labeled 'User exit macro' from the Shuffler into the middle of the screen and attach it to the icon with the name 'Macro'. Rename it.
  • If required, link the user exit macro icon you have just created with one of the event icons located in the right-hand screen.
Creating the user exit
  • Start Transaction SMOD.
  • Enter APODM005 in the 'Enhancement' field. Select 'Display'.
  • Then choose 'Components' or Shift+F11 and double-click the name of the function module.
  • Double-click the include contained in the function module to enter the source code.
Interface

Below we exaplain how to fill the interface of the user exit. The user only fills or changes the following tables:

    • T_C_TAB
    • T_E_TAB_OLD


The T_C_TAB table is the actual output table in this case. T_E_TAB_OLD provides information about data changes and must be maintained for technical reasons. All other tables act as input parameters.

The values on the planning board are stored under the V field name in the T_C_TAB table. The table entries are explicitly defined by their Z line index and their C column index. The T_I_COLS table provides the column information here while the line information is returned from an inner join via the T_I_PLOB_VALUES and T_I_LINES tables.

The parameters of the following tables are used to calculate lines and columns:

Interface parameter
------------------------------------------------------------------
| Table | Field | Description |
------------------------------------------------------------------
| T_I_COLS | VONTG | Lower date limit |
| T_I_COLS | BISTG | Upper date limit |
------------------------------------------------------------------
| T_I_PLOB_VALUES | SELECTION | Table composed of the |
| | | IOBJNM characteristic and a |
| | | range structure |
| T_I_PLOB_VALUES | PLOBJ | (for join condition) |
| T_I_PLOB_VALUES- | IOBJNM | Technical name of the |
| SELECTION | | rel. characteristic |
------------------------------------------------------------------
| T_I_LINES | FELDH | Technical name of the |
| | | rel. key figure |
| T_I_LINES | GRIDNR | Name of the rel. grid |
| T_I_LINES | KRIT1 | (for join condition) |
------------------------------------------------------------------
| T_C_TAB / T_E_TAB_OLD | Z | Line index of planning board |
| T_C_TAB / T_E_TAB_OLD | C | Column index of planning board |
| T_C_TAB / T_E_TAB_OLD | V | num. planning board entry |
------------------------------------------------------------------


To manipulate the planning board entries, you must use the source code of the user exit to adjust the grid entries of the T_C_TAB table appropriately. In this case, each individual cell is addressed using the coordinates of the grid. Proceed as follows:

  • Determine column C from the T_I_COLS table depending on the VONTG and BISTG date limits.
  • Use the internal table T_I_PLOB_VALUES-SELECTION to check that the solution is unique and, if necessary, determine T_I_PLOB_VALUES-PLOBJ.
  • In table T_I_LINES, use the following key fields
    • T_I_PLOB_VALUES-PLOBJ
    • FELDH
    • GRIDNR = '001'

to determine the line number Z = T_I_LINES-LINE.

  • In the T_C_TAB table, enter the required value for the determined line and column index under T_C_TAB-V.
  • If you want to change a value for the table, save the earlier T_C_TAB entry in the table with the same structure, that is, T_E_TAB_OLD. If you enter a new value into the T_C_TAB table, you must insert a null value into the T_E_TAB_OLD table for the corresponding rows and column number.
Notes
  • If you want to make changes at the lowest level of granularity, you must ensure that your selection is unique. We shall only consider this case here.
  • You can find the technical names for key figures and characteristics in Transaction /SAPAPO/SDP8B.
Sample code

The following function module fills all buckets for the FELDH key figure within the time interval VONTG to BISTG with a constant value V. The selection is determined by the IOBJNM and CHAR_VAL fields, whereby the first field provides the technical name of the characteristic and the second indicates the value of the characteristic.

FUNCTION zfill_buckets
*"----------------------------------------------------------------------
*"*"Global interface:
*" IMPORTING
*" VALUE(I_CUBE) TYPE /SAPAPO/INFOCUBE
*" VALUE(I_LAYOUT) TYPE /SAPAPO/LAYOUT
*" VALUE(I_SCTYP) TYPE /SAPAPO/SCTYP
*" VALUE(I_MACRO_NAME) TYPE /SAPAPO/TXMAK
*" VALUE(I_ACT_PLOBJ) TYPE /SAPAPO/PLOBJ
*" VALUE(VONTG) TYPE BEGDA
*" VALUE(BISTG) TYPE ENDDA
*" VALUE(IOBJNM) TYPE /SAPAPO/IOBJNM OPTIONAL
*" VALUE(CHAR_VAL) TYPE /SAPAPO/CHAVL
*" VALUE(FELDH) TYPE /SAPAPO/IOBJNM
*" VALUE(V) TYPE I
*" TABLES
*" T_I_PLOB_VALUES TYPE /SAPAPO/DM_T_PLOB_VALUES
*" T_I_DRILL_HIER STRUCTURE /SAPAPO/PGAN
*" T_I_LINES STRUCTURE /SAPAPO/MCP6_LI
*" T_I_COLS STRUCTURE /SAPAPO/PGCOLS
*" T_C_TAB STRUCTURE /SAPAPO/MXSOP
*" T_E_TAB_OLD STRUCTURE /SAPAPO/MXSOP
*"----------------------------------------------------------------------
DATA: l_selection LIKE LINE OF t_i_plob_values-selection.
DATA: l_line LIKE LINE OF t_i_lines.
DATA: l_tab LIKE LINE OF t_c_tab.
DATA: l_col LIKE LINE OF t_i_cols.
DATA: l_column LIKE t_i_cols-column.
DATA: l_cnt TYPE i.
DATA: l_gridnr TYPE char3 VALUE '001'.
DATA: l_index LIKE sy-tabix.

* read table t_i_cols index 1 into l_col.
LOOP AT t_i_cols INTO l_col WHERE bistg <= bistg
AND vontg >= vontg.
l_column = l_col-column.

LOOP AT t_i_plob_values.
* For checking uniqueness calculate # entries
CLEAR l_cnt.
LOOP AT t_i_plob_values-selection INTO l_selection
WHERE iobjnm = iobjnm
AND low = char_val.
l_cnt = l_cnt + 1.
IF l_cnt > 1.
EXIT.
ENDIF.
ENDLOOP.

IF sy-subrc <> 0 OR l_cnt > 1.
CONTINUE.
ENDIF.
READ TABLE t_i_plob_values-selection WITH KEY
iobjnm = iobjnm
low = char_val
z = l_line-line
c = l_column
TRANSPORTING NO FIELDS.
* store old value
IF sy-subrc = 0.
MODIFY t_e_tab_old FROM l_tab INDEX sy-tabix.
ELSE.
APPEND l_tab TO t_e_tab_old.
ENDIF.
* store new value
l_tab-v = v.
MODIFY t_c_tab FROM l_tab INDEX l_index.
ENDLOOP.
ENDLOOP.

ENDFUNCTION.

Header Data



Release Status:Released for Customer
Released on:16.02.2006 09:45:22
Master Language:German
Priority:Correction with medium priority
Category:Consulting
Primary Component:SCM-APO-FCS-MAC MacroBuilder
Secondary Components:SCM-APO-SNP-MAC MacroBuilder

Affected Releases

Software
Component
Release
From
Release
To
Release
And
subsequent
SAP_APO
30
30A
30A
SAP_APO
310
310
310
SCM
400
400
400
SCM
410
410
410
SCM
500
500
500
SCM
510
510
510

Related Notes




1045639 - Consulting notes in SNP/CTM

539797 - Collective consulting note on macros

No comments: