DATA:
si_edidc TYPE edidc,
si_ltap TYPE ltap,
si_edid4 TYPE edid4,
n_color TYPE i,
i_vbuk TYPE vbuk,
wa_docnum TYPE edidc-docnum,
input_exception TYPE bdwf_param-exception VALUE 0,
c_01 TYPE ekkn-zekkn VALUE '01',
c_02 TYPE zidcs-statut VALUE '02',
c_x TYPE c VALUE 'X',
c_user TYPE sy-uname VALUE 'ARMANNOC',
display_action TYPE sy-ucomm.
TABLES :
edidc, "Control record (IDoc)
edids, "Status Record (IDoc)
edid4, "IDoc Data Records
mseg, "Document Segment: Material
ekes, "Vendor Confirmations
ekko, "Purchasing Document header
vekp, "Handling Unit - Header Table
z0imm01, "Donnees de confirmation inter-site
teds2, "Short description of IDoc status values
dfies, "DD Interface: Table Fields for DDIF_FIELDINFO_GET
vbuk, "Sales Document: Header Status and Administrative Data
ekpo, "Purchasing Document Item
tvarv, "Table of variables in selection criteria
ltap, "Transfer order item
mard, "Storage Location Data for Material
mchb, "Batch Stocks
mska, "Sales Order Stock
aufk, "Order master data
zidcs, "Table des statuts d'IDOCS. Declaration de production
ekkn, "Account Assignment in Purchasing Document
lips.
DATA :
ti_edidc TYPE edidc OCCURS 0 WITH HEADER LINE,
ti_edid4 TYPE edid4 OCCURS 0 WITH HEADER LINE,
ti_edids TYPE edids OCCURS 0 WITH HEADER LINE,
ti_vekp TYPE vekp OCCURS 0 WITH HEADER LINE,
changed_fields_edidc TYPE dfies OCCURS 0 WITH HEADER LINE,
changed_fields_edid4 TYPE dfies OCCURS 0 WITH HEADER LINE,
ti_mseg TYPE mseg OCCURS 0 WITH HEADER LINE,
ti_ltap TYPE ltap OCCURS 0 WITH HEADER LINE,
ti_lips TYPE lips OCCURS 0 WITH HEADER LINE,
ti_lips_idoc TYPE e1vpaci OCCURS 0 WITH HEADER LINE.
*IT for Old/New External Handling Unit Identification
DATA: BEGIN OF ti_exidv OCCURS 0.
DATA:
old TYPE e1vpach-exidv,
new TYPE e1vpach-exidv.
DATA: END OF ti_exidv.
*IT for Vendor Confirmations & Purchasing document type
DATA: BEGIN OF ti_lo_ekko OCCURS 0.
INCLUDE STRUCTURE ekko.
DATA:
xblnr TYPE ekes-xblnr,
elikz TYPE ekpo-elikz,
ebelp TYPE ekpo-ebelp.
DATA: END OF ti_lo_ekko.
*IT for Control record (IDoc)and Short description of IDoc status values
DATA: BEGIN OF ti_n_edidc OCCURS 0.
INCLUDE STRUCTURE edidc.
DATA descrp TYPE teds2-descrp.
DATA: END OF ti_n_edidc.
*IT for Add goods movement from external system: Item / IDoc number
DATA: BEGIN OF ti_e1mbxyi OCCURS 0.
DATA docnum TYPE edidc-docnum.
INCLUDE STRUCTURE e1mbxyi.
DATA: END OF ti_e1mbxyi.
*IT Transfer Order Item and Control / IDoc number
DATA: BEGIN OF ti_e1ltori OCCURS 0.
DATA docnum TYPE edidc-docnum.
INCLUDE STRUCTURE e1ltori.
DATA: END OF ti_e1ltori.
*Rajout MRD le 31/01/2008
DATA: BEGIN OF ti_e1ltcoi OCCURS 0.
DATA docnum TYPE edidc-docnum.
INCLUDE STRUCTURE e1ltcoi.
DATA: END OF ti_e1ltcoi.
* IT for Batch and Sales Order Stock informations
DATA: BEGIN OF ti_batch_stock OCCURS 0.
DATA:
matnr TYPE mska-matnr,
werks TYPE mska-werks,
lgort TYPE mska-lgort,
charg TYPE mska-charg,
clabs TYPE mchb-clabs,
cinsm TYPE mchb-cinsm,
cspem TYPE mchb-cspem,
cvmla TYPE mchb-cvmla,
cvmin TYPE mchb-cvmin,
cvmsp TYPE mchb-cvmsp,
sobkz TYPE mska-sobkz,
vbeln TYPE mska-vbeln ,
posnr TYPE mska-posnr,
kalab TYPE mska-kalab,
kains TYPE mska-kains,
kaspe TYPE mska-kaspe,
kavla TYPE mska-kavla,
kavin TYPE mska-kavin,
kavsp TYPE mska-kavsp.
DATA: END OF ti_batch_stock.
SELECT-OPTIONS s_mestyp FOR edidc-mestyp
OBLIGATORY.
SELECT-OPTIONS s_datum FOR sy-datum
DEFAULT sy-datum
OBLIGATORY.
PARAMETERS p_status TYPE edidc-status
OBLIGATORY
DEFAULT c_status_in_application_error.
**-------------------------------------------------------------------*
** read data into IT_DATA
**-------------------------------------------------------------------*
*Control record (IDoc)
CLEAR ti_edidc.
REFRESH ti_edidc.
SELECT * FROM edidc
INTO CORRESPONDING FIELDS OF TABLE ti_edidc
WHERE docnum IN s_docnum
AND status = p_status
AND mestyp IN s_mestyp
AND upddat IN s_datum.
IF sy-subrc = 0.
*Exclude Idoc already deleted
CLEAR si_edidc.
LOOP AT ti_edidc
INTO si_edidc
WHERE status NE c_status_in_idoc_processed.
*IDoc Data Records from 4.0 onwards
CLEAR ti_edid4.
REFRESH ti_edid4.
SELECT * FROM edid4
INTO CORRESPONDING FIELDS OF TABLE ti_edid4
WHERE docnum = si_edidc-docnum.
CHECK sy-subrc = 0.
CLEAR si_edid4.
LOOP AT ti_edid4
INTO si_edid4.
*Idoc already deleted
READ TABLE ti_edidc WITH KEY
docnum = si_edid4-docnum
status = c_status_in_idoc_processed.
CHECK NOT sy-subrc = 0.
************************************************************************
*Message type
CASE si_edidc-mestyp.
************************************************************************
* IDOC Z1IMM061 - Recept° commandes d'achat sous-traitance de SPIN
WHEN 'Z1IMM061'.
*Segment Remontee reception sur commande d'achat de SPIN
perform_segment z1e1imm061.
conversion_exit_alpha_input si_z1e1imm061-vbeln.
*Account Assignment in Purchasing Document
SELECT SINGLE * FROM ekkn
WHERE ebeln = si_z1e1imm061-ebeln
AND ebelp = si_z1e1imm061-ebelp
AND zekkn = c_01. "'01'
CHECK:
sy-subrc = 0 AND
ekkn-vbeln <> si_z1e1imm061-vbeln.
*Storage Location Data for Material
SELECT SINGLE * FROM mard
WHERE matnr = si_z1e1imm04-matnr
AND werks = si_z1e1imm04-werks
AND lgort = si_z1e1imm04-lgort.
CHECK sy-subrc = 0.
*Batch Stocks
SELECT SINGLE * FROM mchb
WHERE matnr = si_z1e1imm04-matnr
AND werks = si_z1e1imm04-werks
AND lgort = si_z1e1imm04-lgort
AND charg = si_z1e1imm04-lotva.
*Order master data
SELECT SINGLE * FROM aufk
WHERE aufnr = si_z1e1imm04-aufnr.
IF NOT aufk-kdauf IS INITIAL.
*Sales Order Stock
SELECT SINGLE * FROM mska
WHERE matnr = si_z1e1imm04-matnr
AND werks = si_z1e1imm04-werks
AND lgort = si_z1e1imm04-lgort
AND charg = si_z1e1imm04-lotva
AND sobkz = c_error "'E'
AND vbeln = aufk-kdauf
AND posnr = aufk-kdpos.
ENDIF.
CLEAR ti_batch_stock.
REFRESH ti_batch_stock.
*Batch and Sales Order Stock informations
IF NOT mchb IS INITIAL.
MOVE-CORRESPONDING mchb TO ti_batch_stock.
APPEND ti_batch_stock.
CLEAR ti_batch_stock.
ENDIF.
IF NOT mska IS INITIAL.
MOVE-CORRESPONDING mska TO ti_batch_stock.
APPEND ti_batch_stock.
CLEAR ti_batch_stock.
ENDIF.
CHECK NOT mchb IS INITIAL AND NOT mska IS INITIAL.
CASE si_z1e1imm04-insmk.
WHEN ' '.
*Valuated stock with unrestricted use
ti_batch_stock clabs kalab.
CASE ti_batch_stock-clabs.
*Sales Order Stock
WHEN 0.
check_ti_batch_stock kalab.
*Table des statuts d'IDOCS. Declaration de production.
SELECT SINGLE * FROM zidcs
WHERE docnum = si_edidc-docnum.
CHECK sy-subrc = 0
AND zidcs-statut <> c_02. "'02'
PERFORM foreign_lock USING si_edidc-docnum.
UPDATE zidcs SET statut = c_actvt_edit
WHERE docnum = si_edidc-docnum.
* IDOC WMMBXY - IDoc report goods movements in IM***********************
WHEN 'WMMBXY'.
CASE si_edid4-segnam.
*Segment Goods movements for mobile data entry (header data)
WHEN 'E1MBXYH'.
perform_segment e1mbxyh.
*Add goods movement from external system: Item
*And Goods movements(...)
WHEN 'E1MBXYI'.
CHECK NOT si_e1mbxyh IS INITIAL.
perform_segment e1mbxyi.
*Document Segment: Material
IF wa_docnum <> si_edidc-docnum.
CLEAR ti_mseg.
REFRESH ti_mseg.
SELECT * FROM mseg
INTO CORRESPONDING FIELDS OF TABLE ti_mseg
WHERE mjahr = si_e1mbxyh-bldat(4)
AND bwart = si_e1mbxyi-bwart
AND matnr = si_e1mbxyi-matnr
AND werks = si_e1mbxyi-werks
AND lgort = si_e1mbxyi-lgort
AND charg = si_e1mbxyi-charg
AND insmk = si_e1mbxyi-insmk
AND sobkz = si_e1mbxyi-sobkz
AND kdauf = si_e1mbxyi-kdauf
AND kdpos = si_e1mbxyi-kdpos
AND sgtxt = si_e1mbxyi-sgtxt
AND wempf = si_e1mbxyi-wempf
AND umlgo = si_e1mbxyi-umlgo.
IF sy-subrc = 0.
PERFORM delete_idoc USING si_edidc-docnum.
ELSE.
CLEAR wa_docnum.
wa_docnum = si_edidc-docnum.
ENDIF. " # 0
ENDIF. " # INITIAL
*error - no further processing
CHECK si_edidc-status <> c_status_in_idoc_processed."#68
*quantity in unit of entry nul
*and Error - no further processing
IF si_e1mbxyi-erfmg = c_zero. "0
* IDOC WMTORD - IDoc report goods movements in IM **********************
WHEN 'WMTORD'.
CASE si_edid4-segnam.
WHEN 'E1LTORH'.
*Transfer order header
perform_segment e1ltorh.
*Transfer Order Item
WHEN 'E1LTORI'.
perform_segment e1ltori.
CHECK NOT si_e1ltori IS INITIAL.
*Destination target quantity in stockkeeping unit
CASE si_e1ltori-nsolm.
WHEN c_zero. "VALUE 0
PERFORM delete_edid4 USING si_edid4-docnum
si_edid4-counter
si_edid4-segnum.
WHEN OTHERS.
*Transfer order item
CLEAR ti_ltap.
REFRESH ti_ltap.
SELECT * FROM ltap
INTO TABLE ti_ltap
WHERE lgnum = si_e1ltorh-lgnum
AND matnr = si_e1ltori-matnr
AND werks = si_e1ltori-werks
AND charg = si_e1ltori-charg
AND meins = si_e1ltori-meins
AND letyp = si_e1ltori-letyp
AND qname = si_e1ltorh-bname
AND zeugn = si_e1ltori-zeugn
AND vltyp = si_e1ltori-vltyp
AND vlpla = si_e1ltori-vlpla
AND nltyp = si_e1ltori-vlpla
AND nlpla = si_e1ltori-nlpla
AND nsolm = si_e1ltori-nsolm
AND lgort = si_e1ltori-lgort
AND pquit <> ' '.
IF sy-subrc = 0.
PERFORM delete_edid4 USING si_edid4-docnum
si_edid4-counter
si_edid4-segnum.
ENDIF.
ENDCASE.
*number of data records
CASE si_edidc-maxsegnum.
*Number of data records = Number of SAP segment
WHEN si_edid4-segnum.
CLEAR si_edid4-sdata.
MOVE si_e1edl24 TO si_edid4-sdata.
PERFORM update_edid4 USING si_edidc-docnum
si_edid4-sdata.
ENDIF.
*Delivery header
*and Reference data ordering party
WHEN 'E1EDL41'.
IF NOT si_e1edl20 IS INITIAL.
perform_segment e1edl41.
*Vendor Confirmations
*and Purchasing document type
*and Purchasing Document Item
CLEAR ti_lo_ekko.
REFRESH ti_lo_ekko.
SELECT * FROM ekko AS f
LEFT JOIN ekpo AS j
ON j~ebeln = f~ebeln
AND j~ebelp = si_e1edl41-posex
LEFT JOIN ekes AS p
ON p~ebeln = f~ebeln
AND p~ebelp = si_e1edl41-posex
LEFT JOIN z0imm01 AS z
ON z~ekorg = f~ekorg
AND z~bsart = f~bsart
INTO CORRESPONDING FIELDS OF TABLE ti_lo_ekko
WHERE f~ebeln = si_e1edl41-bstnr.
CHECK sy-subrc = 0.
*Purchasing Document Number
*Delivery
*Or Purchasing document type
*or "Delivery completed" indicator
LOOP AT ti_lo_ekko
WHERE xblnr = si_e1edl20-vbeln
AND ebeln = si_e1edl41-bstnr
OR bsart IS initial
OR elikz = c_x.
CHECK sy-subrc = 0.
EXIT.
ENDLOOP.
CHECK sy-subrc = 0.
PERFORM delete_idoc USING si_edidc-docnum.
ENDIF. " INITIAL
ENDCASE. " si_edid4-segnam
* IDOC Z1IWM071 - Suppression de Reservation ***************************
WHEN 'Z1IWM071'.
*Error: Application document not posted
CHECK si_edidc-status = c_status_in_application_error. "51
PERFORM delete_idoc USING si_edidc-docnum.
* IDOC SDPACK - Packing confirmation ***********************************
WHEN 'SDPACK'.
CASE si_edid4-segnam.
WHEN 'E1VPACD'.
perform_segment e1vpacd.
CLEAR i_vbuk.
CALL FUNCTION 'SD_VBUK_SELECT'
EXPORTING
i_document_number = si_e1vpacd-vbeln
IMPORTING
*Shipping Units Confirmation: Header
WHEN 'E1VPACH'.
*Overall packing status of all items
CASE i_vbuk-pkstk.
WHEN c_action_clear_and_refresh.
"C Completely processed
PERFORM delete_idoc USING si_edidc-docnum.
WHEN OTHERS.
perform_segment e1vpach.
conversion_exit_alpha_input si_e1vpach-exidv.
*Handling Units - Database Accesses
*Packaging Material Type
CLEAR ti_vekp.
REFRESH ti_vekp.
SELECT * FROM vekp AS a
INNER JOIN tvarv AS b
ON a~vhart = b~low
AND b~name = 'Z0IDOC01_VHART'
INTO CORRESPONDING FIELDS OF TABLE ti_vekp
WHERE exidv = si_e1vpach-exidv.
***Correction en cours
IF ti_lips[] IS INITIAL
OR ti_lips_idoc-vbeln NE ti_lips-vbeln.
CLEAR ti_lips.
REFRESH ti_lips.
SELECT * FROM lips
INTO TABLE ti_lips
WHERE vbeln = ti_lips_idoc-vbeln.
DELETE ti_lips_idoc WHERE vbeln NE ti_lips-vbeln.
ENDIF.
*Number of data records = Number of SAP segment
IF si_edidc-maxsegnum = si_edid4-segnum.
ENDIF.
ENDCASE. " si_edid4-segnam
****Rajout MRD le 31/01/2008
* IDOC WMTOCO - IDoc**********************
WHEN 'WMTOCO'.
CASE si_edid4-segnam.
WHEN 'E1LTCOH'.
*Transfer order header
perform_segment e1ltcoh.
*Transfer Order Item
WHEN 'E1LTCOI'.
perform_segment e1ltcoi.
CHECK NOT si_e1ltcoi IS INITIAL.
*Transfer order item
CLEAR ti_ltap.
REFRESH ti_ltap.
SELECT * FROM ltap
INTO TABLE ti_ltap
WHERE lgnum = si_e1ltcoh-lgnum
AND tanum = si_e1ltcoh-tanum
AND tapos = si_e1ltcoi-tapos
AND pquit <> ' '.
IF sy-subrc = 0.
PERFORM delete_edid4 USING si_edid4-docnum
si_edid4-counter
si_edid4-segnum.
ENDIF.
ENDCASE.
ENDCASE. " si_edidc-mestyp
ENDLOOP. " ti_edid4
ENDLOOP. " ti_edidc
PERFORM display_list TABLES ti_edidc.
ELSE.
MESSAGE s349(e0).
* Selection de donnees impossible
ENDIF. "No Control record (IDoc)
END-OF-SELECTION.
*---------------------------------------------------------------------*
* FORM DELETE_IDOC *
*---------------------------------------------------------------------*
* This routine sets the IDOC's status to 'ready for deletion' *
*---------------------------------------------------------------------*
FORM delete_idoc USING p_si_edidc-docnum.
PERFORM foreign_lock USING p_si_edidc-docnum.
*Update status record 68 for IDoc to delete IDOC
UPDATE edidc SET status = c_status_in_idoc_processed "68
WHERE docnum = p_si_edidc-docnum
AND status = c_status_in_application_error. "51
COMMIT WORK.
*Update status in ti_edidc
ti_edidc-status = c_status_in_idoc_processed.
MODIFY ti_edidc TRANSPORTING status WHERE docnum = si_edid4-docnum.
CLEAR ti_edidc.
ENDFORM. " delete_idoc
*&---------------------------------------------------------------------*
*& Form foreign_lock
*&---------------------------------------------------------------------*
* This routine lock and unlock entry for table EDIDC
*----------------------------------------------------------------------*
FORM foreign_lock USING p_si_edidc-docnum.
*&---------------------------------------------------------------------*
*& Form update_edid4
*&---------------------------------------------------------------------*
* This routine update the table EDID4 with new values of segment sdata
*----------------------------------------------------------------------*
FORM update_edid4 USING p_si_edidc-docnum
p_si_edid4-sdata.
PERFORM foreign_lock USING p_si_edidc-docnum.
*Update IDoc Data Records
UPDATE edid4 SET sdata = p_si_edid4-sdata
WHERE docnum = si_edid4-docnum AND
counter = si_edid4-counter AND
segnum = si_edid4-segnum.
COMMIT WORK.
ENDFORM. " update_edid4
*&---------------------------------------------------------------------*
*& Form field_e1vpaci
*&---------------------------------------------------------------------*
* This routine sets the new HU number
*----------------------------------------------------------------------*
FORM field_e1vpaci.
IF NOT si_e1vpaci-exidv IS INITIAL.
ASSIGN si_e1vpaci-exidv TO <hu>.
ELSE.
ASSIGN si_e1vpaci-exidv_ob TO <hu>.
ENDIF.
conversion_exit_alpha_input <hu>.
READ TABLE ti_exidv WITH KEY old = <hu>.
IF sy-subrc = 0.
CLEAR <hu>.
<hu> = ti_exidv-new.
CLEAR si_edid4-sdata.
MOVE si_e1vpaci TO si_edid4-sdata.
PERFORM update_edid4 USING si_edidc-docnum
si_edid4-sdata.
ENDIF. " # 0
ENDFORM. " field_e1vpaci
*&---------------------------------------------------------------------*
*& Form delete_edid4
*&---------------------------------------------------------------------*
* This routine delete the wrong segment
*----------------------------------------------------------------------*
FORM delete_edid4 USING p_si_edid4_docnum
p_si_edid4_counter
p_si_edid4_segnum.
PERFORM foreign_lock USING p_si_edid4_docnum.
*Delete IDoc Data Records
DELETE FROM edid4 WHERE docnum = p_si_edid4_docnum AND
counter = p_si_edid4_counter AND
segnum = p_si_edid4_segnum.
COMMIT WORK.
ENDFORM. " delete_edid4
*&---------------------------------------------------------------------*
*& Form display_list
*&---------------------------------------------------------------------*
* This routine display the report
*----------------------------------------------------------------------*
FORM display_list TABLES p_ti_edidc STRUCTURE edidc.
LOOP AT p_ti_edidc.
*Error: Application document not posted
IF p_ti_edidc-status = c_status_in_application_error. "51
*Short description of IDoc status values
*Control record (IDoc)
CLEAR ti_n_edidc.
REFRESH ti_n_edidc.
SELECT * FROM edidc AS a
INNER JOIN teds2 AS b
ON a~status = b~status
AND b~langua = sy-langu
INTO CORRESPONDING FIELDS OF TABLE ti_n_edidc
FOR ALL ENTRIES IN p_ti_edidc
WHERE a~docnum = p_ti_edidc-docnum.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.