Please enable JavaScript to view this site.

A-Shell Reference

Added May 2024

LOCK #ch

Applicable only when LOKSER enabled, LOCK is used to lock the primary index (ch) after locating a record using a secondary index. This is automatic when the record is located via the primary index.

Example

The following illustrates looking up a record in the secondary index and then deleting it. The LOCK statement is used to first lock the primary index before the delete operation.

OPEN #PCH, "WIDGET", ISAM'INDEXED,  RECSIZ, RECNO    ! primary index & data

OPEN #SCH, "WIDGET2", ISAM'INDEXED, RECSIZ, RECNO    ! secondary index

...

ISAM #SCH , 1, KEY       ! lookup key in secondary index SCH

IF ERF(SCH) = 33 then

    ? "Record not found"

ELSEIF ERF(SCH) # 0 then

    GOTO ISAM'ERROR

ELSE

    LOCK #PCH            ! lock primary index

    READL #PCH, REC      

    ISAM #SCH, 4, SKEY   ! delete secondary key

    IF ERF(SCH) # 0 GOTO ISAM'ERROR

    ISAM #PCH, 4, PKEY   ! delete primary key

    IF ERF(PCH) # 0 GOTO ISAM'ERROR

    ISAM #PCH, 6, PKEY   ! delete data rec

    IF ERF(PCH) # 0 GOTO ISAM'ERROR

    WRITE #PCH, REC

ENDIF

 

See Also