Application Development and Automation 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: 
Read only

Function Module/BAPI

Former Member
0 Likes
1,152

Hi,

I have a simple question, if there is a function module/BAPI/any other way for getting the price of a material on a given date?

4 REPLIES 4
Read only

valter_oliveira
Active Contributor
0 Likes
771

Hello.

Check database tables A004 and then KONP.

Example:


DATA: l_knumh LIKE a004-knumh,
      l_kpein TYPE kpein.

  CLEAR: l_knumh, l_kpein, p_kbetr.
  SELECT knumh FROM a004 UP TO 1 ROWS
    INTO (l_knumh)
   WHERE kappl EQ 'V'
     AND kschl EQ 'ZPR0'
     AND vkorg EQ 'INCM'
     AND vtweg EQ 'I1'
     AND matnr EQ p_matnr
     AND datbi GE sy-datum     "Fim de validade
     AND datab LE sy-datum.    "Início de validade
    EXIT.
  ENDSELECT.
  CHECK sy-subrc EQ 0.

* Valor da condição
  SELECT kbetr kpein
    FROM konp UP TO 1 ROWS
    INTO (p_kbetr, l_kpein)
   WHERE knumh EQ l_knumh
     AND konwa EQ 'EUR'.
    EXIT.
  ENDSELECT.
  CHECK sy-subrc EQ 0.

* Divide preço pela unidade de preço da condição
  DIVIDE p_kbetr BY l_kpein.

Regards.

Valter Oliveira.

Read only

0 Likes
771

Thanks for your reply. I couldn;t quite follow your code. Could you please explain, what are you trying to retreive ?

I understand the table MBEWH has the historical price information, but for some wierd reason the standard price for the period we are interested in, is 0.00. Otherwise I suppose thats the table that we can use for getting the standard price for the material in the given period(year, month).

Any other way, by which we can get the information? Can using CDHDR and CDPOS be of any help?

Edited by: SAP Novice on Jul 11, 2008 3:05 PM

Read only

0 Likes
771

Hi again.

Sorry for the missunderstood. I though that you were talking about sales price of materials ... Regarding the materials price that you need they are kept in tables MBEW and MBEWH.

I'll give you an example of how it is stored. MBEWH doesn't give you the price in all periods. It gives you the history of the change periods. Periods where the price have changed. So, if you want the price at, for example, 4 months ago, you should go to MBEWH using period 3, and then, if you do not find a price, must add one period at a time until present.


FORM f_calc_price USING p_matnr p_werks
               CHANGING p_vprsv p_stprs p_verpr p_peinh p_bklas.

* Actual Price 
  CLEAR mbew.
  SELECT SINGLE vprsv stprs verpr peinh bklas FROM mbew
           INTO (mbew-vprsv, mbew-stprs, mbew-verpr, mbew-peinh,
                 mbew-bklas)
          WHERE matnr EQ p_matnr
            AND bwkey EQ p_werks
            AND bwtar EQ space.

* Historic price of selected period
  CLEAR mbewh.
  READ TABLE t_mbewh INTO wa_mbewh
        WITH TABLE KEY matnr = <fs1>-matnr
                       bwkey = <fs1>-werks
                       lfgja = p_ano
                       lfmon = p_per.
  IF sy-subrc EQ 0.
    MOVE: wa_mbewh-vprsv TO mbew-vprsv,
          wa_mbewh-stprs TO mbew-stprs,
          wa_mbewh-verpr TO mbew-verpr,
          wa_mbewh-peinh TO mbew-peinh,
          wa_mbewh-bklas TO mbew-bklas.
  ELSE.
    w_mes = p_per.
    w_ano = p_ano.

*   w_dif_mes
    DO w_dif_mes TIMES.
      ADD 1 TO w_mes.
      WRITE w_mes TO w_per.
*Se mudou de ano, o mês passa a Janeiro
      IF w_per EQ 13.
        ADD 1 TO w_ano.
        w_mes = 1.
        w_per = 1.
      ENDIF.
      IF w_per LT 10 AND w_per NE '01'.
        CONCATENATE '0' w_per INTO w_per.
      ENDIF.
      READ TABLE t_mbewh INTO wa_mbewh
            WITH TABLE KEY matnr = <fs1>-matnr
                           bwkey = <fs1>-werks
                           lfgja = w_ano
                           lfmon = w_per.
      CHECK sy-subrc EQ 0.
      MOVE: wa_mbewh-vprsv TO mbew-vprsv,
            wa_mbewh-stprs TO mbew-stprs,
            wa_mbewh-verpr TO mbew-verpr,
            wa_mbewh-peinh TO mbew-peinh,
            wa_mbewh-bklas TO mbew-bklas.
      EXIT.
    ENDDO.
  ENDIF.  "sy-subrc eq 0

  MOVE: mbew-vprsv TO p_vprsv,
        mbew-stprs TO p_stprs,
        mbew-verpr TO p_verpr,
        mbew-peinh TO p_peinh,
        mbew-bklas TO p_bklas.

ENDFORM.

Regards.

Valter Oliveira.

Read only

Former Member
0 Likes
771

hiiii

FM which will give you all details like below.try using them

BAPI_MATERIAL_GET_DETAIL

regards

twinkal