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

Former Member
0 Likes
564

Hi gurus,

my requirement is to change one internal table to anotherone like....

INTERNAL TABLE A

NAME TUES POL COST

rahul 1000 mumbai 2000

abhay 999 delhi 1400

shetal 888 banglore 1500

nitin 777 gurgaon 1788

...... ...... ....... .........

...... ....... ......... ............

and the output i want to be....

INTERNAL TABLE B

COMPANY1 COMPANY2 COMPANY3 COMPANY4 .............

rahul abhay shetal nitin .............

i am getting INTERNAL TABLE A from function module...ineed to transfer first coulmn value to INTERNAL TABLE B

regards

rahul

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
524

Hi rahul,

You can loop at first internal table, store first column in a variable. Then second index onwards you can go on concatenating first column data into that variable separated by space.

e.g.

data: v_name type string.

Loop at itab into wa_itab.
 if sy-tabix eq 1.
   v_name = wa_itab-name.
 else.
   concatenate v_name wa_itab-name into v_name separated by space.
 Endif.
Endloop.

Use this string to append to your second internal table. Hope it helps.

Thanks,

Archana

6 REPLIES 6
Read only

Former Member
0 Likes
525

Hi rahul,

You can loop at first internal table, store first column in a variable. Then second index onwards you can go on concatenating first column data into that variable separated by space.

e.g.

data: v_name type string.

Loop at itab into wa_itab.
 if sy-tabix eq 1.
   v_name = wa_itab-name.
 else.
   concatenate v_name wa_itab-name into v_name separated by space.
 Endif.
Endloop.

Use this string to append to your second internal table. Hope it helps.

Thanks,

Archana

Read only

Former Member
0 Likes
524

Hi,

This is simple

1.loop in tableA

2. write the value of name in table B

3.append the same in te TableB.

You'll get the desired result.

Hope this might solve your problem.

Pooja

Read only

anup_deshmukh4
Active Contributor
0 Likes
524

hello rahulsparshmeenu

do you want the internal table B to be dynamic coz you want to transpose the internal table A ( According to example...you have suggested....)

in that case you Columns in IT B would be dynamic if this is the case please update for further assistance

Read only

0 Likes
524

yes i want it to be dynamic as it has to be transfered to

IT_FINAL

to show in alv.

regards

rahul

Read only

0 Likes
524

Oks...for that Case you will have to go for a long procedure USING RTTS ....!

1. Count the no of copanies( unique )... in the IT A

2. Get a structre Constructed using RTTS for all the Companies ie. Build the structre for IT B according to requirement......! then create a table for the structre ( append the Values....)

3. Create a Dynamic Field Catlogue for the same

4. Display the ITAB

For RTTS refer to the below link

http://wiki.sdn.sap.com/wiki/display/ABAP/RuntimeTypeServices+%28RTTS%29

Or if you understant field symbols very good you can construct you own..!

Read only

Former Member
0 Likes
524

Hi

u can go for the following logic:-

data: v_lines type i,
         v_str type string.
data: it_table type ref to data.

describe table IT_A lines v_lines.

do v_lines times.
 concatenate 'company' sy-index into v_str.
  wa_fcat-fieldname = v_str.
  .
  .
 append wa_fcat to it_fcat.
enddo.

CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING
      it_fieldcatalog = it_fcat
    IMPORTING
      ep_table        = it_table.
  IF sy-subrc = 0 .

   ASSIGN it_table->* TO <fs_table>.
* Create dynamic work area and assign to FS
    CREATE DATA it_line LIKE LINE OF <fs_table>.
    ASSIGN it_line->* TO <fs_wa>.

.

now you have your dynamic internal table <fs_table> and work area <fs_wa>

to do required processing.

Rgds/Abhi