Standard function or logic required

Hi all,
I have one  number (9876), now i need to get the sum of this number.That is 98765 that is 35.so i need to extract 3+5 = 8. si finalli i need get 8
can anybody give me some logic (sample code) or some predefiend functions for this.
Many Thanks,
Ragh

Hi,
Take a look at function module 'BKK_COMPUTE_SUM_OF_DIGITS'.  I'm not sure you should use the function module directly (CAUTION: It is not released by SAP!), but you can use the same logic or copy its source code for use in your own method/function module.
*---- calculate sum of digits for given number with maximum 4 digits --
  field-symbols <f>.
  data: l_ref(4) type n,
        l_sum    type i value 0.
  l_ref = i_number.
  assign l_ref+0(1) to <f>.
  l_sum = l_sum + <f>.
  do 3 times.
    assign <f>+1 to <f>.
    l_sum = l_sum + <f>.
  enddo.
Here's another way for you to consider.  It is different than the code within the SAP function module but same concept (without field-symbols):
PARAMETERS: p_num(4) TYPE n.
DATA: l_sum  TYPE i,
      l_next TYPE i.
l_sum = p_num(1).
DO 3 TIMES.
  l_next = sy-index.
  l_sum = l_sum + p_num+l_next(1).
ENDDO.
WRITE: /1 'The digits of', p_num, 'add up to:', l_sum.
Regards,
Jamie
Edited by: James Gaddis on Feb 29, 2008 11:19 AM  --  Added the code for quick reference and in case you are using pre-ECC 5.0 system.
Edited by: James Gaddis on Feb 29, 2008 2:07 PM  -- Added an alternative coding method.

