ABAP routine for Top 10 material

Hi All,
I want to write an ABAP routine to get the Top 10 material as per their sales data.
I have written a query where I have put condition (for Top 10).
But I need to create an APD taking this query as base query. But conditions fail to filter data when it comes into a transactional ODS via an APD.
So, I want to write a routine for transaformation of data (to get top 10 material based on their sales data) from base query to the transactional ODS.
Please help me in writing this code.
I am an amatuer in ABAP.
Thanks,
SB

Hi ,
You Need to read Data from the ODS for Top 10 Materials. I can give you the Logic but you would need to take the Help of an ABAPPER to convert this into the code
Lets consider an ODS : ZODS which has a KF for Sales Data (ZKF)
*****Define Internal Table ****************
TABLES :
/BIC/AZODS
DATA:
BEGIN of ITAB OCCURS 0,
    0material(18)       TYPE c,
    ZKF           like /bic/AZODS-/bic/ZKF,
END OF ITAB.
DATA:
BEGIN of ITAB1 OCCURS 0,
    0material(18)       TYPE c,
    ZKF           like /bic/AZODS-/bic/ZKF,
END OF ITAB1.
Select MATERIAL, /BIC/ZKF from /BIC/AZODS into corresponding fields of ITAB1.
LOOP AT ITAB1
ITAB-MATERIAL = ITAB1-MATERIAL
ITAB-ZKF= ITAB1-ZKF
COLLECT ITAB.
ENDLOOP.
SORT ITAB ZKF.
************this will have the materials sorted take the first 10 Material Nos*****

