Logic - Average value for a particular Customer + Period

Hello Experts,
Please help me in the Logic to find out Average for the below scenario:
This is the Output:
Customer
Period
Payment Timeliness
Cust-001
01/97
-4
Cust-001
01/97
2
Cust-001
01/97
3
Cust-001
04/97
3
Cust-001
04/97
5
Cust-001
06/97
-4
Cust-001
07/97
2
Cust-001
08/97
3
Cust-002
09/97
5
Cust-002
09/97
4
Cust-002
10/97
6
Cust-002
10/97
-2
Cust-002
12/97
-4
Requirement is:
Customer
Period
Payment Timeliness
Cust-001
01/97
0.333
Cust-001
04/97
4
Cust-001
06/97
-4
Cust-001
07/97
2
Cust-001
08/97
3
Cust-002
09/97
4.5
Cust-002
10/97
2
Cust-002
12/97
-4
Display the Average of all the Payment Timeliness for a particular Month as shown above.
My Code is:
*&      Form  fetch_data
FORM fetch_data .
  SELECT bukrs
         belnr
         gjahr
         blart
         bldat
         budat
         monat
   FROM  bkpf
   INTO  TABLE g_t_bkpf
   WHERE bukrs EQ '0470'
   AND   gjahr EQ p_year
   AND ( blart EQ 'EZ'
   OR    blart EQ 'DZ' )
   AND   monat IN s_month.
  IF sy-subrc EQ 0.
    SELECT bukrs
           belnr
           gjahr
           augdt
           buzei
           shkzg
           kunnr
           zfbdt
           zbd1t
           zbd2t
           zbd3t
           rebzg
     FROM  bseg
     INTO  TABLE g_t_bseg
     FOR ALL ENTRIES IN g_t_bkpf
     WHERE bukrs EQ g_t_bkpf-bukrs
     AND   belnr EQ g_t_bkpf-belnr
     AND   gjahr EQ g_t_bkpf-gjahr
     AND   kunnr IN s_kunnr.
    IF sy-subrc EQ 0.
    ELSE.
      WRITE:/'No Data Found'.
    ENDIF.
  ENDIF.
ENDFORM.                    " fetch_data
FORM display_paystats .
  DATA: l_due_date     TYPE faedt_fpos,
        l_timeliness   TYPE p,
        l_kunnr        type kunnr,
        l_counter      type i,
        l_period       type char5,
        l_tot_timeli   type p.
  IF g_t_bseg IS NOT INITIAL.
    WRITE: /10 'Customer ', 24 'Period ', 35 'Payment Timeliness'.
    WRITE: /10 sy-uline(44).
    LOOP AT g_t_bseg INTO g_wa_bseg.
      CLEAR l_due_date.
      CALL FUNCTION 'NET_DUE_DATE_GET'
        EXPORTING
          i_zfbdt       = g_wa_bseg-zfbdt
          i_zbd1t       = g_wa_bseg-zbd1t
          i_zbd2t       = g_wa_bseg-zbd2t
          i_zbd3t       = g_wa_bseg-zbd3t
          i_shkzg       = g_wa_bseg-shkzg
          i_rebzg       = g_wa_bseg-rebzg
       IMPORTING
         e_faedt       = l_due_date.
      READ TABLE g_t_bkpf INTO g_wa_bkpf WITH KEY
                                          bukrs = g_wa_bseg-bukrs
                                          belnr = g_wa_bseg-belnr
                                          gjahr = g_wa_bseg-gjahr.
      IF sy-subrc EQ 0.
        l_timeliness = g_wa_bkpf-budat - l_due_date.
      ENDIF.
      CLEAR g_wa_paystat.
      g_wa_paystat-kunnr = g_wa_bseg-kunnr.
      CONCATENATE g_wa_bseg-augdt+4(2) '/' g_wa_bseg-augdt+2(2) INTO g_wa_paystat-period.
      g_wa_paystat-timeli = l_timeliness.
      APPEND g_wa_paystat TO g_t_paystat.
      CLEAR : g_wa_bseg, g_wa_paystat.
    ENDLOOP.
    SORT g_t_paystat BY period.
    LOOP AT g_t_paystat INTO g_wa_paystat.
      WRITE:/10 g_wa_paystat-kunnr, 24 g_wa_paystat-period, 35 g_wa_paystat-timeli.
    ENDLOOP.
  ENDIF.
