Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

how to get xkomv-kwert (condition value) from a pricing condition ZZP1

former_member496861
Participant
0 Kudos

Hi experts,

I have a pricing condition zcust that I need to modify in the sales order. The calculation of ZCUST is dependent on the condition value in another price condition ZZP1. The price for ZZP1 is a fixed amount of $6 which is split among line items in the order. In sapmv45A, when the code hits userexit_save_document_prepare, the value of xkomv-kwert (condition value) exist. In other user-exits in sapm45A, I was unable to find xkomv-kwert. My question is: How can I find the value of xkomv-kwert as i don't know how ZZP1 is calculated ?? There is no routine attached to ZZP1.

THE ZCUST has a routine 993 which is similar to 3. Here in program saplv61A, i was trying to get xkomv-kwert for ZZP1 but unable to get any data. Can anyone suggest where i can get the data (xkomv-kwert) for ZZP1 in saplv61a ?

I looked at userexit_xkomv_bewerten_end in saplv61a but it does not help.

XKomv-kbetr always has data. If i have ZZP1 data, then i can modify ZCUST.

Many thanks.

Joyce

1 ACCEPTED SOLUTION

Jelena
Active Contributor

What kind of a routine are you talking about? Is this a requirement, a formula? Condition value, condition base value, etc.? The number doesn't tell us anything because the same number can be present in different areas.

The condition formula should be executed only once per condition - I've just tested it in our system. Are you sure that it is assigned to only one condition? How do you know that? Did you check the pricing procedure?

In any case, in the routine XKOMV-KSCHL should show for which condition the routine gets triggered. Also look at other values in XKOMV header line - if you see that the routine gets triggered several times for the exact same XKOMV line this would mean that somewhere a re-pricing is started.

What do you mean that you're unable to get XKOMV-KWERT for ZZP1? What exactly are you doing to get this value?

There is no "end of processing" for XKOMV. If you need to do anything after the order has been finalized and before saving, this can only be done in the already mentioned user exit USEREXIT_SAVE_DOCUMENT_PREPARE. Before that the users can do many things that could change the conditions. I don't know how else to explain this to you...

27 REPLIES 27

former_member156446
Active Contributor
0 Kudos

Hi look for xkwert or ykwert... that will be the place where SAP hold the xkomv-kwert value before coming into the routine.. which will be replaced in later stages...

also check : LV61AA43 , LV61AA55 these have lot of enhancement points if you are in ECC6.0

0 Kudos

Hi J@Y,

For these: " LV61AA43 , LV61AA55 these have lot of enhancement points ",

I saw in one of the program has this below:

" ENHANCEMENT-POINT xkomv_bewerten_13 SPOTS es_saplv61a. "

I am not familiar with enhancement points. If i need to add my codes, do i click on xkomv_bewerten_13 ?

What is the " es_saplv61a " for ? Do you have any guidance on making changes to enhancement points?

thanks

Joyce

0 Kudos

>

> Hi J@Y,

> I am not familiar with enhancement points. If i need to add my codes, do i click on xkomv_bewerten_13 ?

> What is the " es_saplv61a " for ? Do you have any guidance on making changes to enhancement points?

>

there is nothing like where should I write the code... in the debug mode.. see which enhancement point is near to the code line you want to edit and just implement that enhancement point... these point will inbuilt or embed the our custom code into sap std. program and execute as per the order of line... if some custom code in xkomv_bewerten_13 might help u figure out xkwert ot xkomv-kwert then write ur code by implementing the enhancement point.. and it should work...

another thought.... cant read table xkomv into wa_komv whete kschl = ' <ur condition type> ' help?

