Software  >  OpenVMS Systems > mirror > h71000.www7.hp.com > Documentation > 731final > 6489 > hanzi

HP OpenVMS Systems Documentation

Content starts here

OpenVMS Óû§ÊÖ²á


Ç°Ò³ Ŀ¼ Ë÷Òý

14.12.2 ʹÓà /INDEX ºÍ /KEY ÏÞ¶¨´Ê

ÒªËæ»úµØ´ÓË÷Òý˳ÐòÎļþ¶ÁÈ¡¼Ç¼£¬Ê¹Óà READ ÃüÁîÏÞ¶¨´Ê /INDEX ºÍ /KEY¡£ÕâЩÏÞ¶¨´ÊÖ¸¶¨Ó¦¸ÃÕâÑù´ÓÎļþ¶ÁÈ¡¼Ç¼:ÔÚË÷ÒýÖвéÕÒÖ¸¶¨µÄ¼ü²¢·µ»ØÓëÕâ¸ö¼ü¹ØÁªµÄ¼Ç¼¡£Èç¹û²»Ö¸¶¨Ò»¸öË÷Òý£¬ÔòʹÓÃÖ÷Ë÷Òý (0)¡£

ÔÚËæ»úµØ¶ÁÈ¡Ò»¸ö¼Ç¼֮ºó£¬Ê¹Óò»´ø /KEY »ò /INDEX ÏÞ¶¨´ÊµÄ READ ÃüÁî¿ÉÒÔ˳ÐòµØ¶ÁÈ¡ÎļþµÄÊ£Óಿ·Ö¡£

14.12.3 ʹÓà /DELETE ÏÞ¶¨´Ê

Äú¿ÉÒÔʹÓôø /DELETE ÏÞ¶¨´ÊµÄ READ ÃüÁî´ÓË÷Òý˳ÐòÎļþÖÐɾ³ý¼Ç¼¡£/DELETE ÏÞ¶¨´Êʹһ¸ö¼Ç¼ÔÚ¶ÁÈ¡Ö®ºó´ÓÎļþɾ³ý¡£Ê¹Óôø /INDEX ºÍ /KEY ÏÞ¶¨´ÊµÄ /DELETE ÏÞ¶¨´Ê¿Éɾ³ýÒ»¸ö¸ø¶¨¼üÖ¸¶¨µÄ¼Ç¼¡£

ÓÐ¹Ø /DELETE¡¢/INDEX ºÍ /KEY ÏÞ¶¨´ÊµÄÏêÇ飬Çë²ÎÔÄ OpenVMS DCL Dictionary ¶Ô READ ÃüÁîµÄÃèÊö¡£

14.13 ʹÓùرÕÃüÁî

CLOSE ÃüÁî¹Ø±ÕÎļþ£¬²¢½â³ýÓÉ OPEN ÃüÁÁ¢µÄÂß¼­ÃûµÄ¸³Öµ¡£È·ÐÅÔÚÃüÁî¹ý³ÌÖÕֹ֮ǰ£¬¹Ø±ÕÔÚÃüÁî¹ý³ÌÖдò¿ªµÄËùÓÐÎļþ¡£Èç¹û²»Äܹرմò¿ªµÄÎļþ£¬ÄÇôµ±ÃüÁî¹ý³ÌÖÕֹʱÕâ¸öÎļþÈÔÈ»±£³Ö´ò¿ª£¬²¢ÇÒÒÑ·ÖÅä¸ø´ò¿ªÎļþµÄÂß¼­Ãû²»»á´Ó½ø³ÌÂß¼­Ãû±íɾ³ý¡£

ÔÚÒÔÏÂÀý×ÓÖУ¬CLOSE ÃüÁî¹Ø±ÕÎļþ STATS.DAT ²¢½â³ýÂß¼­Ãû INFILE ¸³Öµ:


$ OPEN INFILE DISK4:[MURPHY]STATS.DAT
   .
   .
   .
$ CLOSE INFILE

14.14 ÐÞ¸ÄÎļþ

±¾½ÚÃèÊöÐÞ¸ÄÎļþµÄÈýÖÖ·½·¨:

  • ¸üмǼ
  • ½¨Á¢ÐµÄÊä³öÎļþ
  • ¸½¼Ó¼Ç¼

14.14.1 ¸üмǼ

ʹÓøüз½·¨Ð޸ļǼʱ£¬Äú¿ÉÒÔ¶ÔÎļþµÄÉÙÁ¿¼Ç¼½øÐнÏС¸ü¸Ä¡£ÒòΪÕâ¸ö·½·¨²»ÔÊÐíÄú¸ü¸Ä¼Ç¼µÄ´óС»òÕßÎļþÖеļǼÊý£¬Òò´ËÖ»¶Ô¸ñʽ¼Ç¼µÄÎļþ²ÅʹÓÃËü (ÀýÈ磬ÔÚÊý¾ÝÎļþÖÐ)¡£

Òª¶ÔÎļþ½øÐнÏС¸ü¸Ä£¬Ê¹ÓÃÕâ¸ö¹ý³Ì:

