Source: APICS Guidelines for ERP
Saturday, July 30, 2011
Sunday, July 24, 2011
Monday, July 18, 2011
Tutorial on ABAP custom macro functions in APO macro building
source:http://apolemia.blogspot.com/2008/02/tutorial-on-abap-functions-for-dp.html
It seems that there is no standard function to calculate the statistical mode. So I thought it would make a good example for a short tutorial on creation of ABAP functions to be used in planning macros.The macro functions are standard functions created with SE37 that must have a specific call signature (input and output parameters and tables). The base parameters are the ones shown in the following figure (later other options are presented).

The VALUE_TAB structure has two fields, one for numbers and one for strings. All input parameters set in the macro are added to this table in the same order as defined in the macro, in the number or string field depending on the data type.
For our exemple the function will receive a list of numbers. The goal is to calculate the mode of the integer part of the numbers. Since the mode can be a list of several numbers, we intend to return the largest integer number of the list.
Bellow is the code for such a function. It just counts the frequency of the numbers (after convertion to integers). The final list is sorted and the mode (or maximum of modes) is returned on the output parameter field F_ARGUMENT. The other parameter F_CALC_ERROR is a flag that should be set in case of errors that cannot be handled (the equivalent of raising an exception).
FUNCTION z_macro_maxmode .
*"----------------------------------------------------------------------
*"*"Local interface:
*" TABLES
*" VALUE_TAB STRUCTURE /SAPAPO/VALUE_TAB
*" CHANGING
*" REFERENCE(F_CALC_ERROR) TYPE C
*" REFERENCE(F_ARGUMENT) TYPE /SAPAPO/MXSOP-V
*"----------------------------------------------------------------------
TYPES:
BEGIN OF t_histogram,
value TYPE i,
counter TYPE i,
END OF t_histogram.
DATA:
lv_value TYPE i,
ls_hist TYPE t_histogram,
lt_hist TYPE TABLE OF t_histogram WITH KEY value.
LOOP AT value_tab.
IF value_tab-string IS INITIAL.
CLEAR ls_hist.
* just truncated integers to make it simpler
lv_value = trunc( value_tab-value ).
READ TABLE lt_hist WITH TABLE KEY value = lv_value INTO ls_hist.
IF sy-subrc = 0.
* already in the table, increase the counter
ls_hist-counter = ls_hist-counter + 1.
MODIFY TABLE lt_hist FROM ls_hist TRANSPORTING counter.
ELSE.
* insert value for the first time in the table
ls_hist-value = lv_value.
ls_hist-counter = 1.
INSERT ls_hist INTO TABLE lt_hist.
ENDIF.
ENDIF.
ENDLOOP.
* return the integer with largest counter (if more than one return the
* largest integer)
SORT lt_hist BY counter DESCENDING value DESCENDING.
READ TABLE lt_hist INDEX 1 INTO ls_hist.
f_argument = ls_hist-value.
ENDFUNCTION.Now this function can be added to the macro builder (/sapapo/advm). First one registers the function using the following menu option.


A list of parameters is shown. The previous macro only uses the base parameters so no other checkbox is flagged, but here is the place to choose the parameter options.

Then the macro is created with the new function being called like the standard ones.

