Actually, I've already written functional module which should work correctly. If you interested I could post the sample here.
Purpose: Correctly read standard price from Material Ledger tables. Taking into account ML structure.
FUNCTION Z_CKML_STPRICE_READ.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" VALUE(P_MATNR) LIKE CKMLHD-MATNR
*" VALUE(P_BWKEY) LIKE CKMLHD-BWKEY
*" VALUE(P_BDATJ) LIKE CKMLCR-BDATJ
*" VALUE(P_POPER) LIKE CKMLCR-POPER
*" VALUE(P_CURTP) LIKE CKMLCR-CURTP
*" EXPORTING
*" VALUE(P_CKMLCR) LIKE CKMLCR STRUCTURE CKMLCR
*" EXCEPTIONS
*" NO_DATA_FOUND
*"----------------------------------------------------------------------
DATA: TMP_CKMLCR LIKE CKMLCR OCCURS 0 WITH HEADER LINE.
TABLES: CKMLHD, CKMLCR.
CLEAR: P_CKMLCR, CKMLHD, TMP_CKMLCR.
SELECT SINGLE * FROM CKMLHD WHERE MATNR = P_MATNR
AND BWKEY = P_BWKEY.
AND MLAST = '3'.
IF SY-SUBRC <> 0.
RAISE NO_DATA_FOUND.
ENDIF.
* trying to locate latest valid and closed period record
SELECT * FROM CKMLCR INTO TABLE TMP_CKMLCR
WHERE KALNR = CKMLHD-KALNR
AND (
( ( BDATJ = P_BDATJ ) AND ( POPER <= P_POPER ) )
OR
( BDATJ < P_BDATJ )
)
AND CURTP = P_CURTP
ORDER BY BDATJ DESCENDING POPER DESCENDING.
IF SY-SUBRC <> 0.
RAISE NO_DATA_FOUND.
ENDIF.
READ TABLE TMP_CKMLCR INDEX 1.
SELECT SINGLE * FROM CKMLCR
INTO P_CKMLCR
WHERE KALNR = TMP_CKMLCR-KALNR
AND BDATJ = TMP_CKMLCR-BDATJ
AND POPER = TMP_CKMLCR-POPER
AND CURTP = TMP_CKMLCR-CURTP.
Social Plugin