ENDFORM.                    " display_paystats
Where should I check the condition?
I thought of assigning the Period / KUNNR in a Variable; then compare from the second record.
But then how can I skip the check for 1st time inside a Loop?
Since this is BSEG/BKPF entries; it is slow. So, please suggest some logic that doesn't affect the performance.
Is it possible to write this logic within BSEG LOOP?
Appreciate your help.
Thank you!
Thanks & Regards,
Sowmya

Found out by myself
Closing the thread.
SORT g_t_paystat BY kunnr period.
    LOOP AT g_t_paystat INTO g_wa_paystat.
      l_kunnr = g_wa_paystat-kunnr.
      l_period = g_wa_paystat-period.
      l_tot_timeli = g_wa_paystat-timeli.
      IF sy-tabix NE 1.
        READ TABLE g_t_paystat INTO g_wa_paystat1 WITH KEY kunnr  = l_kunnr
                                                           period = l_period.
        IF sy-subrc EQ 0.
          l_counter = l_counter + 1.
          l_tot_timeli = l_tot_timeli + 1.
        ELSE.
          g_wa_paystat-timeli = l_tot_timeli / l_counter.
          MODIFY g_t_paystat FROM g_wa_paystat TRANSPORTING timeli WHERE kunnr  = l_kunnr
                                                                   AND   period = l_period.
          CLEAR:
            l_counter,
            l_tot_timeli.
        ENDIF.
      ENDIF.
    ENDLOOP.
    DELETE ADJACENT DUPLICATES FROM g_t_paystat COMPARING kunnr period.
    LOOP AT g_t_paystat INTO g_wa_paystat.
      WRITE:/10 g_wa_paystat-kunnr, 24 g_wa_paystat-period, 35 g_wa_paystat-timeli.
    ENDLOOP.

