cancel
Showing results for 
Search instead for 
Did you mean: 

UDF, to fetch value from record to corresponding field

ravi_teja14
Participant
0 Kudos

Hi Team,

I am trying to fetch the value from record set based on the length. The input file is flat file and the values need to be assigned to the Target structure as the below format mentioned as the below blog.

Tried to modify the udf by using substring(int beginIndex, int endIndex)


inputfile structure


CUSTAAA123

ORDR111FIRSTORDER

LINE19MATERIAL112348

TAXLLOCAL12812

ORDR285SECONDORDER

LINE20MATERIAL20

CUSTBBB456

CUSTCCC789

ORDR777FIRSTORDER3

LINE10MATERIAL17

TAX1LOCAL7

TAX1STATE8

TAX1FEDERAL9

Please help me in modifying the below javacode to retrevie the values based on the beginindex & endIndex

UDF-

public void udf_Shopping(String[] eachLine, ResultList Customer, ResultList Name, ResultList ID, ResultList Order, ResultList OrderNumber, ResultList OrderNote, ResultList LineItem, ResultList LineNumber, ResultList Material, ResultList TaxLine, ResultList Type, ResultList Amount, Container container) throws StreamTransformationException{ 

int countCust = 0, countOrdr = 0, countLine = 0

String values[]; 

for (String line : eachLine) { 

values = line.split(","); 

if (line.startsWith("Cust")) { 

Customer.addValue("");  Name.addValue(values[1]);  Name.addContextChange(); 

ID.addValue(values[2]);    ID.addContextChange(); 

//Add context change form second Customer. 

if (countCust > 0) {       Order.addContextChange();  } 

countCust++; 

} else if (line.startsWith("Ordr")) { 

Order.addValue(""); 

OrderNumber.addValue(values[1]);  OrderNumber.addContextChange(); 

OrderNote.addValue(values[2]);    OrderNote.addContextChange(); 

//Add context change form second Order. 

if (countOrdr > 0) {              LineItem.addContextChange();  } 

countOrdr++; 

} else if (line.startsWith("Line")) { 

LineItem.addValue(""); 

LineNumber.addValue(values[1]);  LineNumber.addContextChange(); 

Material.addValue(values[2]);    Material.addContextChange(); 

//Add context change form second LineItem. 

  if (countLine > 0) {             TaxLine.addContextChange();        } 

  countLine++; 

  } else if (line.startsWith("Taxl")) { 

  TaxLine.addValue(""); 

Type.addValue(values[1]);    Type.addContextChange(); 

Amount.addValue(values[2]);  Amount.addContextChange();

}

  }

 


T,hanks

Ravi

Accepted Solutions (0)

Answers (1)

Answers (1)

azharshaikh
Active Contributor
0 Kudos

Hi Ravi,

Its not very clear what you are trying to achieve? Can you provide the output that you require for the sample input shared abv.

Also note that Java is case sensitive...you have mentioned in your code

if (line.startsWith("Cust"))...........

where as in Sample input I see that its in CAPS : CUSTAAA123


Regards,

Azhar

ravi_teja14
Participant
0 Kudos

Hi Azhar,

The expected output as below.

<Recordset>

    <Name>AAA</Name>

    <ID>123</ID>

    <OrderNumber>111</OrderNumber>

    <OrderNote>FIRSTORDER</OrderNote>

    <LineNumber>10</LineNumber>

    <Material>MATERIAL10</Material>

    <Type>LOCAL</Type>

    <Amount>1</Amount>

  </Recordset>

input file format is -

CustAAA123

Ordr111FIRSTORDER

Line19MATERIAL112348

TaxLLOCAL12812

Ordr285SECONDORDER

Line20MATERIAL20

CustBBB456

CustCCC789

Ordr777FIRSTORDER3

Line10MATERIAL17

Tax1LOCAL7

There is no change in the flat file except in fixed length instead of ',' . Please help in modifying the above java code to capture the values in between the lenghts like fixed length. want to capture the values between 2-5 & 7-9 .

by using the substring(int beginIndex, int endIndex)



Thanks,

Ravi

    

azharshaikh
Active Contributor
0 Kudos

Hi Ravi,

If its a Fixed Length Flat file, You can perform Substring Operations as follows:


if (var1.startsWith("Cust"))

return var1.substring(4,7);

And So On..

Regards,

Azhar