Skip to Content
0

sorting items on basis of unique field

Jun 19, 2017 at 08:14 AM

90

avatar image
Former Member

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

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

6 Answers

Manoj K Jun 19, 2017 at 08:39 AM
1

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

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Jun 20, 2017 at 01:32 PM
0

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

Thanks,
Apu

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Jun 19, 2017 at 08:00 PM
0

Hi,

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

Thanks,

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Jun 20, 2017 at 02:18 PM
0

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

Share
10 |10000 characters needed characters left characters exceeded
Evgeniy Kolmakov Jun 19, 2017 at 09:02 AM
0

Hi Abhay!

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

Regards, Evgeniy.

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Jun 21, 2017 at 10:57 AM
0

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

Share
10 |10000 characters needed characters left characters exceeded