cancel
Showing results for 
Search instead for 
Did you mean: 

macro requiremnt in DP which is like SNP

Former Member
0 Kudos

Hi Experts,

I have a macro requirement in DP. Please find the details in the below table.

I have a key figures as below

KF1 is quantity

KF2 is NUMERIC

KF3 is quantity

For example

I have a value in KF1 for week1 100, Week2 50, week3 70, week4 100, week5 40, week6 30, and week7 20

Now user will enter the value 3 in KF2 WEEK1 which is numeric

THEN

The result row would be KF3 week1. it should calculate the values in KF1 WEEK2+KF1 WEEK3+KF1 WEEK4 That means 50+70+100 = 220

This 220 should populate in KF3 WEEK1.

USER may put the values either 3 or 2 or 9 and 13, 20, etc...

if it is 2 the the values should consider only  week2 KF1 and WEEK3 KF1. Then the total would be 120 in KF3 WEEK1.

KF3 result would be based the value in KF2 and the KF1 from NEXT week onwards.

week1week2week3week4week5week6week7
KF11005070100403020
KF23
KF3220

If anyone knew the logic please guide how two write this macro in PB.

It NEEDS very urgent.. Thanks before your answer.

Regards

Rajesh

Accepted Solutions (0)

Answers (3)

Answers (3)

rajkj
Active Contributor
0 Kudos

Hi Rajesh,

Your requirement can be met in an indirect way using the standard macro function. It requires you to just use one additional key figure to represent the number of days as shown in the screenshots.

The method described below is based on the standard macro function 'COVERAGE_SUM'.

COVERAGE_SUM()

COVERAGE_SUM (necessary days’ supply ; area containing quantity ; area containing days in the period) returns the total quantity that corresponds to the days' supply required. Instead of the area, you can also enter two sequences with the same number of entries.

For example:

COVERAGE_SUM ( 10 ;
  20 ; 30 ; 40 ; 50
  1 ; 2 ; 7 ; 10 )
provides the sum of the values 20, 30, 40 = 90, since the sum of days in the first three periods corresponds to the necessary days’ supply.

The last parameter of the macro function represents the number of working days in a given week. Our additional key fig is required to cover this data stream.

1. Data view - You need to use an aux. or time series key figure to supply data as shown below (just populate with one for all the periods).

2. Macro implementation - Verify the dates I used for each parameter.

I hope this helps you.

Thanks,
Rajesh K. Jagadeeswaran

Above post is updated to include one more screenshot for easy understanding of the macro implementation.

Caterpillar
Explorer
0 Kudos

Rajesh,

I have been using the coverage_sum function in DP in APO 4.0 for some time without any problems.  However, when migrating our configuration to our new APO 7.0 environment, the coverage_sum function is not working the same.  It is giving erroneous data out towards the end of my horizon in my planning book.

It appears to be summing the work days instead of my forecast.  In 11/2016, I'm getting '31' which seems to be workdays from 12/2016.  Backing up, continue to add the workdays, and that's what's being populated in my Planned DLR Inventory.  I've initialized my planning area multiple times thinking I had junk data, but it continues to calculate this way.

My macro is written as:

Any thoughts?

Thanks,

Kristin

rajkj
Active Contributor
0 Kudos

Kristin,

Your screenshot did not show any values for the key figure "Final forecast - STU". I guess the values of Planned DLR Inventory were from previous macro run. Pl populate 'Final Forecast-STU' row and execute the macro 'Planned Dealer Inventory'.

Results verification -

Planned DLR Inventory (t) = [Sum of Final forecast - STU (t+1, t+2, t+3, ...) / Sum of Workdays (t+1, t+2, t+3, ...) ] * Planned Days Supply (t)

Where Sum of Workdays (t+1, t+2, t+3, ...) is just greater than Planned Days Supply (t)

                                         

e.g.

If the planned days' supply is 30 days and assuming workdays(number of days in the bucket) of next bucket also 30, then Planned DLR Inventory must be equal to 'Final Forecast-STU' of next period.

Thanks,
Rajesh

Caterpillar
Explorer
0 Kudos

Rajesh,

Thank you for your quick reply.

That's why I've reinitialized my planning book to make sure I am starting with nothing.  Even with '0' Final Forecast, values are being populated in Planned DLR Inventory.  It should be '0' if my forecast is '0'.  Even when I add forecast, it still gives me those same bad values plus what I've entered in my forecast:

The correct value for August should be 60 (20+20+(20*(29/30)))

Here's a screen shot from our APO 4.0 environment using the exact same function:

Since my forecast is '0', there is no planned inventory.

It has something to do with the end of my horizon, that's the only place the numbers get weird. The values are correct in the early months:

gurucharanscm
Contributor
0 Kudos

Hi Rajesh,

The below code should fit for your requirement:

Here,

KF1 = Forecast

KF2 = Additional Field 1

KF3 = Promotion

Former Member
0 Kudos

Hi Guru Charan,

First Thanks for your response. The macro which you posted is not working as per my requirement.


W1W2W3W4W5W6W7
KF11005070100403020
KF23





KF3220





The above table refers to my requirement.

If the user enter the value 2 in KF2-W1 then calculation will be KF1-W2 50 + K1-W3+70 + KF1-W4 100

