Skip to Content
author's profile photo Former Member
Former Member

Assign Component ...

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

Add a comment
10|10000 characters needed characters exceeded

Related questions

4 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Oct 11, 2005 at 08:49 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 11, 2005 at 09:44 AM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      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

  • author's profile photo Former Member
    Former Member
    Posted on Oct 11, 2005 at 10:05 AM

    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 ?

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      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

  • author's profile photo Former Member
    Former Member
    Posted on Oct 11, 2005 at 10:49 AM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.