Switch to Italian
Giovanni's logo
Handle multiple occurrences of an input variable from the browser
this means Version 2
index
M
power search
blue line

What is a multiple input variable from the browser

Suppose that a CGI expects to receive from the browser an input string like the following

itemno=00727&qty=1&itemno=00932&qty=7&itemno=01858&qty=15

That could be an order of three items, each with a different quantity.
In other words, the CGI receives multiple occurrences of input variables imtemno and qty.

CGIDEV2 service program provides the following procedures:

  • ZhbGetVarCnt returns the number of multiple occurrences of a given input field
  • ZhbGetVar returns the value of one of the multiple occurrences of a given input field
  • ZhbGetVarUpper returns the value of one of the multiple occurrences of a given input field in uppercase characters
Example:
 * Prototype definitions and standard system API error structure
 /copy CGIDEV2/qrpglesrc,prototypeb
 /copy CGIDEV2/qrpglesrc,usec
 * Number of variables
DnbrVars          s             10i 0
 * Saved query string
Dsavedquerystring...
D                 s          32767    varying
 * Return code
D rc              s             10i 0 inz(0)
 * Variables for retrieving multiple occurrencies of "itemno" and "qty"
D itemcount       s             10i 0
D varocc          s             10i 0
 *
D itemno          s              5a
D qty             s              3a
 *           ... etc. ...
 * Get input
C                   eval      nbrVars =
C                             zhbgetinput(savedquerystring:qusec)
 * Example of multiple occurences
C                   eval      itemcount = ZhbGetVarCnt('itemno')
C                   IF        itemcount > 0
C     1             do        itemcount     varocc
C                   eval      itemno = ZhbGetVar('itemno':varocc)
C                   eval      qty    = ZhbGetVar('qty':varocc)
C                   exsr      ProcessItem
C                   enddo
C                   ENDIF

These procedures are able to process an unlimited number of occurrences of the same input variable.

For an example of retrieving multiple occurrences of an input variable, please check out program boatsch2 in the YachtWorld demo.