Skip to Content
0
Former Member
Jul 09, 2010 at 10:59 AM

Sales return delivery - amount takes current MAP instead of old MAP

52 Views

Dear All,

I have the same problem as described in the post:

return-delivery-goods-receipt-amount-takes-current

Which are the settings I have to made in order to determine the system to take the old MAP (my cost at the sale moment) instead of the current MAP. I have a return delivery and the PGI will generate a material document with 653 movement type. After the PGI - the system should recalculate the MAP.

I use BADI LE_SHP_GOODSMOVEMENT, but the system still overwrites old MAP with the current MAP.

 
DATA: lmseg TYPE LINE OF shp_imsegvb_t , 
      llips TYPE LINE OF shp_lips_t , 
      lvgbel TYPE lips-vgbel , 
      lvgpos TYPE lips-vgpos , 
      lcmpv TYPE mbew-verpr , 
      lwaers TYPE mseg-waers , 
      lmeins TYPE mseg-meins . 

LOOP AT ct_ximseg INTO lmseg . 
     LOOP AT it_xlips INTO llips . 
          CLEAR lvgbel. CLEAR lvgpos . 
          IF lmseg-vbeln = llips-vbeln AND 
             lmseg-posnr = llips-posnr . 
                 lvgbel = llips-vgbel . 
                 lvgpos = llips-vgpos . 
          ENDIF . 
          IF NOT lvgbel IS INITIAL AND NOT lvgpos IS INITIAL . 
                 CALL FUNCTION 'Z_CMPV' 
                      EXPORTING i_vgbel = lvgbel 
                                i_vgpos = lvgpos 
                      IMPORTING e_cmpv = lcmpv 
                                e_waers = lwaers 
                                e_meins = lmeins 
                      EXCEPTIONS 
                                ERR_NO_RECORD_FOUND = 4 . 
          ENDIF . 
     ENDLOOP . 
     IF lmseg-meins = lmeins . 
        lmseg-dmbtr = lcmpv * lmseg-menge . 
        lmseg-waers = lwaers . 
        MODIFY ct_ximseg FROM lmseg . 
     ENDIF . 
ENDLOOP . 

And the function module:

 
TABLES: vbap, vbrp, vbfa, mseg . 
DATA: ldmbtr LIKE mseg-dmbtr , 
      lwaers LIKE mseg-waers , 
      lmenge LIKE mseg-menge , 
      lmeins LIKE mseg-meins , 
      lmblnr LIKE mseg-mblnr , 
      lzeile LIKE mseg-zeile . 

SELECT c~vbeln c~posnn 
       INTO (lmblnr, lzeile) 
       FROM ( vbap AS a 
              INNER JOIN vbrp AS b ON a~vgbel = b~vbeln AND 
                                      a~vgpos = b~posnr 
              INNER JOIN vbfa AS c ON b~vgbel = c~vbelv AND 
                                      b~vgpos = c~posnv ) 
       WHERE a~vbeln = i_vgbel AND 
             a~posnr = i_vgpos AND 
             b~vgtyp = 'J' AND 
             c~vbtyp_n = 'R' AND 
             c~vbtyp_v = 'J' AND 
             c~bwart = '601'. 
ENDSELECT . 
IF sy-subrc = 0 . 
    SELECT SINGLE dmbtr waers menge meins 
           FROM mseg 
           INTO (ldmbtr, lwaers, lmenge, lmeins) 
           WHERE mblnr = lmblnr AND 
                 zeile = lzeile . 
    IF sy-subrc = 0 . 
          e_cmpv = ldmbtr / lmenge . 
          e_waers = lwaers . 
          e_meins = lmeins . 
    ENDIF . 
ENDIF . 

Could you provide some help?

Thanks.