REPORT zdemo09.
DATA:BEGIN OF gs_itab,
matnr TYPE mardh-matnr,
werks TYPE mardh-werks,
lgort TYPE mardh-lgort,
lfgja TYPE mardh-lfgja,
lfmon TYPE mardh-lfmon,
labst TYPE mardh-labst,
END OF gs_itab,
gt_itab LIKE TABLE OF gs_itab.
PARAMETERS:
p_matnr LIKE mardh-matnr,
p_werks LIKE mardh-werks,
p_lgort LIKE mardh-lgort,
p_lfgja LIKE mardh-lfgja,
p_lfmon LIKE mardh-lfmon.
SELECT SINGLE
matnr
werks
lgort
lfgja
lfmon
labst
INTO CORRESPONDING FIELDS OF gs_itab
FROM mard
WHERE matnr EQ p_matnr
AND werks EQ p_werks
AND lgort EQ p_lgort.
CHECK sy-subrc EQ 0.
***期末库存落在MARD
IF ( gs_itab-lfgja LT p_lfgja ) OR
( gs_itab-lfgja EQ p_lfgja AND gs_itab-lfmon LE p_lfmon ).
WRITE: '期末库存',gs_itab-labst.
EXIT.
ENDIF.
*期末库存落在MARDH
SELECT
matnr
werks
lgort
lfgja
lfmon
labst
INTO TABLE gt_itab
FROM mardh
WHERE matnr EQ p_matnr
AND werks EQ p_werks
AND lgort EQ p_lgort
AND ( ( lfgja EQ p_lfgja AND lfmon LE p_lfmon ) OR
( lfgja LT p_lfgja ) ).
***期末库存落在MARDH
SORT gt_itab BY matnr werks lgort lfgja DESCENDING lfmon DESCENDING.
LOOP AT gt_itab INTO gs_itab.
WRITE: '期末库存',gs_itab-labst.
EXIT.
ENDLOOP.
阅读(2347) | 评论(0) | 转发(0) |