Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Getting error as 'BD' cannot be converted to number

munikov
Discoverer
0 Kudos

I am using the for iteration with condition i am getting the error .

Could you please help me with the same?

Here is the syntax for the same.

DATA(lt_final_data) = VALUE tt_product_price( FOR <fs> IN it_pr_aps_data
( zgta_country_id = COND #( let t = VALUE #( it_pr_aps_data[ <fs>-zgta_country_id ]-zgta_country_id ) in
WHEN t is INITIAL
THEN t
when t is not INITIAL
then
VALUE #( it_gex047it[ ziso_country_code = <fs>-zgta_country_id ]-zgta_country_id_1
DEFAULT ' ') )

What i am doing wrong here?

1 ACCEPTED SOLUTION

Sandra_Rossi
Active Contributor

The issue is in the words in UPPER CASE of this line:

let t = value #( it_pr_aps_data[ <FS>-ZGTA_COUNTRY_ID ]-zgta_country_id ) in

You should use:

let t = value #( it_pr_aps_data[ YOURCOMPONENT = <FS>-ZGTA_COUNTRY_ID ]-zgta_country_id ) in

In the table expression, if you don't indicate "yourcomponent =", the argument is meant to be a numeric row index. If the variable is not numeric there is an attempt to convert it into a number (and does a runtime error CONVT_NO_NUMBER if it's not).

9 REPLIES 9

BiberM
Active Participant
0 Kudos

The first thing I see: did you put the NOT in the wrong WHEN-clause? If it is initial you take of as result.

Jelena
Active Contributor
0 Kudos

Check your variable definitions. According to the message, you're attempting to assign a character type value ('BD') to a numeric variable.

To be honest, this is where I feel the newfangled syntax with VALUE and COND is not actually beneficial. It could also be due to lack of formatting and cryptic names but I'm honestly having trouble reading this code and understanding what it's supposed to do.

BiberM
Active Participant

Based on Jelenas thoughts:

The type of variable t is derived upon first assignment. In Let you used # to derive the type automatically. Try giving it a specific type instead.

Sandra_Rossi
Active Contributor
0 Kudos

I second Jelena, it's difficult to read your code. Please use the CODE button to format your code, and try to use the indentation!

Michael Biber gave the right answer.

NB: simply your code: instead of

when t is not INITIAL
then

use

else

Sandra_Rossi
Active Contributor
0 Kudos

Thank you.

You may also use CODE only on the code block, not on the whole comment, like this:

DATA(lt_final_data) = VALUE tt_product_price( 
  FOR <fs> IN it_pr_aps_data
  ( zgta_country_id     = COND #( 
                          LET t = VALUE #( it_pr_aps_data[ <fs>-zgta_country_id ]-zgta_country_id ) IN
                          WHEN t IS INITIAL THEN t
                          ELSE VALUE #( it_gex047it[ ziso_country_code = <fs>-zgta_country_id ]-zgta_country_id_1 DEFAULT ' ') )
    zgta_reporting_comp = <fs>-zgta_reporting_comp
    zupc                = <fs>-zupc
    zeffective_date     = <fs>-zeffective_date
    zvldto              = <fs>-zvldto
    zprice_code         = <fs>-zprice_code ) ).

And use indentation to align the blocks.

Sandra_Rossi
Active Contributor

The issue is in the words in UPPER CASE of this line:

let t = value #( it_pr_aps_data[ <FS>-ZGTA_COUNTRY_ID ]-zgta_country_id ) in

You should use:

let t = value #( it_pr_aps_data[ YOURCOMPONENT = <FS>-ZGTA_COUNTRY_ID ]-zgta_country_id ) in

In the table expression, if you don't indicate "yourcomponent =", the argument is meant to be a numeric row index. If the variable is not numeric there is an attempt to convert it into a number (and does a runtime error CONVT_NO_NUMBER if it's not).

0 Kudos

Hi

Is it necessary to read the IT_PR_APS_DATA record again? <FS> is just that, a IT_PR_APS_DATA record.

regards,
Mateusz

Sandra_Rossi
Active Contributor
0 Kudos

This is not clean code.

don't:

COND #( WHEN x IS INITIAL THEN value1
        WHEN x IS NOT INITIAL THEN value2 )

do:

COND #( WHEN x IS INITIAL THEN value1
        ELSE value2 )

Sandra_Rossi
Active Contributor

Please mark the best answer and close the question. Thank you.