search in SCN for how to implement the enhancement point and u can find a [lot on internet as well..|http://www.sapdev.co.uk/enhance/eframework/ef_implicit.htm]

0 Kudos

HI J@Y,

Thanks for your valuable info. In the order, i have one line item, When i debug the routine, it seems the routines is executed many times. Why is this? The routine is attached to zcust only.

Say i have 2 line items in the order. If i can find where the end of exceution for xkomv, it would help me. Here, then i can see all the condition types for the 2 line items.

Many thanks.

Joyce

Jelena
Active Contributor
0 Kudos

Frankly, this sounds like a poor configuration decision. Why can't you just apply 6$ flat fee as a header condition?

Anyway, if a fixed amount 6$ must be spread evenly over all the items in the order, this could only be done in the user exit SAVE_PREPARE. All other user exits and formulas are triggered for specific line or condition. At that moment you cannot know how many items will there be in the order. So, unless you failed to mention something, looks like you'll have to trigger re-pricing when saving the document. This is pretty dangerous and I would once again encourage your functional consultant to look into other options.

0 Kudos

>

>So, unless you failed to mention something, looks like you'll have to trigger re-pricing when saving the document. This is pretty >dangerous .....

I agree.. this could be done in Config as well...

we can write wrapper program which will be a RFC on PRICING Fm and call the function in a new task addition...and get the new values into the User exit or routine.

0 Kudos

HI Jelena,

I wished they have used a scale for $6 ZPP1. I just don't undertand how the price is calculated so $6 is spread evenly. The pricing proc for ZPP1 has no formula. I realized that if i go to header /condition tab, then the price is calculated for all the line items. Do you know how i can find the calculation for ZPP1 ? Is there a way to trigger re-pricing after entering all the line items ? Can you explain why this is dangerous ?

Thanks

Joyce

0 Kudos

Hi J@Y,

Are you saying re-pricing can be trigger when saving the document vai configuration ? I think this is done already in the system. How can i find out the config ?

So it seems i can write a FM to modify the values after pricing FM is done for one line item.

thanks

Joyce

kiran_k8
Active Contributor
0 Kudos

Raj,

If it can be done through Config means that IT SHOULD BE DONE THROUGH CONFIG only.

As they say "but I had a chance to work with some ignorant and lazy SD consultants who would rather push tasks to the ABAP developers than make an effort and find a solution using standard or to suggest a business process change."----Exactly.

Don't worry,Experience will give you the confidence to Question the Functional Consultants.

K.Kiran.

Former Member
0 Kudos

HI,

You can try the code written below in your routine for ZCUST i'e 903. You have to change little bit as per your requirement.

But it could solve your problrm to calculate ZCUST as per ZZP1.

***

DATA: ZKOMV LIKE XKOMV OCCURS 0 WITH HEADER LINE,

KBETRT LIKE XKOMV-KBETR,

M_KUMZA LIKE XKOMV-KUMZA,

CURRENTLINE LIKE SY-TABIX.

LOOP AT XKOMV .

MOVE-CORRESPONDING XKOMV TO ZKOMV.

APPEND ZKOMV. CLEAR ZKOMV.

IF XKOMV-KSCHL = 'ZCUST'.

CURRENTLINE = SY-TABIX .

ENDIF.

ENDLOOP.

READ TABLE XKOMV INDEX CURRENTLINE. " 4 .

LOOP AT ZKOMV.

IF ZKOMV-KSCHL EQ 'ZZP1'.

KBETRT = KBETRT + ZKOMV-KBETR .

ENDIF.

ENDLOOP.

IF KOMP-MGAME NE 0 .

XKOMV-KWERT = KBETRT * KOMP-MGAME / 1000.

XKWERT = KBETRT * KOMP-MGAME / 1000.

ENDIF.

YKMEIN = KOMP-KMEIN .

ENDFORM.

***

Minor Formulas could have to change.

Regds,

Anil

Edited by: Anil Katoch on Jul 9, 2009 2:43 PM

0 Kudos

Hi Anil,

THanks for the coding. I am still not sure how ZPP1 is calculated, so not sure what the formula should be.

However, it give me an idea to look further. In the routine for zcust re 993, i can get the xkomb-kbetr. However, i am still trying to get the xkomv-kwert which i am unable to get from the Pricing FM.

Do you know if Pricing FM calculate for line item, then goes back to sapmv45a ?

I like to give more points but the others are grey out.

thanks

Joyce

Jelena
Active Contributor
0 Kudos

Joyce,

I have a feeling you're so focused on the technical details that you might not see the big picture and might not understand the requirements correctly or fully. I would go back to the functional consultant and ask him/her to clarify what needs to be done exactly. From your posts I'm getting rather confusing information. <br>

1) If a flat fee (e.g. 6$ or whatever amount) has to be applied to the whole order, IMHO this has to be done via a header-level condition. What is the purpose of "spreading" it over all the order items? If this is for the partial returns/credits then it would be much easier to calculate the corresponding "share" when processing the credit. Also how will rounding etc. be handled? What if there are 13 or 999 items? Just think about it.<br>

