Application Development 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: 

Move data into table

Former Member
0 Kudos
133

Hi All,

Could anyone help how to Move data into certain column/position of the table. Hope my question are clarify. Please guide with some sample code.Thanks in advance!

tables:s_record.

DATA: BEGIN OF itab1 OCCURS 0,

name like s_record-name,

student like s_record-student,

result like s_record-result,

<b>Aaddress type c,

ACourse type c,</b>

END OF itab1.

Data: m_data1(30) type c value 'AUS',

m_data2(2) type c value 'CA.

<u><b>Output file: data should be insert/display as below sequence</b></u>

Name

Student

<b>Address</b>

<b>Course</b>

Result

<u>My code:</u>

Select name, student, result into (I_Name,

I_Student,

I_Result)

From S_Records

Where Reg_date in Join_date.

MOVE m_data1 TO itab1-Aaddress.

MOVE m_data2 TO itab1-ACourse.

1 ACCEPTED SOLUTION

Former Member
0 Kudos
100

Hi,

You can write like this:

Select name, student, result into (itab1-Name,

itab1-Student,

itab1-Result)

From S_Records

Where Reg_date in Join_date.

MOVE m_data1 TO itab1-Aaddress.

MOVE m_data2 TO itab1-ACourse.

append itab1.

clear itab1.

endselect.

regards,

Anji

7 REPLIES 7

Former Member
0 Kudos
101

Hi,

You can write like this:

Select name, student, result into (itab1-Name,

itab1-Student,

itab1-Result)

From S_Records

Where Reg_date in Join_date.

MOVE m_data1 TO itab1-Aaddress.

MOVE m_data2 TO itab1-ACourse.

append itab1.

clear itab1.

endselect.

regards,

Anji

Former Member
0 Kudos
100

Where are u appending the values in itab for name , student and for result..??...

If the itab is having the data...then u cannot directly append the values ...it will append in all the rows..

so,

MOVE m_data1 TO itab1-Aaddress.

MOVE m_data2 TO itab1-ACourse.

modify itab1

transporting aaddress acourse

where name = l_Name and

student ='l_student etc...

0 Kudos
100

Hi ,

I'm appending the values from s_record for name , student and for result. However for the new declare data types, there are currently not exist in db. I want to add this field to internal table and set the default value for these 2 new declare data and move the value to the Internal table.

The position of the records to be insert in internal tables should look like below.

Name

Student

<b>Address

Course</b>

Result

0 Kudos
100

Hi..,

you can select data in which ever way u want..

this doesnt make any difference here... !!

but when u print or display them onli u need to write address first and the result next..

write :

itab-name,

/itab-......,

/itab-address,

/itab-aero,

/itab-result.

hope u understood..

0 Kudos
100

if u r displaying data with ALV Fms , then here is the solution to ur issue.

Create a field catalog with the existing fields in the internal table, Name, Student, Result.

Now append those required fields to this field catalog, here the fields to be added in ur case are Address, Course.

Here I am mentioning pieces of code to do this..

PERFORM append_catalog USING 'Address'<address Filedname> ' 4 '' '' '<refencere Diled>' '<referfnce structure>'.

FORM append_catalog USING p_name p_field p_len p_sum p_head

p_rfield p_rtable.

gt_variant_fieldcat-col_pos = gt_variant_fieldcat-col_pos + 1.

gt_variant_fieldcat-row_pos = gt_variant_fieldcat-row_pos.

gt_variant_fieldcat-reptext_ddic = p_name.

gt_variant_fieldcat-seltext_s = p_head.

gt_variant_fieldcat-fieldname = p_field.

gt_variant_fieldcat-tabname = gt_variant_fieldcat-tabname.

gt_variant_fieldcat-outputlen = p_len.

gt_variant_fieldcat-do_sum = p_sum.

gt_variant_fieldcat-ref_fieldname = p_rfield.

gt_variant_fieldcat-ref_tabname = p_rtable.

APPEND gt_variant_fieldcat.

ENDFORM. " append_catalog

Now create an object reference with the field catalog and internal table we have.

and create a field symbol for this.

FIELD-SYMBOLS : <fs> TYPE table,

<wa_fs>.

data : it_data TYPE REF TO data,

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = l_ts_fieldcat

IMPORTING

ep_table = it_data.

ASSIGN it_data->* TO <fs>.

  • Create a work area for the dynamic table

CREATE DATA l_wa LIKE LINE OF <fs>.

ASSIGN l_wa->* TO <wa_fs>.

Now the fileds to be added are included in the fiels symbols <FS> which is referring to the table.

Now assign the component reference to any field asymbol and do the necessary changes for that field symbol and it will get affcted automatically in the field symbol which is refering to the table.

ASSIGN COMPONENT 'ADRNR' OF STRUCTURE <wa_fs> TO <value>.

Now pass this field symbol to ALV Fm that u r using.

Hope ur issue may solve with this idea.

Regards,

Sujatha.

Message was edited by:

Sujatha Reddy

Former Member
0 Kudos
100

Hi..,

declare ur table like this..

DATA: BEGIN OF itab1 OCCURS 0,

name like s_record-name,

student like s_record-student,

result like s_record-result,

Aaddress(30) type c, <<<-------

ACourse(2) type c, <<<-------

END OF itab1.

Data: m_data1(30) type c value 'AUS',

m_data2(2) type c value 'CA.

Select name, student, result into (Itab_Name,

Itab_Student,

Itab_Result)

From S_Records

Where Reg_date in Join_date.

MOVE m_data1 TO Itab-Aaddress.

MOVE m_data2 TO Itab-ACourse.

append Itab.

clear Itab.

endselect.

Hope it solves ur problem ..

regards,

sai ramesh

Former Member
0 Kudos
100

Hi,

Your code should be

Select name, student, result into (itab1-Name,
itab1-Student,
itab1-Result)
From S_Records
Where Reg_date in Join_date.

MOVE m_data1 TO itab1-Aaddress.
MOVE m_data2 TO itab1-ACourse. 
Append itab1.
clear itab1.

Regards

Sudheer