Similar Messages

  • Standard Function Modules required

    I am look for a standard Function Module / RFC / BAPI for the below
    Get the list of table (for a given search criteria like if I give m* it should return me list of
              tables starting with m)
    Get details of the table (its field details)
    Regards,
    Samson.

    Select TABNAME fron dd02l into Itab where Tabname like M*
    Select FIELDNAME ROLLNAME DOMNAME DATATYPE from dd03l into itab2 fro all entries in Itab where tabname = itab-tabname.
    Or:
    Select TABNAME fron dd02l into Itab where Tabname like M*
    Loo at Itab.
    Pass table name in each loop pass to FM: GET_FIELDTAB or DDIF_FIELDINFO_GET
    GET_FIELDTAB    -
    >If you pass table it will give you related fields.
    Endloop.
    Regards,
    Gurpreet

  • Is it necessary to use the standard function modules always?

    Hi All,
       Suppose i can retrieve the BUSINEES PARTNER ID from the table BUT000 with the help of 'BP_GUID' field through a select query statement. 
    Now is it necessary to use a standard function module to retrieve the same data. what about the performance? which is the better solution. to implement our own code or to use the function module available.
    Please someone clarify me about this issue.
    Regards,
    Sharry.

    If you'd ask the question in general it's obvious that there is no good answer as it always would depend on the circumstance. However, as you've posted your question in the performance tuning forum, let's look at your question in this context first. I think it's fairly safe to say, that in almost 100% of the cases a standard function module will not be as fast as any well implemented and custom tailored code. If in doubt, just try reading the code of the function module you want to read; most likely you will find lots of unnecessary fluff in there, often they read data that you don't even need.
    And as far as buffering is concerned, that can also be an issue. E.g. let's say you do a massive read of distinct business partners and you only need the data once for each partner. Obviously buffering is silly in this case and it might even slow down your program, because the implemented buffering is not necessarily well implemented. I've come across a few cases, where the buffer tables where standard tables with no efficient read access (so no sorted table or hash table) and once tons of data were buffered, it actually took a moment to look up if the record already was buffered (just to find it wasn't there yet).
    Now most of the times this slowdown is not an issue as the lookup is still fast compared to the (usually) prevalent database accesses with their slower IO timing. But another factor to consider is memory consumption and why buffer data in memory (and waste it), if you can't use the buffer anyway? So when I do use standard function modules, I usually try to see what they retain in global memory, to better understand if I need to call some initialization/clearing/refresh function...
    Note also that often you need to process lots of data, but don't find a standard function module for "mass access", so you need to read your object one by one. Obviously that's another good candidate for implementing your own queries, where you can process the data in packages.
    So what might be the reason to use a standard function module? Well, often it's required because the logic is so complex that it would take you too much time to implement it (not to mention that we often simply don't know all the logic that's coded in there). Another advantage is that you might get independent of the data model. E.g. for IDoc interfaces SAP switched in some release the tables where the data is stored. So if you had coded your own queries to get IDoc data, they wouldn't have worked after this particular release upgrade. The standard function on the other hand, checks both the old and new tables, so by using it you would have been fine.
    The one major caveat I'd give though is to always check whether the function module is released or at least documented to some degree. I.e. if it's not released, SAP won't support it and does not guarantee that the interface or logic stays the same. In my experience lots of functions I do want to use are not released (or documented), but I will still use them because they seem to be the best alternative in certain scenarios.
    Cheers, harald

  • Currency Translation at the Web Template level (standard functionality)

    Hi Experts ,
    We are currently working in BI 7.0 env. with source system ECC 5.0.
    We are working for a task where we need to make the BEx  queries enabled for currency translation .
    The requirement is :-
    The user should be enable to give/opt/choose for the follwoing options:-
    Currency type (target currency in which the translation is aimed)
    Exchange Rate ( Standard(M) or other(P) or something else) and
    Key date: The translation will be performed taking the exchange rate on that particular date.
    We do have 2 option to perform the task...
    1:- Either we do it thru currency translation type definition(RSCUR) and then attaching this currency translation for every amount key figure values at each query level. OR
    2:- If we can go and find something at the Web Template level and add/modify the template in such a way so that it gives us the functionality to translate a source currency into a desired one with desired exchange rate type (currently either M or P) and for a specific date.
    At this point of time when we do have numerous sub-areas holding hundreds of queries, we want something which should be available as the modification/addition to standard functionality at the web template level and not at the query level as changing each and every one of them and testing would be a cumbersome process and would be costly and risky at the same time. So we are just wondering if we can find something with option no. 2 and add/modify something in the standard functionality.
    Please ask for any more information required.
    Thanks very much.
    regds.

    Hi Amit,
    You would still need to define the Currency Translation using RSCUR where you would specify
    -the exchange rate type (either fixed or variable)
    -the target currency (either fixed or variable)
    -the reference date
    You don't need to modify any of your queries. You can instead use 'Translate Currency'/[SET_CURRENCY_TRANSLATION] command in WAD & specify the Currency Translation as defined in RSCUR. If you want the target currency & exchange rate type to be driven by user input, you can define these as variables in RSCUR & invoke the variable screen using 'OPEN_VARIABLE_DIALOG' in WAD for user input just before calling 'SET_CURRENCY_TRANSLATION' command.
    --Priya

  • How to use standard function keys as custom keys

    how to use standard function keys as custom keys.
    i have encountered that problem while developing a screen, there i'm supposed to use standard function key F2 ( which actually meant for choose) for clearing the screen fields where the cursor is present and f1 for saving data that entered in screen fields, etc...
    kindly help me out.

    Hi ,
    Solution to use SAP reserve function keys F1 .. F4 (mostly this requirement comes up for RF screens) can be acheived by assigning your new Function code using the Menu path Utilities --> F key Consistency in the Menu Painter (SE41) . Once you assign your cutom function code to the standard Fn keys the only remaining step is to make sure that you set a curson on any of the field on sceen by using the Key Word "SET CURSOR" .
    If you dont use the key word SET CURSOR in the PBO of the screen then you might not see any response for F4.
    Thanks

  • Regarding Standard function

    Hi
    I am getting 6 digit number from the source.
    ex 103924
    in the target i want 1039.24
    Please tell me is there any standard function for this and tell me how to use it.
    regards
    venkat.

    Hi,
    You can use the FormatNumber API and formulate the no as per your requirment.
    Or Best way if the no of digits are not fixed then Multiply the Source field by 0.01
    Source Field--> Multiply (0.001 Constant) --> Target field
    Thanks
    swarup

  • Handling date to ADD or Substract fixed # of days using standard function

    Hi ,
    Using the standard functions in XI, is it possible to add or subtract a fixed number of days from the date i get from the input file.
    Like, from file I get the date as 25/06/2009.My output should be 05/07/2009 after adding 10 days .
    can some one guide how to handle this.
    Thanks,
    Ven..

    Hi Ven,
    Here is a  UDF code,which takes date(format:yyyyMMdd) as input and does addition or subtraction operations based on <field 1> value,return the result date(format:yyyyMMdd) as string value.
    public String GenerateDate(String date_input, String field1,Container container){
    //Here "date_input" and "field1" are inputs for this UDF
    int date = Integer.parseInt(date_input);
    Calendar cal;
    int day = date % 100;
    int month = (date/100) % 100 - 1;
    int year = date / 10000;
    cal = Calendar.getInstance();
    cal.set(year, month, day);
    /implement addition or subtraction logic here as your needs/
    if (field1 == "A")
    cal.add(Calendar.DATE, 10);
    else if(field == "B")
    cal.add(Calendar.DATE, -5);
    day = cal.get(Calendar.DATE);
    month = cal.get(Calendar.MONTH)+ 1;
    year = cal.get(Calendar.YEAR);
    date = year * 10000 + month * 100 + day;
    return (""+date);
    You can use Standard Funtion DateTrans to convert date from your format to the format used in the UDF and vice versa.
    Regards
    Pravesh

  • Any standard function module to read data from a cube

    Hi,
    I want to read data from a cube say XYZ, into an internal table. Is there any standard function module to do this? If so can anyone plz tell me what change should i make in the function module for my requirement.
    Regards
    BW Fresher.

    Hi R,
    Try function module 'RSDRI_INFOPROV_READ'
    ABAP Report RSDRI_INFOPROV_READ_DEMO contains an example of how the function module can be used.
    Udo

  • Standard Function to convert internal table to binary

    Hello Firends,
    Is there a standard function that can be used to convert an internal table to binary data
    and vice versa.
    regards
    kaushik

    Hi,
    I am not sure what is the requirement but you can download internal table contents in BINARY format using GUI_DOWNLOAD and viceversa you can upload Binary contents.
    ashish

  • Standard function modules

    how to work with standard function modules

    To work with standard function modules,
    First Check the function module in se37  and also read the function module documentation if available
    execute the function module.
    u will get a screen.
    You need to give some inputs in the output of the function module. say object-id as a input 4400000456.
    Also check the import and export parameters which gets updated once u execute the function modules after feeding inputs to the function module.
    actually in the example, 4400000456.
    once u give the input. the corresponding internal tables related to that object-id get automatically thru the fM.
    then u can retrieve the related information from the internal tables of function modules.
    say Get the number of days for a particular month
    in this function module my input is month  and year.
    this will return no of days for that particular month.
       CALL FUNCTION 'NUMBER_OF_DAYS_PER_MONTH_GET'
         EXPORTING
           par_month = p_bumon
           par_year  = p_bdatj
         IMPORTING
           par_days  = lv_days.
    Similary u can work with other function module , which is necessary for your requirement
    Thanks

  • Want to overwrite the standard functionality.

    Hi All,
    I have table name on selection screen field, then if I execute I want the selection screen like se 16 as it
    shows differnt fields filter criteria and further if I say execute, it should not show standard functionality,
    like se 16, but it should show , what ever I have to show in the output. means I have to overwrite the std functionality currently happening in se 16..
    if I enter VBAK and got the selection screen fields and I do execute(like se 16), but if I want to supress the further execuation as happening currently (as per the standard code), and I want to write my own functionality when I execute the seclection screen of different fields of VBAK..
    can anybody help me ?
    the thing is my selection screen (both selection screen coming in se16- like first is only "table name" and another is "table fields") is same as like se 16 but further functionality is different..
    Regards,
    Mrunal

    Hi Asha,
    Thanks for the input. My exact requirement is, I don't want to supress any field, the current functionality of SE 16 is showing some selection screen fields when we enter the table name and after that, It show
    the data base entries, In my case, I need the exact same selection screen with table name and further selection screen fields under that table but I don't want the further entries as per the existing code of se16, I want to use theses slection screen only and want to write my own functioality.
         As I want same selection screen as per se 16,so I used call transaction for se 16 or different
    function modules, so by using theses , I got the selection screen but by default when u execute, It will show the entries like se 16, but I don't want that..
    Regards,
    Mrunal

  • Standard function modules to get birthday list etc.

    Dear all,
    I need to read the following information, it is nice to have standard function modules, do you know any?
    1. monthly birthday list
    2. anniversaries of people in a month
    3. Entries/Exits of people in a month
    4. reminder for other HR events like Performance Review and Expiry of Probation
    Thanks a lot.

    Alex
    goto t-code SE37 and do a wildcard search:
    type *birth* and hit the F4 key on keyboard
    the list of function modules to extract brithdates will list out.
    you will need to spend time to review if each of them fits your requirement
    likewise for other function, feel free to do the wildcard search using the keyword in Se37
    should you are not able to find any FM for your use, i am afraid you may need to develop your own FM
    Edited by: Gregg Chen on May 19, 2011 3:20 PM

  • Issue in Standard Function DateTrans

    Hi,
    I have a requirement to convert the date format from dd-MMM-yyyy to MMddyyyy.
    I am using standard Function "DateTrans" for this conversion.I am getting the error  Unparseable date: "01-DEC-2011"
    I am working on PI7.1EHP1.
    Source Dateformat: 01-DEC-2011(dd-MMM-yyyy)
    Target Dateformat:  12012011(MMddyyyy)
    Can anyone help me on this?
    Regards,
    Sharanya

    Well Saranya... Your date trans format is perfect..
    But in PI 12 month is not dec  try dic .. It will work..
    If you are specific about DEC then you should write an UDF..
    Or use stnd fns by splitting the input date you are getting like
    split date by using substrings and for months write fixvalues 0-12 and then concate the results and use std date trans fn this can also do for you...

  • Logic required  for Sort in ALV

    Hi All,
    I am dowloding the ALV report layout in excel sheet thorough mailing functionality.
    I want to implenemnt the dynamic sort. Here I am writing this.but i want the logic for below code.
          CALL FUNCTION 'LT_DBDATA_READ_FROM_LTDX'
            EXPORTING
      I_TOOL             = 'LT'
              IS_VARKEY          = W_VARKEY_EU
            TABLES
              T_DBFIELDCAT       = IT_DBFIELDCAT_EU
            T_DBSORTINFO       =  IT_DBSORTINFO
             T_DBFILTER         = IT_FILTER_LAYOUT
             T_DBLAYOUT         = IT_DB_LAYOUT.
    LIT_DBSORTINFO[] = IT_DBSORTINFO[].
        SORT LIT_DBSORTINFO[] BY KEY1.
        DELETE ADJACENT DUPLICATES FROM LIT_DBSORTINFO[] COMPARING KEY1.
        LOOP AT LIT_DBSORTINFO[].
          CLEAR: LW_SPOS,
                 LW_UP,
                 LW_DOWN,
                 LW_SUBTOT,
                 LW_COMP,
                 LW_EXPA,
                 LW_GROUP.
          CLEAR IT_DBSORTINFO[].
          READ TABLE IT_DBSORTINFO WITH KEY
                                    KEY1  = LIT_DBSORTINFO-KEY1
                                    PARAM = 'SPOS'.
          IF SY-SUBRC = 0.
            LW_SPOS = IT_DBSORTINFO-VALUE.
          ENDIF.
          CLEAR IT_DBSORTINFO.
          READ TABLE IT_DBSORTINFO WITH KEY
                                    KEY1  = LIT_DBSORTINFO-KEY1
                                    PARAM = 'UP'.
          IF SY-SUBRC = 0.
            LW_UP = IT_DBSORTINFO-VALUE.
          ENDIF.
          CLEAR IT_DBSORTINFO.
          READ TABLE IT_DBSORTINFO WITH KEY
                                    KEY1  = LIT_DBSORTINFO-KEY1
                                    PARAM = 'DOWN'.
          IF SY-SUBRC = 0.
            LW_DOWN = IT_DBSORTINFO-VALUE.
          ENDIF.
          CLEAR IT_DBSORTINFO.
          READ TABLE IT_DBSORTINFO WITH KEY
                                    KEY1  = LIT_DBSORTINFO-KEY1
                                    PARAM = 'SUBTOT'.
          IF SY-SUBRC = 0.
            LW_SUBTOT = IT_DBSORTINFO-VALUE.
          ENDIF.
          CLEAR IT_DBSORTINFO.
          READ TABLE IT_DBSORTINFO WITH KEY
                                    KEY1  = LIT_DBSORTINFO-KEY1
                                    PARAM = 'COMP'.
          IF SY-SUBRC = 0.
            LW_COMP = IT_DBSORTINFO-VALUE.
          ENDIF.
          CLEAR IT_DBSORTINFO.
          READ TABLE IT_DBSORTINFO WITH KEY
                                    KEY1  = LIT_DBSORTINFO-KEY1
                                    PARAM = 'EXPA'.
          IF SY-SUBRC = 0.
            LW_EXPA = IT_DBSORTINFO-VALUE.
          ENDIF.
          CLEAR IT_DBSORTINFO.
          READ TABLE IT_DBSORTINFO WITH KEY
                                    KEY1  = LIT_DBSORTINFO-KEY1
                                    PARAM = 'GROUP'.
          IF SY-SUBRC = 0.
            LW_GROUP = IT_DBSORTINFO-VALUE.
          ENDIF.
          LOOP AT IT_ALV_DATA FROM W_LOOP_FROM_EU TO W_LOOP_TO_EU.
            LW_TABIX = SY-TABIX.
            READ TABLE IT_FIELDCAT INTO LW_FIELDCAT WITH KEY
                               FIELDNAME = LIT_DBSORTINFO-KEY1.
            IF SY-SUBRC = 0.
              ASSIGN COMPONENT SY-TABIX OF
                         STRUCTURE IT_ALV_DATA TO <LFS>.
              IF SY-SUBRC = 0.
                CLEAR LW_CHAR.
                LW_CHAR = <LFS>.
                  IF LW_SPOS= 'SPOS'.
                  LOGIC Required
                    ENDIF.
                  ELSEIF LW_OPTION = 'DOWN'.
                 LOgic required
                    ENDIF.
                        ENDIF.
          ENDLOOP.
        ENDLOOP.
    regards,
    Ajay reddy

    Hai,
    Let
    1)general data
    2)all customers
    3)company code data
    4)sales organization data
    are the check box names,Then
    Just use the piece  of code below:
    <b>IF general data = 'X'.
       COUNT = COUNT + 1.
    ENDIF.
    IF all_customers = 'X'.
       COUNT = COUNT + 1.
    ENDIF.
    IF company_code_data = 'X'.
       COUNT = COUNT + 1.
    ENDIF.
    IF sales_organization_data = 'X'.
       COUNT = COUNT + 1.
    ENDIF.</b>
    Now check whether more than one Check Boxes are selected or not
    <b>IF COUNT GT 1.
    "* Do the oprations  what ever you want here  
    ENDIF.</b>
    <b>Reward points if it helps you.</b>
    Regds,
    Rama chary.Pammi

  • Enhance standard function module in ECC 5.0 System

    Hi All,
    My requirement is to add the custome fields in the standard screen.there is no screen exit for this screen.
    The screen is calling by using the standard function module CALL_SCREEN_HU_DISPLAY
    Iam working on ECC 5.0 System, Is it possisble to enhance the standard function module and add custome fields.
    Please let me know if any suggestions.
    Thanks & Regards,
    Nagendra

    Hi Reddy,
    Thanks for the reply..
    Can u please give the steps how to create implicit enhancement in function modules.
    Thanks & Regards,
    Nagendra

