Need ABAP code for Routine

Hi Gurus My requirement goes like this.
                              I need to write the routine in Transformation from DSO to DSO
Source table
Doc         Amt         Netduedate      Reference Doc
1000      10000     01.01.2010        
1500       5000      30.01.2010        1000
1700       3000      02.02.2010        1000  
In the Above table 1st document is Invoice Document, 2nd and 3rd are Partial Payment Document.
My requirement is 2nd and 3rd record Netduedate value should have 01.01.2010 by referring reference Doc field, for the above Ex We should have the output like this
Target table
Doc         Amt         Netduedate      Reference Doc
1000      10000     01.01.2010        
1500       5000      01.01.2010        1000
1700       3000      01.01.2010        1000  
Please give me the syntax code and where to write the code ie in the start routine or in the field routine. the dataflow is between one DSO to Another DSO
Please Provide me the solution ASAP as this is very Urgency.
Thanks in Advance

If suppose your documents are being loaded in same load,
1. start routine - create internal table like SOURCE_PACKAGE
DATA IT_SOURCE_PACKAGE TYPE TABLE OF SOURCE_PACKAGE.
DATA WA_SOURCE_PACKAGE LIKE LINE OF SOURCE_PACKAGE.
2. copy all records to new internal table, IT_SOURCE_PACKAGE[] = SOURCE_PACKAGE[]
3. delete partial docs, DELETE IT_SOURCE_PACKAGE WHERE REF_DOC IS NOT INITIAL.
4. Sort internal table SORT IT_SOURCE_PACKAGE BY DOC
5. Look for original doc inside loop.
LOOP AT SOURCE_PACKAGE ASSIGNING <SOURCE_FIELDS> WHERE REF_DOC IS NOT INITIAL.
READ TABLE IT_SOURCE_PACKAGE 
      INTO WA_SOURCE_PACKAGE
      WITH KEY DOC = <SOURCE_FIELDS>-REF_DOC  BINARY SEARCH.
IF SYSUBRC EQ 0.
  <SOURCE_FIELDS>-NDUEDATE = WA_SOURCE_PACKAGE -NDUEDATE.
ENDIF.
ENDLOOP.
If the original documents are found in different loads in the source DSO, we need to pull the records from active table of the target DSO after step 2.
-Jijo

