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

ABAP Query Code for Count Function

adeel_sarwar
Contributor
0 Likes
975

Hi,

I have an ABAP Query and just created a new field which requires ABAP Code to do the following :-

The report is for Purchase Orders and Purchase Requisitions. 2 Purchase Orders may have the same requisition, so what I want to do is count the number of the same requisitions in the report

e.g.

PO Req Count

45000001 10015 2

45000020 10015 2

Can some one please provide with the full code? Points will be awarded

Thanks

4 REPLIES 4
Read only

Former Member
0 Likes
698

If you ONLY need number of requistions following code works...

DATA : BEGIN OF itab OCCURS 0,

banfn LIKE eban-banfn,

ebeln LIKE ekko-ebeln,

END OF itab.

DATA : count(2) TYPE p.

DATA : no_of_records(3) TYPE p.

"your code goes here to get POs and Reqs.

SORT itab BY banfn ebeln.

LOOP AT itab.

ADD 1 TO count.

AT END OF banfn.

IF count GE 2.

ADD count TO no_of_records.

ENDIF.

CLEAR count.

ENDAT.

ENDLOOP.

WRITE 😕 no_of_records.

Read only

0 Likes
698

Hi,

No errors in the below code but it is bringing a value 0 even though there are duplicates in the table which is suggesting to me that the code is not working.

Any help would be appreciated. Thanks

DATA : BEGIN OF itab OCCURS 0,

aufnr LIKE ekkn-aufnr,

END OF itab.

DATA : count(2) TYPE p.

DATA : no_of_records(3) TYPE p.

Clear no_of_records.

select aufnr from ekkn into itab.

endselect.

SORT itab BY aufnr.

LOOP AT itab.

ADD 1 TO count.

AT END OF aufnr.

IF count GE 2.

ADD count TO no_of_records.

ENDIF.

CLEAR count.

ENDAT.

ENDLOOP.

*WRITE 😕 'Good Bye'.

DUPLICATES = NO_of_records.

Read only

Former Member
0 Likes
698

Hi Adeel,

Sort the table by Purchase Requisitions.

Loop at Itab.

count = count + 1.

At New Req.

Count is the number of same requisitions.

Here you can modify the table Itab where req = itab-req and Count = count.

Endat.

Endloop.

Hope it helps.

Lokesh

Edited by: Lokesh Aggarwal on Jan 2, 2008 5:01 PM

Read only

adeel_sarwar
Contributor
0 Likes
698

ABAP Programmer used