× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.


  • Subject: Reading files with MI (speed)
  • From: Leif Svalgaard <l.svalgaard@xxxxxxxxxxxxx>
  • Date: Mon, 22 Nov 1999 14:28:00 -0600

Here is a simple program that opens a file TESTFILE created
with CRTPF FILE(TESTFILE) RCDLEN(132) SIZE(*NOMAX) LVLCHK(*NO)
and writes 100,000 records, then closes the file and opens it again
and reads the 100,000 records back. A message is sent to your
message queue after writing and after reading telling you how many
seconds it took. On my little 150 box the timings were as follows
Write 100,000   72 secs
Read 100,000   55 secs 
you can decrease the reading time by override of the number
of records to read at a time:
OVRDBF FILE(TESTFILE) NBRRCDS(10000)
It doesn't make much difference (2 seconds).

You can try to do the same in RPG and/or C so we can
compare timings.

DCL SYSPTR .SEPT(6440) BAS(..SEPT);
DCL DD PCO CHAR(16) BASPCO;
   DCL SPCPTR ..SEPT DEF(PCO) POS( 1);

DCL CON CLOSE  BIN(2) INIT(11);
DCL CON OPEN   BIN(2) INIT(12);
DCL CON *LIBL  BIN(2) INIT(-75);
DCL CON *FIRST BIN(2) INIT(-71);
DCL CON LIB-ID BIN(2) INIT(72);
DCL CON MBR-ID BIN(2) INIT(73);

/* TEST FILE CONTROL BLOCK */
DCL SPCPTR .TFCB INIT(TFCB);
DCL DD      TFCB CHAR(214) BDRY(16);
    DCL SPCPTR .TFCB-ODP               DEF(TFCB) POS(  1);
    DCL SPCPTR .TFCB-INBUF             DEF(TFCB) POS( 17);
    DCL SPCPTR .TFCB-OUTBUF            DEF(TFCB) POS( 33);
    DCL SPCPTR .TFCB-OPEN-FEEDBACK     DEF(TFCB) POS( 49);
    DCL SPCPTR .TFCB-IO-FEEDBACK       DEF(TFCB) POS( 65);
    DCL SPCPTR .TFCB-NEXT-UFCB         DEF(TFCB) POS( 81);

    DCL DD *                  CHAR(32) DEF(TFCB) POS( 97);
    DCL DD TFCB-FILE          CHAR(10) DEF(TFCB) POS(129);
    DCL DD TFCB-LIB-ID        BIN(2)   DEF(TFCB) POS(139);
    DCL DD TFCB-LIBRARY       CHAR(10) DEF(TFCB) POS(141);
    DCL DD TFCB-MBR-ID        BIN(2)   DEF(TFCB) POS(151);
    DCL DD TFCB-MEMBER        CHAR(10) DEF(TFCB) POS(153);

    DCL DD TFCB-DEVICE-NAME   CHAR(10) DEF(TFCB) POS(163);
    DCL DD TFCB-DEVICE-INDEX  BIN(2)   DEF(TFCB) POS(173);

    DCL DD TFCB-FLAGS-1       CHAR(1)  DEF(TFCB) POS(175) INIT(X'80');
    DCL DD TFCB-FLAGS-2       CHAR(1)  DEF(TFCB) POS(176) INIT(X'10');

    DCL DD TFCB-REL-VERSION   CHAR(4)  DEF(TFCB) POS(177);
    DCL DD TFCB-INV-MK-COUNT  BIN (4)  DEF(TFCB) POS(181);
    DCL DD TFCB-MORE-FLAGS    CHAR(1)  DEF(TFCB) POS(185);
    DCL DD *                  CHAR(23) DEF(TFCB) POS(186);

    DCL DD TFCB-RECORD-ID     BIN (2)  DEF(TFCB) POS(209) INIT(1);
    DCL DD TFCB-RECORD-LENGTH BIN (2)  DEF(TFCB) POS(211) INIT(132);
    DCL DD TFCB-NO-MORE-PARMS BIN (2)  DEF(TFCB) POS(213) INIT(32767);

DCL OL  OPEN-T(.TFCB);
DCL OL CLOSE-T(.TFCB);

DCL SPCPTR .NULL;
DCL SPCPTR .PUT-OPT-T INIT(PUT-OPT-T);
DCL DD      PUT-OPT-T BIN(4) INIT(H'10000005');
DCL OL PUT-T(.TFCB, .PUT-OPT-T, .NULL);
DCL DD T-PUT BIN(2);

DCL SPCPTR .ODP-ROOT;
DCL SPC     ODP-ROOT  BAS(.ODP-ROOT);
    DCL DD ODP-STATUS       CHAR(4) DIR;
    DCL DD ODP-DEV-LENGTH   BIN(4)  DIR;
    DCL DD ODP-OPEN-SIZE    BIN(4)  DIR;
    DCL DD ODP.OPEN-FEEDBCK BIN(4)  DIR;
    DCL DD ODP.DEV-NAMELIST BIN(4)  DIR;
    DCL DD ODP....MORE....  CHAR(1) DIR;

DCL SPCPTR .DEVICE-CONTROL-BLOCK;
DCL SPC     DEVICE-CONTROL-BLOCK  BAS(.DEVICE-CONTROL-BLOCK);
    DCL DD  DCB-MAX-NBR-OF-DEVICES   BIN( 2) DIR;
    DCL DD  DCB-DEVICES-IN-THE-ODP   BIN( 2) DIR;
    DCL DD  DCB-DEVICE-NAME         CHAR(10) DIR;
    DCL DD  DCB-OFFSET-TO-FM-WORK    BIN( 4) DIR;
    DCL DD  DCB-LENGTH-OF-FM-WORK    BIN( 4) DIR;
    DCL DD  DCB-INDEX-FOR-LUD-PTR    BIN( 2) DIR;
    DCL DD  DCB-GET                  BIN( 2) DIR;
    DCL DD  DCB-GET-BY-RRN           BIN( 2) DIR;
    DCL DD  DCB-GET-BY-KEY           BIN( 2) DIR;
    DCL DD  *                        BIN( 2) DIR;
    DCL DD  DCB-PUT                  BIN( 2) DIR;
    DCL DD  DCB-PUT-GET              BIN( 2) DIR;
    DCL DD  DCB-UPDATE               BIN( 2) DIR;
    DCL DD  DCB-DELETE               BIN( 2) DIR;
    DCL DD  DCB-FORCE-EOD            BIN( 2) DIR;
    DCL DD  DCB-FORCE-EOV            BIN( 2) DIR;
    DCL DD  *                        BIN( 2) DIR;
    DCL DD  *                        BIN( 2) DIR;
    DCL DD  DCB-FREE-REC-LOCK        BIN( 2) DIR;
    DCL DD  *                        BIN( 2) DIR;
    DCL DD  *                        BIN( 2) DIR;
    DCL DD  *                        BIN( 2) DIR;
    DCL DD  DCB-CLOSE                BIN( 2) DIR;
    DCL DD  DCB-OPEN                 BIN( 2) DIR;
    DCL DD  DCB-SPTB                 BIN( 2) DIR;

DCL SPCPTR .TBUF;
DCL SPC     TBUF BAS(.TBUF);
    DCL DD TBUF-DATA     CHAR(132) DIR;
    DCL DD TBUF-REC-NBR  ZND(8,0) DEF(TBUF-DATA) POS(1);

DCL DD NBR-OF-RECORDS     BIN(4);
DCL DD MAX-NBR-OF-RECORDS BIN(4) INIT(100000);
DCL DD TIME-BEFORE PKD(21,0);
DCL DD TIME-AFTER  PKD(21,0);

/*******************************************************************/

ENTRY * EXT;
SET-FILE-INFO:
    CPYBWP    .NULL, *;  /* YOU CANNOT INIT(*) */
    CPYNV      TFCB-LIB-ID,  *LIBL; /* DEFAULT */
    CPYBLAP    TFCB-LIBRARY,"*LIBL", " ";

OPEN-TEST-FILE:
    CPYBLAP    TFCB-FILE,  "TESTFILE", " ";
    CPYNV      TFCB-MBR-ID, MBR-ID;
    CPYBLA     TFCB-MEMBER, TFCB-FILE;

    CALLX     .SEPT(OPEN), OPEN-T, *;
    CPYBWP    .TBUF, .TFCB-OUTBUF;
    CPYBWP    .ODP-ROOT, .TFCB-ODP;
    ADDSPP    .DEVICE-CONTROL-BLOCK, .ODP-ROOT, ODP.DEV-NAMELIST;
    CPYNV      T-PUT, DCB-PUT;

    CPYBREP    TBUF-DATA, " ";
    CPYNV      NBR-OF-RECORDS, 0;
    CALLI      GET-TIME, *, .GET-TIME;
    CPYNV      TIME-BEFORE, TIMESTAMP;
WRITE-RECORD:
    ADDN(S)    NBR-OF-RECORDS, 1;
    CPYNV      TBUF-REC-NBR, NBR-OF-RECORDS;
    CALLX     .SEPT(T-PUT), PUT-T, *;
    CMPNV(B)   NBR-OF-RECORDS, MAX-NBR-OF-RECORDS/LO(WRITE-RECORD);

    CALLI      GET-TIME, *, .GET-TIME;
    CPYBLAP    MSG-TEXT, "Done writing", " ";
    CPYNV      TIME-AFTER, TIMESTAMP;
    SUBN       MSG-SECS, TIME-AFTER, TIME-BEFORE;
    CALLI      SHOW-MESSAGE, *, .SHOW-MESSAGE;

    CALLX     .SEPT(CLOSE), CLOSE-T, *;

/* INPUT FILE PARAMETERS */
DCL SPCPTR .IFCB INIT(IFCB);
DCL DD IFCB CHAR(214) BDRY(16);
    DCL SPCPTR .IFCB-ODP               DEF(IFCB) POS(  1);
    DCL SPCPTR .IFCB-INBUF             DEF(IFCB) POS( 17);
    DCL SPCPTR .IFCB-OUTBUF            DEF(IFCB) POS( 33);
    DCL SPCPTR .IFCB-OPEN-FEEDBACK     DEF(IFCB) POS( 49);
    DCL SPCPTR .IFCB-IO-FEEDBACK       DEF(IFCB) POS( 65);
    DCL SPCPTR .IFCB-NEXT-UFCB         DEF(IFCB) POS( 81);

    DCL DD *                  CHAR(32) DEF(IFCB) POS( 97);
    DCL DD IFCB-FILE          CHAR(10) DEF(IFCB) POS(129);
    DCL DD IFCB-LIB-ID        BIN(2)   DEF(IFCB) POS(139);
    DCL DD IFCB-LIBRARY       CHAR(10) DEF(IFCB) POS(141);
    DCL DD IFCB-MBR-ID        BIN(2)   DEF(IFCB) POS(151);
    DCL DD IFCB-MEMBER        CHAR(10) DEF(IFCB) POS(153);

    DCL DD IFCB-DEVICE-NAME   CHAR(10) DEF(IFCB) POS(163);
    DCL DD IFCB-DEVICE-INDEX  BIN(2)   DEF(IFCB) POS(173);

    DCL DD IFCB-FLAGS-1       CHAR(1)  DEF(IFCB) POS(175) INIT(X'80');
    DCL DD IFCB-FLAGS-2       CHAR(1)  DEF(IFCB) POS(176) INIT(X'20');

    DCL DD IFCB-REL-VERSION   CHAR(4)  DEF(IFCB) POS(177);
    DCL DD IFCB-INV-MK-COUNT  BIN (4)  DEF(IFCB) POS(181);
    DCL DD IFCB-MORE-FLAGS    CHAR(1)  DEF(IFCB) POS(185);
    DCL DD *                  CHAR(23) DEF(IFCB) POS(186);

    DCL DD IFCB-RECORD-ID     BIN (2)  DEF(IFCB) POS(209) INIT(1);
    DCL DD IFCB-RECORD-LENGTH BIN (2)  DEF(IFCB) POS(211) INIT(132);
    DCL DD IFCB-NO-MORE-PARMS BIN (2)  DEF(IFCB) POS(213) INIT(32767);

DCL OL  OPEN-I(.IFCB);
DCL OL CLOSE-I(.IFCB);

DCL SPCPTR .IBUF;
DCL DD IBUF CHAR(132) BAS(.IBUF);
    DCL DD IBUF-DATA       CHAR(132) DIR;
        DCL DD IBUF-REC-NBR ZND(8,0) DEF(IBUF-DATA) POS(1);

DCL DD I-GET BIN(2);
DCL SPCPTR .GET-OPT-I INIT(GET-OPT-I);
DCL DD GET-OPT-I BIN(4) INIT(H'03000001');
DCL OL GET-I(.IFCB, .GET-OPT-I, .NULL);

    CPYNV      IFCB-LIB-ID,  *LIBL; /* DEFAULT */
    CPYBLAP    IFCB-LIBRARY,"*LIBL", " ";

OPEN-INPUT-FILE:
    CPYBLAP    IFCB-FILE,  "TESTFILE", " ";
    CPYNV      IFCB-MBR-ID, MBR-ID;
    CPYBLA     IFCB-MEMBER, IFCB-FILE;
    CALLX     .SEPT(OPEN), OPEN-I, *;

    CPYBWP    .IBUF, .IFCB-INBUF;
    CPYBWP    .ODP-ROOT, .IFCB-ODP;
    ADDSPP    .DEVICE-CONTROL-BLOCK, .ODP-ROOT, ODP.DEV-NAMELIST;
    CPYNV      I-GET, DCB-GET;

    CPYNV      NBR-OF-RECORDS, 0;
    CALLI      GET-TIME, *, .GET-TIME;
    CPYNV      TIME-BEFORE, TIMESTAMP;
