English 中文(简体)
在声明中使用数字或字母代码;在“如果”表中使用
原标题:using numeric or alphabetic codes in statements; for use in "if" statements

我很想知道如何在COBOL中做一些事情。 我正试图撰写一个方案,在数据档案中记录数据与产出相匹配时使用。 但是,我还没有这样做,但我认为需要做的是制定不同数据类型的编码。

blue = 1
brown = 2.

因此,我试图这样做,但愿不工作。 我已在主谈中宣布:

01  COLOR-IN    PIC (9)
    05    BLUE         VALUE 1.
    05    BROWN        VALUE 2.

然后,我只想写一下像发言一样的话。

IF COLOR-IN = BLUE 
   PERFORM 200-OUTPUT.

因此,我询问的是,我如何使肤色等同于数字或字母代码。 我应该作什么发言。

我是这样说的。 我使用了88份声明。 和

88      MALE     VALUE  M .

But I have another problem. The output does list the records that meet the if statement criteria, however, I need to code in the program the actual hair and eye color so that when the program executes it prints the hair and eye color instead of 1 or 2. Can anyone give me an example or hint on how to do that?

最佳回答

+1 学习88s。 它们非常有用。

A table (array) of labels that correspond to your values is what you re looking for. If you use alphabetic codes, as in your 88 MALE VALUE M case, then your table has an entry for the value and for the label.

01  INPUT-VALUE                 PIC X(1).
    88  MALE                    VALUE "M".
    88  FEMALE                  VALUE "F".

01  LABELS-AND-VALUES-AREA.
    05  LABELS-AND-VALUES.
        07  ONE-LABEL-AND-VALUE OCCURS 2.
            09  ONE-LABEL       PIC X(6).
            09  ONE-VALUE       PIC X(1).
    05      FILLER REDEFINES LABELS-AND-VALUES
                                VALUE "MALE  MFEMALEF".
01  I                           PIC S9(4) COMP.
01  DISPLAY-LABEL               PIC x(6).

    MOVE "?" TO DISPLAY-LABEL
    PERFORM VARYING I FROM 1 BY 1 UNTIL I > 2
        IF INPUT-VALUE = ONE-VALUE(I)
            MOVE ONE-LABEL(I) TO DISPLAY-LABEL
        END-IF
    END-PERFORM 

如果你用数字表示你的投入价值,你就可以跳出眼光,正确打上你想要的标签。

01  INPUT-VALUE                 PIC 9(1).
    88  MALE                    VALUE "1".
    88  FEMALE                  VALUE "2".
    88  VALID-INPUT             VALUE "1", "2".

01  LABELS-AND-VALUES-AREA.
    05  LABELS-AND-VALUES.
        07  ONE-LABEL-AND-VALUE OCCURS 2.
            09  ONE-LABEL       PIC X(6).
    05      FILLER REDEFINES LABELS-AND-VALUES
                                VALUE "MALE  FEMALE".
01  DISPLAY-LABEL               PIC x(6).

   IF VALID-INPUT
       MOVE ONE-LABEL(INPUT-VALUE) TO DISPLAY-LABEL
   ELSE
       MOVE "?" TO DISPLAY-LABEL
   END-IF

就此而言,你可能希望添加一些关于缺失/未知数据的准则。

<>Update>

我增加了一些处理缺失/众所周知的数据的代码。

问题回答

暂无回答




相关问题
Detect months with 31 days

Is there an analogous form of the following code: if(month == 4,6,9,11) { do something; } Or must it be: if(month == 4 || month == 6 etc...) { do something; } I am trying to write an if ...

&& (AND) and || (OR) in IF statements

I have the following code: if(!partialHits.get(req_nr).containsKey(z) || partialHits.get(req_nr).get(z) < tmpmap.get(z)){ partialHits.get(z).put(z, tmpmap.get(z)); } where partialHits ...

If / else order sequence issue

I have the following set up, a ddl (ddlProd, radBuyer) and autocomplete text box (txtProdAC, radProd) that when populated and their respective radio buttons are selected, a grid view of the data is ...

PHP if or statement not working

We are trying to use the below piece of code if (($_GET[ 1 ] != "1") || ($_GET[ 1 ] != "2")) { When we try this no matter what value the variable has it will evaluate as true even when data is ...

C++ String manipulation - if stament

I have the following code that works correctly. However after I add an else statement anything always evaluates to else wgetstr(inputWin, ch); //get line and store in ch variable str = ch; ...

Are one-line if / for -statements good Python style?

Every so often on here I see someone s code and what looks to be a one-liner , that being a one line statement that performs in the standard way a traditional if statement or for loop works. I ...

Which is faster - if..else or Select..case?

I have three condition to compare. Which one is more faster between the following two? Please point me out. Thanks all! If var = 1 then Command for updating database ElseIf var = 2 then ...

热门标签