IBM Support

Error DB21007E seen when DB2 is accessing a text file

Troubleshooting


Problem

DB21007E seen when DB2 is accessing a text file

Cause

A DB21007E message is sometimes seen when DB2 is accessing a text file. This is seen when the file has the wrong carriage return (line termination) characters due to the text file being transferred from a Windows machine in binary mode. If the transfer is done in ascii mode, the new lines will be converted.

Diagnosing The Problem

The below demonstrates an example of the issue when the file has the wrong carriage return characters:

    $ db2 -tvf test.sql
    DB21007E End of file reached while reading the command.

    $ file test.sql
    test.sql: ASCII text, with CRLF line terminators

    $ dos2unix test.sql
    dos2unix: converting file test.sql to UNIX format ...

    $ db2 -tvf test.sql
    Success

    $ file test.sql
    test.sql: ASCII text

Resolving The Problem

The issue can be resolved in one or more of the following ways:
1) dos2unix $filename
2) tr -d '\015' < $filename > $filename.fixed
3) Edit the file using vi:

    a) Key in the following command to find and replace all instances of ^M. To create the ^M character, press 'CTRL+v' followed by 'Enter':
      :%s/^M//g
    b) Save the file.
4) Retransfer the file in ASCII mode



[{"Product":{"code":"SSEPGG","label":"Db2 for Linux, UNIX and Windows"},"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Component":"OTHER - Uncategorised","Platform":[{"code":"PF002","label":"AIX"},{"code":"PF010","label":"HP-UX"},{"code":"PF016","label":"Linux"},{"code":"PF027","label":"Solaris"}],"Version":"9.8;9.7;9.5;9.1;8","Edition":"","Line of Business":{"code":"LOB10","label":"Data and AI"}}]

Document Information

Modified date:
16 June 2018

UID

swg21363861