× 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.


  • Subject: Re: Formatting Data in RPG 4
  • From: Jim Langston <jimlangston@xxxxxxxxxxxxxxxx>
  • Date: Thu, 26 Apr 2001 08:35:10 -0700
  • Organization: Pacer International

Okay, change all the input_record with %TrimR(input_Record).
Or make a new var, input_trimmed and give it the trimmed right value of 
input_record.
You'll need to use a varying length field to store the trimmed value though.

Pseudo code:

Output_record = blanks
do until end of file
  read input_record 
  if length(output_record) + length(%TrimR(input_record)) > 80
      length_to_add = 80 - length(output_record)
      output_record = output_record + left(input_record, 1, length_to_add)
      write output_record
      output_record = right(%TrimR(input_record), length(%TrimR(input_record)) 
- Length_to_add)
  else  
      output record = output record + %TrimR(input_record)
  end if
end do
if length(output_record) > 0
  write output_record
end if

Or, optionally:

Pseudo code:

D InputTrimmed    Varying

Output_record = blanks
do until end of file
  read input_record 
  InputTrimmed = %TrimR(Input_Record)
  if length(output_record) + length(input_trimmed) > 80
      length_to_add = 80 - length(output_record)
      output_record = output_record + left(input_trimmed, 1, length_to_add)
      write output_record
      output_record = right(input_trimmed, length(input_trimmed) - 
Length_to_add)
  else  
      output record = output record + input_trimmed
  end if
end do
if length(output_record) > 0
  write output_record
end if

Justin Kiteley wrote:
> 
> Peter,Jim and all,
> 
> Thanks for the ideas.  The problem I am having is that the input data is
> anywhere from 1 to 80 char long, almost always varying in size with spaces
> in the data that need to be retained.
> 
> Example:  lets say the max length was 20 and i was trying to wrap data to a
> larger field, removing unwanted trailing spaces. cap X's represent necessary
> spaces small x's unnecessary spaces.  Sorry if it's confusing, I couldn't
> think of any other way to explaing it!
> 
> Before
> 
> record 1  - TestingX12xxxxxxxxxx
> record 2  - TestX12XXTestXXXXTst
> record 3  - TstX1X23xxxxxxxxxxxx
> 
> After (what I am having trouble achieving)
> 
> record 1 - TestingX12TestX12XXTestX
> record 2 - XXXTstTstX1X23xxxxxxxxx
> 
>   I was just wondering if there was an easier (more efficient, less code)
> way to do it.  Rather than the circuitous code I have right now.  I suppose
> the only answer to the spaces problem is to use checkr to find farthest
> right position of data in the field to be wrapped then parse out the data
> character by character into the new 80 field using arrays, keeping track of
> where you are by counters, and then reading the next record when 80 is
> reached.  I'm going to try to adapt Peter's code first and try it out, but
> I'm not sure how it will handle the spaces.  I also don't know how much data
> will be in the file, so I guess I have to define the "largefield" as large
> as possible?  If anybody else has ideas on this don't be shy.  I'll post my
> code once I get it working properly if anybody wants to see it.    Again,
> thanks for the input!
> 
> Justin Kiteley
> 
> +---
> | This is the RPG/400 Mailing List!
> | To submit a new message, send your mail to RPG400-L@midrange.com.
> | To subscribe to this list send email to RPG400-L-SUB@midrange.com.
> | To unsubscribe from this list send email to RPG400-L-UNSUB@midrange.com.
> | Questions should be directed to the list owner/operator: david@midrange.com
> +---

-- 


Regards,

Jim Langston

Me transmitte sursum, Caledoni!
+---
| This is the RPG/400 Mailing List!
| To submit a new message, send your mail to RPG400-L@midrange.com.
| To subscribe to this list send email to RPG400-L-SUB@midrange.com.
| To unsubscribe from this list send email to RPG400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator: david@midrange.com
+---

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.