This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to identify extended ASCII characters and replace it with a space

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!!

  • 0

    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?

  • 0 in reply to 

    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.

  • 0 in reply to 

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

  • 0 in reply to 

    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.

  • Verified Answer

    +1 in reply to 

    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.    

  • 0 in reply to 

    Thank you Tom Slight smile

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