Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

inbound IDOC processing, error duplicate key

Former Member
0 Kudos

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

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Sven,

I am unclear as to whether you are trying to insert data to the database or trying to change certain segment data (of your Inbound IDOC) before it gets posted to the database. ( using EDI_CHANGE_DATA_SEGMENTS )

Can you please confirm that ?

Regards,

Urmila

9 REPLIES 9

Former Member
0 Kudos

Hi Sven,

I am unclear as to whether you are trying to insert data to the database or trying to change certain segment data (of your Inbound IDOC) before it gets posted to the database. ( using EDI_CHANGE_DATA_SEGMENTS )

Can you please confirm that ?

Regards,

Urmila

0 Kudos

Urmila,

THX for the already quick response

We receive the IDOC from an external system,

and before processing the IDOC we want to change the segments (inserting plus modifying)

we will then call the program to actually process the IDOC.

Regards ,

Sven

Former Member
0 Kudos

Hi Sven,

This is just a hunch, but I think it is worth a try.

Before appending the record to V_STATUS;

Can you enter V_STATUS-STACOD = 'SAPE0183' or 'SAPE0184'.

Can you please check and let me know if this works ?

Also at the start of function module "EDI_DOCUMENT_CLOSE_EDIT" can you put a break-point and check what the value of the field

DOCUMENT_IN_EDIT-ORIGINAL is ? This value should probably not be 0.

Thanks,

Urmila

0 Kudos

Hi Urmila,

Thx again for the response,

I also found in debug that these are the parameters that SAP sets to indicate an original document or not; this is in the function : "EDI_DOCUMENT_OPEN_FOR_EDIT"

and then when closing and updating in the function "EDI_DOCUMENT_CLOSE_EDIT" he checks on these parameters.

(actually it seems SAP wants tomake a copy ... )

<i>IF DOCUMENT_IN_EDIT-ORIGINAL EQ 0.

" noch keine Kopie vorhanden</i>

SO I already tried to manipulate these settings (its already in my code):

(like you also suggested)

<i> clear EDIDS.

select single * from EDIDS where docnum = v_docnum.

if sy-subrc = 0.

  • MOVE EDIDS-STACOD to V_STATUS-STACOD.

endif .</i>

I thought it was a field I could provide in the STATUS-structure (in the function 'IDOC_STATUS_WRITE_TO_DATABASE')but it isn't.

SO do you know where I can provide the "STACOD" field ?

when I check "DOCUMENT_IN_EDIT-ORIGINAL" it's '0'

in the function "EDI_DOCUMENT_CLOSE_EDIT". this could indeed be THE parameter to manipulate.

Hope to hear from you soon,

points will of course be rewarded.

greets,

Sven

Former Member
0 Kudos

Hi Sven,

What I am about to propose is a little complex, but seems to be the only possible solution.

Use the following Function Modules in sequence:

1. EDI_DOCUMENT_OPEN_FOR_PROCESS

2. EDI_DOCUMENT_STATUS_SET

3. EDI_DOCUMENT_CLOSE_PROCESS

Let me know if this works....

Regards,

Urmila

0 Kudos

Urmila,

I use the function in the following order :

- EDI_DOCUMENT_OPEN_FOR_EDIT

(I kept it to get the EDIDD internal table with the

sdata for the IDOC in an easy way)

- EDI_DOCUMENT_OPEN_FOR_PROCESS

- EDI_DOCUMENT_STATUS_SET (status 51 edit mode)

- EDI_CHANGE_DATA_SEGMENTS

(if I don't keep this function, where can you change

the EDIDD data table)

- EDI_DOCUMENT_STATUS_SET (status 32 processed mode)

- EDI_DOCUMENT_CLOSE_PROCESS

It doesnt give any errors, but it also doesn't change the idoc...

Do you still have suggestions ?

what do you think about

delete from EDID4 and insert into EDID4 ?

Hope to here from you.

Here is the code extract :

INCLUDE ZBE01458_TOP.

INITIALIZATION.

V_EDIT_STATUS = '69'.

V_PROCESSED_STATUS = '32'.

V_SAPCODE = 'SAPE0184'.

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.

move-corresponding T_EDIDC to WA_EDIDC.

PERFORM OPEN_IDOC_FOR_CHANGE.

refresh v_status.

V_STATUS-docnum = V_DOCNUM.

V_STATUS-status = V_EDIT_STATUS.

  • V_STATUS-STACOD = V_SAPCODE.

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.

V_STA-docnum = v_docnum.

V_STA-status = '51'.

V_STA-repid = sy-repid.

V_STA-tabnam = 'EDI_DS'.

V_STA-mandt = sy-mandt.

V_STA-stamqu = 'SAP'.

V_STA-stamid = 'B1'.

V_STA-stamno = '999'.

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

  • t_edi_ds40-stapa2 = t_new_kunnr.

V_STA-logdat = sy-datum.

V_STA-logtim = sy-uzeit.

V_STA-STACOD = V_SAPCODE.

PERFORM CHANGE_IDOC_STATUS

  • tables V_STATUS

USING V_STA

V_DOCNUM.

...

*************

changing EDIDD

**************

...

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.

V_STA-docnum = v_docnum.

V_STA-status = '32'.

V_STA-repid = sy-repid.

V_STA-tabnam = 'EDI_DS'.

V_STA-mandt = sy-mandt.

V_STA-stamqu = 'SAP'.

V_STA-stamid = 'B1'.

V_STA-stamno = '999'.

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

  • t_edi_ds40-stapa2 = t_new_kunnr.

V_STA-logdat = sy-datum.

V_STA-logtim = sy-uzeit.

V_STA-STACOD = V_SAPCODE.

  • PERFORM CHANGE_IDOC_STATUS

  • tables V_STATUS

  • USING V_STA

  • 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 = WA_EDIDC

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.

CALL FUNCTION 'EDI_DOCUMENT_OPEN_FOR_PROCESS'

EXPORTING

  • DB_READ_OPTION = DB_READ

DOCUMENT_NUMBER = V_DOCNUM

  • ENQUEUE_OPTION = SYNCHRONOUS

IMPORTING

IDOC_CONTROL = WA_EDIDC

  • EXCEPTIONS

  • DOCUMENT_FOREIGN_LOCK = 1

  • DOCUMENT_NOT_EXIST = 2

  • DOCUMENT_NUMBER_INVALID = 3

  • DOCUMENT_IS_ALREADY_OPEN = 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_PROCESS'

EXPORTING

DOCUMENT_NUMBER = V_DOCNUM

  • BACKGROUND = NO_BACKGROUND

  • NO_DEQUEUE = ' '

IMPORTING

IDOC_CONTROL = WA_EDIDC

  • EXCEPTIONS

  • DOCUMENT_NOT_OPEN = 1

  • FAILURE_IN_DB_WRITE = 2

  • PARAMETER_ERROR = 3

  • STATUS_SET_MISSING = 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.

  • 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_STA

P_DOCNUM.

CALL FUNCTION 'EDI_DOCUMENT_STATUS_SET'

EXPORTING

DOCUMENT_NUMBER = P_DOCNUM

IDOC_STATUS = P_STA

IMPORTING

IDOC_CONTROL = WA_EDIDC

  • EXCEPTIONS

  • DOCUMENT_NUMBER_INVALID = 1

  • OTHER_FIELDS_INVALID = 2

  • STATUS_INVALID = 3

  • OTHERS = 4

.

IF SY-SUBRC <> 0.

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

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

ENDIF.

*

  • 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

Former Member
0 Kudos

