cancel
Showing results for 
Search instead for 
Did you mean: 

How to add one symbol for field in mapping

former_member182412
Active Contributor
0 Kudos

Hi Experts,

I am doing proxy to file scenario.

my requirement is like this, i need to add ~ symbol for each fieldbefore sending to receiver.

if the field length eqal to 12 the target field must be like this.

if the field is contains 6 characters the remaining characters must be filled with spaces and after hat i need to add ~ symbol.

~978976 ~

How can achieve this, can anyone help me.

Kind regards,

Praveen.

Edited by: Praveen Kumar on Aug 4, 2009 1:09 PM

Accepted Solutions (1)

Accepted Solutions (1)

prateek
Active Contributor
0 Kudos

I am not sure if I understood it correctly but can't you use Concat function directly?

Can you explain further your requirement?

Regards,

Prateek

former_member182412
Active Contributor
0 Kudos

if the field length is 12, but the value is 123456

concat is adding the symbol like this tilt123456tilt

but i want like this : ~123456 ~ (~123456 four spaces ~)

is concat possible to do this???

Edited by: Praveen Kumar on Aug 4, 2009 1:21 PM

Edited by: Praveen Kumar on Aug 4, 2009 1:21 PM

Edited by: Praveen Kumar on Aug 4, 2009 1:21 PM

santhosh_kumarv
Active Contributor
0 Kudos

You would require a UDF....

Try this

return ("~" + String.format("%10s" , input) + "~");

Mapping

input field -


> UDF -


> output field.

~SaNv...

JaganMohan
Participant
0 Kudos

Dear Praveen,

You can write a UDF. In that you can find the length of the string before mapping and add the blank spaces for the remaining places and pass it to target.

Regards,

JP.

former_member182412
Active Contributor
0 Kudos

Hi Santhosh,

sorry i am not java expert, can you please give me the full code in UDF and when i create UDF what must i select value or context.

santhosh_kumarv
Active Contributor
0 Kudos

Hi..

Select the UDF type as value.... and create a parameter with name input

it is only a one line code.. which i have given already

return ("~" + String.format("%10s" , input) + "~");

~SaNv....

former_member182412
Active Contributor
0 Kudos

i am getting this error when i use this code.

return ("" + String.format("%10s" , a) + "");

Source code has syntax error: /usr/sap/CXD/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map9b43d3a081b911dea2f200144f2b5900/source/com/sap/xi/tf/_MM_SapIsuToFile_.java:101: cannot resolve symbol symbol : method format (java.lang.String,java.lang.String) location: class java.lang.String return ("" + String.format("%10s" , a) + ""); ^ 1 error

santhosh_kumarv
Active Contributor
0 Kudos

>>Source code has syntax error:

Strange...!! I am able to execute this code without any error with desired output... In the import statement add

java.lang.String.*

and give a try....

~SaNv...

former_member182412
Active Contributor
0 Kudos

still the same error

Former Member
0 Kudos

Praveen,

I hope your input parameter name is 'a' only.

Regards,

---Satish

santhosh_kumarv
Active Contributor
0 Kudos

Is your function header looks like below...

public String <udf name>(String a, Container container)

~SaNv...

former_member182412
Active Contributor
0 Kudos

Yes it is like this:

public String addSymbol(String a,Container container){

Former Member
0 Kudos

Hi,

In my understand String.format standard function will support JDK1.5 onwards. Lower version will not support. So,check in your jdk version before use that standard function.

So another way use this code,

UDF header like this,

Public String <udf name>(String a, Container container))

Inside UDF put this code:

int strLen = a.length();
for(int i=strLen;i<12;i++)
{
a = a + " ";
}
return "~" + a + "~";

Note: . Example: in this code field length is using 12. becaz we mentioned that loop i<12. If what you need put it instead of 12.

Hope It's working fine .

Regards

Vijaykumar

Answers (3)

Answers (3)

deepak_shah
Contributor
0 Kudos

Hi

You can use Format num standard function and concat function along with some mapping manipulation.

Format num function will help to define lenght of 12

Former Member
0 Kudos

Hi,

FormatNum is not supported to this requirement. Becaz Number format is Right justified, how to put extra spaces in right side.

So , only solution is to achieve this issue for using UDF. Your jdk version is 1.5 or above means using String.format which is given by praveen or else using my above code.

Regards

Vijaykumar

Former Member
0 Kudos

Hi Praveen,

You create one UDF using this code.

int strLen = a.length();

for(int i=strLen;i<12;i++)

{

a=a+" ";

}

return ""a"";

Sourcefield -


> UDF -


> TargetField.

I hope it's help for you.

Regards

Vijay

Former Member
0 Kudos

Once again send that code,

int strLen = a.length();

for(int i=strLen;i<12;i++)

{

a = a + " ";

}

return "" + a + "";

santhosh_kumarv
Active Contributor
0 Kudos

Hi,

You can use string concat standard function

~SaNv..