cancel
Showing results for 
Search instead for 
Did you mean: 

JDBC receiver - conditional insert

sbhutani1
Contributor
0 Kudos

Hi,

I am doing a scenario in which i have to insert a record into jdbc table based on a field value in source structure.

e.g. i have an xml message with 3 records like below

col 1 col2 col3

A 1 !

B @

C 3 #

now i want to insert a record for A and C but not for B, since for B col2 has no value.

in short i want to skip my mapping in case of B.

Thanks,

Sumit

Accepted Solutions (0)

Answers (2)

Answers (2)

rodrigoalejandro_pertierr
Active Contributor
0 Kudos

to do this,

you must define a condicion in Receiver Determination in ID and specify what value shuold come in this field for data passed to receiver system.

in IR, how you are getting data from a DB, you must define a specific structure, see this link

<DT_xxxxx>

..<row>0...unbounded

....<col1>

....<col2>

....<col3>

..</row>

</DT_xxxxx>

the tag <row> indicate that you are receiving data from a SQL query that you execute in this case in you Communication Channel.

Thanks

Rodrigo

Reward Points Please

justin_santhanam
Active Contributor
0 Kudos

Sumit,

Which target structure are u using? It can be easily done in mapping. If you could give the source and target structure it could be easy for us to suggest.

raj.

sbhutani1
Contributor
0 Kudos

Source message

BAPI

>Document

>>Item

>>>field1

>>>field2

Target message

>Statement

>>Tablename

>>>action

>>>Table

>>>Access

where item is mapped with statement.

justin_santhanam
Active Contributor
0 Kudos

Sumit,

What's the occurence of field1 and field2?

raj.

sbhutani1
Contributor
0 Kudos

occurance is 1 for all the fields....

justin_santhanam
Active Contributor
0 Kudos

Sumit,

If it's 1, then how come in your example you missed one col( I mean one field). It's not possible right? If the occurrence is 1 , then always must present in the source, isn't it? I can suggest you right away the solution, but before I want to confirm with you what u are exactly looking for, that's why I'm asking all these question.

raj.

Edited by: Raj on Feb 25, 2008 9:13 AM

sbhutani1
Contributor
0 Kudos

yes it is right and thats why i am getting an exception. now i dont want to execute my mapping if there is no value in col2.

any suggestions?

justin_santhanam
Active Contributor
0 Kudos

Sumit,

If you are not sure whether the data will come all the times from the source, then change the occurrence to 0..1.Here's the solution.

Go thru the below logic.

The item must be mapped to the Access node of the target.

Results

http://www.flickr.com/photos/23855877@N07/2291840434/sizes/o/

Mapping for Access node

http://www.flickr.com/photos/23855877@N07/2291840440/sizes/o/

Mapping for Fields

http://www.flickr.com/photos/23855877@N07/2291840444/sizes/o/

UDF used for generating Access Node

http://www.flickr.com/photos/23855877@N07/2291840510/sizes/o/


 for(int i=0;i<input1.length;i++)
{
if(!(input1<i>.equals("No Value") || input2<i>.equals("No Value")))
result.addValue("");
}

UDF used for generating fields

http://www.flickr.com/photos/23855877@N07/2291840512/sizes/o/


   
for(int i=0;i<input1.length;i++)
{
if(!(input1<i>.equals("No Value") || input2<i>.equals("No Value")))
{
	if(field[0].equals("1"))
	{
	result.addValue(""+input1<i>+"");
	result.addContextChange();
	}
	else if (field[0].equals("2"))
	{
	result.addValue(""+input2<i>+"");
	result.addContextChange();
	}
}
}

Hope it helps!

raj.

sbhutani1
Contributor
0 Kudos

Hi Raj,

i dont have any knowledge of java, is there any other way (standard xi) of excluding item node in case of there is no value in a field.

Thanks

Sumit

rodrigoalejandro_pertierr
Active Contributor
0 Kudos

hi

excuse me the previous post, i was wrong with JDBC structure.

for structures see this.

http://help.sap.com/saphelp_nw04/helpdata/en/2e/96fd3f2d14e869e10000000a155106/frameset.htm

about you questions, yes is possible to check if there is a value in a field or if the field exist in the receiver structure. you must put it in receiver determination--> condicion

for example:

/p1:MT_sp_demo/row/REG256 = EX --> here you check if the field REG256 exist in XML structure

(/p1:MT_sp_demo/row/REG256 &#8800; )here verify if the fiel have any value

also here you can use Xpath function (substring,lenght,ect)

Thanks

Rodrigo

justin_santhanam
Active Contributor
0 Kudos

Sumit,

I didn't do Java Mapping. It's very very simple User defined function in graphical mapping. I gave exactly all the flow with all the snapshots. Do you want me to explain the code? Tell me I'll try to explain!

raj.