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 prevent similar conditions in Sales order?

Former Member
0 Kudos

Good day,

Please can anyone give a solution for requirement.

The following condition types are grouped as follows and are the only ones that should be reflected in the Sales order

Freight

ZFS1

ZFS2

ZFS3

ZFS4

Insurance

ZIS1

ZIS2

Here if it have ZFS1 it should not allow to include other freights(ZFS2/ZFS3/ZFS4) in the same sales order.

And I want to throw a error msg to user that "you con't charge more freight in same sales order".

Please advise me how I can do this with ABAP code and where I can use the logic?

Thank you,

Sudheer

1 ACCEPTED SOLUTION

arindam_m
Active Contributor
0 Kudos

Hi,

Please use Exits or BADI to check conditions tab and give the required message.You can use the program MV45AFZZ. The appropriate exit would be USEREXIT_SAVE_DOCUMENT_PREPARE. Check the below link for available exits.


http://help.sap.com/saphelp_46c/helpdata/en/1c/f62c7dd435d1118b3f0060b03ca329/content.htm

Cheers,

Arindam

27 REPLIES 27

arindam_m
Active Contributor
0 Kudos

Hi,

Please use Exits or BADI to check conditions tab and give the required message.You can use the program MV45AFZZ. The appropriate exit would be USEREXIT_SAVE_DOCUMENT_PREPARE. Check the below link for available exits.


http://help.sap.com/saphelp_46c/helpdata/en/1c/f62c7dd435d1118b3f0060b03ca329/content.htm

Cheers,

Arindam

Former Member
0 Kudos

Hi Arindam,

Thank you for your response.

The User exit is available in SAPLV69A program am working with va02. Do we have any other User exits for my requirement.

Thank you for your time.

Sudheer

arindam_m
Active Contributor
0 Kudos

This message was moderated.

former_member206632
Participant
0 Kudos

Hello Sudheer,

Does it have to be an ABAP solution? Have you considered using the standard Condition Exclusion fonctionality? You can find it here in SPRO, go and check it:

  • Sales and Distribution
  • Basic Functions
  • Pricing
  • Condition Exclusion

You will probably not be able to raise the exact message that you want, but it has the advantage of being a standard solution.

Regards,

João

0 Kudos

Hi Neves,

My functional tried that unfortunately it is not effecting.

Thank you,

Sudheer

Former Member
0 Kudos

Hi,

Here you can use the condition exclusion functionality which may solve your problem. But it do not give you message. for message you can use requirement.

In exclusion group function you have option to choose best condition between condition types or within the condition types.

In "Maintain condition exclusion for pricing procedures"

Hope it will help you.,

Regards

Pitabash

former_member188076
Active Contributor
0 Kudos

Hi,

As per my understanding, you must have certain logic for determining ZFS1 or ZFS2 and so on.

It will be better if you explain the same here.

I agree with Neves, to explore the possibility of Condition Exclusion, based on your requirement that when a particular condition type is required, else you may use the Requirement Routine, to activate or de-activate a particular condition.

Regards,

Amitesh Anand

bastinvinoth
Contributor
0 Kudos

Hi sudheer reddy

Program Name : MV45AFZZ

Routine Name : USEREXIT_SAVE_DOCUMENT_PREPARE

there you can set the error msg

just  put the below condition.

read table XKOMV with key kschl = 'ZFS2'      "as of now i have added only one condition type

if sy-subrc eq '0'.

message you con't charge more freight in same sales order'' type 'E'.

endif.

Regards,

Bastin.G

0 Kudos

This message was moderated.

0 Kudos

Hi Bastin,

Please can you advise me how it compare all freights(ZFS1,ZFS2,ZFS3,ZFS4) with the above code?

Here I have to control other surcharges also please explain.

Thank you for your time,

Kind regards,

Sudheer

0 Kudos

Hi Sudheer

The best you can do as suggested by Pitabash Behera i.e. through condition exclusion and this the best way to do it, you can take the help of condition exclusion procedure A All conditions found whithin the first exclusion group are compared and the condition the best price is chosen. All others are de-activated.

else you can go with coding in user exit MV45AFZZ at save prepare but try it with step and counter then then write the logic but this is not advisable because each time you need to change your logic when ever there is new requirement.

Regards

A M

0 Kudos

Hi sudheer reddy

did u try loop statement over there .

loop at xkomv into wa_xkomv,

"for example say

if wa_xkomv-kschl = 'ZFS1'.

    fs1 = wa_xkomv-kwert.

elseif wa_xkomv-kschl = 'ZFS2'.

    fs2 = wa_xkomv-kwert.

endloop.

pass all your values over to variable and compare it ,based on ur requirement.

