Example: Sample LC LSX Agent to Call a DB2® Stored Procedure

This example uses the SQL stored procedure shown in the previous example.

Sample LS:

[Options]
Option Public
Option Explicit
Uselsx "*lsxlc"

[Initialize]
Sub Initialize
	Dim sess As New LCSession
	Dim conn As New LCConnection ("db2")
	
	'set the connection parameters...
	conn.Database = "databaseName"
	conn.UserId = "userId"
	conn.Password = "passWord"
	
	'connect to the database...
	conn.Connect
	
	'set the stored procedure owner and stored procedure name...
	conn.Owner = "DB2ADMIN"
	conn.Procedure = "NEW_SALES_ORDER"
	'set Fieldnames property with any output parameters declared in 
	the stored procedure...
	conn.Fieldnames = "SONUM"
	
	'declare any fields and fieldlists for input/output data...
	Dim input_fieldlist As New LCFieldList
	Dim output_parms As New LCFieldlist
	Dim in_field As New LCField (1, LCTYPE_INT)
	Dim sonum As New LCField (1, LCTYPE_NUMERIC)
	Dim out As Double

	'set the input parameters of the stored procedure...	
	Set in_field = input_fieldlist.Append ("CUSTID", LCTYPE_INT)
	in_field.Value = 2146
	
	Set in_field = input_fieldlist.Append ("ITEMID", LCTYPE_INT)
	in_field.Value = 196
	
	Set in_field = input_fieldlist.Append ("QTY", LCTYPE_INT)
	in_field.Value = 500
	
	'with the input parameters set, call the stored procedure...
	'the declared output_parms fieldlist will hold the output parameters 
	of the stored procedure...
	out = conn.Call (input_fieldlist, 1, output_parms)
	'fetch parameter(s) into the output_parms fieldlist...
	out = conn.Fetch (output_parms)
	
	'retrieve the parameter(s) from the output_parms fieldlist...
	Set sonum = output_parms.GetField (1)
	
	'use the output parameter value(s) in your script...
	Print "Your new sales order number is " & sonum.Value(0)
	
	conn.Disconnect
	
End Sub