2019 Aug 16 10:53 AM
Hi all,
I am using the following code to get the row count of an Internal Table
IF sy-subrc IS INITIAL.
SELECT KUNNR VBELN FROM VBAK
INTO TABLE g_it_vbak
FOR ALL ENTRIES IN g_it_kna1
WHERE KUNNR EQ g_it_kna1-kunnr.
g_anzahl = lines( g_it_vbak ).
However, I am looking to get the number of row count against KUNNR. I mean I need to have output where I will have lines count per client and not the total number of row counts against the query.
Thanks in advance.
Arnab
2019 Aug 16 11:02 AM
2019 Aug 16 11:02 AM
2019 Aug 16 11:05 AM
At first I did with COUNT( * ). This gave me the same result until and unless I put the Select inside a LOOP. The person who made the request for the program did not like Select inside a loop. So, I am trying to find another solution.
2019 Aug 16 1:46 PM
arnab19871 try something like this. You will get count of VBELN per each KUNNR in one SELECT statement. Study the documentation and examples for more details.
EDIT: you will have to replace FOR ALL ENTRIES IN with range table (WHERE kunnr IN lt_kunnr_range_tab), because COUNT does not support "FAE".
SELECT COUNT( DISTINCT vbeln ) kunnr<br> INTO TABLE lt_orders_per_customer
2019 Aug 16 5:24 PM
2019 Aug 19 7:53 AM
2019 Aug 19 12:26 PM
2019 Aug 21 1:37 PM
se38 Yes, he is a great person. That's why he gave a middle age man with no coding experience a chance. I just hope I can learn fast and make him feel that he did not make any mistake.
2019 Aug 21 2:57 PM
Thanks for the input guys. The problem is solved. I am attaching my code for anybody who might have the same problem in the future. Please see the comment section of this post for the full Programme.
Data Declaration:
Data: g_anzahl TYPE i.
Select Option:
IF sy-subrc IS INITIAL.
SELECT KUNNR VBELN FROM VBAK
INTO CORRESPONDING FIELDS OF TABLE g_it_vbak
FOR ALL ENTRIES IN g_it_kna1
WHERE KUNNR EQ g_it_kna1-kunnr.
ENDIF.
To get the desired output: (This loop is placed inside another loop for the output)
IF sy-subrc = 0.
CLEAR g_anzahl.
LOOP AT g_it_vbak INTO g_wa_vbak WHERE KUNNR = g_wa_kna1-kunnr.
g_anzahl = g_anzahl + 1.
* ADD 1 to g_anzahl.
ENDLOOP.