cancel
Showing results for 
Search instead for 
Did you mean: 

Insert into JDBC table based on one field value

former_member309357
Participant
0 Kudos

Hello Experts,

     I have a scenario PROXY - PI - JDBC. We have to insert data into two tables based on condition type. Say if condition type = 1, insert the data into first table or else if condition type = 2 insert data into second table.

    Please let me know your valuable inputs on this. It is a bit urgent requirement.

 

    Thanks a lot in advance, experts.

Thanks

Ravi

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Ravi

Create two statement in your JDBC message structure.

StatementName1

StatementName2

Use createIf function for populating both the statement.

if condion 1 = true --> createIf------>

StatementName1

if condion 2 = true --> createIf------>

StatementName2

Use the follwing structure for your insert query

<StatementName>  

<dbTableName action=”INSERT”>

<table>realDbTableName</table>

<access>

<col1>val1</col1>

<col2>val2</col2>

</access>

<access>

<col1>val11</col1>

</access>

</dbTableName> 

  </StatementName2>

Let me know if you still have any doubts.

former_member309357
Participant
0 Kudos

Hi Indrajit,

     Thanks a lot for your quick response. Checked by creating two statements and tested in PI mapping and its working fine.

     Will you please elaborate more on the below statement you have provided i.e: How the below query to be used:

Use the following structure for your insert query

<StatementName> 

<dbTableName action=”INSERT”>

<table>realDbTableName</table>

<access>

<col1>val1</col1>

<col2>val2</col2>

</access>

<access>

<col1>val11</col1>

</access>

</dbTableName>

  </StatementName2>

Thanks

Ravi

former_member309357
Participant
0 Kudos

Hi Indrajit,

     We have a change on the scenario. From source we have a chance to get both conditions at a time as two structures. So for condition 1 we need to insert the data in first table and for the condition 2 we need to insert the data in the second table.

    At the same time we have to insert corresponding data into specific tables.

    Kindly give your valuable inputs on this.

Thank

Prashanth

Former Member
0 Kudos

Hi Ravi

Please create one strcuture mentioned below for your JDBC structure

Map field action with 'SQL_DML'

Map the field access like below

mention your condition in the if. For test I have used Content = 'X'

in the two constant , write your insert query which will be like below

INSERT INTO tableA VALUES('$fieldvalue1$','$fieldvalue2$')

INSERT INTO tableB VALUES('$fieldvalue1$','$fieldvalue2$')

Finaly map fieldvalue1 and fieldvalue2 with the desired fileds in the source structure.

Hope now you will be able to complete your task. Let me know if you have any doubts.

Answers (2)

Answers (2)

baskar_gopalakrishnan2
Active Contributor
0 Kudos

Very simple. You don't need to create two statements structure.   Please check below

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

see the example without placeholder and with placeholder.

You can use that format and in the mapping based on the condition you create string in constant function and map the constant function to the access tag. That's it.

<StatementName>

<anyName action=“SQL_DML”>

<access>Write insert statement here</access>

<key>

  <placeholder1>value1</placeholder1>

  <placeholder2>value2<placeholder2>   

</key>

</anyName >

  </StatementName>

iaki_vila
Active Contributor
0 Kudos

Hi Ravi,

If the DB is the same for the two tables you can use the same JDBC receiver communication channel. You only need to map in the message mapping the right DB table discerning with the if standard function to map one table or another in the <table> tag.

Check this http://help.sap.com/saphelp_nw73/helpdata/en/44/7b67fffde93673e10000000a114a6b/content.htm?frameset=...

Regards.