cancel
Showing results for 
Search instead for 
Did you mean: 

problem with UDF

Former Member
0 Kudos

Hello,

I need to do a select from database and know the number of register founded.

I've the following UDF:

String Query = " ";

Channel channel = null;

DataBaseAccessor accessor = null;

DataBaseResult resultSet = null;

String ret = "0";

// Build the Query String

Query = "Select * from SAP_INTERF_PROYECTOS where NUMDOC = '" + BELNR + "' and POSDOC = '" + POSEX +"'";

try{

//Determine a channel, as created in the Configuration

channel = LookupService.getChannel("bs_arteche_tp_db_jdbc","cc_lookup_receiver");

//Get a system accessor for the channel. As the call is being made to an DB, an DatabaseAccessor is obtained.

accessor = LookupService.getDataBaseAccessor(channel);

//Execute Query and get the values in resultset

resultSet = accessor.executeQuery(Query);

}

//for(Iterator rows = resultSet.getRows();rows.hasNext();){

//ret = "1";

//}

catch(Exception ex){

}

finally

{

try

{

if (accessor != null)

ret = "1";

}

catch (Exception ex)

{

}

}

return ret;

The statment 'for' doesn't work, because it stays in an infinite loop.

The statment 'if' always return the same value, does not mind if exist register in the database

How can i verify if the database return register or not?

Thanks very much,

Regards,

Accepted Solutions (1)

Accepted Solutions (1)

Shabarish_Nair
Active Contributor
0 Kudos
for(Iterator rows = resultSet.getRows();rows.hasNext();){
Map rowMap = (Map)rows.next();
//do your logic here
}

use the above code.

Ref: /people/siva.maranani/blog/2005/08/23/lookup146s-in-xi-made-simpler

Former Member
0 Kudos

Hello Shabarish,

I have done the same at /people/siva.maranani/blog/2005/08/23/lookup146s-in-xi-made-simpler, but the UDF does't work fine.

When I test the message mapping, it returnrs the error "Cannot produce target element /ns0:MT_OFERTAS/STATEMENT/TABLENAME/ACCESS/ESTADO. Check xml instance is valid for source xsd and target-field mapping fulfills requirements of target xsd". If I display the queue of the UDF it returns "SUPPRESS".

Do you know how can I solve this problem?

Thanks very much.

Former Member
0 Kudos

Hello,

I solve the problem. I change UDF Cache: I had selected Context radiobutton and I change by the Value radiobutton.

Thanks.

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

If you interested in number of registers, please use count(*) instead of * which will return number of records which are satisfying the where condition. No need to use the loop and all just check the return value for greater than 1 and do the needful.

Hope this helps.

Thanks,

Kalpesh

Former Member
0 Kudos

Hi,

Check the syntax with this [https://help.sap.com/javadocs/NW04/current/pi/com/sap/aii/mapping/lookup/LookupService.html]

and have a look here

[https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/5365aa90-0201-0010-5a9a-e231f40187db]

Hope it will help u.