Wednesday, September 7, 2022

Creating Heuristics Using Your Own Algorithm

Purpose

You can program heuristic algorithms yourself, link them to the SAP APO system, and define heuristics. This allows you to specifically address your planning requirements.

Caution

Your own heuristics are an enhancement of the SAP planning processes. Note that even small changes or enhancements to the planning processes can lead to unexpected planning results. Any changes or enhancements you make are at your own risk. SAP cannot be held responsible for any defects or malfunctions resulting from changes or enhancements to the software.

In an integrated system landscape with an SAP R/3 system, you should pay particular attention to whether the changes to planning data and orders are also supported by the CIF interface and by SAP R/3. For example, inspection lots cannot be changed as standard in SAP APO. You cannot change, create, or delete inspection lots using your own heuristics, because SAP does not support the transfer of these changes from SAP APO to SAP R/3.

Note

SAP provides BAdIs for some standard heuristics – for procurement planning heuristics, for example. Before you program your own heuristics, check if you can use a BAdI. For more information, see the Implementation Guide for Production Planning and Detailed Scheduling (PP/DS) under Business Add-Ins for PP/DS.

Process Flow

Copy the function group /SAPAPO/RRP_HEUR_TEMPLATE under a new name. This is used as a main program for the subscreen in which you maintain settings for the heuristic. A dialog box appears that contains a list of the function modules that are to be copied. Copy and rename the following function modules:

Function module for the algorithm /SAPAPO/HEU_TEMPLATE

Get function module /SAPAPO/HEU_TEMPLATE_DATAGET

This function module is used to read the output structure for the screen.

Set function module /SAPAPO/HEU_TEMPLATE_DATASET

This function module is used for input into the output structure of the screen.

Create an output structure for the subscreen in the ABAP Dictionary. You can use the structure /SAPAPO/HEU_TEMPLATE_D1000_STR as a template.

Replace the name of the template output structure with your output structure name everywhere this appears in the function group, for example, in the


Top include

Set function module

Get function module

Subscreen 1000

Use the subscreen 1000 for the maintenance of the heuristic settings.


The structure /SAPAPO/HEUR_SETTINGS contains the tables in which the settings for the heuristics are stored on the database. Use one of the existing tables or create your own include structure in the table structure /SAPAPO/HEURCUST.

Modify the function modules to ensure that the relevant settings stored in the structure /SAPAPO/HEUR_SETTINGS are copied into the relevant fields of the output structure for the subscreen.

Modify the get function module to ensure that the fields of the output structure are copied into the relevant fields of the structure /SAPAPO/HEUR_SETTINGS.


Program the algorithm function module.

The interface consists of import and export parameters.

Import parameters include:

Relevant settings /SAPAPO/HEUR_SETTINGS

Planning version: You must ensure that this data is transferred to SAP liveCache.

Simulation version: You must ensure that this data is transferred to SAP liveCache.

The structure /SAPAPO/HEUR_OBJECT_KEYS. This structure contains the tables with the planning objects (resources, line networks, products, orders, and operations).


Export parameters include:

(E_CHANGED_OBJECTS). This updates the objects in the main program.

(E_OBJECT_KEYS). This is used during background planning to transfer the objects from one processing step to another.

Note

For an example of how algorithms are programmed, see the algorithm for the standard heuristic SAP001 Standard lot-sizing heuristic .

To integrate the heuristic into the SAP APO system, enter the following objects in the table /SAPAPO/HEURFUNC:

The function module for the planning algorithm

Function group

The subscreen

The set function module

The get function module

In the table /SAPAPO/HEURFUNC, you also have to define:

Where the heuristic can be executed – for example, in the production planning run or in the DS planning board

The objects for which it can be executed – for example, for products or for resources

Whether the heuristic is a procurement planning heuristic that you can enter in the location product master as a product heuristic

You define this using the PROD_HEUR field. After a planning run using the heuristic, the system only resets the planning file entry for a product if you have flagged the heuristic in the table as a product heuristic.