²½Öè ¶¯×÷
1 ´ò¿ªÓжÁºÍд´æȡȨÎļþ¡£
2 ʹÓà READ ÃüÁîͨ¶ÁÎļþ£¬Ö±ÖÁÏëÒªÐ޸ĵļǼ¡£
3 ÐÞ¸ÄÕâ¸ö¼Ç¼¡£

ÔÚ˳ÐòÎļþÖУ¬Õâ¸ö¼Ç¼µÄÎı¾´óС±ØÐëÍêÈ«Óëԭʼ¼Ç¼һÑù¡£Èç¹ûÐ޸ļǼµÄÎı¾½Ï¶Ì£¬ÄÇôÓÿոñ¼Ç¼Ìî³ä£¬°Ñ¿Õ¸ñÌí¼Óµ½Ð޸ļǼµÄÄ©¶Ë£¬Ö±µ½ËüÓëԭʼ¼Ç¼³¤¶ÈÏàͬ¡£Èç¹ûÐ޸ļǼµÄÎı¾½Ï³¤£¬ÔòÐèÒª½¨Á¢ÐÂÎļþ¡£

4 ʹÓà WRITE/UPDATE ÃüÁî°ÑÐ޸ļǼд»ØÔ­À´µÄÎļþ¡£
5 Öظ´²½Öè 2 ÖÁ 4£¬Ö±µ½¸ü¸ÄÁË´òËã¸ü¸ÄµÄËùÓмǼ¡£
6 ʹÓà CLOSE ÃüÁî¹Ø±ÕÕâ¸öÎļþ¡£

Äú¹Ø±ÕÕâ¸öÎļþÖ®ºó£¬Ëü°üº¬Ó뿪ʼʱͬÑùµÄ°æ±¾ºÅ£¬¼´Ê¹¸ö±ð¼Ç¼Òѱ»¸ü¸Ä¡£

ÒÔÏÂÃüÁî¹ý³ÌչʾÈçºÎͨ¹ý¶ÁÈ¡ºÍ¸üиö±ð¼Ç¼¸ü¸Ä˳ÐòÎļþ:


$! Open STATS.DAT and assign it the logical name FILE
$!
$ OPEN/READ/WRITE FILE DISK4:[MURPHY]STATS.DAT
$ BEGIN_LOOP:
$! Read the next record from FILE into the symbol RECORD
$     READ/END_OF_FILE=END_LOOP FILE RECORD
$! Display the record and see if the user wants to change it
$! If yes, get the new record.  If no, repeat loop
$!
$     PROMPT:
$          WRITE SYS$OUTPUT RECORD
$          INQUIRE/NOPUNCTUATION OK "Change? Y or N [Y] "
$          IF OK .EQS. "N" THEN GOTO BEGIN_LOOP
$          INQUIRE NEW_RECORD "New record"
$! Compare the old and new records
$! If old record is shorter than new record, issue an
$! error message. If old record and new record are the
$! same length, write the record. Otherwise pad the new
$! record with spaces so it is correct length
$!
$          OLD_LEN = F$LENGTH(RECORD)
$          NEW_LEN = F$LENGTH(NEW_RECORD)
$          IF OLD_LEN .LT. NEW_LEN THEN GOTO ERROR
$          IF OLD_LEN .EQ. NEW_LEN THEN GOTO WRITE_RECORD
$          SPACES = "             "
$          PAD = F$EXTRACT(0,OLD_LEN-NEW_LEN,SPACES)
$          NEW_RECORD = NEW_RECORD + PAD
$!
$     WRITE_RECORD:
$          WRITE/UPDATE FILE NEW_RECORD
$          GOTO BEGIN_LOOP
$!
$     ERROR:
$          WRITE SYS$OUTPUT "Error -- New record is too long"
$          GOTO PROMPT
$!
$     END_LOOP:
$          CLOSE FILE
$          EXIT

ϵͳ°Ñ¼Ç¼ÏÔʾÔÚÖÕ¶ËÉÏ£¬²¢ÎÊÄú¼Ç¼ÊÇ·ñÐèÒªÐ޸ġ£Èç¹ûÄúÑ¡ÔñÐ޸ļǼ£¬¾Í´ÓÖն˶ÁȡмǼ£¬²¢ÇÒ°ÑËüµÄ³¤¶ÈÓëԭʼ¼Ç¼³¤¶È½øÐбȽϡ£Èç¹ûԭʼ¼Ç¼½Ï³¤£¬ÄÇôÌî³ä¶îÍâµÄ¿Õ¸ñʹмǼÓÐͬÑùµÄ´óС¡£Èç¹ûԭʼ¼Ç¼½Ï¶Ì£¬ÔòϵͳÏÔʾ³ö´íÏûÏ¢²¢ÇÒÔÙ´ÎÌáʾÊäÈëмǼ¡£

14.14.2 ½¨Á¢ÐµÄÊä³öÎļþ

Òª¶ÔÎļþ½øÐдóµÄ¸ü¸Ä£¬´ò¿ªÓÃÓÚ¶Á´æÈ¡µÄÎļþ²¢ÇÒ´ò¿ªÓÃÓÚд´æÈ¡µÄÐÂÎļþ¡£ÒòΪÊǽ¨Á¢ÐµÄÊä³öÎļþ£¬Òò´Ë¿ÉÒÔÐ޸ļǼµÄ´óС¡¢Ìí¼Ó¼Ç¼¡¢É¾³ý¼Ç¼»ò²åÈë¼Ç¼¡£

