Skip to Content
avatar image
Former Member

Sorting of segments in IDOC

Hi Abap experts.

I need to sort/arrange  the data as shown in the screen shot given below.

row 5, 6,7 should come at top as row 1,2and 3 and 1,2,3,4 should come below it as row 4,5,6,7.

Any help with code sample or example ? The basic type is DELVRY03.

Thanks for your help.


idoc_sort.JPG (103.0 kB)
idoc_sort.JPG (103.0 kB)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    Nov 02, 2015 at 06:22 PM

    Ravi,

    You need to determine the beginning and end of each group of Handling Unit segments, then sort the groups in the new order, and write the parts of the iDoc to a new internal table.

    Try this:

    TYPES:

      BEGIN OF item_list_type,

        sort  TYPE c,

        start TYPE sytabix,

        end   TYPE sytabix,

      END OF item_list_type.

    DATA: t_items TYPE STANDARD TABLE OF item_list_type WITH HEADER LINE.

    DATA: li_new  TYPE STANDARD TABLE OF edidd.

    DATA: x_idx   TYPE i.

    DATA: x_pre   TYPE i. "precede Handling Unit data

    DATA: x_post  TYPE i. "follow Handling Unit data

    FIELD-SYMBOLS: <d> TYPE edidd.

      LOOP AT li_data_temp ASSIGNING <d>.

        x_idx = sy-tabix.

        CASE <d>-segnam.

          WHEN 'E1EDL37'.

            IF x_pre IS INITIAL.

              x_pre = x_idx - 1.

            ENDIF.

            IF t_items IS NOT INITIAL.

    *         Mark end of previous Handling Unit group

              t_items-end = x_idx - 1.

              APPEND: t_items.

              CLEAR: t_items.

            ENDIF.

    *       Mark beginning of this Handling Unit group

            t_items-start = x_idx.

          WHEN 'E1EDL54'.

          IF x_post IS INITIAL.

            x_post = x_idx.

          ENDIF.

    *     Mark end of last Handling Unit group

          t_items-end = x_idx - 1.

          APPEND: t_items.

        ENDCASE.

      ENDLOOP.

      IF t_items-end IS INITIAL.

    *   Finish last Handling Unit group, if document did not have a E1EDL54 segment

        DESCRIBE TABLE t_data LINES: t_items-end, x_post.

        APPEND: t_items.

      ENDIF.


    APPEND LINES OF li_data_temp FROM 1 TO x_pre TO li_new.

    SORT: t_items.

    LOOP AT t_items.

      APPEND LINES OF li_data_temp FROM t_items-start TO t_items-end TO li_new.

    ENDLOOP.

    APPEND LINES OF li_data_temp FROM x_post TO li_new.

    The internal table li_new[] is now ordered as you desired. This approach will allow you to reorder the Handling Unit groups, each beginning with a E1EDL37 segment, according to the sort fields you define.

    Add comment
    10|10000 characters needed characters exceeded