Similar Messages

  • Need ABAP code for the below Services requirement

    Hi,
    We have a requirement to show all the services for a particular Purchase order number.For this I built a view on 2 tables ESLL and EKPO.Now based on the below logic I need to bring the services for the Purchase order..
    1.Enter PO number,item no. and Doc category in EKPO and find the Pack no.
    2.Now take the Pack no. of EKPO and give in ESLL and find the Sub pack no.
    3.Now take this Subpack no. and Give this sub pack as Pack no. in ESLL
    4.This will be the Service entry record for that PO number.
    Can any one Please suggest me to how to write the ABAP code for the above logic.
    Thanks & Regards,
    Dinakar

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

  • Need ABAP code for Datasource Enhancement

    Hi All,
    I need no Enhance the WBS Element(PS_PSP_PNR) to2 LIS_02_ITM Datasource
    the table EKKN Having WBS element
    From EKKN Table We have to take the filed Append to the2LIS_02_ITM datasource
    Please any one give me ABAP code which is write in CMOD
    Thanks........
    Regards!
    Malli

    Hi,
    See SAP Help
    http://help.sap.com/saphelp_nw04s/helpdata/en/6e/fe6e420f00d242e10000000a1550b0/content.htm
    See the simple example code, so follow the same.Take ABAPer help, don't use select and end select.
    CASE i_datasource.
      Data: l_s_data1 LIKE mc13vd0itm,
            l_tabix   LIKE sy-tabix,
      WHEN '2LIS_13_VDITM'.
        LOOP AT c_t_data INTO l_s_data1.
          l_tabix = sy-tabix.
          SELECT SINGLE auart INTO l_s_data1-zzprdtyp FROM vbak
                 WHERE  vbeln  = l_s_data1-aubel.
          IF sy-subrc = 0.
            MODIFY c_t_data FROM l_s_data1 INDEX l_tabix.
          ENDIF.
        ENDLOOP.
    ENDCASE.
    Data: l_s_data18 LIKE mc12vc0itm ,
          l_tabix   LIKE sy-tabix.
      WHEN '2LIS_12_VCITM' .
        LOOP AT c_t_data INTO l_s_data18.
          l_tabix = sy-tabix.
          SELECT SINGLE ernam FROM ekko
           INTO (l_s_data18-ernam)
           WHERE ebeln = l_s_data18-vgbel .
          IF sy-subrc = 0.
            MODIFY c_t_data FROM l_s_data18 INDEX l_tabix.
          ENDIF.
        ENDLOOP.
    See article on Step by Step Guide to Enhance a Data Source:
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/00c1f726-1dc2-2c10-f891-ddfbffdb1a46?quicklink=index&overridelayout=true
    Thanks
    Reddy

  • Needs sample ABAP code for field routine

    Dear Expert,
    There is a field "Pay Scale Group" in my DSO which stores the data in the format
    AA1/B1/CCC2/DD2/EEE1, A1/BB2/CC2/DDD3/EE2 etc. These data has to be transferred to
    InfoCube where "pay Scale Group" in the InfoCube will store the data like EEE1,EE2 etc.
    I need to write a field routine on the transformation between DSO and Cube.
    Can any one please help me with the sample ABAP code for this scenario.
    Some more examples for better understanding of the requirement:-
    Data in DSO(Source)            Data in Cube(Target)
    ===================            ===================
    AA1/B1/CCC2/DD2/EEE1            EEE1
    AAA1/BB2/CC1/DDD3/EE2           EE2
    A2/BBB2/CC2/DDD3/EEE5           EEE5
    AA2/BB1/C1/DDD3/EE3             EE3
    A3/B1/CC2/DDD1/EE4              EE4
    Many thanks in advance.
    Regards,
    Prakash
    Please do not dump your code requirements in SDN
    Edited by: Pravender on May 18, 2011 11:37 AM

    Hi,
    You can use the following code :
    Suppose the technical name of the field coming from DSO is ZPAY_SGRP.
    And also for example let me take one record, that is ZPAY_SGRP = AA1/B1/CCC2/DD2/EEE1 .
    My assumption is that there will always be 4 '/'.
    In the field routine write the below code
    data: V1(5) type c,
              V2(5) type c,
             V3(5) type c,
              V4(5) type c,
             V5(5) type c.
    data : VAR1 TYPE /BIC/OIZPAY_SGRP.
    split VAR 1  at '/' into V1 V2 V3 V4 V5.
    result = V5.
    V5 will be having the characters after the last '/' .That is V5 = EEE1.
    Hope the above reply was helpful.
    Kind Regards,
    Ashutosh Singh
    Edited by: Ashutosh Singh on May 17, 2011 3:53 PM
    Edited by: Ashutosh Singh on May 17, 2011 4:17 PM

  • ABAP code for BI 7.0 transformations start routine

    Hi all,
    I am trying to update data from DSO1 (Source1: transaction data) to Infocube(TARGET)
    In the transformations Start routine, I have to read DSO2(Source2: Master data) for some fields.
    DSO1 has CUSTOMER as part of key
    DSO2 has CUSTOMER (key) and other fields....FIELD1, FILED2, FIELD3
    Infocube to be updated with FIELDS1,2 & 3 WHILE READING DSO2.
    WHERE DSO1 CUSTOMER matches with DSO2 CUSTOMER.
    Also, data NOT TO BE UPLOADED into Infocube if FIELD1 in DSO2= NULL
    Please give me the abap code for the above logic.
    Appreciate any help in this regard.
    Thanks.

    This is a doc from this site:
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/6090a621-c170-2910-c1ab-d9203321ee19
    Ravi Thothadri

  • Abap code for splitting date needed

    Hi Experts,
    I need ABAP code or a function module to split date into date, month and year. As I have very little knowledge in ABAP, I do not know how to do it. Kindly help me.
    Thanks in advance,
    With Kind Regards,
    Kannan

    Hello kannan,
    I tried writing this program , it worked for me .
    PARAMETERS : date(10) TYPE c default '24.12.2014',
                  dd(2) type c,
                  mm(2) type c,
                  yyyy(4) type c.
    split date at '.' into dd mm yyyy.
    WRITE : / 'Day: ', dd.
    WRITE : / 'Month: ', mm.
    WRITE : / 'Year: ', yyyy.
    If you feel this program suits  you try this as well.

  • ABAP Code for BI objects

    Hi Friends,
    I have created BI objects like infocubes, infoobjects, DTP, Datasource to transfer data from a flat file to BI system using SAP GUI... All data from flat file are transfered to BI successfully... i dont have any knowledge in ABAP... So i need to see the ABAP code for the BI objects i created above in my project... how can i see the coding for that?
    thanks in advance
    sasi

    Hi Sasi,
    All the objects which you create in BI will be stored in some standad tables,it only fetch details accordingly from those tables.For MasterData you can find the option as Display Routines in Extras.If you want to get more infomation about the STD Table and the Program involed in BI objects,just enter in (/h) mode.
    Regards,
    Prem

  • Need ABAP code to make unique hierarchy values - Request prompt help

    hi
    <removed>
    I am new to SAP. Please help me in the following
    I require an ABAP code for the following scenario
    I have a simple hieraarchy. The hierarchy is
    SEG -> fam -> clas -> comm
    The values of the seg , fam, cla, com......all will be charecter values
    But in some cases the values will be NOT_KNOWN
    If the values are NOT_KNOWN i need to change them as NOT_KNOWN_1, NOT_KNOWN_2...like that unique charecter values
    should be replaced for NOT_KNOWN
    Example
    SEG->FAM->CLA ->COM
    Clothing -> Mens wear -> Designer garments -> NOT_KNOWN
    Construction -> equipments -> machinery->NOT_KNOWN
    Computers -> Laptops -> Imported -> NOT_KNOWN
                     -> desktops ->flat monitors -> Indian
                           -> imported                     -> NOT_KNOWN->
    NOT_KNOWN -> baggages
    This should be changed to
    SEG->FAM->CLA ->COM
    Clothing -> Mens wear -> Designer garments -> NOT_KNOWN_1
    Construction -> equipments -> machinery->NOT_KNOWN_2
    Computers -> Laptops -> Imported -> NOT_KNOWN_3
              -> desktops ->flat monitors -> Indian
                              -> imported                         
           -> NOT_KNOWN_4 ->
    NOT_KNOWN_5 -> baggages
    This is to make them unique nodes to upload them in hiereachy
    Data is coming from database tables and i was not supposed to do anything in database and the incomin
    data needs to finetuned like this to update them in cube
    So I like to have some coding which will enable this to work in the start routine
    If start routine is not the right option, where else we can do coding
    <removed>
    Regards
    KC

    data : w_suff_n(8) type n,
             w_suff_c(8).
    loop at data_package.
    if data_package-<fieldval> = 'NOT_KNOWN'.
      w_suff_n = w_suff_n + 1. w_suff_c = w_suff_n.
      shift w_suff_c left deleting leading '0'.
      concatenate data_package-<fieldval> w_suff_c into data_package-<fieldval>.
      modify data_package.
    endif.
    endloop.
    *Change <fieldval> in the above to the actual field name.

  • How To Create ABAP Code For HR Context Sensitive Structural Authorization

    Hello,
    We have created a HR Custom Program which IS NOT built off the PCH or PNP Logical Database. As a result, we need to manually create ABAP code for HR Context Sensitive Structural Authorization Check in our custom HR program. Via HR Context Sensitive Structural Authorizations, we are restricting access to personnel numbers and the underlying HRP* tables.
    Any assistance would be greatly appreciated with the identification of the SAP standard function modules (Ex. RH_STRU_AUTHORITY_CHECK, HR_CHECK_AUTHORITY_INFTY, HR_CHECK_AUTHORITY_INFTY , etc) used in HR Context Sensitive Structural Authorization Check, how they are used to control HR Structural authorization (P_ORGINCON), and some sample code.
    Thank you in advance for all your assistance,
    Ken Bowers

    Hello Ken
    You can use the interface methods IF_EX_HRPAD00AUTH_CHECK to get the same structural authorization as you can see in PA20/PA30. You need to use the methods set_org_assignment and check_authorization for this purpose. For more information you can refer to include FP50PE21 from line 237 onwards till 270.
    Regards
    Ranganath

  • Need a code for Customer exit for extractor 0WBS_ELEMT_ATTR

    Hi Guys,
    I need a code for following requirement.
    I have appended some fields to standard extractor 0WBS_ELEMT_ATTR which normally takes data from PRPS table. But the new fields will be getting data from PRTE and PROJ table. with common keys. Following is my code which is not working. Please help me out, I am not good in abap. Please note some lines are commented.
    Thanks,
    H
    CODE:::::
    form 0wbs_elemt_attr  tables i_t_data structure biw_prps.
      data: it_wbs_prps like biw_prps occurs 0.
      data wa_prps like it_wbs_prps.
    data: begin of it_wbs_prps occurs 0,
             PSPNR like prps-pspnr,
             POSID like prps-posid,
             PBUKR like prps-PBUKR,
             IZWEK like prps-IZWEK,
             USR10 like prps-USR10,
             USR00 like prps-USR00,
             USR02 like prps-USR02,
             OBJNR like prps-OBJNR,
           end of it_wbs_prps.
    data wa_prps like it_wbs_prps.
      data: begin of it_wbs_prps1 occurs 0,
              PSPNR like prps-pspnr,
              POSID like prps-posid,
            end of it_wbs_prps1.
      data wa_prps1 like it_wbs_prps1.
      data: begin of it_wbs_prte occurs 0,
              posnr like prte-posnr,
              PSTRT like prte-PSTRT,
              PENDE like prte-PENDE,
              ESTRT like prte-ESTRT,
              EENDE like prte-EENDE,
              ISTRT like prte-ISTRT,
              IENDE like prte-IENDE,
            end of it_wbs_prte.
      data wa_prte like it_wbs_prte.
      data: begin of it_wbs_proj occurs 0,
              PSPNR like proj-pspnr,
              PLFAZ like proj-plfaz,
              PLSEZ like proj-plsez,
            end of it_wbs_proj.
      data wa_proj like it_wbs_proj.
    refresh: it_wbs_prte, it_wbs_proj.
    *it_wbs_jest.
    if i_t_data[] is not initial.
    Get data from PRPS WBS Master Data
         select pspnr posid PBUKR IZWEK USR10 USR00 USR02 objnr
           into corresponding fields of table it_wbs_prps
           from prps
            for all entries in i_t_data
          where POSID = i_t_data-POSID.
         sort it_wbs_prps by posid.
    Get data from PRPS1 WBS Master Data
          select pspnr posid
           into corresponding fields of table it_wbs_prps1
            from prps
            for all entries in i_t_data
         where POSID = i_t_data-POSID.
        sort it_wbs_prps1 by posid.
    Get data from PRTE Scheduling Data for Project Item
         if it_wbs_prps1[] is not initial.
         select posnr PSTRT PENDE ESTRT EENDE ISTRT IENDE
           into corresponding fields of table it_wbs_prte
           from prte
            for all entries in it_wbs_prps1
          where posnr = it_wbs_prps1-pspnr.
         sort it_wbs_prte by posnr.
         endif.
    Get data from PROJ Project Master Data
         if it_wbs_prps1[] is not initial.
         select pspnr PLFAZ PLSEZ
           into corresponding fields of table it_wbs_proj
           from proj
           for all entries in it_wbs_prps
          where pspnr = it_wbs_proj-pspnr.
         sort it_wbs_proj by pspnr.
         endif.
    loop at i_t_data.
       clear: wa_prps1, wa_prte, wa_proj.
       read table it_wbs_prps into wa_prps with key
                  posid = i_t_data-posid binary search.
       read table it_wbs_prte into wa_prte with key
                  posnr = wa_prps1-pspnr.
       read table it_wbs_proj into wa_proj with key
                  pspnr = it_wbs_proj-pspnr.
             i_t_data-zzPBUKR = wa_prps-pbukr.
             i_t_data-zzIZWEK = wa_prps-IZWEK.
             i_t_data-zzUSR10 = wa_prps-USR10.
             i_t_data-zzUSR00 = wa_prps-USR00.
             i_t_data-zzUSR02 = wa_prps-USR02.
              i_t_data-zzPSTRT = wa_prte-PSTRT.
              i_t_data-zzPENDE = wa_prte-PENDE.
              i_t_data-zzESTRT = wa_prte-ESTRT.
              i_t_data-zzEENDE = wa_prte-EENDE.
              i_t_data-zzISTRT = wa_prte-ISTRT.
              i_t_data-zzIENDE = wa_prte-IENDE.
              i_t_data-zzPLFAZ = wa_proj-PLFAZ.
              i_t_data-zzPLSEZ = wa_proj-PLSEZ.
        modify i_t_data.
    endloop.
    endif.
    endform.                    " 0wbs_elemt_attr

    Hi,
    it_wbs_prps1 .
    If you are going to use this internal table to check for a null condition, shouldn't you first assign the data package to it?
    For example,   it_wbs_prps1 = i_t_data[].
    Because you are now using  it_wbs_prps1 to select data from a table and it doesn't have any data.
    Please check.
    -RMP
    Edit : Please ignore this. I didn't see that you are actually filling the internal table. Sorry!
    Edited by: RMP on Oct 18, 2010 12:16 PM

  • ABAP  Code for SAP exit varaibles?

    Hi,
    i) Where can I find the abap code for SAP exit variables
    OP_KEYDT used for the net due date
    OP_KEYD2 used for the posting date
    OP_KEYD3 used for the clearing date, which are used in FI AR aging report(0FIAR_C03).
    Based on the Net Due Date, which is key date(0NETDUEDATE), entered by the user at runtime, the posting date and celaring date are populated.
    II) The problem is we want to simulate a similar scenario, but with key date, which user enters is based on the custom Net Due Date(ZNETDUEDATE).And this date is populated to posting date and clearing date variables.
    How do we acheive that.
    Thanks.

    Hi Kumar,
    Try this below mentioned example where default date is current date.
    Step1: Create a variable(ex: cur_date) on requrired characteristic with Processing type "Customer Eixt" and check the check box for ready for input(if this variable need in selection screen).
    Step 2: Goto T Code : CMOD and provide appropriate Project and choose components and click on display.
    Step3: Double click on exit "EXIT_SAPLRRS0_001" you can see include "ZXRSRU01", double click on include.
    Step4: Sample code to populate.
    WHEN 'CUR_DATE'.
    Data : l_p_range_SSS TYPE rrrangesid.
    IF I_STEP = 1.
    l_p_range_SSS-Low = sy-datum.
    l_p_range_SSS-Sign = 'I'.
    l_p_range_SSS-Opt = 'EQ'.
    APPEND l_p_range_SSS TO e_t_range.
    Endif.
    The following values are valid for I_STEP:
    · I_STEP = 1
    Call up takes place directly before variable entry
    · I_STEP = 2
    Call up takes place directly after variable entry. This step is only started up when the same variable could not be filled at I_STEP=1.
    · I_STEP = 3
    In this call up, you can check the values of the variables. Triggering an exception (RAISE) causes the variable screen to appear once more. Afterwards, I_STEP=2 is also called up again.
    · I_STEP = 0
    The enhancement is not called from the variable screen. The call up can come from the authorization check or from the Monitor.
    Also, refer this link..
    http://help.sap.com/saphelp_bw320/helpdata/en/1d/ca10d858c2e949ba4a152c44f8128a/content.htm
    Cheers,
    Allen

  • ABAP code for Date Range

    Hi All,
    I have requirement to write code for date range.
    Characterstic = Run-Out Date, it was created reference to 0Date.
    Requirement is data should load depends on Run-Out Date 7 days old and 14 days future.
    Logic is -7 days old >= Run_out date <= 14 days future.
    please let me know how I need to proceed with ABAP code for this requirement.
    Thanks.
    Please do not ask for ABAP code here. Its not a training forum
    Edited by: Pravender on Aug 18, 2011 1:46 AM

    >
    Sree vignesh wrote:
    > Hi,
    > In the select option we have a field month range as
    > SELECT-OPTION : FROM 01.2007       TO  01.2009 " Let say Ur Selection option is SO_MONTH
    > but now i need to add the DMBTR field considering the month range in the SELECT OPTION i.e., only FROM 01.2007 TO  01.2009 i mean without 2006 data.
    >
    > LOOP AT LT_DATA WHERE month in SO_MONTH. " Here add a Where condition
    >     ls_output-matnr = lt_data-belnr.
    >     ls_output-werks = lt_data-bukrs.
    >     ls_output-lgort = lt_data-dmbtr.   
    >
    >     COLLECT  ls_output INTO lt_output .
    >
    >   ENDLOOP.
    >
    > please help with code .
    >
    > thanks in advance.
    Regards,
    Suneel G

  • I Need Java code for following Algorithm

    * I Need Java code for following algorithm. Kindly any one help.
    1. Read the contents (ideas and its corresponding scores) from two files named as 'a' and 'b'.
    2. Stored the file 'a' contents in array a[].
    3. Stored the file 'b' contents in array b[].
    4. compare both files like
    if(a.equals(b[j])
    Writing the common idea and add the score from file 'a' and 'b'.
    else
    write the uncommon idea and its score..
    For example :
    Form Agents.txt
    action,65
    architecture,85
    eco-,15
    essay,30
    form,85
    form,85
    link,40
    tangent,25
    Form Agents1.txt
    Black holes,69
    essay,78
    Herewith i have above mentioned two files named as Form Agents and Form Agents1.
    Form Agents has eight fields
    Form Agents1 has two fields
    --> 'essay' is common in two files, so store the idea 'essay' and add the score from Form Agents score is '30' and Form Agents1 has 78 (essay 108).
    Finally it stores idea in another file with uncommon fields also.
    Please help us.

    We have tried with following code.
    But we cant add the scores.
    For Example:
    Form Agents.txt --> has "essay,30"
    Form Agents1.txt --> has "essay,78"
    Result is: essay,108
    Finally it stores idea in another file with uncommon fields also.
    So Any one pls correct the following code.
    try
    DataOutputStream o1=new DataOutputStream(new
    FileOutputStream("C:\\Interfaces\\interfaces\\temp\\BlackBoard\\My Design
    World\\Project\\Material\\art\\System Agents\\Form Agents\\CandidateResponses\\Form
    Agents.txt"));
    //Reading the contents of the files
    BufferedReader br= new BufferedReader(new InputStreamReader(new
    FileInputStream("C:\\Interfaces\\interfaces\\temp\\BlackBoard\\My Design
    World\\Project\\Material\\art\\System Agents\\Form Agents\\Ideological\\Form
    Agents.txt")));
    BufferedReader br1= new BufferedReader(new InputStreamReader(new
    FileInputStream("C:\\Interfaces\\interfaces\\temp\\BlackBoard\\My Design
    World\\Project\\Material\\art\\System Agents\\Form Agents\\Related\\Form
    Agents.txt")));
    while((s=br.readLine())!=null)
    s1+=s+"\n";
    while((s2=br1.readLine())!=null)
    s3+=s2+"\n";
    int numTokens = 0;
    StringTokenizer st = new StringTokenizer(s1);
    String[] a = new String[10000];
    String[] br_n=new String[10000];
    int i=0;
    while (st.hasMoreTokens())
    s2 = st.nextToken();
    a=s2.substring(0,s2.length()-3);
    s6=s2.substring(s2.length()-2);
    br_n[i]=s6;
    i++;
    numTokens++;
    int numTokens1 = 0;
    StringTokenizer st1 = new StringTokenizer (s3);
    String[] b = new String[10000];
    String[] br1_n=new String[1000];
    int j=0;
    while (st1.hasMoreTokens())
    s4 = st1.nextToken();
    b[j]=s4.substring(0,s4.length()-3);
    s7=s4.substring(s4.length()-2);
    br1_n[j]=s7;
    j++;
    numTokens1++;
    int x=0;
    for(int m=0;m<a.length;m++)
    for(int n=0;n<b.length;n++)
    if(a[m].equalsIgnoreCase(b[n])){
    int sc=Integer.parseInt(br_n[m]);
         int sc1=Integer.parseInt(br1_n[n]);
    int score=sc+sc1;
         o.writeBytes(a[m]+","+score+"\n");
    break;
    else
    o.writeBytes(a[m]+","+br_n[m]+"\n");
    break;
    }catch(Exception e){}

  • I need php code for copy paste our all histroy of browser in a text page.

    I need php code for copy paste our all histroy of browser in a text page can any one send me the code please.

    You can use an application like GarageSale for doing this....
    http://www.macupdate.com/info.php/id/16035/garagesale

  • Need a code for finding prime no.s from 0 to 100.

    Hi,
    i need a code for finding prime no.s from 0 to 100.
    Please help me out.
    Regards,
    Santosh Kotra.

    hai santosh,
    here is an example program to find the prime number...........
    EXAMPLE:
    DATA: BEGIN OF primes OCCURS 0,
            number TYPE i,
            exp    TYPE i,
          END OF primes.
    DATA: w_mult TYPE i,
          w_limi TYPE i,
          w_prem TYPE i.
    DATA: w_outp TYPE text132.
    DATA: w_rtime TYPE i,
          w_stime TYPE p DECIMALS 3.
    DEFINE add_part.
      sy-fdpos = strlen( &1 ) + 1.
      &1+sy-fdpos(*) = &2.
      condense &1.
    END-OF-DEFINITION.
    PARAMETERS: p_numb TYPE i,                "number to check
                p_fact TYPE c AS CHECKBOX,    "display components
                p_nbpr TYPE c AS CHECKBOX.    "nb of primes
    START-OF-SELECTION.
      GET RUN TIME FIELD w_rtime.
      IF p_nbpr IS INITIAL OR p_numb LE 12000.
        PERFORM eratostene USING p_numb.
        add_part w_outp p_numb.
        READ TABLE primes WITH KEY number = p_numb.
        IF sy-subrc = 0.
          add_part w_outp 'is prime'.
        ELSE.
          IF p_fact IS INITIAL.
            add_part w_outp 'is not prime'.
          ELSE.
            add_part w_outp '='.
            w_limi = p_numb.
            LOOP AT primes WHERE exp GT 0.
              CHECK primes-number LE w_limi.
              IF w_prem GT 0.
                add_part w_outp '*'.
              ENDIF.
              IF primes-exp GT 1.
                add_part w_outp '('.
                add_part w_outp primes-number.
                add_part w_outp '^'.
                add_part w_outp primes-exp.
                add_part w_outp ')'.
              ELSE.
                add_part w_outp primes-number.
              ENDIF.
              w_limi = w_limi / ( primes-number ** primes-exp ).
              IF w_limi = 1.
                EXIT.
              ENDIF.
              w_prem = 1.
            ENDLOOP.
          ENDIF.
        ENDIF.
        WRITE: / w_outp.
        IF NOT p_nbpr IS INITIAL.
          DESCRIBE TABLE primes LINES sy-tmaxl.
          CLEAR: w_outp.
          add_part w_outp 'Number of primes:'.
          add_part w_outp sy-tmaxl.
          WRITE: / w_outp.
          SKIP.
          LOOP AT primes.
            WRITE: / primes-number.
          ENDLOOP.
        ENDIF.
      ELSE.
        PERFORM factors.
      ENDIF.
      GET RUN TIME FIELD w_rtime.
      w_stime = w_rtime / 1000000.
      SKIP.
      CLEAR: w_outp.
      add_part w_outp 'Calculation time:'.
      add_part w_outp w_stime.
      WRITE: / w_outp.
          FORM eratostene                                               *
    FORM eratostene USING in_number TYPE i.
      DATA: BEGIN OF no_primes OCCURS 0,
              number TYPE i,
            END OF no_primes.
      DATA: cnum TYPE i,
            dnum TYPE i,
            limi TYPE i,
            mult TYPE i,
            puis TYPE i,
            cmod TYPE i.
      IF NOT ( p_fact IS INITIAL AND p_nbpr IS INITIAL ).
        limi = in_number.
      ELSE.
        limi = sqrt( in_number ).
      ENDIF.
      cnum = 2.
      WHILE cnum LE limi.
        READ TABLE no_primes WITH KEY number = cnum.
        IF sy-subrc NE 0.
          primes-number = cnum.
          mult = 2.
          puis = 1.
          dnum = mult * cnum.
          WHILE dnum LE in_number.
            READ TABLE no_primes WITH KEY number = dnum.
            IF sy-subrc NE 0.
              no_primes-number = dnum.
              APPEND no_primes.
            ENDIF.
            IF NOT p_fact IS INITIAL.
              cmod = dnum MOD ( cnum ** puis ).
              IF cmod = 0.
                cmod = in_number MOD ( cnum ** puis ).
                IF cmod = 0.
                  primes-exp = puis.
                  puis = puis + 1.
                ENDIF.
              ENDIF.
            ENDIF.
            mult = mult + 1.
            dnum = mult * cnum.
          ENDWHILE.
          APPEND primes.
          CLEAR: primes.
        ENDIF.
        cnum = cnum + 1.
      ENDWHILE.
    ENDFORM.
          FORM factors                                                  *
    FORM factors.
      DATA: ex_factors TYPE string,
            mod        TYPE i,
            still      TYPE f,
            factor     TYPE i,
            exponent   TYPE i,
            square     TYPE f,
            fac_string TYPE text40,
            exp_string TYPE text40.
      IF p_numb LE 3.
        ex_factors = p_numb.
      ELSE.
        factor = 2.
        still  = p_numb.
        DO.
          CLEAR: exponent.
          mod = still MOD factor.
          WHILE mod = 0.
            exponent = exponent + 1.
            still    = still div factor.
            mod      = still MOD factor.
          ENDWHILE.
          IF exponent EQ 1.
            fac_string = factor.
            CONCATENATE ex_factors '*'  fac_string
                                   INTO ex_factors
                           SEPARATED BY space.
            CONDENSE ex_factors.
          ELSEIF exponent GT 1.
            fac_string = factor.
            exp_string = exponent.
            CONCATENATE ex_factors '* (' fac_string
                                   '^'   exp_string ')'
                                   INTO  ex_factors
                           SEPARATED BY space.
            CONDENSE ex_factors.
          ENDIF.
          factor = factor + 1.
          square = factor ** 2.
          IF square GT still.
            EXIT.
          ENDIF.
        ENDDO.
        IF still GT 1.
          CATCH SYSTEM-EXCEPTIONS convt_overflow = 1.
            fac_string = factor = still.
          ENDCATCH.
          IF sy-subrc NE 0.
            fac_string = still.
          ENDIF.
          CONCATENATE ex_factors '*' fac_string
                                INTO ex_factors
                        SEPARATED BY space.
          CONDENSE ex_factors.
        ENDIF.
        SHIFT ex_factors UP TO '*'.
        SHIFT ex_factors BY 2 PLACES.
      ENDIF.
      WRITE: / p_numb RIGHT-JUSTIFIED.
      IF ex_factors CA '*^'.
        WRITE: '=', ex_factors.
      ELSE.
        WRITE: 'is prime'.
      ENDIF.
    ENDFORM.
    HOPE THIS WILL BE HELPFULL.
    regards
    praba.

Maybe you are looking for