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



Lynette Chronister wrote:

>what is the easiest way to right justify a character variable.
>oh, p.s. im writing in 400 not ILE.

The easiest (by far) is to use RPG IV: evalr     output = %trimr(input) 

Here is an RPG/400 version donated many years ago by Booth Martin.  It
handles numbers, but pulling out the IF...END will allow it to handle
characters too:

E                    ARI        15  1                               
E                    ARO        15  1                               
 * -------------------------------------------------------          
IDUMMY       DS                                                     
I I            '1500           '         1  15 FROM                 
I I            '               '        16  30 TARGET               
I I            0                        31  450NUMBER               
 * -------------------------------------------------------          
C*                                                                  
C* OK, here's an old-fashioned way to get your string               
C* right-adjusted, numbers only                                     
C*  Courtesy Booth Martin, Midrange-L mailing list                  
C*                                                                  
C*  Definitions:                                                    
C*    FROM     A 15 character field that is our original data field.
C*                                                                  
C*    TARGET  A 15 character field that is our new, right adjusted, 
C*               numbers only field.                                
C*                                                                  
C*    ARI       An array; 15 elements each 1 character long, for    
C* input.                                                           
C*    ARO      An array; 15 elements each 1 character long, for    
C* output.                                                         
C*    I          A 2-digit field for an index of the ARI array.    
C*    O         A 2-digit field for an index of the ARO array.     
C*                                                                 
C* Narrative: We'll move our FROM field into the ARI array and then
C* starting  at the end (element 15) we will go backwards.         
C* As we go backwards we will check each element of ARI to see if  
C* it is a number.  If it is a number we will move it to the "O"   
C* element of ARO and decrement the index  "O" for ARO by 1.       
C* When done, we will then move our ARO array to our finish        
C* field, TARGET.                                                  
C*                                                                 
 * -------------------------------------------------------         
 * Set our array indexes (note that we are setting the array index 
 * at 15 and decrementing it  -  this gets us right adjusted):     
C                     Z-ADD15        I       20                    
C                     Z-ADD15        O       20                    
 * Move our "from" field into the array ARI:                       
C                     MOVEAFROM      ARI                           
 * Read through the array ARI, an element at a time:               
C                     DO   15                                
 * If the array element is >=0, and <=9, choose it:          
C           ARI,I     IFGE '0'                               
C           ARI,I     ANDLE'9'                               
 * It is chosen, and moved to right side of the array ARO:   
C                     MOVE ARI,I     ARO,O                   
C                     SUB  1         O                       
C                     ENDIF                                  
C*                                                           
C                     SUB  1         I                       
C                     ENDDO                                  
 * Once we are done, move the array ARO to our desired field:
C                     MOVEAARO       TARGET                  
 * Convert to a number                                       
C                     MOVE TARGET    NUMBER                  
 * ----------------------------------------------------------
 * This process will move a field like  "A1$2e45(*&6asd7"    
 *                                     to  "        1234567" 
 * ----------------------------------------------------------
C                     DUMP                                   
C                     SETON                     LR           

Here is my soapbox:
Your company should be able to see the difference between these two routines
in terms of clarity, maintainability, adaptability, expandability and
performance.  If your company chooses to stay with RPG/400 despite the
obvious benefits, what other obvious benefits is your company withholding
from you?

Buck Calabro
Aptis; Albany, NY
"Nothing is so firmly believed as
 that which we least know" -- Michel Montaigne
Visit the Midrange archives at http://www.midrange.com
+---
| 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 ...

Follow-Ups:

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.