Hi Neal, Here's part of the code, basically this is for a specific condition type "Y155". The discount should be applied if a certain number/combination of materials in the SO are in the salesdeal. If there are no duplicate materials, all is good for both header and item level. But if there is a duplicate material, all is good for header level only. At item level, both (duplicate materials) will have the same value, but we need the duplicate material to be zero (my code somehow doesn't work even if I've already set it to zero). On the later part of this code there is a condition "if sy-ucomm = PK01" if the user goes to the condition at item level. This part of the code prevents the condition value from blowing up. But for the current output, materials that are the same, also has the same condition value even if I've set it to zero. For the actual condition calculation, you can start at "LOOP AT I_FULLPACK". Also I've noticed at header level, the KPOSN of XKOMV is always the last item number, is that OK? The code works for header level. Thanks and best regards, Jet ---------- case gkomv-key-kschl. when c_y155. tkschl = gkomv-key-kschl. tsalesdeal = gkomv-key-vakey+3(10). ... ... * Selects records from KONAIND, KONH and KONM IF tsalesdeal IS NOT INITIAL. SELECT a~knuma a~knumh b~vakey c~kstbm c~kbetr FROM konaind AS A INNER JOIN konh AS B ON a~knumh = b~knumh INNER JOIN konm as C ON c~knumh = b~knumh INTO CORRESPONDING FIELDS OF TABLE i_pairs WHERE a~knuma = tsalesdeal AND b~kschl = c_y155. IF sy-subrc = 0. IF sy-subrc = 0. LOOP AT i_pairs ASSIGNING <fs_pairs>. <fs_pairs>-c_vakey = <fs_pairs>-vakey+44(18). * get product code r_prdha-sign = 'I'. r_prdha-option = 'CP'. CONCATENATE '*' <fs_pairs>-vakey+36(8) INTO r_prdha-low. APPEND r_prdha. ENDLOOP. IF <fs_pairs> IS ASSIGNED. UNASSIGN <fs_pairs>. ENDIF. * get material's product heirarchy IF i_pairs[] IS NOT INITIAL. select matnr prdha FROM MARA INTO TABLE i_mara FOR ALL ENTRIES IN i_pairs WHERE matnr = i_pairs-c_vakey. IF sy-subrc = 0. SORT i_mara by matnr. * get materials using product code ELSE. SELECT MATNR PRDHA FROM MARA INTO TABLE I_MARA WHERE PRDHA IN R_PRDHA. IF SY-SUBRC = 0. SORT I_MARA BY MATNR. ENDIF. ENDIF. ENDIF. ENDIF. endif. endif. loop at tkomv into tmpkomv where kschl = tkschl. "Determine if document item is not statistical if tmpkomv-kinak <> c_w. "Get quantity from tkomp where attainment has fired "on the line item and attainment is not excluded. "determine if condition has been excluded for "attainments and is used for payout only. loop at xkonp into tmpkonp where key-knumh = tmpkomv-knumh. if tmpkonp-konp-kznep <> c_x and tmpkonp-konp-knuma_ag = tsalesdeal. loop at tkomp into tmpkomp where kposn = tmpkomv-kposn. CLEAR: wa_items, wa_mara. * Check if material in sales deal READ TABLE i_mara into wa_mara WITH KEY matnr = tmpkomp-matnr. IF sy-subrc = 0. * Check if current item's product detail is already in i_items wa_items-sdeal = tsalesdeal. wa_items-matnr = tmpkomp-matnr. "material wa_items-kposn = tmpkomp-kposn. "item number wa_items-prodh = tmpkomp-prodh. "product hierarchy wa_items-prdha = tmpkomp-prodh+10(8). "detail prod code/summary code wa_items-qty = tmpkomp-mglme / 1000. "material quantity wa_items-kbetr = tmpkonp-konp-kbetr. "Rate (condition amount or percentage) READ TABLE i_pairs ASSIGNING <fs_pairs> WITH KEY knuma = tsalesdeal knumh = tmpkomv-knumh. IF sy-subrc = 0. wa_items-scale = <fs_pairs>-kstbm / 1000. "base scale <fs_pairs>-c_vakey = tmpkomp-matnr. ENDIF. IF <fs_pairs> IS ASSIGNED. UNASSIGN <fs_pairs>. ENDIF. APPEND wa_items TO i_items. ENDIF. endloop. endif. endloop. endif. endloop. DESCRIBE TABLE i_items[] LINES v_lines. IF V_LINES < 2. * if there is only 1 material, do not process for pairs package xkomv-kbuff = c_x. ELSE. * check if items are in salesdeal materials, proceed to price discounts clear v_exit. i_items2[] = i_items[]. * Check if current item's product detail is already in i_items SORT i_items BY SDEAL PRDHA KPOSN. DELETE ADJACENT DUPLICATES FROM i_items COMPARING SDEAL PRDHA. SORT: i_items, i_items2 BY KPOSN DESCENDING. WHILE v_exit = space. * continue if there's still items LOOP AT i_items ASSIGNING <fs_items> where sdeal = tsalesdeal. DELETE i_items2 WHERE KPOSN = <fs_items>-kposn. "delete all except duplicate. IF <fs_items>-qty = 0. * if qty is 0, exit while loop v_exit = c_x. ELSE. * deduct 1 per material, per sales deal <fs_items>-qty = <fs_items>-qty - 1. AT LAST. * Get 1 full pack per material combination / sales deal CLEAR wa_fullpack. wa_fullpack-knuma = <fs_items>-sdeal. * check if there is only 1 material, fullpack should be 0 wa_fullpack-full = 1. COLLECT wa_fullpack INTO i_fullpack. ENDAT. ENDIF. ENDLOOP. ENDWHILE. LOOP AT i_fullpack INTO wa_fullpack WHERE knuma = tsalesdeal. READ TABLE i_pairs INTO wa_pairs WITH KEY knuma = wa_fullpack-knuma knumh = gkomv-key-knumh. IF sy-subrc = 0. LOOP AT i_items ASSIGNING <fs_items> WHERE sdeal = wa_fullpack-knuma AND matnr = wa_pairs-c_vakey. <fs_items>-discnt = <fs_items>-kbetr / <fs_items>-scale. "discount * Calculate pricing amount and condition value gkomv-kbetr = <fs_items>-discnt. gkomv-kawrt = wa_fullpack-full * 100. "number of full packages the line item has gkomv-kwert = wa_fullpack-full * gkomv-kbetr. xkwert = gkomv-kwert. tkwert = gkomv-kwert. modify gkomv. READ TABLE xkomv WITH KEY kschl = c_y155 * kposn = <fs_items>-kposn knumh = wa_pairs-knumh. IF sy-subrc = 0. v_tabix = sy-tabix. * Calculate pricing amount & condition value xkomv-kbetr = <fs_items>-discnt. xkomv-kawrt = gkomv-kawrt. xkomv-kwert = gkomv-kwert. xkomv-kfaktor = gkomv-kawrt / 100. "(+)NDXK905646 modify xkomv INDEX v_tabix. CLEAR v_tabix. ENDIF. * <<I'm testing this part if an item is selected and the little coin icon is clicked>> * this code prevents the condition value from blowing up, but what it it was being saved? will this code still work? IF sy-ucomm = c_pko1. READ TABLE tkomv ASSIGNING <fs_tkomv> WITH KEY kposn = <fs_items>-kposn kschl = c_y155 knumh = wa_pairs-knumh. IF sy-subrc = 0. * Calculate pricing amount & condition value <fs_tkomv>-kbetr = <fs_items>-discnt. <fs_tkomv>-kawrt = wa_fullpack-full * 100."number of full packages the line item has <fs_tkomv>-kwert = wa_fullpack-full * gkomv-kbetr. <fs_tkomv>-kfaktor = gkomv-kawrt / 100. ENDIF. ENDIF. ENDLOOP. * <<I'm testing this part if an item is selected and the little coin icon is clicked>> * this code prevents the condition value from blowing up, but what it it was being saved? will this code still work? * I_ITEM2 contains all duplicate materials IF sy-ucomm = c_pko1. LOOP AT i_items2 ASSIGNING <fs_items> WHERE sdeal = wa_fullpack-knuma AND matnr = wa_pairs-c_vakey. READ TABLE tkomv ASSIGNING <fs_tkomv> WITH KEY kposn = <fs_items>-kposn kschl = c_y155 knumh = wa_pairs-knumh. IF sy-subrc = 0. * Calculate pricing amount & condition value to ZERO <fs_tkomv>-kbetr = 0. <fs_tkomv>-kawrt = 0. <fs_tkomv>-kwert = 0. <fs_tkomv>-kfaktor = 0. ENDIF. ENDLOOP. ENDIF. ENDIF. CLEAR: wa_pairs. IF <fs_gkomv> IS ASSIGNED. UNASSIGN <fs_gkomv>. ENDIF. IF <fs_tkomv> IS ASSIGNED. UNASSIGN <fs_tkomv>. ENDIF. IF <fs_xkomv> IS ASSIGNED. UNASSIGN <fs_xkomv>. ENDIF. IF <fs_items> IS ASSIGNED. UNASSIGN <fs_items>. ENDIF. CLEAR wa_fullpack. ENDLOOP. xkomv-kbuff = c_x. ENDIF. endif. endcase. ENDFORM.
| | | ---------------Original Message--------------- From: Jet Austria Sent: Wednesday, October 05, 2011 5:39 AM Subject: Change Condition Value to Zero in VOFM Routine Hi Guys, Need help on changing condition values at item level. During Sales order creation (VA01). We created a routine in VOFM where a condition type will have some discounts for certain combination of materials that are found in a sales deal. For a normal sales order with no duplicate materials, the code works fine for both header and item level. But if the same material number is used for another item in that same sales order (e.g. item 1 and item 3 are the same), the item level condition values blow up for the duplicate materials only. I've been trying to modify TKOMV in our VOFM routine, with the duplicate material number I was placing zero value. But the value doesn't become zero, only somehow it has the same values as with the original material.Is there a way to make the value to zero? Or any userexits that I need to use? (our clients prefer to using only the VOFM routine, but if the userexit really is necessary, we can use it). Thanks, Jet | | __.____._ Copyright © 2011 Toolbox.com and message author. Toolbox.com 4343 N. Scottsdale Road Suite 280, Scottsdale, AZ 85251 | | Popular White Papers In the Spotlight _.____.__ |