Using CPYTOIMPF to copy .txt file (need result to be fixed length – not truncated)

25 pts.
AS/400 File Transfer
File transfers
iseries v5r4
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

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

Discuss This Question: 6  Replies

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • philpl1jb
    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
    54,090 pointsBadges:
  • BurnedOut
    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 pointsBadges:
  • DanTheDane
    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)  
    To create the filename add something like this to your CL-program:
    DCL VAR(&filepth) TYPE(*CHAR) LEN(64)
    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,555 pointsBadges:
  • TomLiotta
    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
    125,585 pointsBadges:
  • BurnedOut
    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 pointsBadges:
  • TomLiotta
    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
    125,585 pointsBadges:

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.


Share this item with your network: