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

Help on moving fields

Former Member
0 Likes
586

Hi expert,

I have one workarea called ls_college contains field guid, collegename, city,state, university.

It contains value of guid and college,i have another workarea called ls_modify having same fields but it contains only the value of city.

so i want to fill this value to ls_college workarea.

In this scenario ls_modify can hold any value of the field its dynamic,so i want to transfer these values to ls_college workarea.

but one more thing is, i have one variable which hold the field name which i want to transfer it to ls_college.

Thank you in advance..

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
559

Hi Nikhil,

if the structures are typed you can do it like this:

ls_college-CITY = ls_modify-CITY.

If you can guarantee that no other fields of ls_collge could be overwritten you can also do a

move-corresponding ls_modify to ls_college.

If you want to move only the value of the component(fieldname) which is stored in your other variable do it like this.

FIELD-SYMBOLS: <field>    type any,

                             <field2> type any.

ASSIGN COMPONENT field_name OF STRUCTURE LS_COLLEGE TO <field>.

IF SY-SUBRC = 0.

     ASSIGN COMPONENT field_name OF STRUCTURE LS_MODIFY TO <field2>.

     IF SY-SUBRC = 0.

          <field> = <field2>.      

     ENDIF.

ENDIF.

Regards Jonas

5 REPLIES 5
Read only

Former Member
0 Likes
559

Hi Nikhil,

Since both are workareas you can directly assign as workareas will carry only one entry.

Hence ls_college-city = ls_modify-city.

You can do the same to pass the variable value also.

ls_college-(fieldname to which the value should be passed) = variable.

Hope this helps!

Read only

former_member183073
Active Participant
0 Likes
559

Hi Nikhil,

if i understand you scenario properly you have two workareas

                    ls_college

                    ls_modify

depending on the field name in your variable you want to transfer the relevant value from ls_modify to ls_college.

CASE var.
  WHEN 'GUID'.
      ls_college-guid = ls_modify-guid.   
  WHEN 'COLLEGENAME'.
    ls_college-collegename = ls_modify-collegename.
  WHEN 'CITY'.
    ls_college-city = ls_modify-city.
  WHEN 'STATE'.
    ls_college-state = ls_modify-state.
  WHEN 'UNIVERSITY'.
    ls_college-university = ls_modify-university.
  WHEN OTHERS.
ENDCASE.

Read only

Former Member
0 Likes
560

Hi Nikhil,

if the structures are typed you can do it like this:

ls_college-CITY = ls_modify-CITY.

If you can guarantee that no other fields of ls_collge could be overwritten you can also do a

move-corresponding ls_modify to ls_college.

If you want to move only the value of the component(fieldname) which is stored in your other variable do it like this.

FIELD-SYMBOLS: <field>    type any,

                             <field2> type any.

ASSIGN COMPONENT field_name OF STRUCTURE LS_COLLEGE TO <field>.

IF SY-SUBRC = 0.

     ASSIGN COMPONENT field_name OF STRUCTURE LS_MODIFY TO <field2>.

     IF SY-SUBRC = 0.

          <field> = <field2>.      

     ENDIF.

ENDIF.

Regards Jonas

Read only

0 Likes
559

Thank you so much.....

Read only

0 Likes
559

This message was moderated.