How can i do this assign?

Development (ABAP Development WorkBench, ABAP/4 programming)

Moderators: Snowy, thx4allthefish, YuriT, Gothmog

Post Reply
kkktank
Posts: 13
Joined: Mon May 26, 2008 8:29 am

How can i do this assign?

Post by kkktank » Wed Jul 30, 2008 10:42 pm

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.'

m@t
Posts: 4119
Joined: Thu Sep 04, 2003 7:37 am
Location: Switzerland

Re: How can i do this assign?

Post by m@t » Thu Jul 31, 2008 2:35 am

Sorry, read it through three times and still can't work out what your going on about.
TULY Image The quality of answers is roughly proportional to the quality of the question.

The downside of being better than everyone else is that people tend to assume you're pretentious.

ashthomas
Posts: 107
Joined: Sat Jan 12, 2008 12:03 pm
Location: West London
Contact:

Re: How can i do this assign?

Post by ashthomas » Thu Jul 31, 2008 8:39 am

Hello,

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


Ash Thomas
Ash People, Sap Consultants & Sap Consultancy
http://www.ashpeople.com

kkktank
Posts: 13
Joined: Mon May 26, 2008 8:29 am

Re: How can i do this assign?

Post by kkktank » Wed Aug 27, 2008 10:45 pm

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.

Rich
Posts: 7116
Joined: Thu Oct 31, 2002 4:47 pm
Location: Liverpool
Contact:

Re: How can i do this assign?

Post by Rich » Thu Aug 28, 2008 1:21 am

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 ?
Regards

Rich

Image
Abap KC:http://www.richard-harper.me.uk/Kb
SFMDR:http://www.se37.com

Post Reply