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: 

Sorting Idoc Segments

Former Member
0 Kudos

Hi experts,

I have a project where i need to sort the Idoc segments according to certain sorting algorithm.

Since i'm new to Idocs I need a sample ABAP code of how to sort segments in an Idoc.

Thanks.

1 ACCEPTED SOLUTION

kesavadas_thekkillath
Active Contributor
0 Kudos

Hi ,

You have to find a suitable exit or badi to do that.

SAmple code can be found in function SPCM_SORT_IDOC_STRUCTURE

8 REPLIES 8

Former Member
0 Kudos

Hi,

Not sure on what you mean by you need to sort IDOC segments, the segments within an IDOC are structured as per the structure defined in the corresponding IDOC type any re-ordering/restructuring will lead to a syntax error.

Please provide more information on the actual scenario.

Regards,

Chen

0 Kudos

Hi Chen,

I will describe for you the idea first. Now after the Idoc is created and sent to the certain destination, I need to catch it using an ABAP program, make some post processing changes to it, then send it again to the desired destination.

During the post processing of the Idoc i need to re-sort the segments based on the SSCC18 number inside the iDoc.

Therefore i need to look into segment E1EDP08 (if exists) and then sort the segments E1EDP07, E1EDP08 and E1EDP09

in the same sequence of the SSCC18 numbers that appear into E1EDP08.

Is that possible? if so then could you help me with some guidelines?

Thanks

kesavadas_thekkillath
Active Contributor
0 Kudos

Hi ,

You have to find a suitable exit or badi to do that.

SAmple code can be found in function SPCM_SORT_IDOC_STRUCTURE

0 Kudos

Hi,

@Keshav - Keshav the fm SPCM_SORT_IDOC_STRUCTURE will only help you build the EDIDD as per the IDOC Type along with the Extension data.

@truthseeker88 - I still have a few questions before i can answer your questions, i am presuming that you are looking at IDOC Type DESADV01, confirm if it is a different IDOC

Now after the Idoc is created and sent to the certain destination, I need to catch it using an ABAP program, make some post processing changes to it, then send it again to the desired destination.

Do you mean you will be(or you want to) sending two IDOCs to the target system, or do you want to change the sort order in the first IDOC itself?

During the post processing of the Idoc i need to re-sort the segments based on the SSCC18 number inside the iDoc.

Well, the fact is a given IDOC Type has a defined standard structure and cannot be changed. so in case of DESADV01 the structure is (considering only the segments you have posted) is as below, use WE30 to see the complete structure of the IDOC

E1EDP07 -


Parent Segment

E1EDP08 --- Child Segment

E1EDP09 --- Child Segment

Therefore i need to look into segment E1EDP08 (if exists) and then sort the segments E1EDP07, E1EDP08 and E1EDP09

in the same sequence of the SSCC18 numbers that appear into E1EDP08.

So, i am still not clear on what you mean by sort E1EDP07, E1EDP08 and E1EDP09 based on SSCC18 number that appears in E1EDP08.

Let us take an Example here, we have an IDOC which has two E1EDP07s in it, and each E1EDP07 has 1 E1EDP08 and E1EDP09, so the structure will be as below.

E1EDP07 -


Parent Segment 1

E1EDP08 --- Child Segment 1

E1EDP09 --- Child Segment 1

E1EDP07 -


Parent Segment 2

E1EDP08 --- Child Segment 2

E1EDP09 --- Child Segment 2

You can change the sort order so that E1EDP07-Parent Segment 2 comes above E1EDP07-Parent segment 1 because of SSCC18, this is possible

E1EDP07 -


Parent Segment 2

E1EDP08 --- Child Segment 2

E1EDP09 --- Child Segment 2

E1EDP07 -


Parent Segment 1

E1EDP08 --- Child Segment 1

E1EDP09 --- Child Segment 1

But if you are looking at changing the hierarchy/parent-child relation this is not possible,

E1EDP08 -


Child Segment 1

E1EDP09 --- Child Segment 1

E1EDP07 --- Parent Segment 1

E1EDP08 -


Child Segment 2

E1EDP09 --- Child Segment 2

E1EDP07 --- Parent Segment 2

Let me know if i am off track here

Regards,

Chen

0 Kudos

Hi Chen,

The Idoc basic type is Desadv01 & msg type is ASN, and I will send only 1 Idoc to the destination.

The exact requirement is:

we have

E1EDP07 --- Segment 7

E1EDP08 -


Segment 8 ULID (Field EXIDV) ending with 456

E1EDP09 --- Segment 9

E1EDP07 --- Segment 10

E1EDP08 -


Child Segment 11 ULID ending with 123

E1EDP09 --- Child Segment 12

After sorting it should be like this:

E1EDP07 --- Segment 10

E1EDP08 -


Child Segment 11 ULID (Field EXIDV) ending with 123

E1EDP09 --- Child Segment 12

E1EDP07 --- Segment 7

E1EDP08 -


Segment 8 ULID ending with 456

