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: 

building an internal table from another internal table

Former Member
0 Kudos

Hello Friends,

I have an internal table with say for eg : 15 materials. I need to display them on the sapscropt form .

I want to format this internal table into another internal table with 3 columns and each column having 5 materials so that i can fit all the 10 materials on one page.

Please advise .

Thank you ,

Teresa

Eg: itab1

m1

m2

m3

m4

m5

m6

I need the new itab2 to look like

col1 col2 col3

m1 m2 m3

m4 m5 m6

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Teresa lytle,

Following code solves your problem:

REPORT ZMA_TEST .

Tables: mara, makt.

data: begin of itab occurs 0,
      matnr like mara-matnr,
"      maktx like makt-maktx,
end of itab.

data: begin of itab2 occurs 0,
       matnr like makt-matnr,
       matnr2 like makt-matnr,

      end of itab2.


select matnr into table itab from makt up to 15 rows where spras eq 'E'.

data: i type i, y type i.


describe table itab lines i.

y = i / 2.


loop at itab from 1 to y.

  itab2-matnr = itab-matnr.
  append itab2.

endloop.


loop at itab from y to i.
  itab2-matnr2 = itab-matnr.
  append itab2.

endloop.


loop at itab2.
  write: itab2.
endloop.

2 REPLIES 2

Former Member
0 Kudos

HI,

define itab2 with component col1 col2 col3 .

data: a type i value '0'.

loop at ita1.

a = a + 1.

if a = 1.

itab2-col1 = ita1-matnr.

endif.

if a = 2.

itab2-col2 = ita1-matnr.

endif.

if a = 3.

itab2-col3 = ita1-matnr.

clear a.

endif.

endloop.

hope this will help u.

Former Member
0 Kudos

Hi Teresa lytle,

Following code solves your problem:

REPORT ZMA_TEST .

Tables: mara, makt.

data: begin of itab occurs 0,
      matnr like mara-matnr,
"      maktx like makt-maktx,
end of itab.

data: begin of itab2 occurs 0,
       matnr like makt-matnr,
       matnr2 like makt-matnr,

      end of itab2.


select matnr into table itab from makt up to 15 rows where spras eq 'E'.

data: i type i, y type i.


describe table itab lines i.

y = i / 2.


loop at itab from 1 to y.

  itab2-matnr = itab-matnr.
  append itab2.

endloop.


loop at itab from y to i.
  itab2-matnr2 = itab-matnr.
  append itab2.

endloop.


loop at itab2.
  write: itab2.
endloop.