Skip to Content
0
Former Member
Mar 27, 2006 at 08:30 AM

inbound IDOC processing, error duplicate key

1052 Views

We want to retrieve certain order-idocs in our system, before they are processed, to change AND insert segment data.

Flow we use in our current program

- DOC_STATUS_WRITE_TO_DATABASE

to change the status of the idoc (ok) (status 69)

- EDI_DOCUMENT_OPEN_FOR_EDIT (ok)

- EDI_CHANGE_DATA_SEGMENTS (ok)

- EDI_DOCUMENT_CLOSE_EDIT => not ok

This program gives SAPSQL error

Via debugging, we see that a new idoc number is

called (save as backup idoc ?), but we want the

current IDOC to be processed.

The system wants to insert in EDID4 => dump :

"Use an ABAP/4 Open SQL array insert only if you

are sure that none of the records passed already

exists in the database."

( I prefer to use these standard functions, in stead of just deleting and inserting into "EDID4" )

regards,

answers will be rewarded.

code extract

INCLUDE ZBE01458_TOP.

INITIALIZATION.

V_EDIT_STATUS = '69'.

V_PROCESSED_STATUS = '32'.

start-of-selection.

clear t_edidc. refresh t_edidc.

SELECT * FROM EDIDC into table t_edidc

WHERE DOCNUM in S_docnum

and mestyp in S_mestyp

and idoctp in S_idoctp

and credat in S_credat

and rcvpor in S_rcvpor

and rcvprt in S_rcvprt

and rcvprn in S_rcvprn

and sndpor in S_sndpor

and sndprt in S_sndprt

and sndprn in S_sndprn

and status in S_status.

loop at t_edidc.

move t_edidc-docnum to v_docnum.

refresh v_status.

V_STATUS-docnum = V_DOCNUM.

V_STATUS-status = V_EDIT_STATUS.

clear EDIDS.

select single * from EDIDS where docnum = v_docnum.

if sy-subrc = 0.

  • MOVE EDIDS-STACOD to V_STATUS-STACOD.

endif .

APPEND V_STATUS.

PERFORM CHANGE_IDOC_STATUS tables V_STATUS USING V_DOCNUM.

****

changing part for DEDIDD "idoc data

****

PERFORM OPEN_IDOC_FOR_CHANGE.

PERFORM CHANGE_IDOC.

PERFORM CLOSE_IDOC_FOR_CHANGE.

refresh v_status.

V_STATUS-docnum = V_DOCNUM.

V_STATUS-status = V_PROCESSED_STATUS.

APPEND V_STATUS.

PERFORM CHANGE_IDOC_STATUS tables V_STATUS

USING V_DOCNUM.

endloop.

&----


*& Form OPEN_IDOC_FOR_CHANGE

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM OPEN_IDOC_FOR_CHANGE.

CALL FUNCTION 'EDI_DOCUMENT_OPEN_FOR_EDIT'

EXPORTING

DOCUMENT_NUMBER = V_DOCNUM

  • ALREADY_OPEN = 'N'

  • IMPORTING

  • IDOC_CONTROL =

TABLES

IDOC_DATA = DEDIDD

EXCEPTIONS

DOCUMENT_FOREIGN_LOCK = 1

DOCUMENT_NOT_EXIST = 2

DOCUMENT_NOT_OPEN = 3

STATUS_IS_UNABLE_FOR_CHANGING = 4

OTHERS = 5

.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDFORM. " OPEN_IDOC_FOR_CHANGE

&----


*& Form CHANGE_IDOC

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM CHANGE_IDOC.

CALL FUNCTION 'EDI_CHANGE_DATA_SEGMENTS'

TABLES

IDOC_CHANGED_DATA_RANGE = DEDIDD

EXCEPTIONS

IDOC_NOT_OPEN = 1

DATA_RECORD_NOT_EXIST = 2

OTHERS = 3.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDFORM. " CHANGE_IDOC

&----


*& Form CLOSE_IDOC_FOR_CHANGE

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM CLOSE_IDOC_FOR_CHANGE.

CLEAR t_EDI_DS40.

t_edi_ds40-docnum = v_docnum.

t_edi_ds40-status = '51'.

t_edi_ds40-repid = sy-repid.

t_edi_ds40-tabnam = 'EDI_DS'.

t_edi_ds40-mandt = sy-mandt.

t_edi_ds40-stamqu = 'SAP'.

t_edi_ds40-stamid = 'B1'.

t_edi_ds40-stamno = '999'.

t_edi_ds40-stapa1 = 'Changes made to idoc ...'.

  • t_edi_ds40-stapa2 = t_new_kunnr.

t_edi_ds40-logdat = sy-datum.

t_edi_ds40-logtim = sy-uzeit.

APPEND t_edi_ds40.

CALL FUNCTION 'EDI_DOCUMENT_CLOSE_EDIT'

EXPORTING

DOCUMENT_NUMBER = V_DOCNUM

DO_COMMIT = 'X'

DO_UPDATE = 'X'

WRITE_ALL_STATUS = 'X'

TABLES

STATUS_RECORDS = t_EDI_DS40

EXCEPTIONS

IDOC_NOT_OPEN = 1

DB_ERROR = 2

OTHERS = 3

.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDFORM. " CLOSE_IDOC_FOR_CHANGE

&----


*& Form CHANGE_IDOC_STATUS

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM CHANGE_IDOC_STATUS tables P_IDOC_STATUS structure V_IDOC_STATUS

USING P_DOCNUM.

CALL FUNCTION 'IDOC_STATUS_WRITE_TO_DATABASE'

EXPORTING

IDOC_NUMBER = p_docnum

  • IDOC_OPENED_FLAG = ' '

  • NO_DEQUEUE_FLAG = 'X'

  • IMPORTING

  • IDOC_CONTROL =

TABLES

IDOC_STATUS = P_IDOC_STATUS

  • EXCEPTIONS

  • IDOC_FOREIGN_LOCK = 1

  • IDOC_NOT_FOUND = 2

  • IDOC_STATUS_RECORDS_EMPTY = 3

  • IDOC_STATUS_INVALID = 4

  • DB_ERROR = 5

  • OTHERS = 6

.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

else.

commit work.

ENDIF.

ENDFORM. " CHANGE_IDOC_STATUS