An ESP function should have the following basic structure with regard to its interaction with the Open Server API:
Get the number of parameters.
Get the values of the input/output parameters and bind them to local variables.
Use the input parameter values to perform processing, and store the results in local variables.
Initialize any output parameters with appropriate values, bind them with local variables, and transfer them to the client.
Use srv_sendinfo to send the returned row to the client.
Use srv_sendstatus to send the status to the client.
Use srv_senddone to inform the client that processing is done.
If there is an error condition, use srv_sendinfo to send the error message to the client.
See the Open Server Server-Library/C Reference Manual for documentation of the Open Server routines.