Here are some gotchas that SQL/400 users might find useful. The first will bite RPG programmers who believe that SQL cursors will remain open when returning to a prior program without setting on LR.
Files accessed using embedded SQL are handled differently than files opened and closed by other methods. To simulate the non-LR return, you must compile the RPGSQL program specifying *ENDJOB for the Close SQL Cursor (CLOSQLCSR) parameter. You then need to include a Close SQL Cursors routine that is executed whenever the program terminates with LR on. You should also assume that your cursor may be open on entry because SQL cursors are not closed in the RPG termination or cancel routines. The Reclaim Resources (RCLRSC) command also ignores SQL cursors.
Another potential gotcha is the LIKE comparison operator. It allows comparison of fields using the % and _ wildcard characters. When using LIKE, be aware that comparison values are not padded with blanks. SQL/400 assumes that all character fields are variable length.
To use LIKE, pad out all character values to their full length or end your comparison string with the % character. This is not necessary for variable length fields or when using any of the other comparison operators that automatically pad with blanks.
The final gotcha concerns partial outer joins. This condition exists when two files are joined and there is not a corresponding record in the secondary file.
A work-around described in the SQL Redbook involves using the UNION keyword and multiple SELECT statements. The work-around will increase the amount of time spent executing a multifile join exponentially depending on the number of files being joined. Often the only practical solution is to incorporate a "does not apply" or "not established" value in your database with a corresponding record in your secondary file. IBM's suggestion to use OPNQRYF-with JDFTVAL(*YES)- can bite back when joining more than two files since JDFTVAL cannot be specified at the file level.
As more AS/400 shops jump on the SQL bandwagon, IBM may be forced to extend SQL/400 to address these inconsistencies. Until then, creative programming is all that's available.
LATEST COMMENTS
MC Press Online