• Decision Tables and the EVALUATE statement

    From Rick Smith@1:2320/100 to comp.lang.cobol on Thu Apr 27 15:39:23 2017
    From Newsgroup: comp.lang.cobol

    In March 2017, there was a discussion relating to decision
    tables and EVALUATE. It got me thinking. I searched for
    references and located a document at Object Management
    Group (OMG) titled Decision Model and Notation (DMN).
    < http://www.omg.org/spec/DMN/1.1/PDF > [a PS version is
    available]. The PDF is 182 pages. Section 8 discusses
    decision tables.

    This document makes clear there are two orientations for
    decision tables: vertical and horizontal. Verticle is what
    is, perhaps, more common and understood. In fact, many of
    the results for a search will return information on
    verticle decision tables, as if it was the only orientation.

    Since the horizontal orientation is closer to EVALUATE and
    is, in most respects, similar to a spreadsheet; I decided
    to see whether a spreadsheet could be used to create a
    decision table that could be translated into an EVALUATE
    statement. No surprise, it can!

    I exported the spreadsheet to a .csv file and wrote a
    COBOL program <g> to handle the translation. Unfortunately,
    .csv files have some formatting issues to deal with. I
    decided to use a decision table <g> to deal with those.
    This is the final .csv that was input into the program
    that uses the library text. Needless to say, 'bootstrapping'
    was involved!

    -----
    CSV-DT,,,,,,,,,
    ,state,m = fld-start,csv-rec (m:1),csv-rec (m + 1:1),,,,, 1,1,TRUE,quote,any,move 2 to state,add 1 to m,,,
    2,1,TRUE,space,"""'""",add 1 to m,,,,
    3,1,any,"not "",""",any,move csv-rec (m:1) to ws-rec (n:1),add 1 to m,add 1 to n,,
    4,1,any,""",""",any,move fld-sep to ws-rec (n:1),add 1 to m,add 1 to n,move m to fld-start,
    5,2,any,not quote,any,move csv-rec (m:1) to ws-rec (n:1),add 1 to m,add 1 to n,,
    6,2,any,quote,quote,move quote to ws-rec (n:1),add 2 to m,add 1 to n,, 7,2,any,quote,""",""",move fld-sep to ws-rec (n:1),add 2 to m,add 1 to n,move m
    to fld-start,move 1 to state
    8,2,any,quote,""" """,add 2 to m,add 1 to n,move m to fld-start,move 1 to state,
    -----

    The .csv was created using OpenOffice.org CALC so it
    should load into LibreOffice and did load into Google
    Sheets. Copy, Paste, Save, and import to see how it
    looks in a spreadsheet.

    The final library text (copybook) is:

    -----
    *> CSV-DT
    evaluate state also m = fld-start also csv-rec (m:1)
    also csv-rec (m + 1:1)
    *> Rule 1
    when 1 also TRUE also quote also any
    move 2 to state
    add 1 to m
    *> Rule 2
    when 1 also TRUE also space also "'"
    add 1 to m
    *> Rule 3
    when 1 also any also not "," also any
    move csv-rec (m:1) to ws-rec (n:1)
    add 1 to m
    add 1 to n
    *> Rule 4
    when 1 also any also "," also any
    move fld-sep to ws-rec (n:1)
    add 1 to m
    add 1 to n
    move m to fld-start
    *> Rule 5
    when 2 also any also not quote also any
    move csv-rec (m:1) to ws-rec (n:1)
    add 1 to m
    add 1 to n
    *> Rule 6
    when 2 also any also quote also quote
    move quote to ws-rec (n:1)
    add 2 to m
    add 1 to n
    *> Rule 7
    when 2 also any also quote also ","
    move fld-sep to ws-rec (n:1)
    add 2 to m
    add 1 to n
    move m to fld-start
    move 1 to state
    *> Rule 8
    when 2 also any also quote also " "
    add 2 to m
    add 1 to n
    move m to fld-start
    move 1 to state
    end-evaluate
    .
    -----

    Rules:
    1. Detects a quoted field.
    2. Removes an extraneous space, since, apparently, an
    apostrophe cannot start a field in a speadsheet.
    3. Copies one character in an unquoted field.
    4. Detects an end of an unquoted field. (Last field
    detection is not required, since, at most, one space
    character will be added.)
    5. Copies one character in a quoted field.
    6. Converts two quotation marks to one.
    7. Detects an end of a quoted field.
    8. Detects an end of a quoted field when it is the last
    field.

    Given the ability of current spreadsheets to prevent rows
    and columns from scrolling, it should IMHO be possible to
    create very large decision tables that can be translated
    into EVALUATE statements.

    SEEN-BY: 154/30 2320/100 0 1 227/0
  • From pete dashwood@1:2320/100 to comp.lang.cobol on Fri Apr 28 18:43:56 2017
    From Newsgroup: comp.lang.cobol

    On 28/04/17 10:39 AM, Rick Smith wrote:
    add 2 to m
    add 1 to n
    *> Rule 7
    when 2 also any also quote also ","

    Very cool, Rick.

    Jimmy Gavan would have loved it...

    Pete.
    --
    I used to write COBOL; now I can do anything...

    SEEN-BY: 154/30 2320/100 0 1 227/0
  • From Vince Coen@1:2320/100 to Rick Smith on Fri Apr 28 12:47:11 2017
    From Newsgroup: comp.lang.cobol

    Hello Rick!

    Thursday April 27 2017 23:39, Rick Smith wrote to All:

    In March 2017, there was a discussion relating to decision
    tables and EVALUATE. It got me thinking. I searched for
    references and located a document at Object Management
    Group (OMG) titled Decision Model and Notation (DMN).
    < http://www.omg.org/spec/DMN/1.1/PDF > [a PS version is
    available]. The PDF is 182 pages. Section 8 discusses
    decision tables.


    If interested there is a decision table processor to include such into a
    Cobol program written heck forgotten - around 19070's anyway you can find
    the source at https://sourceforge.net/p/open-cobol/contrib/HEAD/tree/trunk/tools/dectrans
    /

    and select Download snapshot

    You will end up getting all of them but its not a big download.

    Written for GNU Cobol.

    Yes, documentation included.


    Vince

    SEEN-BY: 154/30 2320/100 0 1 227/0
  • From docdwarf@1:2320/100 to comp.lang.cobol on Fri Apr 28 16:05:59 2017
    From Newsgroup: comp.lang.cobol

    In article <5b96207f-3d07-4d9f-9c5d-429da6026664@googlegroups.com>,
    Rick Smith <rs847925@gmail.com> wrote:

    [snip and a condensing... my apologies]

    evaluate state also m = fld-start also csv-rec (m:1)
    ...
    when 1 also TRUE also quote also any
    ...
    when 1 also TRUE also space also "'"
    ...
    when 1 also any also not "," also any
    ...
    when 1 also any also "," also any
    ...
    when 2 also any also not quote also any
    ...
    when 2 also any also quote also quote
    ...
    when 2 also any also quote also ","
    ...
    when 2 also any also quote also " "
    ...
    end-evaluate
    .

    A lovely bit of code, Mr Smith. It reminded me of a long-term disability insurance system I worked on a few years back, a textbook example of hairsplitting legalisms implemented in COBOL '74.

    DD

    SEEN-BY: 154/30 2320/100 0 1 227/0
  • From Rick Smith@1:2320/100 to comp.lang.cobol on Fri Apr 28 15:01:50 2017
    From Newsgroup: comp.lang.cobol

    On Friday, April 28, 2017 at 12:06:00 PM UTC-4, docd...@panix.com wrote:
    In article <5b96207f-3d07-4d9f-9c5d-429da6026664@googlegroups.com>,
    Rick Smith <rs84...@gmail.com> wrote:

    [snip and a condensing... my apologies]

    Not required, Mr Dwarf. Snipping is expected on long posts.

    evaluate state also m = fld-start also csv-rec (m:1)
    ...
    when 1 also TRUE also quote also any
    ...
    when 1 also TRUE also space also "'"
    ...
    when 1 also any also not "," also any
    ...
    when 1 also any also "," also any
    ...
    when 2 also any also not quote also any
    ...
    when 2 also any also quote also quote
    ...
    when 2 also any also quote also ","
    ...
    when 2 also any also quote also " "
    ...
    end-evaluate
    .

    A lovely bit of code, Mr Smith. It reminded me of a long-term disability insurance system I worked on a few years back, a textbook example of hairsplitting legalisms implemented in COBOL '74.

    Would that the program formatting that code were as lovely!

    SEEN-BY: 154/30 2320/100 0 1 227/0
  • From Rick Smith@1:2320/100 to comp.lang.cobol on Fri Apr 28 15:25:07 2017
    From Newsgroup: comp.lang.cobol

    On Friday, April 28, 2017 at 7:53:54 AM UTC-4, Vince Coen wrote:
    Hello Rick!

    [snip]

    If interested there is a decision table processor to include such into a Cobol program written heck forgotten - around 19070's anyway you can find
    the source at https://sourceforge.net/p/open-cobol/contrib/HEAD/tree/trunk/tools/dectrans
    /

    While I appreciate the reference, the program uses a vertical
    decision table and generates IF statements. At this point, I am
    working with horizontal decision tables and EVALUATE.

    My next step will be to find other interesting ways to use EVALUATE.

    SEEN-BY: 154/30 2320/100 0 1 227/0