Unconfigured Ad Widget

Collapse

Announcement

Collapse
No announcement yet.

Numeric Field - Character Field

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

  • Numeric Field - Character Field

    I wish to move a numeric field into a character field, but the numeric may sometimes be negative. How can I move the value and represent/retain the negative symbol? When I try just MOVEL I get unpredictable characters in the field. (RPG4) Thanks.. Katy

  • #2
    Numeric Field - Character Field

    Use the %editc() function (or %editw()) to put a formatted string in the variable.

    Comment


    • #3
      Numeric Field - Character Field

      Katy, %char is another option. David Morris

      Comment


      • #4
        Numeric Field - Character Field

        Katy, Michael and David give good exampes. Me however, I like to use brute force when doing this, such as: c if num_field < 0 c eval num_field = num_field * -1 c movel num_field char_field c move '-' char_field c else c move num_field char_field c endif I know I can do this with %char() and concatenation, but sometimes, good old fashioned code works for me. Hope this helps, Bret

        Comment


        • #5
          Numeric Field - Character Field

          When I try just MOVEL I get unpredictable characters in the field.
          What you get should be predicatable. All bytes except the last should have digits in them. The last one is '}' for a negative number ending in zero, and J-R for numbers ending in 1-9.

          Comment


          • #6
            Numeric Field - Character Field

            That's the way I did it in the end. Good old fashioned RPG... and it works. Cheers. Kate

            Comment


            • #7
              Numeric Field - Character Field

              The old-fashioned brute force method works, yes ... Will you create a new character temporary for numeric fields with different lengths to avoid getting results of "12 -"? Wouldn't you rather see "-12" than "12-"? How will you handle numbers with decimal positions? The "good old-fashioned" technique for that takes a couple of pages of code. By the way, make sure you use the (P) extender on the MOVE(L)s. Otherwise, if you have a negative value (say 27-) followed by a positive value (say 13), the result for 13 will be "213" rather than " 13". Katy, I'd reconsider using several lines of code vs a single line with %CHAR or %EDITC. Besides the shorter code, the builtin functions will adjust themselves automatically to changes in the number of digits in your number; your code will require manual adjustment.
               * With %EDITC, you choose the formatting based on the edit code * If you really want the sign on the right, use edit code 'L' C EVAL string = %EDITC(num : 'P') * With %CHAR, you get "naturally" formatted numbers ("-12", "7.6800" etc) C EVAL string = %CHAR(num) 
              Barbara Morris

              Comment


              • #8
                Numeric Field - Character Field

                Barbara, Thanks. I will give these a try and evaluate them. I'm sure they do what you say, I'm just old-fashioned. Bret

                Comment


                • #9
                  Numeric Field - Character Field

                  I really didn't know that I would spark off such a debate! A little background from me might explain why I went the route I did. I'm an RPG400 person really, and have only just started to use RPG4 (no training or anything) purely because I had some awkward date manipulation to do and SUBDUR fitted the bill perfectly. I haven't either seen or used any of the fancy expressions that RPG4 seems to use, so I'm steering well clear until I've had some training/demonstrations/guidance. Thanks for all your help. DO any of you know of a good text book to guide me into conversion from RPG400 to this ILE RPG4 malarky? Kate

                  Comment


                  • #10
                    Numeric Field - Character Field

                    Katy, Go to the IBM book manager site. It's free and there are hundreds of books there. Many of them for RPG/IV/ILE, CL, DDS, and so on. The books on DB2 and SQL are great. You can view these with Acrobat Reader. http://publib.boulder.ibm.com/pubs/h...ne/v4r4eng.htm If you don't have Acrobat Reader, it will download for you at this site when you attempt to open a book using the PDF version. I reccomend the PDF version as the FIND facility of Acrobat is great.You can print from this site, using Acrobat Reader, by book, or specified pages of the book. There is also a "redbook" called 'Who knew you could do that with RPG IV: A Sorcer's Guide to system access and more' which sells for $20.00 (i recommend getting your own copy and mark it up. This is an excellent source of information. http://www.redbooks.ibm.com/abstracts/sg245402.html There are books on system management, security, operations, back up, subfiles, dds, cl, db2, etc, etc. You have to register for the redbook site now, but it too, is free. Hope this helps, Bret

                    Comment


                    • #11
                      Numeric Field - Character Field

                      How about: Eval charfield = %char(numericfield) I believe you must be at V4R4 to support this though. Dan

                      Comment

                      Working...
                      X