cancel
Showing results for 
Search instead for 
Did you mean: 

Sorting and splitting of line items

Former Member
0 Kudos

hi

I need help for the following scenario :

PI will be receivng text files where the number of line items will be of the order say 2800 line items per file.

Each file is a document posting(IDOC) , but the condition is that in SAP FI the number of records that can be posted are only 999 , so the fix is that after every 998 records read by SAP PI a dummy record is to be inserted and an IDOC is posted and for the next IDOC(next 998 records) the first line item is again a dummy record which is the reversal of the last line item inserted to balance the credit and debits.

a) How can PI read the file in such a way that the first 998 line items can be posted as one idoc and the remaining line items in the next idoc etc

b)Also the file to be read, has to be first sorted on date ,ie each line item with the same date field have to be clubbed and then the 998 split has to be applied.

Kindly help in suggesting the approach , if it requires a UDF ,,can some body please provide the code for the same ?

thanks

Rohan

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Rohan,

I think you will need to use multimapping:

source -> temp (sort by date)

temp -> target (split)

You can use similar code to split the line items:

for(int j = 0; j< a.length; j++)

{

counter = counter + 1;

counter1 = counter1+ 1;

result.addValue(a[j]);

if (counter == 998)

{ if (a.length - counter1==0)

{ counter = 0; }

else

{ result.addContextChange();

counter = 0;

}

}

}

Hope this helps..let us know if you come up with a better method!!

Regards,

Lasya

Former Member
0 Kudos

Has this never been done before

a) sorting the records of the incoming file on the basis of a field for eg. ascending date ?

b) splitting the file on the numer of records ie 999 records for one idoc and the next 999 for the second and so on ?

Can anyone please suggest something ?+

Thanks

Rohan

Edited by: RohanS on Jun 29, 2009 4:37 PM

Former Member
0 Kudos

I had a similar scenario at a customer, finally had to revert to mapping class.

On the face of it, a UDF or a class mapping will work.

However, as the requirements get more elaborate, only viable (& technically reusable option) is to use mapping in a class (either an ABAP class or a Java class) will work.

If volume of data is a consideration and some data elements need verification (company code, GL accounts etc), then you may lean towards an ABAP class.

Let me know if you need more help.

Anupam

Former Member
0 Kudos

Thanks Anupam

But can this be done using Java mapping ?

is there no other alternative ??

Do you have any ABAP mapping code or Java Mapping code you can help me out with ??

Thanks

Rohan

Former Member
0 Kudos

Hi RohanS,

I think that one possible solution is use multimapping. You can generate more than one IDOC document from one input message.

Pls, see the following reference:

[Multimapping without BPM|https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/3115] [original link is broken] [original link is broken] [original link is broken];

I hope It helps you.

Ivan

prateek
Active Contributor
0 Kudos

This java mapping discusses the same problem

/people/daniel.graversen/blog/2009/07/03/sap-pi-xml-mappings-using-groovy

Regards,

Prateek

Former Member
0 Kudos

Hi,

For Sorting you can try SortByKey function which sorts the Second Queue Based on the first Queue Values..

Hope this might be useful

Note that The context should be same for the Both the Input Values to pass to the Function.

Regards,

Sainath