MMQM

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 10

REPORT ZQEVAC20 LINE-SIZE 255 NO STANDARD PAGE HEADING.

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

CALL FUNCTION 'ENQUEUE_EQQALS1'


EXPORTING
PRUEFLOS = C_PRUEFLOS
EXCEPTIONS
FOREIGN_LOCK = 1.

IF NOT SY-SUBRC IS INITIAL.


REPLACE '&' WITH SY-MSGV1 INTO L_MESSAGE.
MESSAGE I208(00) WITH L_MESSAGE.
SUBMIT (SY-REPID) VIA SELECTION-SCREEN.
ENDIF.

* possible inxpection types


SELECT * INTO TABLE G_INSP_TYPES FROM TQ32
WHERE HERKUNFT IN ('01', '04', '05', '08', '09').

* 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

* read storage locations


IF NOT G_MATTAB[] IS INITIAL.
SELECT * FROM T001L INTO T001L
FOR ALL ENTRIES IN G_MATTAB
WHERE WERKS = G_MATTAB-WERKS.

* check stock is not EWM relevant


GV_EWM_ACTIVE =
/SPE/CL_CTRL=>IS_EWM( I_PLANT = T001L-WERKS
I_STLOC = T001L-LGORT ).
* add stock into table
* in case it is not HU revant and not EWM relevant
IF T001L-XHUPF IS INITIAL
AND GV_EWM_ACTIVE IS INITIAL.
APPEND T001L TO G_SLOC_TAB.
ENDIF.
ENDSELECT.
ENDIF.
*
LOOP AT G_MATTAB.
*
REFRESH G_BESTTAB. CLEAR G_BESTTAB.
*----------------------------------------------------------------------*
* Q-stock of materials
IF NOT G_SLOC_TAB[] IS INITIAL.
PERFORM MM_BEST_LESEN.
ENDIF.
*----------------------------------------------------------------------*
* quantities of inspection lots
PERFORM LOSE_LESEN.
* evaluate lots
LOOP AT G_BESTTAB.
IF G_BESTTAB-MM_MENGE NE G_BESTTAB-QM_MENGE.
* different quatity. write info
WRITE:/(3) ICON_CHANGE AS ICON HOTSPOT,
4 G_BESTTAB-MATNR,
G_BESTTAB-WERKS,
G_BESTTAB-LGORT,
G_BESTTAB-CHARG,
G_BESTTAB-SOBKZ,
G_BESTTAB-MM_MENGE, "#EC UOM_IN_MES
G_BESTTAB-QM_MENGE, "#EC UOM_IN_MES
G_BESTTAB-LIFNR,
G_BESTTAB-PSPNR,
G_BESTTAB-KDAUF,
G_BESTTAB-KDPOS NO-ZERO.
HIDE: G_BESTTAB.
ENDIF.
ENDLOOP.
ENDLOOP.
* Initialize workarea
CLEAR G_BESTTAB.

************************************************************************
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 .

MOVE L_PRUEFLOS TO G_BESTTAB-PRUEFLOS.


ELSE.
CLEAR G_BESTTAB-PRUEFLOS.
ENDIF.
COLLECT G_BESTTAB.
ENDIF.
ENDIF.

ENDSELECT.

ENDFORM. " LOSE_LESEN


*&---------------------------------------------------------------------*
*& Form MM_BEST_LESEN
*&---------------------------------------------------------------------*
* Quantity per Material/Plant
*----------------------------------------------------------------------*
FORM MM_BEST_LESEN.
DATA:
L_XCHAR LIKE MARC-XCHAR.

SELECT SINGLE XCHAR INTO (L_XCHAR) FROM MARC


WHERE MATNR EQ G_MATTAB-MATNR
AND WERKS EQ G_MATTAB-WERKS.

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.

SELECT SINSM LGORT CHARG SOBKZ LIFNR


INTO (G_BESTTAB-MM_MENGE,G_BESTTAB-LGORT,
G_BESTTAB-CHARG,G_BESTTAB-SOBKZ,G_BESTTAB-LIFNR)
FROM MKOL
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.
* sales order stock
CLEAR G_BESTTAB.
MOVE-CORRESPONDING G_MATTAB TO G_BESTTAB.

SELECT KAINS LGORT CHARG SOBKZ VBELN POSNR


INTO (G_BESTTAB-MM_MENGE,G_BESTTAB-LGORT,
G_BESTTAB-CHARG,G_BESTTAB-SOBKZ,
G_BESTTAB-KDAUF,G_BESTTAB-KDPOS)
FROM MSKA
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.
* project stock
CLEAR G_BESTTAB.
MOVE-CORRESPONDING G_MATTAB TO G_BESTTAB.
SELECT PRINS LGORT CHARG SOBKZ PSPNR
INTO (G_BESTTAB-MM_MENGE,G_BESTTAB-LGORT,
G_BESTTAB-CHARG,G_BESTTAB-SOBKZ,G_BESTTAB-PSPNR)
FROM MSPR
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.

ENDFORM. " MM_BEST_LESEN

*&---------------------------------------------------------------------*
*& 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.

L_DIFMG = G_BESTTAB-QM_MENGE - G_BESTTAB-MM_MENGE.


