cancel
Showing results for 
Search instead for 
Did you mean: 

Reg: Mapping Problem

Former Member
0 Kudos

Hi....

I am having input File which is having only one field..Below is the input file structure.

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

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

<ns0:MTO_Check_Request xmlns:ns0="http://axis.com/file_upload">

<FileName>Test_Master</FileName>

</ns0:MTO_Check_Request>

The Input value should be splitted .

Then My output should like below format.

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

<ns0:MTI_Check_Response xmlns:ns0="http://axis.com/file_upload">

<FileName>Test</FileName>

<FileType>Master</FileType>

</ns0:MTI_Check_Response>

Can you please help how to do the mapping. If any UDF required can you please provide.

Thanks & Regards,

Leela

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

Use like below..In the global variables(String[] arr = null; )and use as per malini ans,

Select context or queue for udf:

Split 1:

arr = a[0].split("_");

result.addValue(arr[0]);

Split 2:

arr = a[0].split("_");

result.addValue(arr[1]);

Regards,

Prakasu

Former Member
0 Kudos

Hi..

Thank u so much. My problem got solved. You will get ur points.

Regards,

Leela

Answers (11)

Answers (11)

markangelo_dihiansan
Active Contributor
0 Kudos

Hi Leela,

Here is an alternate solution:

FileName --> UDF1 --> FileName

UDF1 and UDF2 are both of value type

Here is the code for UDF1, argument type is: input

int c[] = null;

c = new int [1];

c[0]=input[0].indexOf("_");

result.addValue(input[0].substring(0,c[0]));

FileName --> UDF2 --> FileType

Here is the code for UDF2, argument type is: input1

int c[] = null;

c = new int [1];

c[0]=input1[0].indexOf("_");

result.addValue(input1[0].substring(c[0]+1,input1[0].length()));

Let me know if this worked.

Regards,

Former Member
0 Kudos

Hi,

What is the function paramete for ur UDF? is it value or queue or context. If it is value change to queue.

Former Member
0 Kudos

Hi,

It is because u declare it as a string array ie String array and in function it is used as string. That might be causing the error . Give it as arr[] insted of arr.

Edited by: sivarama krishna on Feb 25, 2009 1:02 PM

Former Member
0 Kudos

Hi,

It is because u declare it as a string array ie String arr[]; and in function it is used as arr. That might be causing the error . Give it as arr[] insted of arr.

Edited by: sivarama krishna on Feb 25, 2009 12:58 PM

Former Member
0 Kudos

Declare it as String arr = a[0].split("_");

sorry i have typed it wrong in the previous mail.

Former Member
0 Kudos

hi Leela,

the error is because u havent declared the arr . Declare it as : arr = a[0].split("_");

Former Member
0 Kudos

Hi... I have declared that. even though it is showing the same error.

Regards,

Leela

Former Member
0 Kudos

Hi...

If i include that i am getting the below error.

Source code has syntax error: /usr/sap/APD/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map51268d30033311dea6d6002264977f6e/source/com/sap/xi/tf/_MM_Check_DB_Request_.java:69: incompatible types found : java.lang.String[] required: java.lang.String String arr = a[0].split("_"); ^ /usr/sap/APD/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map51268d30033311dea6d6002264977f6e/source/com/sap/xi/tf/_MM_Check_DB_Request_.java:70: array required, but java.lang.String found result.addValue(arr[0]); ^ /usr/sap/APD/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map51268d30033311dea6d6002264977f6e/source/com/sap/xi/tf/_MM_Check_DB_Request_.java:76: incompatible types found : java.lang.String[] required: java.lang.String String arr = a[0].split("_"); ^ /usr/sap/APD/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map51268d30033311dea6d6002264977f6e/source/com/sap/xi/tf/_MM_Check_DB_Request_.java:77: array required, but java.lang.String found result.addValue(arr[1]); ^ 4 errors

Regards,

Leela

Former Member
0 Kudos