2) If the task is simply to calculate the value of ZCUST condition based on ZZP1 condition then it could be done by applying the formula to ZCUST condition. Formulas are applied in the configuration and the code is maintained in VOFM transaction. It seems that you don't realize that XKOMV is actually a table, not a structure. In the pricing procedure ZCUST condition must be placed later than ZZP1 condition. In this way when the code reaches ZCUST the value of ZZP1 should already be calculated (if everything has been done correctly). Then in your formula, read XKOMV table with key KSCHL = 'ZZP1' and find the value from there (KWERT, KBERT, KAWRT - whatever your requirement is). Then calculate the variable XKWERT according to your requirements. Before reading XKOMV make sure to store the current cursor position (SAP code might assume that a specific line is currently in memory) and re-read the same record at the end of your routine.<br>

But, once again, if you need to "spread" the amount over all the items, the formula won't work for a simple reason that at the time when the formulas, user exits, etc. are triggered not all items have been created yet. For example, the user enters one item, so in the formula you apply ZCUST = 6$. Then the user creates another item. Now you have to change the previous item to 3$ and apply 3$ to the new item. This is not just difficult to program but is also terrible for performance (imagine, you might have hundreds of items in one order!). And what will you do if, after creating a 100 item order the user goes and deletes one item?

And what about taxes? How will they be calculated? Also consider that when pricing runs, the "subtotal" fields in VBAP (KZWI1...6) are being updated. If you disrupt the process, the fields will have incorrect values.

I don't want to jump to conclusions here, but I had a chance to work with some ignorant and lazy SD consultants who would rather push tasks to the ABAP developers than make an effort and find a solution using standard or to suggest a business process change. Just look at some questions in the SD forum - half of these "experts" are, for the lack of a better word, idiots.

P.S. If you want to find more information about the formulas, search for VOFM - there are a lot of documents and posts available.

Good luck!

0 Kudos

HI Jelena,

You have provided valuable insights. #2 is what i was trying to determined. The problem here is i was not able to get kwert for ZPP1, so i am unable to calculate ZCUST correctly. ZPP1 price comes first, then ZCUST.

I don;t know why the routine is executed so many times for one line item though the routine is for one condition type.

Many thanks. I wished i can give you and other replies more points. These are greyed out.

Joyce

Jelena
Active Contributor

What kind of a routine are you talking about? Is this a requirement, a formula? Condition value, condition base value, etc.? The number doesn't tell us anything because the same number can be present in different areas.

The condition formula should be executed only once per condition - I've just tested it in our system. Are you sure that it is assigned to only one condition? How do you know that? Did you check the pricing procedure?

In any case, in the routine XKOMV-KSCHL should show for which condition the routine gets triggered. Also look at other values in XKOMV header line - if you see that the routine gets triggered several times for the exact same XKOMV line this would mean that somewhere a re-pricing is started.

What do you mean that you're unable to get XKOMV-KWERT for ZZP1? What exactly are you doing to get this value?

There is no "end of processing" for XKOMV. If you need to do anything after the order has been finalized and before saving, this can only be done in the already mentioned user exit USEREXIT_SAVE_DOCUMENT_PREPARE. Before that the users can do many things that could change the conditions. I don't know how else to explain this to you...

0 Kudos

Hi Jelena,

In VOFM, it is Formula/Condition Base Value for routine 993. In Pricing Procedure, it falls in column "Base Type" for 993.

Let's see if i can simplify this: In a sales order with 2 line items:

prices Amt Condition Value (USD)

Line 10 ZS1 sell price 2.30 1150

ZPP1 charge 6.36 3.40 (note the distribution **)

ZL1 3 3

ZR1 % 1.000% 11.50

ZR2 0.01 5

Suggested price = 2.35 1172.90

ZCUST 2.34 1170

total price 2.34 1170

Note: The ZCUST price is wrong. It is missing the ZPP1 charge which is 3.40. Zcust should be 1170 + 3.40 = 1173.40

Line 20 ZS1 sell price 25 1000

ZPP1 charge 6.36 2.96 (note the distribution **)

ZL1 3 3

ZR1 % 1.000% 10

ZR2 0.01 0.6

Suggested price = 25.41 1016.56

ZCUST 25.34 1013.60 (should be 1013.60 + 2.96)

Total price 25.34 1013.60

You can see the ZCUST is calculated incorrectly. The routine calculate zcust as $1170 and $1013.60 for each item which did not include the distribution amount of ZPP1 ($3.40 and $2.96).

When i debug the routine, the xkomv-kwert is zero. I am trying to get $3.40 and $2.96 so i can add to to zcust in the routine.

Am trying to determine in saplv61A at which include that i can see #3.40 and $2.96 for both line items in xkomv-kwert.