E1EDP09 --- Segment 9

Any ABAP guidelines on how to start?

Edited by: truthseeker88 on May 18, 2011 2:14 PM

0 Kudos

If I slightly rephrase your problem, your problem is filling item segment of IDOC based in SSCC18 number. So segment sequence remain as it is, as defined in IDOC structure but data appears sorted based on SSCC18 number in items.

This is how I would proceed, this is by no mean standard ABAP guideline.

Mostly, code which create outbound Idoc and fill data in it are bundled in function module, usually with name IDOC_OUTPUT_<message_type>.

1) Find the function module used in your case (I think its IDOC_OUTPUT_DESADV01 in your case).

2) Having found right function module, look for code where P07, P08 and P09 segements are filled.

3) Try and sort the data (internal table), used in function module to fill these segments. Probably user-exit will be there where you can put you code.

Regards,

Pawan.

0 Kudos

Hi,

To achieve your requirement, depending on whenther you are running on ECC 5.0 or ECC 6.0, you can choose one of the options below,

1) ECC 6.0 - In the FM "IDOC_OUTPUT_DESADV01" you can either implement the Implicit Enhancement option at the end of the function module, or you can implement the Enhancement Spot ENHANCEMENT-POINT IDOC_OUTPUT_DESADV01_G2 SPOTS ES_SAPLVED2.

2) Now if you are running on ECC 5.0 or less then you can implement the User exit USEREXIT_E1EDS02 in include LVED2FZZ.

Note: You will need an access key in the above case to implement the user exit.

The below piece of code has the logic to re-align/sort the segments based on E1EDP08, create a report program with the below code and pass an existing IDOC number as an input to understand the logic and them implement the same in the enhancement/user exit. All the best !!!


TYPES: BEGIN OF t_edp08,
         psgnum TYPE edi_psgnum,
         edp08  TYPE e1edp08,
       END OF t_edp08.

DATA: li_data      TYPE STANDARD TABLE OF edidd,
      lw_data      TYPE edidd,
      li_data_temp TYPE STANDARD TABLE OF edidd,
      li_edp08     TYPE STANDARD TABLE OF t_edp08,
      lw_edp08     TYPE t_edp08,
      lw_data_temp TYPE edidd,
      l_tabix      TYPE sytabix,
      l_segnum     TYPE idocdsgnum,
      l_psgnum     TYPE edi_psgnum.

CALL FUNCTION 'IDOC_READ_COMPLETELY'
  EXPORTING
    document_number         = '0000000000607773'
  TABLES
    int_edidd               = li_data
  EXCEPTIONS
    document_not_exist      = 1
    document_number_invalid = 2
    OTHERS                  = 3.
IF sy-subrc <> 0.
ENDIF.

LOOP AT li_data INTO lw_data WHERE segnam EQ 'E1EDP07'.
  l_tabix = sy-tabix.
  l_segnum = lw_data-segnum.
*  APPEND lw_data TO li_data_temp.

  LOOP AT li_data INTO lw_data FROM l_tabix.
    IF lw_data-segnam EQ 'E1EDS02'.
      EXIT.
    ENDIF.
    IF lw_data-segnam EQ 'E1EDP08'.
      lw_edp08-psgnum = lw_data-psgnum.
      lw_edp08-edp08 = lw_data-sdata.
      APPEND lw_edp08 TO li_edp08.
    ENDIF.
    APPEND lw_data TO li_data_temp.
  ENDLOOP.
  EXIT.
ENDLOOP.
DELETE li_data WHERE segnam EQ 'E1EDP07' OR
                     segnam EQ 'E1EDP08' OR
                     segnam EQ 'E1EDP09' OR
                     segnam EQ 'E1EDPT1' OR
                     segnam EQ 'E1EDPT2'.

SORT li_edp08 BY edp08-venum.

LOOP AT li_edp08 INTO lw_edp08.
  READ TABLE li_data_temp INTO lw_data_temp
    WITH KEY segnum = lw_edp08-psgnum.
  IF sy-subrc EQ 0.
    lw_data_temp-segnum = l_segnum.
    l_psgnum = l_segnum.
    l_segnum = l_segnum + 1.
    INSERT lw_data_temp INTO li_data INDEX l_tabix.
    l_tabix = l_tabix + 1.
    IF sy-subrc EQ 0.
    ENDIF.
    LOOP AT li_data_temp INTO lw_data_temp
      WHERE psgnum EQ lw_edp08-psgnum.
    lw_data_temp-segnum = l_segnum.
    lw_data_temp-psgnum = l_psgnum.
    l_segnum = l_segnum + 1.
      INSERT lw_data_temp INTO li_data INDEX l_tabix.
      l_tabix = l_tabix + 1.
      IF sy-subrc EQ 0.
      ENDIF.
    ENDLOOP.
  ENDIF.
ENDLOOP.
IF sy-subrc EQ 0.
ENDIF.

Regards,

Chen

0 Kudos

Hi Chen,

This really helped me..Thanks a lot!