I've found that moving logic to ABAP functions can be a good way to simplify complex macros.
Tuesday, June 21, 2011
Cross-System Stock Transfer Using Purchase Order and Sales Order
Source:http://help.sap.com/saphelp_46c/helpdata/en/4d/2b90dc43ad11d189410000e829fbbd/content.htm
Cross-System Stock Transfer Using Purchase Order and Sales Order 
Purpose
You want to transfer material from one plant to another. Each plant has its own SAP R/3 system. Both SAP R/3 systems are connected to an SAP APO system.
In the scenario described here, the stock transfer is carried out using a purchase order in the receiving plant and a corresponding sales order in the issuing plant. In SAP APO, the plants are represented as the source and target location.
Prerequisites
You are working with SAP R/3 4.0B or higher.
In the Supplying SAP R/3 System
· The SAP R/3 system ordering the material (the ordering plant) must be created as a customer. The customer does not have to be transferred to SAP APO.
· An active integration model must exist for materials, plants, and customers, and the master data must be transferred to SAP APO.
· An active integration model must exist for sales orders and stocks (deliveries are contained in the integration model for sales orders) so that these objects can be transferred between SAP R/3 and SAP APO, and so that the changes to stock that this results in can also be transferred.
· SAP Notes 421200 and 515019 must be implemented.
In the Ordering SAP R/3 System
· The SAP R/3 system supplying the material (the supplying plant) must be created as a vendor. The vendor does not have to be transferred to SAP APO.
· An active integration model must exist for materials and plants, and the master data must be transferred to SAP APO.
· An active integration model must exist for purchase orders, purchase requisitions, and stocks so that these objects can be transferred between SAP R/3 and SAP APO, and so that the changes to stock that this results in can also be transferred.
· A purchasing info record must be created in the ordering SAP R/3 system and transferred to the SAP APO system. If this has not been done, the system uses the vendor location and not the plant location as the source of supply for the order in SAP APO.
· When transferring the purchasing info record, SAP APO creates an external procurement relationship and a transportation lane between the two plants. For SNP (not for PP/DS), you must also create a means of transport for this transportation lane in SAP APO.
The purchasing info record or scheduling agreement can only be transferred to SAP APO once the mapping between the location, the vendor, and the customer has been completed, using transaction /SAPAPO/LOCALI. Otherwise, SAP APO would create a transportation lane between vendor and plant when the purchasing info record or scheduling agreement was transferred. If this case, the requirements for the stock transfers would be created in SAP APO in the vendor location and not in the plant location.
In the SAP APO System
· You need to make the following assignments (mapping) in SAP APO so that the customer and vendor in SAP R/3 can be mapped to the corresponding locations in SAP APO (and vice versa):
a. Use transaction /SAPAPO/LOCALI in SAP APO to call the screen Change View "Location Alias": Overview. In the transaction /SAPAPO/LOCALI, you must use leading zeros for numeric customer and vendor numbers. The number of leading zeros depends upon the number of digits in the corresponding number ranges in SAP R/3.
For the customer, you must define the number of the ship-to-party in the transaction /SAPAPO/LOCALI. If you do not do this, the release order is not deleted in SAP APO when the sales order is transferred to SAP APO.
For the customer, you must define the number of the ship-to-party in the transaction /SAPAPO/LOCALI. If you do not do this, the release order is not deleted in SAP APO when the sales order is transferred to SAP APO.
b. Assign the customer number to the receiving plant:
§ Under LogSystem, enter the logical system that represents the supplying SAP R/3 system.
§ Under Location, enter the key of the ordering SAP APO location (the receiving plant).
§ Under Alias, assign the external key of the ordering SAP APO system (the customer number)
§
§ For this combination, select under Operation the operation type Stock Transfer: Customer and under Loc. Type the location type Customer.
c. Assign the vendor number to the issuing plant:
§ Under LogSystem, enter the logical system that represents the ordering SAP R/3 system.
§ Under Location, enter the key of the supplying SAP APO location (the issuing plant).
§ Under Alias, assign the external key of the supplying SAP APO system (the vendor number)
§ For this combination, select under Operation the operation type Stock Transfer: Vendor and under Loc. Type the location type Vendor.
· In SNP and PP/DS, the settings for carrying out planning must exist. For more information, see
Supply Network Planning Process and
Production Planning and Detailed Scheduling (PP/DS).
Supply Network Planning Process and
Production Planning and Detailed Scheduling (PP/DS).· Transportation lanes must exist. For more information, see the section on Integrating Sources of Supply in Purchase Orders and Purchase Requisitions.
· The distribution definition must be maintained in the SAP APO implementation guide. This determines to which system SAP APO publishes the external procurement documents. Select the publication type External Procurement and assign to it the number of the receiving location and the logical system of the SAP R/3 system.
· For SNP, you have to specify in the implementation guide for SAP APO whether the stock transfer documents generated in SAP APO are transferred to SAP R/3 directly, periodically or not at all. For this, choose SAP Advanced Planning and Optimization (SAP APO) ® Supply Chain Planning ® Supply Network Planning (SNP) ®Basic Settings ®Configure Transfer to OLTP Systems. For deployment, you must also specify whether the system is to generate purchase orders or purchase requisitions. You can find more information on conversion under point 2 in the Process Flow section.
· For PP/DS, you must specify in the implementation guide in SAP APO whether transfer events are generated for the Transfer to SAP R/3 External Procurement. The events can either always be generated, according to the conversion indicator, or not at all. To specify this, choose SAP Advanced Planning and Optimization (SAP APO) ® Supply Chain Planning ® Production Planning and Detailed Scheduling (PP/DS) ® Global Settings ® Maintain Global Parameters and Defaults. The selection you make depends on when the purchase requisitions are needed in SAP R/3. For more information, see
Transferring Orders to the SAP R/3 System.
Transferring Orders to the SAP R/3 System.· In the application menu for SAP APO you have to set whether changes for certain users should be published immediately or periodically to SAP R/3. To do this, choose Tools ®APO Administration ®Integration ®Settings ®User Settings. For more information, see Publication of Planning Results.
Process Flow

...
1. The SNP planning run generates an SNP stock transfer.
If deployment or the TLB run do not take place and the result of SNP planning run is to be used, the SNP stock transfer can be transferred directly to the SAP R/3 system of the receiving plant.
If deployment or the TLB run do not take place and the result of SNP planning run is to be used, the SNP stock transfer can be transferred directly to the SAP R/3 system of the receiving plant.
If you execute requirements planning in the supplying SAP R/3 system, you can transfer the distribution demand that was planned in SNP to the supplying SAP R/3 system as a planned independent requirement. This takes place as background processing in Demand Planning (transfer to SAP R/3 in the activity definition). For more information, see
Transferring the Demand Plan to SAP R/3 Demand Management.
Transferring the Demand Plan to SAP R/3 Demand Management.The prerequisite for this is that you create a new planning book and data view with the period unit "days." For this, you can copy the standard book SNP94 (mixed period units are used in the standard book).
2. In most cases, a deployment run takes place after the SNP planning run. This generates a deployment stock transfer (see also, System-Internal Stock Transfer Using Stock Transfer Orders). This, in turn, creates a purchase order or purchase requisition during the transfer to the ordering SAP R/3 system. If a purchase requisition is created, you can transfer the distribution demand that was planned in deployment to the SAP R/3 system as a planned independent requirement, as described above.
If only purchase requisitions are generated in the deployment run or if you are only working with SNP, the purchase requisition can be converted to a purchase order in either SAP R/3 or SAP APO by setting the conversion indicator in PP/DS.

