tags:

views:

204

answers:

2

This is a rather simple question that has me stumped. How do you check for a particular value in an alphabetic field in COBOL 85? For example, I am using an EVALUATE statement to check for several possible values in an alphabetic field; depending on the value present, I will take one of several possible actions.

Basically, what I'm trying to do is this:

EVALUATE TRUE
    WHEN INPUT-FIELD IS EQUAL TO 'L'
        MOVE 'LARGE' TO OUTPUT-FIELD
    WHEN INPUT-FIELD IS EQUAL TO 'S'
        MOVE 'SMALL' TO OUTPUT-FIELD
END-EVALUATE

If anyone could shed some light on this it would be greatly appreciated.

A: 

Bah, please disregard this question. I was forgetting to include the index of the array when checking the input value; the comparison is working fine.

+2  A: 

I'd just use the condition names. In your data definition area, you have (something like):

01  MY-RECORD
    05  INPUT-FIELD           PIC X.
        88  INP-FLD-IS-LARGE      VALUE 'L'.
        88  INP-FLD-IS-SMALL      VALUE 'S'.
    05  OTHER-DATA            PIC X(20).

then, down in your code:

IF INP-FLD-IS-LARGE THEN
    MOVE 'LARGE' TO OUTPUT-FIELD
ELSE
    IF INP-FLD-IS-SMALL THEN
        MOVE 'SMALL' TO OUTPUT-FIELD
    END-IF
END-IF

I prefer putting conditions in the data definition area because they belong to the data (encapsulation). Keep in mind you can still use EVALUATE although for simpler cases like this, it's overkill. I'd just use IF ELSE

paxdiablo