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

small issue regarding internal table

Former Member
0 Likes
644

hi friends,

can u pls solve this query asap.

i have selected three fields into an internaltable which is standard type of internal table having only three fields.

those are employeeno,date,hours........

the records are like this....

ex: 1 12/03/2008 40

2 13/03/2008 50

1 12/03/2008 60.

so i want to add the fields which have same employee no as well as same date.

and i want the record like this.

12/03/2008 100

how can i? possible send the code.

the fields in the database table r not primary fields.........

5 REPLIES 5
Read only

Former Member
0 Likes
622

use COLLECT statement

Edited by: Pankaj Singh on Mar 26, 2008 3:24 PM

Edited by: Pankaj Singh on Mar 26, 2008 3:24 PM

Read only

Former Member
0 Likes
622

Hi,

first u have to sort ur internal table by emp no and date .

then on change of emp no date , u need to collect the hours and transfer it into another internal table which will be in ur req format.

i hope u get the point

reward if helpful

Read only

Former Member
0 Likes
622

Hi Rahul,

Sort the internal table by emp no and date .

Then write on change of emp no date

use collect statement

Thanks & Regards,

AMK.

Reward Points if useful.

Read only

Former Member
0 Likes
622

First Declare your internal table2 with the employee_no, date, hours fields and collect them into this table from your original internal table(say internal table 1).

1 12/03/2008 40

2 13/03/2008 50

1 12/03/2008 60

loop at it_table1.

move: it_table1-employee_no to it_table2-employee_no,

it_table1-date to it_table2-date,

it_table1-hours to it_table2-hours.

collect it_table2.

endloop.

you will have a records like this

1 12/03/2008 100.

2 13/03/2008 50.

Note if you dont want the employee no. just do repeat the above process but this way if you have another employee who worked on the same date will get collected

for eg:

1 12/03/2008 40

2 13/03/2008 50

1 12/03/2008 60

2 12/03/2008 70 "Assumption of this record in your internal table

loop at it_table2.

move it_table2-date to it_table3-date,

it_table2-hours to it_table3-hours.

collect it_table3.

endloop.

you will have records like this.

12/03/2008 170.

13/03/2008 50.

siddu

Read only

Former Member
0 Likes
622

Hello you can use the following code:


SORT it_table1 BY date hours.
LOOP AT it_table1.
  COLLECT it_table1 INTO it_table2.
ENDLOOP.

Regards.