Create a heuristic in Customizing for Production Planning and Detailed Scheduling based on the algorithm you have defined. For more information on defining heuristics, see the Implementation Guide (IMG) for Production Planning and Detailed Scheduling (PP/DS) .

Note

You can create and connect system documentation for the algorithm.

To create the documentation, create a Dialog Text using transaction SE61. Create and activate the text.

To connect the documentation to the algorithm, proceed as according to SAP note 613189.

To call the system documentation, in Customizing for Production Planning and Detailed Scheduling (PP/DS), under Maintain Heuristics , select the Information icon for the heuristic.


Friday, April 14, 2017

How to get strategy and consumption modes for the Product location combination in SAP APO??

Its not straight to find strategy and consumption modes for the Product location combination in SAP APO. However, this data may be needed for your custom development.
I would suggest to use the function module /SAPAPO/DEM_STRA_ALL to get the strategy and consumption modes and related values.
The relevant table is: /SAPAPO/MATRQ

 

Sunday, March 22, 2015

SAP APO unit conversion


1. To get the Base Unit of Measure, use the FM:

  CALL FUNCTION '/SAPAPO/DM_MATID_GET_MATERIAL'
       EXPORTING
            iv_matid           = iv_matid
       IMPORTING
            ev_meins           = lv_meins --> Here you will get base unit of measure
       EXCEPTIONS
            material_not_found = 1
            OTHERS             = 2. 

2. Now, use the following FM to get the factor between base unit of measure and the alternative unit of measure.

CALL FUNCTION '/SAPAPO/DM_UNIT_CONVERSION'
       EXPORTING
            i_matid            = iv_matid
            i_meins_from       = iv_basme
            i_meins_to         = lv_meins
       IMPORTING
            e_umref            = lv_factor
       EXCEPTIONS
            material_not_found = 1
            conversion_error   = 2
            OTHERS             = 3.
3. Multiply the quantity with the factor, to get the converted quantity in alternate unit of measure.

Tuesday, August 19, 2014

SAP APO BAdI Enhancement


SAP APO BAdI Enhancement: 

/SAPAPO/RRP_PLANNING

/SAPAPO/RRP_IO_COL

Wednesday, July 9, 2014

SAP APO CIF Debugging


SAP APO CIF Debugging Tips

1. Stop all the CIF queues:
In General, the if your are ok to stop all the CIF queues, then use the transaction SMQR and then "Deregister" the CF* queues. It will stop all the CIF queues. This transaction (SMQR) is available in APO and ERP system. As per the requirement stop the CIF queue in required system.

2. Stop CIF queues for the specific user

Generally in the productive environment above mentioned approach will not work, as we can not stop all the CIF queues (CF*), hence we need to stop user specific queues.
A) To stop user specific inbound queues in the R/3 system, go to transaction /SAPAPO/C4 and add your   user id, with options :
Logging:    As per you requirement.
Debugging: Debugging On, Recording of t/qRFCs (NOSENDS)
recording: Default

B) To stop user specific inbound queues in the APO system, go to transaction CFC2 and add your user id, with options :
RFC Mode : Queued RFC
Logging:    As per you requirement.
Debug: R (Debugging is activated and t/qRFCs are only recorded)

Note: CFC2 transaction required transport request. If you don't have transport request in that case the CFC2 entries can be directly maintained in CIFGPARAMS table.


Once the queue is stopped, then double click on the queues and you will find debug button. Here you can start your debugging.

Also, if you want to see the data in the internal table of the queue then double click on teh queue and you can find the data in the internal table.

Monday, July 7, 2014

Useful function modules


/SAPAPO/DM_PROD_LOC_READ  - Multiple matid & locid related data
/SAPAPO/LOC_GET_LOCT -- FM to get the location text
/SAPAPO/DM_MAT_TEXT_GET - material text

Function modules related to resource:
/SAPAPO/BLRG_RESNAME_GETRESUID - From res. ID get the resource name

