Former Member

# Grouping logic Required

Dear All,

We have a requirment where grouping of fields is required.

Requirment is to build a range for cumulative case number grouped on weight.

To simplify following is the example

i. Delivery D1 is having 20 batches B1, B2, B3u2026u2026u2026.B10

ii. Each batch is having cumulative case number as one of the characteristics which has numbers like 1,2,3,4,5,7,8,9,10,11 each with a weight as 20,20,20.5,20,21,20,20,20,20,20

Batch Number Case Number Weight

B1 1 20

B2 2 20

B3 3 20.5

B4 4 20

B5 5 21

B6 6 20

B7 7 20

B8 8 20

B9 9 20

B10 10 20

iv. So we need to print as follow

1. 1-2 => 20

2. 3 => 20.5

3. 4 => 20

4. 5 => 21

5. 7-11 => 20

Points would be awarded accordingly

Regards,

Rishikesh

10|10000 characters needed characters exceeded

### Related questions

Former Member
Posted on Jul 24, 2008 at 03:55 PM

2 simple steps mate.

One: Declare a table as follows. (All fields assumed to be char in example). Be sure to declare "weight" as the first field in the list of table fields.

DATA: BEGIN OF tab OCCURS 0,

weight TYPE char10,

batch TYPE char10,

case TYPE char10,

END OF tab.

Two: Write the following logic to print output exactly as required.

LOOP AT tab.

tab1 = tab.

AT NEW weight.

var = tab1-case.

ENDAT.

AT END OF weight.

WRITE var.

IF var <> tab1-case.

WRITE '-'.

WRITE tab1-case.

ENDIF.

WRITE '=>'.

WRITE tab1-weight.

WRITE /.

ENDAT.

ENDLOOP.

10|10000 characters needed characters exceeded
• Former Member
Posted on Jul 24, 2008 at 03:42 PM

Write the codig as ..

Declare Itab with the following structure .. and populate the

values ..

data : begin of itab occurs 0,

b type p decimals 2,

a type i,

end of itab.

itab-a = '1'.

itab-b = '20'.

append itab.

itab-a = '2'.

itab-b = '20'.

append itab.

itab-a = '3'.

itab-b = '20.5'.

append itab.

itab-a = '4'.

itab-b = '20'.

append itab.

itab-a = '5'.

itab-b = '21'.

append itab.

itab-a = '6'.

itab-b = '20'.

append itab.

itab-a = '7'.

itab-b = '20'.

append itab.

itab-a = '8'.

itab-b = '20'.

append itab.

itab-a = '9'.

itab-b = '20'.

append itab.

itab-a = '10'.

itab-b = '20'.

append itab.

data : v_count type i.

loop at itab.

v_count = v_count + 1.

at end of b.

write :/ itab-b ,

v_count.

clear : v_count.

endat.

endloop.

O/P ....

20.00 2

20.50 1

20.00 1

21.00 1

20.00 5

10|10000 characters needed characters exceeded
• Former Member Former Member

u can just take a variable and write in the loop .. endloop

data : v_count type i.

loop at itab.

at new b.

v_count = v_count + 1.

endat.

at end of b.

write :/ v_count,

'-' ,

sy-tabix , itab-b ,

clear : v_count.

endat.

endloop.

• Former Member
Posted on Jul 24, 2008 at 03:46 PM

Hi,

Try this:

```Loop at itab.

on change of itab-field3.
write:/ itab-field1, '-'.
endon.

c1 = c1 + 1.
at end of field3.
write: itab-field1, '=>'.
write: c1.
clear c1.
endat.

endloop.

```

regards,

Subramanian