25 pts.
 Using CPYTOIMPF to copy .txt file (need result to be fixed length – not truncated)
I have been trying to find a way to use the CPYTOIMPF or CPYTOSTMF commands to copy a Program described file that is 2220 characters long so that the resulting text file has the same record length and is in a readable format. I have been able to transfer the file as a fixed length but the characters are translated to @ and other characters.  I have been trying to use the option STMFCCSID of *PCASCII with DTAFMT of *FIXED and RECDLM of *CRLF  I have also used the option of STMFCODPAG of *PCASCII with the same result. If the file is transfered in a format that is readable then the records are truncated.  I have been unable to find a way to get the entire record transfered without having it truncated and being in a format that is usable I want to name the resulting file something like: ReportFileCCYYMMDDHHMMSS.txt so that each time it is copied it will have a unique name. Does anyone have any ideas of how to do this? Thanks for your help. Ann

Software/Hardware used:
AS400 V5-R4
ASKED: April 21, 2010  9:17 PM
UPDATED: April 23, 2010  1:00 AM

Answer Wiki:
Last Wiki Answer Submitted:  Be the first to answer this question.
All Answer Wiki Contributors:  Be the first to answer this question.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

Way back, I think I had a similiar issue–only to discover that the lines weren’t truncated but that the viewer I was using made them look truncated.
Phil

 44,190 pts.

 

I know the lines are truncated because the reporting entity that I sent the file to rejected it because of the record lengths. I’ve also looked at the file in EditPlus and it shows an end of record marker at different places depending on the number of spaces contained at the end of each record.

Ann

 25 pts.

 

From a DDS-described file the below pgm copies rows to the IFS.
Accessing the file as a mapped drive/file it looks just fine (fixed textformat and chars converted right from EDCDIC to ASCII (i used Notepad++):

CPYTOIMPF FROMFILE(mylib/myfile)  
          TOSTMF('/mydir/myfile.TXT')
          MBROPT(*REPLACE)         
          STMFCODPAG(*PCASCII)     
          RCDDLM(*CRLF)            
          DTAFMT(*FIXED)           
          STRDLM(*NONE)            
          RMVBLANK(*NONE)          
          FLDDLM(*TAB)

To create the filename add something like this to your CL-program:

DCL VAR(&DATTIM) TYPE(*CHAR) LEN(20)
DCL VAR(&filepth) TYPE(*CHAR) LEN(64)

RTVJOBA DATETIME(&DATTIM)  

CHGVAR VAR(&file)  VALUE('ReportFile' *TCAT &dattim *TCAT '.txt')
CHGVAR VAR(&filepath) VALUE('/mydir/' *TCAT &file)

CPYTOIMPF FROMFILE(mylib/myfile) TOSTMF(&filepath) .....etc

I hope this helps you.

DanF

 2,540 pts.

 

First, make certain that your target streamfile does not exist. You want the CPYTOIMPF command to create the streamfile object according to the attributes you give on the command.

Next, run CHGJOB CCSID(37).

Now, run your CPYTOIMPF command again with the “STMFCCSID of *PCASCII with DTAFMT of *FIXED and RECDLM of *CRLF” options.

Review the result and report it back here. If it’s clean, then we probably know where to look for the source of the problem. If it makes no difference, then we’ve pretty much eliminated a category of possible problems.

The CHGJOB CCSID(37) might be the wrong job CCSID. The actual number should be whatever your system CCSID is supposed to be. You can look down through your interactive job’s attributes to see your current job CCSID as well as your job’s “default CCSID”. Whatever shows up in those job attributes is the CCSID you should use for CHGJOB as long as you do not use 65535.

You can use DSPF in hex mode to see where your streamfile lines actually end as well as to see what characters are being represented.

Tom

 108,260 pts.

 

Well the following seems to be working for me – thank you to everyone for your assistance.

CPYTOIMPF FROMFILE(LIBRARY/FileName member) +
TOSTMF(&FILE) MBROPT(*REPLACE) +
FROMCCSID(37) STMFCCSID(*PCASCII) +
RCDDLM(*CRLF) DTAFMT(*FIXED)

 25 pts.

 

Then I suspect that your system QCCSID value is not set appropriately to allow your system to do proper translations when transferring to other systems, or the file was created when the QCCSID was inappropriate, or that file was simply created with inappropriate CCSID settings. A “transfer” of data between database and streamfile is the point of corruption, most likely.

By specifying explicit CCSID, the system knows what character conversions to use when it does the EBCDIC->ASCII work.

Glad it’s working. Note that the actual problem should be tracked down. The specific system or database fix should be planned for the future because future transfers may suffer the same way until settings are changed.

Tom

 108,260 pts.