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: 

Building Inbound IDoc

Former Member
0 Kudos

I am creating an inbound IDoc using ABAP. I have successfully created the IDoc, but I am getting errors, I believe because of the format of the Data Records in the IDoc. Here are the fields for the Data Records:

MANDT - using sy-mandt

DOCNUM

SEGNUM

SEGNAM - populating with segment name

PSGNUM

HLEVEL

DTINT2

SDATA - populating with data based on segment format

Can somebody either explain, or provide a link to instructions on how the other elements should be populated. I am getting a "flat" IDoc, and I think it's because I am not populating the hlevel, and possibly other elements, properly. I'm just not sure what to put in these elements to show the correct hierarchy of the IDoc.

9 REPLIES 9

Former Member
0 Kudos

DOCNUM - Leave Blank ( will be created by internally)

SEGNUM - Sequential Number of segment 01 - 02 ...

HLEVEL - Number of parent Segment .

Hope this should solve the issue . For example in MATAMS

E1MARAM SEGNUM - 01

HLEVEL - Space

E1MARCM SEGNUM - 02

HLEVEL - 04

Or just goto table EDID4 in SE16 and see the values for an existing IDOC .

Cheers.

rainer_hbenthal
Active Contributor
0 Kudos

Just have a look at table edid4 and use forward navigation with f1.

Former Member
0 Kudos

Denise,

here is an example of updating contract prices using an ABAP, hope this helps

DATA: I_IDOC_DATA LIKE EDIDD OCCURS 0 WITH HEADER LINE,

I_IDOC_COMM LIKE EDIDC,

*--- Fills receiver tables

CALL FUNCTION 'OWN_LOGICAL_SYSTEM_GET'

IMPORTING

OWN_LOGICAL_SYSTEM = WA_LOGSYS

EXCEPTIONS

OWN_LOGICAL_SYSTEM_NOT_DEFINED = 1

OTHERS = 2.

IF SY-SUBRC <> 0.

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

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

ENDIF.

*--- Create IDoc control-record

CLEAR I_IDOC_COMM.

I_IDOC_COMM-MESTYP = 'COND_A'.

I_IDOC_COMM-IDOCTP = 'COND_A01'.

I_IDOC_COMM-DIRECT = '2'.

I_IDOC_COMM-SERIAL = SY-DATUM.

I_IDOC_COMM-SERIAL+8 = SY-UZEIT.

I_IDOC_COMM-RCVPOR = SPACE.

I_IDOC_COMM-RCVPRT = 'LS'.

I_IDOC_COMM-RCVPRN = WA_LOGSYS.

I_IDOC_COMM-SNDPOR = P_SNDPOR.

I_IDOC_COMM-SNDPRT = 'LS'.

I_IDOC_COMM-SNDPRN = WA_LOGSYS.

LOOP AT I_COND_UPD INTO WA_COND_UPD.

REFRESH I_IDOC_DATA.

*--- Fill E1KOMG segment

CLEAR E1KOMG.

E1KOMG-KVEWE = 'A'.

E1KOMG-KOTABNR = WA_COND_UPD-KOTABNR.

E1KOMG-KAPPL = WA_COND_UPD-KAPPL.

E1KOMG-KSCHL = WA_COND_UPD-KSCHL.

IF WA_COND_UPD-KOTABNR = '017'.

MOVE: WA_COND_UPD-LIFNR TO E1KOMG-VAKEY+0(10).

MOVE: WA_COND_UPD-MATNR TO E1KOMG-VAKEY+10(18).

MOVE: WA_COND_UPD-EKORG TO E1KOMG-VAKEY+28(4).

MOVE: WA_COND_UPD-WERKS TO E1KOMG-VAKEY+32(4).

MOVE: WA_COND_UPD-ESOKZ TO E1KOMG-VAKEY+36(1).

IF E1KOMG-VAKEY+36(1) = SPACE.

MOVE '0' TO E1KOMG-VAKEY+36(1).

ENDIF.

ENDIF.

CLEAR I_IDOC_DATA.

MOVE 'E1KOMG' TO I_IDOC_DATA-SEGNAM.

MOVE E1KOMG TO I_IDOC_DATA-SDATA.

APPEND I_IDOC_DATA.

*--- Fill E1KONH segment

CLEAR E1KONH.

E1KONH-DATAB = WA_COND_UPD-DATAB.

E1KONH-DATBI = WA_COND_UPD-DATBI.

CLEAR I_IDOC_DATA.

MOVE 'E1KONH' TO I_IDOC_DATA-SEGNAM.

MOVE E1KONH TO I_IDOC_DATA-SDATA.

APPEND I_IDOC_DATA.

*--- Fill E1KONP segment

CLEAR E1KONP.

E1KONP-KSCHL = WA_COND_UPD-KSCHL.

E1KONP-STFKZ = WA_COND_UPD-STFKZ.

E1KONP-KZBZG = WA_COND_UPD-KZBZG.

