muleschemadataweaveanypoint-studioflat-file

FlatFile schema creation "out of order segment" error in mule 4


I am trying to parse a huge flat file into flat file schema, from a file if 3 rows contains tag value "2" then it should pick all three rows at a time but in my case, am unable to pick those rows whose tag values are similar but if it is in sequentially manner then i am able to pick if it is in different rows then it is unable to pick the rows and while parsing it throws error.

I want to pick all data along with all the data tag value starts with =2 all the tag value starts with= G

Please help me how can i achieve it?

1220612WEBL230PROD2206080606CA01                                         
200000162608361   FFVV220606D910142122982635 4TKTT0140MAZUR/JESSICA APRIL
500000100000071069CAD2CA      00000001425XG      00000003384SQ      00000
G000001YXY  YVR                      AC  K 03JUL22     06SEPKZ2HZCFL     
2000001CAD   657.60            CAD   710.690QYXY AC YVR Q3.00Q27.00 197.1
G000001                   00000000000      CAD2  CA                      
2000001AC ONLY -BG AC                                                    

Schema

form: FLATFILE

structures:
- id: 'ID'
  name: ID
  data:
  - { idRef: 'IT01', count: 1 }
  - { idRef: 'IT02', count: '>1' }
  - { idRef: 'IT05', count: '>1' }
  - { idRef: 'IT0G', count: '>1' }
  
segments:
- id: 'IT01'
  name: IFG RET file header
  values:
  - { name: 'recIdentifier', usage: M, type: String, length: 1, tagValue: '1' }
  - { name: 'sate', usage: M, type: String, length: 6 }
  - { name: 'fier', usage: M, type: String, length: 4 }
  - { name: 'Number', usage: M, type: String, length: 3 }
  - { name: 'nt', usage: M, type: String, length: 4 }
  - { name: 'ate', usage: M, type: String, length: 6 }
  - { name: 'ime', usage: M, type: String, length: 4 }
  - { name: 'Code', usage: M, type: String, length: 2 }
  - { name: 'Number', usage: M, type: String, length: 2 }
  - { name: 'notUsed1', usage: M, type: String, length: 41 }
- id: 'IT02'
  name: IFG RET file IT02 record
  values:
  - { name: 'notUsed1', usage: M, type: String, length: 1, tagValue: '2' }
  - { name: 'sate', usage: M, type: String, length: 6 }
  - { name: 'fier', usage: M, type: String, length: 4 }
  - { name: 'Number', usage: M, type: String, length: 3 }
  - { name: 'nt', usage: M, type: String, length: 4 }
  - { name: 'ate', usage: M, type: String, length: 6 }
  - { name: 'ime', usage: M, type: String, length: 4 }
  - { name: 'Code', usage: M, type: String, length: 2 }
  - { name: 'Number', usage: M, type: String, length: 2 }
  - { name: 'notUsed1', usage: M, type: String, length: 41 }
- id: 'IT05'
  name: IFG RET file IT05 record
  values:
  - { name: 'notUsed1', usage: M, type: String, length: 1, tagValue: '5' }
  - { name: 'sate', usage: M, type: String, length: 6 }
  - { name: 'fier', usage: M, type: String, length: 4 }
  - { name: 'Number', usage: M, type: String, length: 3 }
  - { name: 'nt', usage: M, type: String, length: 4 }
  - { name: 'ate', usage: M, type: String, length: 6 }
  - { name: 'ime', usage: M, type: String, length: 4 }
  - { name: 'Code', usage: M, type: String, length: 2 }
  - { name: 'Number', usage: M, type: String, length: 2 }
  - { name: 'notUsed1', usage: M, type: String, length: 41 }
- id: 'IT0G'
  name: IFG RET file IT0G record
  values:
  - { name: 'recIdentifier', usage: M, type: String, length: 1, tagValue: 'G' }
  - { name: 'sate', usage: M, type: String, length: 6 }
  - { name: 'fier', usage: M, type: String, length: 4 }
  - { name: 'Number', usage: M, type: String, length: 3 }
  - { name: 'nt', usage: M, type: String, length: 4 }
  - { name: 'ate', usage: M, type: String, length: 6 }
  - { name: 'ime', usage: M, type: String, length: 4 }
  - { name: 'Code', usage: M, type: String, length: 2 }
  - { name: 'Number', usage: M, type: String, length: 2 }
  - { name: 'notUsed1', usage: M, type: String, length: 41 }

Expected output-

{
  "actions": [
    {
      "5": [
        {
          "Records": "      0000000",
          "hello3": "      00000000000"
          
        }
      ],
      "2": [
        {
          "After": "16DEC",
          "hello": "YYZ"
        }
      ],
 "Header": {   //how to generate this field in flat file schema please help me
          
  "1": {
    "reportingSystemIdentifier": "WEBL",
    "recIdentifier": "1"
    
  }
}
]
}
``````````````

Solution

  • The error is caused because the structure expects the order defined in the flat file schema (records 2, records 5, records G) but in the file line 5 has a record 2 after a record G.

    If the records are in ordered groups of 2, 5, G you could try using a group with repetitions.

    However if the records are unordered, then the flat file format may not support such a structure. You may need to implement an alternative with code (Java or scripts).

    Updating the structure with a group that contains records 2, 5 and G in that order may work. Just as an example:

    ...
    structures:
    - id: 'IFGRET'
      name: IFGRET
      data:
      - { idRef: 'IT01', count: 1 }
      - groupId: 'Details'
        count: '>1'
        items:
        - { idRef: 'IT02', count: '>1' }
        - { idRef: 'IT05', count: '>1' }
        - { idRef: 'IT0G', count: '>1' }
    ...