2020 May 15 9:21 AM
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?
2020 May 16 6:00 AM
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 ) inYou should use:
let t = value #( it_pr_aps_data[ YOURCOMPONENT = <FS>-ZGTA_COUNTRY_ID ]-zgta_country_id ) inIn 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).
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?
2020 May 15 10:05 AM
The first thing I see: did you put the NOT in the wrong WHEN-clause? If it is initial you take of as result.
2020 May 15 5:33 PM
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.
2020 May 15 5:39 PM
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.
2020 May 15 6:22 PM
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
2020 May 16 5:53 AM
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.
2020 May 16 6:00 AM
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 ) inYou should use:
let t = value #( it_pr_aps_data[ YOURCOMPONENT = <FS>-ZGTA_COUNTRY_ID ]-zgta_country_id ) inIn 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).
2020 May 16 6:20 AM
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
2020 May 17 9:14 AM
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 )
2020 May 18 7:36 AM
Please mark the best answer and close the question. Thank you.