How To Obtain Material Price in ABAP

If you want to read the prices of a material in ABAP, you may find the following sample code useful. Please note that KALN1 in GT_ALVITEM would be filled from MBEW.

*&———————————————————————*
*& Form read_function_prices
*&———————————————————————*
FORM read_function_prices.

DATA:
BEGIN OF lt_kalnr OCCURS 0,
werks LIKE mbew-werks,
matnr LIKE mbew-matnr,
kalnr LIKE mbew-kaln1,
END OF lt_kalnr,

lt_ckmlpp TYPE ckmlpp OCCURS 0 WITH HEADER LINE,
lt_ckmlcr TYPE ckmlcr OCCURS 0 WITH HEADER LINE,
lt_ckmlhd TYPE ckmlhd OCCURS 0 WITH HEADER LINE,

lv_bdatj TYPE ckmlpp-bdatj,
lv_poper TYPE ckmlpp-poper.

* Başlık tablosuna malzemelerimizi dolduralım
LOOP AT gt_alvitem.
CLEAR lt_ckmlhd.
lt_ckmlhd-kalnr = gt_alvitem-kaln1.
APPEND lt_ckmlhd.
ENDLOOP.

* Dönemler
lv_poper = p_poper.
lv_bdatj = p_gjahr.

* Fonksiyonu çağıralım
CALL FUNCTION ‘CKMS_PERIOD_READ_ONLY’
EXPORTING
i_period_from = lv_poper
i_year_from = lv_bdatj
i_period_to = lv_poper
i_year_to = lv_bdatj
TABLES
et_ckmlpp = lt_ckmlpp[]
et_ckmlcr = lt_ckmlcr[]
it_ckmlhd = lt_ckmlhd[].

* Okuduğumuz fiyatları geri döndürelim
LOOP AT lt_ckmlcr WHERE curtp EQ gc_curtp.
READ TABLE lt_ckmlpp WITH KEY kalnr = lt_ckmlcr-kalnr
bdatj = lt_ckmlcr-bdatj
poper = lt_ckmlcr-poper
untper = lt_ckmlcr-untper.
CHECK sy-subrc EQ 0.

READ TABLE gt_alvitem WITH KEY kaln1 = lt_ckmlcr-kalnr.
CHECK sy-subrc EQ 0.

gt_alvitem-salk3 = lt_ckmlcr-salk3.
gt_alvitem-lbkum = lt_ckmlpp-lbkum.
MODIFY gt_alvitem INDEX sy-tabix.
ENDLOOP.

ENDFORM. ” read_function_prices

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s