The following shows how easy it is to call an RPG from Groovy. Note that this particular RPG returns information via a parameter; it does not return a result set.
boolean isDuplicatePO(String custNo, String poNo, String orderNo) {
def sql = new groovy.sql.Sql(sessionFactory.
getCurrentSession().connection())
boolean duplicate = false
sql.call ("call o99lib.o99epo (?,?,?,?)",
[Sql.in(Types.CHAR, custNo),
Sql.in(Types.CHAR, poNo),
Sql.out(Types.CHAR),
Sql.in(Types.CHAR, orderNo)
]) { dup -> duplicate = (dup == 'Y')}
return duplicate
}
The Groovy Sql object was built in the above code from a connection obtained from a Grails DataSource. But you could build your own with:
def sql = groovy.sql.Sql.newInstance(
"jdbc:as400://192.168.1.50/mylib",
"don", "secret",
"com.ibm.as400.access.AS400JDBCDriver")
To create the stored procedure wrapper, I used the following:
CREATE PROCEDURE O99LIB/O99EPO(
IN custNo CHAR(7),
IN poNo CHAR(25),
OUT dup CHAR(1),
IN ordNo CHAR(6))
LANGUAGE RPGLE
NOT DETERMINISTIC
NO SQL
EXTERNAL NAME O99LIB/O99EPO
PARAMETER STYLE GENERAL
Most RPG code does not make it obvious whether or not the parameters are input, output, or input/output. But it is worth the effort to figure out what is what and appropriately define the parameter usage in the create procedure statement.
1 comment:
Don, This works great, however if in addition to the params I want to also get back a result set.
How do you do that?
Kevin
Post a Comment