ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

service program that returns next values

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • service program that returns next values

    Hello,
    Can I make a service program that keeps it's memory and return the next result set. makes sense right.

    I want a procedure that will return a data structure from a SQL statement. The next time I invoke the procedure I want it to return the next data structure or a blank one for EOF.

    In old school rpg I would just do a return without setting LR on, then use a shut down call that would set LR on. I have no clue how to do this in a procedure.

    Thanks.
    Hunting down the future ms. Ex DeadManWalks. *certain restrictions apply

  • #2
    Re: service program that returns next values

    Have a look at the LIMIT and OFFSET enhancements for the SELECT statement in the last technology refresh.

    Birgitta

    Comment


    • #3
      Re: service program that returns next values

      Just to answer your general question about variables keeping their memory across calls...

      In a procedure, define the variable with the STATIC keyword. That will make it retain its value across calls to the procedure.

      Or you could define the variable as a global variable in the module by defining it before any procedures. In a NOMAIN module, global variables never get reinitialized, so you automatically get the same behaviour as returning with LR off.

      If you want to reinitialize a local static variable in a procedure, you'd have to call the procedure with some special parameter or no parameter. That's not usually very convenient with prototyped procedures since you'd have to make the parameter setup work for both normal calls and the shutdown-call.

      If you want to be able to reinitialize a global variable, you could add an "init" procedure to refresh any globals you want, or you could add a "shutdown" procedure to do any cleanup you want, like closing global files.

      Comment

      Working...
      X