Verifying COBOL data for a capital letter?

I am in my second quarter of the college and take "Advanced COBOL", we only got a task that requires us to code in some validation procedures for different data. Everything has been done for me, except for a small verification procedure.

There is a PART-NUMBER field, the length of which is 8 bytes. The first 5 columns must be a number. The 6th column should be uppercase, and the last 2 columns should be in the range 01-68 or 78-99. The only problem I am facing is figuring out how to confirm that the 6th column is capital.

Here is the code I'm using: From the working repository:

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 that I'm probably not doing this in a very efficient way, but for now I just need to get it to work. I read the entire chapter on data validation from the book, and this is a kind of last-minute error (the program should appear tomorrow), so the teacher is not available. I would really appreciate any help I can handle this. I really lost the way I should check capital letters. The method I'm using now reports an error if there is nothing in the 6th column of the part number except A or Z.

+4
source share
4 answers

I do not see anything fundamentally wrong with your code. I put it in the driver, compiled and launched it. I got the expected results: An error message when the 6th character PART-NUMBER was not an uppercase letter.

Your COBOL coding style is very different from what I'm used to seeing (not so, just different).

Most COBOL veteran programmers would encode 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 

IF applies both of your editing criteria and does nothing if both transmit (CONTINUE), otherwise an error is reported (part of ELSE). The above does essentially the same thing as your example code, except for using IF rather than EVALUATE .

I give you full grades for testing both ALPHABETIC and capital letters using a level range of 88 ( THRU ). Many programmers would use only level 88, the implicit assumption that "A" THRU "Z" covers only alphabetic characters - this is not true in some environments (in particular, EBCDIC characters).

PS I see you guys must have the same teacher as Kimmy!

+4
source

One thing you need to worry about is the value of β€œA” through β€œZ”. It will only work on ASCII machines.

If you are actually encoding the values ​​"A", "B", "C", "Z". It will work on all platforms.

+1
source

For uppercase letters, you can check the ALPHABETIC-UPPER clause:

 IF PART-LETTER-DL NOT EQUAL SPACE AND PART-LETTER-DL IS ALPHABETIC-UPPER ... END-IF. 

ALPHABETIC-LOWER can also be used, but remember that SPACE is considered ALPHABETIC, so you need to check SPACE if you just want uppercase letters.

+1
source

For EBCDIC, drop the ALPHABETIC test and just use 88:

 88 CAPITAL-LETTER VALUE 'A' THRU 'I' 'J' THRU 'R' 'S' THRU 'Z'. 

Specifying individual letters works, but generates 26 comparisons! The above generates three. ALPHABETIC plus' A 'THRU' Z 'is only two, but has some built-in confusion (the space is alphabetic, and THRU includes non-printable numbers in the range from X'C1 to X'E9').

0
source

Source: https://habr.com/ru/post/1216391/


All Articles