Array calculation in ABAP

hi gurus,
I have to use array for some calculations. I begin new project and have to calculate distance with using array. I searched forums but I found nothing. please help me?
thanks,

#include <stdio.h>
int main()
int m,n,mat[100][100],i,j,l;
int a,b,top,max=50000;
char k1='c';
printf("total country = ");
scanf(" %d", &n);
printf(" total direction = ");  // total road: A-C is a road B-G is another road
scanf(" %d", &m);
     for(i=1;i<=n;i++){
          for(j=1;j<=n;j++){
               mat<i>[j]=max;
for(i=1;i<=n;i++)
    mat<i><i>=0;
for(i=1;i<=m;i++)
printf("enter first country ");
scanf("%d", &a);
printf("enter second country",i);
scanf(" %d", &b);
printf("intervals of countries");
scanf("%d", &mat[a]<b>);
mat<b>[a]=mat[a]<b>;
for(l=1;l<=n;l++)
     for(i=1;i<=n;i++)
                          for(j=1;j<=n;j++)
                                    top=mat<i>[l] + mat[l][j];
                                          if(top < mat<i>[j]){
                                             mat<i>[j]=top;
while(k1 != 'q')
printf(" enter to find interval of 2 countries = ");
scanf(" %d", &a);
scanf(" %d", &b);
printf(" min interval = %d \n",mat[a]<b>);
printf(" q for quit any key for continue = ");
scanf(" %c", &k1);
intervals: 1) A-B = 600
2) A-C=50 C-F=150 F-G= 200 G-B=50 (that is A-B = 450)
3) A-D=100 D-H=200 H-G=50 G-B=50. (that is A-B = 400)
example records in my table
     A   | B    | C  | D    | F    | G | H
A | 0   | 600 | 50 | 100 | -     | -   | - 
B |600 | 0    | -   | -      | -     | 50| -
C | 50 |  -    | 0   | -      | 150| -   | -
D |100 | -    | -    | 0     | -    | -   |200
F |-     | -     |150|  -     | 0   |200|-
G |-    | 50   |-    | -      | 200| 0  |50
H |-    |-      | -    | 200 | -     | 50| 0
after program run
     A   | B     | C   | D    | F    | G    | H
A | 0    | 400 | 50  | 100 | 200 |350  | 300 
B |400 | 0     | 400| 300 | 250 | 50   | 100
C | 50  | 400 | 0    | 150 | 150 | 350 | 400
D |100 |300  | 150 | 0    | 300 | 250 |200
F |200 |250  |150  |300  | 0    | 200 |250
G |350 | 50  |350  | 250 | 200 | 0    |50
H |300 |100 | 400 | 200 | 250 | 50   | 0
I dont update my table. I just want find direction and min interval to go from A to B.
I think not hard for gurus.
thank all for help.

