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

'at new' problem

Former Member
0 Likes
836

hi all.

i have an internal table with a counter (aa), coep-belnr and coep-buzei.

so with the same belnr and different buzei in the counter must be added 1 each time.

and each time that i have new belnr then the counter will be equal to 1 and so on.

for example.

belnr buzei aa(counter)

A A 1

A B 2

A C 3

B A 1

B B 2

B C 3

B D 4

i used many codes but the resault was not the one i wanted.

one of them is:

sort it_file by belnr buzei.

loop at it_file.

h_file = it_file.

at new belnr.

h_file-aa = 0.

at new buzei.

add 1 to h_file-aa.

endat.

endat.

modify it_file from h_file index sy-tabix.

endloop.

please if you have smth in mind.........

thank you.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
818

DATA : COUNT TYPE I.

sort it_file by belnr buzei.

loop at it_file.

h_file = it_file.

at new buzei.

add 1 to COUNT.

endat.

H_FILE-AA = COUNT.

AT END OF BELNR.

COUNT = 0.

ENDAT.

modify it_file from h_file index sy-tabix.

endloop.

REGARDS

SHIBA DUTTA

hi all.

i have an internal table with a counter (aa), coep-belnr and coep-buzei.

so with the same belnr and different buzei in the counter must be added 1 each time.

and each time that i have new belnr then the counter will be equal to 1 and so on.

for example.

belnr buzei aa(counter)

A A 1

A B 2

A C 3

B A 1

B B 2

B C 3

B D 4

i used many codes but the resault was not the one i wanted.

one of them is:

sort it_file by belnr buzei.

loop at it_file.

h_file = it_file.

at new belnr.

h_file-aa = 0.

at new buzei.

add 1 to h_file-aa.

endat.

endat.

modify it_file from h_file index sy-tabix.

endloop.

please if you have smth in mind.........

thank you.

6 REPLIES 6
Read only

Former Member
0 Likes
818

Hi,

data: g_count type sy-index.

loop at itab.

g_count = g_count+1.
aa = gcount.
modify itab transporting aa.
at new belnr.
g_count = 0.
endat.
endloop.

This will work

Jogdand M B

Read only

Former Member
0 Likes
819

DATA : COUNT TYPE I.

sort it_file by belnr buzei.

loop at it_file.

h_file = it_file.

at new buzei.

add 1 to COUNT.

endat.

H_FILE-AA = COUNT.

AT END OF BELNR.

COUNT = 0.

ENDAT.

modify it_file from h_file index sy-tabix.

endloop.

REGARDS

SHIBA DUTTA

Read only

Former Member
0 Likes
818

The order of the fields in your table affect the results. If you have your table declared as :

belnr

buzei

counter

then the at new buzei statement will occur every time belnr changes. When you state at new belnr, then fields to the right are populated with *. This too will affect the operation of your code.

Read only

Former Member
0 Likes
818

hi

you can try with this.

Data l_local like itab.

Data l_local1 like itab.

Loop at itab.

Clear l_local.

L_local = itab.

At new itab-belnr.

L_local-aa =0.

Clear l_local1.

Endat.

L_local1 = l_local.

If l_local1- buzei = l_local-buzei.

L_local-aa = L_local-aa + 1.

Endif.

Modify itab from l_local index sy-tabix.

Endloop.

thanks

Mohit

Read only

Former Member
0 Likes
818

hi

Please check with this change.

Data l_local like itab.

Data l_local1 like itab.

Loop at itab.

Clear l_local.

L_local = itab.

At new itab-belnr.

L_local-aa =0.

Clear l_local1.

Endat.

L_local1 = l_local.

If l_local1- buzei <> l_local-buzei. " change

L_local-aa = L_local-aa + 1.

Endif.

Modify itab from l_local index sy-tabix.

Endloop.

thanks

Mohit

Read only

Former Member
0 Likes
818

thank you all.