Skip to Content
avatar image
Former Member

How to handle a fixed length file without newline?

Hi Experts,

I'd like to handle a fixed length file without newline by sender file adapter.

A file like following.

It contains three recores."AAXBBBXCCCCX" is one record.

AA1BBB1CCCC1AA2BBB2CCCC2AA3BBB3CCCC3

I tried that following two parameters set. But only first recored was read.

fieldFixedLengths

fieldFixedLengthType

Please tell me how to handle.

Thanks

Shinya Kawagoe.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Best Answer
    avatar image
    Former Member
    Mar 08, 2011 at 09:42 AM

    >

    > Hi Experts,

    >

    > I'd like to handle a fixed length file without newline by sender file adapter.

    > A file like following.

    > It contains three recores."AAXBBBXCCCCX" is one record.

    >

    > AA1BBB1CCCC1AA2BBB2CCCC2AA3BBB3CCCC3

    >

    > I tried that following two parameters set. But only first recored was read.

    >

    > fieldFixedLengths

    > fieldFixedLengthType

    >

    > Please tell me how to handle.

    >

    > Thanks

    > Shinya Kawagoe.

    You can read all the file, and concatenate the rows in a single field with an UDF in mapping.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      For this case we wrote a simple Adapter Module inserting an end of line character after an offset.

      This way it can be reused in many interfaces.

      And reading the whole file may not be an option in case of large source files. May cause performance / memory issues.

      eolbean.offset = <recordLlen>

      XMLPayload xmlpayload = msg.getDocument();
      
      byte[] content = xmlpayload.getContent();
      
      byte crlf = 0x0A;
      int current = 0;
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      
      int lines = content.length / recordLen;
      do 
      {
      	lines--;
      	baos.write(content, current, recordLen);
      	
      	if (lines > 0) // if other lines, eol required
      	{
      		baos.write(crlf);
      		current += recordLen;
      	}
      } while (lines > 0);
      
      xmlpayload.setContent(baos.toByteArray());
      baos.close();
      Audit.addAuditLogEntry(key, AuditLogStatus.SUCCESS,	MODULE + " Done EOLing.");

  • avatar image
    Former Member
    Mar 08, 2011 at 11:46 AM

    Hi Shinya

    I think its better you read it as one single line and then split in mapping by doing substring as it is a fixed length file

    Regards

    Sandeep

    Add comment
    10|10000 characters needed characters exceeded

  • Mar 08, 2011 at 02:50 PM

    Write a simple UDF...

    Read the line first and use substring to parse the chars during mapping as similar

    String completeLine="AA1BBB1CCCC1AA2BBB2CCCC2AA3BBB3CCCC3";
    String firstRecord = completeLine.substring(0,12);
    String secondRecord = completeLine.substring(12,24);
    String thirdRecord = completeLine.substring(24);

    Hope this helps

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Mar 09, 2011 at 02:45 AM

    Hi all,

    Thanks for all reply.

    I wouldn't like to use UDF or another add-on programming.

    I'd like to solve this situation using PI standard function only.

    But maybe I think it must be impossible.

    If someone had good answer, tell me please.

    Regards

    Shinya Kawagoe.

    Edited by: Shinya Kawagoe on Mar 9, 2011 11:45 AM

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Shinya

      Intially read the entire line into one Field

      ex:

      Input : A1B1C1A2B2C2

      Use two data type

      One is

      Record((0 to1))

      Input

      and second data type is

      Record(o to unbounded)

      Input

      and then use two mapping

      First mapping is to just split the record using standard substring function

      Record

      Input - A1B1C1

      Record

      Input-A2B2C2

      and second mapping for actual mapping as per your requirement and

      you can call both mappings in one operation mapping as operation mapping

      Regards

      Sandeep