Application Development and Automation 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: 
Read only

Problem with GET REFERENCE statement

matteo_montalto
Contributor
0 Likes
1,523

Hi gurus,

shortly; I need to populate a table whose elements are made as follows:

CODE   TYPE MDM_FIELD_CODE (a string, basically)

VALUE  TYPE REF TO DATA.

I need to loop over an item table and populate the above sketched table; so I wrote as follows:

LOOP AT lt_item INTO ls_item.

*** MDMSRM_SHORT_DESCRIPTION ***

     CLEAR value_pair.

     MOVE 'MDMSRM_SHORT_DESCRIPTION' to value_pair-code.

     GET REFERENCE OF ls_item-short_desc INTO value_pair-value.

     APPEND value_pair TO lt_value_pair.

....

ENDLOOP.

The problem is: each time the loop is performed, all the VALUE fields already appended have the value of the last iteration.

How can I overcome this problem? Is there a sort of unassignment technique for GET REFERENCE?

Thanks,

1 ACCEPTED SOLUTION
Read only

RaymondGiuseppi
Active Contributor
0 Likes
1,222

As you store the reference of the work area field and not of the internal table record field, this is normal behaviour. Look at source sample attached for a solution using ASSIGNING <fs>.

Regards,

Raymond

4 REPLIES 4
Read only

RaymondGiuseppi
Active Contributor
0 Likes
1,223

As you store the reference of the work area field and not of the internal table record field, this is normal behaviour. Look at source sample attached for a solution using ASSIGNING <fs>.

Regards,

Raymond

Read only

0 Likes
1,222

Thanks Raymond,

your solution solved my problem.

One more question... in that LOOP cycle, I have to build up a structure in this way:

LOOP... ASSIGNING <item>.

     CLEAR ls_min_qty.

     MOVE <item>-min_qty TO ls_min_qty-content.

     MOVE '$$$' TO ls_min_qty-unit_code.

     GET REFERENCE OF ls_min_qty INTO value_pair-value.

     APPEND value_pair TO lt_value_pair.

---

ENDLOOP.


I assume this would lead to the same problem I posted above, as each GET REFERENCE of structure will overwrite previous assignments. How would you overcome this issue?

Thanks again

Read only

0 Likes
1,222

Yes you would always get reference to the work area.

So use similar solution, with a statement APPEND [INITIAL LINE/wa] TO itab ASSIGNING <fs> and use the field symbol in the get reference statement.

Regards,

Raymond

Read only

0 Likes
1,222

Had some difficulties in working with field-symbols as I have to reference to a structure which is partly derived from the workarea and partly fixed...

I did as follows, maybe it's not the best solution, however, seems to work:

FIELD-SYMBOLS <item>        TYPE zsrm_cat_files_i.

FIELD-SYMBOLS: <minqty>      TYPE mdm_gdt_quantity-content.

FIELD-SYMBOLS: <minqty_unit> TYPE MDM_CDT_MEASURE_UNIT_CODE.

FIELD-SYMBOLS: <minqty_struct> TYPE mdm_gdt_quantity.

DATA minimum_qty TYPE REF TO mdm_gdt_quantity


LOOP ... ASSIGNING <item>.

...

   CREATE DATA minimum_qty.

   ASSIGN minimum_qty->* TO <minqty_struct>.

   ASSIGN COMPONENT 1 OF STRUCTURE <minqty_struct> TO <minqty>.

   ASSIGN COMPONENT 2 OF STRUCTURE <minqty_struct> TO <minqty_unit>.

   <minqty> = <item>-min_qty.

   <minqty_unit> = '$$$'.

   GET REFERENCE OF <minqty_struct> INTO value_pair-value.

   APPEND value_pair TO lt_value_pair.