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

printing internal table

Former Member
0 Likes
1,375

hi friends,

i have a internal table itab with 3 fileds called f1,f2,f3 and the contents are.........

-


f1 f2 f3

-


A1 A2 A3

B1 B2 B3

C1 C2 C3

D1 D2 D3

E1 E2 E3

F1 F2 F3

G1 G2 G3

-


if i want to print the output like this

A1 B1 C1 D1 E1 F1 G1

A2 B2 C2 D2 E2 F2 G2

A3 B3 C3 D3 E3 F3 G3

WHAT IS THE PROCEDURE?

11 REPLIES 11
Read only

Former Member
0 Likes
1,348

LOOP AT itab.

WRITE itab-f1.

ENDLOOP.

LOOP AT itab.

WRITE itab-f2.

ENDLOOP.

LOOP AT itab.

WRITE itab-f3.

ENDLOOP.

This would be the simple solution.

Ps:Reward points if helpful.

Read only

0 Likes
1,348
DATA str1(256).
DATA str2(256).
DATA str3(256).


LOOP AT itab.

str1= str1 + '  ' + itab-f1.
str2= str2 + '  ' + itab-f2.
str3= str3 + '  ' + itab-f3.

ENDLOOP.

WRITE : / str1.
WRITE : / str2.
WRITE : / str3.
Read only

0 Likes
1,348

This should work:

DATA: BEGIN OF gt_data OCCURS 0,

f1(2),

f2(2),

f3(2),

END OF gt_data.

gt_data-f1 = 'A1'.

gt_data-f2 = 'A2'.

gt_data-f3 = 'A3'. APPEND gt_data. CLEAR gt_data.

gt_data-f1 = 'B1'.

gt_data-f2 = 'B2'.

gt_data-f3 = 'B3'. APPEND gt_data. CLEAR gt_data.

gt_data-f1 = 'C1'.

gt_data-f2 = 'C2'.

gt_data-f3 = 'C3'. APPEND gt_data. CLEAR gt_data.

DATA str1(256).

DATA str2(256).

DATA str3(256).

LOOP AT gt_data.

CONCATENATE str1 gt_data-f1 INTO str1 SEPARATED BY space.

CONCATENATE str2 gt_data-f2 INTO str2 SEPARATED BY space.

CONCATENATE str3 gt_data-f3 INTO str3 SEPARATED BY space.

ENDLOOP.

WRITE: / str1.

WRITE: / str2.

WRITE: / str3.

Please close the issue with appropriate points if helpful.

Venu

Read only

0 Likes
1,348

You can do this using <b>RESERVE</b> and <b>BACK</b>.

check out this code sample.

data: begin of itab occurs 0 ,

fc(2),

sc(2) ,

tc(2) ,

end of itab .

move: 'A1' to itab-fc ,

'A2' to itab-sc ,

'A3' to itab-tc .

append itab .

clear itab .

move: 'B1' to itab-fc ,

'B2' to itab-sc ,

'B3' to itab-tc .

append itab .

clear itab .

move: 'C1' to itab-fc ,

'C2' to itab-sc ,

'C3' to itab-tc .

append itab .

clear itab .

LOOP AT ITAB .

<b>RESERVE 3 LINES</b>.

WRITE: / ITAB-FC .

<b>BACK</b> .

WRITE:/5 ITAB-SC,

15 ITAB-TC .

ENDLOOP .

Regards

Raja

Read only

Former Member
0 Likes
1,348

plz give me another solution.....

actually this was asked in an interview... i was answered same as u have given the answer now..i.e with 3 loops..

but the interviwer wants to do in another way....

plz send some alternate solution.......if possible

Read only

0 Likes
1,348

He wanted you to use field-symbols. You can read up on this in the help files.

Rob

Read only

Former Member
0 Likes
1,348

hi all,

types: begin of my_type,

f1 type c,

f2 type c,

f3 type c,

end of my_type.

data:

my_table TYPE STANDARD TABLE OF my_type WITH HEADER LINE,

ind type i.

my_table-f1 = 'Q'.

my_table-f2 = 'A'.

my_table-f3 = 'Z'.

APPEND my_table.

my_table-f1 = 'W'.

my_table-f2 = 'S'.

my_table-f3 = 'X'.

APPEND my_table.

my_table-f1 = 'E'.

my_table-f2 = 'D'.

my_table-f3 = 'C'.

APPEND my_table.

clear my_table.

write my_table.

LOOP AT my_table.

sy-linno = 3.

ind = sy-tabix.

ind = ind * 10.

WRITE AT ind my_table-f1.

sy-linno = 4.

WRITE AT ind my_table-f2.

sy-linno = 5.

WRITE AT ind my_table-f3.

ENDLOOP.

regards

Andrej

Message was edited by: Andrej Chujikov

Read only

Former Member
0 Likes
1,348

try this code:

REPORT Z901_SDN1.

data : lin type i.

data : begin of wa_tab,

f1(20),

f2(20),

f3(20),

end of wa_tab.

data : itab1 like standard table of wa_tab.

perform append using 'abc' 'def' 'xyz'.

perform append using 'abc' 'def' 'xyz'.

perform append using 'abc' 'def' 'xyz'.

perform append using 'abc' 'def' 'xyz'.

perform append using 'abc' 'def' 'xyz'.

perform append using 'abc' 'def' 'xyz'.

describe table itab1 lines lin.

do lin times.

read table itab1 index sy-index into wa_tab.

write : wa_tab-f1.

enddo.

do lin times.

read table itab1 index sy-index into wa_tab.

write : wa_tab-f2.

enddo.

do lin times.

read table itab1 index sy-index into wa_tab.

write : wa_tab-f3.

enddo.

form append using a b c.

wa_tab-f1 = a.

wa_tab-f2 = b.

wa_tab-f3 = c.

append wa_tab to itab1.

endform.

Read only

Former Member
0 Likes
1,348

data:i value 1

loop at itab into str.

write : at i(2) str-f1,

/,at i(2) str-f2,

/, at i(2) str-f3.

back.

i = i + 3.

endloop.

str is the work area of the table itab which has 3 fields f1 f2 f3.

Read only

0 Likes
1,348

DATA str1(256).

DATA str2(256).

DATA str3(256).

LOOP AT itab.

CONCATENATE str1 itab-f1 INTO str1 SEPERATED BY SPACE..

CONCATENATE str2 itab-f2 INTO str2 SEPERATED BY SPACE.

CONCATENATE str3 itab-f3 INTO str3 SEPERATED BY SPACE.

ENDLOOP.

WRITE : / str1.

WRITE : / str2.

WRITE : / str3.

Read only

0 Likes
1,348

Since prashanth g mentioned that its a interview question, i guess they wanted to know how to use other KERY WORDS / commands to get this done. As i have mentioned before, you can use RESERVE and BACK to do this. Try the example code i have provided.

Regards

Raja

if the question is answered, mark it so.