cancel
Showing results for 
Search instead for 
Did you mean: 

How to insert spaces in elements in message mapping

Former Member
0 Kudos

Hi All,

I have scenario, where in the incoming data is put into a file, but if there is no incoming data for any element it should insert spaces equivalent to the lenght of the field. how can this be done?

XIer

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi ,

No need to use udf when standard funtions are available.

The best thing to is to use ..the standard function call mapbydefault in such cases ..

here inside it you can give spaces equal to fieldlength (when string)

this with existence check will take care of your problem.

source-mapbydefault -


trim--length ---(if greataer then zero) -createif-target

or

source-mapbydefault -


trim--length ---(if greater then zero) ---target.

Regards,

Deepak

Former Member
0 Kudos

Thanks guys its working now.

XIer

Former Member
0 Kudos

Hi,

Can you please update the post how it is working so that if anyone have the same issue they can go through this thread. Also since it is solved please close the thread.

Regards,

---Satsih

Former Member
0 Kudos

Sorry posted multiple times

Former Member
0 Kudos

Sorry posted multiple times

Former Member
0 Kudos

Satish,

I have got the same requirement when i was working

I did like

source field --->mapbydefault -


>targetfield

in the mapbydefault I have given spaces as required like Henrique told above and one

thing is mandatory,we have to keep target field min occurrence to '1' .

Answers (1)

Answers (1)

justin_santhanam
Active Contributor
0 Kudos

Hi,

Use Exists function.

Source --->Exists -


> If ---> Target

In IF Function

Insert Source [True Branch]

Insert Constant[Spaces] [Else Branch]

Best regards,

raj.

Former Member
0 Kudos

I tried that it doesn't work

Xier

justin_santhanam
Active Contributor
0 Kudos

Can u give sample data, so that it could be easy to understand ur reqmt!!

best regards,

raj.

Former Member
0 Kudos

Hi,

Use if then else with exists function in mapping. If the field exists then pass the value else you pass constant with spaces equal to length of the field.

Regards,

---Satish

Former Member
0 Kudos

Lets say I have three fields on the source side

field1

field2

field3

and three fields on the target side

field4 (length 3)

field5 (length 4)

field6 (length 5)

so if i pass

field1 = abc

field2 = empty field

field3 = def

I should get

abc def

the empty space equals the lenght of the field...

Pls advice

Xier

Former Member
0 Kudos

Hi,

If you follow the steps mentioned by me or raj (both are same) your issue will definitely resolved. Once when you do this while testing dont delete the node itself just remove the value only.

Regards,

---Satish

justin_santhanam
Active Contributor
0 Kudos

Hi ,

I think I got ur reqmt, please refer the link

http://www.flickr.com/photo_zoom.gne?id=1042377965&size=o

Best regards,

raj.

Former Member
0 Kudos

Satish I tried using ifThenElse

but when i test message mapping and check the target xml code in 'Test Message Mapping' without passing fields of some fields, it does not show empty spaces in the xml target code.

Xier

henrique_pinto
Active Contributor
0 Kudos

Use mapwithdefault for fields 4, 5, 6, with parameters being 3 blankspaces (field4), 4 blankspaces (field5) and 5 blankspaces (field5).

Regards,

Henrique.

justin_santhanam
Active Contributor
0 Kudos

Oops!!

I'm sorry made mistake. Change the then else part in my image

Best regards,

raj.

Former Member
0 Kudos

Raj that is what i am talking about, the spaces don't show when i test the mapping in 'Test Message Mapping'

Kindly try and pls let me know

Xier

Former Member
0 Kudos

Henrique, this is the XML 'SRC' file get on the target side when I test the mapping,

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

<ns0:MT_Countresult xmlns:ns0="urn:sce.com:xi:FI:TestProjectStructureUpload"><record><field1>a</field1><field2></field2><field3>b</field3></record></ns0:MT_Countresult>

I passed a for field1 nothing for field2 and b for field3.

why is space not coming between <field2></field2>

I used field2 --> 'MapWith Default' --> field2

XIer

Message was edited by:

XIer

Former Member
0 Kudos

Hi,

When you test in test message mapping you will not see the spaces. If you want to see the spaces whether it is present or not then executie test message mapping and then click on Source of target message. Then copy the whole xml message in an notepad. There you can see the spaces also.

Regards,

---Satish

Former Member
0 Kudos

I copied and pasted the stuff in notepad, still I can't see the spaces. Am I doing something wrong.

Xier

Former Member
0 Kudos

Please Click on Source text view in target after you execute the mapping. Then copy the xml file into notepad and see. You should see the spaces. If you dont see then please send me the screenshots of the mapping and the notepad file to satishguntaka@gmail.com

Regards,

---Satish

henrique_pinto
Active Contributor
0 Kudos

Xier,

your problem is that the MapWithDefault function will fill only the fields which have no value, for example, if that tag is like <field2/>. When you have <field2></field2>, you have a value, even though this value is an empty string.

To test your scenario properly, change your input xml to:

<?xml version="1.0" encoding="UTF-8"?>
<ns0:MT_Countresult xmlns:ns0="urn:sce.com:xi:FI:TestProjectStructureUpload">
	<record>
		<field1>a</field1>
		<field2/>
		<field3>b</field3>
	</record>
</ns0:MT_Countresult>

If your requirement is to insert spaces when you have empty string as the input (<field2></field2> case), then you can't use MapWithDefault. In this case, you have to use an if logic: if input = "" (empty string) then output = " " (4 blankspaces), else output = input.

If you don't know how the input will come, best scenario would be to combine the MapWithDefault + If logic, in order to solve both cases (no input or empty string input).

Regards,

Henrique.

Former Member
0 Kudos

Hi ,

No need to use udf when standard funtions are available.

The best thing to is to use ..the standard function call mapbydefault in such cases ..

here inside it you can give spaces equal to fieldlength (when string)

this with existence check will take care of your problem.

source-mapbydefault -


trim--length ---(if greataer then zero) -createif-target

or

source-mapbydefault -


trim--length ---(if greater then zero) ---target.

Regards,

Deepak