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

problem in loop at internal table

Former Member
0 Likes
1,347

Hello Friends,

below is my internal table

it_bsis

bukrs hkont aufnr budat wrbtr1

1000 0000300101 000602000002 20080501 7500.00

1000 0000300101 000602000026 20080920 13350.00

1000 0000300101 000602000026 20080923 20025.00

1000 0000300102 000602000026 20080923 10000.00

1000 0000302111 99ASD 20081129 120000.00

1000 0000302111 99ASD 20081129 150000.00

1000 0000302111 99ASD 20081129 150000.00

1000 0000302111 99ASD 20081130 120000.00

1000 0000302118 08CARNINT001 20080731 150000.00

1000 0000302118 08CARNINT001 20080731 100000.00

1000 0000302118 08CARNINT001 20080831 20000.00

1000 0000302118 08CARNINT001 20080707 150000.00

1000 0000302118 08CARNINT001 20080707 100000.00

1000 0000302118 08CARNINT001 20080801 20000.00

Expected output is

it_bsis2

bukrs hkont aufnr budat wrbtr1

1000 0000300101 000602000002 20080501 7500.00

1000 0000300101 000602000026 20080920 13350.00 + 20025.00

1000 0000300102 000602000026 20080923 10000.00

1000 0000302111 99ASD 20081129 540000.00

1000 0000302118 08CARNINT001 20080801 54000.00

can some one guide me to get the correct output.

i want to group them together on the basis of these conditions.

against one aufnr there can be many hkont , i have to sum up all hkont along with wrbtr1.

1 ACCEPTED SOLUTION
Read only

former_member873340
Active Participant
0 Likes
1,331

Hi Jitesh,

SAP has a wonderful inbuilt feature to achieve this.

try to use this code.

loop at it_bsis.

at end of aufnr.

sum.

modify it_bsis.

endat.

endloop.

sort it_bsis by bukrs hkont ascending wrbtr1 descending.

delete adjacent duplicates comparing bukrs hkont aufnr.

I am sure it will solve your query.

Let me know in case you face any problem.

Gowri

8 REPLIES 8
Read only

faisalatsap
Active Contributor
0 Likes
1,331

Hi,

Use COLLECT hope will solve out your problem

Reply if any Issue,

Best Regards,

Faisal

Read only

Former Member
0 Likes
1,331

Jithesh,

You could use either the Collect Statement or On Change Of statement to achieve this purpose.

Try playing in ABAP using those two statements.

Thanks,

Babu Kilari

Read only

former_member873340
Active Participant
0 Likes
1,332

Hi Jitesh,

SAP has a wonderful inbuilt feature to achieve this.

try to use this code.

loop at it_bsis.

at end of aufnr.

sum.

modify it_bsis.

endat.

endloop.

sort it_bsis by bukrs hkont ascending wrbtr1 descending.

delete adjacent duplicates comparing bukrs hkont aufnr.

I am sure it will solve your query.

Let me know in case you face any problem.

Gowri

Read only

0 Likes
1,331

Dear Gowri,

Your solution is wat i wanted .. but i need a lil more modifictaion.

1000 0000300101 000602000002 ******** 7500.00

1000 0000300101 000602000026 20080920 13350.00

1000 0000300101 000602000026 ******** 33375.00

1000 0000302111 99ASD 20081129 120000.00

1000 0000302111 99ASD 20081129 150000.00

1000 0000302111 99ASD 20081129 150000.00

1000 0000302111 99ASD ******** 540000.00

1000 0000302118 08CARNINT001 20080731 150000.00

1000 0000302118 08CARNINT001 20080731 100000.00

1000 0000302118 08CARNINT001 20080831 20000.00

1000 0000302118 08CARNINT001 20080707 150000.00

1000 0000302118 08CARNINT001 20080707 100000.00

1000 0000302118 08CARNINT001 ******** 540000.00

but the only drawback is .. it convert s my date into ********.

i need the date also

Read only

0 Likes
1,331

ha ha i expected this

anyway the solution is take the date field into a variable and then modify it.

something like this

loop at it_bsis.

l_date = it_bsis-budat.

at end of aufnr.

sum.

it_bsis-budat = l_date.

modify it_bsis.

endat.

endloop.

Due to the property of at end of... it converts all characters to ******* so hence the problem....

Tell me in case u need further help

Gowri

Read only

0 Likes
1,331

Thanks gowri

Your query is working fine.

Read only

Former Member
0 Likes
1,331

HI,

Try this Code.

SORT ITAB BY BUKRS HKONT AUFNR BUDAT DESCENDING.
LOOP AT ITAB.
WA = ITAB.
L_WRBTR = L_WRBTR + ITAB-WRBTR.
AT END OF AUFNR.

WRITE :/ WA-BUKRS, 
              WA-HKONT,
              WA-AUFNR,
              WA-BUDAT,
              L_WRBTR.
CLEAR L_WRBTR.
SKIP.
ENDAT.

ENDLOOP.

Read only

Former Member
0 Likes
1,331

Hi Jitesh,

First you will need to SORT internal table in ascending order on aufnr and hkont.

The Loop at internal table and use "ON CHANGE OF" statement to sum up the values of fields.

Regards

Shital