Maybe you are looking for

  • HP Colour laserjet pro mfp m177fw

    I have just upgraded my HP Colour Laserjet MFP 175 to the new 177. When I had the 175 I could use the HP all in one Android app to scan from my tablet. Now I have the 177 it refuses to scan. It will print to it but it will not scan from it. Does anyo

  • Trying to listen to WFAN via iTunes - not working

    I can successfully listen to WFAN in NY via QuickTime and WMP. I'd like to try listening through iTunes, but cannot get it to work. I have the URL which ends in .asx. I can listen to the sample Apple provides in help, so I would guess my firewall is

  • Convert data from one table to another

    SQL> select * from A; empid | mon_tips | tues_tips | wed_tips | thu_tips | fri_tips ----------------- ------------  --------- ----------+---------- 1 | 10 | 20 | 30 | 20 | 10 2 | 10 | 20 | 30 | 40 | 50 i want a SQL query that will convert the data fr

  • Network security:LAN manager authentication level setting on GPO

    Hi, We have a requirement from project team to change the one of the security setting on default domain policy for all computers in domain. Below are the security setting which we need to modify. computer configuration-->windows settings-->security s

  • Desktop App as a Web App

    Hi! Just curiousity, is it possible to make an application that basically made as an AIR (desktop) App be viewed as a Web Application? (somehow embed into .html and get all its properties, functionalities).