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: 

Please help with data type declaration

Former Member
0 Kudos

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

1 ACCEPTED SOLUTION

Former Member
0 Kudos

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

12 REPLIES 12

Former Member
0 Kudos

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

Former Member
0 Kudos

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

0 Kudos

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

0 Kudos

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

0 Kudos

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

0 Kudos

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?

0 Kudos

try this.

CREATE DATA <y_value> TYPE char20.

awrd points if useful

Bhupal

0 Kudos

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?

0 Kudos

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

0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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