TRAP Examples


Example 1:

 

  

TRAP

NOMASTER IF IO

  

OPEN

APMASTER,"ACCTSPAY"

 

The TRAP instruction indicates that the program should CALL the subroutine NOMASTER if an IO error occurs. If the OPEN instruction fails because the file does not exist, an IO error occurs and the program calls NOMASTER.

 

Example 2:

 

  

TRAP

NOPROGRM NORESET IF CFAIL

  

CHAIN

"APAYUPTE"

 

The TRAP instruction indicates that the program should CALL the subroutine NOPROGRM if a CFAIL error occurs. If the CHAIN instruction fails (program does not exist, is a bad load module or insufficient system resources), a CFAIL error occurs and the program calls NOPROGRM. The trap remains set (NORESET) until a new TRAP CFAIL is set, a TRAPCLR CFAIL occurs or the program terminates.

 

Example 3:

 

  

TRAP

HELP NORESET PRIOR IF F1

  

KEYIN

"Enter Account Number: ",ACCTNO;

  

...

 

HELP

 

 

  

DISPLAY

.....

  

KEYIN

ANS;

  

RETURN

 

 

The TRAP instruction indicates that the program should CALL the subroutine HELP if an F1 function key is pressed during the KEYIN instruction. The PRIOR option causes the RETURN instruction in the HELP subroutine to return to the KEYIN instruction instead of the instruction after the KEYIN instruction. Note that the PRIOR option on TRAP is only active during a KEYIN instruction.

 

Example 4:

 

*

 

 

. Display the time every 60 seconds.

.

 

 

  

...

 

  

TRAP

GETTIME IF TIMER="60"

  

...

 

  

 

 

#STATE

DIM

100

#TIME

DIM

5

GETTIME

 

 

  

CLOCK

TIME,#TIME

  

STATESAVE

#STATE

  

DISPLAY

*SETSWALL=1:1:76:80,*HON,*DIOFF,#TIME;

  

STATEREST

#STATE

  

TRAP

GETTIME IF TIMER="60"

  

RETURN

 

 

The TRAP instruction indicates that the program should CALL the subroutine GETTIME when sixty seconds has expired. The GETTIME routine retrieves the current system time. It then saves the current display state, outputs the time and then restores the display state. Finally, the routine resets the timer trap and returns.

 



PL/B Language Reference TRACE Examples TRAPCLR Examples