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: 

How to check data type of the field symbol at run time

Former Member
0 Kudos

Hi,

My code is as following:

LOOP AT <fs> ASSIGNING <wa_covp_ext>.

ASSIGN COMPONENT 86 OF STRUCTURE <wa_covp_ext> TO <f_zzname>.

IF sy-subrc = 0.

ASSIGN COMPONENT 158 OF STRUCTURE <wa_covp_ext> TO <f_pernr>.

IF sy-subrc = 0.

SELECT SINGLE sname INTO <f_zzname> FROM pa0001

WHERE pernr = <f_pernr>

AND endda GE sy-datum

AND begda LE sy-datum.

ENDIF.

ENDIF.

ENDLOOP.

This query is giving dump when <f_zzname> is type P length 8 and decimals 2, because it tries to put PA0001-sname into it which is type C length 30. So I want to check the type of <f_zzname> before the select statement. If it is character 30, then I will write the select statement else not.

How to check data type of the field symbol at run time? If it's not possible, then can somebody suggest a workaround? Thanks.

6 REPLIES 6

Former Member

check this ...

write describe statement ...

field-symbols : <f_zzname> .

data : sname like pa0001-sname,

typ(10).

assign sname to <f_zzname>.

describe field <f_zzname> type typ.

write : typ. <-- typ contains character type in this case ..

U can check if typ is of character(C) if so .. write the select statement ...

0 Kudos

Hi Srini,

Thanks for your reply. I tried this logic, but the describe statement returns the type,length and decimals ONLY IF the field is character data type. In my code, the field symbol has values either character 30 or packed decimal length 8 decimals 2. When field symbol has packed decimal, the describe statement gives dump.

0 Kudos

You can use the CL_ABAP_TYPEDESCR class.

Grettings.

0 Kudos

Is there any FM which can be used for this purpose?

matt
Active Contributor
0 Kudos

Ashwini Kalyankar wrote:

Is there any FM which can be used for this purpose?

No. There is a class.

0 Kudos

Hi,

When you are sure which field u want to fetch (SNAME in this case), why not declare the field symbol of the same type.

Why to assign the component and all.

Hope this helps.