Giovanni's logo
Tips for optimum use of an external DS
this means Version 2
blue line
  1. The fields of the physical file to be used as an external Data Structure should define only the variables which might be in the input string sent by the client browser
    • there is no need to define here the output variables from your CGI programs to the response html
  2. Field names must be the same as the names of the variables in the input string (i.e. the names preceded by ? or &) and must be different from your data base field names
    • to avoid mismatches inside your programs
  3. About fields that should be converted as numeric
    • remember that no numeric field can be defined in HTML, all fields there are in character format.
      QtmhCvtDb API may convert them to numeric if you define them as numeric in the external data structure. However, read the following ...
    • Fields defined with data type S in the external data structure may not be converted (the API may fail, your program bumps out -you may need PTF's to fix the API-)
    • Fields defined with data type P in the external data structure are converted by the API as long as their contents are really numeric (if by chance the user enters alphabetics, the API bumps out).
      You have two ways to make sure that an input field contains numeric data
      • control the input data on the browser itself, by means of a JavaScript routine (see my Javascript tutorial); this is my favorite approach
      • writing in the CGI a routine that checks numeric fields in the input string; this routine should run before the call to procedure CvtDb
    • Fields defined with data type A have no problems. If they are supposed to contain numeric data, then your program should check them before converting to numeric. That is another way to differ numeric control after the call to procedure CvtDb.
  4. How many external data structures do I need?
    This is up to you to decide. You may have:
    • A separate data structure for each program
    • Several data structures shared among programs
    • A single external data structure for all programs in a given library
    • ... etc.
  5. What then if I add, change, or delete fields in an external data structure shared by several programs?
    • Any time you do this and recompile an external data structure physical file, your existing CGI programs, using that data structure, though may not bump out, do not receive any longer their input fields as expected.
      You may tell this from the fact that they appear as not receiving their inputs any longer.
    • You should then
      1. endtcpsvr *http
      2. recompile all your RPG modules and recreate all the CGI programs using that external data structure
      3. strtcpsvr *http
    This is why I recommend you to maintain a CL program to perform this job.
    Worth doing it since the beginning of your developments, in order to save a lot of your time.
  6. What is suggested if one decides to use a single external data structure for all programs in a given library?
    • My suggestion is to create this data structure independently from the need of the individual programs.
      • Field names could be just anonymous (e.g. CGIINP01, CGIINP02, CGIINP03, ...
      • Field lengths should be great enough to accomodate any program requirements (e.g. 100 characters)
      • There should be enough fields for the most input-demanding programs
      As an example, you may look at the external data structure used by command
      crtcgisrc ... option(1)
    • You should however be aware of some minor performance problem when using large external data structures, expecially when running them in CGIDEBUG mode.


Warning
In your HTML scripts you must make sure that no input fields exceed their lengths as specified in the corresponding fields of the external data structure. Should this happen, CvtDb would stop parsing the input string.
  • In the input type=text fields of your HTML forms you must always specify the maxlength attribute
  • input type=textarea fields do not support the maxlength attribute. In these cases you must use a Javascript function to make sure that the length of the input text does not exceed the length of the target field in the external data structure.