Hi...

Do we need to import any library functions for that? if yes can you provide ?

Regards,

Leela

Former Member
0 Kudos

Hi leela,

Goto Edit java sections

under global variables declare as String arr[];

your problem will be resolved.

No need of importing any library functions here..

Former Member
0 Kudos

Hi Leela,

use this Below UDF...

public void split1(String[] FileName,ResultList result,Container container)

{

int idx=0;

int tokenCount;

String ret[]=new String [3];

StringTokenizer st=new StringTokenizer(FileName[0]);

tokenCount= st.countTokens();

while (st.hasMoreTokens())

{

ret[idx]=st.nextToken(); // here idx should be in square brackets

idx++;

}

for (idx=0;idx<tokenCount; idx++)

{

result.addValue(ret[idx]); // here idx should be in square brackets

}

} // end of UDF

Thank You,

Madhav

Note: Points If Useful.

Former Member
0 Kudos

Hi Leela,

Write a UDF and the input of the UDF should be the text node or input node.

In the UDF use this function:

String [] asValues = strInput.split("_");

and return the values using a for loop.

markangelo_dihiansan
Active Contributor
0 Kudos

Hi Leela,

Would you be able to provide more examples aside from test_master?

Regards,

Former Member
0 Kudos

Hi..

Below are the sample inputs. The input value should be split based on the underscore("_").

Input1_Master

Input2_Annexure

Sample_Annexure

Test_Master

Regards,

Leela

markangelo_dihiansan
Active Contributor
0 Kudos

Hi Leela,

In that case, the solution provided by Malini should suffice.

Regards,

Former Member
0 Kudos

Hi,

Use a UDF to split the input on "_"

Declare a global varible String arr[]; under initialization section


public void split1(String[] a,ResultList result,Container container)
{
arr  = a[0].split("_");
result.addValue(arr[0]);
}

public void split2(String[] a,ResultList result,Container container)
{
result.addValue(arr[1]);
}

FileName>split1->FileName

FileName->split2->FileType

Former Member
0 Kudos

Hi..

I have used your udf. But i am getting the below errors.

/usr/sap/APD/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map8baf0ec0033111deba47002264977f6e/source/com/sap/xi/tf/_MM_Check_DB_Request_.java:68: cannot resolve symbol symbol : variable arr location: class com.sap.xi.tf._MM_Check_DB_Request_ arr = a[0].split("_"); ^ /usr/sap/APD/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map8baf0ec0033111deba47002264977f6e/source/com/sap/xi/tf/_MM_Check_DB_Request_.java:69: cannot resolve symbol symbol : variable arr location: class com.sap.xi.tf._MM_Check_DB_Request_ result.addValue(arr[0]); ^ /usr/sap/APD/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map8baf0ec0033111deba47002264977f6e/source/com/sap/xi/tf/_MM_Check_DB_Request_.java:75: cannot resolve symbol symbol : variable arr location: class com.sap.xi.tf._MM_Check_DB_Request_ result.addValue(arr[1]); ^ 3 errors

Regards,

Leela

prateek
Active Contributor
0 Kudos

Use substring standard text function.

Regards,

Prateek

Former Member
0 Kudos

I cant use substring because the file name not constant. It will be changing. Based on "_", we need to split. The input file can be either Test_Master or Test_Annexure.

Regards,

Leela

Former Member
0 Kudos

Hi,

Use the below UDF to split based on the token pattern("_" in your case).

public static String TokenAt(String sInput, String sPattern, String sTokenNo) {

int iTokenNo = 0;

try {

sToken = sInput.split(sPattern);

int iNoOfTokens = sToken.length;

iTokenNo = Integer.parseInt(sTokenNo);

iTokenNo = ((iTokenNo > iNoOfTokens) ? iNoOfTokens : iTokenNo);

} catch (Exception e) {

return "";

}

return sToken[iTokenNo - 1];

}

Regards,

Swetha.