× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Thanks for the replies everyone. Step 1 - update skills! It's always there, but sometimes you just need a poke.

-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx
[mailto:rpg400-l-bounces@xxxxxxxxxxxx]On Behalf Of Scott Klement
Sent: Wednesday, December 12, 2007 1:48 PM
To: RPG programming on the AS400 / iSeries
Subject: Re: Question: end of record in .csv file


Hi Raymond,

The extra blanks come from the fact that you've told CPYTOIMPF that the
file format is *FIXED. Since the records in your flat file have a fixed
length of 250 chars, when it's written to the IFS, the records will also
have a fixed length of 252 chars (the 250 for the original record, plus
the CRLF at the end).

The blanks are there because you told them to be. A fixed-length
database record is always the same length, every time. If you don't
fill up the entire 250 characters, it will fill the remainder with
blanks. CPYTOIMPF won't strip them off for you because you told it the
file format is fixed-length, and therefore it wouldn't make sense to
strip them off.

So how can you solve this? Three different alternatives come to mind:

a) Instead of writing the CSV to a physical file, write it to a stream
file. Stream files are not organized into fixed-length records, and
therefore they won't be padded with blanks.

This is the way the file would've been generated on any other platform,
as well. But, in RPG, we avoid this because stream files didn't exist
on the System/3, and we can't possibly ever learn anything new.
Learning something that didn't exist 30 years ago is just evil.

b) Instead of using CPYTOIMPF, simply FTP the data directly from the
physical file to the destination. Skip the (unnecessary, IMHO) copy to
the IFS. FTP has a facility for trimming trailing blanks from records.

c) Instead of manually building a CSV file and storing the data in a
physical file, create an ordinary physical file with ordinary externally
defined fields -- and use CPYTOIMPF to convert the PF to a delimited
file. That way, you don't have to add the fields together with commas
in your program, the commas will be added by CPYTOIMPF.



Raymond Tenorio wrote:
Hi folks,

Through rpg I create a .csv file using:
field = %trim(field1) + ',' + %trim(field2) + ',' and so on... for 15 to 20 fields.

My file is one field and it's 250A.

Then I have a CL that:
CPYTOIMPF FROMFILE(QTEMP/&FILNAM1) TOSTMF(&FILNAM) +
MBROPT(*REPLACE) STMFCODPAG(*PCASCII) +
RCDDLM(*CRLF) DTAFMT(*FIXED)

I then ftp the file. At the end of each record there's numerous spaces.

My question: how do I eliminate the spaces at the end of each record?

Thank you in advance.

Ray


This communication is not intended as an offer of purchase and is intended only for use by the addressee(s).



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.