Then maybe i can modify the routine or saplv61A so it shows the correct zcust price after entering the 2 line items in the sales order create (VA01) ? Can you pls suggest ?

If i make the changes in USEREXIT_SAVE_DOCUMENT_PREPARE, then user cannot see the correct zcust until the order is saved. This would be too late to know the zcust price ahead of time.

Pls view in the Edit mode... i see my texts have been compressed.

Many thanks

Joyce

Edited by: Joyce Chan on Jul 9, 2009 10:24 PM

Edited by: Joyce Chan on Jul 9, 2009 10:25 PM

0 Kudos

Hi check with ur functional team if they can change the sequence of the steps in the pricing procedure. If they can do it then u can know the value to be based upon... by the time u reach the routine... and u can make the calculations, based on another condition type.

if you want to know the value how the next condition type is calculated will be based upon the field arbfeld in LV61AA43 line 273 and routine will be called at line 649, PERFORM (frm_kondi_wert) IN PROGRAM saplv61a IF FOUND.

0 Kudos

Hi J@Y,

I located the field arbfeld in LV61AA43 line 273. Let me see if I can find out how the condition type is calculated for ZPP1 for each line iten.

Many thanks.

Joyce

0 Kudos

arbfeld will be the value which finally gets into xkomv-kwert or xkomv-kbetr, If its pricing then that case statement would satisfy 'B' and value will be calculated.

0 Kudos

Hi J@Y,

I still cannot see where sap calculates the xkomv-kwert for ZPP1 but i noticed that it got calculated using FM Pricing_Complete.

I will take another look at arbfeld. You state:

" If its pricing then that case statement would satisfy 'B' and value will be calculated "

The 'If its pricing'... Do you mean price versus discount/surcharge ?

Since i cannot modify ZCUST at userexit_save_doc in sapmv45a since user want to look at pricing before save doc, i need to know where i can add my coding. It would be after FM pricing_complete.

Do you think that i could add my changes in saplv61A but not in sapmv45a ?

I will look thru the weekend and keep you all posted.

thanks

Joyce

0 Kudos
line 273 :     arbfeld = 0.
                   arbfeld     = xkomv-kawrt * xkbetr.

line 283 :     CASE xkomv-krech.   " if its pricing calculation its B or G if I remember right

line 613 :       xkomv-kwert = arbfeld.

0 Kudos

Hi J@Y,

I am still debugging the program in the middle of other tasks. I find your tips very helpful.

Many thanks.

Joyce

Jelena
Active Contributor
0 Kudos

I debugged one of our base value routines - they do get triggered several times during the document creation, but only once in the display mode. If you look at the ABAP stack in debugger you'll see that pricing routines are called from different places, so this is normal. During the first run XKWERT is blank, then it gets populated with the value that has been determined automatically.

You need to add some code to the routine assigned to ZCUST condition. Here is an example of how the value of another condition is being read in our routine:

data: tmp_xkomv like xkomv occurs 0 with header line.
tmp_xkomv[] = xkomv[].
read table tmp_xkomv with key kschl = 'Z...'.
xkomv-kbetr = 100000 * tmp_xkomv-kwert / xkomv-kawrt.
if xkomv-kbetr < 0 and xkwert > 0. 
   xkwert = xkwert * -1. 
endif.

It's not perfect (e.g. no exception handling), but just to give you an idea. I still believe you'll run into one of the issues mentioned above, but if you insist...

0 Kudos

Hi Jelena,

thanks for your reply. Somehow I still need to get xkomv-kwert from ZPP1 before i can calculate ZCUST.

I will debug the program and see what i can get.

Many thanks

Joyce

v_kalyani
Discoverer
0 Kudos

Try this code , it may be helpful

clear: i_xkomv1.

read table xkomv into i_xkomv1 with key kschl = zzp1.

if i_xkomv1-kwert <> 0.

xkwert = i_xkomv1-kwert.

endif

0 Kudos

HI Kalyani,

Thanks for the code.

Joyce

former_member496861
Participant
0 Kudos

Hi all who replied,

I got a lot of feedback on this thread and appreciate all your good responses.

Many thanks !

Joyce

former_member204244
Active Participant
0 Kudos

hello All,

I am also facing similar kind of issue. My condition is ZCUR whose value is initial in first trips of routine. Then User exit runs which considers wrong value of ZCUr and then again value gets set in the ZCUr correctly.

Need Your help please!

Thanks,

Ishani