ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Help with writing a program to update numeric from alpha

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help with writing a program to update numeric from alpha

    Hello Everyone,

    I am new born to RPG. I have created a PF named PF9
    Code:
     A                                          UNIQUE                      
     A              R RPF9                                                  
     A                ALPHAN        25A         TEXT( 'ALPHA NUMERIC DATA') 
     A                NUMENRIC      25S 0                                   
     A              K ALPHAN
    Records in the PF9 are
    Code:
    Line   ....+....1....+....2....+....3....+....4....+....5....+....6.   
           ALPHAN                                              NUMENRIC    
    000001 11dagaoioiwoiu817¢8263eio                                  0    
    000002 ieouyp298364 jGW*&¢732891                                  0    
    000003 ¢9oi0898ouigh83y8                                          0    
    000004 jsewhi36¬8¬ohilho9                                         0    
    000005 bdeufy86&¢kjeou3j2978                                      0
    I want to create a RPGLE program where i can remove all the numbers from the ALPHAN and move it to Numeric.

    Thanks in advance for the help.

    Regards
    Nilesh

  • #2
    Re: Problem with Special characters

    give an example of what you are looking for in the data.
    Hunting down the future ms. Ex DeadManWalks. *certain restrictions apply

    Comment


    • #3
      Re: Problem with Special characters

      Since your question is not related at all to the original discussion here, could you please start a new thread? This would make it much easier for me to understand and follow this discussion. (Though, perhaps the folks who run this forum can just move your messages so you don't have to re-type what you've already posted.) I would appreciate it.

      If it helps, you can start a new thread by:
      • Go here: http://www.code400.com/forum/forum.php
      • Click the forum where your discussion fits. In this case, click "RPG/RPGLE" because you have an RPG question.
      • Click "Post new thread" to start a new thread.


      That would help a lot.

      Also, if you could please put [code] before your code/file examples, and [/code] afterwards, that would help a lot, too. Without these it's hard to see which part of your file data is in the alpha field and which part is in the numeric field. That makes your question difficult to answer.

      Thanks a lot!

      Comment


      • #4
        Re: Help with writing a program to update numeric from alpha

        moved to a new thread in "Freshers"
        I'm not anti-social, I just don't like people -Tommy Holden

        Comment


        • #5
          Re: Help with writing a program to update numeric from alpha

          Thanks, Tommy.

          So, Nilesh3110.. here's an example that _might_ do what you want. (It wasn't clear what to do when there was a bunch of different groups of numbers in the 'alphan' field... use them all?)

          Code:
               FRPF9FILE  UF   E           K DISK
          
               D                 ds
               D  char                          1a
               D  bin                           3u 0 overlay(char)
          
               D NUMENRIC_LEN    C                   %len(NUMENRIC)
               D NUMENRIC_DEC    C                   %decpos(NUMENRIC)
          
               D x               s             10i 0
               D nonnum          s            256a   varying
               D blanks          s            256a   varying
          
                /free
                   // Set up translation strings that contain all non-numeric
                   // characters.
          
                   for x = 1 to 256;
                     bin = x - 1;
                     if not (char >= '0' and char <= '9');
                        nonnum += char;
                        blanks += ' ';
                     endif;
                   endfor;
          
          
                   // Spin through the file and update the 'numenric' (sic)
                   //  field.
          
                   setll *start RPF9FILE;
                   read RPF9FILE;
                   dow not %eof(RPF9FILE);
                      Numenric = %dec( %xlate(nonnum: blanks: alphan)
                                     : NUMENRIC_LEN
                                     : NUMENRIC_DEC );
                      update RPF9;
                      read RPF9FILE;
                   enddo;
          
                   *inlr = *on;
          
                /end-free
          What happens is that we create a string ('nonnum') that contains all possible char values _except_ numeric digits. Then, we can use that string with %XLATE() to convert all non-numeric fields into blanks. Then the %DEC() BIF converts the digits into a number. (%DEC will ignore blanks.)

          The result looks like this:
          Code:
           Line   ....+....1....+....2....+....3....+....4....+....5....+....6. 
                  ALPHAN                                              NUMENRIC  
           000001 11dagaoioiwoiu817¢8263eio                        118,178,263  
           000002 ieouyp298364 jGW*&¢732891                    298,364,732,891  
           000003 ¢9oi0898ouigh83y8                                 90,898,838  
           000004 jsewhi36¬8¬ohilho9                                     3,689  
           000005 bdeufy86&¢kjeou3j2978                              8,632,978
          Is that what you were looking for?

          Comment

          Working...
          X