OPEN/WRITE ÃüÁî´ò¿ªÐÂÎļþÓÃÓÚд´æÈ¡¡£ÐÂÎļþ¿ÉÒÔÓÐÓëԭʼÎļþͬÑùµÄÃû³Æ£¬²¢ÇÒ°æ±¾ºÅ±È¾ÉÎļþµÄ°æ±¾ºÅ´ó 1¡£

×¢Òâ

Ҫȷ±£´ò¿ªÕýÈ·µÄÎļþÓÃÓÚ¶ÁÈ¡£¬ÔÚ´ò¿ªÓÃÓÚд´æÈ¡µÄа汾֮ǰ£¬±ØÐë´ò¿ªÓÃÓÚ¶Á´æÈ¡µÄÏÖÓÐÎļþ¡£

Òª½¨Á¢¿ÉÒÔÐ޸ĵÄÎļþ£¬Ê¹ÓÃÒÔϹý³Ì:

²½Öè ¶¯×÷
1 ´ò¿ªÓÃÓÚ¶Á´æÈ¡µÄÎļþ¡£

ÕâÊÇÊäÈëÎļþ£¬Ò²ÊÇÄúÐ޸ĵÄÎļþ¡£

2 ´ò¿ªÒ»¸öÓÃÓÚд´æÈ¡µÄÐÂÎļþ¡£

ÕâÊÇÊä³öÎļþ£¬Ò²ÊÇÄú½¨Á¢µÄÎļþ¡£Èç¹û¸ø³öµÄÊä³öÎļþÓëÊäÈëÎļþͬÃû£¬ÄÇôÊä³öÎļþµÄ°æ±¾ºÅ½«ÓбÈÊäÈëÎļþ´ó 1 ¡£

3 ʹÓà READ ÃüÁî´ÓÐ޸ĵÄÎļþ¶Áȡÿ¸ö¼Ç¼¡£

µ±Äú´ÓԭʼÎļþ¶Áȡÿ¸ö¼Ç¼ʱ£¬¾ö¶¨ÈçºÎ´¦ÀíÕâ¸ö¼Ç¼¡£

4 ¼ÌÐø¶ÁÈ¡ºÍ´¦Àí¼Ç¼£¬Ö±µ½Íê³É¡£
5 ʹÓà CLOSE ÃüÁî¹Ø±ÕÊäÈëÎļþºÍÊä³öÎļþ¡£

ÔÚÒÔϱí¸ñÖУ¬·ûºÅ RECORD °üº¬´ÓԭʼÎļþ¶ÁÈ¡µÄ¼Ç¼:

Èç¹û¼Ç¼ÊÇ ÄÇô
²»¸ü¸Ä °ÑͬÑùµÄ·ûºÅдÈëÐÂÎļþ¡£
¸ü¸Ä ʹÓà INQUIRE ÃüÁî°Ñ²»Í¬µÄ¼Ç¼¶ÁÈëÕâ¸ö·ûºÅ£¬È»ºó°ÑÕâ¸öÐ޸ķûºÅдÈëÐÂÎļþ¡£
ɾ³ý ²»°ÑÕâ¸ö·ûºÅдÈëÐÂÎļþ¡£
²åÈë ʹÓÃÒ»¸öÑ­»·°Ñ¼Ç¼¶ÁÈëÕâ¸ö·ûºÅ£¬È»ºó°ÑÕâ¸ö·ûºÅдÈëÐÂÎļþ¡£

Àý×Ó: Ð޸ļǼ

  • ÔÚÒÔÏÂÀý×ÓÖУ¬·ûºÅ NEW_FILE ±»Ð´ÈëÐÂÎļþ:


    $ ! No change
    $ WRITE NEW_FILE RECORD
    
  • ÔÚÒÔÏÂÀý×ÓÖУ¬INQUIRE ÃüÁîÓÃÀ´°ÑÒ»¸öÒÑÐ޸ĵķûºÅдÈëÐÂÎļþ:


    $ ! Change
    $ INQUIRE NEW_RECORD "New record"
    $ WRITE NEW_FILE NEW_RECORD
    
  • ÔÚÒÔÏÂÀý×ÓÖУ¬Ê¹ÓÃÒ»¸öÑ­»·°Ñ·ûºÅдÈëÐÂÎļþ:


    $ ! Insertion
    $LOOP:
    $ !Get new records to insert
    $ INQUIRE NEW_RECORD "New record"
    $ IF RECORD .EQS. "" THEN GOTO END_LOOP
    $ WRITE NEW_FILE NEW_RECORD
    $ GOTO LOOP
    $END_LOOP:
    

Àý×Ó: ½¨Á¢Êä³öÎļþ

ÒÔÏÂÀý×Óչʾһ¸öÃüÁî¹ý³Ì£¬Ëü´ÓÊäÈëÎļþ¶ÁÈ¡¼Ç¼£¬´¦ÀíÕâ¸ö¼Ç¼£¬È»ºó°ÑÕâ¸ö¼Ç¼¸´ÖƵ½Ò»¸öÊä³öÎļþ:


