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: 

count registers in loop

former_member182371
Active Contributor
0 Kudos

Hi,

i´ve got the following internal table:

DATA: BEGIN OF ITAB OCCURS 0.

RSNUM TYPE MSEG-RSNUM,

RSPOS TYPE MSEG-RSPOS,

CHARG TYPE MSEG-CHARG.

DATA: END OF ITAB.

i can have several CHARG within the same RSNUM RSPOS.

How can i know the number of RSNUM RSPOS?

e.g.

RSNUM RSPOS CHARG

7000000182 0001 C000000548

7000000182 0001 C000000549

7000000182 0002 C000000550

in a LOOP with AT NEW RSNUM i would get the number of RSNUM but i need the combination of RSNUM RSPOS.

How can i do like AT NEW but for both RSNUM and RSPOS?

Best regards.

1 ACCEPTED SOLUTION

former_member182371
Active Contributor
0 Kudos

Sorry, the former example was a wrog one.

the correct example would be:

RSNUM RSPOS CHARG

7000000182 0001 C000000548

7000000182 0001 C000000549

7000000182 0002 C000000550

7000000183 0001 C000000551

here i would need: number of registers = 3

1 for 7000000182 0001

1 for 7000000182 0002

1 for 7000000183 0001

Sorry and my excuses for the former post.

Best regards.

12 REPLIES 12

Former Member
0 Kudos

You could say at new RSPOS, all the changes on teh left hand side of the filed are treated as new.

Rgds,

Manohar

make sure to sort the table rsnum rspos

Former Member
0 Kudos

try ON CHANGE OF ..... RSNUM or RSPOS.

regards

Former Member
0 Kudos

With your internal table

DATA COUNT TYPE I.

LOOP AT ITAB.

.....

.....

count = count + 1.

At end of RSPOS.

< Here in field count you will have the no of lines

corresponding to one RSNUM & RSPOS >

ENDAT.

ENDLOOP.

Former Member
0 Kudos

Hi

Do You want to know the number of combination or all combination?

Max

former_member182371
Active Contributor
0 Kudos

Hi,

with this example:

RSNUM RSPOS CHARG

7000000182 0001 C000000548

7000000182 0001 C000000549

7000000182 0002 C000000550

the number of registers i need is 2

1 for 7000000182 0001 and

1 for 7000000182 0002

Best regards.

0 Kudos

Sir ,

Please say at

Loop at table.

at new rspos.

count = count + 1.

at end.

endloop.

former_member182371
Active Contributor
0 Kudos

Sorry, the former example was a wrog one.

the correct example would be:

RSNUM RSPOS CHARG

7000000182 0001 C000000548

7000000182 0001 C000000549

7000000182 0002 C000000550

7000000183 0001 C000000551

here i would need: number of registers = 3

1 for 7000000182 0001

1 for 7000000182 0002

1 for 7000000183 0001

Sorry and my excuses for the former post.

Best regards.

0 Kudos

Hi

Use AT END or AT NEW event for field RSPOS

LOOP AT itab

AT NEW RSPOS.

ENDAT.

ENDLOOP

Remember:

LOOP AT itab

AT NEW FIELD.

ENDAT.

ENDLOOP

these events runs if a value of a field at left of FIELD is changing or if the value of FIELD is changing.

Max

Message was edited by: max bianchi

Message was edited by: max bianchi

0 Kudos

then do like this -

data v_cnt type i.

sort itab by RSNUM RSPOS CHARG.

loop at itab.

at new RSPOS.

v_cnt = v_cnt + 1.

endat.

endloop.

it will give you v_cnt = 3 for the example you mentioned here, i.e. -

RSNUM RSPOS CHARG

7000000182 0001 C000000548

7000000182 0001 C000000549

7000000182 0002 C000000550

7000000183 0001 C000000551

0 Kudos

If you are not really interested in keeping the duplicate RSNUM RSPOS in your internal table, then simply do this;


SORT itab BY rsnum rspos.
DELETE ADJACENT DUPLICATES FROM itab COMPARING rsnum rspos.
DESCRIBE TABLE itab LINES v_cnt.

This will give you what you want. Now if you want to keep your original itab intact, then make a copy of it and do this on the copy.

Regards,

Srinivas

0 Kudos

hi

7000000182 0001 C000000548

7000000182 0002 C000000548

7000000182 0003 C000000548

7000000182 0001 C000000549

7000000182 0001 C000000549

7000000182 0001 C000000549

7000000182 0002 C000000550

7000000183 0001 C000000551

7000000183 0003 C000000551

what is your expected result.

7000000182 0001 C000000548

7000000182 0001 C000000549

7000000182 0002 C000000550

7000000183 0001 C000000551

as per your example if you delete the adjacent duplicates

all the records has 1 value.

please clarify bit more.

cheers,

sasi

0 Kudos

> Sorry, the former example was a wrog one.

> the correct example would be:

> RSNUM RSPOS CHARG

> 7000000182 0001 C000000548

> 7000000182 0001 C000000549

> 7000000182 0002 C000000550

> 7000000183 0001 C000000551

>

> here i would need: number of registers = 3

> 1 for 7000000182 0001

> 1 for 7000000182 0002

> 1 for 7000000183 0001

>

> Sorry and my excuses for the former post.

> Best regards.

Hi Sasi,

If you look at his post pasted above, you will see that he wanted the count of unique RSNUM RSPOS combination which is what my response will achieve.

Calsadillo, can you please let me know if I am on the wrong track? If not, please close the post once answered.

Regards,

Srinivas