Monday, September 26, 2011

Easytrieve: How to delete records in KSDS file?

Here is how you can perform the Delete


Deleting a Record
-=-=-=-=-=-=-=-=-=

   You can use the WRITE statement to delete individual records from an INDEXED file.  The deleted record is the file's current input record.

            FILE KSDS INDEXED UPDATE
            %PERSNL
            FILE KEYS
            WHO 1 5 N
            JOB INPUT KEYS NAME MYPROG
              READ KSDS KEY WHO STATUS
              IF FILE-STATUS NE 0
                DISPLAY 'READ FAILED...KEY= ' WHO
                STOP
              END-IF
              WRITE KSDS DELETE STATUS
              IF FILE-STATUS NE 0
                DISPLAY 'DELETE FAILED'
                STOP
              END-IF

Similarly, here is how you can UPDATE a record

Updating a Record
=-=-=-=-=-=-=-=-=-

   You can modify and rewrite the current input record by using the WRITE statement.

            FILE KSDS INDEXED UPDATE
            %PERSNL
            FILE KEYS
            WHO      1  5 N
            PHONE    6 10 N
            JOB INPUT KEYS NAME MYPROG
              READ KSDS KEY WHO STATUS
              IF FILE-STATUS NE 0
                DISPLAY 'READ FAILED...KEY= ' WHO
                STOP
              END-IF
              MOVE PHONE TO TELEPHONE
              WRITE KSDS UPDATE STATUS
              IF FILE-STATUS NE 0
                DISPLAY 'UPDATE FAILED...KEY= ' WHO
                STOP
              END-IF

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.