8 COBOL in Distributed Environment

The following conditions have to be noticed when using COBOL together with the distributed Dialog Manager.

Example

In the following example, a listbox is filled with any number of items defined by the user. The filling is first done in the temporary memory which is then assigned to the object.

The contents is queried individually after it was copied via the network in a second function.

Dialog file

dialog DEMO

{

    .xraster   8;

    .yraster   20;

}

 

function void InitTestAppl(object);

 

application TestAppl

{

    .active false;

    .connect "lovelace:4711";

 

    /* F U N C T I O N   D E F I N I T I O N S */

    function cobol void FillListbox  (object, integer, string[80],     integer);

    function cobol void GetListbox  (object);

}

 

on TestAppl start

{

    InitTestAppl(this);

}

 

/* V A R I A B L E   D E F I N I T I O N S */

variable boolean Retvalue := true;

variable boolean Changed := false;

variable integer Number := 0;

variable integer CurrentIndex := 0;

 

/* C O L O R   D E F I N I T I O N S */

color RED "red", grey(75), white;

 

/* D E F I N I T I O N S   O F   A C C E L E R A T O R S */

accelerator  AP1

{

    0: F5;

}

accelerator  AP2

{

    0: F6;

}

 

accelerator AP3

{

    0: cntrl + F4;

}

 

accelerator AP4

{

    0: cntrl + F9;

}

 

accelerator AP5

{

    0: F7;

}

accelerator AP6

{

    0: F8;

}

 

accelerator EXIT

{

    0: cntrl + 'e';

}

 

/* D E F A U L T    D E F I N I T I O N S */

 

default window

{

    .sizeraster    true;

    .posraster        true;

    .titlebar        true;

    .closeable        true;

    .sizeable        true;

    .moveable        true;

    .visible        true;

    .sensitive        true;

    .xraster        8;

    .yraster        20;

}

default pushbutton

{

    .sizeraster    true;

    .posraster     true;

    .xauto         1;

    .yauto         1;

    .visible         true;

    .sensitive     true;

    .width        8;

}

 

/* default value for all edittexts */

default edittext

{

    .visible     true;        /* show the edittexts        */

    .maxchars         80;     /* set the maximum chars    */

    .sensitive     true;    /* make it sensitive        */

    .sizeraster     true;    /* dimension not in pixel    */

    .posraster     true;    /* position not in pixel    */

    .xauto     1;    /* left aligned            */

    .yauto     1;    /* top aligned            */

    .borderwidth     0;

    .multiline    false;

}

 

default statictext

{

    .sizeraster        true;

    .posraster        true;

    .xauto        1;

    .yauto        1;

    .sensitive        false;

    .visible        true;

}

 

default listbox

{

    .sizeraster        true;

    .posraster        true;

    .multisel        false;

    .visible        true;

    .sensitive      true;

    .borderwidth     1;

}

 

default menubox

{

    .visible         true;

    .sensitive         true;

}

 

default menuitem

{

    .visible         true;

    .sensitive         true;

}

default menusep

{

    .visible         true;

}

 

/* D E F I N I T I O N S   O F   M O D E L S */

 

model edittext EnterNumber

{

    .width        6;

    .maxchars        10;

    .format        "%5ud";

    .sensitive         false;

}

 

/* this model is only used to bind rules */

model menuitem ActionMenus

{

}

 

/* D E F I N I T I O N S   O F   O B J E C T S */

/* Definition of the main window */

window Test

{

    .title    "DIALOG MANAGER EXAMPLE";

    .xleft    0;

    .ytop        0;

    .width    78;

    .height    21;

 

    menu menubox FileMenu

    {

    .title     "File";

    child menuitem Exit

    {

    .text     "&Exit";

    .accelerator EXIT;

    }

    }

    child statictext

    {

        .text        "Dummy-String :";

        .xleft    1;

        .ytop     0;

    }

    child edittext File

    {

        .xleft    14;

        .ytop        0;

        .width    20;

        .content    "test-string";

    }

    child statictext

    {

        .text        "&Lines :";

        .xleft    60;

        .ytop        0;

    }

 

    child edittext Lines

    {

        .model    EnterNumber;

        .xleft    69;

        .ytop        0;

        .sensitive true;

        .content     "10";

    }

    child listbox F1

    {

    .xauto        0;

    .xleft        2;

    .xright        2;

    .yauto        0;

    .ytop            4;

    .ybottom        4;

    .accelerator    AP6;

    }

 

    child pushbutton Pb1

    {

        .xleft         2;

        .yauto         -1;

        .ybottom         0;

        .text            "&Set";

        .accelerator    AP1;

    }

    child pushbutton Pb2

    {

        .xauto        -1;

        .xright        2;

        .yauto        -1;

        .ybottom        0;

        .text            "&Get";

        .accelerator      AP2;

    }

 

    child statictext ActionLine

    {

        .xleft        2;

        .ytop            3;

        .text            "";

    }

 

}

 

/* Definition of the confirm window */

window Confirm

