HPlogo MPE XL Native Language Programmer's Guide: 900 Series HP 3000 Computer Systems > Appendix F Example Programs

Compare Character Strings from a COBOLII Program

» 

Technical documentation

Complete book in PDF
» Feedback

 » Table of Contents

 » Index

The example shows a new KSAM/3000 file built programmatically with a language attribute. This means that the keys are sorted according to the collating sequence of this language. After building the file, the program writes 15 hard-coded data records into it.

Perform a generic FFINDBYKEY with a partial key of length1 containing "E". This positions the KSAM/3000 file pointer to the first record whose key starts with "E".

After locating this record, read all subsequent records in the file sequentially and call NLKEYCOMPARE to check whether the key found is what was requested. If the result returned by NLKEYCOMPARE is 3, the program is done. There are no more records whose key starts with any kind of "E".

 1     $CONTROL USLINIT

 1.1    IDENTIFICATION DIVISION.

 1.2        PROGRAM-ID. EXAMPLE.

 1.3        AUTHOR. LORO.

 1.4    ENVIRONMENT DIVISION.

 1.5    CONFIGURATION SECTION.

 1.6    SOURCE-COMPUTER. HP3000.

 1.7    OBJECT-COMPUTER. HP3000.

 1.8    SPECIAL-NAMES.

 1.9        CONDITION-CODE IS CC.

 2      DATA DIVISION.

 2.1    WORKING-STORAGE SECTION.

 2.2       77      QUITNUM             PIC S9(4) COMP VALUE 0.

 2.3       77      LANGNUM             PIC S9(4) COMP VALUE 0.

 2.4       77      LEGTH               PIC S9(4) COMP VALUE 0.

 2.5       77      FNUM                PIC S9(4) COMP VALUE 0.

 2.6       77      RESULT              PIC S9(4) COMP VALUE 0.

 2.7       77      FOPTIONS            PIC S9(4) COMP.

 2.8       77      AOPTIONS            PIC S9(4) COMP.

 2.9       77      IND                 PIC S9(4) COMP.

 3

 3.1       01      TABLES.

 3.2         05    COLL-table          PIC X(800).

 3.3         05    KSAM-PARAM.

 3.4           10  KEY-FILE            PIC X(8) VALUE SPACES.

 3.5           10  KEY-FILE-SIZ        PIC S9(8) COMP.

 3.6           10  FILLER              PIC X(8) VALUE SPACES.

 3.7           10  LANGUAGE-NUM        PIC S9(4) COMP.

 3.8           10  FILLER              PIC X(8) VALUE SPACES.

 3.9           10  FLAGWORD            PIC S9(4) COMP.

 4             10  NUM-OF-KEYS         PIC S9(4) COMP.

 4.1           10  KEY-DESCR           PIC S9(4) COMP.

 4.2           10  KEY-LOCATION        PIC S9(4) COMP.

 4.3           10  DUPL-BLOCK          PIC S9(4) COMP.

 4.4           10  FILLER              PIC X(20).
 4.5

 4.6       01      STRINGS.

 4.7         05    GEN-KEY             PIC X(4).

 4.8         05    FILENAME            PIC X(8) VALUE SPACES.

 4.9

 5         01      ERRORS.

 5.1         05    ERR1                PIC S9(4) COMP.

 5.2         05    ERR2                PIC S9(4) COMP VALUE 0.

 5.3

 5.4       01      DATA-RECS.

 5.5         05    DATA-REC1           PIC X(50).

 5.6         05    DATA-REC2           PIC X(50).

 5.7         05    DATA-REC3           PIC X(50).

 5.8

 5.9       01      DATA-RECS-R REDEFINES DATA-RECS.

 6           05    DATA-RECORD                      OCCURS 15.

 6.1           10  FILLER              PIC X(10).

 6.2

 6.3       01      KSAM-RECORD.

 6.4         05    FILLER              PIC X(3).

 6.5         05    RECORD-KEY          PIC X(4).

 6.6         05    FILLER              PIC X(3).

 6.7

 6.8    PROCEDURE DIVISION.

 6.9    INIT-KSAM-RECORDS.

 7     * Initialize the Data Record with the data which should be

 7.1   * written to the KSAM file.

 7.2

 7.3    MOVE "014ABBeZZZ011EZqrzyx001ABCDXXX007EdCDxyx012IzzAzzz"

 7.4    TO DATA-REC1.

 7.5

 7.6    MOVE "003EaBCXXX008\\aaYZZ015iABDYZY005eLDFyxy002BBCdxxx"

 7.7    TO DATA-REC2.

 7.8

 7.9    MOVE "004eABCYYY006EabcYYY009AAAAyzz010eaxfxyz013FGHIzqs"

 8      TO DATA-REC3.

 8.1

 8.2   *  Hard-code the language used in the example program

 8.3   *  to 0 (NATIVE - 3000).

 8.4

 8.5        MOVE 0          TO LANGNUM.

 8.6

 8.7   *  Build a new KSAM file with the data file name

 8.8   *  KD000. The key file has the name KK000.

 8.9

 9     *  Set the values for KSAM parameter array.

 9.1

 9.2    MOVE "KD000   " TO FILENAME.

 9.3    MOVE "KK000   " TO KEY-FILE.

 9.4
 9.5    MOVE 1          TO NUM-OF-KEYS.

 9.6    MOVE LANGNUM    TO LANGUAGE-NUM.

 9.7    MOVE %20        TO FLAGWORD.

 9.8    MOVE 0          TO KEY-FILE-SIZ.

 9.9    MOVE %10004     TO KEY-DESCR.

