01-09-2008 10:25 AM
Hi All,
I have declared a field as data type P, but only inside my ELSE condition i want to change it to data type C with a length of 20. Outside of this ELSE loop it should remain as P only.
Is it possible? & if yes how should i do it?
Await inputs.
Vivek
01-09-2008 10:29 AM
Hi Vivek
Please use the syntax CREATE DATA which will help you to create the data varaibles dynamically. You can find more info. in SAP HELP.
~ Ranganath
01-09-2008 10:27 AM
Declare another variable with type C and size 20.
In ur Else condition copy ur value into another variable which is of type C and size 20.
Perform ur operations on that Character variable in ur Else block.
awrd points if helpful
Bhupal
01-09-2008 10:29 AM
Hi Vivek
Please use the syntax CREATE DATA which will help you to create the data varaibles dynamically. You can find more info. in SAP HELP.
~ Ranganath
01-09-2008 10:39 AM
Hi Ranganath,
Thanks for the info, i tried as below
CREATE DATA Y_VALUE TYPE C(20).
But system prompts:
"Y_VALUE" is not a field reference.
I think this is because Y_VALUE is defined as an additional field in my infoset. So how should i declare it in this case?
Await inputs.
Vivek
01-09-2008 10:47 AM
Hi Vivek
Your declaration should look something like this
**********************************************
constants : l_c_p value 'DMBTR',
l_c_char type char 6 value 'CHAR20'.
DATA : l_ref_data TYPE REF TO data.
field-symbols : <l_fs> type any.
if <cond1> .
CREATE DATA l_ref_infty_data TYPE (l_c_p).
ASSIGN l_ref_data->* TO <l_fs>.
else.
CREATE DATA l_ref_infty_data TYPE (l_c_char).
ASSIGN l_ref_data->* TO <l_fs>.
endif.
*********************************************************
Now your field symbols <l_fs> will be of either P or CHAR20 based on the condition.
Hope this helps !
~ Ranganath
01-09-2008 10:47 AM
Check this example:
DATA: dref TYPE REF TO DATA.
FIELD-SYMBOLS: <fs> TYPE ANY.
" Create object of type SBOOK and attach the field symbol
CREATE DATA dref TYPE sbook.
ASSIGN dref->* TO <fs>.
awrd points if useful
Bhupal
01-09-2008 11:09 AM
I have done as below, but still get error
DATA : l_ref_data TYPE REF TO data.
field-symbols: <Y_VALUE> type any.
Inside my IF condition
CREATE DATA Y_VALUE TYPE BSEG-WRBTR.
..
..
..
ASSIGN l_ref_data->* TO <Y_VALUE>.
In ELSE condition
CREATE DATA Y_VALUE TYPE C(20).
Y_VALUE = 'No value'.
ASSIGN l_ref_data->* TO <Y_VALUE>.
ENDIF.
But still syntax check says
"Y_VALUE" is not a field reference.
May i know what mistake i have done?
01-09-2008 11:16 AM
try this.
CREATE DATA <y_value> TYPE char20.
awrd points if useful
Bhupal
01-09-2008 11:22 AM
i think i am facing this issue because Y_VALUE is a extra node.
i.e. i have defined Y_VALUE as a extra node in my infoset in the extras tab.
So in this case how should i define it?
01-09-2008 11:26 AM
Hi Vivek
Please try this code
DATA : l_ref_data TYPE REF TO data.
field-symbols: <Y_VALUE> type any.
Inside my IF condition
CREATE DATA l_ref_data TYPE BSEG-WRBTR.
..
..
..
ASSIGN l_ref_data->* TO <Y_VALUE>.
In ELSE condition
CREATE DATA Y_VALUE TYPE CHAR20.
ASSIGN l_ref_data->* TO <Y_VALUE>.
<Y_VALUE> = 'No value'
ENDIF.
~ Ranganath
01-10-2008 3:04 AM
Hi Ranganath,
I have entered the code as mentioned by you in ELSE condition, the syntax check is ok, but the query on execution throws a dump & the error analysis reads
Error Analysis:
The first operand entered at CREATE DATA is not a data reference
How to resolve this error?
Vivek
01-09-2008 10:45 AM
Hi
Vivek
no it is not at all possible to declare one with variable with one type in one place and as anothre type in another place where as this type of declaration is only possible wih field string
01-09-2008 10:58 AM
Hi Vivek,
you can try defining two variables and use field-symbol to change pointer as you desired..
Of course, you will not be able to use same variable, but data will be stored in 2 different variables,
Regards,
Mohaiyuddin