Line 1: Code will be fully free.
Line 2: My standard control options keywords.
Line 4: Constant to add Carriage Return and Line Feed to a text file.
Lines 7: Declaration of a clob host variable of 10000 bytes.
Lines 13-15: Variables to hold the values of the json file.
Lines 16-17: Variables to be used with %scan and %subst.
Line 19: Variable to contain the html code that will be written to the file.
Line 21: Declaration of the first clob file to hold the html code.
Line 41: Declaration of the second clob file that will hold the json file so ccsid is set to utf-8.
Lines 44-45: Declaration of the blob files to copy the jpg.
Line 47: Change of the sql compiler options in code. No commit cycle will be used and sql cursors will be automatically closed when the module ends.
Lines 49-51: ifsFile1 is set using full path using the subfields generated by the precompiler. The file will be opened in overwrite mode.
Lines 53-58: Html code is assigned to a variable. Although it is not necessary, each line is finished with a carriage return and a line feed so you can see how to write a new line in any ifs text file.
Line 60: This is the line where DB2 writes the content of the variable htmlVar to the file ifsFile1 that points to ‘/home/asalcedo/whoami2.html’.
Lines 62-64: ifsFile2 is set to an existing file in the ifs using full path. The file will be opened to be read.
Line 66: DB2 assigns the content of the file pointed in variable ifsFile2 in the clob variable db2Clob1.
Lines 68-88: As is in the comments of the code, this is not the proper method to process a json file or json string. It is here just for educational purposes as it was another string held in the clob variable. You can see the structure of the json file below and it only has 3 fields called name, job and city. As fields are separated from values with a colon (:) the program search first for this position. Then as all the values are characters and in json are between double quotes the program search for the last double quote that finish the value. Finally using these positions (and with some addition and subtraction to calculate the starting position and exact length) and a substring the value is extracted to a variable.
Lines 86-88: A message is composed with the values of the json file and it will be show in the screen message line and in the job log using snd-msg operation code.
Lines 91-93: The first jpg file is assigned to blobFile1 and it is opened to be read. The jpg file must exist in the ifs.
Lines 95-97: The second jpg file is assigned to blobFile2 and it is opened as overwrite, that is, if the file does not exists it will be created and otherwise will be overwritten.
Line 99: DB2 makes the copy assigning the contents of blobFile1 to blobFile2.
One Response