Declare one workarea for XKOMV structure and try to loop it,

then based on condition write read statement over there inside the loop.

based on the work area values you can easily validate all those fright charges.

Regards,

Bastin.G



Former Member
0 Kudos

Dear Sudheer Reddy,

    Exclude all the condition Type except the required one ZFS1, it is possible through the standard system only why you want to go for any modificaions and substitutions, exclude all the Condition types which you dont want and maintain the requirement in Pricing Procedure For ZFS1....Hope this will work out.

And similarly for insurance too you follow the same thing ......

Regards

Bhupal Reddy

deepabalu
Participant
0 Kudos

Hi Sudheer,

As suggested by

Former Member
0 Kudos

Through Condition Exclusion you compare the condition type and giving the priority to condition type so you can not use multiple condition type in future ... if you want want to be flexible for both scenario best is to use alternate Condition formula for alternative calculation type

Regards

Sohan Bhavsar

Former Member
0 Kudos

Hi All,

Thanks for your suggestions.

As Pitabash Behera said It can control with SAP Standard condition exclusion functionality. But my Functional guy is saying that It is not validate with the procedure in the requirement. So we decided to do that by using USER EXITS.

I'm trying read the xkmov table statement in the enhancement point but SAP saying the read table is not possible.


Please can you help me what code can effects for my requirement Please.

(Req: ex:  If the item is already charged for the freight(ZFS1) then it should not allow to charge the other freight(ZFS2) it should be either ZFS1 or ZFS2. )

Also Here am using CASE for the all condition groups.

Thank you,

Sudheer

0 Kudos

Hi Sudheer ,

Apart from the above solutions I will also like to give one more solution which you can try with.

There is a Customer Exit in SD V45A0003 using this you can evaluate entries of KOMV while posting.

Implement EXIT_SAPMV45A_003 of that Exit .

And the below code will help you access KOMV entries :

DATA: BEGIN OF TXKOMV OCCURS 50.

         INCLUDE STRUCTURE KOMV.

DATA: END OF TXKOMV.

DATA : TAB_NAME(40) TYPE C ,

FIELD-SYMBOLS : <TAB> TYPE ANY.

TAB_NAME = '(SAPMV45A)XKOMV[]'.

ASSIGN (TAB_NAME) TO <TAB>.

TXKOMV[] = <TAB>.

SORT TXKOMV BY KPOSN KSCHL .

In table TXKOMV you will get data required.

Refer the below thread :

http://scn.sap.com/thread/721523

0 Kudos

Hi

If you don't want to manage it with condition exclusion, you can do it with requirements (VOFM routines) and set it in the pricing procedure. Populate the groups in a customer table and look for them in the VOFM, if you check a group, set SY-SUBRC = 4 and the condition won't work. In this requirements you can see all pricing procedure with the internal table TKOMV. Set a break-point and debug it. And be careful with the performance.

I hope this helps you

Regards

Eduardo

Former Member
0 Kudos

Hi Sijin,

Thank you for the code.

with the code we can delete the duplicate records, But in my requirement there are few condition types grouped so I want to control them also.

ex: if it have freight like below

ZFS1       10.00 USD/MT(%)

ZFS2         100.00  USD/MT (Not allow to enter or add condition type)

ZFS3/ZFS4 are not allowed because these header values.

Please advise.

Thank you,

Kind regards,

Sudheer

0 Kudos

Sudheer ,

That link was for reference only , you need to change it accordingly,'

like

DATA: BEGIN OF TXKOMV OCCURS 50.

         INCLUDE STRUCTURE KOMV.

DATA: END OF TXKOMV.

DATA : TAB_NAME(40) TYPE C ,

FIELD-SYMBOLS : <TAB> TYPE ANY.

TAB_NAME = '(SAPMV45A)XKOMV[]'.

ASSIGN (TAB_NAME) TO <TAB>.

TXKOMV[] = <TAB>.

SORT TXKOMV BY KPOSN KSCHL .

Now in TXKOMV data is there , so use READ accordingly write your logic and get your job done

Former Member
0 Kudos

Hi Sudheer,

For Remove duplicate Condition , go to MV45AFZZ and Find

FORM USEREXIT_PRICING_PREPARE_TKOMP .

Write a code like following.

LOOP AT XKOMV.

    IF LV_KSCHL EQ XKOMV-KSCHL.

         MESSAGE ID 'ZXX' TYPE 'I' NUMBER '001' . " Raise a Desired Message

         LEAVE LIST-PROCESSING.

    ELSE.

         LV_KSCHL = XKOMV-KSCHL.

    ENDIF

ENDLOOP.

Thanks!

Ram Shanker


Former Member
0 Kudos

Hi all,

