R/3 systems provide the flexibility to support a diverse list of logistics processes including purchase orders, deliveries, invoices, price determination, pricing calculations, as well as many others. Each of these processes often comes with its own set of demands. Using transaction code VOFM, you can maintain standard routines and create and deploy customized routines that meet your business's individual requirements.
Key Concept
VOFM routines consist of a few lines of ABAP code maintained via transaction VOFM. SAP ships an extensive set of standard VOFM routines with R/3 systems, which can also support customized routines.
Employing routines via transaction code VOFM is one way of embedding versatility into
your business rules for many logistics processes. VOFM provides a central interface for creating and
maintaining routines, which are short but powerful pieces of standard or custom code that add flexibility to your business
processes.
I will introduce you to VOFM routines and provide you with an overview of what they can do. In addition,
I'll show you some standard VOFM routines that SAP provides and discuss how you can create your own.
What Are VOFM Routines?
VOFM routines satisfy business rules, such as if a pricing indicator is set as blank, the product is sold
free of charge. They also allow you to convert quote-to-contract business rules only if the quote has not expired or copy
partners from quote to contract. In addition, VOFM
routines allow products belonging to a particular product group to be sold only to wholesale customers and
calculate profit margin as net value minus cost of the item.
Not surprisingly, VOFM routines are used across many logistics processes like purchase orders, deliveries,
invoices, price determination, material determination, message determination, free goods, and pricing calculations. And
you can use their power in many more situations!
Because VOFM routines are included in many logistics business processes, standard SAP systems offer
hundreds of them. If you have custom business requirements that cannot be met by those shipped by SAP, you can create your
own VOFM routines. The beauty of VOFM routines is that even if you develop routines of your own, they are still included
as a part of the standard processes. For example, if you create a VOFM routine to determine situations when a product can
be sold free of charge, standard pricing calculations can call this newly created routine and adapt the calculations based
on the new business logic.
VOFM routines are divided into four main areas: requirements, copying requirements, data transfer, and
formulas (Figure 1). SAP R/3 assigns a number to identify each routine. In each area, standard delivered
routines are numbered 1-599, except for the structure of group key formulas (namespace 1-49, customer namespace 50-99).

Figure 1
The four main areas of VOFM routines
Clients can also create their own VOFM routines. The customer namespace numbers range from 600-999 and
should be used when creating custom VOFM
routines to prevent them from being overwritten during an upgrade. I explain how to create your own VOFM
routines later.
Let's look at the various routine categories. For each, I will provide an example from standard delivered
routines as well as an example of a custom business requirement. (See "VOFM Routines" sidebar below for more details.)
Requirement Routines
Requirement routines return a true or false result and define conditions that must be satisfied before an
action can take place. A requirement routine in pricing can be used to check a document's currency and allow access only
when it is a local currency. Similarly, a material determination requirement specifies under what conditions to contact a
material determination record.
Requirements improve system performance by avoiding unnecessary calls to the database. For instance,
unless the foreign currency requirement is met, the system does not access the currency database.
Pricing requirements are requirement
routines used within sales pricing calculations that define when to enter the pricing database. These
requirements are assigned to a condition type in a pricing procedure or to an individual access in an access sequence.
Access can only be made if the requirement is met.
The code for standard delivered pricing requirements use two common work areas:
KOMK — Pricing communication structure containing header-related fields from the
sales document
KOMP — Pricing communication structure containing item-related fields from the
sales document
In the typical pricing procedure shown in Figure 2, one of the condition types in column
CTyp is PR00. If a pricing procedure requirement is assigned to PR00,
the system checks to see that it is met. If it is, then the system continues to look for prices using the assigned access
sequence, and if not, the system skips that condition type and goes to the next level of the pricing procedure. The same
process is followed for individual levels of an access sequence. If a requirement is assigned to an access sequence level,
then access is only allowed if the requirement is met.

