cancel
Showing results for 
Search instead for 
Did you mean: 

Sample code to fill the target field with spaces

Former Member
0 Kudos

Hi All,

Can anyone has sample code to fill the target field with spaces? I have many fields where I need to fill with spaces like 30,164 like that.

Thx

Navin

Accepted Solutions (1)

Accepted Solutions (1)

bhavesh_kantilal
Active Contributor
0 Kudos

Navin,

use this simple udf. The input will be a constant containing the number of spaces you want .Let this input parameter be Blanks.

String returnBlank="";
for(int i=0; i<Blanks;i++){
   returnBlank=returnBlank+" ";
}

return returnBlank;

Regards

Bhavesh

Former Member
0 Kudos

Hi Bhavesh,

I get the following error when I use sampel code below:

H:/usr/sap/RXI/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map0478a140eabb11dbb905001143eeb19b/source/com/sap/xi/tf/_test_source1_target2_.java:42: <b>operator < cannot be applied to int,java.lang.String for(int i=0; i<Blanks;i++){ ^ 1 error</b>

Please let me know how to resolve this?

Thx

Navin

henrique_pinto
Active Contributor
0 Kudos

Your input (in the case, Blanks) is of String type. You'll have to parse it b4 you can use it.

...
int Blanks = Integer.parseInt(input);
...

where <i>input</i> is the input field.

But, IMHO, you should use MapWithDefault standard field instead.

Regards,

Henrique.

MichalKrawczyk
Active Contributor
0 Kudos

Hi,

you can change to:

int numerofblanks = Integer.parseInt(Blanks);

String returnBlank="";

for(int i=0; i<numerofblanks;i++){

returnBlank=returnBlank+" ";

}

return returnBlank;

Regards,

michal

former_member189558
Contributor
0 Kudos

Hello Navin,

The reason you are getting this error is Blank is string and I is integer.

U need to convert Blank to Integer first using:

int B = Integer.parseInt(Blank);

then use B instead of Blanks in the forloop

Thanks,

Himadri

Message was edited by:

Himadri Chakraborty

former_member189558
Contributor
0 Kudos

Hello Navin,

The reason you are getting this error is Blank is string and I is integer.

U need to convert Blank to Integer first using:

int B = Integer.parseInt(Blanks);

then use B instead of Blanks in the forloop

Thanks,

Himadri

Former Member
0 Kudos

Hi Henrique,

Can I use MapWithDefault in my case?

Thx

Navin

henrique_pinto
Active Contributor
0 Kudos

Sure can!

Just enter in it the value you want it to input whenever an empty field comes.

Regards,

Henrique.

Former Member
0 Kudos

I still dont get it. How does it insert spaces?? Description says something else.

Thx

Navin

henrique_pinto
Active Contributor
0 Kudos

From http://help.sap.com/saphelp_nw2004s/helpdata/en/43/c4cdfc334824478090739c04c4a249/frameset.htm :

<i>

Replaces empty contexts in the inbound queue with a default value, which you specify in the function properties.

Example:

If “Default” is the default value and

A|B1,B2| |C| |D

is the inbound queue,

mapWithDefault returns the following outbound queue:

A | B1,B2 | Default | C | Default |D.

The function corresponds to the following combination of standard functions:

If(

[]field,

exists([]field),

Constant([value=default]))</i>

So, just click twice on the MapWithDefault field and enter your 30 spaces or whatever. It will fill empty fields with it.

But, for it to work, your empty field will need to be unique in the context, meaning, it must have max occurrence of 1 and be inserted in the unbounded tag. If thats not the case, just use the udf.

Regards,

Henrique.

Answers (0)