offene Bestellungen

www.4AP.de - alles über ABAP  -  Bestände, offene Bestellungen und offene Fertigungsaufträge

um z.B. die Bewertungsklasse umbuchen zu können muss folgendes geprüft werden:


*
* Coded by Thorsten Neubüser - www.4ap.de
*
 
LOOP AT it_daten.
CLEAR: alv_output, alv_output2.
MOVE-CORRESPONDING it_daten TO alv_output.

* Bestandsprüfung
SELECT SINGLE mbew~lbkum mbew~vmkum mara~meins
FROM mbew INNER JOIN mara ON mara~matnr = mbew~matnr
INTO CORRESPONDING FIELDS OF alv_output
WHERE mbew~mandt = sy-mandt
AND mbew~matnr = it_daten-matnr
AND mbew~bwkey = it_daten-werks
AND mbew~bwtar = ''.
IF NOT alv_output-vmkum IS INITIAL.
alv_output-status(1) = 'X'.
alv_output-bestand_vorhanden = 1.
IF p_bstnd = 'X'.
alv_output-delete = 1.
ENDIF. " p_bstnd = 'X'
ENDIF.
IF NOT alv_output-lbkum IS INITIAL.
alv_output-status+1(1) = 'X'.
alv_output-bestand_vorhanden = 1.
IF p_bstnd = 'X'.
alv_output-delete = 1.
ENDIF. " p_bstnd = 'X'
ENDIF.

* Bestellungen
DATA: it_xekdoc TYPE TABLE OF ekdoc WITH HEADER LINE.
CLEAR: alv_output-bestellung_vorhanden, it_xekdoc.
REFRESH: it_xekdoc.
CALL FUNCTION 'ME_CHECK_DOCUMENT_FOR_MATERIAL'
EXPORTING
* EXISTENCE_CHECK = ' '
matnr = it_daten-matnr
* PLANT_INITIAL = ' '
werks = it_daten-werks
* PLANT_INFO = ' '
* BWART =
* BWKEY =
* NO_ACCOUNT_ASSIGNED = ' '
* BMATN =
* MPROF =
* IF_SOBKZ =
* IF_VBELN =
* IF_VBELP =
* IF_PSPNR =
* IMPORTING
* CONTRACT_FLAG =
* DELPLAN_FLAG =
* INFO_FLAG =
* PO_FLAG =
* REQ_FLAG =
* RFQ_FLAG =

TABLES
xekdoc = it_xekdoc.
LOOP AT it_xekdoc.
* Wann ist eine Bestellung noch offen???
* ELIKZ oder EREKZ nicht gesetzt

CLEAR: alv_output-elikz, alv_output-erekz.
SELECT SINGLE elikz erekz FROM ekpo CLIENT SPECIFIED
INTO CORRESPONDING FIELDS OF alv_output
WHERE mandt = sy-mandt
AND ebeln = it_xekdoc-ebeln
AND ebelp = it_xekdoc-ebelp.
IF alv_output-elikz IS INITIAL OR alv_output-erekz IS INITIAL.
IF alv_output-ebeln IS INITIAL.
MOVE-CORRESPONDING it_xekdoc TO alv_output.
alv_output-bestellung_vorhanden = 1.
alv_output-status+2(1) = 'X'.
IF p_bestel = 'X'.
alv_output-delete = 1.
ENDIF. " p_bestel = 'X'
ELSE. " alv_output-ebeln is initial
clear: alv_output2.
MOVE-CORRESPONDING it_daten TO alv_output2.
MOVE-CORRESPONDING it_xekdoc TO alv_output2.
if p_bestel = 'X'.
alv_output2-delete = 1.
endif. " p_bestel = 'X'
APPEND alv_output2.
ENDIF. " alv_output-ebeln is initial
ENDIF. " help_elikz is initial and help_erekz is initial
ENDLOOP.
clear: it_xekdoc.


