cancel
Showing results for 
Search instead for 
Did you mean: 

Assign Component ...

Former Member
0 Kudos

Hi All,

With ASSIGN COMPONENT it's possible to do a 'horizontal' read from a structure. I'm looking for a solution to put back (the changed) value in the 'source' field.

Example :

LOOP AT itab.

DO x TIMES.

ASSIGN COMPONENT sy-index OF STRUCTURE wa_structure TO <f1>.

IF sy-subrc ne 0. continue. ENDIF.

new_value = <f1> + 1.

      • how to get this changed value back in original source field (wa_structure-field_x)

...

ENDDO.

ENDLOOP.

Thanks,

Rob Makelaar

The Netherlands

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

How simple can it be !

Thank you, Max and Svetlin. I'll devide the points between the two of you.

Once again thank you.

Rob Makelaar.

Former Member
0 Kudos

Hi,

See my code for the real problem :

LOOP AT tab.

MOVE-CORRESPONDING tab TO wa_convert.

DO 13 TIMES.

ASSIGN COMPONENT sy-index OF STRUCTURE wa_convert TO <f1>.

IF sy-subrc NE 0.

EXIT.

ELSE.

<b>value_in = <f1>.</b> CLEAR value_out.

CALL FUNCTION 'MD_CONVERT_MATERIAL_UNIT'

EXPORTING

i_matnr = tab-matnr

i_in_me = tab-meins

i_out_me = 'KG'

i_menge = value_in

IMPORTING

e_menge = <b>value_out</b>

EXCEPTIONS

error_in_application = 1

error = 2

OTHERS = 3.

IF sy-subrc <> 0.

ENDIF.

I can't do a call of a FM with a field-symbol, so i must transfer it to a 'help' variable. At this point i'm loosing track of the source field. Any suggestions ?

Former Member
0 Kudos

LOOP AT tab.

MOVE-CORRESPONDING tab TO wa_convert.

DO 13 TIMES.

ASSIGN COMPONENT sy-index OF STRUCTURE wa_convert TO <f1>.

IF sy-subrc NE 0.

EXIT.

ELSE.

value_in = <f1>. CLEAR value_out.

CALL FUNCTION 'MD_CONVERT_MATERIAL_UNIT'

EXPORTING

i_matnr = tab-matnr

i_in_me = tab-meins

i_out_me = 'KG'

i_menge = value_in

IMPORTING

e_menge = value_out

EXCEPTIONS

error_in_application = 1

error = 2

OTHERS = 3.

IF sy-subrc <> 0.

ENDIF.

<i><f1> = value_out.

enddo.

MODIFY tab FROM wa_convert.

endloop.</i>

or

declare the field symbol as

field-symbols <F1> type EKPO-MENGE.

Svetlin

P.S. Please assign reward points for helpful answers.

Message was edited by: Svetlin Rusev

Former Member
0 Kudos

DATA: VALUE_IN LIKE EKPO-MENGE,

VALUE_OUT LIKE EKPO-MENGE.

LOOP AT TAB.

MOVE-CORRESPONDING TAB TO WA_CONVERT.

DO 13 TIMES.

ASSIGN COMPONENT SY-INDEX OF STRUCTURE WA_CONVERT TO <F1>.

IF SY-SUBRC NE 0.

EXIT.

ELSE.

VALUE_IN = <F1>. CLEAR VALUE_OUT.

CALL FUNCTION 'MD_CONVERT_MATERIAL_UNIT'

EXPORTING

I_MATNR = TAB-MATNR

I_IN_ME = TAB-MEINS

I_OUT_ME = 'KG'

I_MENGE = VALUE_IN

IMPORTING

E_MENGE = VALUE_OUT

EXCEPTIONS

ERROR_IN_APPLICATION = 1

ERROR = 2

OTHERS = 3.

IF SY-SUBRC <> 0.

ENDIF.

MOVE VALUE_OUT TO <F1>.

ENDIF.

ENDDO.

ENDLOOP.

If you're sure the field (assigned to field-symbol) is always like EKPO-MENGE, you can try to do this:

FIELD-SYMBOLS: <FS_MENGE> LIKE EKPO-MENGE.

LOOP AT TAB.

MOVE-CORRESPONDING TAB TO WA_CONVERT.

DO 13 TIMES.

ASSIGN COMPONENT SY-INDEX OF STRUCTURE WA_CONVERT TO <FS_MENGE>.

IF SY-SUBRC NE 0.

EXIT.

ELSE.

CALL FUNCTION 'MD_CONVERT_MATERIAL_UNIT'

EXPORTING

I_MATNR = TAB-MATNR

I_IN_ME = TAB-MEINS

I_OUT_ME = 'KG'

I_MENGE = <FS_MENGE>

IMPORTING

E_MENGE = <FS_MENGE>

EXCEPTIONS

ERROR_IN_APPLICATION = 1

ERROR = 2

OTHERS = 3.

IF SY-SUBRC <> 0.

ENDIF.

ENDIF.

ENDDO.

ENDLOOP.

Max

Message was edited by: max bianchi

Former Member
0 Kudos

Stephan,

Here's the problem : I have a structure with 100 values. For 40 of them, i must do a conversion to KG's with a function module. 40 times a call with 'hard-coded' the name of the field is a possibility. But with assign component its much smaller.

Regards,

Rob Makelaar.

Former Member
0 Kudos

Hi Rob,

I see your point...

I just tell you that you can do.

<fs> = <fs> + 1

or

new_val = <fs> + 1.

<fs> = new_val.

or

new_vale = class=>convert( value = <fs> ).

<fs> = new_vale.

...

you see what I mean ?

Former Member
0 Kudos

Hi,

The field symbol refers to the real field. When you change the field symbol value, you actually change the field value.

field = <f1>.

<f1> = new_value.

result

field is equal to new_value.

Svetlin

Former Member
0 Kudos

Hi Rob

Your code is right, if you update your field-symbols, you'll update your field:

LOOP AT itab.

DO x TIMES.

ASSIGN COMPONENT sy-index OF STRUCTURE wa_structure

TO <f1>.

IF sy-subrc ne 0. continue. ENDIF.

  • For example conversion from kg to g

<f1> = <f1> * 1000.

ENDDO.

ENDLOOP.

Max

Former Member
0 Kudos

hI rOB?

Why just don't you do

<fs1> = <fs1> + 1 .

is that what you ask...

regards,

If you find my answer rellevant, please don't forget the reward

Former Member
0 Kudos

did it help ?