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: 

Checking value in a structure

Former Member
0 Kudos

I have a structure with 16 fields.

Only one of them contains a value while others are blank.

How do I check which field contains the value?

5 REPLIES 5

Former Member
0 Kudos

hi

no shortcut . you have to chek all the fields. i faced the same issue. Only thin which you can do after geeting value in one field skip testing of rest of the fields.

Aditya

0 Kudos

How do I skip the testing the rest of the fields after the value is found in one field?

If I use EXIT satement, it comes out of the method while I need it to come out of the If condition only.

Former Member
0 Kudos

Hi,

You can do it in 2 ways,

1. print them in report with WRITE statement and get it.

OR

2. use condition STATEMENT with

IF (strname)-(Fieldname1) IS NOT INITIAL.

write: (strname)-(Fieldname1).

ELSEIF (strname)-(Fieldname2) IS NOT INITIAL.

write: (strname)-(Fieldname2). .

.

.

.

.

.

.

ENDIF.

regards,

Anirban

Former Member
0 Kudos

hi

no shortcut . you have to chek all the fields. i faced the same issue. Only thin which you can do after geeting value in one field skip testing of rest of the fields.

Aditya

Former Member
0 Kudos

Hi,

maybe this is helpful:


DATA gs_structure TYPE z_structure.

DATA gx_struc TYPE REF TO cl_abap_structdescr.
FIELD-SYMBOLS <gs_components> TYPE abap_compdescr.
FIELD-SYMBOLS <gv_field> TYPE ANY.

gx_struc ?= cl_abap_typedescr=>describe_by_data( gs_structure ).

LOOP AT gx_struc->components ASSIGNING <gs_components>.
  ASSIGN COMPONENT <gs_components>-name OF STRUCTURE gs_structure TO <gv_field>.
  CHECK NOT <gv_field> IS INITIAL.
* do something
  EXIT.
ENDLOOP.

Regards Rudi