Can I FTP an AS400 file with different record lenghts

65 pts.
Tags:
AS/400 FTP
FTP File from AS400 record length
Hi

I have created an AS400 file with record length of 100.

I am writing to this file a header record which I want to be length 80 (I am writing spaces to the end of the record to pad it out to 80) a number of detail records of length 100 (there again I am padding it with spaces) and a trailer record of 80.

I am then using FTP command to send the file to dat file on my pc. When I FTP'd the file it did not send down the spaces at the end of the records so each record had a different length.  I tried to ftp using QUOTE SITE TRIM 0.  When I do this the complete dat file is record length 100.

Is there a way I can get my header & trailer of 80 and detail records of 100 in the dat file.

Any help would be appreciated.

 

Regards

 

Rachel

 

 



Software/Hardware used:
AS400
ASKED: January 6, 2010  4:41 PM
UPDATED: February 8, 2010  11:51 AM

Answer Wiki

Thanks. We'll let you know when a new response is added.

The easiest way is simply to create the file with the first line having 80 bytes and remaining lines having 100 bytes. Create the file exactly as you want it to be.

The issue here seems to be that you’re creating a database file and then FTPing it into a streamfile. If you don’t need a database file, don’t create one. Just create a streamfile in the first place and avoid the length problems.

In ILE RPG, the <a href=”http://publib.boulder.ibm.com/infocenter/iseries/v5r4/index.jsp?topic=/apis/unix2.htm”>open(), write() and close() APIs</a> provide the most direct solution.

Although they can have some learning obstacles that take a couple tries to get around, they’re really not that hard. The <a href=”http://www.redbooks.ibm.com/abstracts/sg245402.html”>Sorcerer’s Guide (Who Knew You Could Do That with RPG IV?) Redbook</a> has more examples than anyone should need. Be sure to click the <a href=”ftp://www.redbooks.ibm.com/redbooks/SG245402/”>Additional Material</a> just below the Redbook download link even if you don’t download the Redbook at all. Example code is supplied.

Tom

Discuss This Question: 11  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.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Rachel99
    Tom Thanks for your response. I was just wondering could this work if I had the database file and used CPYTOSTMF to copy it to a streamfile and then FTP it. I have being trying to do this but having problems and am just wondering if it is possible or am I wasting my time. Regards Rachel
    65 pointsBadges:
    report
  • TomLiotta
    Rachel, I haven't tried this, but I can't think of a reason it wouldn't work. Create two separate physical files -- the first as CRTPF RCDLEN(80) and the second as RCDLEN(100). Write your header to the first PF and your details to the second. Then use CPYTOSTMF STMFOPT(*REPLACE) to prepare the streamfile with the short header line and STMFOPT(*ADD) to add all details. It should be easy enough, and it might be capable of giving exactly what you need. (Maybe.) Not much risk in giving it a test. Tom
    125,585 pointsBadges:
    report
  • Rachel99
    Tom I created a pysical file with record length 100 but when I try to do the CPYTOSTMF I am getting the following error: Message . . . . : Object is not a file or is a file with attributes not supported by this command. Cause . . . . . : Object /qsys.lib/april.lib/blakeld.file/blakeld.mbr must be either a source physical file that has three fields or a program described file. Externally described files and source physical files containing fewer or more than three fields are not permitted by this command. Recovery . . . : Specify the name of an existing source physical file with correct attributes, or specify a program described file, then try the command again. My file has just one field in it so it looks like that wont work. Not quite sure what to do now. Rachel
    65 pointsBadges:
    report
  • Cwc
    Rachel, are you sure your physical file was created without DDS? If it's externally described, by having been created from DDS or DDL, then that's what the problem likely is. If so, try creating just through the command line, as in Tom's suggestion.
    4,290 pointsBadges:
    report
  • Rachel99
    Hi I created the 3 physical files using CRTPF,. The first is my header with record lenght 80, the second the detail with record length 100 and the last file is my trailer with record length 80. I have used CPYTOSTMF using *REPLACE for the Header file and *ADD for my detail and trailer. I have set the ENDLINFMT field to *FIXED as this keeps the spaces at the end of my records. My problem is that the detail is correct with record length 100 and the trailer is correct with record length 80 but the header is not keeping the correct record length. It has variable field lengths over 100 - I have checked the the setup of my pyhsical file and its seems correct at length 80. Any sugestions would be appreciated Thanks rachel
    65 pointsBadges:
    report
  • TomLiotta
    Rachel: I have set the ENDLINFMT field to *FIXED AFAIK, you can't have *FIXED with CPYTOSTMF if the row lengths are going to be different. Either the streamfile will be *FIXED at some length, or different rows will have different lengths and be delimited by something like *CRLF. You can't have both because they are contradictory. Unless you're at V5R4 or higher...? If so, then don't use CPYTOSTMF. Use CPYTOIMPF. Use RCDDLM(*CRLF) DTAFMT(*FIXED) RMVBLANK(*NONE). Maybe RCDDLM(*LF) will be better; without knowing what will be using the file, there's no way to be sure. Finally, if even this doesn't provide what you need, then you're down to two options --
    1. Use the IFS APIs as originally noted to format each line exactly as you need.
    2. Use user space APIs to populate a user space exactly as you want your streamfile populated. Then use CPY to copy the user space to a streamfile.
    I don't see alternatives yet. Hmmm... before I copied the above text into here, another possibility did come to mind. I haven't tried this for trailing blanks either (nor does truncating them make much sense when lines must be delimited, but you set the requirement). Qshell has the cat utility. You can create a series of streamfiles -- the first with 80-byte lines, the second with 100-byte lines, etc., -- and see if cat will combine them into a final streamfile without truncation. To tell the truth, I'd be very skeptical of the "truncate trailing blanks" part. It just doesn't seem to have any purpose. Tom
    125,585 pointsBadges:
    report
  • Rachel99
    Tom I used the CPYTOIMPF with RCDDLM(*CRLF) DTAFMT(*FIXED) and it seems to have done the job. When I FTP it now I am getting the file with fixed record lengths. Thanks for all your help and advice Rachel
    65 pointsBadges:
    report
  • TomLiotta
    Rachel, Happy it worked (for now). If specific related details need work in the future, open a new question with reference to this one for background. There are usually tweaks for combinations that handle most situations. Tom
    125,585 pointsBadges:
    report
  • Rachel99
    Tom Am hoping that it will work okay - do you think that there will be problems with it. Just a bit worried after reading your response as I was going to put this live to our system after some further testing next week and it involved paying suppliers so has to be 100% correct. Regards Rachel
    65 pointsBadges:
    report
  • TomLiotta
    Rachel: do you think that there will be problems with it. Apologies for slow response. Too much real work (and other questions.) I don't have reason to think problems would appear. But I mentioned a variety of possible methods and any one might have generated other questions. For example, you might be preparing the file for a Unix system that expected RCDDLM(*LF) instead of RCDDLM(*CRLF). I'd probably make it RCDDLM(&LineDelmtr) to make it variable and set it outside of the procedure, depending on what the target was. But you haven't posted any new questions, so I suspect you understand what it's doing well enough. Tom
    125,585 pointsBadges:
    report
  • Rachel99
    Tom So far I have not had any problems so hopefully that will continue !. Thanks for all your help. Rachel
    65 pointsBadges:
    report

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.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

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

Following