{

    .title         "Confirm exit";

    .xleft         10;

    .ytop         8;

    .width         40;

    .height         6;

    .visible         false;

    .dialogbox     true;

 

    /* this object is only visible on Alpha Terminals */

    child hp_softkeys

    {

        .text[1]     "";

        .text[2]     "";

        .text[3]     "";

        .text[4]     "";

        .text[6]     "";

        .text[7]     "";

        .text[8]     "";

        .text[9]     "";

    }

    child statictext

    {

        .text         "Would you like to save your changes?";

        .ytop         1;

        .xleft         2;

    }

    child pushbutton Yes

    {

        .ytop         3;

        .xleft         20;

        .width         8;

        .height         1;

        .text         "&Yes";

        .bgc             RED;

    }

    child pushbutton No

    {

        .ytop         3;

        .xleft         30;

        .width         8;

        .height         1;

        .text         "&No";

        .bgc             RED;

    }

}

 

/* R U L E S   O F   T H E   D I A L O G  */

 

/* dialog start rule */

on dialog start

{

    TestAppl.active := true;

    if (not TestAppl.active) then

    TestAppl.local := true;

        TestAppl.active := true;

    endif

}

 

/* this rules reads the rest of the file into the listbox */

on Test close

{

    exit();

}

 

on Pb1 select

{

    FillListbox(F1, atoi(Lines.content), File.content,     length(File.content) + 1);

}

 

on Pb2 select

{

    GetListbox(F1);

}

on Exit select

{

  exit();

}

Corresponding COBOL program

    *SET OSVS

    IDENTIFICATION DIVISION.

    PROGRAM-ID. FILLLISTBOX.

    AUTHOR. "MD".

 

    ENVIRONMENT DIVISION.

    INPUT-OUTPUT SECTION.

    DATA DIVISION.

    FILE SECTION.

 

    WORKING-STORAGE SECTION.

    01    STR-TAB.

        05 STRFIELD PIC X OCCURS 80.

    01    INT-TAB.

        05 INTFIELD    PIC 9 OCCURS 5.

    77    COUNTER         PIC 9(4) VALUE 0.

    77    DM-POINTER        PIC 9(4) BINARY VALUE 0.

    77    ICOUNT        PIC 9(4) BINARY VALUE 0.

    77    I             PIC 99 VALUE ZERO.

    77    J            PIC 99 VALUE ZERO.

 

    LINKAGE SECTION.

    COPY "IDMcobls.cob".

 

    77    DLG-COUNT PIC 9(9) binary.

    77    DLG-OBJECT PIC 9(4) binary.

    77    DLG-STRING PIC X(80).

    77    DLG-STR-LEN PIC 9(9) binary.

 

    *This COBOL function creates a temporary memory in DM

    *and then assigns it to a listbox

 

    PROCEDURE DIVISION USING DM-COMMON-DATA DLG-OBJECT DLG-COUNT

        DLG-STRING DLG-STR-LEN.

    ORGANIZE-IN SECTION.

        MOVE DLG-COUNT TO ICOUNT.

    *Initialization of memory in DM

        CALL "DMcob_InitVector" USING DM-StdArgs DM-POINTER DT-String

        ICOUNT.

    *Initialization of DM-Value structure

        MOVE DT-STRING TO DM-DATATYPE.

        MOVE DLG-STRING TO DM-VALUE-STRING.

 

    *Setting of individual contents

        PERFORM VARYING COUNTER FROM 1 BY 1 UNTIL COUNTER = DLG-COUNT

        MOVE COUNTER TO DM-INDEX

        MOVE DLG-STRING TO STR-TAB

    *Preparation of a changed string for display

        MOVE COUNTER TO INT-TAB

        MOVE DLG-STR-LEN TO J

        MOVE SPACE TO STRFIELD(J)

        ADD 1 TO J

        PERFORM VARYING I FROM 1 BY 1 UNTIL I > 5

            MOVE INTFIELD(I) TO STRFIELD(J)

            ADD 1 TO J

        END-PERFORM

 

        MOVE STR-TAB TO DM-VALUE-STRING

        CALL "DMcob_SetVectorValue" USING DM-STDARGS DM-VALUE

            DM-POINTER

        END-PERFORM.

    *Transfer of the stored values to the display

        MOVE DLG-OBJECT TO DM-OBJECT.

        MOVE AT-CONTENT TO DM-ATTRIBUTE.

        MOVE 1 TO DM-INDEXCOUNT.

        MOVE 1 TO DM-index.

        CALL "DMcob_SetVector" USING DM-StdArgs DM-Value

        DM-POINTER  0 0 0.

 

    *Freeing memory

        CALL "DMcob_FreeVector" USING DM-StdArgs DM-POINTER.

 

        GOBACK.

 

        ENTRY "GETLISTBOX" USING DM-COMMON-DATA DLG-OBJECT.

 

        MOVE DLG-OBJECT TO DM-OBJECT.

        MOVE AT-CONTENT TO DM-ATTRIBUTE.

        MOVE 1 TO DM-INDEXCOUNT.

        MOVE 1 TO DM-index.

        CALL "DMcob_GetVector" USING DM-StdArgs DM-Value

            DM-POINTER ICOUNT 0 0.

 

    *Inquiring individual contents

        PERFORM VARYING COUNTER FROM 1 BY 1 UNTIL COUNTER = ICOUNT

        MOVE COUNTER TO DM-INDEX

        CALL "DMcob_GetVectorValue" USING DM-STDARGS DM-VALUE

            DM-POINTER

        END-PERFORM.

    *Freeing memory

        CALL "DMcob_FreeVector" USING DM-StdArgs DM-POINTER.

        GOBACK.