Skip to Content
Technical Articles

How to add an user-defined segment to an IDoc

Description:

This post will show you how to create a new Segment and append it to a IDoc type as an extension.

 

Introduction:

When you create a new extension for an IDoc, transfer the data, then insert again into IDoc, it sometime might lead to Status Error 26 “Get details from previous status records with status 26”.

It is because of hierarchy error. In another word, you insert the record into wrong position.

This post will use a trick to avoid that problem.

 

Scenario:

You have to transfer some custom data via IDoc  ARBCIG_DELINS for Scheduling Agreement Delivery. You need to implement the below steps to achieve it:

  1. Create a new Zsegment
  2. Create extension for Idoc type
  3. Maintain Output Types and Assignment to IDoc Types in WE82
  4. Maintain Partner Profile in WE20
  5. Write the code in USER EXIT ZXM06U60 (for Scheduling Agreement)

 

  1. Create a new Z-Segment (Tcode WE31)

 

 

Then set it released by press F3, Go to Menu->Edit->Set Release

2. Create Extension for Basic Type ARBCIG_DELINS (Tcode WE30)

 

 

3. Maintain Output Types and Assignment to IDoc Types in WE82 (Tcode WE82)

4.Maintain Partner Profile in WE20  (Tcode WE20)

 

5.Write the code in USER EXIT ZXM06U60 (for Scheduling Agreement)

Because our ZSegment position is right under  E1EDP10 Segment, therefore we need to find   the exact index nowhere to insert the new segment. We use the following code:

 

  CALL FUNCTION 'IDOCTYPE_READ'
    EXPORTING
      PI_IDOCTYP         = 'ARBCIG_DELINS'
      PI_CHECK_AUTHORITY = ' '
    TABLES
      PT_SYNTAX          = LT_EDI_IAPI02
    EXCEPTIONS
      OBJECT_NOT_FOUND   = 1
      DB_ERROR           = 2
      NO_AUTHORITY       = 3
      OTHERS             = 4.
  IF SY-SUBRC <> 0.
    EXIT.
  ELSE.
    READ TABLE LT_EDI_IAPI02 INTO LS_EDI_IAPI02 WITH KEY SEGTYP = 'E1EDP10' .
    IF SY-SUBRC <> 0 .
      EXIT.
    ELSE.
      LV_NR = LS_EDI_IAPI02-NR .
    ENDIF.
  ENDIF.

** Identify the exact index no. where to insert the new segment.
  LOOP AT DINT_EDIDD ASSIGNING FIELD-SYMBOL(<LF_IDOCS>) .
    LW_INDEX = SY-TABIX.
    READ TABLE LT_EDI_IAPI02 INTO LS_EDI_IAPI02 WITH KEY SEGTYP = <LF_IDOCS>-SEGNAM.
    IF LS_EDI_IAPI02-NR > LV_NR AND LV_COMPL = SPACE.
      LV_COMPL = 'X' .
      EXIT.
    ENDIF.
  ENDLOOP.

 

Then we check the Zsegment is existing or not and Append or Insert corresponding.

 

    READ TABLE LT_EDIDD ASSIGNING FIELD-SYMBOL(<LF_TEST>)
                        WITH KEY SEGNAM = 'Z1EDP10'.

    IF SY-SUBRC = 0.
      <LF_TEST>-SDATA = LS_Z1EDP10.
    ELSE.
      MOVE <LF_E1EDP10_TM> TO LS_EDIDD.
      CLEAR LS_EDIDD-SDATA.

      LS_EDIDD-SEGNAM = 'Z1EDP10'.
      LS_EDIDD-SDATA = LS_Z1EDP10.
      LW_INDEX = LW_INDEX + 1.

      IF LV_COMPL = 'X' .
        INSERT LS_EDIDD INTO DINT_EDIDD INDEX LW_INDEX.
      ELSE.
        APPEND LS_EDIDD TO DINT_EDIDD.
      ENDIF.
    ENDIF.

 

Finally, the values of Zsegment will come through into IDoc.

 

Conclusion:

To avoid Hierarchy Error, you need to insert the segment to correct index.

If you have any question, please leave your comment. Thank you.

2 Comments
You must be Logged on to comment or reply to a post.
  • It’s nice of you to share but while doing that please make sure you are offering the readers accurate and more comprehensive information.

    Status 26 is a syntax error and the error message is telling us to look at the second status line where you’d find another, more explanatory, message. The part “transfer the data, then insert again into IDoc” I’m not able to understand at all, to be honest.

    It’s not a good idea to create extensions with the same name as the object you are extending. From the screenshots, it seems that an extension with a Z prefix already existed in your system. In that case you could’ve named yours Z…_1 or something. It’d still be a better choice.

    Even though transaction WE82 is, unfortunately, named “Output Types…” it’d be beneficial to explain that it is about assigning the extension to the IDoc and message type while “output” is just a bad terminology choice by SAP. (Title doesn’t even match the column headers, as we can see.)

    ZXM06U60 is not a user exit, it’s an include name. It’d be better to mention the user exit name (from SMOD transaction, I assume) where it’s located. Then the readers could find it easily in their system.

    What you are doing in this blog is not actually a “trick”, it’s how the extension needs to be done properly. When a new segment is created then it needs to be populated in the right sequence in a user exit. I’m not sure how and when exactly this particular user exit called but in most cases there is a user exit that loops through the segment internal table (which has EDIDD in the name) and then we can simply add a new segment as soon as the loop step reaches the parent/preceding standard segment.

    Also there is no need for a screenshot with the code if the code is already posted as text. The duplicate code looks very confusing to the readers.

    Last but not least, before posting a blog please make sure to check if the subject has already been written about on SCN. Maybe I’m missing something but the general steps for IDoc extension have already been covered many times. Google search for “how to add custom IDoc segments site:sap.com” finds 5k+ items. There is this Wiki post, this blog with similar steps, and many Q&A posts. Even regarding status 26 specifically there is an answered question (and a few more). There is also this very detailed document on the Oracle website, of all places.

    If you chose to write on a well-covered subject then at least try to offer more value to the readers. Add more explanation (e.g. what is the significance of “set release”?), links to additional materials, etc. See how Vivek did in the blog linked above.