$! Open STATS.DAT for reading and assign it
$! the logical name INFILE
$! Open a new version of STATS.DAT for writing
$! and assign it the logical name OUTFILE
$!
$ OPEN/READ INFILE DISK4:[MURPHY]STATS.DAT
$ OPEN/WRITE OUTFILE DISK4:[MURPHY]STATS.DAT
$!
$ BEGIN_LOOP:
$! Read the next record from INFILE into the symbol RECORD
$!
$     READ/END_OF_FILE=END_LOOP INFILE RECORD
$! Display the record and see if the user wants to change it
$! If yes, get the new record
$! If no, write record directly to OUTFILE
$!
$     PROMPT:
$          WRITE SYS$OUTPUT RECORD
$          INQUIRE/NOPUNCTUATION OK "Change? Y or N [Y] "
$          IF OK .EQS. "N" THEN GOTO WRITE_RECORD
$          INQUIRE RECORD "New record"
$!
$     WRITE_RECORD:
$          WRITE OUTFILE RECORD
$          GOTO BEGIN_LOOP
$!
$! Close input and output files
$     END_LOOP:
$          CLOSE INFILE
$          CLOSE OUTFILE
$          EXIT

14.14.3 ΪÎļþ¸½¼Ó¼Ç¼

ʹÓÃÒÔϹý³Ì (OPEN/APPEND ÃüÁî) °Ñ¼Ç¼¸½¼Óµ½ÏÖÓÐÎļþµÄÄ©¶Ë:

²½Öè ¶¯×÷
1 ʹÓôø /APPEND ÏÞ¶¨´ÊµÄ OPEN ÃüÁî°Ñ¼Ç¼ָÕ붨λÔÚÎļþβ¡£

/APPEND ÏÞ¶¨´Ê²»½¨Á¢ÎļþµÄа汾¡£

2 ʹÓà WRITE ÃüÁîдÈëеÄÊý¾Ý¼Ç¼¡£
3 ¼ÌÐøÌí¼Ó¼Ç¼£¬Ö±µ½Íê³É¡£
4 ʹÓà CLOSE ÃüÁî¹Ø±ÕÕâ¸öÎļþ¡£

ÒÔÏÂÃüÁî¹ý³Ì°Ñ¼Ç¼¸½¼Óµ½Îļþ STATS.DAT µÄÄ©¶Ë:


$! Open STATS.DAT to append files and assign
$! it the logical name FILE
$!
$ OPEN/APPEND FILE DISK4:[MURPHY]STATS.DAT
$!
$ BEGIN_LOOP:
$! Obtain record to be appended and place this
$! record in the symbol RECORD
$!
$     PROMPT:
$          INQUIRE RECORD -
           "Enter new record (press RET to quit) "
$          IF RECORD .EQS. "" THEN GOTO END_LOOP
$! Write record to FILE
$!
$          WRITE FILE RECORD
$          GOTO BEGIN_LOOP
$!
$! Close FILE and exit
$!
$     END_LOOP:
$          CLOSE FILE
$          EXIT

14.15 ´¦ÀíÎļþ I/O ³ö´í

¶Ô OPEN¡¢READ »ò WRITE ÃüÁîʹÓà /ERROR ÏÞ¶¨´Ê¿ÉÒÖÖÆϵͳ³ö´íÏûÏ¢£¬²¢°Ñ¿ØÖÆ´«µÝµ½Ö¸¶¨µÄ±êºÅ¡£Èç¹ûÔÚÊäÈë»òÊä³ö²Ù×÷ÆÚ¼ä³ö´í£¬ÄÇô /ERROR ÏÞ¶¨´ÊÈ¡´úËùÓÐÆäËû³ö´í¿ØÖÆ»úÖÆ (³ýÁËÔÚ READ ÃüÁîÉ쵀 /END_OF_FILE ÏÞ¶¨´ÊÖ®Íâ)¡£

ÒÔÏÂÀý×Ó¶Ô OPEN ÃüÁîʹÓà /ERROR ÏÞ¶¨´Ê:


$ OPEN/READ/ERROR=CHECK FILE CONTINGEN.DOC
   .
   .
   .
$ CHECK:
$  WRITE SYS$OUTPUT "Error opening file"

OPEN ÃüÁîÇëÇó´ò¿ªÎļþ CONTINGEN.DOC ÓÃÓÚ¶ÁÈ¡¡£Èç¹û²»ÄÜ´ò¿ªÕâ¸öÎļþ (ÀýÈ磬Õâ¸öÎļþ²»´æÔÚ)£¬ÄÇô OPEN ÃüÁî·µ»ØÒ»¸ö³ö´íÌõ¼þ£¬²¢°Ñ¿ØÖÆ´«µÝµ½ CHECK ±êºÅ¡£

/ERROR ÏÞ¶¨´ÊÖ¸¶¨µÄ³ö´í·¾¶È¡´úÆäÃüÁ½¨Á¢µÄµ±Ç° ON Ìõ¼þ¡£Èç¹û³ö´í²¢ÇÒÄ¿±ê±êºÅ±»³É¹¦µØ¸ø³ö¿ØÖÆ£¬ÄÇô±£ÁôµÄÈ«¾Ö·ûºÅ $STATUS ±£³Ö³ö´í´úÂë¡£¿ÉÒÔÔÚ³ö´í´¦ÀíÀýÐгÌÐòÖÐʹÓà F$MESSAGE ´Ê·¨º¯ÊýÀ´ÏÔʾ $STATUS ÖеÄÏûÏ¢¡£

