Skip to Content
avatar image
Former Member

sorting items on basis of unique field

Hi ,

I am trying to sort the item based on field in item structure here is below

structure

Input

<F10F><RECORD_TYPE>F10F</RECORD_TYPE>
<INVOICE_NUMBER>7000008</INVOICE_NUMBER>
<F10F><RECORD_TYPE>F10F</RECORD_TYPE>

<F10F><RECORD_TYPE>F10F</RECORD_TYPE>
<INVOICE_NUMBER>7000009</INVOICE_NUMBER>
<F10F><RECORD_TYPE>F10F</RECORD_TYPE>

<F20F_F49F>
<RECORD_TYPE>F20F</RECORD_TYPE>
<INVOICE_NUMBER>7000008</INVOICE_NUMBER>

<F20F_F49F>
<RECORD_TYPE>F20F</RECORD_TYPE>
<INVOICE_NUMBER>7000009</INVOICE_NUMBER>
</F20F_F49F>

I am trying get the sort items based on basis invoice field as belown

<F10F><RECORD_TYPE>F10F</RECORD_TYPE>
<INVOICE_NUMBER>7000008</INVOICE_NUMBER>
<F10F><RECORD_TYPE>F10F</RECORD_TYPE>

<F20F_F49F>
<RECORD_TYPE>F20F</RECORD_TYPE>
<INVOICE_NUMBER>7000008</INVOICE_NUMBER>

<F10F><RECORD_TYPE>F10F</RECORD_TYPE>
<INVOICE_NUMBER>7000009</INVOICE_NUMBER>
<F10F><RECORD_TYPE>F10F</RECORD_TYPE>

<F20F_F49F>
<RECORD_TYPE>F20F</RECORD_TYPE>
<INVOICE_NUMBER>7000009</INVOICE_NUMBER>
</F20F_F49F>

Regards

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

6 Answers

  • Jun 19, 2017 at 08:39 AM

    Abhay,

    Your logic would be something like this in below thread or you may use XSLT too.

    https://answers.sap.com/questions/220687/split-records-based-on-field-change-mapping-udf-or.html?childToView=221357#answer-221357

    Br,

    Manoj

    Add comment
    10|10000 characters needed characters exceeded

  • Jun 20, 2017 at 01:32 PM

    Basically, you want to group the data. Use format by example to do this.

    Thanks,
    Apu

    Add comment
    10|10000 characters needed characters exceeded

  • Jun 19, 2017 at 08:00 PM

    Hi,

    Can u try Sort for <INVOICE_NUMBER> and sort by key for rest all fields, it should give required results.

    Thanks,

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jun 20, 2017 at 02:18 PM

    Hi

    Issue is with the structure:

    Yours structure is :

    RECORD_TYPE 0..*
    INVOICE_NUMBER 0..*

    F10F 0..*

    make this as

    Details 0..*

    RECORD_TYPE 0..1

    INVOICE_NUMBER 0..1

    F10F 0..1

    Details will be mapped to occurrence of invoice number and you can sort it easily for yours file to be created in certain format

    Add comment
    10|10000 characters needed characters exceeded

  • Jun 19, 2017 at 09:02 AM

    Hi Abhay!

    Another option is to use XST transformation with "xsl:sort" element.

    Regards, Evgeniy.

    Add comment
    10|10000 characters needed characters exceeded

  • Jun 21, 2017 at 10:57 AM

    Hi,

    Use "sort" Node function to short INVOICE_NUMBER. Note: remove contexts of it so that all INVOICE_NUMBER are in under one Parent node and after sorting use "splitByValue-Each Value" to add element under different context.
    After that use "shortByKey" function with INVOICE_NUMBER as key, to add all same level elements within same sorted context. For this also, you need to do same as above step.

    Try it. If you have any problem, reply me.

    Regards,

    Anoop Kumar Rai

    Add comment
    10|10000 characters needed characters exceeded