I am having problem with my code please advise alternate way to compare condition type in txkomv table for validation.

please advise me how to validate the condition value if the conditions are grouped.

Below is my logic:

DATA:   BEGIN OF tXKOMV OCCURS 50.

         INCLUDE STRUCTURE KOMV.

DATA:   END   OF tXKOMV.

data : tab_name(40) type c ,

       ld_len type i , ld_len1 type i .

field-symbols : <tab> type  any.

tab_name = '(SAPMV45A)XKOMV[]'.

assign (tab_name) to <tab>.

txkomv[] = <tab>.

*describe table txkomv lines ld_len .

sort txkomv by kposn KSCHL.

*describe table txkomv lines ld_len1 .

if ld_len1 ne ld_len.

     refresh txkomv .

if txkomv-kschl is not INITIAL.

loop at txkomv.

CASE TXKOMV-KSCHL.

   WHEN 'ZFS%'.

*    READ TABLE TXKOMV.

     IF TXKOMV-KSCHL = 'ZFS1' and TXKOMV-KSCHL <> 'ZFS2' AND TXKOMV-                 kSCHL <> 'ZFS3' and txkomv-kschl <> 'ZFS4'.

       ELSEIF TXKOMV-KSCHL <> 'ZFS1' and TXKOMV-KSCHL = 'ZFS2' AND TXKOMV-KSCHL <> 'ZFS3' and txkomv-kschl <> 'ZFS4'.

         ELSEIF TXKOMV-KSCHL <> 'ZFS1' and TXKOMV-KSCHL <> 'ZFS2' AND TXKOMV-KSCHL = 'ZFS3' and txkomv-kschl <> 'ZFS4'.

           ELSEIF TXKOMV-KSCHL <> 'ZFS1' and TXKOMV-KSCHL <> 'ZFS2' AND TXKOMV-KSCHL <> 'ZFS3' and txkomv-kschl = 'ZFS4'.

             ELSEIF TXKOMV-KSCHL = 'ZFS1' and TXKOMV-KSCHL = 'ZFS2' AND TXKOMV-KSCHL <> 'ZFS3' and txkomv-kschl <> 'ZFS4'.

               ELSEIF TXKOMV-KSCHL = 'ZFS1' and TXKOMV-KSCHL <> 'ZFS2' AND TXKOMV-KSCHL = 'ZFS3' and txkomv-kschl <> 'ZFS4'.

                 ELSEIF TXKOMV-KSCHL = 'ZFS1' and TXKOMV-KSCHL <> 'ZFS2' AND TXKOMV-KSCHL <> 'ZFS3' and txkomv-kschl = 'ZFS4'.

                   ELSEIF TXKOMV-KSCHL <> 'ZFS1' and TXKOMV-KSCHL = 'ZFS2' AND TXKOMV-KSCHL <> 'ZFS3' and txkomv-kschl <> 'ZFS4'.

0 Kudos

Whats your exact requirement ?

I mean is it that only Two of condition types from ZFS1 , ZFS2 ,ZFS3 ,ZFS4 should be allowed at a time ?

Is  there any particular group of condition types which can be maintained ?

Please elaborate bit more , your exact purpose can't be traced from the final code you have pasted.

and I guess below code is not required ,

refresh txkomv .

I think you got this copied from that example code.

Message was edited by: Sijin Sij

Former Member
0 Kudos

Hi Sijin,

I just changed the example code for my requirement.

Please see actual requirement is:

There are 4 surcharge groups

Freight Insurance Inland Delivery Import Duty
ZFS1ZIS1ZID3ZDSA
ZFS2ZIS2ZID4ZDSB
ZFS3


ZFS4


let's work with Freight,

If ZFS1 is charged some specific line item and then the user again try to charge any freight(ZFS1,ZFS2,ZFS3,ZFS4) It should say the Freight is already charged.

similarly If ZFS2 is charged some specific line item and then the user again try to charge any freight(ZFS1,ZFS2,ZFS3,ZFS4) It should say the Freight is already charged.

that means for the line item user should charge only one Freight condition. it is either ZFS1 or ZFS2 or ZFS3 or ZFS4.

I'm implementing this at USEREXIT_SAVE_DOCUMENT_PREPARE.

the code is checking for condition but it is giving the massage even though it charged only once.

Please see my code and please advise where should I change.

data : tab_name(40) type c.

field-symbols : <tab> type  any.

tab_name = '(SAPMV45A)XKOMV[]'.

assign (tab_name) to <tab>.

txkomv[] = <tab>.

sort txkomv by kposn KSCHL.

loop at txkomv.