ÔÚÒÔÏÂÀý×ÓÖУ¬´Ê·¨º¯Êý F$MESSAGE ÓÃÀ´ÏÔʾ F$STATUS ´Ê»ãµÄÄÚÈÝ:


$ OPEN/READ/ERROR=CHECK FILE 'P1'
   .
   .
   .
$ CHECK:
$  ERR_MESSAGE = F$MESSAGE($STATUS)
$  WRITE SYS$OUTPUT "Error opening file: ",P1
$  WRITE SYS$OUTPUT ERR_MESSAGE
   .
   .
   .

14.15.1 ĬÈϳö´í¶¯×÷

ʹÓà OPEN¡¢READ¡¢WRITE »ò CLOSE ÃüÁîʱ£¬Èç¹û³ö´í£¬²¢ÇÒûÓÐÖ¸¶¨³ö´í¶¯×÷£¬ÄÇô²ÉÈ¡µ±Ç°µÄ ON ÃüÁ×÷¡£

READ ÃüÁî½ÓÊÕÒ»ÌõÎļþ½áÊøÏûϢʱ£¬Æä³ö´í¶¯×÷È·¶¨ÈçÏÂ:

  • Èç¹ûʹÓà /END_OF_FILE ÏÞ¶¨´Ê£¬¿ØÖƱ»´«µÝµ½Ö¸¶¨µÄ±êºÅ¡£
  • Èç¹ûûÓÐʹÓà /END_OF_FILE ÏÞ¶¨´Ê£¬¿ØÖƾͱ»´«µÝµ½ /ERROR ÏÞ¶¨´ÊÖ¸¶¨µÄ±êºÅ¡£
  • Èç¹ûûÓÐÖ¸¶¨ÈÎÒâÒ»¸öÏÞ¶¨´Ê (/END_OF_FILE »ò /ERROR)£¬ÄÇô²ÉÈ¡µ±Ç°µÄ ON ÃüÁ×÷¡£

14.16 ¿ØÖÆÖ´ÐÐÁ÷µÄ¼¼Êõ

ÃüÁî¹ý³ÌµÄÕý³£Ö´ÐÐÁ÷ÊÇ˳ÐòµÄ: ¹ý³ÌÖеÄÃüÁîÒÀ´ÎÖ´ÐУ¬Ö±µ½Îļþβ¡£È»¶ø£¬ÄúÒ²¿ÉÒÔ¿ØÖÆijЩÓï¾äÊÇ·ñÖ´ÐУ¬»òÕß¹ý³ÌÔÚʲôÌõ¼þÏÂÓ¦¸Ã¼ÌÐøÖ´ÐС£

ÒÔϼ¸½ÚÂÛÊö:

  • ¿ÉÒÔÓÃÀ´¿ØÖÆ»ò¸Ä±äÖ´ÐÐÁ÷µÄ DCL ÃüÁî:
    • IF£¬THEN£¬ELSE
    • GOTO
    • GOSUB
    • CALL
  • ʹÓÃÃüÁî¿é
  • ±àд Case Óï¾ä
  • ±àдѭ»·

14.16.1 ʹÓà IF ÃüÁî

IF ÃüÁî²âÊÔ±í´ïʽµÄÖµ£¬µ±±í´ïʽµÄ½á¹ûΪÕæʱִÐÐÒ»¸öÃüÁî»òÒ»¿éÃüÁî¡£µ±±í´ïʽµÄ½á¹ûΪ¼Ùʱ£¬·¢ÉúÒÔÏÂÇé¿öÖ®Ò»:

  • µ±Ò»¸öÃüÁî¸úËæ THEN ÃüÁîʱ£¬¾Í²»Ö´ÐÐËü£¬¶øÖ´ÐкóÃæµÄÃüÁî¡£
  • µ±Ò»¿éÃüÁî¸úËæ THEN ÃüÁî¶øûÓÐÖ¸¶¨ ELSE ÃüÁîʱ£¬Õâ¸öÃüÁî¾ÍÁ¢¼´Ö´ÐкóÃæµÄ ENDIF ÃüÁî¡£
  • Ö¸¶¨ ELSE ÃüÁîʱ£¬¾ÍÖ´ÐÐÕâ¸öÃüÁî»ò¸úËæ ELSE ÃüÁîµÄÒ»¿éÃüÁî¡£

DCL Ϊ IF ÃüÁîÌṩÁ½¸ö²»Í¬¸ñʽ¡£µ±ÎªÕâ¸ö IF ÃüÁîÖ¸¶¨µÄ±í´ïʽΪÕæʱ£¬µÚÒ»¸ö¸ñʽִÐе¥¸öÃüÁÈçµÚ 13 ÕÂËùÊö¡£