READ-RECORD:
    ADDN(S)    NBR-OF-RECORDS, 1;
    CALLX     .SEPT(I-GET), GET-I, *;
    CMPNV(B)   NBR-OF-RECORDS, MAX-NBR-OF-RECORDS/LO(READ-RECORD);

    CALLI      GET-TIME, *, .GET-TIME;
    CPYBLAP    MSG-TEXT, "Done reading", " ";
    CPYNV      TIME-AFTER, TIMESTAMP;
    SUBN       MSG-SECS, TIME-AFTER, TIME-BEFORE;
    CALLI      SHOW-MESSAGE, *, .SHOW-MESSAGE;

    CALLX     .SEPT(CLOSE), CLOSE-I, *;
    RTX        *;

DCL DD MACHINE-CLOCK CHAR(2) INIT(X'0100');
DCL SPCPTR .MACHINE-ATTR INIT(MACHINE-ATTR);
DCL DD      MACHINE-ATTR CHAR(24) BDRY(16);
    DCL DD  MAT-MAX-SIZE   BIN(4) DEF(MACHINE-ATTR)  POS( 1) INIT(16);
    DCL DD  MAT-ACT-SIZE   BIN(4) DEF(MACHINE-ATTR)  POS( 5);
    DCL DD  MAT-TIMESTAMP CHAR(8) DEF(MACHINE-ATTR)  POS( 9);
        DCL DD MAT-TIME-HI BIN(4) UNSGND DEF(MAT-TIMESTAMP) POS(1);
        DCL DD MAT-TIME-LO BIN(4) UNSGND DEF(MAT-TIMESTAMP) POS(5);
    DCL DD  *             CHAR(8) DEF(MACHINE-ATTR)  POS(17);

DCL DD TIMESTAMP     PKD(21,0); /* CAN HOLD 64-BIT UNSIGNED */
DCL DD TIMESTAMP-HI  PKD(11,0);
DCL DD TIMESTAMP-LO  PKD(11,0);
DCL DD TWO**32       PKD(11,0) INIT(P'4294967296');
DCL DD NBR-SECONDS   PKD(15,0);
DCL DD NBR-DAYS      BIN(4);
DCL DD NBR-YEARS     BIN(4);
DCL DD ADD-YEARS     BIN(4);
DCL DD NBR-PERIODS   BIN(4);
DCL DD DAY-MONTH     BIN(4);
DCL DD D             BIN(4);
DCL DD S             BIN(4);
DCL DD M             BIN(4);
          /* DAY BASE FOR: JanFebMarAprMayJunJulAugSepOctNovDec*/
DCL DD DAYS CHAR(36) INIT("000031059090120151181212243273304334");
DCL DD DAYS-ACCUM (12)ZND(3,0) DEF(DAYS) POS(1);

DCL DD THE-TIME CHAR(20);
    DCL DD YEAR  ZND(4,0) DEF(THE-TIME) POS( 1);
    DCL DD *     CHAR(1)  DEF(THE-TIME) POS( 5) INIT("/");
    DCL DD MONTH ZND(2,0) DEF(THE-TIME) POS( 6);
    DCL DD *     CHAR(1)  DEF(THE-TIME) POS( 8) INIT("/");
    DCL DD DAY   ZND(2,0) DEF(THE-TIME) POS( 9);
    DCL DD *     CHAR(2)  DEF(THE-TIME) POS(11) INIT(" ");
    DCL DD HOUR  ZND(2,0) DEF(THE-TIME) POS(13);
    DCL DD *     CHAR(1)  DEF(THE-TIME) POS(15) INIT(":");
    DCL DD MIN   ZND(2,0) DEF(THE-TIME) POS(16);
    DCL DD *     CHAR(1)  DEF(THE-TIME) POS(18) INIT(":");
    DCL DD SEC   ZND(2,0) DEF(THE-TIME) POS(19);

/*******************************************************************/

