I looked at enums -- it is almost a match, however enums are limited to integers, and 88 levels are used with any data type.
Here is another snip of COBOL that I need to convert:
Code:
01 MY-FIELD-TYPE PIC X(4) Value Spaces.
88 Valid-Type
Values are "CHAR" "DIG " "DMY " "MDY " "YMD " "IMP0" "IMP1"
"IMP2" "IMP3" "IMP4" "IMP5" "IMP6" "IMP7" "IMP8"
"IMP9" "NUM " "NUM0" "NUM1" "NUM2" "NUM3" "NUM4"
"NUM5" "NUM6" "NUM7" "NUM8" "NUM9".
So, then test as follows
Code:
if Valid-Type then
display "Field type is valid"
else
display "Invalid field type found"
end-if
I appreciate your suggestion, enum will work for many cases, like:
Code:
01 TXT-SW PIC 9 VALUE 0.
88 TXT-CLOSED VALUE 0.
88 TXT-OPEN VALUE 1.
88 TXT-EOF VALUE 4.
88 TXT-ERROR VALUE 9.
If TXT-CLOSED Then
Open Output Text-File.
The above statement would be true if TXT-SW was equal to 0.
I also need advice for the best most portable method to handle fixed length and variable length strings in C.
I know C handles variable length strings great, as long as they are null terminated, however the COBOL code that I am converting is used to build a dll and/or .so and the calling applications may pass strings into this library that are not null terminated, but fixed length, something that must be allowed.