DCL Ò²Ìṩһ¸ö¿é½á¹¹ IF ¸ñʽ¡£Èç¹ûÖ¸¶¨µÄ±í´ïʽΪÕ棬ÄÇô¿é½á¹¹ IF ÃüÁîÖ´ÐÐÒ»¸öÒÔÉÏÃüÁ²¢ÇÒ½ÓÊÜ¿ÉÑ¡µÄELSE Óï¾ä£¬Èç¹û±í´ïʽΪ¼ÙËüÖ´ÐÐÒ»¸ö»ò¶à¸öÃüÁî¡£

14.16.2 ʹÓà THEN ÃüÁî

µ±±í´ïʽΪÕæʱҪִÐÐÒ»¸öÒÔÉÏÃüÁ¿ÉÖ¸¶¨ THEN ÃüÁîΪһ¸ö¶¯´Ê (Ç°Ãæ¼ÓÉÏÃÀÔª·ûµÄ DCL ÃüÁî)£¬²¢ÇÒÓà ENDIF Óï¾äÖÕÖ¹×÷Ϊ½á¹ûµÄ¿é½á¹¹Óï¾ä¡£

ÔÚÒÔÏÂÀý×ÓÖУ¬THEN Óï¾äÓÃ×÷Ò»¸ö¶¯´Ê:


$ IF expression
$   THEN
$       command
$       command
   .
   .
   .
$ ENDIF

14.16.3 ʹÓà ELSE ÃüÁî

µ±±í´ïʽΪ¼ÙʱҪִÐÐÒ»¸ö»ò¶à¸öÃüÁ¿ÉÖ¸¶¨ ELSE Óï¾äΪһ¸ö¶¯´Ê£¬²¢ÇÒÓà ENDIF Óï¾äÖÕÖ¹×÷Ϊ½á¹ûµÄ¿é½á¹¹Óï¾ä¡£

ÔÚÒÔÏÂÀý×ÓÖУ¬ELSE ÃüÁîÓÃ×÷Ò»¸ö¶¯´Ê:


$ IF expression
$   THEN
$       command
$       command
   .
   .
   .
$   ELSE
$       command
$       command
   .
   .
   .
$ ENDIF

14.16.4 ʹÓÃÃüÁî¿é

ÃüÁî¿é¿ÉÒÔ°´¼¸ÖÖ·½·¨Ö´ÐУ¬ÕâÈ¡¾öÓÚÄúÊÇ°ÑÕâЩÃüÁî·ÅÔÚͬһÃüÁî¹ý³Ì£¬»òÊÇ°ÑËüÃÇ·ÅÈëÁíÒ»¸öÃüÁî¹ý³Ì²¢ÔÚÄÇÀïÖ´ÐС£ÆäÖ¸ÒýÈçÏÂ:

  • Èç¹û°ÑÕâЩÃüÁî·ÅÔÚͬһÃüÁî¹ý³ÌÖУ¬ÄÇô°ÑËüÃÇ·ÅÔÚ THEN Óï¾äÖ®ºó¡£ÀýÈç:


    $ IF condition
    $ THEN  command
            command
       .
       .
       .
    $ ENDIF
    
  • Èç¹û°ÑÕâЩÃüÁî·ÅÈëÒ»¸öµ¥¶ÀµÄ¹ý³Ì£¬ÄÇôµ÷ÓÃÕâ¸öÃüÁî¹ý³ÌÒÔ×÷Ϊ THEN Óï¾äµÄÒ»²¿·Ö¡£ÀýÈç:


    $ IF condition
    $ THEN @command_procedure
    $ ELSE command
    $      command
    $ ENDIF
    
  • ¿ÉÒÔ¼ÌÐøÖ¸¶¨·Ç¿é½á¹¹µÄ IF ¸ñʽ£¬²¢ÇÒµ±Âú×ãÖ¸¶¨µÄÌõ¼þʱ°Ñ¿ØÖÆÁ÷Ö¸Òýµ½±êºÅµÄÇøÓò¡£ÀýÈç:


    $ IF not condition THEN GOTO END_LABEL
       .
       .
       .
    $END_LABEL:
    

µ± IF ±í´ïʽµÄ½á¹ûΪÕæʱ£¬Äú¿ÉÒÔÖ´ÐÐÔÚ THEN ÃüÁîÖ®ºóµÄÒ»¿éÃüÁʹÓÃÒ»¿éÃüÁîʱ£¬°Ñ THEN ÃüÁî×÷ΪµÚÒ»¸öÃüÁî·ÅÔÚ¸úËæ IF ÃüÁîµÄÃüÁîÐÐÉÏ¡£

ÔÚÒÔÏÂÀý×ÓÖУ¬µ± F$MODE µÈÓÚ "INTERACTIVE" ʱ£¬Ö´ÐÐÁ½¸ö SET TERMINAL ÃüÁî²¢ÇÒ°ÑÕâ¸ö¹ý³ÌµÄ¿ØÖÆ´«µÝ¸ø±êºÅ PROCEED¡£µ± F$MODE ²»µÈÓÚ "INTERACTIVE" ʱ£¬Í˳öÕâ¸ö¹ý³Ì¡£


$ IF F$MODE () .EQS. "INTERACTIVE"
$ THEN
$    SET TERMINAL/DEVICE=VT320
$    SET TERMINAL/WIDTH=132
$    GOTO PROCEED
$ ENDIF
$ EXIT
$PROCEED:

