× 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: Challenge
  • From: "Mark A. Manske" <manske@xxxxxxxxxxxx>
  • Date: Fri, 5 Nov 1999 14:08:13 -0600
  • Disposition-Notification-To: "Mark A. Manske" <manske@pconline.com>
  • Importance: Normal



-----Original Message-----
From: owner-rpg400-l@midrange.com [mailto:owner-rpg400-l@midrange.com]On
Behalf Of Lurton Keel

I have a little RPG challenge.
I get an 8 character string that has a number that may or may not have a
decimal position.
Examples: 12345.78 or 123 or 1.23456, etc.
I need to convert this to a number (10,5).
The way it was done in RPG prior was to move to an array and scan for the
decimal, do a bunch of move, movels.

Is there a more elegant way to do this in ILE?

I have done a similar thing with a bank file coming in,
here is a code snipit from a rather green, but willing pupil of ILE

in this example ================17 is being used because that is the
size of the input here, you would change that to 8
and since your number is  a 10/5 field,  lessthan  would 
be defined instead as            5  5
and   lessthandollar would be    5 


also the statement %subst(mwamount:pos:2) would have to be refined
to calc the end of the field so that 2 will also be a variable

This can at least give you some ideas of what you "could" do 


D wholenumber     S             17    
D wholenumbern    S             17  0 
D lessthandollar  S              2    
D lessthan        S              2  2 
D blankfield      S             17    
D len             S              5  0 
D blanklen        S              5  0 
D pos             S              5  0 

C                   eval      wholenumber    = *blanks     
C                   eval      lessthandollar = *blanks     
 *must find out what the field is, since comes in as alpha 
 *______check for the decimal position                     
C     '.'           scan      mwamount      pos            
C                   IF        pos = *zeros                 
C     ' '           scan      mwamount      pos            
C                   eval      lessthandollar = '00'        
C                   eval      len = pos -1                 
C                   eval      blanklen = 17 - len          
C                   eval      pos = pos + 1                
                                                           
C                   else                                   
                                                           
C                   eval      len = pos -1                 
C                   eval      blanklen = 17 - len          
C                   eval      pos = pos + 1                      
C                   eval      lessthandollar =                   
C                                          %subst(mwamount:pos:2)
C                   endIF                                        
                                                                 
C                   eval      pos = blanklen + 1                 
C                   eval      %subst(wholenumber:1:blanklen) =   
C                                %subst(blankfield:1:blanklen)   
C                   eval      %subst(wholenumber:pos:len) =      
C                                %subst(mwamount:1:len)          
                                                                 
c                   move      lessthandollarlessthan             
c                   move      wholenumber   wholenumbern         
                                                                 
C                   eval      BKCAMT =   wholenumbern  +         
c                                        lessthan                
                                                                 
where BKCAMT is the numeric field I am updating in a file from 

I don't know about elegance, but it works here...




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