10      MOVE 4          TO KEY-LOCATION.

10.1    MOVE %100024    TO DUPL-BLOCK.

10.2    MOVE %4000      TO FOPTIONS.

10.3    MOVE 5          TO AOPTIONS.

10.4

10.5    CALL INTRINSIC "FOPEN" USING FILENAME,

10.6                                 FOPTIONS,

10.7                                 AOPTIONS,

10.8                                 -10,

10.9                                 \\,

11                                   KSAM-PARAM

11.1                          GIVING FNUM.

11.2    IF CC NOT EQUAL 0

11.3       CALL INTRINSIC "PRINTFILEINFO" USING FNUM,

11.4       CALL INTRINSIC "QUIT" USING 1000.

11.5

11.6   *  Fill the hard-coded data into the KSAM file.

11.7

11.8    PERFORM FILL-IN-DATA VARYING IND FROM 1 BY 1

11.9                         UNTIL IND > 15.

12      GO TO FIND-DATA.

12.1

12.2  FILL-IN-DATA.

12.3    CALL INTRINSIC "FWRITE" USING FNUM,

12.4                                  DATA-RECORD(IND),

12.5                                  -10,

12.6                                  0.

12.7     IF CC NOT EQUAL 0

12.8        CALL INTRINSIC "PRINTFILEINFO" USING FNUM,

12.9        CALL INTRINSIC "QUIT" USING 2000.

13

13.1  FIND-DATA.

13.2   *  Perform a generic FFINDBYKEY with a

13.3   *  partial key of length 1 and value "E". The relational

13.4   *  operator will be 2 (greater or equal).

13.5   *  This FFINDBYKEY will position the KSAM pointer at the

13.6   *  first key starting with any kind of "E".

13.7

13.8    MOVE "E" TO GEN-KEY.

13.9

14      CALL INTRINSIC "FFINDBYKEY" USING FNUM,

14.1                                      GEN-KEY,

14.2                                      0,

14.3                                      1,

14.4                                      2.
14.5    IF CC NOT EQUAL 0

14.6       CALL INTRINSIC "PRINTFILEINFO" USING FNUM,

14.7       CALL INTRINSIC "QUIT" USING 3000.

14.8

14.9   *  Read the subsequent entries and check whether an

15     *  exact match occurred by using NLKEYCOMPARE.

15.1   *  When NLKEYCOMPARE returns 3 as a result, there are no

15.2   *  more keys starting with any kind of "E".

15.3   *  If an exact match was found the record is printed.

15.4

15.5    DISPLAY

15.6    "THE FOLLOWING RECORDS MATCH GEN-KEY (E) EXACTLY:"

15.7    MOVE 0     TO RESULT.

15.8    PERFORM READ-DATA UNTIL RESULT EQUAL 3.

15.9    GO TO TERMINATE-PGM.

16

16.1  READ-DATA.

16.2    CALL INTRINSIC "FREAD" USING FNUM,

16.3                                 KSAM-RECORD,

16.4                                 -10.

16.5    IF CC NOT EQUAL 0

16.6       CALL INTRINSIC "PRINTFILEINFO" USING FNUM,

16.7       CALL INTRINSIC "QUIT" USING 4000.

16.8

16.9    CALL INTRINSIC "NLKEYCOMPARE" USING  GEN-KEY,

17                                           1,

17.1                                         RECORD-KEY,

17.2                                         4,

17.3                                         RESULT,

17.4                                         LANGNUM,

17.5                                         ERRORS,

17.6                                         COLL-table.

17.7    IF ERR1 NOT EQUAL 0

17.8       COMPUTE QUITNUM = 5000 + ERR1,

17.9       CALL INTRINSIC "QUIT" USING QUITNUM.

18      IF RESULT = 0

18.1       DISPLAY KSAM-RECORD.

18.2

18.3  TERMINATE-PGM.

18.4   * Close the KSAM file and purge it.

18.5

18.6    CALL INTRINSIC "FCLOSE" USING FNUM,

18.7                                  4,

18.8                                  0.

18.9

19      STOP RUN.

Executing the program results in the following:

:RUN PROGRAM



THE FOLLOWING RECORDS MATCH GEN-KEY (E) EXACTLY:

011EZqrzyx

003EaBCXXX

007EdCDxyx



END OF PROGRAM

:
Feedback to webmaster