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

Move data dynamically

Former Member
0 Likes
912

Hi. I have a function module that is passing data in a structure with many fields. What I want to do is move data from 1 of the structure fields into a new field based on which field a user enters.

For example, if the user keys in field "DESCRIPTION" I want to move the field called "DESCRIPTION" from the structure.

I can easily find what the user enters, the problem is moving the field.

I could do a massive IF or CASE statement, but is there any way I can simply say "MOVE <structure>-<user field> to <new field>"?

Any help would be greatly appreaciated.

Regards,

Dave.

1 ACCEPTED SOLUTION
Read only

MarcinPciak
Active Contributor
0 Likes
882

Hi,


"USER_FIELD stores field name i.e. DESCRIPTION
"STRUCT is the structure you are passing to FM
"<NEW_FIELD> is your target field

"assuming above you can do this in the following way
field-symbols <comp> type any.

assign component USER_FIELD of structure STRUCT to <comp>.
if sy-subrc = 0.
   move <comp> to <new_field>.
endif.

Regards

Marcin

7 REPLIES 7
Read only

Former Member
0 Likes
882

Hi,

you can use MOVE- CORRESPONDING.

Read only

0 Likes
882

You can use a Move-Corresponding to move the corresponding fileds from one structure to another, else you will have to use a field symbol of type any and assign the values to that field symbol.

Regards,

S.Dakshna Nagarnatam.

Read only

Former Member
0 Likes
882

Hi,

You can make use of ASSIGN COMPONENT statement.

Regards,

Ankur Parab

Read only

Former Member
0 Likes
882

Hi,

if the structure are different and some field names are same..



loop at structure.

move-corresponding fields of structure to Itab.

append itab.
endloop.

if both the structure are same..


itab[] = structure[].

Prabhudas

Read only

MarcinPciak
Active Contributor
0 Likes
883

Hi,


"USER_FIELD stores field name i.e. DESCRIPTION
"STRUCT is the structure you are passing to FM
"<NEW_FIELD> is your target field

"assuming above you can do this in the following way
field-symbols <comp> type any.

assign component USER_FIELD of structure STRUCT to <comp>.
if sy-subrc = 0.
   move <comp> to <new_field>.
endif.

Regards

Marcin

Read only

0 Likes
882

Thanks, I was able to do it with the assigning to field symbol type any.

Read only

Former Member
0 Likes
882

will it help...


*&---------------------------------------------------------------------*
*& Report  ZTEST_SOURAV33
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ztest_sourav33.


TYPES:
BEGIN OF x_struc1,
  af1 TYPE c LENGTH 10,
  af2 TYPE p LENGTH 2 DECIMALS 3,
  af3 TYPE i,
END OF x_struc1,
BEGIN OF x_struc2,
  bf1 TYPE c LENGTH 5,
  af1 TYPE c LENGTH 10,
  bf2 TYPE n,
  af2 TYPE p LENGTH 2 DECIMALS 3,
  bf3 TYPE c LENGTH 5,
  af3 TYPE i,
END OF x_struc2.

DATA: work_area1 TYPE x_struc1,
      work_area2 TYPE x_struc2.

work_area1-af1 = 'TEST123456'.
work_area1-af2 = '0.865'.
work_area1-af3 = 14.

PARAMETERS: field TYPE c LENGTH 3. " AF1, or AF2 or AF3


AT SELECTION-SCREEN.

  IF field = 'AF1' OR
     field = 'AF2' OR
     field = 'AF3'.

  ELSE.
    MESSAGE e001(00) WITH 'Enter AF1, AF2 or AF3'.
  ENDIF.

START-OF-SELECTION.

  FIELD-SYMBOLS: <f1> TYPE ANY,
                 <f2> TYPE ANY.
  DATA temp TYPE string.

  CONCATENATE 'WORK_AREA1-' field INTO temp.

  ASSIGN (temp) TO <f1>.
  IF sy-subrc = 0.

    CONCATENATE 'WORK_AREA2-' field INTO temp.
    ASSIGN (temp) TO <f2>.
    IF sy-subrc = 0.
      <f2> = <f1>.
     write: temp, '=', <f2>.
    ENDIF.
  ENDIF.