DCL INSPTR .GET-TIME;
ENTRY       GET-TIME INT;
    MATMATR   .MACHINE-ATTR, MACHINE-CLOCK;
    CPYNV      TIMESTAMP-LO, MAT-TIME-LO;
    CPYNV      TIMESTAMP-HI, MAT-TIME-HI;
    MULT       TIMESTAMP, TIMESTAMP-HI, TWO**32;
    ADDN(S)    TIMESTAMP, TIMESTAMP-LO;
    DIV(SR)    TIMESTAMP, 4096000000;                 /* NOW SECONDS */
    ADDN(S)    TIMESTAMP, 43386;                      /* 12:03:06 PM */
    DIVREM     NBR-DAYS, TIMESTAMP, 86400, NBR-SECONDS;
    SUBN(S)    NBR-DAYS, 131;  /* WAS: AUG 23,1928, NOW: JAN 01,1929 */
    DIVREM     NBR-PERIODS, NBR-DAYS, 1461, NBR-DAYS; /*     4 YEARS */
    MULT       NBR-YEARS, NBR-PERIODS, 4;
    ADDN(S)    NBR-YEARS, 1929;
    DIVREM     ADD-YEARS, NBR-DAYS, 365, NBR-DAYS;
    ADDN       YEAR, NBR-YEARS, ADD-YEARS;
    CPYNV      M, 13;
    CMPNV(B)   ADD-YEARS, 3/LO(FIND-MONTH);
LEAP-YEAR:
    CMPNV(B)   NBR-DAYS, 59/LO(FIND-MONTH),EQ(FEB-29TH);
    SUBN(S)    NBR-DAYS, 1;
FIND-MONTH:
    SUBN(S)    M, 1;
    SUBN(B)    DAY-MONTH, NBR-DAYS, DAYS-ACCUM(M)/NEG(FIND-MONTH);
    ADDN       DAY, DAY-MONTH, 1;
    CPYNV(B)   MONTH, M/NNAN(COMPUTE-TIME);
FEB-29TH:
    CPYNV      MONTH, 2;
    CPYNV      DAY, 29;

COMPUTE-TIME:
    DIVREM     HOUR, NBR-SECONDS, 3600, NBR-SECONDS;
    DIVREM     MIN,  NBR-SECONDS,   60, SEC;
    B         .GET-TIME;

/* SHOW A MESSAGE */

DCL SPCPTR .MSG-ID   INIT(MSG-ID);
DCL DD      MSG-ID   CHAR (7) INIT("       ");

DCL SPCPTR .MSG-FILE INIT(MSG-FILE);
DCL DD      MSG-FILE CHAR(20) INIT("                    ");

DCL SPCPTR .MSG-TEXT INIT(MSG-TEXT);
DCL DD      MSG-TEXT CHAR(60);
    DCL DD  MSG-TIME CHAR(20) DEF(MSG-TEXT) POS(16);
    DCL DD  MSG-SECS ZND(8,0) DEF(MSG-TEXT) POS(40);

DCL SPCPTR .MSG-SIZE INIT(MSG-SIZE);
DCL DD      MSG-SIZE BIN( 4)  INIT(60);

DCL SPCPTR .MSG-TYPE INIT(MSG-TYPE);
DCL DD      MSG-TYPE CHAR(10) INIT("*INFO     ");

DCL SPCPTR .MSG-QS   INIT(MSG-QS);
DCL DD      MSG-QS   CHAR(20) INIT("*REQUESTER          ");

DCL SPCPTR .MSG-QSN  INIT(MSG-QSN);
DCL DD      MSG-QSN  BIN( 4)  INIT(1);

DCL SPCPTR .REPLY-Q  INIT(REPLY-Q);
DCL DD      REPLY-Q  CHAR(20) INIT("                    ");

DCL SPCPTR .MSG-KEY  INIT(MSG-KEY);
DCL DD      MSG-KEY  CHAR( 4);

DCL SPCPTR .ERR-CODE INIT(ERR-CODE);
DCL DD      ERR-CODE BIN( 4) INIT(0);

DCL OL QMHSNDM (.MSG-ID,   .MSG-FILE, .MSG-TEXT, .MSG-SIZE,
                .MSG-TYPE, .MSG-QS,   .MSG-QSN,  .REPLY-Q,
                .MSG-KEY,  .ERR-CODE)  ARG;

DCL INSPTR .SHOW-MESSAGE;
ENTRY       SHOW-MESSAGE INT;
    CPYBLA     MSG-TIME, THE-TIME;
    CALLX     .SEPT(4268), QMHSNDM, *; /* SEND MSG TO MSGQ */
    B         .SHOW-MESSAGE;

PEND;
+---
| This is the MI Programmers Mailing List!
| To submit a new message, send your mail to MI400@midrange.com.
| To subscribe to this list send email to MI400-SUB@midrange.com.
| To unsubscribe from this list send email to MI400-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator: dr2@cssas400.com
+---


As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.