Reputation: 27
Eval Num = 1;
Why do we prefer:
C EXCEPT DDMAST
---------------------------
O RDDMAST E DDMAST
O NUM
Over:
UPDATE DDMAST
Upvotes: 0
Views: 618
Reputation: 11
So the syntax of UPDAT/UPDATE may have come out later than EXCPT/EXCEPT, but that doesn't really make it more modern. In fact, if I remember correctly the first version of ILE did not offer the %fields BIF. Anyway, although the use of EXCPT/EXCEPT (or UPDATE DDMAST %fields(X,Y,Z); (required in fully free since there are no O specs)) appears to be old-fashioned long-hand at first, specifying the exact fields (columns) being updated makes the code sturdier (resistant to accidental bugs being created during program enhancements) when for example you have global variables and the possibility that a PF or LF field name can be changed inadvertently in memory buffer (like by accessing another file record with overlapping field names (audit field names, key field names etc.)).
Thus we always used exception output to clarify exactly what fields are being updated and consider the use of update without clarifying fields/columns as an inappropriate shortcut. By always specifying the fields/columns being updated, this (a) makes it clear to the enhancement/maintenance developer which fields/columns are intending to be changed (by the original programmer), (b) has the added benefit that the compile listing x-ref shows the narrowed list of fields being updated and (c) similarly shows the exact and narrowed list in quality automated documentation utilities like Abstract. When it comes to SQL, if you think about it in a parallel manner, most database updates via SQL are also specified down to the column level.
So for one thing you really wouldn’t want to convert from EXCEPT to UPDATE without also including the fields being updated lest risk introducing bugs into the program during modernization.
Upvotes: 0
Reputation: 23813
In 25yrs, I've never seen EXCEPT used for a Physical File. EXCEPT is used for "exception records" defined in the o-specs. I suppose it might make sense to WRITE exceptions to a table rather than a spool file. But I've never seen it.
Honestly, looking at the documentation, it's not even clear that it can be used instead of UPDATE.
A bit of googling turned up a post that indicated EXCEPT could be used to update selected fields in a PF. There is a performance benefit to doing that.
However the modern (though 21yrs old) way to update individual fields only is with the %FIELDS()
BIF.
update ddmast %fields(num);
Lastly, you can't (directly) define o-specs in a fully **free
RPG IV program.
Using EXCEPT instead of UPDATE would not be allowed in my shop.
Upvotes: 4
Reputation: 11493
We don't.
It is really a shop preference. I was going to say EXCPT was easier, but I can't really even justify that in my mind. A lot of folks used EXCPT to output to the printer because it was easier than creating a print file, and sometimes that made it's way to database files as well because it was the same process, but I always preferred WRITE and UPDATE and DELETE over EXCPT, and eventually even stopped using EXCPT for reports as well since you could do more things with a printer file than you could with the program described output specs. These days I don't even use record level IO for database files, preferring SQL.
Upvotes: 4