MMQM
MMQM
MMQM
TABLES: QMAT,
JEST,
MARA,
MARC,
MARD,
MKOL,
MSKA,
MSPR,
MCHB,
QALS,
T001L.
*----------------------------------------------------------------------*
INCLUDE <ICON>.
CONSTANTS:
C_PRUEFLOS LIKE QALS-PRUEFLOS VALUE '999999999999',
C_Q_BEST LIKE QALS-INSMK VALUE 'X',
C_KREUZ LIKE QM00-QKZ VALUE 'X'.
*----------------------------------------------------------------------*
SELECT-OPTIONS MATERIAL FOR QMAT-MATNR MATCHCODE OBJECT MAT1.
SELECT-OPTIONS WERK FOR QMAT-WERKS.
*----------------------------------------------------------------------*
DATA:
* inspection types
G_INSP_TYPES LIKE TQ32 OCCURS 0,
* Table of materials
BEGIN OF G_MATTAB OCCURS 0,
MATNR LIKE QMAT-MATNR,
WERKS LIKE QMAT-WERKS,
END OF G_MATTAB,
* Table of quantities
BEGIN OF G_BESTTAB OCCURS 0,
MATNR LIKE QALS-MATNR,
WERKS LIKE QALS-WERKVORG,
LGORT LIKE QALS-LAGORTVORG,
CHARG LIKE QALS-CHARG,
SOBKZ LIKE QALS-SOBKZ,
LIFNR LIKE QALS-LIFNR, "f�r SOBKZ = K
PSPNR LIKE QALS-PS_PSP_PNR, "f�r SOBKZ = Q
KDAUF LIKE QALS-KDAUF, "f�r SOBKZ = E
KDPOS LIKE QALS-KDPOS, "f�r SOBKZ = E
MM_MENGE LIKE QALS-LMENGEZUB,
QM_MENGE LIKE QALS-LMENGEZUB,
MEINS LIKE QALS-MENGENEINH,
PRUEFLOS LIKE QALS-PRUEFLOS, "early inspection
OK LIKE QM00-QKZ,
END OF G_BESTTAB,
* storage locations
G_SLOC_TAB TYPE STANDARD TABLE OF T001L,
GV_EWM_ACTIVE TYPE /SPE/CTRL_IS_ACTIVE,
*
G_FIELD(30),
G_NEW_ICON LIKE ICON_CHECKED VALUE ICON_CHECKED,
G_OK LIKE QM00-QKZ,
G_DATA_AVAILABLE LIKE QM00-QKZ,
*
G_LISTI LIKE SY-LISTI,
G_LILLI LIKE SY-LILLI,
*
END_OF_DATA.
*----------------------------------------------------------------------*
************************************************************************
START-OF-SELECTION.
* Make sure that the report is running only once in a system
DATA:
L_MESSAGE LIKE SY-MSGV1 VALUE 'Report is in usage by &'. "#EC NOTEXT
* read QMAT
SELECT DISTINCT MATNR WERKS
INTO CORRESPONDING FIELDS OF TABLE G_MATTAB
FROM QMAT
FOR ALL ENTRIES IN G_INSP_TYPES
WHERE MATNR IN MATERIAL
AND WERKS IN WERK
AND AKTIV = C_KREUZ
AND ART = G_INSP_TYPES-ART
AND AFR = SPACE. "HUM
************************************************************************
END-OF-SELECTION.
IF G_DATA_AVAILABLE IS INITIAL.
WRITE: /20 ICON_CHECKED AS ICON,
'No differences between QM quantities and' NO-GAP, "#EC NOTEXT
' MM quatities found'. "#EC NOTEXT
ENDIF.
************************************************************************
TOP-OF-PAGE.
ULINE.
WRITE:/' Material Plnt SLoc Batch ' NO-GAP, "#EC NOTEXT
'S MM-Quantity QM-Quantity ' NO-GAP, "#EC NOTEXT
'Vendor Project Customer order'. "#EC NOTEXT
ULINE.
MOVE C_KREUZ TO G_DATA_AVAILABLE.
************************************************************************
AT LINE-SELECTION.
MOVE: SY-LISTI TO G_LISTI,
SY-LILLI TO G_LILLI.
GET CURSOR FIELD G_FIELD.
CHECK G_FIELD EQ 'ICON_CHANGE'.
CHECK G_BESTTAB-OK IS INITIAL.
* select line -> g_besttab filled
IF G_BESTTAB-MM_MENGE LT G_BESTTAB-QM_MENGE.
* more QM quantity
PERFORM LOSE_KORRIGIEREN USING G_BESTTAB-OK.
ELSE.
* more MM quantity
PERFORM BESTAND_KORRIGIEREN USING G_BESTTAB-OK.
ENDIF.
IF G_BESTTAB-OK NE SPACE.
*
READ LINE G_LILLI INDEX G_LISTI.
MOVE 'X' TO G_BESTTAB-OK.
* MODIFY LINE G_LILLI INDEX G_LISTI
* FIELD VALUE G_BESTTAB.
* change Icon to ok
TRANSLATE G_NEW_ICON USING '@ '.
CONDENSE G_NEW_ICON NO-GAPS.
MODIFY LINE G_LILLI INDEX G_LISTI
FIELD VALUE ICON_CHANGE FROM G_NEW_ICON.
ENDIF.
CLEAR G_BESTTAB.
************************************************************************
*&---------------------------------------------------------------------*
*& Form LOSE_LESEN
*&---------------------------------------------------------------------*
* get the lots
*----------------------------------------------------------------------*
FORM LOSE_LESEN.
DATA: L_OBJNR LIKE QALS-OBJNR,
L_INACT LIKE JEST-INACT,
L_XCHPF LIKE QALS-XCHPF,
L_LIFNR LIKE QALS-LIFNR,
L_KDAUF LIKE QALS-KDAUF,
L_KDPOS LIKE QALS-KDPOS,
L_PSPNR LIKE QALS-PS_PSP_PNR,
L_STAT18 LIKE QALS-STAT18,
L_PRUEFLOS LIKE QALS-PRUEFLOS.
CLEAR G_BESTTAB.
*
SELECT MATNR WERKVORG LAGORTVORG CHARG SOBKZ OBJNR
LIFNR PS_PSP_PNR KDAUF KDPOS LMENGEZUB XCHPF
STAT18 PRUEFLOS
INTO (G_BESTTAB-MATNR,G_BESTTAB-WERKS,
G_BESTTAB-LGORT,G_BESTTAB-CHARG,
G_BESTTAB-SOBKZ,L_OBJNR,
L_LIFNR,L_PSPNR,L_KDAUF,L_KDPOS,
G_BESTTAB-QM_MENGE,L_XCHPF,
L_STAT18,L_PRUEFLOS) FROM QALS
FOR ALL ENTRIES IN G_SLOC_TAB
WHERE MATNR EQ G_MATTAB-MATNR
AND WERKVORG EQ G_MATTAB-WERKS
AND WERKVORG EQ G_SLOC_TAB-WERKS
AND STAT01 EQ C_KREUZ
AND INSMK EQ C_Q_BEST
AND STAT34 EQ SPACE
AND LMENGEZUB GT 0
AND LAGORTVORG EQ G_SLOC_TAB-LGORT.
SELECT SINGLE INACT FROM JEST INTO L_INACT
WHERE OBJNR EQ L_OBJNR
AND STAT EQ 'I0203'
AND INACT EQ SPACE.
* lot only relevant with active JEST-entry which is not active
IF SY-SUBRC IS INITIAL.
SELECT SINGLE INACT FROM JEST INTO L_INACT
WHERE OBJNR EQ L_OBJNR
AND STAT EQ 'I0220'
AND INACT EQ SPACE.
IF NOT SY-SUBRC IS INITIAL.
* lot quantity is not comlete posted (redundant to STAT34)
* special stock ?
CLEAR: G_BESTTAB-LIFNR,
G_BESTTAB-PSPNR,
G_BESTTAB-KDAUF,
G_BESTTAB-KDPOS.
CASE G_BESTTAB-SOBKZ.
WHEN SPACE.
WHEN 'K'. MOVE L_LIFNR TO G_BESTTAB-LIFNR.
WHEN 'Q'. MOVE L_PSPNR TO G_BESTTAB-PSPNR.
WHEN 'E'.
MOVE L_KDAUF TO G_BESTTAB-KDAUF.
MOVE L_KDPOS TO G_BESTTAB-KDPOS.
ENDCASE.
IF L_STAT18 EQ 'Y' "early insp.lot without batch
AND L_XCHPF NE SPACE
AND G_BESTTAB-CHARG IS INITIAL .
ENDSELECT.
IF L_XCHAR IS INITIAL.
* not batch controlled
CLEAR G_BESTTAB.
MOVE-CORRESPONDING G_MATTAB TO G_BESTTAB.
SELECT INSME LGORT INTO (G_BESTTAB-MM_MENGE,G_BESTTAB-LGORT)
FROM MARD
FOR ALL ENTRIES IN G_SLOC_TAB
WHERE MATNR EQ G_MATTAB-MATNR
AND WERKS EQ G_MATTAB-WERKS
AND WERKS EQ G_SLOC_TAB-WERKS
AND LGORT EQ G_SLOC_TAB-LGORT.
APPEND G_BESTTAB.
ENDSELECT.
ELSE.
* Batch controlled
CLEAR G_BESTTAB.
MOVE-CORRESPONDING G_MATTAB TO G_BESTTAB.
SELECT CINSM LGORT CHARG
INTO (G_BESTTAB-MM_MENGE,G_BESTTAB-LGORT,
G_BESTTAB-CHARG)
FROM MCHB
FOR ALL ENTRIES IN G_SLOC_TAB
WHERE MATNR EQ G_MATTAB-MATNR
AND WERKS EQ G_MATTAB-WERKS
AND WERKS EQ G_SLOC_TAB-WERKS
AND LGORT EQ G_SLOC_TAB-LGORT.
APPEND G_BESTTAB.
ENDSELECT.
ENDIF.
* consignment stock
CLEAR G_BESTTAB.
MOVE-CORRESPONDING G_MATTAB TO G_BESTTAB.
*&---------------------------------------------------------------------*
*& Form LOSE_KORRIGIEREN
*&---------------------------------------------------------------------*
* Reduce open quantity for lot and update
*----------------------------------------------------------------------*
FORM LOSE_KORRIGIEREN USING P_OK LIKE QM00-QKZ.
DATA:
L_SUBRC LIKE SY-SUBRC,
L_MEINS LIKE MARA-MEINS,
L_KUNNR LIKE QALS-KUNNR, "Dummy
L_DIFMG LIKE QALS-LMENGEZUB.
*
CLEAR P_OK.
* get unit of measure
PERFORM HOLE_MARA_MEINS USING G_BESTTAB-MATNR
CHANGING L_MEINS.
CASE L_SUBRC.
WHEN 0.
" Nothing to do
WHEN 4.
MESSAGE I164(QA).
WHEN 8.
MESSAGE I077(QA) WITH G_BESTTAB-MATNR
G_BESTTAB-CHARG
G_BESTTAB-WERKS
G_BESTTAB-LGORT.
WHEN 12.
MESSAGE I078(QA) WITH G_BESTTAB-MATNR
G_BESTTAB-CHARG
G_BESTTAB-WERKS
G_BESTTAB-PRUEFLOS.
WHEN OTHERS.
ENDCASE.
*&---------------------------------------------------------------------*
*& Form HOLE_MARA_MEINS
*&---------------------------------------------------------------------*
* Get unit
*----------------------------------------------------------------------*
* --> P_MATNR
* <-- P_MEINS
*----------------------------------------------------------------------*
FORM HOLE_MARA_MEINS USING P_MATNR
CHANGING P_MEINS.
STATICS:
S_MATNR LIKE MARA-MATNR,
S_MEINS LIKE MARA-MEINS.
IF P_MATNR NE S_MATNR.
MOVE P_MATNR TO S_MATNR.
SELECT SINGLE MEINS INTO (S_MEINS) FROM MARA
WHERE MATNR EQ S_MATNR.
ENDIF.
MOVE S_MEINS TO P_MEINS.
ENDFORM. " HOLE_MARA_MEINS
*&---------------------------------------------------------------------*
*& Form bestand_korrigieren
*&---------------------------------------------------------------------*
* Special routine for quantity correction in quality stock
*----------------------------------------------------------------------*
FORM BESTAND_KORRIGIEREN USING P_OK LIKE QM00-QKZ.
DATA:
L_MEINS LIKE MARA-MEINS,
L_DIFMG LIKE QALS-LMENGEZUB,
L_RMQED LIKE RMQED,
L_QALS LIKE QALS.
*
CLEAR P_OK.
*
L_DIFMG = G_BESTTAB-MM_MENGE - G_BESTTAB-QM_MENGE.