Skip to main content

I have a COBOL program that reads from an ISAM file. For few of the records in this file, a field (say FIELD123) has extended ASCII characters along with ASCII characters (example - 410090¶). When I try to write the record in the output sequential file with extended ASCII character, then the program fails. In order to confirm if this was the issue, I moved spaces to FIELD123 and then tried to write the record. This time the program did not fail. 

I need your help with below activities:

# How to identify extended ASCII characters?

# If there is extended ASCII character in a field, then replace only the extended ASCII character with space but retain the ASCII value from the field

Thank you!!

I have a COBOL program that reads from an ISAM file. For few of the records in this file, a field (say FIELD123) has extended ASCII characters along with ASCII characters (example - 410090¶). When I try to write the record in the output sequential file with extended ASCII character, then the program fails. In order to confirm if this was the issue, I moved spaces to FIELD123 and then tried to write the record. This time the program did not fail. 

I need your help with below activities:

# How to identify extended ASCII characters?

# If there is extended ASCII character in a field, then replace only the extended ASCII character with space but retain the ASCII value from the field

Thank you!!

Not sure what "extended ASCII" means.  

What is the PIC of FIELD123?

How does the write to sequential fail?  Is the file LINE sequential or BINARY sequential?


Not sure what "extended ASCII" means.  

What is the PIC of FIELD123?

How does the write to sequential fail?  Is the file LINE sequential or BINARY sequential?

The FIELD123 is PIC X(020). Also, the file is LINE sequential.

I posted an example of the value in the FIELD123 in my original post for which the write failed. I am sharing the example again (example - 410090¶). I think the last character in the example is what is causing issue because when I move spaces to the entire field or hard-code in the program to move spaces from 7th column onwards, then the program doesn't fail. However, the column at which this special character is not fixed.


The FIELD123 is PIC X(020). Also, the file is LINE sequential.

I posted an example of the value in the FIELD123 in my original post for which the write failed. I am sharing the example again (example - 410090¶). I think the last character in the example is what is causing issue because when I move spaces to the entire field or hard-code in the program to move spaces from 7th column onwards, then the program doesn't fail. However, the column at which this special character is not fixed.

The paragraph character (hex 14) can be converted to a space using INSPECT FIELD123 CONVERTING 0x14 TO SPACE.


The paragraph character (hex 14) can be converted to a space using INSPECT FIELD123 CONVERTING 0x14 TO SPACE.

Thank you Tom for the reply. I found out that there are more such type of characters. Is there to identify and replace all of them with space rather than doing it one at a time. I found § (section sign) and some special currency symbols as well.


Thank you Tom for the reply. I found out that there are more such type of characters. Is there to identify and replace all of them with space rather than doing it one at a time. I found § (section sign) and some special currency symbols as well.

Here you go.  

       identification division.
       program-id. a.
       data division.
       working-storage section.

       01  field123    pic x(30) value all x"14a7b6".

       procedure division.
       a.
           display field123
           inspect field123 converting
                   x"000102030405060708090a0b0c0d0e0f" &
                   x"101112131415161718191a1b1c1d1e1f" &
                   x"a0a1a2a3a4a5a6a7a8a9aaabacadaeaf" &
                   x"b0b1b2b3b4b5b6b7b8b9babbbcbdbebf" &
                   x"c0c1c2c3c4c5c6c7c8c9cacbcccdcecf" &
                   x"d0d1d2d3d4d5d6d7d8d9dadbdcdddedf" &
                   x"e0e1e2e3e4e5e6e7e8e9eaebecedeeef" &
                   x"f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff" 
               to  spaces.
           display field123
           stop run.    


Here you go.  

       identification division.
       program-id. a.
       data division.
       working-storage section.

       01  field123    pic x(30) value all x"14a7b6".

       procedure division.
       a.
           display field123
           inspect field123 converting
                   x"000102030405060708090a0b0c0d0e0f" &
                   x"101112131415161718191a1b1c1d1e1f" &
                   x"a0a1a2a3a4a5a6a7a8a9aaabacadaeaf" &
                   x"b0b1b2b3b4b5b6b7b8b9babbbcbdbebf" &
                   x"c0c1c2c3c4c5c6c7c8c9cacbcccdcecf" &
                   x"d0d1d2d3d4d5d6d7d8d9dadbdcdddedf" &
                   x"e0e1e2e3e4e5e6e7e8e9eaebecedeeef" &
                   x"f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff" 
               to  spaces.
           display field123
           stop run.    

Thank you Tom 🙂

The code that you suggested worked and replaced all special characters with space and retained the other alphanumeric data