HELPLIB.HLB  —  RDML72  Statements  FOR Segmented Strings, Examples
    The following programs demonstrate the use of the FOR statement
    to retrieve segmented strings. Since the PERSONNEL database does
    not have any segmented strings stored, the programs first store
    three strings in the RESUME field of the RESUMES relation (for
    more information on storing segmented strings, see the help entry
    on STORE Statement with segmented strings). The programs retrieve
    the segmented strings using a nested FOR statement. The outer FOR
    statement selects a record based on EMPLOYEE_ID. The inner FOR
    statement prints each segmented string stored in RESUME for the
    selected employee.

1  –  C Example

    #include <stdio.h>
    DATABASE PERS = FILENAME "PERSONNEL";

    main()
    {
    int line;
    char *document[3];

    document[0] = "first line of resume  ";
    document[1] = "second line of resume ";
    document[2] = "last line of resume   ";

    READY PERS;
    START_TRANSACTION READ_WRITE;

    STORE R IN RESUMES USING
       strcpy (R.EMPLOYEE_ID,"12345");
       for (line = 0; line <= 2; line++)
          STORE SEG IN R.RESUME
                strcpy(SEG.VALUE,document[line]);
                SEG.LENGTH = strlen(SEG.VALUE);
          END_STORE;
    END_STORE;

    FOR R IN RESUMES WITH R.EMPLOYEE_ID = "12345"
       FOR SEG IN R.RESUME
          printf("%s\n",SEG.VALUE);
       END_FOR;
    END_FOR;

    COMMIT;
    FINISH;
    }

2  –  Pascal Example

    program segstr (input,output);
    DATABASE PERS = FILENAME 'PERSONNEL';

    type                     lines = varying [80] of char;
    var                      linecnt  : integer;
                             document : array [0..2] of lines;

    begin

    document[0] := 'first line of resume  ';
    document[1] := 'second line of resume ';
    document[2] := 'last line of resume   ';

    READY PERS;
    START_TRANSACTION READ_WRITE;

    STORE R IN RESUMES USING
       R.EMPLOYEE_ID:= '12345';
       for linecnt := 0 to 2 do
          STORE SEG IN R.RESUME
             SEG := document[linecnt];
             SEG.LENGTH := length(document[linecnt]);
          END_STORE;
    END_STORE;

    FOR R IN RESUMES WITH R.EMPLOYEE_ID = '12345'
        FOR SEG IN R.RESUME
          writeln (SEG);
        END_FOR;
    END_FOR;

    COMMIT;
    FINISH;
    end.
Close Help