7 26 3 DELETE Examples

LANSA Technical

7.26.3 DELETE Examples

Example 1: Delete an order specified in field #ORDNUM from an order header file:

DELETE FROM_FILE(ORDHDR) WITH_KEY(#ORDNUM)
 

Example 2: Delete order line number 1 and then order line 2 from an order lines file called ORDLIN. The order number is contained in a field called #ORDNUM:

DELETE FROM_FILE(ORDLIN) WITH_KEY(#ORDNUM 1)
DELETE FROM_FILE(ORDLIN) WITH_KEY(#ORDNUM 2)
 

Note the use of the numeric literals 1 and 2 as key values.

This example could also have been coded as:

CHANGE    FIELD(#I) TO(1)
DOWHILE   COND('#I <= 2')
DELETE    FROM_FILE(ORDLIN) WITH_KEY(#ORDNUM #I)
CHANGE    FIELD(#I) TO('#I + 1')
ENDWHILE
 

Example 3: Delete all order lines associated with an order specified in field #ORDNUM:

DELETE FROM_FILE(ORDLIN) WITH_KEY(#ORDNUM)
 

Note that this command deletes multiple records from the file.

Example 4: Delete all order lines associated with an order specified in field #ORDNUM and then delete the order header record:

DELETE FROM_FILE(ORDLIN) WITH_KEY(#ORDNUM)
DELETE FROM_FILE(ORDHDR) WITH_KEY(#ORDNUM)
 

Example 5: Delete all records from file NAMES where field #DLTIND contains a Y:

DELETE FROM_FILE(NAMES) WHERE('#DLTIND = Y')
 

Example 6: Delete all records from file NAMES where field #DLTIND contains a Y and field #UPDATE is less than the current date:

DELETE FROM_FILE(NAMES) WHERE('(#DLTIND = Y) AND (#UPDATE < *YYMMDD)')
 

Note the use of the system variable *YYMMDD which contains the current date in format YYMMDD (which is presumably the same format as #UPDATE).