大写字母的COBOL数据验证? [英] COBOL Data Validation for capital letter?

查看:117
本文介绍了大写字母的COBOL数据验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在上大学的第二季度,参加高级COBOL课程时,我们刚刚收到了一项作业,该作业要求我们在一些验证程序中编写不同数据的代码。除了小型验证程序外,我已完成所有工作。



有一个名为 PART-NUMBER的字段,其长度为8个字节。前5列必须是数字。第六列必须为大写字母,最后两列必须为01-68或78-99。我唯一的问题是弄清楚如何验证第六列是否为大写。



这是我正在使用的代码:
从工作存储中:

  01 DETAIL-LINE。 
05零件编号。
10部分-第一-五-DL PIC X(5)。
10 PART-LETTER-DL PIC X.
88大写字母值'A'至'Z'。
10部分最后2个DL图片XX。

从300-有效号码-部分

 评估零件字母-DL字母
正确时评估资本字母
虚假移动是以记录错误开关
移动零件编号移到字段名称
移动到字段值
否进入否部分到错误
在错误移动时最终评估
记录错误切换为是
将零件号移至字段名称
将部分禁止移至字段值
将是移至部分错误
最终评估

我知道我可能不是以非常有效的方式执行此操作,但是现在,我只需要使其工作即可。我已经阅读了本书中有关数据验证的整个章节,这是最后一分钟的错误(计划将于明天到期),因此老师无法使用。我将不胜感激。我真的不知道如何验证大写字母。如果零件编号的第6列中除A或Z以外的其他值,我现在使用的方法将报告错误。

解决方案

我没有发现您的代码有任何根本性的错误。我将其放入
驱动程序中,进行编译并运行。我得到了预期的结果:当PART-NUMBER的第6个字符不是大写字母时,错误仅报告



您的COBOL编码样式非常不同



大多数资深的COBOL程序员都会编写如下代码:

 如果部件字母DL是字母和
字母大写
继续
其他
移动'PART NUMBER'移至字段名称
禁止部分移至字段值
移'YES'禁止部分错误
END-IF

IF 会同时应用您的两个编辑条件,并且如果两个都通过,则不执行任何操作(继续) ,否则报告
个错误(ELSE部分)。除了使用 IF 而不是 EVALUATE 之外,以上代码与您的代码
示例基本上具有相同的作用。 / p>

我给您满分88分的水平测试 ALPHABETIC 和大写字母
直通)。许多程序员只会使用88级,这使
隐含假设'A'THRU'Z'仅覆盖字母字符-在某些环境中,
是绝对错误的(特别是EBCDIC字符集)



PS我看到你们的老师必须和Kimmy一样!


I'm in my second quarter of college and taking "Advanced COBOL" we just received an assignment that requires us to code in some validation procedures for different data. I have everything done except on small validation procedure.

There is a field called "PART-NUMBER" that is 8 bytes long. The first 5 columns must be a number. The 6th column must be a capital letter and the last 2 columns must be in the range of 01-68 or 78-99. The only problem I have is figuring out how to validate that the 6th column is capital.

Here is the code I am using: From working storage:

01 DETAIL-LINE.                                         
05 PART-NUMBER.                                     
    10 PART-FIRST-FIVE-DL        PIC X(5).          
    10 PART-LETTER-DL            PIC X.             
        88 CAPITAL-LETTER        VALUE 'A' THRU 'Z'.
    10 PART-LAST-TWO-DL          PIC XX.

From 300-VALIDATE-PART-NUMBER

EVALUATE PART-LETTER-DL ALPHABETIC               
   WHEN TRUE EVALUATE CAPITAL-LETTER               
      WHEN FALSE MOVE 'YES' TO RECORD-ERROR-SWITCH
      MOVE 'PART NUMBER' TO FIELD-NAME            
      MOVE PART-NO-IN TO FIELD-VALUE              
      MOVE 'YES' TO PART-NO-ERROR                 
   END-EVALUATE                                    
   WHEN FALSE MOVE 'YES' TO RECORD-ERROR-SWITCH    
   MOVE 'PART NUMBER' TO FIELD-NAME                
   MOVE PART-NO-IN TO FIELD-VALUE                  
   MOVE 'YES' TO PART-NO-ERROR                     
END-EVALUATE 

I know I'm probably not doing this in a very efficient way but for now I just need to get it to work. I've read the whole chapter on data validation from the book and this is sort of a last minute error (program is due tomorrow) so the teacher is unavailable. I would greatly appreciate any help I can get with this. I'm really lost on how I'm supposed to validate capital letters. The method I'm using now reports an error if anything other than A or Z is in the 6th column of the part number.

解决方案

I don't see anything fundamentally wrong with your code. I put it into a driver program, compiled and ran it. I got the expected results: Error reported only when the 6th character of PART-NUMBER was not an upper case letter.

Your COBOL coding style is very different from what I am used to seeing (not wrong, just different).

Most veteran COBOL programmers would code something like:

    IF PART-LETTER-DL IS ALPHABETIC AND
       CAPITAL-LETTER
       CONTINUE
    ELSE
       MOVE 'PART NUMBER' TO FIELD-NAME            
       MOVE PART-NO-IN TO FIELD-VALUE              
       MOVE 'YES' TO PART-NO-ERROR
    END-IF

The IF applies both of your edit criteria and does nothing if both pass (CONTINUE), otherwise an error is reported (ELSE part). The above does essentially the same thing your code example does except using IF as opposed to EVALUATE.

I give you full marks for testing both ALPHABETIC and capital letter using an 88 level range (THRU). A lot of programmers would only use the 88 level, making the implicit assumption that 'A' THRU 'Z' covers only alphabetic characters - this is dead wrong in some environments (EBCDIC character sets in particular).

P.S. I see you guys must have the same teacher that Kimmy had!

这篇关于大写字母的COBOL数据验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