ÒÔÏÂÀý×Ó˵Ã÷ÈçºÎʹÓà IF ÃüÁîºÍ ELSE ÃüÁîÁ¬ÔÚÒ»ÆðµÄÃüÁî¿é:


$ INQUIRE DEV "Device to check"
$ IF F$GETDVI(DEV, "EXISTS")
$ THEN
$    WRITE SYS$OUTPUT "The device exists."
$    SHOW DEVICE 'DEV'
$    SET DEVICE/ERROR_LOGGING 'DEV'
$ ELSE
$     WRITE SYS$OUTPUT "The device does not exist."
$    WRITE SYS$OUTPUT "Error logging has not been enabled."
$ ENDIF
$ EXIT

µ±Ìõ¼þΪÕæʱ£¬Õâ¸ö¹ý³Ì°ÑÒ»ÌõÏûϢдÈë SYS$OUTPUT ²¢Ö´ÐÐ SHOW DEVICE ºÍ SET DEVICE ÃüÁî¡£µ±Ìõ¼þ²»ÎªÕæʱ£¬Õâ¸ö¹ý³Ì°ÑÁ½ÌõÏûϢдÈë SYS$OUTPUT¡£

ÄúʹÓà IF-THEN-ELSE ÓïÑԽṹʱ£¬×ñÑ­ÒÔÏÂÏÞÖÆ:

  • IF Óï¾äµÄǶÌ×¼¶²»Äܳ¬¹ý 15 ¼¶¡£
  • ʹÓà ELSE »ò ENDIF Óï¾äÖÕÖ¹ THEN Óï¾ä¿ªÊ¼µÄÃüÁî¿é¡£
  • ʹÓà ENDIF Óï¾äÖÕÖ¹ ELSE Óï¾ä¿ªÊ¼µÄÃüÁî¿é¡£
  • ÔÚ IF Óï¾äÖ®ºóʹÓà THEN Óï¾ä×÷ΪµÚÒ»¸ö¿ÉÖ´ÐÐÓï¾ä¡£
  • ²»ÒªÔÚ°üº¬ THEN »ò ELSE Óï¾äµÄÃüÁîÐÐÉÏÖ¸¶¨±êºÅ¡£È»¶ø£¬Äú¿ÉÒÔÔÚ°üº¬ ENDIF Óï¾äµÄÃüÁîÐÐÉÏÖ¸¶¨±êºÅ¡£³ÌÐò¿ÉÒÔÔÚµ±Ç°ÃüÁî¿éÄÚ·ÖÖ§£¬µ«ÊDz»½¨Òé·ÖÖ§µ½ÁíÒ»¸öÃüÁî¿éµÄÖм䡣

Õæ±í´ïʽ

Õâ¸ö¸úËæ IF ÃüÁîµÄ±í´ïʽ¿ÉÒÔ°üÀ¨Ò»¸ö»ò¶à¸öÊý×Ö³£Êý¡¢´®ÎÄ×Ö¡¢·ûºÅÃû»ò´Ê·¨º¯Êý£¬²¢ÇÒÓÃÂß¼­¡¢ËãÊõ»ò×Ö·û´®ÔËËã·û·Ö¸ô¡£Èç¹ûÒ»¸ö±í´ïʽÓÐÒÔÏÂÖµÖ®Ò»£¬Ëü¾ÍΪÕæ:

  • ÆæÊýÖµ
  • ´Ó×Öĸ Y¡¢y¡¢T »ò t ¿ªÊ¼µÄ×Ö·û´®Öµ
  • °üº¬¿ÉÐγÉÆæÊýÖµµÄÊý×ÖµÄ×Ö·û´®Öµ (ÀýÈ磬×Ö·û´® "27")

¼Ù±í´ïʽ

Èç¹ûÒ»¸ö±í´ïʽÓÐÒÔÏÂÖµÖ®Ò»£¬Ëü¾ÍΪ¼Ù:

  • żÊýÖµ
  • ²»ÊÇ´Ó×Öĸ Y¡¢y¡¢T »ò t ¿ªÊ¼µÄ×Ö·û´®Öµ
  • °üº¬¿ÉÐγÉżÊýÖµµÄÊý×ÖµÄ×Ö·û´®Öµ (ÀýÈ磬×Ö·û´® "28")

±àд±í´ïʽ

