Send file creates extra blank record/line in file with XCOM for Windows
search cancel

Send file creates extra blank record/line in file with XCOM for Windows

book

Article ID: 225806

calendar_today

Updated On:

Products

XCOM Data Transport XCOM Data Transport - Windows XCOM Data Transport - z/OS

Issue/Introduction

Send file initiated from XCOM z/OS to XCOM for Windows.
There is an extra blank record created at the end of the file received on Windows and this extra record is unexpected by a Windows application that reads this file.
Need to know how to transfer the file without creating the extra record on windows?

Environment

XCOM™ Data Transport® for z/OS
XCOM™ Data Transport® for Windows

Resolution

XCOM traces for both z/OS and Windows show that XCOM is sending/receiving the same number of records and blocks on each side of the transfer i.e. no extra bank record is being written by XCOM to the Windows file.
When Windows writes the file it adds a CRLF (Carriage Return and Line Feed) to the end of each line in the file including the last one. 

If the transferred file is opened in a Windows editor like Notepad/Notepad++ the last CRLF appears to be an extra blank line e.g. file test1.txt contains 5 lines with "ABC" on each line but shows 6 lines with the last blank line:

When examining the file in hex e.g. PowerShell command "format-hex" it will show the hex characters 0D 0A (CRLF) at the end of the last line:

PS C:\temp> format-hex test1.txt

         Path: C:\temp\test1.txt

           00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F

00000000   41 42 43 0D 0A 41 42 43 0D 0A 41 42 43 0D 0A 41  ABC..ABC..ABC..A
00000010   42 43 0D 0A 41 42 43 0D 0A                       BC..ABC..

Therefore the solution is that the Windows application that is processing the file needs to be able to handle the CRLF at the end of the last line.

One alternative option is to use an XCOM post-processing script to remove the final CRLF after the file has been transferred e.g. customize xcomend.bat to call a script to remove the final CRLF.

See this PowerShell script xcomend.ps1 I created after finding references on the web on how to Remove last line from file with Powershell (including checking if the CRLF exists):

$file = $args.get(0).Substring(1)
write-host "-file: " $file
$stream = [System.IO.File]::Open($file,[System.IO.FileMode]::Open)
$stream.Position = $stream.Length - 2
$bytes = 0..1 | %{ $stream.ReadByte() }
$compareBytes = 13,10 # CR,LF
if ("$bytes" -eq "$compareBytes") {
    $stream.SetLength($stream.Length - 2)
}
$stream.Close()
$stream.Dispose()
The new script xcomend.ps1 was placed into directory %XCOM_HOME% and this line was added to the end of the default xcomend.bat to process the transferred file with the script:
powershell.exe -command "& '%XCOM_HOME%\xcomend.ps1' \"-%file%\"" >> c:\temp\xcomend.out
(NOTE:  The final ">> c:\temp\xcomend.out" was only used to capture errors from debugging first attempts)

After running the script for the transferred file example test1.txt above. When opening the file in a Windows editor like Notepad/Notepad++ it now only shows 5 lines with no final blank line:


Using PowerShell command "format-hex" also shows the hex characters 0D 0A (CRLF) have gone from the end of the last line:
PS C:\temp> format-hex test1.txt


           Path: C:\temp\test1.txt

           00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F

00000000   41 42 43 0D 0A 41 42 43 0D 0A 41 42 43 0D 0A 41  ABC..ABC..ABC..A
00000010   42 43 0D 0A 41 42 43                             BC..ABC

Note this is an example and XCOM Support does not provide any support for custom post-processing scripts.