Similar Messages

  • Count no. of records for a particular customer in the query?

    Hi,
    1)Can anybody guide as to how do we count the number of records for a particular customer. E.g.
    C1 has placed 2 orders
    C2 has placed 4 orders
    C3 has placed 5 orders
    so in all the ODS has 11 records. Now while designing the query we need to ensure that we show only the Customers who have placed more than 3 orders. What could be logic to solve this kind of a problem?
    2) Is there a way that we can access the structure and data of the ODS in ABAP code say one of the includes in a user exit?
    The requirement says there could be N number of cases opened and closed in one month. Now we need to calculate the average number of days taken to close a case? Any ideas on the possible solution.
    Thanks
    RB

    Hi Rajat,
      Take a calculated key figure rename it as Count , go to the properties of that calculated key figure on the left hand side not at the columns side in the properties click on the button Enhance which is shown in the down left side, in the exception aggregation part select "count all values <>0" , take the reference character as customer Id . Now go to the Customer character which is in rows go to properties and select  "Normalise to" combo box  in that select "Query result" now u will get the exact result which ur looking for .

  • Retrieve the sales orders for a particular customer in selection screen

    Hi
    I want to retrieve the sales orders for a particular customer(entering customer number field in the selection screen and then clicking on f4 help on sales order field in the selection screen I should get only sales order numbers for that particular customer number).How can I achieve this through search helps?Are there any standard search helps that I can use.
    <removed_by_moderator>
    Edited by: Julius Bussche on Apr 9, 2009 12:55 PM

    Hi,
    try this:
    at selection-screen on value-request for p_par.
    select * from vbak
    into itab
    where kunnr = p_par.
    then use the FM 'F4IF_TABLE_VALUE_REQUEST'.
    with
    retfield = 'VBELN'
    dynprog = sy-repid
    dynpnr = sy-dynnr
    dynprofield = <name of parameter>
    value_org = 'S'
    tables = itab.
    Regards,
    Leo.

  • Techical field ( and Table ) for Promotion type for a particular Customer

    Hi All,
    Where can I find the promotion type for a particular Customer?
    Thanks,
    Sanjeet

    Hi Suman,
    I think you are talking about Transaction VB33.
    Table - KONA (Rebate Agreements)
    Field - KNUMA (Agreement (various conditions grouped together))
    Structure - RV13A (Input/Output Fields for Price Element Maintenance)
    Field - KNUMA_PI (Promotion)
    And if you want based on particular customer..
    Table - KOTE003 (Customer)
    Field - KNUMA (Agreement (various conditions grouped together))
    Table - KOTE004 (Customer Hierarchy)
    Field - KNUMA (Agreement (various conditions grouped together))
    Best Regards,
    Sayak

  • Display list of sales orders for one particular customer using BAPI in WD

    Friends,
    i want to display list of sales orders for one particular customer, the materials ordered, quantity ordered, goods issue date of that particular order and contact information about that particular customer, using Webdynpro.
    Please somebody send me related info,blogs,help links , to complete this task, this is very urgent.
    Please help
    Peter

    Find the WD tutorials here...
    <a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webdynpro/web%20dynpro%20sample%20applications%20and%20tutorials.htm">Tutorials</a>

  • Delivery for a particular customer

    Is it possible to create delivery for a particular
    customer on specific dates we want? How we will do it in SAP if possible? thanks

    Hi
    Further...if you wish to create deliveries on different future dates, one more alternative is to create a SCHEDULING AGREEMENT with delivery dates and quantities given in the schedule lines. Based on the delivery date, it automatically wil be added in the delivery due list.
    Thanks,
    Ravi

  • Maintaing a default value for a particular field in the selection screen

    Hi all,
    How to maintain a default value for a particular field in the Selection Screen of a Standard report
    Regards
    Ajay

    >
    ajay babu wrote:
    > Hi all,
    >
    > How to maintain a default value for a particular field in the Selection Screen of a Standard report
    >
    > Regards
    > Ajay
    Create a variant for your standard program and assign this variant to the field 'Start with variant' while creating transaction code for the standard program in the transaction 'SE93'.
    Regards
    Rajesh.

  • How to club the amount field for the particular customer from file

    Hi ,
    In my BDC i am getting the Amount field which is need to be put in the Header data . For 1 Customer there are more than 5 line in amount field in the Excel file.
    For the Particular Customer , I need to club all the amount ffield and put it into the Heade data for the customer.
    How to do this .
    Thanks

    got answer

  • Average value for waveform chart

    Hello everyone.
    Can i make a time interval, where i can measure average value for a waveform chart ?
    for example fom 0:30 to 0:45
    I have uploadet my VI
    Thanks in advance
    Oesen
    Best regards
    Oesen
    Solved!
    Go to Solution.
    Attachments:
    Trykmaaling.vi ‏83 KB

    Oesen,
    When you are displaying data on a chart, the newest data is appears at the right of the previous data. When the chart history buffer is full (default length = 1024), adding a new point deletes the oldest point.  Visually it appears that the data slides to the left as new data is added to the right end.
    My question relates to how the user would "tell" the program what data to average. In the image you posted you marked a segment of the data to be averaged.  Suppose the user marks point "A" as the beginning of the segment. While the user is deciding where to put mark "B" additional data is acquired and point "A" disappears because it is beyond the history length.  What does the program do in such a case?   A slight variation is the situation where both "A" and "B" have been marked but some of the data is deleted from the history before the averaging or other processing has begun.
    Lynn

  • Visibility for a particular customized record.

    We are facing an issue of visibility for a particular customized record.
    As customized record costing is created automatically using web services, so by default it is picking the name of the Administrator.How can we remove admin by default and assign its real owner by default?
    Thanks in Advance,
    Manish.

    You should be able to assign this by using post default on the Opportunity Owner ID field to be the creator of the record. If you have hard coded a WS username to complete this perhaps look at using SSO

  • Purchase value for a particular document type of po

    I need Purchase value for a particular document type of po

    Hi Thanks for the reply. Sum of net order value will give right. Any selections we have to do at headr level ? Does it hold good for SA's also ? Please help

  • Calculating Accumulative Value for a particular period

    Hi,
    I want to calculate acumulative values based on 0calmonth for a key figure.
    In Rows, i want 0calmonth and a key figure in Columns. If we select the property of the key figure as "Cumulative". It is adding values like in first month, first month value, in 2nd month it is showing the values by adding 1st and 2nd months. But I gave a Interval variable on 0calmonth (e.g  03.2006 to 09.2006 ) it displaying cumulative values from 3rd month. In 4th month it is showing value for 3rd and 4th month. But i want to see the values as "Accumulative" means from starting of that year. Eventhougth i gave the period value as 03.2006 to 09.2006, it has to display the value of 3rd month as adding of 1st,2nd and 3rd months. like that it has to show up to last month in the given peroid.
    Please can any one suggest me....
    Thanks and Regards
    Rajesh
    Message was edited by:
            rajesh
    Message was edited by:
            rajesh

    Hi ,
    For my Above Problem I am using the code as follows. But it has no errors. but when it is displaying on the web browser. it is not getting values.
    DATA: L_S_RANGE1 TYPE RSR_S_RANGESID.
          DATA: LOC_VAR_RANGE1 LIKE RRRANGEEXIT.
          DATA: L_VALUE LIKE RRRANGEEXIT-HIGH.
    CASE I_VNAM.
        WHEN 'ZCUM_INTERVAL'.
          IF I_STEP = 2.
          LOOP AT i_t_var_range INTO LOC_VAR_RANGE1 WHERE VNAM = '0I_CMNTH'.
             L_VALUE = LOC_VAR_RANGE1-LOW.
             while L_VALUE4(2) < LOC_VAR_RANGE1-HIGH4(2).
                if sy-index > 1.
                  L_VALUE4(2) = L_VALUE4(2) + 1.
                  if strlen( L_value+4(2) ) = 1.
                     concatenate '0' L_VALUE4(2) into L_VALUE4(2).
                  endif.
                endif.
                CLEAR L_S_RANGE1.
                L_S_RANGE1-LOW = LOC_VAR_RANGE1-LOW(4).
                L_S_RANGE1-LOW+4(2) = '01'.
                L_S_RANGE1-HIGH = L_VALUE.
               L_S_RANGE1-SIGN = 'I'.
               L_S_RANGE1-OPT = 'BT'.
                APPEND L_S_RANGE1 TO E_T_RANGE.
              ENDwhile.
            ENDLOOP.
          ENDIF.
    Please can any one suggest me regarding this.
    Thanks in Advance...
    TR
    Rajesh

  • Adding values for a single customer

    Hi Everybody,
    I am facing a programming issue. I have to do something like this:
    For a each customer, for all open items for that customer, I have to add the amount due at every period in aging in Accounts receivable. So for example, if I have two customers: A and B and
    A has 5 open items
    B has 3 open items
    for each open item there is an amount due for both customers. So what i have to do is add for A 1+2 = amount 1.
    amount 1 + 3 = amount 2, amount 24 = amount 3, amount 35 = amount 4.
    Similarly for B also I have to do the same thing. Right now my amount are getting added up into one single value at each line of the table. So for all customers it is just getting added in every row of the table and not seperately for every new customer.
    Can somebody suggest something or give some example?
    Please help.
    Thanks & regards,
    AM

    I'm not sure I understand what you are trying to do. Is it something like:
    REPORT ztest.
    TABLES: bsid.
    PARAMETERS p_bukrs LIKE bsid-bukrs.
    SELECT-OPTIONS s_kunnr FOR bsid-kunnr.
    DATA: BEGIN OF itab OCCURS 0,
            bukrs LIKE bsid-bukrs,
            kunnr LIKE bsid-kunnr,
            under_30_amt LIKE bsid-dmbtr,
            under_60_amt LIKE bsid-dmbtr,
            under_90_amt LIKE bsid-dmbtr,
            over_90_amt  LIKE bsid-dmbtr,
          END   OF itab.
    DATA: under_30_date LIKE sy-datum,
          under_60_date LIKE sy-datum,
          under_90_date LIKE sy-datum,
          over_90_date  LIKE sy-datum.
    under_30_date = sy-datum - 30.
    under_60_date = sy-datum - 60.
    under_90_date = sy-datum - 90.
    over_90_date  = sy-datum - 30.
    SELECT bukrs kunnr bldat dmbtr
      INTO CORRESPONDING FIELDS OF bsid
      FROM bsid
      WHERE bukrs = p_bukrs
        AND kunnr IN s_kunnr.
      CLEAR itab.
      MOVE: bsid-bukrs TO itab-bukrs,
            bsid-kunnr TO itab-kunnr.
      IF bsid-bldat > under_30_date.
        MOVE bsid-dmbtr TO itab-under_30_amt.
      ELSEIF bsid-bldat > under_60_date.
        MOVE bsid-dmbtr TO itab-under_60_amt.
      ELSEIF bsid-bldat > under_90_date.
        MOVE bsid-dmbtr TO itab-under_90_amt.
      ELSE.
        MOVE bsid-dmbtr TO itab-over_90_amt.
      ENDIF.
      COLLECT itab.
    ENDSELECT.
    LOOP AT itab.
      WRITE: /001 itab-bukrs,
                  itab-kunnr,
                  itab-under_30_amt,
                  itab-under_60_amt,
                  itab-under_90_amt,
                  itab-over_90_amt.
    ENDLOOP.
    <i>Caveats</i>
    I'm not sure what date you should use for aging. I used the document date. Maybe it's the baseline date. Maybe it's something else.
    Collect is inefficient. You might want to do it another way.
    I may be way off base - you may be doing something else entirely.
    Rob

  • To automate outbound process for a particular customer

    Hi All,
    I have setup a edi 855 outbound process, I don't know how make the 855 happen automatically for received 850 for a particular new customer. can anyone help me... cos we are supposed to go-live anytime next week...

    Hi,
    You should enhance the standard Data source 0customer_attr with that additional partner function (sales head) as per the proper logic and replicate the same . if it is 3.5 that same object( related to that field length and data type) same object can be added as attribute at info object level and do the transfer rules   and activate that and try to the load.
    Thanks & Regards,
    Sathish

  • How to restrict Option values for a particular metadata in profile checkin

    How to restrict Option values (drop down) for a particular metadata in profile checkin-
    Metadata field Color is having options dropdown values (stored in table/views)-
    Display name - Blue, Value=1
    Display name - Red, Value=2
    Display name - Yellow, Value=3
    Display name - Green, Value=4
    Display name - Black, Value=5
    For a particular profile checkin form, for the metadata field Color I want the dropdown value consist of only top three options
    Display name - Blue, Value=1
    Display name - Red, Value=2
    Display name - Yellow, Value=3
    But this should be done on profile level only, should not impact the standrad checkin form and other profile checkin forms.
    Please help me if any one having any suggestion to implement the above secnario
    Thanks,
    Sumit

    Hi,
    Into the rule containing the Color metadata, you can restrict the values of the list.
    In "Has restricted list and pane", list the values 1, 2 and 3 (new line for each value) :
    1
    2
    3
    Romain.

