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 from an internal table where flag = 'X' (in 7.4 netweaver above)

0 Kudos

Hi Experts,

is it possible to improve my logic(7.4 above alternative) so that we have lesser lines yet the same results?

i also consider LOOPING into ITAB and adding counter logic

but i'm thinking if is it possible to have one line logic for counting

eg. describle table itab where key = 'Key1' and flag1 = 'X' lines Key1Flag1count.

describle table itab where key = 'Key1' and flag2 = 'X' lines Key1Flag2count.

result should be:

Key1Flag1count = 2

Key1Flag2count = 0

Key1Flag3count = 2

Key2Flag1count = 0

Key2Flag2count = 2

Key2Flag3count = 0

1 ACCEPTED SOLUTION

anmolamb
Participant

Hi mchua9,

As you said you are working on 7.40 then REDUCE statement can come for rescue.

data(lv_lines) = REDUCE i( init x = 0 for wa in itab where ( key1 = 'Key1' or key2 = 'Key2' ..... ) next x = x + 1 ).

Regards,

Anmol

6 REPLIES 6

mateuszadamus
Active Contributor
0 Kudos

Hi mchua9

I would go with a LOOP statement, because you want to have a count of records for different conditions. This way you will only LOOP once through the table and count all necessary records in one go.

Regards,
Mateusz

Sandra_Rossi
Active Contributor
0 Kudos

Your question is incoherent: where are KEY2 and KEY3 columns?

anmolamb
Participant

Hi mchua9,

As you said you are working on 7.40 then REDUCE statement can come for rescue.

data(lv_lines) = REDUCE i( init x = 0 for wa in itab where ( key1 = 'Key1' or key2 = 'Key2' ..... ) next x = x + 1 ).

Regards,

Anmol

0 Kudos

FILTER statement is also similar with transferring and deleting internal tables, which is great

but REDUCE statement gets the requirement done in just a single line! thank you for this answer!

0 Kudos

Hi Anmol,

I had a similar requirement where I had to simulate the COUNT feature of SELECT syntax over an INTERNAL Table.

And your response helped me in achieving the same, just attaching the sample code snippet for others with similar requirements.

Thanks,

Sijin