Total is 220. The value in KF3 current week is based on the value which user enter in KF2 current week + KF1 WEEK+ (This means 3 weeks of KF1 From next week).

suppose if the user entered 5 in KF2 current week then it should consider 5 weeks total of KF1 from week+.

This is the total of KF1-W2 50 + KF1-W3 70 + KF1-W4 100 + KF1 W5 40 + KF1 W6 70 = 330

This total should populate in KF3 WEEK1 =330

The screen shot which you sent is not working as expected my requirement.

it is similar but not as expected

example for your macro

suppose user enter 3 in KF2 then it is considering KF1 W1 10 + KF1 W3 2 = 12

THE total is in KF3 = 12. In this case it is not considering KF1 W2. This is wrong.

In may case it should considering KF1 W2 as well. please find below table for the reference of your macro calculation... i can explain again if you are not understand in this case.

Thanks dude.


W1W2W3W4W5W6W7
KF1105215134
KF23





KF312





Former Member
0 Kudos

Rajesh,

As per my knowledge this can't be done using standard macros. But this is possible with the custom function module macro.

Here - WK 01 - is your KF2, WK-00 is your KF1, WK-02 would be your KF3

Z_CALCULATE_QTY is ABAP Function module macro -

Here is the result with macro execution

let me know if you need any more information.

Former Member
0 Kudos

Hi Reddy,

Thanks for your inputs.

I will try the way you mentioned here. I need more information from you. Hope you might have understood the above requirement.

KF1 -QTY KF

KF2 - number KF

KF3 - QTY KF (Result KF)

User enter the value in KF2 current week  then the KF1 calculation is based on the KF2 current week number. Here KF1 should consider the value from WEEK+ based on the input in KF2 Current week.

The the final result should populate in KF3 Current week.

Please refer the requirement again if any information or mail me i will explain you again.

I need the ABAP code which you have written for the macro which you have posted here.

thanks

Former Member
0 Kudos

Hi Reddy,,

Could you please let me know what parameters you have maintain for this function module.

I mean the parameters import/export and table in the function module?

I am getting some parameter error while triggering the macro. I have written the macro the same which you specified but need some input from you for triggering the macro successfully.

I need some parameter for the function module

like Attribute / import / export / Changing / Table /exception / source code

plez provide the details above mentioned tabs in the function module.

Thanks,

Former Member
0 Kudos

Hi Rajesh,

Here are the details.

FM interface in Macro work bench

FM - Code

   FUNCTION z_calculate_qty.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     REFERENCE(SDP_BOOK) TYPE  /SAPAPO/FUNSTRING OPTIONAL
*"     REFERENCE(SDP_VIEW) TYPE  /SAPAPO/FUNSTRING OPTIONAL
*"     REFERENCE(FUN_PARA) TYPE  /SAPAPO/ADV_PARA OPTIONAL
*"     REFERENCE(ACT_COLUMN) TYPE  /SAPAPO/MXCOL OPTIONAL
*"  TABLES
*"      VALUE_TAB STRUCTURE  /SAPAPO/VALUE_TAB
*"      COLS_INDEX STRUCTURE  /SAPAPO/PGCOLS OPTIONAL
*"      LINE_INDEX STRUCTURE  /SAPAPO/MCP6_LI OPTIONAL
*"  CHANGING
*"     REFERENCE(F_CALC_ERROR) TYPE  C OPTIONAL
*"     REFERENCE(F_ARGUMENT) LIKE  /SAPAPO/MXSOP-V OPTIONAL
*"----------------------------------------------------------------------



  FIELD-SYMBOLS: <ls_value> TYPE /sapapo/value_tab.

  DATA: wa_col_index TYPE /sapapo/pgcols.

  DATA: lv_buckets TYPE /sapapo/svtty_fltp,
        lv_error TYPE c,
        lv_bucket_date TYPE sy-datum,
        lv_current_index TYPE sy-index,
        wa_value_tab TYPE /sapapo/value_tab,
        lv_local_number TYPE i.

  CLEAR : lv_buckets, lv_bucket_date, lv_current_index, lv_local_number,
          f_argument.

  READ TABLE value_tab INDEX 1 INTO wa_value_tab.
  IF sy-subrc IS INITIAL.

* your KF2 value
    lv_buckets = wa_value_tab-value.
  ELSE.
    f_calc_error = 'X'.
    EXIT.
  ENDIF.

  CHECK lv_buckets IS NOT INITIAL.

* first two would be the variables passed from macro
* 3rd would be current week data which we don't consider
   lv_current_index = 3.
  " Adjust initial bucket count and two other variables count

  LOOP AT value_tab INTO wa_value_tab.
    CHECK sy-tabix >= lv_current_index.
    CHECK lv_local_number < lv_buckets.
    f_argument = f_argument + wa_value_tab-value.
    ADD 1 TO lv_local_number.
  ENDLOOP.

ENDFUNCTION.

Note; this is just a psuedocode. you may have to adjust as per your guidelines.

Regards,

Reddy.

Former Member
0 Kudos

In my example; it doesn't consider the current week of KF1 value. It will consider the next (N from KF2 IN current week) value.

If you want to consider the current week(KF1) value also in the calculations; you adjust the code

as - lv_current_index = 2. it should consider that.

Former Member
0 Kudos

HI Reddy,

Thank you very much. Its working fine now.