Similar Messages

  • Mathematical calculations in ABAP Query

    Dear gurus
    Can I perform mathematical calculations in ABAP Query?
    Kingly guide
    MK

    Hi
    You would need tables - AFPO, AUFM, MSEG, MAKTX (if you need mtl description).
    Use AFPO table to pass your FERT material number, then read the order numbers for this order.
    Now in AUFM there is an Index on AUFNR field, so you can pass all the order nos. of the FERT to this field.
    If you want to limit for a certain period, then use AUFM-BUDAT which is the posting date.
    Now add all the 261 movements for which there is no 262 movement, you can check for reversals in MSEG table. This you can do per component & display the data as per your need.
    Regards,
    Vivek
    Added
    You can get this info in COOIS report as well, by selecting List option as Documented Goods Movement & by using suitable filter options.

  • Key Figure calculation in Abap is not working correctly - Overlooping

    Hi,
    I wrote a logic to calculate the ratio of key figure but it is not working correctly
    For example I have a requirement to split 1 Product into Several new Products and also the Net Amount will be splitted to these several new products as well. The total Amount of the new product will be equivalent to the Net Amount.
    So far my Logic is splitting the product to several new products but the amount is incorrect as the calculation is over looping.
    Sample
    A PRODUCT has Net Amount 1000. And this product needs to be splitted into 3 new products. Each of this new product is assigned a ratio of 0.3, 0.2 and 0.7 respectively. total sum of the ratio is 1.
    PRODUCT1 0.3 = 1000 * 0.3 = 300
    PRODUCT2 0.2 = 1000 * 0.2 = 200
    PRODUCT3 0.7 = 1000 * 0.7 = 700
    The total amount of this new products is 1000.
    Now my logic is working this way.
    PRODUCT1 0.3 = 1000 * 0.3 = 300
    PRODUCT2 0.2 = 1000 * 0.2 * 0.3 = 60
    PRODUCT3 0.7 = 1000 * 0.2 * 0.3 * 0.7 = 42
    Only the PRODUCT1 is working correctly and there is overlooping for the remaining products
    Logic used
    DATA: t_data TYPE data_package_structure OCCURS 0 WITH HEADER LINE.
    DATA: t_newdso LIKE /bic/newdso OCCURS 0 WITH HEADER LINE.
    DATA: t_olddso LIKE /bic/olddso OCCURS 0 WITH HEADER LINE.
    DATA: amount LIKE data_package-netamount.
    DATA: zidx LIKE sy-tabix.
    REFRESH t_data.
    LOOP AT data_package.
      zidx = sy-tabix.
      MOVE-CORRESPONDING data_package TO t_data.
      REFRESH t_newdso.
      SELECT * FROM newdso INTO TABLE t_newdso WHERE prod =
      data_package-prod.
      SORT t_newdso BY prod.
    *LOOP AT T_NEWDSO.
      READ TABLE t_newdso WITH KEY prodh4 = t_data-prod.
      IF sy-subrc EQ 0.
        LOOP AT t_newdso.
          t_data-prod = t_newdso-/bic/znew_mp.
          t_data-material = t_newdso-material.
    *T_DATA-NETAMOUNT = T_DATA NETAMOUNT * T_NEWDSO-/BIC/ZSP_RATIO.*
          APPEND t_data.
        ENDLOOP.
      ELSE.
        REFRESH t_olddso.
        SELECT * FROM olddso INTO TABLE t_olddso WHERE prod =
        data_package-prod.
        SORT t_olddso BY prod.
        READ TABLE t_olddso WITH KEY prodh4 = t_data-prod.
        t_data-prod = t_olddso-prod.
        t_data-material = t_olddso-material.
        APPEND t_data.
      ENDIF.
      MODIFY data_package INDEX zidx.
    ENDLOOP.
    REFRESH data_package.
    data_package[] = t_data[].
    thanks
    Edited by: Matt on Sep 27, 2010 2:25 PM - added  tags

    Hi,
    I am not really good at debugging Abap code since I am a newbie. however  I have tried to add CLEAR T_DATA before the first loop.
    REFRESH T_DATA.
    LOOP AT DATA_PACKAGE.
    ZIDX = SY-TABIX.
    MOVE-CORRESPONDING DATA_PACKAGE TO T_DATA.
    and before the second loop and select statement and at the end of the loop.
    REFRESH T_NEWDSO.
    SELECT * FROM NEWDSO INTO table T_NEWDSO WHERE PROD =
    DATA_PACKAGE-PROD.
    SORT T_NEWDSO BY PROD.
    READ TABLE T_NEWDSO WITH KEY PROD = T_DATA-PROD.
    IF sy-subrc EQ 0.
    LOOP AT T_NEWDSO.
    but then not all data are being fetched.
    thanks
    Edited by: Bhat Vaidya on Sep 28, 2010 8:33 AM

  • Array Processing in ABAP

    Hi all,
    I am a total newbie in ABAP.
    I need to process an array in ABAP.
    If it was in .NET C#, it will be like this:
    String strArr = new String[5] { "A", "B", "C", "D", "E" };
    int index = -1;
    for (int i=0; i<strArr.length; i++)
       if (myData.equals(strArr<i>))
            index = i;
            break;
    Can someone please convert the above code into ABAP?
    Urgent. Please help. <REMOVED BY MODERATOR>
    THank you.
    Edited by: Alvaro Tejada Galindo on Feb 22, 2008 5:37 PM

    Hi,
    There is no concept of arrays in ABAP, we use internal tables to hold application data. U can use access internal tables with index.
    Read table itab index l_index this is same as u do in case of arrrays a(l_index)
    Instead use an Internal table to
    populate the values and read them ..
    say your Internal table has a field F1 ..
    itab-f1 = 10.
    append itab.
    clear itab.
    itab-f1 = 20.
    append itab.
    clear itab.
    itab-f1 = 30.
    append itab.
    clear itab.
    Now internal table has 3 values ...
    use loop ... endloop to get the values ..
    loop at itab.
    write :/ itab-f1.
    endloop.
    Also you can do this way:
    IT IS POSSIBLE TO DECLARE THE ONE -DIMENSIONAL ARRAY IN ABAP BY USING INTERNAL TABLES.
    EX.)
    DATA: BEGIN OF IT1 OCCURS 10,
    VAR1 TYPE I,
    END OF IT1.
    IT1-VAR1 = 10.
    APPEND IT1.
    IT1-VAR1 = 20.
    APPEND IT1.
    IT1-VAR1 = 30.
    APPEND IT1.
    LOOP AT IT1.
    WRITE:/ IT1-VAR1 COLOR 5.
    END LOOP.
    <REMOVED BY MODERATOR>
    Cheers,
    Chandra Sekhar.
    Edited by: Alvaro Tejada Galindo on Feb 22, 2008 5:38 PM

  • How to use mathematical calculations in abap

    Hi!
                                In my program,
                                 I declared one variable as w_h(2) type n.
    i am doing calculation as,
    w_h = 100 /60.
    its giving the o/p as 2(1.66...). but in 1.6 i want that 1 alone as my o/p.normally math function floor() is there to bring the o/p as 1. in abap how to use this floor function. or any other possible is there to get the o/p as 1.could anybody plz help me.

    define w_h  as i.
    data: w_h  type i.
    Edited by: mayank jain on Sep 8, 2009 9:42 AM

  • Array concept in abap

    I want to know concept of table(array). i want to take name of 5 student from user and display on screen.how can i increment variable.

    hi
    you use internal table to fetch the data from database and use it for further processing. this will help you decrease hitting the Database frequently and hence improve your performance.
    in ur case:
    REPORT  ZM1                                     .
    DATA: BEGIN OF ITAB OCCURS 0,  " Internal table
            NAME(30),  " Char type
          END OF ITAB.
    SELECTION-SCREEN BEGIN OF BLOCK B1.
    PARAMETER: P_NAME LIKE ITAB-NAME.
    SELECTION-SCREEN END OF BLOCK B1.
    START-OF-SELECTION.
    SELECT <field>
      FROM <table>
      INTO TABLE ITAB
      WHERE <condition>.
      IF SY-SUBRC = 0.
        LOOP AT ITAB.
          WRITE:/ ITAB-NAME.
        ENDLOOP.
      ENDIF.
    **reward if helpful
    regards,
    madhu

  • Checksum calculation in ABAP

    Hi,
    I want to do a sanity check between the raw binary data from 2 ABAP tables.
    How can I do this in ABAP?
    Does ABAP provide any checksum and hashmap algorithms? (API's for them)
    Thanks
    Wenonah

    Hi wenonah,
    1. what i understood is that u want to
       compare two internal tables having raw data.
    2. u can compare get raw/string data from tables
       into internal tables.
       after that u can simply compare it by.
      IF ITAB1[] = ITAB2[].
      This will take care of raw data as well as character
      data.
    Hope the above helps.
    regards,
    amit m.

  • Problem with array calculations

    The only problem I have now is, instead of calculating the payments at 7 years/5.35%, 15 years/5.5%, and 30 years/5.75%, it's calculating them for 7 years at 5.35%, 5.5%, and 5.75%, 15 years at 5.35%, 5.5%, and 5.75%, and so on. I don't need it to do all of that, I need the years to correspond to the correct interest rate. How can I change that? Thank you so much. Here is my new code:
    class PaymentArray {
         public static void main(String[] arguments) {
              double amount = 100000;
              int[] term = {7, 15, 30};
              double[] rate = {.0535, .055, .0575};
              for (int i = 0; i < term.length; i++) {
                   for (int j = 0; j < rate.length; j++) {
                        System.out.println("If the initial loan amount is " + amount);
                        System.out.println("and the length of the term is " + term[i] + " years");
                        System.out.println("and the monthly interest rate is " + rate[j]);
                        double payment = (amount*(rate[j]/12))/(1-(Math.pow(1/(1+(rate[j]/12)),(term*12))));
                        System.out.println("The monthly payment will be " + payment);

    Bollocks! The code tags got me!
    You don't need two loops.
    class PaymentArray {
         public static void main(String[] arguments) {
              double amount = 100000;
              int[] term = {7, 15, 30};
              double[] rate = {.0535, .055, .0575};
              for (int i = 0; i < term.length; i++) {
                        System.out.println("If the initial loan amount is " + amount);
                        System.out.println("and the length of the term is " + term[i] + " years");
                        System.out.println("and the monthly interest rate is " + rate);
                        double payment = (amount*(rate[i]/12))/(1-(Math.pow(1/(1+(rate[i]/12)),(term[i]*12))));
                        System.out.println("The monthly payment will be " + payment);

  • Carrying some calculations in ABAP

    Dear Friends,
    We are having two ztables. One table which is quantity table is hving fields Co Code, Bus Area, Item & Quantity. In this table mainly Items are of 4 types. In the other ztable which is rates table we are having fields like Year, Product 1, Product 2, Product 3, Product4 , Product 5, Product 6 in which we are maintaing rates.
    Now, we want if the Itam is like Product 1 then it should take the quantity from the table 1 for that particular combination of Co Code & Bus Area then multiply it with the unit rate given in othr table.
    Plz guide me in this in writing the code.
    Thanx
    nishu

    Hi Nishu,
    You can execute this code.
    REPORT zkun_sdntable .
    TABLES: zkun_quanttab, zkun_ratetab.
    DATA: BEGIN OF itab1 OCCURS 0.
            INCLUDE STRUCTURE zkun_quanttab.
    DATA: END OF itab1.
    DATA: BEGIN OF itab2 OCCURS 0.
            INCLUDE STRUCTURE zkun_ratetab.
    DATA: END OF itab2.
    DATA : val TYPE zkun_quanttab-my_qty,
           rate TYPE zkun_ratetab-p1.
    DATA : BEGIN OF itab3 OCCURS 0,
           value TYPE zkun_quanttab-my_qty,
           my_ccode TYPE zkun_quanttab-my_ccode,
           my_barea  TYPE zkun_quanttab-my_barea,
           my_item TYPE zkun_quanttab-my_item,
           my_year TYPE zkun_ratetab-my_year,
           END OF itab3.
    SELECT * FROM zkun_quanttab INTO TABLE itab1.
    SELECT * FROM zkun_ratetab INTO TABLE itab2.
    val = 0.
    rate = 0.
    LOOP AT itab1.
      LOOP AT itab2.
        CASE itab1-my_item.
          WHEN 'P1'.
            rate = itab2-p1.
          WHEN 'P2'.
            rate = itab2-p2.
        ENDCASE.
        val = val +  rate * itab1-my_qty.
      ENDLOOP.
      itab3-value = val.
      itab3-my_ccode = itab1-my_ccode.
      itab3-my_barea = itab1-my_barea.
      itab3-my_item = itab1-my_item.
      itab3-my_year = itab2-my_year.
      APPEND itab3.
      val = 0.
    ENDLOOP.
    LOOP AT itab3.
    WRITE : / itab3-my_ccode, itab3-my_barea, itab3-my_year , itab3-my_item,
        itab3-value.
    ENDLOOP.
    Hope this solves your query.
    Regards,
    Kunal.
    Note :
    The structure of table <b>zkun_quanttab</b> contains
    my_ccode for company code, my_barea for business area, my_item for item and my_qty for quantity.
    The structure of table <b>zkun_ratetab</b> contains
    my_year for year, p1 for product1, p2 for product2 etc.

  • Is there arrays or FOR loops in ABAP?

    Hi everyone!
    Is there an array and FOR loops in ABAP similar to the C Language?
    If there is, please give example. _
    Thanks a lot!

    Hi,
    There is no array concept in ABAP but there are field-symbols which are same as pointers in C.As for the FOR loop there is no such command in SAP/ABAP but we do have the do..while and loop...endloop commands.There is also CASE statements and if..endif commands.
    Thanks,
    Sandeep.

  • How to define an array in ABAP

    Hi experts,
       Can we define an array in ABAP. if yes then How. plz help.
    Regards.
    Vaibhav Tiwari.

    Hi,
      There are no array concept in abap, instead of array there are internal table and field strings in abap.
    Ex.
    data : begin of itab occurs 10,
              matnr like mara-matnr
              mbrsh like mara-mbrsh,
              end of itab.
    data : begin of itab,
              matnr like mara-matnr
              mbrsh like mara-mbrsh,
              end of itab.
    Regards,
    Prashant

  • Calculation of two field columns.

    Hi SDNers,
    I have three Fields COST, QUANTITY, and NET QUANTITY in my alv table , Now i want to calculate the field NET QUANTITY based on COST and QUANTITY and display it in NET QUANTITY Here QUANTITY is a editable field and the value in COST is coming from the data base, Here if i manually enter the QUANTITY and click enter then the NET QUANTITY should be updated. how can i achieve This??
    Thanks
    Harish

    Perhaps I am missing something in your requirements, but this seems really simple.  In your event handler, you just read the data from your context.  Do the calculation in ABAP setting the new results back into the context.  You can use the code wizard to help with the logic to read and write to/from the context.  The calcuation itself is really basic ABAP (var1 * var2 = var3).
    What part are you having problems with?

  • Calculations based on the values in the cube

    Hi Guys,
    I need to create a report where I need to calculate a value based on the data available in the cube and not just the data that is the output of the report.
    Is it possible for me to use the data in the table /BIC/<datatarget>00 and perform the calculation using ABAP? If so, how can I display the calculated value on the report and where do I write the code?
    THanks,
    Doniv

    Bhanu,
    But the problem in doing that is, it would still display the age for the corresponding employee in the age column. That should be displayed either.
    All I need is display is the following format
    Department    Averageage
    Dept1           40
    Dept2           50
    Overall         45
    The present format when I set the employee to "No Display" is
    Department    Averageage
    Dept1            40
    ______30
    ______50
    Dept2            50
    ______35
    ______50
    ______65
    overall          45
    *_____ means a blank row
    Thanks,
    Doniv
    Message was edited by: doniv ramuk
    Message was edited by: doniv ramuk

  • Collection in ABAP

    Hello Friends,
    Is there some kind of collection or Array concept in ABAP, Like in JAVA ( Java.util.Collection)??
    In loop I want to take values 1 by 1 and store it in some kind of collection ??
    Many thanks
    Marek

    Hi Marek
    As Suekrue stated, in ABAP the closest concept to an "array" is an "internal table". You can think of them as structured and semanticly-defined matrices. They are like database tables, but are not persistent i.e their lifetime is the programs' runtime.
    You can define an internal table in various ways.
    <u><b>e.g.</b></u>
    DATA: BEGIN OF gt_itab OCCURS 0 ,
            <colmun_1> LIKE/TYPE <data_element/variable> ,
            <colmun_2> LIKE/TYPE <data_element/variable> ,
            <colmun_n> LIKE/TYPE <data_element/variable> ,
          END OF gt_itab .
    With this data declaration, you define an internal table having n columns and several rows (row number is not indicated).
    Alternatively, you can define internal table type at data dictionary and refer to them as
    DATA gt_itab TYPE <DDIC_table_type> .
    or you can refer a structure to be the row-type of an internal table as:
    DATA gt_itab LIKE <DDIC_structure> OCCURS 0 .
    However, reaching to specific records is not done directly indicating the coordinate. You read rows to a work area and reach its field by "-" operator.
    <b><u>e.g.</u></b>
    READ TABLE gt_itab INTO gs_itab INDEX 5 . "read fifth row"
    WRITE:/ gt_itab-<column_name> .
    For more information, I strongly recommend you to inspect SAP Online Help whose address was mentioned at Sidharth's post and the book
    <a href="http://www.sap-press.com/product.cfm?account=&product=H958">"ABAP Objects — The Official Reference" A comprehensive guide to all ABAP language elements</a>
    by Horst Keller & Joachim Jacobitz
    or
    "ABAP Objects: Introduction to Programming SAP Applications" by Horst Keller, Sascha Kruger.
    *--Serdar
    Message was edited by: Serdar Simsekler

  • ABAP runtime error for 0CRM_OPPT_H and I while running RSA3

    hello Gurus,
         I'm having problems while running RSA3 transaction for these data sources.
    0CRM_OPPT_H
    0CRM_OPPT_I
    0CRM_SALES_ACT_1
    0CRM_SALES_ACT_I.
    I'm getting ABAP runtime error for these.
    This is the error:
    Runtime Error          CALL_FUNCTION_CONFLICT_TAB_TYP
    Exception              CX_SY_DYN_CALL_ILLEGAL_TYPE
    I tried finding OSS notes for these, but I didn’t succeed.
    I activated the data source from RSA5, and then I tried RSA3. That time I got “Errors occurred during extraction”.
    After that I activated delta at BWA5, then I started getting runtime error.
    Even though I activated at BWA5, I am not able to see the data sources at BWA7.
    Am I missing any thing…please guide me through this….
    Thanks
    RKR

    Thanks for your replay... All the DS and related tables are active..
    But wen I tried to re-generate the DS again... this is the warning I'm getting... Any idea why I'm getting this....
    The even-numbered length of the DEC field SAMPLE_QTY_ALLOW can lead to problems
    <b>Message no. R8569</b>
    <b>Diagnosis</b>
    You want to use the field SAMPLE_QTY_ALLOW in the extract structure for DataSource 0CRM_OPPT_I. This field has a field of type 'DEC' (or 'CURR' or 'QUAN') with an even number of characters.
    This can create problems since the length resulting from calculations in ABAP (for example, in extractors or Customer Exits for extraction) is too large to be inserted in the database later (PSA in BW), causing a short dump.
    <b>Procedure</b>
    This warning is only relevant when the maximum length of this field is exceeded during extraction, for example when the field is expanded in the Customer Exit through a calculation.
    More information and a remedy can be found in SAP Note 641744.
    When I search the OSS note, SAP suggesting to apply 883310 note.
    In my company we are using CRM 4.0 servie pak8. SAP suggsting to install service pak 11, but my client is not interested to upgrade to 11 as CRM people are working on service pak 8.
    By any chance we can use specific note which change the ABAP code to solve this problem... Please give me some suggetions...
    Thanks
    RKR

Maybe you are looking for

  • Display foreign currency valuation run

    Hi, We had executed the foreign currency valuation run (Tcode FAGL_FC_VAL) for the previous month. How can i see the display of the log/ report for that run again? I want to see if some GL were picked up for valuation or not Thanks

  • WIll cancel sql server database backup cause anything to be hurt?

    I run full backup of one big database. After 20 seconds, I click "stop action now" to cancel this backup. Will it cause anything to hurt? Want to make sure that database is still safe. Thanks

  • SOA in Custom Application Developments

    Hey All, Would nyone help out me in explaining 1> the features of SOA and 2>how are these features used in SOA. in brief i would like to know how does our custom application development satisy/utilize SOA. Hari

  • Value BLANK/SPACE not valid for cost element "Fund"

    Hi! We use funds management in our solution. It has worked fine in development but when doing the module tests we get the following error when creating a shopping cart: Value BLANK/SPACE not valid for cost element "Fund" When creating a PR in backend

  • How can i avoid EOFException?

    Dear Friends, here raf is RandomAccessFile and Record is Object my doubt is when i execute is code, it was executed. and also it throws EOFException. i know what is the problem(EOF) how can i avoid this exception ? please give corrected code.........