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

Internal table reading

Former Member
0 Likes
911

My internal table contains data like.

123102

CAR

computer

987654321

Y010

Z000000001

107999

WASHINGTON

300 DR.

HOUSTON

US

PA

15342

How can i read data field by field into anthor internal table.

i want data like

123102 car computer 987654321

Regards,

Suresh

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
877

Hi Suresh,

I assume that you want to copy only the first four fields into another internal table.

If my assumption is correct you can do as follows.

it_tab1, wa_tab1 of structure:

123102 CAR computer 987654321 Y010 Z000000001 107999 WASHINGTON 300 DR. HOUSTON US PA 15342

it_tab2, wa_tab2 of structure:

123102 CAR computer 987654321

loop at it_tab1 into wa_tab1.
wa_tab2-f1 = wa_tab1-f1.
wa_tab2-f2 = wa_tab1-f2.
wa_tab2-f3 = wa_tab1-f3.
wa_tab2-f4 = wa_tab1-f4.
append wa_tab2 to it_tab2.
endloop.

Regards,

Manoj Kumar P

7 REPLIES 7
Read only

Former Member
0 Likes
878

Hi Suresh,

I assume that you want to copy only the first four fields into another internal table.

If my assumption is correct you can do as follows.

it_tab1, wa_tab1 of structure:

123102 CAR computer 987654321 Y010 Z000000001 107999 WASHINGTON 300 DR. HOUSTON US PA 15342

it_tab2, wa_tab2 of structure:

123102 CAR computer 987654321

loop at it_tab1 into wa_tab1.
wa_tab2-f1 = wa_tab1-f1.
wa_tab2-f2 = wa_tab1-f2.
wa_tab2-f3 = wa_tab1-f3.
wa_tab2-f4 = wa_tab1-f4.
append wa_tab2 to it_tab2.
endloop.

Regards,

Manoj Kumar P

Read only

Former Member
0 Likes
877

What i understand from this is that the new table should be like this

123102 CAR computer 987654321

Y010 Z000000001 107999 WASHINGTON

300 DR. HOUSTON US PA 15342

For this

LOOP at MAIN_table into wa.

wa1-f1 = wa-f1.

wa1-f2 = wa-f2.

wa1-f3= wa-f3.

append wa1 to final_table.

wa1-f1 = wa-f4

wa1-f2 = wa-f5

wa1-f3 = wa-f6

append wa1 to final_table.

wa1-f1 = wa-f7

wa1-f2 = wa-f8

wa1-f3 = wa-f9

append wa1 to final_table.

endloop.

final_table will have the desired output.

Regards,

Prashant

Read only

Former Member
0 Likes
877

Hi,

Try like this:

data: begin of o_list occurs 0,

output(1500) type c,

end of o_list.

data: begin of i_list occurs 0,

fld1(32) type c,

fld2(50) type c,

end of i_list.

o_list-output = '123102 CAR computer 987654321 Y010 Z000000001 107999 WASHINGTON 300 DR. HOUSTON US PA 15342 '.

append o_list.

loop at o_list.

write:/ o_list-output.

endloop.

i_list-fld1 = o_list-output+0(32).

i_list-fld2 = o_list-output+34(68).

append i_list.

loop at i_list.

write:/ i_list-fld1,

/ i_list-fld2.

endloop.

Regards,

Bhaskar

Read only

rainer_hbenthal
Active Contributor
0 Likes
877

>

> |123102 |CAR |computer |987654321 |Y010|Z000000001|107999 |WASHINGTON|300 DR.| |HOUSTON| |US |PA |15342 | |

> Suresh

Is this a string? Is this a list of field components? Or whatever?

Read only

Former Member
0 Likes
877

Hello,

You can do like:

let the 1st internal table be itab1 and its work area is wa1,

and the 2nd internal statement is itab2 and its work area is wa2.

Then we can write:

loop at itab1 into wa1.

move : wa1-field1 to wa2-field2.

wa1-field2 to wa2-field2.

wa1-field3 to wa2-field3.

append wa2 to itab2.

Hope this helps you.

Mansi

Read only

I355602
Product and Topic Expert
Product and Topic Expert
0 Likes
877

Hi Suresh,

Say you have two internal tables 'itab1' and 'itab2' with work areas 'wa1' and 'wa2' respectively.

Suppose 'itab1' contains some records in it.

To copy all contents of 'itab1' to 'itab2', you can use:-


itab2 = itab1.

To copy values of selected fields from 'itab1' to 'itab2', you can use:-


loop at itab1 into wa1.
  wa2-field1 = wa1-field1. "move field values from wa1 to wa2
  wa2-field2 = wa1-field2.
  wa2-field3 = wa1-field3.
  wa2-field4 = wa1-field4.
  append wa2 to itab2. "append itab2
  clear wa2. "clear wa2
endloop.

Hope this solves your problem.

Thanks & Regards

Tarun Gambhir

Read only

Former Member
0 Likes
877

Hi there,

If I were you .. I wud make row into column.

for eg:

loop at ur internal table1 into work area1.

split workarea at '|' into

another work area2 with all the fields in the workarea1

append workarea2 to inttable2.

endloop.

hope this helps

reg