Figure 2
Standard pricing procedure uses requirement routine 2
In Figure 2, note that typically condition types are assigned to requirement 2 in column
Reqt. Pricing requirement 2 is available as a standard routine and represents an item with pricing. The
ABAP coding for routine 2 is displayed in Figure 3 on the next page. It first sets the
result to false (line 3, sy-subrc = 4). Then it checks whether the pricing indicator is relevant for pricing,
either X or B (line 5, check: komp-prsfd ca ‘BX'.) If the pricing indicator is set to relevant for
pricing, then the result is set to true (line 8, sy-subrc = 0).

Figure 3
Pricing requirement routine 2
Pricing requirement 2 checks whether a document item category is relevant for pricing,
because in some cases there will be no pricing. For example, item category TANN represents free-of-charge
items and these items are priced at zero. It does not make sense to determine the condition type value using the condition
technique in this instance, so the requirement is set to 2.
By understanding standard requirement routines, you can extend their use to create custom requirement
routines. Let's say that your business requirement is to determine a condition type value only if the product has a make-
to-order planning strategy. Because the standard SAP R/3 system does not have such a pricing requirement, you can define a
custom pricing requirement like the one in Figure 4 on the next page. This custom program
(981) first sets the result to false (sy-subrc = 4) and then determines the planning
strategy from the MARC table, which contains plant date for material master records. If make-to-order is
the planning strategy, then the result is set to true (sy-subrc = 0). Once the custom requirement is
activated, it can be assigned in the pricing procedure.

Figure 4
Requirement 981 is a custom routine to check that a part is make to order
Copying Requirement Routines
The copying process copies source documents to target documents. For example, it copies sales documents to
deliveries. Copying requirements help you define company-specific business rules so that you can define certain
situations that can prevent subsequent document creation.
If your business process involves
prerequisites, then copying requirements can check what these conditions are. A copy requirement can be used
to ensure that a sold-to customer is the same in the reference and target document, for example. It can also determine
whether a quotation may be copied into a standard order or if text items can be transferred when copying a delivery into a
billing
document.
Copy requirements are defined in the appropriate Customizing area. For example, a new order copy
requirement is assigned to the copy rules for sales
documents. A text copy requirement is assigned to the access sequence for the text type.
The standard SAP R/3 system delivers the orders copying requirement 1, which checks that
the source sold-to matches the target sold-to. In addition, it checks whether the reference quotation has already expired.
If the reference quote is already expired, the system delivers a standard system warning message. You can create a custom
copying requirement to make the warning message appear as an error and prevent users from processing the order if the
reference quote is already expired (Figure 5).

Figure 5
Custom copying requirement (routine 901) to generate an error message
Data Transfer Routines
The data transfer process copies data from a source to a target object and allows you to define business
rules for data transfer processes. A data transfer routine, for example, can allow the transfer of general billing header
data from a reference document into a target. They can also adjust fields transferred from reference documents to sales
orders. Data transfer routines are an easy way to move and manipulate fields from source documents to target documents.
Data transfer routines are defined in the appropriate area in Customizing. For example, a new data
transfer routine for the order header is assigned to the
relevant sales document type, and a new data transfer routine is maintained in copy control for sales
documents. A data transfer routine for texts is assigned to the access sequence for the text type.
When transferring data from one sales order to another, it is also necessary to transfer the partner roles
from the reference to the target. For this purpose, the standard SAP R/3 system provides orders data transfer routine
1, which
transfers the partner's header from the
reference document to the target document header. Invalid partners are removed after this routine and
missing partners are filled in automatically. An example of a custom data transfer routine is to copy the customer's
contract number while creating a debit or credit memo with reference.
Formula Routines
In simple terms, formulas are VOFM
routines that define how a value should be calculated or determined in the system. For instance, a pricing
condition value formula enables you to define how a specific pricing value should be calculated. Similarly, a rounding
rule formula defines how rounding should take place when pricing via mass maintenance such as when all list prices are
increased 10%.
Condition value formulas influence how a condition value determines a particular condition type. In
standard pricing calculations, the condition value is calculated by multiplying the condition rate by the quantity. For
example, 100 units times $23 per unit equals $2,300. Using a condition value formula, it is possible to alter the
condition value, in our example $2,300. Condition value formulas are used in pricing procedures, such as line
950 in Figure 6.

Figure 6
Condition value formula 11 determines the profit margin
Formula routines are entered in the appropriate area such that a condition value formula is assigned to
condition types or value lines in a pricing procedure. Or, a free goods calculation rule is assigned to a free goods
condition record.
The standard SAP R/3 system offers
condition value formula 11 shown in Figure 6 to compute the profit margin for a line item.
To do this, the cost of the item is subtracted from the net value. This formula is then assigned to a value line at the
end of a pricing procedure to visually depict the profit margin for the item.
You can extend the logic to determine the condition values using formula routines for specific custom
requirements. For example, you could create your own custom condition value formula to determine the seasonal discount
conditions, as shown in Figure 7.

Figure 7
Typical pricing procedure that uses formula routine 981
Create a VOFM Routine
When creating your own VOFM routines, use the customer namespace 600-999 to ensure that it is not
overwritten during an upgrade and follow these five basic steps:
- Use transaction VOFM and click on the appropriate area (requirements, copying
requirements, data transfer, or formulas).
- Either overwrite an existing requirement or enter a new number on a new line within the customer
namespace and enter a short description of your routine.
- Program your routine in the ABAP editor and save the code. Note, before you complete this step, I
recommend that you review some standard SAP routines to see how they are programmed and follow similar logic.
- Click on Edit>Activate to activate the new VOFM routine.
- If it is to be used in a specific application area, enter the application the
routine will be used in such as Sales and Distribution or Purchasing.
Tip!
Before creating your own custom routine, check to see if you can use one of the standard routines delivered with the R/3 system.
Once you create and activate a routine, you can use it within appropriate area of Customizing. For
instance, you may assign a new pricing requirement to a
condition type or an access sequence.
VOFM Routines
SAP uses VOFM routines throughout the system and across many business processes. Here is a list of the standard routines that ship with R/3 and how they are used, along with any special instructions applicable to customization.
Requirement Routines — This group of VOFM routines establishes that the system only processes an entry if a certain requirement is met.
Pricing — define when an access should be made within pricing calculations and can be assigned to an individual access within an access source or a condition type in a pricing procedure. Pricing requirements can eliminate unnecessary accesses to the database and improve performance.
Output Control — identify when a particular output document should be processed and can be assigned to a condition type in an output procedure. These requirements specify when output should be created to eliminate unnecessary output.
Account Determination — establish when an access should be made during an account determination routine and can be assigned to a condition type in an account determination procedure.
Material Determination — eliminate unnecessary accesses to improve performance by defining when an access should be made within material determination functions. Assigned to a condition type in a material determination procedure.
Listing/Exclusion — indicate when the system should access listing/exclusion records and is assigned to a condition type in a listing/exclusion determination procedure.
Free Goods — define under what conditions the system should look for free goods agreements and is assigned to condition types in a free goods determination procedure.
Risk Management — establish when a level in the payment guarantee procedure should be processed.
Credit Checks — set when the system should carry out certain credit checks and assign them to the automatic credit controls.
Payment Card Authorization — determine when an authorization process should occur.
Subsequent Function — govern when certain system functions occur such as confirming an available-to-promise (ATP) quantity, create a purchase requisition for a sales document line item, etc.
Copying Requirement Routines — Establish when certain documents will be copied and verify that the characteristics of the reference and target are consistent with precondition definitions for copying before allowing a document to be copied.
Orders — control when to allow copying from an order to a subsequent document using copy routines that verify the characteristics of the reference and target sales documents.
Deliveries — define preconditions to allow a delivery to be created and verifies that the characteristics of the reference sales document are consistent with the definitions of the copy requirement. If the requirements are not met, a message is displayed.
Billing Document — define when copying from a preceding sales documents is permitted by verifying the characteristics of the reference sales documents are consistent with the definitions of the copy requirement prior. If the requirements are not met, a message is issued.
Texts — determine when texts should be automatically transferred from source document to target document. These routines are assigned to determination access sequences, and texts will be copied to the target.
Data Transfer Routines — Control data transfer from fields in source documents to the documents listed below when they are created.
Orders — dictate specific fields to be transferred from reference documents into order documents when the sales order documents are created.
Deliveries — set the fields to be transferred to delivery documents during the copying process while creating the delivery document. When customizing, these routines are assigned to the data transfer routine field in the copy rules for delivery document type/item category.
Billing Documents — transfer fields during the copying process into billing documents when they are created. When customizing, these data transfer routines are assigned to the data transfer routine field in the copy rules for billing document type/item category.
Sales Activities — identify fields to be transferred into sales activities while creating the sales activities. In Customizing, these data transfer routines are assigned to the data transfer routine field in the copy rules for the sales activity type.
Shipping Units — transfer shipping unit details while copying a scheduling agreement into the delivery document as it is created. These routines are assigned to the data transfer routine for shipping unit fields in the copy rules for the delivery type when customizing.
Texts — move texts from source reference document into the target using data transfer routines that will transfer and manage texts in the copy procedure. In Customizing, these data transfer routines are assigned to the access sequence field for data transfer for the text type.
Text Names — manage how text is stored in the system so it can be retrieved later for printing and display. They define the pointers from the source sales documents to the database and are specified in the standard programs for text determination.
Shipment — transfer fields from deliveries into shipments while creating the shipment. In Customizing, these data transfer routines are assigned to the copy routine field in the shipment document type.
Formula Routines — define how a value should be calculated or determined in the system.
Scale Base — modify the value that the system uses to read the scales (quantity, value, weight, etc.) for a condition record during pricing calculations.
Condition Base Value — adjust the condition basis to which the pricing condition rate will be applied. In standard pricing, the system will apply the condition rate to the quantity in the sales document.
Condition Value — alter the condition value determined for a condition type or a specific line in the pricing procedure.
Structure of Group Key — adjust the basis the system uses when reading the scale of a group condition.
Rounding Rule — establish which rounding is used when a mass change of pricing records takes place.
Calc. Rule Free Goods — alter the way in which free goods quantities are computed within a free goods agreement.

Mitresh Kundalia
Mitresh Kundalia heads the SAP practice at Quality Systems & Software (www.QSandS.com), a consulting firm specializing in SAP S/4HANA, SAP General Ledger, and complex System Landscape Optimization (SLO)-type reorganizations. Mitresh is widely acknowledged as a leading SAP expert, with multiple publications and an SAP-PRESS book to his credit. He has published more than 50 peer-reviewed articles and white papers, and he has given presentations at various SAP conferences and events. Mitresh is the chief solutions architect of General Ledger Migration Optimizer (GLMO), a leading product to accelerate and jump-start the SAP S/4HANA and SAP General Ledger initiatives; SAP Data Reorganization Optimizer (SDRO), an SLO-type product for managing complex system landscape reorganizations; and Group Currency Activation and Conversion (GCAC), a product suite to manage introduction of parallel currencies and conversion of data in a live SAP system.
You may contact the author at Mitresh@QSandS.com.
If you have comments about this article or publication, or would like to submit an article idea, please contact the editor.