cancel
Showing results for 
Search instead for 
Did you mean: 

How to parse the footer without keys for sender file adapter

Former Member
0 Kudos

Hi, all

I am having an interface to do that parses a flat file and here is the example format:

Joe;Smith;8E1;2005-01-01

John;Doe;9N5;2004-12-30

COUNT:2

The trailer is the count. If the count is not the same as the number of lines of data, then an error should be returned.

I am not sure how to parse the data with the sender file adapter. Originally I was thinking to use the keyFieldValue to parse in the trailer since COUNT can be the key and ":" is the fieldSeparator. However, the data portion(Joe;Smith:....) does not have a key. So it didn't work out.

Please advise and your help is much appreciated.

Thanks

Jonathan.

Accepted Solutions (1)

Accepted Solutions (1)

RaghuVamseedhar
Active Contributor
0 Kudos

Jonathan,

Please use this FCC

Document NameD_N
Document NamespaceD_Ns
Recordset NameR_N

Recordset Namespace R_Ns

Recordset StructureR_S,*
R_S.fieldSeparator;
R_S.fieldNamesfirstN,secondN,numb,date
R_S.endSeparator'nl'
R_S.missingLastFieldsadd

Output of FCC will be


<?xml version="1.0" encoding="utf-8"?>

<ns:D_N xmlns:ns="D_N">

  <ns:R_N xmlns:ns="R_N">

  <R_S>

  <firstN>Joe</firstN>

  <secondN>Smith</secondN>

  <numb>8E1</numb>

  <date>2005-01-01</date>

  </R_S>

  <R_S>

  <firstN>John</firstN>

  <secondN>Doe</secondN>

  <numb>9N5</numb>

  <date>2004-12-30</date>

  </R_S>

  <R_S>

  <firstN>COUNT:2</firstN>

  <secondN></secondN>

  <numb></numb>

  <date></date>

  </R_S>

  </ns:R_N>

</ns:D_N>

In message mapping write UDF (Execution type 'All values of Queue') to firstN field.


String c = var1[var1.length - 1];

String count = c.substring(c.indexOf(":") + 1, c.length());

System.out.println(count);

if ((var1.length - 1 + "").equals(count)) {

    //System.out.println("equal");

} else {

    //Trigger alert;

//throw new StreamTransformationException(exception.toString());

}

FYI.

Former Member
0 Kudos

Hi, Raghu

Thanks. Is there an easy way to take out the last line "COUNT:2" so that it doesn't show up in the target structure? Here is the proof of concept mapping I am working with:

This obviously won't work as the last record will have no data. But is there an easy way to tell PI not to create the last record node?

Thanks,

Jonathan.

engswee
Active Contributor
0 Kudos

Jonathan

Use CreateIf to create the Record node based on value in FirstName-

FirstName.startWiths = "COUNT:" --> NOT ---> createIf --> RemoveContexts --> Record

This will create a SUPPRESS for the last record, which will cause the last record to not be generated.

For the child fields, you just map according to your requirement.

Rgds

Eng Swee

Former Member
0 Kudos

Thanks, Eng Swee! It works. I was trying a similar mapping and don't understand why it doesn't work. I am still a pretty confused with the context concept in PI.

So why did I only get 1 "record" instead of 2?

Also, if I change the context of firstname to record, that also works. Why is that?

Thanks,

Jonathan.

Former Member
0 Kudos

Okay, after reading some docs, I guess changing the context of firstname to record is the same effect as the removecontexts node function. However, on the target node, can you only get one value if there are multiple context change in the queue?

Thanks,

Jonathan.

engswee
Active Contributor
0 Kudos

Hi Jonathan

The following blog is a good resource for understanding queues and contexts.

Yes, changing context of FirstName to a higher level is the same as RemoveContexts in this specific mapping logic.

Basically, the number of values per context in the output of the last function before the target field needs to match the occurrence defined for the target field.

If your target field has multiple occurrence, you can have more than one value per context. If target field occurrence is one, then you can only have one.

Check out my explanation in the thread below to see if it helps.

Re: Context and Queue Mapping Problem 2

Rgds

Eng Swee

Former Member
0 Kudos

Eng Swee, thank you for your detailed explanation.

Answers (0)