sponsored links

Collapse

Announcement

Collapse
No announcement yet.

Decimal to CHAR

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

  • Decimal to CHAR

    hi all,

    i need to convert a decimal field to a char field..

    here is the need for that.

    i am having a PF named PF01 and FLD1 is one of the field having field attribute of 5P 0. i want to convert the datas stored in the FLD1 of PF01 to the table TAB01 which is having a field FLD2 with attribute of char 10 not null with default.

    -------------------------------------------------
    PF's Desired o/p of o/p of
    DATA Output using using
    (5P 0) CHAR 7 DIGITS CHAR
    -------------------------------------------------
    -100.00 -100.00 10000 -100.00
    100.00 100.00 10000 100.00*
    20.00 020.00 02000 20.00**
    3.00 003.00 00300 3.00***
    0.40 000.40 00040 .40****
    0.05 000.05 00005 .50****
    ---------------------------------------------------

    where * indicates blanks.

    is there is any way simple way to get the desired output?

    thanks in advance..

  • #2
    Re: Decimal to CHAR

    sorry to post the table as a text there..

    here is the deatailed one..

    Code:
    -------------------------------------------------
       PF           Desired    o/p of     o/p of
     DATA        OUTPUT     using     using
     (5,2)             10 A     DIGITS    CHAR  
    -------------------------------------------------
    -100.00	  -100.00    10000    -100.00
     100.00	   100.00    10000    100.00*
       20.00	   020.00    02000    20.00**
         3.00	   003.00    00300    3.00***
         0.40	   000.40    00040    .40****
         0.05	   000.05    00005    .50****
    --------------------------------------------------
    thanks

    Comment


    • #3
      Re: Decimal to CHAR

      Hi

      Maybe this will help you. Try it.

      Code:
      DnNum             S              5  2 inz(-,20)                 
                                                                      
      DcNew             S             10                              
                                                                      
      C                   EVAL      cNew = %TRIM(%EDITC(nNum:'O'))
      For different editing, yust change edit code in apostrophes
      Last edited by Zdenko; July 12th, 2007, 03:29 AM.
      LP Zdenko

      Comment


      • #4
        Re: Decimal to CHAR

        Originally posted by Zdenko View Post
        For different editing, yust change edit code in apostrophes
        And if you want it right-justified, as your example shows, use EVALR instead of EVAL.
        "Time passes, but sometimes it beats the <crap> out of you as it goes."

        Comment


        • #5
          Re: Decimal to CHAR

          Hi Zdenko & littlepd.,

          Thank you for your reply to my query. And i know that with BIF %editc we can do that in RPG ILE.. but i need a sql statement to excute the same..

          I need to run a sql statement that converts a numeric field in a PF to a Character field as like in the desire format specified in my previous post..

          Comment


          • #6
            Re: Decimal to CHAR

            Hi,

            if you need it in SQL, its a little more trickier:
            Assumed you want to right adjust your converted numeric value into a 15A column, you may use the following SQL-Statement:

            PHP Code:
            select Space(15 Length(RTrim(Char(MyNum)))) concat Char(MyNum) as RightAdj
            From MyTable 
            Birgitta

            Comment


            • #7
              Re: Decimal to CHAR

              hi B.Hauser,

              Thanks a lot.. it works.. you are a gein.. man..

              Comment

              sponsored links

              Collapse

              Working...
              X