Small logic in ABAP

Hi,
     am very new to abap , i have the logic of Prime number in c language , i want to do it in ABAP ,
so kindly help me .
thanks,
Sudhakar

REPORT ztest1 .
PARAMETERS: p_from TYPE i,
            p_to   TYPE i.
DATA: v_from      TYPE i,
      v_to        TYPE i,
      v_remainder TYPE i,
      v_is_prime  TYPE c,
      v_divisor   TYPE i.
START-OF-SELECTION.
  v_from = p_from.
  v_to   = p_to.
  DO.
    IF v_from = v_to.
      EXIT.
    ENDIF.
    CLEAR v_is_prime.
    DO v_from TIMES.
      v_divisor = sy-index.
      v_remainder = v_from MOD v_divisor.
      IF v_divisor <> 1      AND
         v_divisor <> v_from AND
         v_remainder = 0.
*-- not a prime
        v_is_prime = 'N'.
        EXIT.
      ENDIF.
    ENDDO.
    IF v_is_prime IS INITIAL.
*-- the number is prime
      WRITE:/ v_from, 'is a prime number'.
    ENDIF.
    v_from = v_from + 1.
  ENDDO.

Similar Messages

  • MD5sum Checksum Logic in ABAP interface

    Hi All..
    I am Pavan, ABAP Consultant from Bangalore, India....
    How to incorporate MD5sum checksum logic in ABAP interface...???
    FYI, MD5sum is a checksum tool available in the web. This tool will generate a unique No' for each flatfile downloaded from SAP via extracts..
    When i send the same flat file to my client, they will validate the checksum again.. Once it is validated, then it will be confirmed that data is not tampered... Otherwise, client will reject the file..
    This is a mandatory process for my client, since they are working as per SOXa standards... (Sarbanes - Oxley Controls & Process)
    Please help me, if any one of you have the information regarding this ..
    Thanks in Advance......
    Regards
    Pavan Sanganal
    Bangalore, India
    Email : [email protected]

    Hi,
    assuming you have the content in the well known table
    sdokcntbins, the following snippet may became useful:
      DATA:
        input_length        TYPE i,
        hash                TYPE hash160,
        data                TYPE xstring.
      CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
        EXPORTING
          input_length = input_length
        IMPORTING
          buffer       = data
        TABLES
          binary_tab   = p_file_content_binary.
      CALL FUNCTION 'CALCULATE_HASH_FOR_RAW'
        EXPORTING
          alg  = 'MD5'
          data = data
        IMPORTING
          hash = hash.
    Best regards,
    Stefan

  • Convert logic in ABAP.

    Hello,
    I want to convert following logic in ABAP.
    if i_out-belnr is between 90000000 and 99999999.
    endif.

    You can do this...
    data: r_belnr type range of belnr,
          wa_belnr like line of r_belnr.
    data: belnr type belnr.
    wa_belnr-low = '90000000'.
    wa_belnr-high = '99999999'.
    wa_belnr-sign = 'I'.
    wa_belnr-option = 'BT'.
    append wa_belnr to r_belnr.
    if i_out-belnr  in r_belnr.
    endif.

  • Logic in ABAP HR

    Hi folks,
             Actually my requirement is, i have some data in an internal table. I have to check the particular record in in that itab is there in infotype 9003 by checking some condtions. if the record is not found in the 9003 i need to display a error message. I am new to ABAP HR. Please help me regarding the logic of comparing ITAB and an infotype in my requirement here.
                    Thanks,
                    Ram.

    Create a program
    In program attributes
    Put PNP for the Logical Database field
    Save it
    You will have PNP's standard selection screen
    If you dont want selection screen from PNP,
    In program attributes Choose HR REPORT CATEGORY
    Create one with no fields for selection
    tables: pernr
    infotypes: 0000, 0001, 0002, 0006, 9003
    start-of-selection.
    get pernr.
    loop at table p9003.
    endloop.
    all values of 9003 will be in internal table p9003
    If you have Personnel number in your internal table itab then the easier code without PNP Logical database is
    loop at itab.
      CALL FUNCTION 'HR_READ_INFOTYPE'
        EXPORTING
    *     TCLAS                 = 'A'
          pernr                 = itab-pernr
          infty                 = 9003
         BEGDA                 = '18000101'
         ENDDA                 = '99991231'
       IMPORTING
         SUBRC                 = subrc
        tables
          infty_tab             = it9003
       EXCEPTIONS
         INFTY_NOT_FOUND       = 1
         OTHERS                = 2
      IF sy-subrc = 0.
    ** Do the processing you want to do
      ENDIF.
    endloop.
    Reward points if helpful

  • Logical difference   ABAP  InputScript

    Hi,
    What is the logical difference between a "Call transaction using..." in ABAP and an InputScript?
    Thanks,
    Govindappa.

    Hi,
    There are 2 main differences between ABAP call transaction and InputScript:
    - The InputScript remains active while you process the transaction.
    In particular, you can read all screen values and make decisions based on these values.
    When you implement a Call Transaction in ABAP, you have to deliver all input data in advance.
    - GuiXT offers a number of built-in features. For example, GuiXT will automatically display those popup screens that you do not handle in your InputScript, so that the user can continue, even in a situation that you did not anticipate.
    Reward Points if found helpfull..
    Cheers,
    Chandra Sekhar.

  • Help in writing logic to abaper for printing contact details from partnr fn

    Hi friends,
    I have to give the logic to the abaper to print the contact details of one partner which is manually entered in the quotation at header level.
    i have a partner z1 with partner type PE which is manually entered in the partner fn field at the header level.  this z1 partner fn is an employee.  The name and contact details of this employee needs to be printed in the header of the output.
    What is the logic i need to give to abaper for this.
    Regards,
    Anand

    Hi Anand,
    In case you do not find an ADRNR for the respective partner funtion in VBPA table, then, it means that the employee number derived from customer master is correct. Then, I think you can take KUNNR number for the employee partner function thro' VBPA and put the same in KNA1 table to get the right ADRNR. (As explained by me in the first post).
    My question now is, are you maintaining the employee in XD01 (customer) or in VPE1 (Sales Rep)?
    You can try with tables PA0002 Personal Data and PA0006 Addresses only if you maintain employees thro' VPE1 Tcode.  PA0006 has PERNR field. But, what you have to make sure is that the table is getting updated. Else, you may not find the data here as well.
    Hope this helps...
    Thanks
    Mukund S

  • A small logical problem in LSMW for MM01...

    I need to create a LSMW for MM01 transaction, wherein I have to check the initial four
    digits of the material as 'ORCL'. If initial four digits of the
    incoming material are 'ORCL', then create this material as it is.
    Else replace these four digits with 'SAPM' (for sap material) while
    creating this material.
    This will  differentiate between materials coming from Oracle and non
    oracle system.
    I know that I need to create a new rule in the step 5 of LSMW: "Maintain Field Mapping and Conversion Rules", under the ABAP heading.
    But, how should the rule proceed??
    Pls help me out!!!

    awesome! thnks a lot naimesh.... you are tooo goood!
    Can you please help me again...??
    Now, I need to replace the records which are not 'ORCLXXX' with SAPXXX format. For example, say a record has the material number as ORCL007. This will pass on and created as ORCL007. If a record has the material number as MMMM007, this should be converted to SAPM007.
    Should I use fieldsymbols for this, or just replace the strings??
    This will be the last, I promise....

  • HR - Supress Error messages at end of PNP Logical dB ABAP

    It appears from the code for logical dB PNP that you can turn off the error messages that automatically print at the end of the program, but I don't see how to do it.  Here's the SAP code in include DBPNPI01:
    FORM end-processing.
      CHECK sw_supress_write EQ no.
    Can anyone tell me how to 'change' sw_supress_write?

    Try this code:
    DATA:
      BEGIN OF t_empty OCCURS 50,
            pernr LIKE pernr-pernr,
      END   OF t_empty.
    DATA:
      temp1 TYPE i,
      temp2 TYPE i,
      temp3 TYPE i.
    NODES: pernr.
    START-OF-SELECTION.
      PERFORM pnp_skipped_pernr(sapdbpnp)
        TABLES t_empty
        USING 'Y'
        CHANGING temp1 temp2 temp3.
    GET pernr.
    * Do something here.
    *FORM pnp_skipped_pernr
    *         TABLES   locked_pernr_tab     LIKE locked[]        "out
    *         USING    supress_reject_info  LIKE sw_supress_write"in
    *         CHANGING auth_skipped_count   LIKE auth-skip-count "out
    *                  locked_skipped_count LIKE locked_pernr_count"out
    *                  locked_occurs_param  LIKE locked_ocp.     "out
    *  locked_pernr_tab[]   = locked[].
    *  sw_supress_write     = supress_reject_info.
    *  auth_skipped_count   = auth-skip-count.
    *  locked_skipped_count = locked_pernr_count.
    *  locked_occurs_param  = locked_ocp.
    *ENDFORM.                               "pnp_skipped_pern
    Let us know how it goes.

  • Need logic in abap-hr

    Hi
    I have a requirement that employee can display,edit,view and confirm his personel data i.e first name,last name.dob etc.
    Requirement is:
    need 4 tabs :1 for display data,1 for edit, 1 for review and 1 for confirm.
    here using bapis for getting data and to change data.
    Need help that what's the infotypes,tables involved here and what's the exact logic.
    Points are assured for correct answers.
    Regards,
    Sree

    Hi Sreeram,
    Employee personal data is held in infotype number 0002.
    The database table @ the back end is PA0002.
    However in HR you do not update infotypes via direct DB update, rather we have function modules for the same:
    Display Data (extracting personal data from infotype 0002) use function module HR_READ_INFOTYPE
    Update Data into infotype 0002 for a employee use function module HR_INFOTYPE_OPERATION.
    Cheers,
    Aditya

  • Please help me think about logic in abap program

    Hello every one.
    i have question.
    my selection of program is
    company code
    brand from:    to:
    fiscal year
    period from:   to:
    example.
    company code  0145
    brand from:AAA    to: ZZZ
    fiscal year 2011
    period from: 4  to: 6
    and desired output report is
    brand AAA        April   May  June
    sale              700     600  700
    COG               300     250  350
    Net sale          400     350  250
    brand BBB        April   May   June
    sale             1000    500   800
    COG               500    250   400
    Net sale          500    250   400
    sum of all brand   April  May  June
    sale              1700    1100  1500
    COG               800     500   750
    Net sale          900     600   650
    pleae help me to think about logic.
    now i just have idea that i have to
    loop at internal_table_brand.
    Moderator Message: Do not dump your spec in the forum.
    Edited by: Suhas Saha on Jun 16, 2011 4:16 PM

    Hi,
    This works now. You just need to create your methods and link them in with your case statement as flounder showed you.
    import java.util.Scanner;
    public class CarConfiguration
         public static void main(String[] args)
         int choise = Menu();
         processSelector(choise);
         private static int Menu()
              System.out.println("\nWELCOME TO CAR CONFIGURATION APPLICATION PROGRAM");
              System.out.println("======================================");
              System.out.println(" Enter _1_ to Chasis Type");
              System.out.println(" Enter _2_ to Engine Type");
              System.out.println(" Enter _3_ to Transmission");
              System.out.println(" Enter _4_ to Options ");
              System.out.println(" Enter _5_ to Finish ");
              System.out.println("======================================");
              System.out.print("Select Your Choise: ");
         Scanner input=new Scanner(System.in);
         int choise=input.nextInt();
         return(choise);
         private static void processSelector(int choise)
              switch(choise)
                   case 1: //enter mehtods here and for all other empty cases
                   break;
                   case 2:
                   break;
                   case 3:
                   break;
                   case 4:
                   break;
                   case 5:
                   break;
                   default:
                   System.out.println("Invalid selection");
                   break;
    }

  • Small query in ABAP dynpro

    Hi Experts,
    I am new to ABAP webdynpro. I have created a sample application following the example provided in the SAP help. In one of "supply function" I have used the below code for getting the node in a context
    datanode = wd_context->get_child_node( name = 'DATA' ).
    wd_context refers to the interface IF_WD_CONTEXT_NODE. I went to this interface and identified the method get_child_node. But when I double click on the method nothing happens. I want to see the coding , how the system gets the node using this method.
    thanks
    sankar

    Hi Sankar,
    IF_WD_CONTEXT_NODE is an interface and hence has no code in it. You need to find the code inside a class which implements this interface. In this case, you need to go to class CL_WDR_CONTEXT_NODE.
    Again, CL_WDR_CONTEXT_NODE is an abstract class. So you need to find the implementation inside a subclass. In this case, the subclasses are CL_WDR_CONTEXT_NODE_MAP and CL_WDR_CONTEXT_NODE_VAL. Both implement the method we are talking about.
    These are general OOPS concepts.
    The hierarchy of classes and interfaces can be very easily found by using the 'Object List' tool for the selected object (Short cut ctrlshiftf5)
    Hope this helps.
    Regards,
    Neha
    Message was edited by:
            Neha Agrawal

  • I have logical problemin ABAP

    hi all
    i hav internal table call it_itab1 so there has som several equal record. so i want to get yhe som of all equal item. i can shaw u to so example.
    it_itab1 table
    code    item  value                                         
    001      4k     120                                         
    001      4k     100                                          
    001      4k      80              
    002      5h      200                      
    002      5h      100
    003      6y      500
    003      6y      400
    i ant to get som of each equl feild
    code     item   value
    001       4k      300 
    002       5h      300
    003       6y      900                 
    i think u can understand wot me want.. i want to sum of each equal feild value...(001 4k =(12010080) ... this is my requrement so how should i write the code. if u can please help me...
    regard
    nawa

    Hi
    U can do it using COLLECT
    Basic form
    COLLECT [wa INTO] itab.
    Addition: ... SORTED BY f
    In an ABAP Objects context, a more severe syntax check is performed that in other ABAP areas. See Short forms of line operations not allowed.
    Effect
    COLLECT allows you to create unique or summarized datasets. The system first tries to find a table entry corresponding to the table key (see Key definition for internal tables ). The key values are taken either from the header line of the internal table itab, or from the explicitly-specified work area wa. itab must have a flat structure, that is, it may not contain other internal tables. All components that are not part of the key must be have numeric types (see ABAP numeric types).
    If the system finds an entry, the numeric fields that are not part of the table key (see ABAP number types) are added to the sum total of the existing entries. If it does not find an entry, the system creates a new entry instead.
    The way in which the system finds the entries depends on the type of the internal table:
    STANDARD TABLE:
    The system creates a temporary hash administration for the table to find the entries. This means that the runtime required to find them does not depend on the number of table entries. The administration is temporary, since it is invalidated by operations like DELETE, INSERT, MODIFY, or SORT. A subsequent COLLECT is then no longer independent of the table size, because the system has to use a linear search to find entries. For this reason, you should only use COLLECT to fill standard tables.
    SORTED TABLE:
    The system uses a binary search to find the entries. There is a logarithmic relationship between the number of table entries and the search time.
    HASHED TABLE:
    The system uses the internal hash administration of the table to find records. Since (unlike standard tables), this remains intact even after table modification operations, the search time is always independent of the number of table entries.
    For standard tables and SORTED TABLEs, the system field SY-TABIX contains the number of the existing or newly-added table entry after the APPEND. With HASHED TABLEs, SY-TABIX is set to 0.
    Notes
    COLLECT allows you to create a unique or summarized dataset, and you should only use it when this is necessary. If neither of these characteristics are required, or where the nature of the table in the application means that it is impossible for duplicate entries to occur, you should use INSERT [wa INTO] TABLE itab instead of COLLECT. If you do need the table to be unique or summarized, COLLECT is the most efficient way to achieve it.
    If you use COLLECT with a work area, the work area must be compatible with the line type of the internal table.
    If you edit a standard table using COLLECT, you should only use the COLLECT or MODIFY ... TRANSPORTING f1 f2 ... statements (where none of f1, f2, ... may be in the key) enthalten sein). Only then can you be sure that:
    -The internal table actually is unique or summarized
    -COLLECT runs efficiently. The check whether the dataset
    already contains an entry with the same key has a constant
    search time (hash procedure).
    If you use any other table modification statements, the check for entries in the dataset with the same key can only run using a linear search (and will accordingly take longer). You can use the function module ABL_TABLE_HASH_STATE to test whether the COLLECT has a constant or linear search time for a given standard table.
    Example
    Summarized sales figures by company:
    TYPES: BEGIN OF COMPANY,
            NAME(20) TYPE C,
            SALES    TYPE I,
          END OF COMPANY.
    DATA: COMP    TYPE COMPANY,
          COMPTAB TYPE HASHED TABLE OF COMPANY
                                    WITH UNIQUE KEY NAME.
    COMP-NAME = 'Duck'.  COMP-SALES = 10. COLLECT COMP INTO COMPTAB.
    COMP-NAME = 'Tiger'. COMP-SALES = 20. COLLECT COMP INTO COMPTAB.
    COMP-NAME = 'Duck'.  COMP-SALES = 30. COLLECT COMP INTO COMPTAB.
    Table COMPTAB now has the following contents:
              NAME    | SALES
              Duck    |   40
              Tiger   |   20
    Addition
    ... SORTED BY f
    Effect
    COLLECT ... SORTED BY f is obsolete, and should no longer be used. It only applies to standard tables, and has the same function as APPEND ... SORTED BY f, which you should use instead. (See also obsolete statements.)
    Note
    Performance:
    Avoid unnecessary assignments to the header line when using internal tables with a header line. Whenever possible, use statements that have an explicit work area.
    For example, "APPEND wa TO itab." is approximately twice as fast as "itab = wa. APPEND itab.". The same applies to COLLECT and INSERT.
    The runtime of a COLLECT increases with the width of the table key and the number of numeric fields whose contents are summated.
    Note
    Runtime errors:
    COLLECT_OVERFLOW: Overflow in an integer field during addition
    COLLECT_OVERFLOW_TYPE_P: Overflow in a type P field during addition.
    TABLE_COLLECT_CHAR_IN_FUNCTION: COLLECT on a non-numeric field.
    Regards,
    Prasanth
    Reward all helpful answers

  • Help needed in writing a small piece of ABAP Code

    Subject : look up in an ODS and update in a characteristic routine (BI 7.0)  
    Hi ,
    My requirement is : I have data coming from both legacy as well as SAP Systems. The user wants both legacy as well as SAP fields data in their reports.
    I have a Standard DSO ( say DSO1) with all the legacy fields with direct mappings from Legacy sytem along with couple of SAP fields which are not mapped as of now.
    I have few more DSO's which have just the legacy field and corresponding SAP field data.
    like DSO 2 with ZCOMPCODE and 0COMPCODE data.
    All i have to do is write a Routine for unmapped 0COMPCODE field in DSO1 that pulls up corrersponding 0COMPCODE values for ZCOMPCODE from DSO 2 .
    *Could someone please help me with the Coding part of the Routine.*
    Greatly appreciate your help.

    CREATE OR REPLACE FUNCTION fucntion_name(latA IN NUMBER, longA IN NUMBER, latB IN NUMBER, longB IN NUMBER) RETURN NUMBER
    IS
    pi      CONSTANT NUMBER:=3.14159;
    theta NUMBER;
    distX  NUMBER;
    distY  NUMBER;
    distZ  NUMBER;
    distP  NUMBER;
    BEGIN
    theta :=longA - longB;
    distX :=sin( latA * PI /180) * sin ( latB * PI /180) + cos ( latA * PI/180) * cos ( latB * PI/180) * cos ( theta * PI / 180);
    distY :=acos(distX); --this is arc cosine
    distZ :=distY * 180/PI;  --PI refers to the mathematical PI
    distP :=distZ * 60 * 1.1515; --this value should be returned. Of course the intermediate variable names don't matter.
    RETURN distP;
    END;Edited by: Ora on May 3, 2011 11:46 PM

  • Small issue in ABAP coding

    HI Folks,
    i have a internal table having 2 fields and 10 reocrds, ineed to find out the records which are starting with digit 9 only, please let me know how can i go with that.
    i traid with '9%' it is giving dump.
    plz help.
    Thanks,
    Ritesh

    Hi,
    check this :
    if your internal table is i_tab and fields are fld1 and fld2 ...
    loop at i_tab into wa_tab.
    if wa_tab-fld1+0(1) = '9'.
      append wa_tab to i_tab2.
    endif.
    endloop.
    i_tab2 will have required records
    regards
    Appana

  • Required small logic to pick data from p2006

    Please delete this thread
    Edited by: saslove sap on Apr 6, 2010 12:31 PM

    Hi shankara,
    1. Direct Select statement ,if used for cluster tables ,will cause performance issues
    U are right, but there is no option.
    2. EVEN if we use some standard FM,
       it will indirectly, use a select statement only.
    3. Hence, we cannot avoid using select statement.
    regards,
    amit m.

Maybe you are looking for

  • How to change preferences for all users in a Citrix enviroment

    Hello. I need change some preference settings for all users in my Citrix enviroment. I know change the preference settings for a user, of course, but a have 160 users and a need to change some settings configuration one time on the server for all use

  • How to transfter data from one page to another one

    Hi everybody, I have got a page index.jsp which includes menswear button, chirldrenswear button and womenswear button, but user click one of them , it will go to another page called display.jsp to display all products information, if button mensware

  • White screen issue on iPhone 4S?

    Recently when I tried to use my iPhone the screen just turned completely white. I have no idea why. The screen is still functional in that if I receive a call, I'm still able to swipe to pick it up. I even tried a hard reset by holding the power and

  • Error CreateImage in for loop array

    Hi, I would like to dynamically create images inside a for loop. It dependent on the array_size that the sevlets will send. Snapshots of code: for (int i = 0; i < ARRAY_SIZE; i++) img[i] = Image.createImage("\"/nike" + (i+1) + ".png\""); }Error: java

  • Facebook application not compatible

    the facebook on my iphone 3g got deleted by accident and now when i try to download the application again it says its not compatible with this iphone. does anyone know what i can do to fix this?