Ϊ IF ÃüÁî±àд±í´ïʽʱ£¬¼á³ÖÒÔϹæÔò:

  • ÔÚ IF Óï¾äÖÐʹÓ÷ûºÅʱ£¬ËüÃǵÄÖµ±»×Ô¶¯Ìæ»»¡£²»±ØʹÓÃÊ¡ÂԺŠ(') ×÷ΪÌæ»»ÔËËã·û£¬³ý·ÇÐèҪǿÖƵü´ú·­Òë¡£
  • ×Ö·û´®±È½ÏÔËËã·û½áÊøÓÚ×Öĸ S¡£ÀýÈ磬ÔËËã·û .EQS.¡¢.LTS. ºÍ .GTS. ÓÃÓÚ×Ö·û´®±È½Ï¡£Ïà·´£¬ÔËËã·û .EQ.¡¢.LT. ºÍ .GT. ÓÃÓÚÕûÊý±È½Ï¡£
  • µ±²âÊԲ鿴Á½¸ö×Ö·û´®ÊÇ·ñÏàͬʱ£¬DCL ²éÕÒµÄÆ¥Åä×Ö·û´®±ØÐëʹÓÃͬÑùµÄ×Öĸ´óСдºÍ´ÎÐò¡£¼´ÊÇ˵£¬×Ö·û´® "COPY" ²»µÈÓÚ×Ö·û´® "copy" »ò×Ö·û´® "CoPy"¡£

ÒÔÏÂÀý×Ó˵Ã÷¿ÉÒÔÓë IF ÃüÁîÒ»ÆðʹÓõıí´ïʽ¡£¶ÔÓÚÆäËûÀý×Ó£¬Çë²ÎÔÄ OpenVMS DCL Dictionary¶Ô IF ÃüÁîµÄÃèÊö¡£

µÚÒ»¸öÀý×ÓʹÓÃÒ»¸öÂß¼­ÔËËã·û£¬²¢ÇÒÖ»Ö´ÐиúËæ THEN Óï¾äµÄÒ»¸öÃüÁî¡£µ±·ûºÅ CONT ²»ÎªÕæʱ£¬Í˳öÕâ¸ö¹ý³Ì¡£


$ INQUIRE CONT "Do you want to continue [Y/N]"
$ IF .NOT. CONT THEN EXIT
   .
   .
   .

ÒÔÏÂÀý×ÓÔÚ IF ±í´ïʽÖÐʹÓÃÒ»¸ö·ûºÅºÍÒ»¸ö±êºÅ:


$ INQUIRE CHANGE "Do you want to change the record [Y/N]"
$ IF CHANGE THEN GOTO GET_CHANGE
   .
   .
   .
$ GET_CHANGE:
   .
   .
   .

µ±·ûºÅ CHANGE ΪÕæʱ£¬¹ý³Ì°Ñ¿ØÖÆ´«µÝµ½±êºÅ GET_CHANGE¡£·ñÔò£¬¹ý³ÌÖ´ÐиúËæ IF ÃüÁîµÄÃüÁî¡£

ÏÂÒ»¸öÀý×Ó˵Ã÷Á½¸ö²»Í¬µÄ IF ÃüÁî:


$ COUNT = 0
$ LOOP:
$    COUNT = COUNT + 1
$    IF COUNT .EQ. 9 THEN EXIT
$    IF P'COUNT' .EQS. "" THEN EXIT
   .
   .
   .
$ GOTO LOOP

µÚÒ»¸ö IF ÃüÁî±È½ÏÁ½¸öÕûÊý£»µÚ¶þ¸ö IF ÃüÁî±È½ÏÁ½¸ö×Ö·û´®¡£×¢Ò⣬.EQ. ÔËËã·ûÓÃÓÚÕûÊý±È½Ï£¬¶ø .EQS. ÔËËã·ûÓÃÓÚ×Ö·û´®±È½Ï¡£

Ê×ÏÈ£¬COUNT ÖµÓëÕûÊý 9 ½øÐбȽϡ£µ±ÕâÁ½¸öÖµÏàͬʱ£¬¾ÍÍ˳öÕâ¸ö¹ý³Ì£»µ±ÕâÁ½¸öÖµ²»Ïàͬʱ£¬¹ý³Ì¼ÌÐø¡£´¦Àí°Ë¸ö²ÎÊý (ÔÊÐíµÄ×î´óÊý) ºóÑ­»·ÖÕÖ¹¡£

ÔÚµÚ¶þ¸ö IF ±í´ïʽÖУ¬·ûºÅ P'COUNT' µÄ×Ö·û´®ÖµÓë¿Õ´®½øÐбȽϲ鿴Õâ¸ö·ûºÅÊÇ·ñÊÇ䶨ÒåµÄ¡£×¢Ò⣬±ØÐëʹÓÃÊ¡ÂÔºÅÇ¿ÖƶԷûºÅ COUNT ½øÐеü´úÌæ»»¡£ÀýÈ磬µ± COUNT ÊÇ 2 ʱ£¬µÚÒ»¸ö·­ÒëµÄ½á¹ûÊÇ P2¡£È»ºó£¬P2 µÄֵʹÓÃÔÚ×Ö·û´®±È½ÏÖС£

µ± IF ±í´ïʽµÄ½á¹ûΪÕæʱ£¬ÄúÒ²¿ÉÒÔÖ´ÐÐÒ»¸öµ¥¶ÀµÄÃüÁî¹ý³Ì¡£ÒÔÏÂÀý×Óµ± IF ±í´ïʽµÄ½á¹ûΪÕæʱ£¬Ö´ÐÐÃüÁî¹ý³Ì EXIT_ROUTINE.COM:


$ GET_COMMAND_LOOP:
$    INQUIRE COMMAND -
     "Enter command (DELETE, DIRECTORY, EXIT, PRINT, PURGE, TYPE)"
$    IF COMMAND .EQS. "EXIT" THEN @EXIT_ROUTINE


Ç°Ò³ ºóÒ³ Ŀ¼ Ë÷Òý