2013 Jun 06 9:35 PM
Hi All,
I have a fixed DSO structure which is populated from BPartner hierarchy. The data fields-Parent level 1, Parent level 2, .. Parent Level 7 are updated with Parent Ids till level 1. So in the routine we start with Looping where IO Name = BP. Then depending on the level we keep updating the data fields one by one. Read the BP hierarchy table with Hierarchy Id and Parent Node No and Level = Level - 1.
Instead of having a Case statement for levels which will have 7 when conditions, is there any way to update the field dynamically.
What I am looking for is if we can determine which field to assign the value using something like Concatenate 'Parent' (level) to lv_field.
Then Result_fields-(lv_field) = Parent id. Appreciate any pointers.
Thanks In Advance !
Thanks,
Aparna
2013 Jun 06 9:53 PM
You can use the Field Symbol to achieve this. You would need to loop through the data, build the field name and use Field Symbol to assign the value.
TYPES:
BEGIN OF ty_dso,
parent_1 TYPE char10,
parent_2 TYPE char10,
parent_3 TYPE char10,
parent_4 TYPE char10,
parent_5 TYPE char10,
parent_6 TYPE char10,
parent_7 TYPE char10,
END OF ty_dso.
DATA: ls_dso TYPE ty_dso.
TYPES:
BEGIN OF lty_levels,
level TYPE i,
value TYPE char10,
END OF lty_levels.
DATA: lt_levels TYPE STANDARD TABLE OF lty_levels.
DATA: ls_levels LIKE LINE OF lt_levels.
* initial data
DO 7 TIMES.
ls_levels-level = sy-index.
ls_levels-value = sy-abcde+sy-index.
APPEND ls_levels TO lt_levels.
CLEAR ls_levels.
ENDDO.
*
DATA: lv_level TYPE char10.
DATA: lv_field TYPE string.
FIELD-SYMBOLS: <lv_parent> TYPE char10.
LOOP AT lt_levels INTO ls_levels.
lv_level = ls_levels-level.
CONDENSE lv_level.
CONCATENATE 'LS_DSO-PARENT_' lv_level INTO lv_field.
CONDENSE lv_field.
ASSIGN (lv_field) TO <lv_parent>.
<lv_parent> = ls_levels-value.
ENDLOOP.
write: ls_dso.
Regards,
Naimesh Patel
You can use the Field Symbol to achieve this. You would need to loop through the data, build the field name and use Field Symbol to assign the value.
TYPES:
BEGIN OF ty_dso,
parent_1 TYPE char10,
parent_2 TYPE char10,
parent_3 TYPE char10,
parent_4 TYPE char10,
parent_5 TYPE char10,
parent_6 TYPE char10,
parent_7 TYPE char10,
END OF ty_dso.
DATA: ls_dso TYPE ty_dso.
TYPES:
BEGIN OF lty_levels,
level TYPE i,
value TYPE char10,
END OF lty_levels.
DATA: lt_levels TYPE STANDARD TABLE OF lty_levels.
DATA: ls_levels LIKE LINE OF lt_levels.
* initial data
DO 7 TIMES.
ls_levels-level = sy-index.
ls_levels-value = sy-abcde+sy-index.
APPEND ls_levels TO lt_levels.
CLEAR ls_levels.
ENDDO.
*
DATA: lv_level TYPE char10.
DATA: lv_field TYPE string.
FIELD-SYMBOLS: <lv_parent> TYPE char10.
LOOP AT lt_levels INTO ls_levels.
lv_level = ls_levels-level.
CONDENSE lv_level.
CONCATENATE 'LS_DSO-PARENT_' lv_level INTO lv_field.
CONDENSE lv_field.
ASSIGN (lv_field) TO <lv_parent>.
<lv_parent> = ls_levels-value.
ENDLOOP.
write: ls_dso.
Regards,
Naimesh Patel
2013 Jun 06 9:53 PM
You can use the Field Symbol to achieve this. You would need to loop through the data, build the field name and use Field Symbol to assign the value.
TYPES:
BEGIN OF ty_dso,
parent_1 TYPE char10,
parent_2 TYPE char10,
parent_3 TYPE char10,
parent_4 TYPE char10,
parent_5 TYPE char10,
parent_6 TYPE char10,
parent_7 TYPE char10,
END OF ty_dso.
DATA: ls_dso TYPE ty_dso.
TYPES:
BEGIN OF lty_levels,
level TYPE i,
value TYPE char10,
END OF lty_levels.
DATA: lt_levels TYPE STANDARD TABLE OF lty_levels.
DATA: ls_levels LIKE LINE OF lt_levels.
* initial data
DO 7 TIMES.
ls_levels-level = sy-index.
ls_levels-value = sy-abcde+sy-index.
APPEND ls_levels TO lt_levels.
CLEAR ls_levels.
ENDDO.
*
DATA: lv_level TYPE char10.
DATA: lv_field TYPE string.
FIELD-SYMBOLS: <lv_parent> TYPE char10.
LOOP AT lt_levels INTO ls_levels.
lv_level = ls_levels-level.
CONDENSE lv_level.
CONCATENATE 'LS_DSO-PARENT_' lv_level INTO lv_field.
CONDENSE lv_field.
ASSIGN (lv_field) TO <lv_parent>.
<lv_parent> = ls_levels-value.
ENDLOOP.
write: ls_dso.
Regards,
Naimesh Patel
| User | Count |
|---|---|
| 6 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |