I believe the other two responders probably have something there.
The logic looks like someone who loves fixed format and only uses free format if they absolutely have to. Such as certain functions not available in fixed format.
I have a tough time understanding a read loop of the customer master file based on the customer key, which I assume is the customer number. Is it likely you have duplicate customer numbers? Or would a chain have worked better?
Then the big picture view has me wondering if you are looking for all customers who may have a substring in their name. Perhaps a customer lookup function? In that case I might use SQL and a cursor:
D Stmt1 s 512a varying
D SearchString s 50a varying
Stmt1 = 'select cusnbr, cmname from cusmst where cmname like ?';
// The 'like' function, with a string surrounded by % signs, is your midstring search
SearchString = '%' + %trim(neword) + '%';
Exec sql declare C1 cursor for SqlStmt;
Exec sql prepare SqlStmt from Stmt1;
Exec sql Open C1 using SearchString;
Exec sql fetch c1 into :cusnbr, :cmname; // Priming read of loop
Dow sqlcode = *zeros;
// logic here to fill subfile of results
Exec sql fetch c1 into :cusnbr, :cmname; // get next row
EndDo; // found all matching rows.
Exec sql close C1;
And if you want to get fancy you can even do a "sounds like". For more information see the following:
https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_74/db2/rbafzscasound.htm
Rob Berendt
As an Amazon Associate we earn from qualifying purchases.