2013 Jan 25 4:16 PM
Hi Guys,
I would like to get all fields and values from an structure dynamically, How I could do this?
Thanks
2013 Jan 25 4:18 PM
Hi Guys,
I would like to get all fields and values from an structure dynamically, How I could do this?
Thanks
2013 Jan 25 4:18 PM
2013 Jan 25 4:30 PM
2013 Jan 25 4:47 PM
An F1 help on the keyword will be helpful.
You will need to have a DO loop inside which you will have to use the ASSIGN COMPONENT statement.
i = 1.
DO.
ASSIGN COMPONENT i OF ls_struc TO <field_value>.
IF <field_value> IS NOT ASSIGNED.
EXIT.
ENDIF.
i = i + 1.
ENDDO.
If you want the structure's field names as well, then you can get them using FM DDIF_NAMETAB_GET. And, in that case, instead of using the counter i, you can use the field name in the ASSIGN COMPONENT statement.
2013 Jan 25 9:05 PM
You may also use the name of a field instead of it's component index.
TYPES:
BEGIN OF struct,
field1 TYPE c,
field2 TYPE c,
End of struct
.
DATA:
ls_struct TYPE struct
.
ASSIGN COMPONENT 'FIELD1'
OF STRUCTURE ls_struct
TO <fs> .
That will allow you to access the fields by name. You may also use a variable in place of a literal string; so you could use variables to store the names of the fields you want to access.
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |