cancel
Showing results for 
Search instead for 
Did you mean: 

Message Mapping using Left justified, right blank/space filled

Former Member
0 Kudos

Hi,

My Interface is outbound Interface.

Suppose source field named 'Filename' is mapped with Target field named 'Filename'.Condition is AS IS(Left justified, right blank/space filled).

How should i do this mapping?

Accepted Solutions (0)

Answers (4)

Answers (4)

baskar_gopalakrishnan2
Active Contributor
0 Kudos

Try this UDF. Another way of doing this

public String leftJustifiedRightSpace(String input) {
            int fieldLength = 20; // decide for your field length
	    input.trim();
	    for(int count=0;count<fieldLength;count++){
	    	input=input+" ";
	    }
return input;
}

anupam_ghosh2
Active Contributor
0 Kudos

Hi Sanghamitra Duttagupta,

you can try this UDF below


public static String fieldJustified(String s)
	{
		
		try
		{
			final int fieldLength=20;
			char filler=' ';
			s=s.trim();
			int l=s.length();
			while(l<fieldLength)
			{
				s=s+filler;
				l++;
			}
		}
		catch(Exception e)
		{
			return s;
		}
		return s;
	}

Please reset the value of the variable "fieldLength", in code above to the field length as per your need. The right side will be filled with extra spaces since value of "filler" variable is ' '. you can set this to any character of your choice so that total field length is equal to value of variable "fieldLength" (which is 20 here).


so if input is  "        hi"
output           "hi                  "

regards

Anupam

Edited by: anupamsap on Aug 1, 2011 1:53 PM

Former Member
0 Kudos

Hi,

If you do not have any specific length or white space preservation requirement, it will be a straight forward 1:1 mapping.

If you want to remove whitespace, use the standard trim function.

For left\right justify the value to a specific length. go for a simple udf, that checks the length and then adds the required number of spaces as per the requirement.

Regards

Former Member
0 Kudos

Hi

You can concatenate the needed number of spaces to your source field.

If source value starts with spaces you want to remove, use trim function before concatenation.

If length of source value is dynamic you can concatenate with enough spaces and then use substring to get the wanted target length.

Regards,

Giuseppe