SAP MRP清单的动态和静态ABAP的取法

2023-10-12 18:08:48 浏览数 (1)

无意中发现有个程序用IMPORT mdtbx FROM DATABASE mdtc(ar) ID mdkp-dtnum取MRP清单的时候,发现如果一个工厂对应多种MRP区域的时候,取不到另外MRP区域的数据,

但是用函数MD_STOCK_REQUIREMENTS_LIST_API可以取到,经深入分析得知这两种取法的区别:

用语句IMPORT mdtbx FROM DATABASE mdtc(ar) ID mdkp-dtnum取的是上一次MRP运行过后的结果,这个是静态的结果(也就是事物码MD05的结果)。

用函数MD_STOCK_REQUIREMENTS_LIST_API取得是实时的MRP的结果,这个是动态的结果(也就是事物码MD04的结果),此种方法可以区别MRP区域,如果不输入MRP区域

的话,就是默认为一个工厂所有MRP区域所有的结果,如果想取静态的其他MRP区域的结果的话,可以使用下面的代码:

代码语言:javascript复制
REPORT ZMRPTABLE.

TABLES: MDKP,  "Header Data for MRP Document
        MDTB,  "MRP table
        MDTC,  "Aggregated MRP table items
        T457T. "Description of MRP elements

DATA: BEGIN OF MDTBX OCCURS 0.
        INCLUDE STRUCTURE MDTB.
DATA: END   OF MDTBX.

SELECT-OPTIONS: PLANT FOR MDKP-PLWRK OBLIGATORY,
                MATNR FOR MDKP-MATNR OBLIGATORY.
* 默认工厂和MRP区域一样的情况
CLEAR: MDKP, MDTB.
SELECT * FROM MDKP WHERE DTART EQ 'MD'
                     AND MATNR IN MATNR
                     AND PLWRK IN PLANT.
    WRITE:/ MDKP-MATNR, MDKP-PLWRK.
    IF MDKP-CFLAG EQ 'X'.
       CLEAR MDTBX. REFRESH MDTBX.
       IMPORT MDTBX FROM DATABASE MDTC(AR) ID MDKP-DTNUM.
       LOOP AT MDTBX.
         MOVE MDTBX TO MDTB.

         SELECT SINGLE * FROM T457T WHERE SPRAS = 'E'
                                      AND DELKZ = MDTB-DELKZ.

         IF MDTB-PLUMI = '-'. MULTIPLY MDTB-MNG01 BY -1. ENDIF.

         WRITE:/ MDTB-DAT00, T457T-DELB1, MDTB-VSTAT,
                                          MDTB-MNG01, MDTB-LGORT.
       ENDLOOP.
    ELSE.
       SELECT * FROM MDTB
                     WHERE DTNUM EQ MDKP-DTNUM
                     ORDER BY PRIMARY KEY.
         SELECT SINGLE * FROM T457T WHERE SPRAS = 'E'
                                      AND DELKZ = MDTB-DELKZ.

         IF MDTB-PLUMI = '-'. MULTIPLY MDTB-MNG01 BY -1. ENDIF.

         WRITE:/ MDTB-DAT00, T457T-DELB1, MDTB-VSTAT,
                                          MDTB-MNG01, MDTB-LGORT.
       ENDSELECT.
    ENDIF.
ENDSELECT.

* 默认工厂和MRP区域不一样的情况

CLEAR: MDKPDB, MDTB.
SELECT * FROM MDKPDB WHERE DTART EQ 'MD'
                     AND MATNR IN MATNR
                     AND PLWRK IN PLANT.
    WRITE:/ MDKPDB-MATNR, MDKPDB-PLWRK.
    IF MDKP-CFLAG EQ 'X'.
       CLEAR MDTBX. REFRESH MDTBX.
       IMPORT MDTBX FROM DATABASE MDTC(AR) ID MDKPDB-DTNUM.
       LOOP AT MDTBX.
         MOVE MDTBX TO MDTB.

         SELECT SINGLE * FROM T457T WHERE SPRAS = 'E'
                                      AND DELKZ = MDTB-DELKZ.

         IF MDTB-PLUMI = '-'. MULTIPLY MDTB-MNG01 BY -1. ENDIF.

         WRITE:/ MDTB-DAT00, T457T-DELB1, MDTB-VSTAT,
                                          MDTB-MNG01, MDTB-LGORT.
       ENDLOOP.
    ELSE.
       SELECT * FROM MDTB
                     WHERE DTNUM EQ MDKPDB-DTNUM
                     ORDER BY PRIMARY KEY.
         SELECT SINGLE * FROM T457T WHERE SPRAS = 'E'
                                      AND DELKZ = MDTB-DELKZ.

         IF MDTB-PLUMI = '-'. MULTIPLY MDTB-MNG01 BY -1. ENDIF.

         WRITE:/ MDTB-DAT00, T457T-DELB1, MDTB-VSTAT,
                                          MDTB-MNG01, MDTB-LGORT.
       ENDSELECT.
    ENDIF.
ENDSELECT.

0 人点赞