Kourier Integrator Online Help
KMK.SERVICE SERVICE_ID {EXPORT-NETCHG | EXPORT-DELETES}{HEADERS "STRING"}
This command can be used to execute a Kourier service from the command line or from within a UniBASIC program.
SERVICE_ID |
The name of a service in the KT_SERVICES file. |
EXPORT-NETCHG |
Indicates that all exports listed in the service are to run in net change mode. |
EXPORT-DELETES |
Indicates that all exports listed in the service are to run in net change with deletes mode. This keyword must be used in combination with the EXPORT-NETCHG keyword. |
HEADERS |
Creates a substitution parameter as specified in "string" where "string" is a named value pair in the format of "name=value". The substitution value can be referenced by using the %name syntax. |
If you attempt to execute a Kourier service when another service is running, you will receive an error. If you want to check to see if a service is “running” before executing a Kourier service, you can try to read the service record from KT_SERVICES with a READU statement. If the record is locked, then 99.9% of the time this means the service is running. The other .1% is when someone is writing the record from the GUI, in which case it is safe to ignore. Following is some sample code that you can use for your READU statement:
0001: OPEN 'KT_SERVICES' TO F.SERVICES ELSE STOP
0002: READU SERVICE FROM F.SERVICES, 'SQL_CUSTOMER' LOCKED
0003: PRINT 'Service is running'
0004: END THEN
0005: PRINT 'Service is NOT running'
0006: END
KMK.SERVICE DEMO_KTLOG EXPORT-NETCHG
In this example, the service DEMO_KTLOG will be run in Net Change mode. The output from each export in the service will be saved in the target DSN as a message. Once the service completes, the messages will be de-queued automatically and delivered to the target DSN.
It is possible to call a Kourier Service from UniBASIC code. To do this you must do the following:
Here is a UniBASIC fragment that shows how you can call a Kourier service and check on its execution status.
0001: *
0002: $INCLUDE KORE-INCLUDES KT.STATUSCOM
0003: *
0004: CMD = \KMK.SERVICE DEMO_KTLOG EXPORT-NETCHG\
0005: *
0006: EXECUTE CMD CAPTURING OUTPUT
0007: *
0008: CMD.STATUS = KT.GETSTATUS(CMD.ERR,CMD.PARAMS)
0009: IF CMD.STATUS THEN; * An error was encountered
0010: PRINT 'Error=':CMD.ERR
0011: PRINT 'Params=':CMD.PARAMS
0012: CALL KT.GETMESSAGE(CMD.ERR,CMD.PARAMS,CMD.ERR.TEXT,'')
0013: PRINT 'ErrText=':CMD.ERR.TEXT
0014: END
Line 002 "includes" the common declarations used by the Kourier command status routines.
Line 008 uses the KT.GETSTATUS function to determine if the service ran successfully or if the service encountered an error. If the KT.GETSTATUS function returns a non-zero value then the service encountered an error. The details of the error are returned in the CMD.ERR and CMD.PARAMS variables.
Line 012 uses the KT.GETMESSAGE subroutine to format the error into a human readable format. This text is returned in the CMD.ERR.TEXT variable.