Function Modules SAP APO Transportation lanes
  Read the overall transportation lanes
    '/SAPAPO/TR_TR_READ'
  Read means of transport
      '/SAPAPO/TR_TRM_READ'
    "Read version-dependent means of transport
        '/SAPAPO/TR_GET_TRMV'
  Read product-specific lanes
    '/SAPAPO/TR_TRPROD_READ'
  Read version-dependent sources of supply
      '/SAPAPO/TR_GET_TRPRODV'
  Read product-specific means of transport
      '/SAPAPO/TR_TRPRODM_READ'
  Read Transport Service Providers
      '/SAPAPO/TR_TRMCARR_READ'
  Read procurement relationships
      '/SAPAPO/MMPUR_TPSRC_GET_ALL'

APO Function modules related to timestamp
/SAPAPO/TIMESTAMP_ADD - Time Stamp 1 + Duration = Time Stamp 2
/SAPAPO/DURATION_GET_SECONDS-  Determines Duration in Seconds from Duration HHHHHH:MM:SS
/SAPAPO/SECONDS_GET_DURATION - Converts Duration in Seconds to Format HHHHHH:MM:SS
/SAPAPO/TIMESTAMP_DIFFERENCE - Time Stamp 1 - Time Stamp 2 = Duration
/SAPAPO/TIMESTAMP_SUBTRACT - Time Stamp 1 - Duration = Time Stamp 2
/SAPAPO/TIMESTAMP_ZONE_TO_UTC - local timestamp to UTC
/SAPAPO/TST_UTC_TO_LOCAL - UTC to local timestamp, date, time
Also, the abap command  GET TIME STAMP FIELD could be used to get the current timestamp.

APO MRP Related FM
'/SAPAPO/RRP_LC_IO_SCHEDULE' - Function module to reschedule an order. Here only the end data should passed for an order. The start date will be calculated automatically by the FM. If the start date is having date less than the plan start date (plan start date, is calculated according to the strategy settings) then this FM module will give the error, with code 44. Hence check beforehand the how much time is required to complete the order and calculate the start date and then check start date with plan start date.




Substract the seconds from the timestamp:

CALL METHOD CL_ABAP_TSTMP=>SUBTRACTSECS
  EXPORTING
    TSTMP   = TIME_STAMP
    SECS    = L_SECONDS
  RECEIVING
    R_TSTMP = TIME_STAMP.

Sunday, July 6, 2014

SAP APO Macro workbench


SAP APO Macro workbench

Transaction : /SAPAPO/ADVM

Macro Function modules:

Macro function module can be designed in the following way!
1. Go to  Transaction  /SAPAPO/ADVM
2. Double click on the planning book / data view
3. Goto Menu -> Edit -> Edit user function
4. Now, the pop up will appear. In this pop up give the user function name.
5. Click on Continue button. Which will give you another pop up window, in which exporting, tables and changing parameters would be availalble for the function module.
6. In general, one can select plob values, selid. (However, it is all dependant on your requirement).
7. value table, f argument and f calc error, will be by default selected.
8. Now, click on the save button.
9. Now, go to transaction SE37. Create a new fucntion module with the same name and parameter values as selected in the step 6 and 7.
10. Write your custom code in the user function module and call this function module in the macro as per your requirement.

Useful function modules for macro function module:
 /SAPAPO/MSDP_GET_PLOB_VALUES - Reads Displayed Planning Objects
If you loop on the selection table (where iobjnm  INTERN_MATLO ) getting out of the above FM, then you can get the matloc id.



Macro User exit and BAdI : 

User exit macro can be implemented through  user exit enhancement APODM005.
Go to transaction SMOD and then go to Enhancement:APODM005.
Alternativly you can goto transaction SE37 and look into function module EXIT_/SAPAPO/SAPMMCP6_005
In the IF clause, check for the i_macro_name = 'Your macro name' and if the condition is true then you can process your custom code, according to business logic.