E1KONP-KSTBM = WA_COND_UPD-KSTBM.

  • e1konp-konms = wa_cond_upd-konms.

PERFORM CONVERT_ISO_UNIT USING WA_COND_UPD-KONMS

CHANGING E1KONP-KONMS.

E1KONP-KSTBW = WA_COND_UPD-KSTBW.

E1KONP-KONWS = WA_COND_UPD-KONWS.

E1KONP-KRECH = WA_COND_UPD-KRECH.

E1KONP-KBETR = WA_COND_UPD-KBETR.

E1KONP-KONWA = WA_COND_UPD-KONWA.

E1KONP-KPEIN = WA_COND_UPD-KPEIN.

  • e1konp-kmein = wa_cond_upd-kmein.

PERFORM CONVERT_ISO_UNIT USING WA_COND_UPD-KMEIN

CHANGING E1KONP-KMEIN.

E1KONP-PRSCH = WA_COND_UPD-PRSCH.

E1KONP-KUMZA = WA_COND_UPD-KUMZA.

E1KONP-KUMNE = WA_COND_UPD-KUMNE.

  • e1konp-meins = wa_cond_upd-meins.

PERFORM CONVERT_ISO_UNIT USING WA_COND_UPD-MEINS

CHANGING E1KONP-MEINS.

E1KONP-KZNEP = WA_COND_UPD-KZNEP.

E1KONP-ZAEHK_IND = WA_COND_UPD-ZAEHK_IND.

CLEAR I_IDOC_DATA.

MOVE 'E1KONP' TO I_IDOC_DATA-SEGNAM.

MOVE E1KONP TO I_IDOC_DATA-SDATA.

APPEND I_IDOC_DATA.

ENDLOOP.

CALL FUNCTION 'IDOC_WRITE_AND_START_INBOUND'

EXPORTING

I_EDIDC = I_IDOC_COMM

DO_COMMIT = 'X'

IMPORTING

DOCNUM = WA_DOCNUM

  • ERROR_BEFORE_CALL_APPLICATION =

TABLES

I_EDIDD = I_IDOC_DATA

EXCEPTIONS

IDOC_NOT_SAVED = 1

OTHERS = 2

0 Kudos

I was able to assign the PSGNUM and HLEVEL, but I am still having problems. I'm not sure if this is because of some of the internal functions I am using here, or if I am still doing something wrong.

This is what I am doing:

1) Load data into internal table.

2) Make call to IDOC_INBOUND_WRITE_TO_DB, passing control record, internal table with data, etc.

3) From within IDOC_INBOUND_WRITE_TO_DB, at line 59, it does a perform data_records_wipe, which goes out and wipes out all of these fields I just populated:

*&---------------------------------------------------------------------*
*&      Form  DATA_RECORDS_WIPE
*&---------------------------------------------------------------------*
*       clear some fields of the idoc data records for ale
*----------------------------------------------------------------------*
FORM DATA_RECORDS_WIPE
                  TABLES
                      T_DATA_RECORDS_IN  STRUCTURE EDIDD.

  LOOP AT  T_DATA_RECORDS_IN.

    CLEAR: T_DATA_RECORDS_IN-MANDT,
           T_DATA_RECORDS_IN-DOCNUM,
           T_DATA_RECORDS_IN-SEGNUM,
           T_DATA_RECORDS_IN-PSGNUM,
           T_DATA_RECORDS_IN-HLEVEL.
    modify t_data_records_in.
  ENDLOOP.

ENDFORM.                               " DATA_RECORDS_WIPE

I think this is what is causing my problem, but I don't know why it is doing this. Is there a better function to call to store the IDoc and process it?

0 Kudos

What is the error that you are getting?

0 Kudos

IDoc: 0000000000570162 Status: Error during syntax check of IDoc (inbound)

EDI: Syntax error in IDoc (segment cannot be identified)

If you go into WE02, for example, segment E1EDKT2 should be a child of E1EDKT1, but it does not have that relationship. If I pull up other ORDERS IDocs that were successfully processed, these formats have a parent/child hierarchy, and you can expand them. I don't know if the two are related, but I'm trying to figure out why mine are not coming across that way.

0 Kudos

So you are using FM IDOC_INBOUND_WRITE_TO_DB which is normally used when you want your IDOCS to pass through ALE layer. Now you have your own program to create an IDOC and pass it to the application, why not directly use IDOC_INPUT_ORDERS.

Cheers.

0 Kudos

Is this a custom IDOC?

Former Member
0 Kudos

Denise,

I didn't have time to read the whole threads. One thing I know is that if there is any segment break the hierarchy definition, you will see a flat IDoc. This happened to me before. You can use WE60 to verify if the IDoc you built is comply with the idoc type definition.

Another tip is that when you are building a IDoc, You don't have to explicitly populate HLEVEL, PSGNUM stuff. Try just populate the segname and SDATA to see if SAP do the rest for you.

Good luck.

Eddy