* Fertigungsaufträge
DATA: it_plant TYPE TABLE OF pre15 WITH HEADER LINE,
et_order TYPE TABLE OF afpo WITH HEADER LINE,
it_order TYPE TABLE OF afpo WITH HEADER LINE.
CALL FUNCTION 'CO_SF_ORDERS_WITHOUT_GR_READ'
EXPORTING
i_matnr = it_daten-matnr
TABLES
it_plant = it_plant " PRE15 table of plants
et_order =
et_order " AFPO orders without good receipt
et_order_error =
it_order. " AFPO orders with goods receipt
* et_order wird derzeit noch nicht ausgewertet. Falls Einträge
* in dieser Tabelle, wäre eine Warnung sinnvoll
* WANN IST EIN AUFTRAG noch offen? ELIKZ = ''

LOOP AT it_order where elikz ne 'X'.
IF NOT it_order-pwerk IS INITIAL.
IF it_order-pwerk IN s_werks and it_order-pwerk = it_daten-werks.
IF p_fauf = 'X'.
alv_output-delete = 1.
ENDIF. " p_fauf = 'X'
IF alv_output-aufnr IS INITIAL.
alv_output-pwerk = it_order-pwerk.
alv_output-dwerk = it_order-dwerk.
alv_output-aufnr = it_order-aufnr.
alv_output-posnr = it_order-posnr.
alv_output-fauf_vorhanden = 1.
alv_output-status+3(1) = 'X'.
ELSE.
clear: alv_output2.
MOVE-CORRESPONDING it_daten TO alv_output2.
MOVE-CORRESPONDING it_xekdoc TO alv_output2.
if p_bestel = 'X'.
alv_output2-delete = 1.
endif. " p_bestel = 'X'
alv_output2-pwerk = it_order-pwerk.
alv_output2-dwerk = it_order-dwerk.
alv_output2-aufnr = it_order-aufnr.
alv_output2-posnr = it_order-posnr.
APPEND alv_output2.
ENDIF. " alv_output-AUFNR is initial
ENDIF.
ENDIF.
IF NOT it_order-dwerk IS INITIAL AND
it_order-dwerk NE it_order-pwerk.
IF it_order-dwerk IN s_werks and it_order-dwerk = it_daten-werks.
IF p_fauf = 'X'.
alv_output-delete = 1.
ENDIF. " p_fauf = 'X'
IF alv_output-aufnr IS INITIAL.
alv_output-pwerk = it_order-pwerk.
alv_output-dwerk = it_order-dwerk.
alv_output-aufnr = it_order-aufnr.
alv_output-posnr = it_order-posnr.
alv_output-fauf_vorhanden = 1.
alv_output-status+3(1) = 'X'.
ELSE. " alv_output-AUFNR is initial
clear: alv_output2.
MOVE-CORRESPONDING it_daten TO alv_output2.
MOVE-CORRESPONDING it_xekdoc TO alv_output2.
if p_bestel = 'X'.
alv_output2-delete = 1.
endif. " p_bestel = 'X'
alv_output2-pwerk = it_order-pwerk.
alv_output2-dwerk = it_order-dwerk.
alv_output2-aufnr = it_order-aufnr.
alv_output2-posnr = it_order-posnr.
APPEND alv_output2.
ENDIF. " alv_output-AUFNR is initial
ENDIF. " it_order-DWERK IN s_WERKS
ENDIF. " OT it_order-DWERK IS INITIAL AND
ENDLOOP. " AT it_order

APPEND alv_output.
ENDLOOP. " at it_daten

APPEND LINES OF alv_output2 TO alv_output.

delete alv_output where delete = 1.

* nur fortfahren wenn mindestens 1 Satz selektiert wurde
DESCRIBE TABLE alv_output LINES sy-tfill.
IF sy-tfill = 0.
MESSAGE i010(es). " nix gefunden
h_fehler = 'X'.
ENDIF. " sy-tfill = 0