* -> subtract
CALL FUNCTION 'QELA_LOT_QUANTITY_CORRECTIONS'
EXPORTING
I_MATNR = G_BESTTAB-MATNR
I_CHARG = G_BESTTAB-CHARG
I_DIFMG = L_DIFMG
I_MEINS = L_MEINS
I_WERKS = G_BESTTAB-WERKS
I_LGORT = G_BESTTAB-LGORT
I_SOBKZ = G_BESTTAB-SOBKZ
I_KDAUF = G_BESTTAB-KDAUF
I_KDPOS = G_BESTTAB-KDPOS
I_LIFNR = G_BESTTAB-LIFNR
I_PS_PSP_PNR = G_BESTTAB-PSPNR
I_KUNNR = L_KUNNR
I_INSP_LOT = G_BESTTAB-PRUEFLOS
* I_WINX1_30 = 2
* I_WINX2_30 = 75
* I_WINY1_30 = 5
* I_WINY2_30 = 15
IMPORTING
E_SUBRC = L_SUBRC.
* EXCEPTIONS
* no_authority = 1.
IF NOT SY-SUBRC IS INITIAL. "#EC *
MESSAGE ID SY-MSGID TYPE 'I' NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
EXIT.
ENDIF.

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.

* if o.k. -> save !


IF L_SUBRC IS INITIAL.
COMMIT WORK AND WAIT.
MOVE C_KREUZ TO P_OK.
ENDIF.

ENDFORM. " LOSE_KORRIGIEREN

*&---------------------------------------------------------------------*
*& 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.

* get unit of measure


PERFORM HOLE_MARA_MEINS USING G_BESTTAB-MATNR
CHANGING L_MEINS.
*
DATA:
L_TEXT(80),
L_IMKPF LIKE IMKPF,
L_IMSEG LIKE IMSEG,
L_IMSEGTAB LIKE IMSEG OCCURS 1,
L_EMKPF LIKE EMKPF,
L_EMSEG LIKE EMSEG,
L_EMSEGTAB LIKE EMSEG OCCURS 1.
* material doc. header
MOVE : SY-DATUM TO L_IMKPF-BLDAT,
SY-DATUM TO L_IMKPF-BUDAT,
'Correction doc. through QM'(111) TO L_IMKPF-BKTXT. "#EC NOTEXT
*
* Canc�l-posting for quality -> unrestricted (check TQ07M)
MOVE: '321' TO L_IMSEG-BWART.
* additional fields
MOVE : G_BESTTAB-MATNR TO L_IMSEG-MATNR,
G_BESTTAB-WERKS TO L_IMSEG-WERKS,
L_MEINS TO L_IMSEG-ERFME,
L_DIFMG TO L_IMSEG-ERFMG,
G_BESTTAB-CHARG TO L_IMSEG-CHARG,
G_BESTTAB-LGORT TO L_IMSEG-LGORT,
G_BESTTAB-SOBKZ TO L_IMSEG-SOBKZ,
G_BESTTAB-LIFNR TO L_IMSEG-LIFNR,
G_BESTTAB-PSPNR TO L_IMSEG-MAT_PSPNR,
G_BESTTAB-KDAUF TO L_IMSEG-MAT_KDAUF,
G_BESTTAB-KDPOS TO L_IMSEG-MAT_KDPOS.
*
APPEND L_IMSEG TO L_IMSEGTAB.
*
* Temporary deactivation of QM in MM !
CALL FUNCTION 'QAAT_QM_ACTIVE_INACTIVE'
EXPORTING
AKTIV = SPACE.
CALL FUNCTION 'MB_CREATE_GOODS_MOVEMENT'
EXPORTING
IMKPF = L_IMKPF
XALLP = C_KREUZ
XALLR = C_KREUZ
CTCOD = 'MB11'
XQMCL = C_KREUZ
IMPORTING
EMKPF = L_EMKPF
TABLES
IMSEG = L_IMSEGTAB
EMSEG = L_EMSEGTAB.
* Reactivation of QM in MM !
CALL FUNCTION 'QAAT_QM_ACTIVE_INACTIVE'
EXPORTING
AKTIV = C_KREUZ.
* Check posting
IF NOT L_EMKPF-SUBRC LE 1.
IF NOT L_EMKPF-MSGNO IS INITIAL.
MESSAGE ID L_EMKPF-MSGID TYPE 'I' NUMBER L_EMKPF-MSGNO
WITH L_EMKPF-MSGV1 L_EMKPF-MSGV2 L_EMKPF-MSGV3 L_EMKPF-MSGV4.
* Error
EXIT.
ENDIF.
LOOP AT L_EMSEGTAB INTO L_EMSEG.
IF NOT L_EMSEG-MSGNO IS INITIAL.
* Error in stock posting
MESSAGE ID L_EMSEG-MSGID TYPE 'I' NUMBER L_EMSEG-MSGNO
WITH L_EMSEG-MSGV1 L_EMSEG-MSGV2 L_EMSEG-MSGV3 L_EMSEG-MSGV4.
* Error
EXIT.
ENDIF.
ENDLOOP.
ELSE.
* o.k., -> save !
CALL FUNCTION 'MB_POST_GOODS_MOVEMENT'.
COMMIT WORK AND WAIT.
MOVE C_KREUZ TO P_OK.
ENDIF.
ENDFORM. " bestand_korrigieren.

You might also like