How to delete all records from view ?

Is possible to delete all records from defined view without reading them (like below):

READ VIEWNAME BY ISN
   DELETE
   END TRANSACTION
END-READ

This is possible with an Adabas direct call (even from Natural, let me know if you want to know more), but not with regular Natural DML (which makes sense as it also shields programmers from inadvertently deleting a file’s contents with a single call).

Two comments re. your example:

  • use a physical read instead of reading by ISN, this will speed it up
  • don’t issue an ET after every single DELETE, do it conditionally after every ‘n’ calls

If it is Adabas you can with direct Adabas Command E1 refresh the file (delete all records). The file must also have the option PGMREFRESH=YES.

Just to add to Wolfgang’s important guidelines for deleting all the records from a file:

Your “viewname” should have but one field, namely the physically first field in the fdt.

steve

DELETE doesn’t require any fields in the view. All you need is the view name.

DEFINE DATA LOCAL 
1 EMP    VIEW EMPLOYEES 
END-DEFINE 
READ EMP PHYSICAL 
  DELETE 
  IF  *COUNTER > 49 
    THEN 
      END TRANSACTION 
  END-IF 
END-READ 
END TRANSACTION 
END

Emptying a file programmatically is not recommended if there are MANY records, or if you are going to do this repeatedly (to the same file). In those situations, use the PGMREFRESH option (via Natural), or the ADADBS utility to REFRESH the file (batch or via Adabas Online System).

Hello,

Be very careful with Natural when you want to delete all records in a view (DDM).
Have you checked that there is only one view (Natural DDM) associated with the physical file (Adabas FDT)?
If so, are you sure it will be always the case?
Personally, in our company, we have banned the use of READ BY ISN and READ PHYSICAL.

To delete all records in one view, we recommend:

  1. For Natural, if the number of records permits:
DEFINE DATA LOCAL 
1 EMP VIEW EMPLOYEES 
1 #COUNTER (I2) 
END-DEFINE 
READ EMP BY EMP-NUM 
  DELETE 
  ADD 1 TO #COUNTER 
    IF #COUNTER> 49 
    THEN 
      END TRANSACTION 
      RESET #COUNTER 
  END-IF 
END-READ 
END TRANSACTION 
END 
  1. Or, use of Utility, if the number of records is important.
ADAULD FILE = nnn, SORTSEQ = AD 

ADALOD UPDATE FILE = nnn, DDISN

Best Regards

Hello,

Be very careful with Natural when you want to delete all records in a view (DDM).
Have you checked that there is only one view (Natural DDM) associated with the physical file (Adabas FDT)?
If so, are you sure it will be always the case?
Personally, in our company, we have banned the use of READ BY ISN and READ PHYSICAL.

To delete all records in one view, we recommend:

  1. For Natural, if the number of records permits:
DEFINE DATA LOCAL 
1 EMP VIEW EMPLOYEES 
1 #COUNTER (I2) 
END-DEFINE 
READ EMP BY EMP-NUM 
  DELETE 
  ADD 1 TO #COUNTER 
    IF #COUNTER> 49 
    THEN 
      END TRANSACTION 
      RESET #COUNTER 
  END-IF 
END-READ 
END TRANSACTION 
END 
  1. Or, use of Utility, if the number of records is important.
ADAULD FILE = nnn, SORTSEQ = AD 

ADALOD UPDATE FILE = nnn, DDISN

Best Regards

Assuming “all records in a view” means “all records on the file” - to delete them use ADADBS REFRESH

ADADBM REFRESH :wink:

Mainframe → ADADBS
OpenSystems → ADADBM

:wink: