XMLQueryService

function options(*DIRECT)

 

define field(#ORDERXML) type(*CHAR) length(256) desc('Path to salesorder.xml') input_atr(LC)

def_list name(#BROWSE) fields((#ORDERNUM *OUT) (#CUSTNUM *OUT))

 

change field(#ORDERXML) to('/LANSA_dc@pgmlib/jsm/instance/order.xml')

begin_loop

 

request fields(#ORDERXML) identify(*DESC) browselist(#browse)

clr_list named(#BROWSE)

execute subroutine(LOADORDERS)

selectlist named(#ORDERS)

add_entry to_list(#BROWSE)

endselect

 

end_loop

 

subroutine name(LOADORDERS)

 

define field(#ORDERNUM) type(*CHAR) length(10) colhdg('Order' 'Number') input_atr(LC)

define field(#CUSTNUM) type(*CHAR) length(10) colhdg('Customer' 'Number') input_atr(LC)

def_list name(#ORDERS) fields(#ORDERNUM #CUSTNUM) type(*WORKING) entrys(100)

 

* open JSM connection

* load the XMLQueryService

use builtin(JSM_OPEN) to_get(#JSMSTS #JSMMSG)

execute subroutine(CHECK) with_parms(#JSMSTS #JSMMSG)

 

change field(#JSMCMD) to('''service_load service(XMLQueryService) trace(*yes)''')

use builtin(JSM_COMMAND) with_args(#JSMCMD) to_get(#JSMSTS #JSMMSG)

execute subroutine(CHECK) with_parms(#JSMSTS #JSMMSG)

 

* load the salesorder.xml file

use builtin(TCONCAT) with_args('load file(' #ORDERXML ')') to_get(#JSMCMD)

use builtin(JSM_COMMAND) with_args(#JSMCMD) to_get(#JSMSTS #JSMMSG)

execute subroutine(CHECK) with_parms(#JSMSTS #JSMMSG)

 

* query each <SalesOrder> element, for each, return

* - value of @SONumber attribute (sales order number)

* - value of @CustNumber attribute of the contained <Customer> element

clr_list named(#ORDERS)

change field(#JSMCMD) to('''query nodes(//SalesOrder) nodesvalue1(@SONumber) nodesvalue2(Customer/@CustNumber) service_list(ORDERNUM,CUSTNUM)''')

use builtin(JSM_COMMAND) with_args(#JSMCMD) to_get(#JSMSTS #JSMMSG #ORDERS)

execute subroutine(CHECK) with_parms(#JSMSTS #JSMMSG)

 

* unload the XMLQueryService

* close the JSM connection

change field(#JSMCMD) to('service_unload')

use builtin(JSM_COMMAND) with_args(#JSMCMD) to_get(#JSMSTS #JSMMSG)

use builtin(JSM_CLOSE) to_get(#JSMSTS #JSMMSG)

 

endroutine

 

* -----------------------------------------------

* Subroutine CHECK: checks the JSM return status

* -----------------------------------------------

subroutine name(CHECK) parms((#JSMSTS *RECEIVED) (#JSMMSG *RECEIVED))

 

if cond('#jsmsts *ne ok')

 

use builtin(TCONCAT) with_args(#JSMSTS ' : ' #JSMMSG) to_get(#STD_TEXTL)

menu msgid(DCM9899) msgf(dc@m01) msgdta(#STD_TEXTL)

 

endif

 

endroutine