In particular for SNP planning, we recommend that you only transfer those purchase requisitions to SAP R/3 that are needed there for further processing.

If you are using SAP R/3 3.1, you can only trigger the conversion of a purchase requisition that was created in SNP or deployment in the SAP R/3 system.
3. The planning result of the TLB run is a TLB shipment. This creates a purchase order during the transfer to the ordering SAP R/3 system.
4. For this purchase order, a sales order is created using ALE, batch input, or manually in the supplying SAP R/3 system.
5. The sales order is transferred from SAP R/3 to SAP APO. A sales order now exists for the source location. However, in SAP APO there is no link between the sales order and the purchase order (TLB shipment). This only exists in the two SAP R/3 systems.
If the conversion of the purchase requisition to a purchase order is triggered in SAP APO, SAP APO also creates a goods issue (release order) that corresponds to the goods receipt.
If the conversion of the purchase requisition to a purchase order is triggered in SAP R/3, SAP APO only creates the goods receipt for the purchase order. The corresponding goods issue is only generated when the relevant sales order is transferred to SAP APO from the supplying SAP R/3 system.
6. The supplying SAP R/3 system creates a delivery for the sales order.
7. The delivery is transferred to SAP APO. SAP APO creates a delivery for the source location and reduces the sales order.
8. In the supplying SAP R/3 system, the goods issue is booked to delivery.
9. The change in stock is transferred to SAP APO. SAP APO reduces the stock and the delivery for the source location.
10. If stock in transit is relevant for planning, you have to work with the shipping notification because stock in transit is not yet maintained in SAP R/3. In this case, a shipping notification is created in the supplying SAP R/3 system and transferred to the ordering SAP R/3 system; for example, by ALE. This transfers the shipping notification to SAP APO. SAP APO creates an order confirmation for the target location and reduces the purchase order schedule line.
11. In the ordering SAP R/3 system, the goods receipt is booked to delivery.
12. The change in stock is transferred to SAP APO. SAP APO increases the stock for the target location.
Change Transfer
Since there is no link between purchase orders and sales orders in SAP APO, changes to sales orders and purchase orders can only be synchronized in SAP R/3.
Changes to sales orders (for example, changes to the confirmed quantity or the confirmed dates) are transferred to SAP APO, but do not lead to an adjustment of the purchase order there. In this case, an adjustment to the purchase order can be achieved by sending an order acknowledgement from the supplying SAP R/3 system to the ordering SAP R/3 system. On the basis of the order confirmation, the ordering SAP R/3 system first changes the purchase order and then transfers these changes to SAP APO.
This is also true for changes to the purchase orders themselves. In this case, a purchase order change notice can be sent from the ordering to the supplying SAP R/3 system. The supplying SAP R/3 system adjusts the sales order as required and transfers this change to SAP APO.
For changes to purchase orders, generally only the goods receipt is transferred to SAP APO; that is, a release order is not created.
Purchase order number and sales order item are not allowed to be changed. This is not usually a problem for sales orders that have been created automatically. Sales orders that have been manually created with the incorrect purchase order number or item must be deleted and recreated.
If you are using the ALE Scenario, the changes to sales orders and purchase orders are synchronized using the communication between the SAP R/3 systems. For more information, see
Transferring Goods Between Distributed Systems (SD,MM).
Transferring Goods Between Distributed Systems (SD,MM).The following restrictions apply:
· If the sales order can only confirm a quantity of zero, the corresponding order acknowledgement for the purchase order is not processed.
· If you change an order, there is no check for which status the sales order has in the supplying SAP R/3 system (for example, whether the delivery has already been created).
· The confirmed quantity and confirmed dates are transferred. If only the order quantity changes, not the confirmed quantity, there is no transfer.
· If you delete or create new items in the sales order there is no corresponding adjustment of the purchase order.
· Order confirmations must be created and transferred to SAP APO so that the changes can be posted in SAP APO. The prerequisite for this is that order confirmation has been set as MRP relevant in SAP R/3 Customizing by choosing Materials Management ® Purchasing ® Confirmations ® Set Up Confirmation Control. For more information see
Confirmations.
Confirmations.
Changes in delivery creation can be transferred to the ordering SAP R/3 system as a shipping notice. The shipping notice is also processed as an order confirmation in the ordering SAP R/3 system.
Thursday, June 9, 2011
Subscribe to:
Posts (Atom)





