第 152 页 / 共 275 页
7 User Exits and BAdIs in Logistics Invoice Verification
2. Before you generate the dynpro with the table control, you should consider
which fields will be displayed in the table control. You need an internal table
and a work structure for these tables to supply the table control with data.
You can simply use the structure DRSEG_CI. Besides your custom fields, this
also contains the item number and is therefore ideal for displaying onscreen.
For this reason, create two global data objects in program SAPMZMRM as shown
in Listing 7.1.
PROGRAM sapmzmrm.
* Global data for table control
DATA: gs_drseg_ci TYPE drseg_ci,
gt_drseg_ci TYPE TABLE OF drseg_ci.
Listing 7.1 Global Data for Table Control
3. Now activate your program. Then right-click in Transaction SE80 in the Reposi-
tory Browser on the program name on the left-hand side. In the context menu
that appears, choose Create • Dynpro. Specify 0100 as the dynpro number.
4. Give a brief description of this dynpro, and only choose the Subscreen option
in the Properties tabstrip in the Dynpro Type section. Other dynpro types
cannot be integrated and you would get a short dump when Transaction
MIRO is started.
5. Then switch to the Screen Painter via the Layout icon. First, you generate a
table control here using a wizard that saves you a lot of work. To do this, click
the Table Control (Using Wizard) icon on the left-hand side, and then draw
a box. Start ideally on the top-left side, and draw your table control approxi-
mately 100 characters wide and 18 lines high. During the creation, you can
see in the upper-right side a counter with the width and height of the table
control (see also Figure 7.4).
6. After you’ve drawn the table control, the wizard appears as shown in Figure
7.5. Skip the initial screen by clicking the Next button.
152
© 2013 by Galileo Press Inc., Boston (MA)
第 153 页 / 共 275 页
Custom Fields in Transaction MIRO 7.1
Figure 7.4 Complete Table Control in the Screen Painter
Figure 7.5 Table Control Wizard
153
Personal Copy for Yang Meteor, user id a8103f58-81fe-4f49-acf6-cfb58959c618
第 154 页 / 共 275 页
7 User Exits and BAdIs in Logistics Invoice Verification
7. Specify a clear name in the section Name of the Table Control. In the exam-
ple, TC_MRM_CUST has been used. Click Next.
8. In Name of the Table choose internal Program Table as the type, and enter
Table GT_DRSEG_CI. Because this internal table doesn’t have any header line,
you must also activate the Table Work Area option, and enter the structure
GS_DRSEG_CI. Click Next.
9. Highlight all of the columns provided in Definition of the Columns (which
have been copied from the structure DRSEG_CI). Click Next.
10. Highlight the Input option in the section Input/Output Attributes in Attri-
butes of the Table Control. The fields in the standard status are now ready
for input. All further options remain unchanged. Click Next.
11. You can still activate the option Scroll in Selection of additional Functions
for the Maintenance of Tables. Four buttons are defined for this below the
table control, which the user can use to scroll quickly through the lines of the
table control. Click Next.
12. In Specify the Include, descriptions for various includes are suggested to you,
in which the necessary data declarations and flow modules are to be created.
Copy the suggestion unchanged, then click Next.
13. Click Complete, and all objects and modules necessary for the table control
are generated.
14. Save your dynpro, and exit the Screen Painter. Activate the dynpro. Also high-
light all other objects that are suggested to you, and activate these as well.
Now you have the fundamental structure of your dynpro. Still missing is the com-
munication with the BAdI to fill the table control with data and write back changed
values; however, before you tackle this part, you should first focus on the BAdI.
7.1.4 Preparation of the Data in the BAdI
Now that you’ve made these preparations, you can deal with the first methods
of the BAdI. Refer to Table 7.1 and Table 7.2 again. While the incoming invoices
are being processed, the system calls the BAdI methods of Table 7.1. You need to
format the data if necessary and temporarily store it in the BAdI. You can store
the data in the attributes of the associated class. When you subsequently retrieve
the data from the BAdI (see Table 7.2) in the flow logic of your dynpro, the data is
ultimately used from these attributes.
154
© 2013 by Galileo Press Inc., Boston (MA)
第 155 页 / 共 275 页
Custom Fields in Transaction MIRO 7.1
1. Create an implementation for the BAdI MRM_ITEM_CUSTFIELDS in Transaction
SE19. You can use, for example, ZMRM_ITEM_CUSTFIELDS as the name for the
implementation. Save the implementation.
2. Store your previously created dynpro in the implementation by switching to
the SUBSCREENS tabstrip and inserting the name and the dynpro number as a
called program (see Figure 7.6).
Figure 7.6 The Subscreens Tabstrip of the BAdI Implementation
3. Switch to the Interface tabstrip and navigate by double-clicking in the imple-
menting class (ZCL_IM_MRM_ITEM_CUSTFIELDS).
4. In the class, take a brief look at the Attributes tabstrip. You’ll find six attributes
here (see Table 7.5), which have been automatically created. These attributes
have been defined in the interface IF_EX_MRM_ITEM_CUSTFIELDS from which the
BAdI has been derived.
An essential basic property of interfaces is that when a class implements an
interface (and nothing else is hidden behind the implementation of a BAdI), the
class must copy all methods and attributes defined in the interface. For this rea-
son, the attributes are automatically generated at this point. This means you
don’t have to do anything else. All attributes that you need later are already
there!
155
Personal Copy for Yang Meteor, user id a8103f58-81fe-4f49-acf6-cfb58959c618
第 156 页 / 共 275 页
7 User Exits and BAdIs in Logistics Invoice Verification
Attribute Description
IF_EX_MRM_ITEM_CUSTFIELDS~ This field contains the transaction type.
The most important possible vales are the
TRANSACTION_TYPE
following:
EE A: Display
EE H: Add (new document)
EE V: Change
IF_EX_MRM_ITEM_CUSTFIELDS~ This structure contains all of the document
header data.
S_RBKPV
IF_EX_MRM_ITEM_CUSTFIELDS~ This internal table contains all the document
items data, including your custom fields.
TAB_DRSEG
IF_EX_MRM_ITEM_CUSTFIELDS~ This internal table only contains your custom
TAB_DRSEG_CUSTOM
fields (type DRSEG_CI; refer to Table 7.3).
IF_EX_MRM_ITEM_CUSTFIELDS~ If the sequence of the data records in your
dynpro has been changed (sorted), you can set
H_SORT
this indicator to retain the sorting.
IF_EX_MRM_ITEM_CUSTFIELDS~ Characteristic: The user has changed the
custom data.
H_CHANGE
Table 7.5 Attributes from Interface IF_EX_MRM_ITEM_CUSTFIELDS
5. Switch again to the Methods tabstrip. First, the methods, which are automat-
ically called, are implemented (refer to Table 7.1). You can use the method
CUSTOMDATA_MODIFY to prepopulate the custom fields. This is not required for
the basic function, however.
Focus instead on the method INVOICE_DATA_TRANSFER. This method has four
input parameters (transaction type, invoice document header, invoice document
items, and your custom fields). In this method, you don’t need to do anything
but copy the parameters that are transferred here into the attributes of the class.
You can find the respective coding for this in Listing 7.2.
METHOD if_ex_mrm_item_custfields~invoice_data_transfer.
* Copying of the input parameters in attributes
me->if_ex_mrm_item_custfields~transaction_type =
i_transaction_type.
me->if_ex_mrm_item_custfields~s_rbkpv =
is_rbkpv.
me->if_ex_mrm_item_custfields~tab_drseg =
156
© 2013 by Galileo Press Inc., Boston (MA)
| Attribute | Description |
|---|---|
| IF_EX_MRM_ITEM_CUSTFIELDS~ TRANSACTION_TYPE | This field contains the transaction type. The most important possible vales are the following: EE A: Display EE H: Add (new document) EE V: Change |
| IF_EX_MRM_ITEM_CUSTFIELDS~ S_RBKPV | This structure contains all of the document header data. |
| IF_EX_MRM_ITEM_CUSTFIELDS~ TAB_DRSEG | This internal table contains all the document items data, including your custom fields. |
| IF_EX_MRM_ITEM_CUSTFIELDS~ TAB_DRSEG_CUSTOM | This internal table only contains your custom fields (type DRSEG_CI; refer to Table 7.3). |
| IF_EX_MRM_ITEM_CUSTFIELDS~ H_SORT | If the sequence of the data records in your dynpro has been changed (sorted), you can set this indicator to retain the sorting. |
| IF_EX_MRM_ITEM_CUSTFIELDS~ H_CHANGE | Characteristic: The user has changed the custom data. |
第 157 页 / 共 275 页
Custom Fields in Transaction MIRO 7.1
it_drseg.
me->if_ex_mrm_item_custfields~tab_drseg_custom =
it_drseg_custom.
ENDMETHOD.
Listing 7.2 Method INVOICE_DATA_TRANSFER
6. After the user has changed the data, it will include the new status in the attri-
bute TAB_DRSEG_CUSTOM (this part is implemented later). The attribute H_CHANGE
also contains an indicator to determine whether the data has been changed.
In the method CUSTOM_DATA_GET, you now don’t need to do anything else but
return this information again to the standard program. For the coding, see
Listing 7.3.
METHOD if_ex_mrm_item_custfields~custom_data_get.
* Return of the changed attributes to callers
et_drseg_cust =
me->if_ex_mrm_item_custfields~tab_drseg_custom.
e_change =
me->if_ex_mrm_item_custfields~h_change.
ENDMETHOD.
Listing 7.3 Method CUSTOM_DATA_GET
7. Follow the methods from Table 7.2, shown earlier. The method INVOICE_DATA_
GET is called from the time PROCESS BEFORE OUTPUT of the flow logic of the dyn-
pro. The task of the method is to return the current contents of the attributes
on the item data to the dynpro. For this, simply provide the export parameters
of the method with the suitable attributes of your class. You can find the coding
for this in Listing 7.4.
METHOD if_ex_mrm_item_custfields~invoice_data_get.
* Prepare data attributes for dynpro
e_transaction_type =
me->if_ex_mrm_item_custfields~transaction_type.
es_rbkpv =
me->if_ex_mrm_item_custfields~s_rbkpv.
et_drseg =
me->if_ex_mrm_item_custfields~tab_drseg.
et_drseg_cust =
me->if_ex_mrm_item_custfields~tab_drseg_custom.
ENDMETHOD.
Listing 7.4 Method INVOICE_DATA_GET
157
Personal Copy for Yang Meteor, user id a8103f58-81fe-4f49-acf6-cfb58959c618
第 158 页 / 共 275 页
7 User Exits and BAdIs in Logistics Invoice Verification
8. The method CUSTOM_DATA_TRANSFER will be called from the time PROCESS AFTER
INPUT of the flow logic of the dynpro. At this point, the dynpro returns the pos-
sibly changed custom fields and an indicator to determine whether any data has
been changed. You store this data in the attributes. The previously implemented
method CUSTOM_DATA_GET can therefore precisely process this data further (see
Listing 7.5).
METHOD if_ex_mrm_item_custfields~custom_data_transfer.
me->if_ex_mrm_item_custfields~tab_drseg_custom =
it_drseg_cust.
me->if_ex_mrm_item_custfields~h_change =
i_change.
ENDMETHOD.
Listing 7.5 Method CUSTOM_DATA_TRANSFER
9. Finally, you still need the method TABPAGE_LABEL_SET to give a description to
the tabstrip. Use a text symbol so that the description can be translated. A maxi-
mum of 11 characters are displayed in the tabstrip (see Listing 7.6).
METHOD if_ex_mrm_item_custfields~tabpage_label_set.
* Description of the tabstrip, max. eleven characters
* text-001 contains the text ‘addition’
e_screen_name = text-001.
ENDMETHOD.
Listing 7.6 Method TABPAGE_LABEL_SET
7.1.5 Back to the Dynpro
Now that you’ve also made all preparations in the BAdI, you need to set up the
data communication between the BAdI and the dynpro. As previously mentioned,
communication between the dynpro and the BAdI flows via the methods INVOICE_
DATA_GET and CUSTOM_DATA_TRANSFER, which in turn access the attributes of the
class. In object-oriented programming, the content of attributes is in each case
precisely linked to an instance of the class. Therefore, if you were to simply gen-
erate a new instance on the implementing class ZCL_IM_MRM_ITEM_CUSTFIELDS to
subsequently call the aforementioned methods, it would be unsuccessful because
the new instance would also have some attributes that would simply be empty.
For this reason, you need to make sure that you access exactly the same instance
that has also been used by the BAdI. The static class CL_EXITHANDLER (see Figure
7.7) exists with the method GET_INSTANCE_FOR_SUBSCREENS. You must only transfer
158
© 2013 by Galileo Press Inc., Boston (MA)
第 159 页 / 共 275 页
Custom Fields in Transaction MIRO 7.1
an appropriate reference variable to this method that refers to the interface of the
BAdI. Using the interface, the method subsequently recognizes the appropriate
instance and returns it.
Figure 7.7 Methods of the Class CL_EXITHANDLER
1. Navigate to Transaction SE80 in your program SAPMZMRM, and switch to dynpro
0100. Insert a new MODULE with the name GET_DATA in the flow logic in the time
PROCESS BEFORE OUTPUT. Double-click GET_DATA to generate the module. Copy
the suggested include (MZMRM_GET_DATAO01).
2. Create a new variable in the module as a reference to the interface of the BAdI.
You can find the name of the interface in Transaction SE18 or SE19 in the Inter-
faces tabstrip. In this case, the interface is IF_EX_MRM_ITEM_CUSTFIELDS. In the
example given, this variable has been named MRM_CUSTFIELDS.
3. Call the method GET_INSTANCE_FOR_SUBSCREENS of the class CL_EXITHANDLER and
transfer your previously defined variable. After calling, your variable shows the
instance of the BAdI.
4. Retrieve all available data from the BAdI via the method INVOICE_DATA_GET. To
include all the data, you must still create suitable variables in your program.
Store these variables in the global area so that you can access them at a later
stage.
159
Personal Copy for Yang Meteor, user id a8103f58-81fe-4f49-acf6-cfb58959c618
第 160 页 / 共 275 页
7 User Exits and BAdIs in Logistics Invoice Verification
5. Finally, you must transfer the data to your table control. Because the table con-
trol uses all of the fields of the structure DRSEG_CI, you can simply copy the
content of the internal table ET_DRSEG_CUST, which you obtain in the previous
step, to the table GT_DRSEG_CI that supplies your table control. You can find the
respective coding for this module in Listing 7.7 and Listing 7.8.
PROGRAM sapmzmrm.
...
* Data declarations for BAdI communication
TYPE-POOLS: mrm, mmcr.
DATA: gv_trtyp LIKE t169-trtyp,
gs_rbkpv TYPE mrm_rbkpv,
gt_drseg TYPE mmcr_tdrseg,
gt_drseg_custom TYPE tdrseg_cust.
Listing 7.7 Data Declarations in Program SAPMZMRM
*------------------------------------------------------------*
***INCLUDE MZMRM_GET_DATAO01 .
*------------------------------------------------------------*
*& Module GET_DATA OUTPUT
*&------------------------------------------------------------
module GET_DATA output.
* Reference to the interface
DATA: mrm_custfields TYPE REF TO if_ex_mrm_item_custfields.
* Obtain instance
CALL METHOD cl_exithandler=>get_instance_for_subscreens
CHANGING
instance = mrm_custfields
EXCEPTIONS
OTHERS = 6.
* Retrieve data fromBAdI
CALL METHOD mrm_custfields->invoice_data_get
IMPORTING
e_transaction_type = gv_trtyp
es_rbkpv = gs_rbkpv
et_drseg = gt_drseg
et_drseg_cust = gt_drseg_custom.
* Transfer in table control
160
© 2013 by Galileo Press Inc., Boston (MA)
第 161 页 / 共 275 页
Custom Fields in Transaction MIRO 7.1
gt_drseg_ci[] = gt_drseg_custom[].
endmodule. “ GET_DATA OUTPUT
Listing 7.8 Module GET_DATA
6. Switch back to the flow logic of your dynpro. Create a new module with the
name WRITE_DATA as the last module in the time PROCESS AFTER INPUT. Double-
click the module name to generate the module, and use the suggested include
(MZMRM_WRITE_DATAI01) again.
7. At this point, you must transfer the data back again to the BAdI. No change can
fundamentally be made if the user is only in the display mode. You must there-
fore implement the following checks when the transaction type that you have
temporarily saved in GV_TRTYP is not identical to ‘A’.
8. You then make a LOOP via the current data of your table control (GT_DRSEG_CI)
and compare each line with the original status that has been stored in the PBO
in the internal table GT_DRSEG_CUSTOM. If a line has changed, note this, and write
the change back to Table GT_DRSEG_CUSTOM.
9. Afterwards, you can create the method CUSTOM_DATA_TRANSFER. The reference
variable MRM_CUSTFIELDS defined in the PBO is still available and can therefore
be used. Return to Table GT_DRSEG_CUSTOM. If data has been changed, place
the indicator I_CHANGE in the parameter interface of the called method. The
parameter I_SORT is not used in the example. You can simply return ABAP_FALSE
here.
The complete coding for the module WRITE_DATA can be found in Listing 7.9.
*------------------------------------------------------------*
***INCLUDE MZMRM_WRITE_DATAI01 .
*------------------------------------------------------------*
*& Module WRITE_DATA INPUT
*&------------------------------------------------------------
MODULE write_data INPUT.
* Local declarations
DATA lv_change TYPE c.
DATA ls_drseg_cust TYPE drseg_ci.
* Only when not in display mode
CHECK gv_trtyp NE ‘A’.
161
Personal Copy for Yang Meteor, user id a8103f58-81fe-4f49-acf6-cfb58959c618
第 162 页 / 共 275 页
7 User Exits and BAdIs in Logistics Invoice Verification
* Have the data been changed?
LOOP AT gt_drseg_ci INTO gs_drseg_ci.
READ TABLE gt_drseg_custom
INTO ls_drseg_cust INDEX sy-tabix.
IF ls_drseg_cust NE gs_drseg_ci.
* Data have been changed
lv_change = ‘X’.
MODIFY gt_drseg_custom FROM gs_drseg_ci
INDEX sy-tabix.
ENDIF.
ENDLOOP.
* Write back data
CALL METHOD mrm_custfields->custom_data_transfer
EXPORTING
i_sort = abap_false
it_drseg_cust = gt_drseg_custom
i_change = lv_change.
ENDMODULE. “ WRITE_DATA INPUT
Listing 7.9 Module WRITE_DATA
You should now activate your latest changes and make sure that the BAdI imple-
mentation is active. After that, you can test the new function using Transaction
MIRO. Both the additional tabstrip and the data you entered should now be
displayed.
However, it isn’t ideal that all fields are always ready for input. It’s better when the
three standard fields: The item number, the account type, and the material num-
ber (see Table 7.3), aren’t fundamentally ready for input. You should also take into
account that your custom fields are also deactivated if a mere display transaction
accesses these. Also, the user can enter values in new items. Because your custom
fields are item related, the input is only possible if an item is actually available in
the document. This can be simply checked via the field C_RBLGP — if there is no
item number available here, no input is possible.
1. Switch once again to the flow logic of your dynpro. The Table Control Wizard
has already suggested a module to you that you can use to change the attributes
of the fields (TC_MRM_CUST_CHANGE_FIELD_ATTR).
162
© 2013 by Galileo Press Inc., Boston (MA)
第 163 页 / 共 275 页
Custom Fields in Transaction MIRO 7.1
2. Remove the comments prior to this line, and double-click the name to create
the module. Because this is another PBO module on the table control, you can
create it in the existing include MZMRMO01.
3. You can then change the fields there, as described earlier. Because this isn’t any
special technique of the BAdI but belongs to the general programming of table
controls, this hasn’t been dealt with in this section in detail. However, you can
find the complete coding in Listing 7.10. You can check the complete flow logic
on the dynpro in Listing 7.11.
*&-----------------------------------------------------------*
*& Module TC_MRM_CUST_CHANGE_FIELD_ATTR OUTPUT
*&-----------------------------------------------------------*
MODULE tc_mrm_cust_change_field_attr OUTPUT.
DATA ls_col TYPE cxtab_column.
* For all columns of the current line
LOOP AT tc_mrm_cust-cols INTO ls_col.
* Standard fields: Prevent input
IF ls_col-screen-name EQ ‘GS_DRSEG_CI-C_RBLGP’ OR
ls_col-screen-name EQ ‘GS_DRSEG_CI-C_KOART’ OR
ls_col-screen-name EQ ‘GS_DRSEG_CI-C_MATNR’.
ls_col-screen-input = 0.
ENDIF.
* In display mode or if no item number
* is assigned – prevent input for custom fields
IF ls_col-screen-name EQ ‘GS_DRSEG_CI-ZZTEXT_1’ OR
ls_col-screen-name EQ ‘GS_DRSEG_CI-ZZTEXT_2’.
IF gv_trtyp = ‘A’ OR
gs_drseg_ci-c_rblgp IS INITIAL.
ls_col-screen-input = 0.
ELSE.
ls_col-screen-input = 1.
ENDIF.
ENDIF.
MODIFY tc_mrm_cust-cols FROM ls_col.
ENDLOOP.
ENDMODULE. “ TC_MRM_CUST_CHANGE_FIELD_ATTR OUTPUT
Listing 7.10 Module TC_MRM_CUST_GET_LINES OUTPUT
163
Personal Copy for Yang Meteor, user id a8103f58-81fe-4f49-acf6-cfb58959c618
第 164 页 / 共 275 页
7 User Exits and BAdIs in Logistics Invoice Verification
PROCESS BEFORE OUTPUT.
MODULE get_data.
*&SPWIZARD: PBO FLOW LOGIC FOR TABLECONTROL ‘TC_MRM_CUST’
MODULE tc_mrm_cust_change_tc_attr.
*&SPWIZARD: MODULE TC_MRM_CUST_CHANGE_COL_ATTR.
LOOP AT gt_drseg_ci
INTO gs_drseg_ci
WITH CONTROL tc_mrm_cust
CURSOR tc_mrm_cust-current_line.
MODULE tc_mrm_cust_get_lines.
MODULE tc_mrm_cust_change_field_attr.
ENDLOOP.
PROCESS AFTER INPUT.
*&SPWIZARD: PAI FLOW LOGIC FOR TABLECONTROL ‘TC_MRM_CUST’
LOOP AT gt_drseg_ci.
CHAIN.
FIELD gs_drseg_ci-c_rblgp.
FIELD gs_drseg_ci-c_koart.
FIELD gs_drseg_ci-c_matnr.
FIELD gs_drseg_ci-zztext_1.
FIELD gs_drseg_ci-zztext_2.
MODULE tc_mrm_cust_modify ON CHAIN-REQUEST.
ENDCHAIN.
ENDLOOP.
MODULE tc_mrm_cust_user_command.
MODULE write_data.
Listing 7.11 Flow Logic on Dynpro 0100
7.2 Overriding Tolerance Checks
Many options are provided with the tolerance limits in the Customizing of Logis-
tics Invoice Verification to influence the locking procedure of incoming invoices
with regard to price or quantity variances. When the incoming invoice is entered,
the absolute or percent upper and lower limits are checked. If a value (quantity/
price) deviates beyond these limits from the associated purchase order, the docu-
ment is locked. As a result of the locking, the invoice cannot be cleared in FI until
164
© 2013 by Galileo Press Inc., Boston (MA)
第 165 页 / 共 275 页
Overriding Tolerance Checks 7.2
the lock has been removed. With the enhancement MM08R002, you can also indi-
vidually override these upper and lower limits.
7.2.1 Tolerance Limits in Customizing
In Customizing (Transaction SPRO), you can find the settings for tolerance limits
under Materials Management • Logistics Invoice Verification • Invoice Lock •
Specify Tolerance Limits. Depending on the company code and the tolerance key,
you can maintain the absolute and percent upper limits and lower limits for dif-
ferences here (see Figure 7.8).
Figure 7.8 Tolerance Limits in Customizing
If you set the Do Not Check option with a limit, the invoice item may differ
indefinitely in this direction. If these limits are exceeded, the invoice can be saved
(in the standard version, the associated message is set as a warning); however, it
is supplied with a locking reason.
The tolerance key stands for an SAP-specified type of deviation between the incom-
ing invoice and purchase order or the goods receipt (GR). You can see in Table 7.6
165
Personal Copy for Yang Meteor, user id a8103f58-81fe-4f49-acf6-cfb58959c618
第 166 页 / 共 275 页
7 User Exits and BAdIs in Logistics Invoice Verification
a brief overview of all the tolerance keys checked by the system. You can also find
detailed descriptions on the individual keys in the Customizing documentation.
Tolerance Key Explanation
AN Amount of item without purchase order reference
AP Amount of item with purchase order reference
BD Write off small differences automatically
BR Percentage purchase order price quantity variance (IR prior
to GR)
BW Percentage purchase order price quantity variance (IR
following GR)
DQ Exceed amount: Quantity variance
DW Quantity variance when GR quantity = zero
KW Price variance: Delivery costs
LA Amount of blanket purchase order
LD Blanket purchase or time limit exceeded
PP Price variance
PS Price variance: Estimated price
ST Date variance
VP Moving average price variance
Table 7.6 Overview of Tolerance Key
7.2.2 Use of the Enhancement
Enhancement MM08R002 is also described using a brief example. Let’s assume that
you have set the tolerance limits for price variances on the purchase order (tol-
erance key PP) in such a way that only 2 percent variance in either direction is
allowed. You now have a material group where the prices for the goods are subject
to significant market fluctuations. Therefore, a variance of 5 percent is allowed in
this case. To implement this, you need to know which material group the mate-
rial of an invoice item belongs to; depending on this information, you must then
redefine the limits. Unfortunately, you receive this information in a different user
exit from the one used to overwrite parameters.
166
© 2013 by Galileo Press Inc., Boston (MA)
| Tolerance Key | Explanation |
|---|---|
| AN | Amount of item without purchase order reference |
| AP | Amount of item with purchase order reference |
| BD | Write off small differences automatically |
| BR | Percentage purchase order price quantity variance (IR prior to GR) |
| BW | Percentage purchase order price quantity variance (IR following GR) |
| DQ | Exceed amount: Quantity variance |
| DW | Quantity variance when GR quantity = zero |
| KW | Price variance: Delivery costs |
| LA | Amount of blanket purchase order |
| LD | Blanket purchase or time limit exceeded |
| PP | Price variance |
| PS | Price variance: Estimated price |
| ST | Date variance |
| VP | Moving average price variance |
第 167 页 / 共 275 页
Overriding Tolerance Checks 7.2
Take a look at Table 7.7. When you enter an item in the incoming invoice and
there is a variance, the EXIT_SAPLMR1M_001 or EXIT_SAPLMRMP_001 is called depend-
ing on the type of variance. You must copy the header and item data to the global
data of the function group. Then the EXIT_SAPLMRMC_001 starts in which you can
redefine the tolerance limits. You can access the header and item data again via the
global data of the function group.
User Exit Description
EXIT_SAPLMR1M_001 Price and quantity variances are run for each item and
contain header and item data of the item.
EXIT_SAPLMRMP_001 Date and amount variances are run for each item and
contain header and item data of the item.
EXIT_SAPLMRMC_001 Each item and relevant tolerance key is run and provides
the option to redefine the tolerance limits.
Table 7.7 User Exits of the Enhancement MM08R002
The following instructions put the theory into practice:
1. Create a new project in Transaction CMOD, and include the enhancement
MM08R002. Then save the project, and switch to Components.
2. Navigate to EXIT_SAPLMR1M_001, and choose the Skip • Global Data menu
option. You cannot directly change the global data of a user exit because that’s a
modification. You can, however, find a line in the global date with the content
INCLUDE ZXM08TOP. This include is in the customer namespace, and you can cus-
tomize it without any modifications.
Double-click the name of the include to create this. Then define two structures
to include the header and item data from the interface of the exit. You can copy
the data types from the interface of the user exit (see Listing 7.12).
*&-----------------------------------------------------------*
*& Include ZXM08TOP
*&-----------------------------------------------------------*
* Global Data: header and item data
DATA: zz_rbkpv TYPE MRM_RBKPV,
zz_drseg TYPE MMCR_DRSEG.
Listing 7.12 Global Data of the Enhancement
167
Personal Copy for Yang Meteor, user id a8103f58-81fe-4f49-acf6-cfb58959c618
| User Exit | Description |
|---|---|
| EXIT_SAPLMR1M_001 | Price and quantity variances are run for each item and contain header and item data of the item. |
| EXIT_SAPLMRMP_001 | Date and amount variances are run for each item and contain header and item data of the item. |
| EXIT_SAPLMRMC_001 | Each item and relevant tolerance key is run and provides the option to redefine the tolerance limits. |
第 168 页 / 共 275 页
7 User Exits and BAdIs in Logistics Invoice Verification
3. Navigate back to the user exit, and double-click to create the include ZXM08U04.
Transfer the data from the interface to the global structures just defined (see
Listing 7.13).
*&-----------------------------------------------------------*
*& Include ZXM08U04 (EXIT_SAPLMR1M_001)
*&-----------------------------------------------------------*
*”*”Local interface:
*” IMPORTING
*” VALUE(I_RBKPV) TYPE MRM_RBKPV
*” VALUE(I_YDRSEG) TYPE MMCR_DRSEG
*” EXCEPTIONS
*” CALL_FAILURE
*”------------------------------------------------------------
zz_rbkpv = i_rbkpv.
zz_drseg = i_ydrseg.
Listing 7.13 User Exit EXIT_SAPLMR1M_001
4. Switch to the user exit EXIT_SAPLMRMP_001, and create the include ZXM08U17.
Transfer the data of the interface here to the global data. The coding is identical
with Listing 7.13.
5. Navigate to EXIT_SAPLMRMC_001, and create the include ZXM08U19. Two import
parameters are provided in this user exit: The company code and the tolerance
key. You should therefore redefine the limits based on these parameters.
The new tolerance limits can be specified using Table 7.8. The fields E_XW1JA,
E_XW2JA, E_XP1JA, and E_XP2JA specify whether the associated limited is
checked, identically with Do Not Check and Check Limit in Customizing (see
Figure 7.8). When you don’t set the flag, an unrestricted variance is allowed
here.
Parameter Explanation
E_WERT1 Lower limit absolute
E_XW1JA Check lower limit absolutely
E_WERT2 Upper limit absolute
E_XW2JA Check lower limit absolutely
Table 7.8 Parameter of the EXIT_SAPLMRMC_001
168
© 2013 by Galileo Press Inc., Boston (MA)
| Parameter | Explanation |
|---|---|
| E_WERT1 | Lower limit absolute |
| E_XW1JA | Check lower limit absolutely |
| E_WERT2 | Upper limit absolute |
| E_XW2JA | Check lower limit absolutely |
第 169 页 / 共 275 页
Overriding Tolerance Checks 7.2
Parameter Explanation
E_PROZ1 Lower limit in percentage terms
E_XP1JA Check lower limit in percentage terms
E_PROZ2 Upper limit in percentage terms
E_XP2JA Check upper limit in percentage terms
E_CHECK Characteristic: Use new limits from user exit
Table 7.8 Parameter of the EXIT_SAPLMRMC_001 (Cont.)
6. Place the flag E_CHECK to apply your changes; otherwise, the settings will con-
tinue to be used from Customizing.
Note
If you set E_CHECK and don’t fill any field, this basically means that unlimited vari-
ances are allowed. Because only the percentage limit in the given example is cus-
tomized, you can optionally read all other values from Customizing (Table T169G).
You can find an example for this in Listing 7.14.
*&-----------------------------------------------------------*
*& Include ZXM08U19 (EXIT_SAPLMRMC_001)
*&-----------------------------------------------------------*
DATA ls_t169g TYPE t169g.
* Differing logic for all company codes
* and price variance (tolerance key PP)
* for material group 007
IF i_tolsl = ‘PP’ AND
zz_drseg-matkl = ‘007’.
* Obtain standard values from Customizing
SELECT SINGLE * FROM t169g INTO ls_t169g
WHERE bukrs = i_bukrs AND
tolsl = i_tolsl.
* Assign absolute limits from Customizing
e_wert1 = ls_t169g-wert1.
e_wert2 = ls_t169g-wert2.
e_xw1ja = ls_t169g-xw1ja.
e_xw2ja = ls_t169g-xw2ja.
169
Personal Copy for Yang Meteor, user id a8103f58-81fe-4f49-acf6-cfb58959c618
| Parameter | Explanation |
|---|---|
| E_PROZ1 | Lower limit in percentage terms |
| E_XP1JA | Check lower limit in percentage terms |
| E_PROZ2 | Upper limit in percentage terms |
| E_XP2JA | Check upper limit in percentage terms |
| E_CHECK | Characteristic: Use new limits from user exit |
| Note |
|---|
| If you set E_CHECK and don’t fill any field, this basically means that unlimited vari- ances are allowed. Because only the percentage limit in the given example is cus- tomized, you can optionally read all other values from Customizing (Table T169G). You can find an example for this in Listing 7.14. |
第 170 页 / 共 275 页
7 User Exits and BAdIs in Logistics Invoice Verification
* Increase percentage variance
e_proz1 = 5.
e_xp1ja = ‘X‘.
e_proz2 = 5.
e_xp2ja = ‘X‘.
* Use change
e_check = ‘X‘.
ENDIF.
Listing 7.14 User Exit EXIT_SAPLMRMC_001
170
© 2013 by Galileo Press Inc., Boston (MA)
第 171 页 / 共 275 页
8 Validation and Substitution of
Accounting Documents
Perhaps you are wondering why there is a chapter on validation and substitution
in SAP ERP Financials (FI) in a book about MM enhancements. The easy answer
is that numerous MM documents have an FI document as a follow-on. Therefore,
you often need to check information from an MM document from the FI point
of view and reject the booking if necessary. Information from MM documents is
frequently formatted and copied to fields of the FI document. The item text (BSEG-
SGTXT) and reference key (BSEG-XREF1/2) fields are very popular here in particular.
Both can be neatly resolved via validation and substitution.
Validation and Substitution
With validation and substitution, you have two very similar tools provided. The differ-
ence between the two is as follows:
EE Validation
With validation, you can check the field contents of the accounting document and
prevent the posting of a document if required by displaying an error message.
EE Substitution
With substitution, you can overwrite some field contents of the accounting
document.
Of course, you also have the option in many MM transactions to check an input or
overwrite field contents via suitable user exits or BAdIs. However, the advantage of
validation and substitution is that there is a central item in the interface between
MM and FI. Therefore, you can implement a central set of rules in validation that
will always run regardless of whether the original document is a material docu-
ment, a logistics incoming invoice, or a document from another application, such
as from Sales and Distribution (SD) or FI.
In the following sections, you’ll learn about the function of validation and substitu-
tion based on an example.
171
Personal Copy for Yang Meteor, user id a8103f58-81fe-4f49-acf6-cfb58959c618
| Validation and Substitution |
|---|
| With validation and substitution, you have two very similar tools provided. The differ- ence between the two is as follows: EE Validation With validation, you can check the field contents of the accounting document and prevent the posting of a document if required by displaying an error message. EE Substitution With substitution, you can overwrite some field contents of the accounting document. |
第 172 页 / 共 275 页
8 Validation and Substitution of Accounting Documents
8.1 Validation of Accounting Documents
You can use validation to check an accounting document and to reject the posting,
if applicable. You create a validation in Transaction OB28. A validation for a spe-
cific callup point is therefore created and contains one or several steps. Each step
in turn consists of a prerequisite, a check, and a message displayed if the check
fails (see Figure 8.1). You should learn a lot more about the concept before you
create an initial validation, and we will provide this additional information in the
following subsections.
Figure 8.1 Overview of a Validation Step
8.1.1 Callup Points
Validation can be triggered at various callup points; usually this happens during
the check for the document header or the document item takes place. This always
refers to the FI document itself and not to the data of the original document, which
can originate from many areas. The header data consists of the fields of Table BKPF.
The item data consists of the fields of Table BSEG.
172
© 2013 by Galileo Press Inc., Boston (MA)
第 173 页 / 共 275 页
Validation of Accounting Documents 8.1
A Boolean class is defined behind each callup point. The Boolean class controls the
tables and fields as well as the message class that is used for error messages. An
overview of the possible modules is provided in Table 8.1.
Callup point Boolean class Scope of check
0001 008 Document header (BKPF)
0002 009 Document item (BSEG)
0003 015 Total document (BKPF and BSEG)
Table 8.1 Callup Points in the Validation and Substitution
8.1.2 Steps
Each validation consists of one or several steps that are executed in succession.
Each step consists of the following sections:
EE Prerequisites
In the Prerequisite section, you establish whether this step is required for the
current document and whether it will be executed. A typical query is, for exam-
ple, the transaction code according to this (BKPF-TCODE) to check the origin of
the document as well as all fields from the document header (Callup points 1
and 2), and the document items (Callup point 2).
EE Check
In the Check section, you specify a condition that must be fulfilled to run the
program without errors and therefore to post the document. You can check all
fields for specific contents or constants, and you can link several field checks if
required.
You can also go to a validation exit for complex checks and carry out the checks
via a normal ABAP coding. To do this, you need to return the result of your
checks to the variable B_RESULT (FALSE or TRUE).
EE Message
In the Message section, you ultimately define the message displayed to the user
if the previously defined check has failed. For documents from MM, the mes-
sage is passed on so that it appears within the MM application if the FI document
cannot be posted because of checks. When you create the initial validation for a
Boolean class, you are asked for a message class that applies to all messages in
this area in the future.
173
Personal Copy for Yang Meteor, user id a8103f58-81fe-4f49-acf6-cfb58959c618
| Callup point | Boolean class | Scope of check |
|---|---|---|
| 0001 | 008 | Document header (BKPF) |
| 0002 | 009 | Document item (BSEG) |
| 0003 | 015 | Total document (BKPF and BSEG) |
第 174 页 / 共 275 页
8 Validation and Substitution of Accounting Documents
Change to Message Class
When you create the validation for a Boolean class, the message class is specified. This
assignment is permanently stored from this time on and cannot be undone when an
existing validation has been deleted. If this assignment is changed, use Report RGUGBR28
(see SAP Note 6975). Then start Program RGUGBR00 (without the last two options) to
regenerate the validations substitutions and rules.
8.1.3 Example without Exit Routine
Now that you understand the basic concepts for validation, the following brief
example shows you how to set up a validation. Of course, your actual checks will
be considerably more comprehensive. However, we’re only describing the under-
lying concept at this point.
Let’s assume that your financial accounting department wants to have a specific
classification key for evaluations in the field item text (BSEG-SGTXT). The assign-
ment key might, for example, display an area of your enterprise so that it can be
displayed quickly in lists on open items. You should make sure that this field is
entered correctly in Logistics Invoice Verification. The item text is copied auto-
matically from the respective text field (DRSEG-SGTXT) of the incoming invoice.
However, check to make sure a text is entered here. The classification keys that are
predefined by financial accounting all start with OS. Therefore, check whether this
text is at the first two positions of the entered text.
1. Start Transaction OB28. In the initial screen (see Figure 8.2), you can create
a validation for each company code and time. In the example, a check of the
document items is executed, that is, for Callup point 2. If, in your case, a vali-
dation already exists for this callup point, you can navigate to this point by
double-clicking the validation. If not, enter any name for the validation, and
then double-click the name. Confirm in the dialog that you now want to create
this validation.
2. In the validation editor (refer to Figure 8.1), check whether your validation is
highlighted in the callup point document item in the left-hand navigation bar.
Then click the Step icon ([Ctrl] + [Shift] + [F5]) to insert a new step.
3. Give the step a name, for example, “SGTXT: Check classification key”, and
switch to the Prerequisite section.
174
© 2013 by Galileo Press Inc., Boston (MA)
| Change to Message Class |
|---|
| When you create the validation for a Boolean class, the message class is specified. This assignment is permanently stored from this time on and cannot be undone when an existing validation has been deleted. If this assignment is changed, use Report RGUGBR28 (see SAP Note 6975). Then start Program RGUGBR00 (without the last two options) to regenerate the validations substitutions and rules. |
第 175 页 / 共 275 页
Validation of Accounting Documents 8.1
Figure 8.2 Initial Screen to the Validation
4. You can carry out the prerequisites by choosing the fields from the List of the
Structures by double-clicking and inserting comparisons on the operators on
the right-hand side. If you choose this variant, you can change the view via
menu path Settings • Technical Name so that you can see the technical field
names. Switch back again to the standard view via menu path Settings • Short
Descriptions.
For experienced users, you can switch to a mode via Settings • Expert Mode,
which allows the direct input of conditions. You can now perform this change
at least for this example.
5. The check only runs if the document originates from the Logistic Invoice Veri-
fication (Transaction MIRO) or the parked document (Transaction MIR7). Also,
the text is only copied into GL account lines, not into the vendor line. For this
reason, the check may only take place when the account type (BSEG-KOART) is
‘S’ for GL account. Enter the prerequisite as shown in Listing 8.1.
BSEG-KOART = ‘S’ AND
( BKPF-TCODE = ‘MIRO’ OR BKPF-TCODE = ‘MIR7’ )
Listing 8.1 Prerequisite for the Validation
6. Now switch to the Check section. The GL account lines must have an item text
that starts with OS. For this, you can simply use the asterisk as the usual place-
holder. However, you need the keyword LIKE as a relational operator. Enter the
following line as a check:
BSEG-SGTXT LIKE ‘OS*’
7. A message is displayed if the previous check fails. You maintain these in the
section Message, to which you now navigate to. At this point, you can view
the message class in which the messages for the validation are stored. You can
175
Personal Copy for Yang Meteor, user id a8103f58-81fe-4f49-acf6-cfb58959c618