Updating row selected by cursor
Line 5: In the RPG program I had to provide create declare a procedure prototype of QCMDEXC, and pass it the length of the string.
Line 23: Having finished with the cursor I need to close it.I always add line 11, it is not necessary as without the cursor is still opened for update.I just think it is better as it documents how the file will be used.Line 4: As this is only a test I do not want to commit changes to the file, therefore I am using the to turn it off.I can do this when compiling the program too, but this makes absolutely sure just in case the person who compiles the program forgets to change the compile command parameter.Lines 2 – 5: As I will be calling the QCMDEXC API program I need to define a procedure prototype for the API. Line 6: I need to define the file, TESTFILE, with a statement.
This file will be used for update, it is keyed, and user opened.
I am sure we all could write a simple program to do this in RPG using its native database access.
Mine looks like: 01 **free 02 dcl-pr QCMDEXC extpgm ; 03 *n char(100) options(*varsize) const ; 04 *n packed(15:5) const ; 05 end-pr ; 06 dcl-f TESTFILE usage(*update) keyed usropn ; 07 QCMDEXC('CPYF FROMFILE(TESTFSAVE) TOFILE(TESTFILE) MBROPT(*REPLACE)':56) ; 08 open TESTFILE ; 09 setll ('1') TESTFILER ; 10 dow (1 = 1) ; 11 reade ('1') TESTFILER ; 12 if (%eof) ; 13 leave ; 14 endif ; 15 FFIELD = 'A' ; 16 update TESTFILER %fields(FFIELD) ; 17 enddo ; 18 close TESTFILE ; 19 *inlr = *on ; running 7.3 I am going to use totally free RPG.
With this in mind I have coded a data structure to be like my file TESTFILE.
I will be using the data structure to receive the input from the SQL Fetch.
Line 7: As this is a test program I want to be able to run this multiple times to make sure I update the right field with the right value.