Skip to content

Instantly share code, notes, and snippets.

@crazko
Created Sep 29, 2014
Embed
What would you like to do?
Get data from class' attributes in a loop.
METHOD get_data.
DATA:
ls_employee TYPE zpy_sk_st_empl,
lv_attrname TYPE abap_attrname,
lv_attr_ref TYPE string,
lv_struc_ref TYPE string.
FIELD-SYMBOLS:
<attr_desc> TYPE abap_attrdescr,
<attr_ref> TYPE any,
<struc_ref> TYPE any.
SELECT SINGLE * FROM zpy_sk_st_empl
INTO ls_employee
WHERE personnel_no = me->personnel_no.
IF sy-subrc <> 0.
* RAISE EXCEPTION
ENDIF.
" Set employee's data
LOOP AT me->attributes ASSIGNING <attr_desc>.
lv_attrname = <attr_desc>-name.
CONCATENATE 'me->' lv_attrname INTO lv_attr_ref.
CONCATENATE 'ls_employee-' lv_attrname INTO lv_struc_ref.
ASSIGN (lv_attr_ref) TO <attr_ref>.
ASSIGN (lv_struc_ref) TO <struc_ref>.
IF <struc_ref> IS ASSIGNED.
<attr_ref> = <struc_ref>.
ENDIF.
ENDLOOP.
ENDMETHOD. "GET_DATA
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment