cancel
Showing results for 
Search instead for 
Did you mean: 

Char to Numeric conversion

Former Member
0 Kudos

Hi

We are running on Information Steward 4.0

I am urgently looking for a solution for a rule where I need to convert a value from a table defined character field into a numeric value. I have searched the available documentation but have not found anything.

I tried applying the Convert to Decimal but when I run the rule it fails stating "Option <to_decimal_ext> must contain a constant value, not a variable, parameter, or column reference"

appreciate your help

regards

Ed

Accepted Solutions (0)

Answers (2)

Answers (2)

former_member655569
Participant
0 Kudos

Can you provide more information on the exact requirement. We use IS and never came across this kind of requirement.

Former Member
0 Kudos

Example below shows the rule where the field dbo.CLASSIFICATION.CHAR_VALUE = varchar

I need to report as error where Z1_GDS_STOR_TEMP_MAX / CHAR_VALUE < Z1_GDS_STOR_TEMP_MIN / CHAR_VALUE

in order to do this I need to convert the value to numeric

I tried the Function "Convert to decimal" in IS rule build but the fails with error message

"Option <to_decimal_ext> must contain a constant value, not a variable, parameter, or column reference."

DECLARE

    $MaxTemp decimal(4, 0);
    $MinTemp decimal(4, 0);

#Scenario 07/ Rule 179:

BEGIN

$MaxTemp = lookup('ECC_SIRS_PRD_MAT Sirius Production Material Data', 'dbo.CLASSIFICATION', 'MATERIAL_NUMBER', $MATNR, 'CHARACTERISTIC', 'Z1_GDS_STOR_TEMP_MAX', 'CHAR_VALUE', null);
$MinTemp = lookup('ECC_SIRS_PRD_MAT Sirius Production Material Data', 'dbo.CLASSIFICATION', 'MATERIAL_NUMBER', $MATNR, 'CHARACTERISTIC', 'Z1_GDS_STOR_TEMP_MIN', 'CHAR_VALUE', null);

IF (to_decimal($MaxTemp, null, null, 4, null) < to_decimal($MinTemp, null, null, 4, null))
RETURN FALSE;
ELSE RETURN TRUE;

END

thanks

Ed

former_member655569
Participant
0 Kudos

If you are using IS4.1 and higher version, there is a option to add derived columns in IS view.

Create a column of type decimal and populate it with CHAR_VALUE column.

Create a Parameter of type decimal in rule and try using it in definition.

former_member184958
Active Participant
0 Kudos

Hi E,

From Character to Numeric,

DATA: lv_chr(4) type c,

      lv_num    type p.

CALL FUNCTION 'MOVE_CHAR_TO_NUM'

  EXPORTING

    CHR             = lv_chr

  IMPORTING

    NUM             = lv_num

  EXCEPTIONS

    CONVT_NO_NUMBER = 1

    CONVT_OVERFLOW  = 2

    OTHERS          = 3.

IF SY-SUBRC <> 0.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

If you want string to decimals use the following,

FIELD-SYMBOLS <BETRG> TYPE any.

DATA lv_BETRG TYPE p DECIMALS 2.

CALL FUNCTION 'HRCM_STRING_TO_AMOUNT_CONVERT'

   EXPORTING

     string                    = '234123477'

    DECIMAL_SEPARATOR         = '.'

    THOUSANDS_SEPARATOR       = ','

    WAERS                     = ' '

  IMPORTING

    BETRG                     lv_BETRG

  EXCEPTIONS

    CONVERT_ERROR             = 1

    OTHERS                    = 2

           .

IF sy-subrc <> 0.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

WRITE lv_BETRG.

Hope This will solve your problem.