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



Marvin Radding wrote:
> 
> I am attempting to use %EDITW to create a character field for a delimited 
> file.
> ...
> I have two problems.
> 
> 1. The first character of the number is blank when I want it to be zero. (Not 
> the negative sign)
> 2. I can't get a leading negative sign.
> 
> Any ideas on how to get the leading negative sign to appear and other than 
> %subst how do I get the leading zero to appear?


I don't think there's any way to get a leading minus sign with an edit
word.  The documentation says "For the minus sign to be considered as a
status, it must be the last character in the edit word".

Below is a procedure that can fix up any edited value so it has leading
zeros and a leading sign.  It would be nicer to call a procedure that
just has a numeric parameter of the exact type (length and decimals) of
fields you want to edit, but if you have lots of different types of
fields to edit this way, it's might be easier to call with a %EDITC in
the parameter, than to figure out exactly which procedure to call for
that particular type.  The %EDITC way has the advantage of not needing
to be changed if the size of the variable changes.

Call it like this, with edit code 'P' (adds a leading negative sign, and
doesn't suppress zero):

   string = editFillZeros (%editc(num:'P'));   // string = '
00000000014.56' 
   string = editFillZeros (%editc(neg:'P'));   // string =
'-00000000014.56' 

And another procedure that could be used to fix up similar edited values
to have parentheses for negative values:

   string = editParens (%editc(num:'P'));         // string = '         
14.56 '  
   string = editParens (%editc(neg:'P'));         // string = '        
(14.56)'  
   string = editParens (%editc(num:'P') : '0');   // string = '
00000000014.56 '  
   string = editParens (%editc(neg:'P') : '0');   // string =
'(00000000014.56)'  
   string = editParens (%editc(num:'P') : '*');   // string = '
*********14.56 '  
   string = editParens (%editc(neg:'P') : '*');   // string =
'(*********14.56)'  

Both procedures have been tested a bit, but not thoroughly.

P editFillZeros   B                                                
D editFillZeros   pi           100a   varying                      
D   editedNum                  100a   varying const                
D retval          s            100a   varying                      
D isNegative      s               n                                
 /free                                                             
                                                                   
    isNegative = %scan('-' : editedNum) > 0;                       
                                                                   
    // set up the returned value with leading zeros instead of    
    // leading blanks, and either a blank or a negative sign        
    // added to the beginning of the edited value.                 
    //    '  -1.23'   -->   '-0001.23'                             
    //    '   1.23'   -->   ' 0001.23'                             
    retval = ' ' + %xlate(' -' : '00' : %trimr(editedNum));        
    if isNegative;                      
       %subst(retval : 1 : 1) = '-';    
    endif;                              
    return retval;                      
 /end-free                              
P editFillZeros  
E                                                                               
      


P editParens      B                                                
D editparens      pi           100a   varying                      
D   editedNum                  100a   varying const                
D   fillValParm                  1a   const options(*nopass)       
D retval          s            100a   varying                      
D parensPos       s             10i 0                              
D fillVal         s              1a   inz(' ')                     
D signPos         s             10i 0 inz(1)                       
 /free                                                             
                                                                   
    if %parms > 1;                                                 
       fillVal = fillValParm;                                      
    endif;                                                         
                                                                   
    signPos = %scan('-' : editedNum);                              
                                                                   
    // set up the returned value either with '(' replacing the     
    // '-' and with ')' just after the non-blank data,              
    // if the value was negative.  Otherwise, just add a blank      
    // after the value.                                             
    // - if fillVal is blank                                        
    //    '  -1.23'   -->   '  (1.23)'                              
    //    '   1.23'   -->   '   1.23 '                              
    // - if fillVal is '0'                                          
    //    '  -1.23'   -->   '(001.23)'                              
    //    '   1.23'   -->   ' 001.23 '                              
    // - if fillVal is '*'                                          
    //    '  -1.23'   -->   '(**1.23)'                              
    //    '   1.23'   -->   ' **1.23 '                              
    if signPos > 0;                                                 
       retval = %xlate('- ':fillVal + fillVal : editedNum);         
       if fillVal <> ' ';                                           
          signPos = 1;                                              
       endif;                                                
       %subst(retval : signPos : 1) = '(';                   
       retval = retval + ')';                                
    else;                                                    
       retval = %xlate(' ':fillVal : editedNum : 2) + ' ';   
    endif;                                                   
    return retval;                                           
 /end-free                                                   
P editparens      E


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.