ABAP Query Code for Count Function

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

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.

Similar Messages

  • ABAP Sample code for HR_MAINTAIN_MASTERDATA

    Hi folks,
    I want to delimit a record in the HR master Table wi the help of Function Module HR_MAINTAIN_MASTERDATA, but its not updating HR master table correctly so please send me some sample code for that function module.
    usefull points will rewarded.
    Reg,
    Hariharan

    hi
    good
    check with this code
    Call update function module:
          CALL FUNCTION 'HR_MAINTAIN_MASTERDATA'
            EXPORTING
              PERNR           = SS300_0001T-PERNR
              ACTIO           = OPERATION
              BEGDA           = VALIDITYBEGIN
              ENDDA           = '99991231'
              SUBTY           = SPACE
              NO_ENQUEUE      = SPACE
            IMPORTING
              RETURN1         = RETURN
            TABLES
              PROPOSED_VALUES = VALUES
            MODIFIED_KEYS   =
            EXCEPTIONS
              OTHERS          = 1.
          IF RETURN IS INITIAL.
            CONCATENATE SS300_0002-VORNA SS300_0002-NACHN
              INTO ENAME SEPARATED BY SPACE.
            CONDENSE ENAME.
            MESSAGE S006 WITH ENAME SPACE.
          ELSE.
            MESSAGE ID     RETURN-ID
                    TYPE   'S'
                    NUMBER RETURN-NUMBER
                    WITH   RETURN-MESSAGE_V1 RETURN-MESSAGE_V2
                           RETURN-MESSAGE_V3 RETURN-MESSAGE_V4.
          ENDIF.
    http://help.sap.com/saphelp_nw04/helpdata/en/f1/0ce464dc8b11d2803800c04f99fbf0/content.htm
    reward point if helpful.
    thanks
    mrutyun^

  • How to create a transaction code for a function group with screen 100 as st

    Hello ,
    I have requirement where I need to create a function group and create screen 100, 200, 300 and include the function in the screens.
    Customer asked me to create a transaction with the screen 100 as the starting screen.
    Can you please let me know how to create a transaction code for a function group with screen 100 as starting screen.
    [ It is not a module pool program ].
    Thanks
    Prashanth.
    Moderator message - Please ask a specific question and do not ask the forum to do your work for you - post locked
    Edited by: Rob Burbank on Jun 2, 2009 11:49 AM

    Go to transaction SE93, enter a transaction code that you want and click on "create". Enter a text and select the "Transaction with Parameters" button. In the Default Values section, enter START_REPORT in the transaction field. Check the "skip initial screen" box. In the Name of Screen field section enter the following lines:
    Name of screen field:                               Value
    D_SREPOVARI-REPORTTYPE                RW
    D_SREPOVARI-REPORT                        ZPCA
    Save and transport accordingly.

  • How to insert a code for a function module into a Customer Exit Variable?

    I have two Key Figures viz., Net Prchs Rtl, and Net Prchs Unt. Both these Key figures have This Week (TW) and Last Week (LW). There is a variable for This week but there is no variable defined for Last week.
    I need to get data in the column LW (Last Week) for both the key figures.
    In function module EXIT_SAPLRRS0_001 one of the functions I have is:
    Get the previous Fiscal Week
              CALL FUNCTION 'DATE_TO_PERIOD_CONVERT'
    I need to create a new variable to get values in the Last week column for different key figures and use function “'DATE_TO_PERIOD_CONVERT'” in that variable.
    Can anyone please explain me the steps as to how to use a function module in a variable so that when the variable is used in a key figure it shows the output.
    In other words what I want to know is after creating a Customer exit variable of type Characteristic value how do I refer the above mentioned function moduel and insert the code for the function module into the Customer exit variable that I created.
    Thank you.
    TR.

    Hi Wond,
    Thanks a lot for your reply. I understand what you mean but I have never done this before so can you please explain it in a detailed manner. I have the following code:
    Get the previous Fiscal Week
              CALL FUNCTION 'DATE_TO_PERIOD_CONVERT'
                EXPORTING
                  i_date         = ld_date
                  i_periv        = lc_periv
                IMPORTING
                  e_buper        = ln_poper
                  e_gjahr        = ln_bdatj
                EXCEPTIONS
                  input_false    = 1
                  t009_notfound  = 2
                  t009b_notfound = 3
                  OTHERS         = 4.
              IF sy-subrc <> 0.
                MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
              ELSE.
                lc_poper = ln_poper.
                CONCATENATE ln_bdatj lc_poper+1(2) INTO wa_e_t_range-low.
                wa_e_t_range-sign = 'I'.
                wa_e_t_range-opt = 'EQ'.
                APPEND wa_e_t_range TO e_t_range.
              ENDIF.
            ENDIF.
          ENDIF.
        ENDIF.
    I believe I should now use the above code in my customer exit variable. If that's right can you please explain me the steps as to how should I do this so that the variable gets populated.
    Thank you.
    Regards,
    TR.

  • Code for SAVE functionality in FPM_OIF_COMPONENT

    Hi Experts,
    I have enhanced the component DPR_DET_DATA_PROJECT_O. The SAVE functionality for this component exists in FPM_OIF_COMPONENT.
    I have to raise error message depending on the custom fields added in  DPR_DET_DATA_PROJECT_O when I click on 'SAVE' button.
    Please share if any ideas where to write the code for SAVE functionality for the custom fields added on DPR_DET_DATA_PROJECT_O.
    Regards,
    Rafi

    Hi Rafi,
    These similar discussions might provide some assistance:
    BAdI or enhancement on SAVE of Cproject
    which badi triggers while saving cproject
    Code to call for saving the data in WDC - DPR_PROJECT_VIEW
    Cheers,
    Amy

  • Function Module to get ABAP source code for a specific version

    Hi all
    Is there a function module that I can use to get the source code of another function module at a specific version?
    For example, can I call a function module passing in "FM_NAME" and "FM_VERSION" and have it return the lines of code associated with that object?
    Thanks in advance.
    Stuart

    Thanks guys
    That's incredibly helpful! I have one more question that I just thought of last night...
    Is there a way to hook into the code activation process? I want to be able to take a snapshot of the ABAP source code at each point when it is activated for use in another system, but need to be able to intercept this event and get the source code at that point in time.
    Any ideas?
    Thanks!

  • SSRS custom code for count in Report Footer

    Hi All,
    Please help me with the custom code used for below requirement
    Debtor Name     current    30+days   60+days    90+days
    aaa                       7000        0.00          0.00          10.00
    bbb                       5000        0.00         20.99         3.00
    ccc                        1000       0.00          0.00           0.00
    Expected result in report footer :                  
                                              0                1            
       2
    if  the value of  30+ , 60+ and 90+ columns  >=1 then i have to display the count in Report footer,for that i have tried using a custom code like below :
    Shared Dim OD As Integer=0
    Public Shared Function Test(ByVal OP As Decimal) As Integer
            If OP >= 1 Then
                OD = OD + 1
            Else
                OD = OD
            End If
            Return OD
       End Function
    and using below code to display
    Code.Test(Overdue)  
    but when i use this code in report footer is not displaying correct value.Please guide me where i am going wrong.
    Please let me know if you need any other details.
    Thanks in advance,
    Samhith.

    Hi Samhith,
    Per my understanding you what to count the rows which values >=1 and display them at the bottom of the table, you are trying to use the custom code to do this but failed, right?
    I have tested in my local environment and find the custom code is not correctly, and I have an alternative method which is more easy and can work in both table  and matrix.
    As Vaibhav Chaudhari also mentioned that we can use the CountDistinct function, but more correctly, we can use the count() function and the RunningValue() function, because CountDistict will not count the duplicated values if they >=1.
    Please find the expression as below:
    =Count(IIf(Fields!Yourfield.Value>=1 , Fields!Yourfield.Value, Nothing))
    OR:
    =RunningValue(IIf(Fields!Yourfield.Value>=1 , 1, Nothing),Sum,"DataSetName")
    If you still have any problem, please feel free to ask.
    Regards
    Vicky Liu

  • ABAP Query : code to change the display

    Hi all,
    I have created an Abap Query and generated it. I see the output now as follows:
    <u>Bill.doc</u>     <u>Item</u>   <u>Net value</u>  <u>Total amt</u>
    900000                    10                  100                  600
    900000                    20                  200                  600
    900000                    30                  300                  600
    900001                    10                  250                  250
    900002                    10                  300                  500
    900002                    20                  200                  500
    Now I want the total amt to be displayed only once for each billing document only for the first item and for the other line items it should be blank as shown below.
    <u>Bill.doc</u>   <u>Item</u>   <u>Net value</u>  <u>Total amt</u>
    900000   10      100            600
    900000   20      200           
    900000   30      300           
    900001   10      250            250
    900002   10      300            500
    900002   20      200
    Can someone please explain me where and how I should write the code to get this working?
    Thanks,
    N
    Helpful answers will be awarded for sure.

    Hi Manohar,
    I am getting the total amount from a field which exists in one of the tables which i used in the abap query.
    the total amount is appearing correctly...i dont need to modify that. i just need to display it only once for each billing doc for the first item.
    i want to know where i should do the coding...i mean in the Infoset or the Abap Program that gets created when i generate the infoset.
    Thanks!
    N
    Message was edited by:
            Narmada Mallavaram
    null

  • ABAP Routine code for the below logic

    Hello BW Experts ,
    I need to write a complex ABAP routine in BW .
    Following is the detail explaination .
    Can anyone tell me the ABAP code for the below logic?
    It would be a greate help as I am unable to do this
    since last two days.
    WBS Elements are maintained at  IOS and  Warranty levels in R/3 side.
    The IOS WBS is a top level of WBS element and below that the Warranty WBS level.
    The IOS and Warranty WBS elements can be differentiated by means of priority field.
    When priority = i   , WBS Element is known as  IOS Level WBS Element and
    When  priority = Y the WBS element is known as Warranty WBS element.
    The Equipment Number is maintained compulsorily at IOS Level WBS elements only.
    It is not maintained at  Warranty WBS Element.
    But the Cost is maintained at Warranty WBS Elements.
    In BW I need all Warranty WBS ( priority = Y) along with their cost figures and Equipment Numbers.
    But as the Equipment Number is not maintained compulsorily at Warranty WBS level we have asked to
    Copy it from  IOS WBS ( priority = i ) and assign it to Warranty WBS level ( priority = Y ).
    So I have included the Equipment Number in the ODS and in update rules I need to write the routine for it as
    per the above logic.
    The Equipment Number is coming from Master data of  WBS Element.
    The WBS element master data we are loading in BW .
    Also the same WBS Element transaction data is coming from the transaction data data source in BW.
    Following fields / infoobjects and the table names in BW :
    1. Equipment Number : /BIC/ZEQUIPMNT  and table name /BIC/MZWBS_ELEM.
    2. WBS Element       : ZWBS_ELEM  is coming from transaction data data source as well as master data.
                                     In ODS update rules it is coming from  transaction data data source Comm_structure-ZWBS_ELEM.
                                     Also we are loading separetly the master data for ZWBS_ELEM.
                                     The  ZEQUIPMNT is an attribute of ZWBS_ELEM.
    3. Priority                :  PRIORITY     and table name /BIC/MZWBS_ELEM.
                                      The info object name for Priority is 0Priority but in master data table /BIC/MZWBS_ELEM
                                      the field name is    PRIORITY.
                                     When PRIORITY = ' i ' then    ZWBS_ELEM is at IOS Level
                                     When PRIORITY = ' y ' then  ZWBS_ELEM is at Warranty Level.
    4. ODS name :  /BIC/AZCOST00 and same is table name active data table .
    So please tell me the routine Code .
    Best Regards ,
    Amol.

    Hi Dinaker,
    Did you find any solution for this issue. I too have a similar requirement of pulling all the service orders for a specific Purchase Order in the BW report.
    Thanks,
    SAPBWI

  • Need code for a function module- Urgent

    Hi friends,
    I have a requirement where I am giving material description as an import parameter in the function module. ( Material description could be a wild search -- say - Mat* ) I want a sub routine in the function module which should get all the materials from the database ( mara or makt..not sure ) for the user entered Material description.
    I want this particular code to be written using a sub-routine using formal parameters inside this fm . Could any one send me the code for this.
    Thanks in advance,
    Vishnu.

    Hi Vishvanath,,
    Please find the below code.
    DATA : BEGIN OF itab OCCURS 0,
           matnr LIKE makt-MATNR,
           MAKTX LIKE makt-MAKTX,
           END OF itab.
    DATA : BEGIN OF itab1 OCCURS 0,
           matnr LIKE makt-MATNR,
           MAKTX LIKE makt-MAKTX,
           END OF itab1.
    data : a(5) type c value 'TEST'.
    perform mat_no using a.
    form mat_no  using    p_a.
    data : lv_temp(4) type c.
    select matnr maktx from makt into table itab.
    loop at itab.
    lv_temp = itab-maktx+0(4).
    if lv_temp = p_a.
      move itab to itab1.
      APPEND ITAB1.
    endif.
    endloop.
    loop at itab1.
    write :/ itab1.
    endloop.
    endform.                    " mat_no
    Thanks.
    Amjad.

  • Creating Java code for the function module

    Hi Colleagues,
    I have a fuction module in ABAP system. Now I want to Generate java code for the FM.
    I cam to know that we can achive that using AXIS, By getting the XML file for the fuction module and generate Java
    Class file using that XML file.
    Can any one tell me how to achive it.
    Or any other way to do that?
    Please provide you valid suggestions.
    Regards,
    Sathya

    Hi,
    You can integrate axis2 in eclipse. I think you have to find the plugin for that.
    After that you can let axis generate the jave code (stubs and proxies) for your web service via the wsdl file.
    Kind Regards,
    Robin

  • Query rewrite for COUNT(DISTINCT)

    Hi,
    I am having fact table with different dimension keys.
    CREATE TABLE FACT
    TIME_SKEY NUMBER
    REGION_SKEY NUMBER,
    AC_SKEY NUMBER
    I need to take COUNT(DISTINCT(AC_SKEY) for TIME_SKEY and REGION_SKEY. There are oracle dimension defined for time and region which are using TIME_SKEY and REGION_SKEY. I have created MV with query rewrite with COUNT(DISTINCT) but it is not using dimension if I am using any other level and MV can't be fast refreshed as it was build using COUNT(DISTINCT).
    CREATE MATERIALIZED VIEW AC_MV
    NOCACHE
    NOLOGGING
    NOCOMPRESS
    NOPARALLEL
    BUILD IMMEDIATE
    REFRESH COMPLETE ON DEMAND
    WITH PRIMARY KEY
    ENABLE QUERY REWRITE
    AS
    SELECT
    TIME_SKEY ,
    REGION_SKEY,
    COUNT (DISTINCTAC_SKEY)
    FROM FACT
    GROUP BY TIME_SKEY, REGION_SKEY;
    Query used to retrieve data is as below
    SELECT TIME_SKEY, COUNT(DISTINCT AC_SKEY) OVER (PARTITION BY TIME_SKEY) UNIQ_AC, COUNT(DISTINCT AC_SKEY) OVER () UNIQ_AC1
    FROM FACT;
    There can be other queries based on time / region dimension.
    Can you please provide help in solving above issue?
    Thanks,
    Pritesh

    What version of the Oracle database?

  • ABAP Query - Table for Batch, Char values & desc.

    Hi Gurus,
    Looking for a Table join for requirement to fetch Characteristic description, char values & Batch no  in ABAP query.
    Thanks.

    dear,
    it depends on which table you selected first (Table join using basis table) and how do you insert next tables.
    i am talking about the info-set creation step.
    let's do a simple query.
    run SQ02. type new infoset name and hit Create.
    type name and type MARA for "Table join using basis table" radio button. Hit Continue.
    now insert (add) tables: MARC, MCHA, CABN, CAWN
    think about Inner Join or Left Outer Join !!'
    say, if you need to display all materials (even if not exist on plant) set Left Outer Join. if you're after materials existing on plant keep default Inner Join.
    friend, my example above is only the example.
    make sure you undertsand how to build a sap query in general.
    never set many tables at once. insert 2-3 tables, return to your query (SQ01) or create it, adjust it and test. step by step - table by table. add the new table in infoset, add the fields, generate it and come back to your query. adjust it and test.
    good luck!

  • ABAP String code for String.IndexOf("str")

    Hi,
    I'm totally new to abap. How can I determine iif one string is in another?
    Thanks,
    Doug

    Hi Doug,
    we have the comparison operator CS (contains string).
    IF 'My brother loves it' CS 'other'.
    evaluates TRUE.
    System variable SY-FDPOS will carry the offset where the string starts, here 5.
    Although we have ABAP objects now for some time, we are far away from languages like JAVA where all data objects are classes with predefined methods.
    But you are welcome to implement something comparable.
    Regards,
    Clemens

  • Need help for Count function in XSLT Mapping

    Hi All,
    We have a requirement in our project,to do the xslt mapping from OAGIS 9.0 to EDI XML.In the EDI XML we have a SE tag whose value is the count of the no. of complex elements that will be generated in the EDIXML file( which is the target).
    Please do let me know if anybody has done this functionality in the xslt mapping.
    Thanks in Advance.
    Regards,
    Kaavya

    Hi,
    for the Hex-Number-conversion see:
    [url http://psoug.org/snippet/Convert-Hex-to-Decimal-Decimal-to-Hex_78.htm] self-defined Conversion-Functions
    What number format do you have? YYYMMDD
    Or is there a Date corresponding to 1 and a number n represent the date n-1 days after day 1?
    Please describe further.
    Bye
    stratmo

Maybe you are looking for

  • Change in Item Category KFF after Prod Migration

    Hi Our company had to move from a 2 segment Item Category KFF to 3 segment Item Category KFF. We know this is not recommended practice, but there was real business need for this. Now we have written programs to change all existing transactions to hav

  • Windows 7 / Photoshop CS5 64-bit installation not working

    I think I've followed all the instructions, and I've looked at many previous posts about the same problem, but I'm having no success.  I've tried the Run as Administrator upon right clicking the Program Files (x86)>Adobe>Adobe Extension Manager CS5>A

  • Presets for M2TS Files

    I've been struggling with quality issues when using my JVC HD7 and Premiere. I've been using MPEGStreamClip to convert the TOD files to DV to edit in Premiere, but I got a lot of swimming in the shadows. Yesterday I came across this post http://www.a

  • Yosemite - random crashes and restarts

    Hi since I have installed Yosemite. My computer is mysteriously restarting and recovering from a crash. It never happens while I am using the computer but I can come home from work or from being away from home and I find that the computer has restart

  • How to uninstall iOS 5 from MacBook Pro

    I made a big mistake last night by downloading iOS 5 to iTunes on my wife's MacBook Pro.  After reading the new iTunes Terms and Condition and checking over the features we do not have any need for the iOS 5 on her iPad2. I did not have the iPad2 att