B2B Integration

 View Only

 Sort and Split a CSV file based on column and decreasing tracking

Phanee Mullapudi's profile image
Phanee Mullapudi posted Sun October 05, 2025 10:11 AM

Hi,

I already referred the 'Split logic based on Control-break' thread, but it does not suit my requirement. So, I posting here. I need to implement below requirement using ITX map.

Source CSV must be sorted by Column A (OrderNum), OrderNum should not be repeated on multiple files on Output XML.

Output should not receive more than 99 lines, mapping should create multiple XML files based no. of rows received in source CSV.

If CSV has 99 lines or less, = 1 output file

If CSV has >99 lines, create multiple files with 99 lines each on output.

Split logic:

Count lines to 99, if line 99 OrderNum in Column A = line 100 OrderNum in Column A, find last unique OrderNum and split the file else split at 99.

Repeat logic - Count next 99 lines, if line 99 OrderNum in Column A = line 100 OrderNum in Column A, find last unique OrderNum and split the file else split at 99.

Repeat as required based on total row count in CSV.

navyakanth surugu's profile image
navyakanth surugu IBM Champion

Hello Phanee,

Could you see if this works for you?

The split can be designed using a hybrid record-count and control-break approach, enforce a 99-row limit per file, but align the split boundary to the last unique OrderNum so that transactional integrity is preserved across output XMLs.

Detailed Resolution:

We can solve this by using a row counter along with a check on the OrderNum:

  1. Count rows up to 99.
  2. When you hit row 99, look at the next row:
    • If it has the same OrderNum, then go back to the last row where the OrderNum changed and split there.
    • If it’s different, just split at 99.
  3. Create a new XML file each time you split and keep repeating this until the CSV is done.
  4. This way:
    • No file will go over 99 rows.
    • An OrderNum will always stay together in one file.
    • The number of files depends on how many rows and orders are in the input.