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

Internal Table Question

Former Member
0 Likes
702

Hi,

I have an internal table as follows..

loc1 matnr charg good

loc1 matnr charg good

loc1 matnr charg good

loc1 matnr charg ok

loc1 matnr charg bad

loc2 matnr charg good

loc2 matnr charg good

loc2 matnr charg ok

loc2 matnr charg bad

Now i want to get a count of how many goods,bad and ok are there in another table..

For ex my result should be as follows..

Loc good ok bad

-


loc1 3 1 1

loc2 2 1 1

Thanks for any ideas..

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
680

Hi,

Please try this.


DATA: BEGIN OF ITAB2 OCCURS 0,
        LOC(4),
        T_GOOD TYPE I,
        T_OK  TYPE I,
        T_BAD TYPE I.
DATA: END OF ITAB2.

SORT ITAB1 BY LOC.

LOOP AT ITAB1.
  CLEAR ITAB2.
  ITAB2-LOC = ITAB1-LOC.
  
  CASE ITAB1-COND.
     WHEN 'GOOD'.
        ITAB2-T_GOOD = '1'.
     WHEN 'OK'.
        ITAB2-T_OK = '1'.
     WHEN 'BAD'.
        ITAB2-T_BAD = '1'.
   ENDCASE.
 
  COLLECT ITAB2.
ENDLOOP.

LOOP AT ITAB2.
  WRITE: / ITAB2-LOC, ITAB2-T_GOOD, ITAB2-T_OK, ITAB2-T_BAD.
ENDLOOP.

Regards,

Ferry Lianto

5 REPLIES 5
Read only

Former Member
0 Likes
680

hi aries,

in the loop of the internal table u can keep a counter like when that value of the variable is good, increase the counter to 1. Likewise u can proceed.

Regards...

Arun

Read only

Former Member
0 Likes
681

Hi,

Please try this.


DATA: BEGIN OF ITAB2 OCCURS 0,
        LOC(4),
        T_GOOD TYPE I,
        T_OK  TYPE I,
        T_BAD TYPE I.
DATA: END OF ITAB2.

SORT ITAB1 BY LOC.

LOOP AT ITAB1.
  CLEAR ITAB2.
  ITAB2-LOC = ITAB1-LOC.
  
  CASE ITAB1-COND.
     WHEN 'GOOD'.
        ITAB2-T_GOOD = '1'.
     WHEN 'OK'.
        ITAB2-T_OK = '1'.
     WHEN 'BAD'.
        ITAB2-T_BAD = '1'.
   ENDCASE.
 
  COLLECT ITAB2.
ENDLOOP.

LOOP AT ITAB2.
  WRITE: / ITAB2-LOC, ITAB2-T_GOOD, ITAB2-T_OK, ITAB2-T_BAD.
ENDLOOP.

Regards,

Ferry Lianto

Read only

0 Likes
680

Thanks Ferry Lianto .It works

Read only

Former Member
0 Likes
680

Hi,

Use at new control break statement and put one variable like count = 0, then

increase this count to 1 after end of control statement.

loop at itab.

at new matnr

write count.

endat.

count = count +1.

endloop.

Regards,

Bhaskar

Read only

Former Member
0 Likes
680

I have just modified Ferry's code and added a line CLEAR ITAB2 .

DATA: BEGIN OF ITAB2 OCCURS 0,

LOC(4),

T_GOOD TYPE I,

T_OK TYPE I,

T_BAD TYPE I,

END OF ITAB2.

SORT ITAB1 BY LOC.

LOOP AT ITAB1.

ITAB2-LOC = ITAB1-LOC.

CASE ITAB1-COND.

WHEN 'GOOD'.

ITAB2-T_GOOD = '1'.

WHEN 'OK'.

ITAB2-T_OK = '1'.

WHEN 'BAD'.

ITAB2-T_BAD = '1'.

ENDCASE.

COLLECT ITAB2.

CLEAR ITAB2. * ELSE ALL THE CONDITION TYPES SAY GOOD BAD AND OK WUD GET ADDED EACH TIME.

ENDLOOP.

LOOP AT ITAB2.

WRITE: / ITAB2-LOC, ITAB2-T_GOOD, ITAB2-T_OK, ITAB2-T_BAD.

ENDLOOP.