ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Char into Digits

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

  • Char into Digits

    I have a 20 character field. The first 9 characters represents the social security number. I have to chain out to a numeric field in another database. What is the best way to do this.

    Example

    20 character field = '145339999 '

    Need to take out the 14533999 and move it to a numeric field for chaining out to another file.

    Thanks,

    DAC

  • #2
    Re: Char into Digits

    well I would frst make sure all we decimal using %check

    Code:
    if        %check(' 0123456789': S4FWIDTHIN) > 0 ;
        then there be characters in my decimal field
    endif;
    Then just use %dec
    Code:
    d JUL             s               d   datfmt(*JUL)          
    d TSTJUL          s               d   datfmt(*JUL)          
    d fileJUL8        s              7  0 inz(2006268)          
    d fileJUL6        s              5  0                       
    
    FileJUL6 =                             
    %dec(%subst(%char(fileJUL8):3:5):5:0)
    All my answers were extracted from the "Big Dummy's Guide to the As400"
    and I take no responsibility for any of them.

    www.code400.com

    Comment


    • #3
      Re: Char into Digits

      SSN = %dec(%subst(fieldA:1:9))

      Comment


      • #4
        Re: Char into Digits

        First convert that char num to dec and store in some var, and then use that var to chain withthe numeric database.

        SSN= %dec(%subst(fld : 1 : 9))

        bye....
        'Coding = Experience'
        hsp

        Comment


        • #5
          Re: Char into Digits

          Just to be different. You could set up a Data Structure (if the position of the numeric is always in the same place). Then, just assign the value of the variable to the data structure and reference the numeric part of the DS.

          Or, am I oversimplifying things?

          Comment


          • #6
            Re: Char into Digits

            Originally posted by FaStOnE View Post
            Just to be different. You could set up a Data Structure (if the position of the numeric is always in the same place). Then, just assign the value of the variable to the data structure and reference the numeric part of the DS.

            Or, am I oversimplifying things?
            (1) Your method uses 3 LOC, the other only 1. So, it costs 1/3 as much

            (2) It is much cooler to use a bif-in-a-bif than a plain ole DS

            (3) Your method also works in obsolete versions of RPG (like RPG-III) - yuck!

            Comment


            • #7
              Re: Char into Digits

              Originally posted by arrow483 View Post
              (3) Your method also works in obsolete versions of RPG (like RPG-III) - yuck!
              Move the relevant bit to a shorter char field and then do TESTN
              Regards

              Kit
              http://www.ecofitonline.com
              DeskfIT - ChangefIT - XrefIT
              ___________________________________
              There are only 3 kinds of people -
              Those that can count and those that can't.

              Comment


              • #8
                Re: Char into Digits

                Hey!! I represent the budding FEW programmers that still appreciate the simpler things in life... like Pocket Protectors and Slide Rules! It's time for the computer geek to rise up and take over his domain! Remember the downtrodden! Never relinquish the outdated source! Just take it upon yourself to stand up and yell "@#%@#%@#%@#%!!!!!"

                Now .. don't ya feel much better!!!

                Comment


                • #9
                  Re: Char into Digits

                  I find that pounding your fist on the desk and knocking your pencil cup on the floor in a fit of programming rage always helps

                  Isn't one aspect of programming backwards compatibility. I think Rick is doing a fine job with his example. Sure it may not be a complicated as nested BIFs but in his simplicity he has made the code more flexible and accepted by more systems
                  Your future President
                  Bryce

                  ---------------------------------------------
                  http://www.bravobryce.com

                  Comment


                  • #10
                    Re: Char into Digits

                    Isn't one aspect of programming backwards compatibility. I think Rick is doing a fine job with his example. Sure it may not be a complicated as nested BIFs but in his simplicity he has made the code more flexible and accepted by more systems
                    Hey, I was just kidding him. Both ways work.

                    Comment


                    • #11
                      Re: Char into Digits

                      its all good fun arrow. my post was in complete sarcasm
                      Your future President
                      Bryce

                      ---------------------------------------------
                      http://www.bravobryce.com

                      Comment


                      • #12
                        Re: Char into Digits

                        Heck! I know I'm a Munson!

                        (Post here if you know what movie that line came from...)

                        Comment


                        • #13
                          Re: Char into Digits

                          "Kingpin"?
                          "Time passes, but sometimes it beats the <crap> out of you as it goes."

                          Comment


                          • #14
                            Re: Char into Digits

                            *Ding* *Ding* *Ding* *Ding*

                            We have a winner!

                            Comment


                            • #15
                              Re: Char into Digits

                              Woohoo! I've always wanted to be a wiener!
                              "Time passes, but sometimes it beats the <crap> out of you as it goes."

                              Comment

                              Working...
                              X