This is a little utility program that reads a a flat 500 byte file called CPYSRCTBL. This is some data ready to go into HTML and it just wants a <BR> glued onto the end of each line.
In the old code, it defines the file as internally described and define the 500 character field calling it filedata. This file is read and each line of read (filedata) is right adjusted and <BR> added onto the end. Then it's updated using the old Output specs with an EXCEPT statement.
Here's the old code:
// add <br> statements
// ------------------------------------------------------------- *
// program i.d. : cpysrchtm *
// date coded : april 1999 *
// function : layout the report correctly *
// ------------------------------------------------------------- *
FCPYSRCTBL UF F 500 DISK extfile('QTEMP/CPYSRCTBL')
ICPYSRCTBL NS
I 1 500 FileData
Dow Not %EOF(CPYSRCTBL);
If %Subst(FileData:1:1) <> '<';
FileData = %Trim(FileData) + '<br>';
EndIF;
Except;
Read CPYSRCTBL;
EndDo;
*INLR = *ON;
O FileData 500
There are lots of ways to modernize this code, but this is the simplest and most basic way I could think of doing it with SQLRPGLE.
Here's the new SQL code:
// ------------------------------------------------------------- *
// add <br> statements
// ------------------------------------------------------------- *
// program i.d. : cpysrchtm
// date coded : april 1999
// function : layout the report correctly *
// ------------------------------------------------------------- *
dcl-s filedata char(500);
monitor;
exec sql DECLARE C0 CURSOR FOR
SELECT CPYSRCTBL
FOR UPDATE ;
exec sql OPEN C0 ;
exec sql FETCH C0 INTO :filedata ;
dow (SQLCOD <> 0);
if %Subst(filedata:1:1) <> '<';
filedata = %Trim(filedata) + '<br>';
endif;
exec sql UPDATE CPYSRCTBL
SET CPYSRCTBL = :filedata
WHERE CURRENT OF C0 ;
exec sql FETCH C0 INTO :filedata ;
enddo;
on-error;
// handle your own crashroutine here
endmon;
*inlr = *on;