Similar Messages

  • ABAP Routine  for 0FISCPER  slect options in InfoPackage

    Hi,
    I am trying to write an ABAP Routine for 0FISCPER as select options (range) dynamically.
    Ex:
    0FISCPER selection for this year as 001.2008 to 012.2008
    0FISCPER selection for next year as 001.2009 to 012.2009.
    Now  we are changing InfoPackage every year manually, so I need to write a routine for 0FISCPER in InfoPackage to handle dynamically every year
    Thanks,
    SK.

    Hi
    write an ABAP routine to get that value..But are you getting any planned data(why you want till end of the year...till infopackage runs is o.k i think, if you don't have planned data)...Any way you can check the below code, which can be useful...
    You can see the below code at->your infopackage selections>Ty-->choose variable type as 6 and enter any ABAP routine name( to create) and then there is a button on the application tool bar called 'routine info'..this give you the following information...
    Definition
    You can define complex selections for InfoPackages and control the automatic deletion of requests from InfoCubes in the scheduler, by using routines.
    Routines are processing blocks in ABAP programs that consist of a pre-defined data declaration section and an ABAP subroutine (form routine). In the subroutine you can use all of the ABAP programming functions.
    You can use the following routines for making selections in InfoPackages:
    1. Selection routines for fields, on the Data Selection tab page
    2. Selection routines for file names, on the External Data tab page
    3. Selection Routines for selecting the from and to dates for time-dependent data, on tab page Update
    4. Selection routines for determining old requests to be deleted after successfully loading a new request, on the Data Target tab page
    Program frame:
    After you have called up the Editor for routine maintenance, you get the following program frame:
    1. Selection routines for fields, on tab page Data Selection:
    program conversion_routine.
    '$*$ begin of global - insert your declaration only below this line -
    TABLES: ...
    DATA:   ...
    $$ end of global - insert your declaration only before this line    -
    FORM COMPUTE_<Fieldname>
      tables l_t_range structure rssdlrange
      changing p_subrc like sy-subrc.
    $$ begin of routine - insert your code only below this line       -
      data: l_idx like sy-tabix.
            read table l_t_range with key
                 fieldname = <Fieldname>.
            l_idx = sy-tabix.
            modify l_t_range index l_idx.
            p_subrc = 0.
    $$ end of routine - insert your code only before this line       -
    ENDFORM.
    2. Selection routines for file names, on tabstrip External Data:
    FORM compute_flat_file_filename
         changing p_filename like rsldpsel-filename
              p_subrc like sy-subrc.
    $$ begin of routine - insert your code only below this line-
              p_filename =
              p_subrc = 0.
    $$ end of routine - insert your code only before this line-
    ENDFORM.
    3. Selection routines for selecting the from and to date for time-dependent data, on tabstrip Update:
    form compute_time_dependent_dates
         changing p_datefrom type d
                  p_dateto   type d
               p_subrc like sy-subrc.
    $$ begin of routine - insert your code only below this line-
              p_datefrom =
              p_dateto   =
              p_subrc = 0.
    $$ end of routine - insert your code only before this line-
    ENDFORM.
    4. Routines for determining the old requests to be deleted after successfully loading a new request, on tab page Data Targets:
    form compute_<InfoCube-Name>
      tables l_t_request_to_delete structure rsreqdelstruc
      using l_request like rsreqdone-rnr
      changing p_subrc like sy-subrc.
    *Insert Source Code to decide if requests should be deleted.
    *All Requests in table l_t_request_to_delete will be deleted
    *from Infocube <InfoCube-Name>.
    *Add new requests if you want to delete more (from this cube).
    *Remove requests you did not want to be deleted.
    $$ begin of routine - insert your code only below this line-
         loop at l_t_request_to_delete.
         endloop.
         clear p_subrc.
    $$ end of routine - insert your code only before this line-
    ENDFORM.
    Note:
    Those fields flagged with <...> are dependent on the selection fields and are filled automatically by the system when you call up the Editor.
    Procedure
    Make the following entries:
    1. Between $$ begin of global ... and $$ end of global ... you can define data declarations. These are the declaration sections for the local data in the routine. This data is only visible in the routines.
    2. The subroutines begin with FORM and end with ENDFORM.
    The subroutines for the particular routines are:
    Selection routines for fields on tab page Data Selection: FORM COMPUTE_<Field name>
    Selection routines for file names on tab page External Data : FORM compute_flat_file_filename
    Selection routines for selecting the from and to dates for time-dependent data on tab page Update: FORM compute_time_dependent_dates
    Routines for determining old requests to be deleted after successfully loading a new request on tab page Data Target: FORM COMPUTE_<InfoCube-Name>
    The subprograms have the following parameters:
    Subprogram FORM COMPUTE_<Field name>:
    l_t_range
    In the table l_t_range the routines for all selection fields that are filled, or have a routine, are made available.
    The routines are executed in the scheduler last of all and therefore, you can change all the selections that you have carried out previously.
    p_subrc
    Using the variable p_subrc you can report errors to the scheduler. p_subrc <> 0 signals an error and means the data request is terminated.
    Subprogram FORM compute_flat_file_filename:
    p_filename:
    You give the name of the file that is to be loaded in parameter p_filename.
    This is useful if your file name contains date dependencies that should be determined by sy-datum and calculated during runtime.
    p_subrc
    You can inform the scheduler of an error with variable p_subrc. p_subrc <> 0 signals an error and means that the data request is terminated.
    Subprogram FORM compute_time_dependent_dates:
    p_datefrom and p_dateto
    Fill these parameters with the from and to dates for time-dependent master data and texts.
    p_subrc
    You can inform the scheduler about an error using variable >LS>p_subrc. p_subrc <> 0 signals an error and means the data request is terminated.
    Subprogram FORM COMPUTE_<InfoCube-Name>:
    l_t_request_to_delete
    You give the request number of the request that is to be deleted in parameter l_t_request_to_delete. You can also delete requests from the table. These are then not deleted.
    p_subrc
    You can inform the scheduler about an error with the variable p_subrc. p_subrc  signals an error and means the data request is terminated.
    3. Insert your program code for the routines between $$ begin of routine ... and $$ end of routine ... so that the respective subprogram variables are supplied with the corresponding values.
    4. Check the syntax of your routine with the Check function.
    5. You can then transfer the routine with the Save function.
    You end routine maintenance when you exit the Editor.
    Hope it helps
    Thanks,
    Teja

  • ABAP routine for loading data of current month in InfoPackage

    Hello experts,
    I want to load data of current month. Therefore I implemented the following ABAP-Routine for field 0CALDAY in the InfoPackage's data selection:
    data: lv_datum_l like sy-datum,
             lv_datum_h like sy-datum. 
      concatenate sy-datum(6) '01' into lv_datum_l.
      call function 'RP_LAST_DAY_OF_MONTHS'
      exporting
      day_in = sy-datum
      importing
      last_day_of_month = lv_datum_h.
      l_t_range-sign = 'I'.
      l_t_range-option = 'BT'.
      l_t_range-low = lv_datum_l.
      l_t_range-high = lv_datum_h.
    But function 'RP_LAST_DAY_OF_MONTHS' cannot be found!
    Any other suggestions for getting last day of current month?
    regards
    hiza

    Hi,
    Add this code. When u complete execution of this code, ZDATE will have ur month end date.
    data : zdate_c(2) type c,
           zyear_c(4) type c,
           zmonth_c(2) type c.
    data :  zdate like sy-datum.
    data :  zday(2) type n.
    zdate = sy-datum
          zyear_c = zdate(4).
          zmonth_c = zdate+4(2).
          zdate_c = '01'.
          concatenate zyear_c zmonth_c zdate_c into zdate.
          CALL FUNCTION 'FIMA_END_OF_MONTH_DETERMINE'
          EXPORTING
            I_DATE         = zdate
          IMPORTING
            E_DAYS_OF_MONTH = NO_OF_DAYS.
          zday = NO_OF_DAYS.
          concatenate zyear_c zmonth_c zday into zdate.

  • Abap Routine for Date selection in Infopackage

    Hi
    I have to write an abap routine for date selections in the infopackage,
    There are two date begda and enda.
    Do i code for BEGDA and fill in the begin date using routine and use another routine to fill the ENDA.
    JPJP

    Hi JP,
      If you have two info objects BEGDA and ENDA in the Info package for selection
      then you will have to write seperate routine for each of them.
      If you want to give single value for each date field then update only the field l_t_range- low otherwise if you want to give range then you can update the internal table fields l_t_range-low and l_t_range-high .
    Regards,
    Prakash

  • ABAP Routine for Deleting and creating index for ODS in Process chains

    Any pointers for the ABAP Routine code for deleting and creating index for ODS in Process chains.

    Hi Sachin,
    find the following ABAP code to delete ODS ondex.
    data : v_ods type RSDODSOBJECT.
    move 'ODSname' to v_ods .
    CALL FUNCTION 'RSSM_PROCESS_ODS_DROP_INDEXES'
      EXPORTING
        I_ODS = v_ods.
    To create index:
    data : v_ods type RSDODSOBJECT.
    move 'ODSname' to v_ods .
    CALL FUNCTION 'RSSM_PROCESS_ODS_CREA_INDEXES'
      EXPORTING
        I_ODS = v_ods.
    hope it helps....
    regards,
    Raju

  • InfoPackage ABAP Routine for Date Range - Only Start Date Extracted

    I am using an ABAP Routine in an InfoPackage to select data for a 2 year period.  The routine converts SY-DATUM into the Current Fiscal Year and Period, and then calculates the Starting and Ending Fiscal Year / Period of a 24 month period.  The Start and End values are passed to the InfoPackage as l_t_range-low and l_t_range-high.
    The Source and Target are both Basic Infocubes.
    The InfoPackage executes successfully, and the Selection values on the Header tab of the monitor reflect a 24 month period.  Unfortunately, on closer review of the data in the cube, only data for the first month appears to have been loaded.  I’m guessing that the extract was only performed with the From value, even though a To value was also provided.
    I created a simple Infopackage and manually input the selection parameter values just to be sure I wasn’t overlooking something. The InfoPackage performed as expected, loading more data which spanned the selection time period.
    I can provide the code if it helps, but the fact that the monitor reflects a Start and End value suggests that the problem is with the InfoPackage, not the ABAP routine.
    Has anybody ever experienced this before ?  Any ideas would be greatly appreciated ?
    Thanks,
    Lyle

    We can write ABAP routine in Infopackage with a range of values (From & To). Make sure you fill all the following information while building the final range information as below,
       l_s_range-sign    = 'I'.
       l_s_range-option  = 'BT'.
       l_s_range-low     = lowvalue.
       l_s_range-high    = highvalue.
      MODIFY l_t_range FROM l_s_range INDEX l_idx.
    As you can see the key is passing the "BT" information for capturing range.
    Hope it helps..
    thanks
    Kumar

  • Using ABAP routines for data selection

    Hello,
    I want to use ABAP routine to determine value range of data selection in Data Package but when I use routine for one field, selection criterias for other fields are ignored, e.g.:
    in Data Package I have two selection fields:
    CPUDT     Accounting Document Entry Date
    AEDAT     Date of the Last Document Change by Transaction
    For CPUDT I wrote ABAP routine
    and for AEDAT I have just typed in period of time.
    I started data extraction and open Monitor for this Data Package.
    At Header tag I checked selections info and there is selection only for CPUDT.
    Could somebody explain me is it normal system behaviour?
    Thanks
    Andrzej

    Thanks for reply but that would be too easy...
    I have tried your advice but nothing changed.
    I think this is data extraction configuration problem.
    Andrzej

  • ABAP Routine for FISCPER

    Dear members
    Y would like your help to create an abap routine into the infopackage.
    I want to obtain last period from current month (sy-datum), for the characteristic 0fiscper at the infopackage
    those anyone know how to create a routine that do that?
    For example
    2010001 to 2009012
    Thanks
    Ariel

    Give tnis a try:
    Global Declarations
    CONSTANTS: c_1(1) TYPE n VALUE 1,
               c_fiscvarnt TYPE /bi0/oifiscvarnt VALUE 'Z1',  "Use whatever your default Fiscal Year Variant is"
               c_i(1) TYPE c VALUE 'I',
               c_bt(2) TYPE c VALUE 'BT'.
    DATA: l_tabix LIKE sy-tabix,
          l_fiscper3 TYPE /bi0/oifiscper3,
          l_fiscyear TYPE /bi0/oifiscyear,
          l_min TYPE /bi0/oifiscper,
          l_max LIKE /bi0/oifiscper.
    Routine
    CLEAR: l_fiscper3,
           l_fiscyear.
    CALL FUNCTION
      'DATE_TO_PERIOD_CONVERT'
    EXPORTING
      i_date  = sy-datum
      i_periv = c_fiscvarnt
    IMPORTING
      e_buper = l_fiscper3
      e_gjahr = l_fiscyear.
    CONCATENATE: l_fiscyear l_fiscper3 INTO l_max.
    l_fiscper3 = l_fiscper3 - c_1.
    IF l_fiscper3 LT 1.
      l_fiscyear = l_fiscyear - c_1.
      l_fiscper3 = c_1.
    ENDIF.
    CONCATENATE: l_fiscyear l_fiscper3 INTO l_min.
    READ TABLE
      l_t_range
    WITH KEY
      fieldname = 'FISCPER'.
    MOVE: sy-tabix TO l_tabix,
          c_i TO l_t_range-sign,
          c_bt TO l_t_range-option,
          l_min TO l_t_range-low,
          l_max TO l_t_range-high.
    MODIFY
      l_t_range
    INDEX
      l_tabix.
    p_subrc = 0.

  • ABAP routine for ATP check

    Hi all...Is there any existing ABAP routine which does ATP check (material availability and allocation check) ??

    fm 'BAPI_MATERIAL_AVAILABILITY'
    BR< JAcek

  • ABAP routin for geeting previous month

    Hello.......
    I want to writ an ABAP routin at the infopackage level.
    I want to get the previous month ( period ).
    example : if sy-datum is 2007.01.01
    output : 2006.12.01.
    reply.
    Thanks in advance.

    Hi,
    Write this in the start routine of infosource or update rules...
    Try this:
      DATA: L_DATE LIKE SY-DATUM.
      DATA: L_YEAR TYPE I.
      DATA: L_MONTH TYPE I.
      L_DATE = (Here enter your input).
      MOVE '01' TO L_DATE+6(2).
      MOVE L_DATE(4) TO L_YEAR.
      MOVE L_DATE+4(2) TO L_MONTH.
      L_MONTH = L_MONTH - 1.
      IF L_MONTH LT 1.
        L_YEAR = L_YEAR - 1.
        L_MONTH = 12.
      ENDIF.
      MOVE L_YEAR TO L_DATE(4).
      MOVE L_MONTH TO L_DATE+4(2).
      MOVE:  L_DATE TO P_DATE.
    Hope this helps
    PB

  • ABAP routine for InfoPackage

    Hi,
    I have an InfoPackage that loads into multiple InfoCubes. Sometime at the end of this year we will stop loading one of the InfoCube.
    What ABAP code do I use to achieve this result? How do I do this type of filter from InfoPackage?
    Thanks in advance for your precious time and help
    Best regard
    Arjun

    Hi Arjun,
    Would be having an InfoPackage against which you would be checking  the 'End of the year' ie any time characteristics say 0CALDAY,
    In your routine check this InfoObject for End of the year and if true you can allow this to load to further InfoProviders or Datatargets.
    Othervise do what ur business logic says.
    This you can do provided you know the exact date ( value) .
    Otherwise try to find out any infoobject whose value is important in terms for ur infoprovider loading . and you can use that infoobject to check in routine.
    Say you want to load XYZ if its not the end of year and otherwise you waht keep it constant.
    if  SOURCE_FIELDS-Ocalday < '20081231'.
    temp = xyz.
    else.
    temp = '00000000'.
    endif.
    Results  = temp.
    Hope this Helps.
    Regards
    Praeon

  • ABAP routine for DTP fiscal year/period filter

    Hi All,
    Delta loads are which not possible for when the transformation source is an InfoSet.  To limit the data in these loads, currently a filter is set in the DTPs on fiscal year/period so only load the current month and 2 prior months are loaded.  This filter has to be updated each month for each of the DTPs manually.  To eliminate this monthly task a dynamic filter (routine) needs should be used rather than a static filter. Can anybody help me in providing the logic
    Regards
    Siri

    data: l_idx like sy-tabix.
    read table l_t_range with key
         fieldname = give field name .
         Data : Year(4) type n,
                   period1(2) type n.
                   period2(2)type n.
    Currper = sy-datum+4(2) .
    period1 = currper-1 .
    period2 = currper-2.
    year = sy-datum+0(4).
    concatenate  year currper to P1.
    concatenate  year period1 to P2. // define P1 , P2 , P3 as 0fiscper .
    concatenate  year period2 to P3.
    l_t_range-sign = 'I'.
    l_t_range-option = 'BT'.
    l_t_range-low =  P3.
    l_t_range-high=  P1.

  • ABAP query for matching material in another table

    Hi Experts,
    I have to do auto GR through an interface by calling MB01 for that i have written a BDC and the application is calling that. but i have to put a restriction that it should only do it for few materials that are in ztable "Zbulkmaterial" it has only one field matnr. I need to match materials in this field with the matial in EKPO, but i cant match it directrly, i have to track that in such way :-
    slip_no from "zval_wb" (this table dsnt have PO number), then slip_no1(diff than 1st slip no.) from "zallow_sl3"(this table has PO number) by that PO we can get material No from EKPO, and then i have to match it with zbulkmaterial-matnr
    As i am new i dnt no what will be the code for this please tel me the query i have to write, is it involves 3 tables i m not able to do that matching of materials.
    Regards,
    Nikhil

    use inner join statement.

  • ABAP routine for loading previous months data in infopackage

    Hi,
    I have an infopackage included in a process chain. The issue is that I need to load previous month's data through the infopackage and I have a data field which is of date type. I could not find an appropriate OLAP variable so I chose the ABAP code in the infopackage. My knowledge of ABAP is not very good so I thought I could get some insight from someone. Need this to be a periodic job/regular without any developer interference.
    Edited by: BG on Apr 9, 2008 1:03 PM

    Hi
    Try this code and see if you are able to achive the results
    data: month(2).
    data: date  like sy-datum,
          last  like sy-datum,
          first like sy-datum.
    read table l_t_range with key
    fieldname = 'BLDAT'.
    l_idx = sy-tabix.
    date = sy-datum.
    month = date+4(2).
    if month = 12.
      month = 01.
    else.
      month = month - 1.
    endif.
    move month to date+4(2).
    call function 'SLS_MISC_GET_LAST_DAY_OF_MONTH'
      exporting
        day_in                  = date
    IMPORTING
       LAST_DAY_OF_MONTH       = last
    EXCEPTIONS
      DAY_IN_NOT_VALID        = 1
      OTHERS                  = 2
    if sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    endif.
    first = last.
    move 01 to first+6(2).
    l_t_range-low  = first
    l_t_range-high = last
    l_t_range-sign = 'I'.
    l_t_range-option = 'BT'.
    modify l_t_range index l_idx.
    p_subrc = 0.
    paste the code as it is in your editor activate this and see if you are able to achive the results.
    assign points if useful.
    regards
    Vishal
    Edited by: Vishal Vashishta on Apr 9, 2008 2:33 PM

  • ABAP Routine  for 0FISCPER  select data in InfoPackage

    Hi all,
    I need to write a routine which has to return values from the last FISCPER to the current FISCPER in the data selection of the infopackage.
    Do somebody already do it?
    Thks

    Try this:
    Global Declarations
    CONSTANTS: c_1(1) TYPE n VALUE 1,
               c_fiscvarnt TYPE /bi0/oifiscvarnt VALUE 'Z1',  "Use whatever your default Fiscal Year Variant is"
               c_i(1) TYPE c VALUE 'I',
               c_bt(2) TYPE c VALUE 'BT'.
    DATA: l_tabix LIKE sy-tabix,
          l_fiscper3 TYPE /bi0/oifiscper3,
          l_fiscyear TYPE /bi0/oifiscyear,
          l_min TYPE /bi0/oifiscper,
          l_max LIKE /bi0/oifiscper.
    Routine
    CLEAR: l_fiscper3,
           l_fiscyear.
    CALL FUNCTION
      'DATE_TO_PERIOD_CONVERT'
    EXPORTING
      i_date  = sy-datum
      i_periv = c_fiscvarnt
    IMPORTING
      e_buper = l_fiscper3
      e_gjahr = l_fiscyear.
    CONCATENATE: l_fiscyear l_fiscper3 INTO l_max.
    l_fiscper3 = l_fiscper3 - c_1.
    IF l_fiscper3 LT 1.
      l_fiscyear = l_fiscyear - c_1.
      l_fiscper3 = c_1.
    ENDIF.
    CONCATENATE: l_fiscyear l_fiscper3 INTO l_min.
    READ TABLE
      l_t_range
    WITH KEY
      fieldname = 'FISCPER'.
    MOVE: sy-tabix TO l_tabix,
          c_i TO l_t_range-sign,
          c_bt TO l_t_range-option,
          l_min TO l_t_range-low,
          l_max TO l_t_range-high.
    MODIFY
      l_t_range
    INDEX
      l_tabix.
    p_subrc = 0.
    Edited by: Dennis Scoville on Dec 7, 2009 11:07 AM

Maybe you are looking for

  • How to stop logic from auto-snapping a midi recording to a grid?

    Everytime I record midi from my keyboard, logic auto snaps the size of the region to fill in to the next and previous complete bar. Is there some way to stop this? I've looked through the manual but can't find much. Thank you!

  • How to create "annual balance" in reports?

    I'm looking for a solution to run a report easily for our annual financial report.. The problem is that i would like to use only two queries wich retrieve all data from account numbers 10000 till 99999 for example. But in reports it should be shown b

  • Change date help icon inside table

    Hello, I've created a new theme and I've changed the date help icon(Theme Editor/Simple Elements/Labels and Fields). I can see new icon in portal but when displaying it from a cell inside a table, it displays the standard icon. Please, I need to show

  • Colorizing an original black and white photo

    Is there a way (kinda simple) to turn a black and white photo (never in color) into a color photo ? The desaturate / history thing won't, of course, work. Thanks!

  • How can you put out of office on your email

    I am unable to find out how to put out of office on my email?