Actually Sven, The sequence I was thinking of is more like this ( though I haven't worked out whether you have all the necessary data for each FM interface )

- EDI_DOCUMENT_OPEN_FOR_PROCESS

- EDI_DOCUMENT_STATUS_SET

- EDI_DOCUMENT_CLOSE_PROCESS

- EDI_DOCUMENT_OPEN_FOR_EDIT

- EDI_CHANGE_DATA_SEGMENTS

- EDI_DOCUMENT_CLOSE_EDIT

Also the second point, I think you should update the IDOC Status in step 2 with '69' and not '51'.

I really hope this works ...

0 Kudos

Urmila,

I tried this sequence : code extract follows...

I got the duplicate key errors again.

what about delete first and then insert again in EDID4 table ?

source code extract:

INCLUDE ZBE01458_TOP.

INITIALIZATION.

V_EDIT_STATUS = '69'.

V_PROCESSED_STATUS = '32'.

V_SAPCODE = 'SAPE0184'.

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.

move-corresponding T_EDIDC to WA_EDIDC.

V_STA-docnum = v_docnum.

V_STA-status = '51'.

V_STA-repid = sy-repid.

V_STA-tabnam = 'EDI_DS'.

V_STA-mandt = sy-mandt.

V_STA-stamqu = 'SAP'.

V_STA-stamid = 'B1'.

V_STA-stamno = '999'.

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

  • t_edi_ds40-stapa2 = t_new_kunnr.

V_STA-logdat = sy-datum.

V_STA-logtim = sy-uzeit.

V_STA-STACOD = V_SAPCODE.

PERFORM OPEN_FOR_PROCESS.

PERFORM SET_IDOC_STATUS USING V_DOCNUM V_STA.

PERFORM CLOSE_IDOC_FOR_PROCESS.

PERFORM OPEN_IDOC_FOR_CHANGE.

PERFORM PROCESS_IDOC_STRUCTURE.

PERFORM CHANGE_IDOC.

PERFORM CLOSE_IDOC_FOR_CHANGE.

  • refresh v_status.

  • V_STATUS-docnum = V_DOCNUM.

  • V_STATUS-status = V_EDIT_STATUS.

    • V_STATUS-STACOD = V_SAPCODE.

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

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 = WA_EDIDC

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 = '69'.

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

&----


*& Form OPEN_FOR_PROCESS

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM OPEN_FOR_PROCESS.

CALL FUNCTION 'EDI_DOCUMENT_OPEN_FOR_PROCESS'

EXPORTING

  • DB_READ_OPTION = DB_READ

DOCUMENT_NUMBER = V_DOCNUM

  • ENQUEUE_OPTION = SYNCHRONOUS

IMPORTING

IDOC_CONTROL = WA_EDIDC

  • EXCEPTIONS

  • DOCUMENT_FOREIGN_LOCK = 1

  • DOCUMENT_NOT_EXIST = 2

  • DOCUMENT_NUMBER_INVALID = 3

  • DOCUMENT_IS_ALREADY_OPEN = 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_FOR_PROCESS

&----


*& Form SET_IDOC_STATUS

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM SET_IDOC_STATUS USING P_DOCNUM P_STA.

CALL FUNCTION 'EDI_DOCUMENT_STATUS_SET'

EXPORTING

DOCUMENT_NUMBER = P_DOCNUM

IDOC_STATUS = P_STA

IMPORTING

IDOC_CONTROL = WA_EDIDC

  • EXCEPTIONS

  • DOCUMENT_NUMBER_INVALID = 1

  • OTHER_FIELDS_INVALID = 2

  • STATUS_INVALID = 3

  • OTHERS = 4

.

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. " SET_IDOC_STATUS

&----


*& Form CLOSE_IDOC_FOR_PROCESS

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM CLOSE_IDOC_FOR_PROCESS.

CALL FUNCTION 'EDI_DOCUMENT_CLOSE_PROCESS'

EXPORTING

DOCUMENT_NUMBER = V_DOCNUM

  • BACKGROUND = NO_BACKGROUND

  • NO_DEQUEUE = ' '

IMPORTING

IDOC_CONTROL = WA_EDIDC

  • EXCEPTIONS

  • DOCUMENT_NOT_OPEN = 1

  • FAILURE_IN_DB_WRITE = 2

  • PARAMETER_ERROR = 3

  • STATUS_SET_MISSING = 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. " CLOSE_IDOC_FOR_PROCESS

Former Member
0 Kudos

Hi Sven,

Thanks for the points....let me know what final solution you come up with ....:-)