ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Error of %DEC

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

  • Error of %DEC

    Hello guys,

    I want to convert a variable value from char to decimal.

    And meet a problem when using %DEC, error msg is :
    "The first parameter for %DEC or %DECH is not valid."

    Here is the coding :

    PF
    --
    A PUTDAT 8 0 COLHDG('Date')


    RPGLE
    -----
    D XYMD8 S 8A

    C EVAL PUTDAT = %DEC(XYMD8:8:0)


    How to solve it ?

    Thanks

  • #2
    Re: Error of %DEC

    Both of these work well here...

    Code:
    d Dec08           s              8  0                  
    d Chr08           s              8a   Inz( '20091225' )
    
    ...
    
    Monitor;                         
       Dec08 = %Dec( Chr08 : 8 : 0 );
    On-Error;                        
       Dsply Chr08;                  
    EndMon;                          
                                     
    Monitor;                         
       Dec08 = %Uns( Chr08 );        
    On-Error;                        
       Dsply Chr08;                  
    EndMon;

    Comment


    • #3
      Re: Error of %DEC

      What's the release you are on?
      Converting character into numeric using built-in-Function %DEC is not possible before release V5R2. Before you either have to use good old MOVE or call a C-Function such as atoi or atof.

      Birgitta

      Comment


      • #4
        Re: Error of %DEC

        What is the definition for the field XYMMD8? This error normally means that this field is not a character field.

        If it is a date field, then you should be able to do something like this:

        C EVAL PUTDAT = %DEC( %char( XYMD8 ) :8:0)

        or

        C EVAL PUTDAT = %DEC( %editc( XYMD8 : 'X' ) :8:0)
        Last edited by MichaelCatalani; January 21, 2010, 08:57 AM.
        Michael Catalani
        IS Director, eCommerce & Web Development
        Acceptance Insurance Corporation
        www.AcceptanceInsurance.com
        www.ProvatoSys.com

        Comment


        • #5
          Re: Error of %DEC

          I thought Atoi and Atof were the two younger brothers of Gorbachev.
          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


          • #6
            I know I'm jumping on an old thread, but I'm tired of driving myself crazy looking for this.
            How do i code the following definition of 'atoi' in free form?

            d atoi Pr 10i 0 ExtProc( 'atoi' )
            d * Value Options(*String)

            TIA

            Comment


            • #7
              dcl-pr atoi int(10) ExtProc( 'atoi' );
              *n pointer value options(*String);
              end-pr;

              In 7.3 and I think PTF'd into 7.2 you can also use:

              dcl-pr atoi int(10) ExtProc( *dclcase );

              Which helps to avoid one of my favourite problems of mis-spelling the extproc keyword value.

              Comment


              • #8
                Just remembered I wrote this up in the Geezer's Guide" series. Try this one for protos etc. https://www.itjungle.com/2014/07/09/fhg070914-story01/

                Comment

                Working...
                X