If TXkomv-kschl CN 'ZFS1'.

   MESSAGE 'ZFS1 FREIGHT ALREADY EXISTS' TYPE 'I'.

   ELSEIF TXkomv-kschl CN 'ZFS2'.

   MESSAGE 'ZFS2 FREIGHT ALREADY EXISTS' TYPE 'I'.

   ELSEIF TXkomv-kschl CN 'ZFS3'.

   MESSAGE 'ZFS3 FREIGHT ALREADY EXISTS' TYPE 'I'.

   ELSEIF TXkomv-kschl CN 'ZFS4'.

   MESSAGE 'ZFS4 FREIGHT ALREADY EXISTS' TYPE 'I'.

endif.

endloop.

Please help me.

Thank you

sudheer

0 Kudos

Why are you using CN operation ?

You can use simple EQ operation instead !

Correct me if I am wrong , I might have not been able to understand your logic for using CN

Read the below link for these operations with Example :

http://wiki.sdn.sap.com/wiki/display/ABAP/String+Comparison+operators

Whenever any other condition type comes into the scene say ZPR0 the IF condition becomes true and you get the message displayed.

0 Kudos

Hi Sijin,

I was just tried with logic operations to reduse the length but that doesn't worked here.

I am implementing this code at USEREXIT_SAVE_DOCUMENT_PREPARE in MV45AFZZ program because when user enter the condition if the surcharge is already charged for the line item it should give error msg. And the mdg should not stop if it is charged only once for the item.

but my code is not working Please could you see the below code and advise me where should i change.

DATA:   BEGIN OF tXKOMV OCCURS 50.

         INCLUDE STRUCTURE KOMV.

DATA:   END   OF tXKOMV.

data : tab_name(40) type c,

        ld_len type i.

field-symbols : <tab> type  any.

tab_name = '(SAPMV45A)XKOMV[]'.

assign (tab_name) to <tab>.

txkomv[] = <tab>.

sort txkomv by kposn KSCHL.

DATA: lv_komv TYPE TABLE OF komv,

       wa_komv type komv.

APPEND txkomv to lv_komv SORTED BY KPOSN.

loop at lv_komv INTO wa_komv where kposn = wa_komv-kposn.

If wa_komv-kschl EQ 'ZFS1' OR wa_komv-kschl EQ 'ZFS2' OR wa_komv-kschl EQ 'ZFS3' OR wa_komv-kschl EQ 'ZFS4' AND wa_komv-KWERT NE 0.

     DELETE LV_KOMV WHERE kschl NS 'ZFS'. "OR kschl NE 'ZFS2' OR kschl NE 'ZFS3' OR kschl NE 'ZFS4'.

ENDIF.

If wa_komv-kschl EQ 'ZIS1' OR wa_komv-kschl EQ 'ZIS2' AND wa_komv-KWERT NE 0.

   DELETE LV_KOMV WHERE kschl NS 'ZIS'.

ENDIF.

If wa_komv-kschl EQ 'ZID3' OR wa_komv-kschl EQ 'ZID4' AND wa_komv-KWERT NE 0.

     DELETE LV_KOMV WHERE kschl NS 'ZID'.

ENDIF.

If wa_komv-kschl EQ 'ZDSA' OR wa_komv-kschl EQ 'ZDSB' AND wa_komv-KWERT NE 0.

   DELETE LV_KOMV WHERE kschl NS 'ZDS'.

ENDIF.

ENDLOOP.

sort lv_komv by kposn KSCHL.

DELETE ADJACENT DUPLICATES FROM lv_komv.

describe table LV_komv lines ld_len.

if ld_len GT 1.

   loop at lv_komv into wa_komv.

   IF WA_KOMV-kschl EQ 'ZFS1' OR WA_KOMV-kschl EQ 'ZFS2' OR WA_KOMV-kschl EQ 'ZFS3' OR WA_KOMV-kschl EQ 'ZFS4'

      MESSAGE 'Freight exists in order please check already existing freight conditions' TYPE 'E'.

   ELSEIF wa_komv-kschl EQ 'ZIS1' or WA_komv-kschl eq 'ZIS2'.

      MESSAGE 'Insurance exists in order please check already existing insurance condition' TYPE 'E'.

   ELSEIF WA_komv-kschl EQ 'ZID3' OR WA_komv-kschl EQ 'ZID4'.

      MESSAGE 'Inland delivery exists in order please check already existing inland delivery condition' TYPE 'E'.

   ELSEIf WA_komv-kschl EQ 'ZDSA' OR WA_komv-kschl EQ 'ZDSB'.

      MESSAGE 'Import duty exists in order please check already existing import duty condition' TYPE 'E'.

   ENDIF.

   ENDLOOP.

ENDIF.

Thank you,

Sudheer

Former Member
0 Kudos

Thanks all,

The issue is sorted.