Maybe you are looking for

  • I am runnung FF 4.0.1, I cannot uphgrade.because FF is not compatible with some programs I have..is there any thing I can do??

    I keep getting notifications to upgrade to FF 8.0.1. However that version of FF will not run several programs I have, for which I paid good money Also...when I went from FF 3.6 to FF 4.all my bookmarks disappeared...and two other major programs cease

  • IReport

    Hi, all. I trying to learn how to produce reports, using iReport, but i am with the follow problem. I want create one report using parameters only. On the iReport, i test and all right. But in run time (calling of a java class), the JasperViewer show

  • Can't get windows 7 firewall to allow transfer of dicom images

    I work in a hospital where I have to send images from a Linux server to a Windows 7 workstation.  I use a software program called K PACS on the windows workstation to receive the images.  I can't transfer images to K-PACS from the Linux computer unle

  • Isql*plus DBA logins

    I want the steps required for configuring isql*plus for dba logins, when i connect to the following url: http://192.168.1.203:5560/isqlplus/dba/dynamic it prompt me for a username and password, how to setup this dba username and password

  • Need help with Connect 4 game, IndexOutOfRangeException was unhandled

    Hi! I've been struggling with this for a while now, the issue is that as soon i move a game piece to the field i get this errorats "IndexOutOfRangeException was unhandled" and i don't know why since my intention with the code was to use for loops loo