‎2009 May 27 12:21 PM
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.
‎2009 May 27 12:30 PM
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
‎2009 May 27 12:23 PM
‎2009 May 27 12:27 PM
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.
‎2009 May 27 12:25 PM
Hi,
You can make use of ASSIGN COMPONENT statement.
Regards,
Ankur Parab
‎2009 May 27 12:28 PM
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
‎2009 May 27 12:30 PM
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
‎2009 May 27 1:39 PM
Thanks, I was able to do it with the assigning to field symbol type any.
‎2009 May 27 1:18 PM
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.