Page 1 of 1

How can i do this assign?

Posted: Wed Jul 30, 2008 10:42 pm
by kkktank

Code: Select all

DATA: BEGIN OF IT_1,
              DATE TYPE DATS,
              QTY   TYPE I,
              INFO  TYPE STRING,
END OF IT_1.

DATA: BEGIN OF IT_2,
              DATE1_QTY TYPE I,
              DATE2_QTY TYPE I,
              DATE3_QTY TYPE I,
              INFO TYPE STRING,
END OF IT_2.
e.g), IT_1 [1] = ('2008-07-31', '100', 'other info'), I wanna assign this row to IT_2, which would be like
('100', '0', '0', 'other info'), giving the condition that 2008-07-31 corresponds to 'date1' in IT_2.

I have tried using 'describe field x help-id hid', but failed to use the hid-component in assignation.
I can use 'SELECT (COMP) FROM (STRUC)', BUT NOT 'IT_2-(COMP) = IT_1-QTY.'

Re: How can i do this assign?

Posted: Thu Jul 31, 2008 2:35 am
by m@t
Sorry, read it through three times and still can't work out what your going on about.

Re: How can i do this assign?

Posted: Thu Jul 31, 2008 8:39 am
by ashthomas
Hello,

As they are different types you'll need to look at casting.

Re: How can i do this assign?

Posted: Wed Aug 27, 2008 10:45 pm
by kkktank
The requirement is so weired, so It may be hard to understand.

I found the solution by using the 'describe' clause.

Code: Select all

DATA: BEGIN OF i_result OCCURS 0,
        field1 TYPE char10,
      END OF i_result.


i_result-field1 = 'F1'.
APPEND i_result.


FIELD-SYMBOLS: <fs> TYPE ANY.

LOOP AT i_result.
  DATA: l_fieldname TYPE char30.
  l_fieldname = 'FIELD1'.
  ASSIGN COMPONENT l_fieldname OF STRUCTURE i_result TO <fs>.
  IF sy-subrc = 0.
    <fs> = 'F2'.
  ENDIF.
  MODIFY i_result.
ENDLOOP.

Re: How can i do this assign?

Posted: Thu Aug 28, 2008 1:21 am
by Rich
kkktank wrote:The requirement is so weired, so It may be hard to understand.

I found the solution by using the 'describe' clause.

Code: Select all

DATA: BEGIN OF i_result OCCURS 0,
        field1 TYPE char10,
      END OF i_result.


i_result-field1 = 'F1'.
APPEND i_result.


FIELD-SYMBOLS: <fs> TYPE ANY.

LOOP AT i_result.
  DATA: l_fieldname TYPE char30.
  l_fieldname = 'FIELD1'.
  ASSIGN COMPONENT l_fieldname OF STRUCTURE i_result TO <fs>.
  IF sy-subrc = 0.
    <fs> = 'F2'.
  ENDIF.
  MODIFY i_result.
ENDLOOP.
Do you not mean

Code: Select all

ASSIGN COMPONENT (l_fieldname) OF STRUCTURE i_result TO <fs>.
Your assign assigns l_fieldname to <fs>, however, with the brackets the field named in l_fieldname is assigned to the <fs>.

How about the ?= operator ?