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



Brian,

How about this?

     H BNDDIR('ISOCKETS/ISOCKETS')
      /COPY iSOCKETS/QCPYSRC,isockets
     D CtrlNbr         DS
     D  a1                            1A
     D  a2                            2A
     D  i1                            3U 0 Overlay(a1)
     D  s2                            2S 0 Overlay(a2)

     C                   callp     CvtToASCII(ctrlnbr.a1:%size(ctrlnbr.a1))
     C                   eval      ctrlnbr.i1 += 1
     C                   callp     CvtFromASCII(ctrlnbr.a1:%size(ctrlnbr.a1))

Since "adding 1" to the ASCII code, effectively does what you want, why not use
ASCII? The above code uses the CvtTo/FromASCII function in the free iSockets
service program. I used a DS with overlays but you don't strictly need to do
that.  If you don't have iSockets, you can download it for free from
www.isockets.net

If you still don't want t use iSockets (I don't know why you wouldn't) you could
use a %USC2() value an achieve similar results, but it isn't as direct.

-Bob Cozzi
www.iSeriesTV.com
iPod your industry news instead of reading it.
Coming June 2006
Ask your friends to tune into iSeriesTV.com


-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx] On
Behalf Of Marco Facchinetti
Sent: Tuesday, May 30, 2006 12:54 PM
To: RPG programming on the AS400 / iSeries
Subject: RE: Add to Character Value

This fantastic peace of code is a subset of our numbering procedure, if you
like it just play with it...

HTH
Marco

A          R T1                                               
A*%%TS  SD  20060530  185307  MUM         REL-V5R3M0  5722-WDS
A                                      CA03                   
A                                  1 29'Test NUME'            
A                                      DSPATR(HI)             
A                                  4  5'Initial number...:'   
A            C1            12A  B  4 28                       
A                                  5  5'Len..............:'   
A            LEN            2Y 0B  5 28EDTCDE(2)              
A                                  6  5'Increment........:'   
A            INCR           2Y 0B  6 28EDTCDE(2)              
A                                  7  5'Risultato........:'   
A            C3            12A  O  7 28                       
A                                 23  3'F3=Uscita'            

h dftactgrp(*no)                                                           
fnumev     cf   e             workstn                                      
d                sds                                                       
dprogramma          *proc                                                  
dutente                 254    263                                         
dnume             pr            12                                         
d source                        12    const                                
D len                           10i 0 const                                
D increment                     10i 0 const                                
 /free                                                                     
  dow 1 = 1;                                                               
    exfmt t1;                                                              
    if *inkc = *on;                                                        
      leave;                                                               
    endif;                                                                 
    c3 = nume(c1:len:incr);                                                
  enddo;                                                                   
  *inlr = *on;                                                             
  return;                                                                  
 /end-free                                                                 
 **************************************************************************
p nume            b                                                        
dnume             pi            12                                         
d source                        12    const                                
D len                           10i 0 const                                
D increment                     10i 0 const                                
d*-------------------------------------------------------------------------
d si              s              1    inz(*on)                             
d no              s              1    inz(*off)                            
d*alfa            c                   '0123456789ABCDEFGHIJKLMNOPQRSTUVWXY-
d*                                    Z'                                   
d alfa            c                   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'         
d numero          s             12                                         
d num             s             12    varying                              
d i               s             10i 0                                      
d p               s             10i 0                                      
d resto           s             10i 0                                      
d*-------------------------------------------------------------------------
 /Free                                                                     
      if len > 0;                                                          
        p = len;                                                           
      else;                                                                
        p = %len(source);                                                  
      endif;                                                               
      if increment > 0;                                                    
        resto = increment;                                                 
      else;                                                                
        resto = 1;                                                         
      endif;                                                               
      if source    <> *blanks;      // Primo "numero" calcolato            
        num = %subst(source : 1 : len);                                    
        dow resto > 0;                                                     
          i = %scan(%subst(num:p:1):alfa) + resto;                         
          resto = %len(alfa)-i;                                            
          if resto >= 0;                                                   
            %subst(num:p:1) = %subst(alfa:i:1);                            
            leave;                                                         
          else;                                                            
            i=%abs(resto)-%int(%abs(resto)/%len(alfa))*%len(alfa);         
            %subst(num:p:1)=%subst(alfa:i:1);                              
            resto = %int(%abs(resto)/%len(alfa))+1;                        
          endif;                                                           
          p-=1;                                                            
        enddo;                                                             
      else;                       // La base minima non è 0 ma AAA.        
        for i=1 to p;                                                      
          num += %subst(alfa:1:1);                                         
        endfor;                                                            
      endif;                                                               
    numero = num;                                                          
    return numero;                                                         
 /End-free                                                                 
p nume            e                                                        

--- Brian Piotrowski <bpiotrowski@xxxxxxxxxxxxxxx> wrote:

Hi Marco,

This problem stems from some legacy code we have at our facilities.  The
original programmers did not leave enough room for an acceptable amount
of characters in the field.

The field is defined as 3A.  This field is part of a control number that
is used in a multitude of programs (that will eventually need to be
rewritten at a future date).  Unfortunately, we have occasions where the
control number exceeds 999.  When this occurs, the system has been
written to flip the first digit to an alpha character.  Thus when the
999 threshold is exceeded, the new control number becomes A01.  Further
to that, when A99 is the last control number and a new record is
created, the next control number becomes B01.  

And so on...C01, D01, ad nauseum.

So what we're looking at is something that will detect when x99 is
reached and flip to the next alpha character in sequence.

So based on this, we'd be looking for some code similar to this:

If FLDX = 99 then
  If subst(FLDX:1:1) = A
    NewCTRLNum = CHAR(subst(FLDX:1:1)+1) + '01'
  Endif;
Endif;

The question is - is there an equivalent to CHAR() in RPG?  Essentially
we'd need to find the hex or decimal value of the next available
character.  For example, if A = char(1) and B = char(2), when we did a
Char(1+1), we'd get B as the next character.

I hope this response hasn't confused or made the process sound more
complicated than it is.

Brian.




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.