To sum values in a internal table

hi
iam using below loop
   Loop at it_table.
   At end of amount.
   sum.
   endat.
   At end of field2.
   sum.
   endat.
   endloop.
my purpose is to sum all values of the table field1 and field2 and use it to display please let me know how to do it
regards
arora

Hi Arora,
SUM in control break command will hold sum of the variable you will mention with control command. If you want to add sum of two variables then add totals of each SUM varaible.
Check the below code.
V_FIELD1_SUM
V_FIELD2_SUM
V_TOTAL_SUM
Loop at it_table.
At LAST amount.
sum.
WRITE IT_TABLE-amount TO V_FIELD1_SUM.
endat.
At LAST field2.
sum.
WRITE IT_TABLE-field2 TO V_FIELD2_SUM.
endat.
endloop.
V_TOTAL_SUM = V_FIELD1_SUM + V_FIELD2_SUM.
WRITE:/ V_FIELD1_SUM,V_FIELD2_SUM,V_TOTAL_SUM
Thanks,
Vinay

Similar Messages

  • Distinct values from dynamic internal tabls

    Hi All,
    I have a dynamic internal tables like <dy_table> , i want to get distinct  values from this internal tables,
    how to do that, structure of dynamic internal tables is dynamic acc. to user conditions.
    regards,
    Anuj

    Hi Anuj
    Just try this,
    CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING
    it_fieldcatalog = tb_fields_for_it
    IMPORTING
    ep_table = gp_dyn_table.
    ASSIGN gp_dyn_table->* TO <gt_table>.
    ASSIGN LOCAL COPY OF INITIAL LINE OF <gt_table> TO <fs_table>.
    LOOP AT tb_output.
    *To assign value for serial number.
    ASSIGN COMPONENT 1 OF STRUCTURE <fs_table> TO <ls_field>.
    <ls_field> = tb_output-sno.
    UNASSIGN <ls_field>.
    *To assign value for Sales Organization.
    ASSIGN COMPONENT 2 OF STRUCTURE <fs_table> TO <ls_field>.
    <ls_field> = tb_output-vkorg.
    UNASSIGN <ls_field>.
    *To assign Rate for its respective Condition type.
    LOOP AT tb_konp WHERE knumh = tb_output-knumh.
    READ TABLE tb_fieldcat1 WITH KEY fieldname = tb_output-kschl.
    IF sy-subrc EQ 0.
    lv_count = tb_fieldcat1-col_pos.
    ASSIGN COMPONENT lv_count OF STRUCTURE <fs_table> TO <ls_field>.
    IF tb_konp-konwa EQ '%'.
    tb_konp-kbetr = tb_konp-kbetr / co_10.
    <ls_field> = tb_konp-kbetr.
    ELSE.
    <ls_field> = tb_konp-kbetr.
    ENDIF.
    ENDIF.
    ENDLOOP.
    lv_count = lv_count + 1.
    APPEND <fs_table> TO <gt_table>.
    CLEAR <fs_table>.
    ENDLOOP.
    Hope this proves helpful to you.

  • How to download values in an internal table into an excel file

    is there any fn module to download the values in an internal table into an excel file..

    hi
    the function module "GUI_DOWNLOAD"  downloads the data from
    an internal table into a file (can be xl, dat ,doc etc) .
    Plz follow the usage below ;
    Parameters : pa_pfile LIKE rlgrap-filename OBLIGATORY.
    Data : lv_filename TYPE STRING.
    lv_filename = pa_pfile.
    CALL FUNCTION 'GUI_DOWNLOAD'
       EXPORTING
       BIN_FILESIZE                  =
         FILENAME                      = lv_filename
         FILETYPE                      = 'ASC'
       APPEND                        = ' '
        WRITE_FIELD_SEPARATOR         = 'X'
       HEADER                        = '00'
       TRUNC_TRAILING_BLANKS         = ' '
       WRITE_LF                      = 'X'
       COL_SELECT                    = ' '
       COL_SELECT_MASK               = ' '
       DAT_MODE                      = ' '
       CONFIRM_OVERWRITE             = ' '
       NO_AUTH_CHECK                 = ' '
    IMPORTING
       FILELENGTH                    =
       TABLES
         DATA_TAB                      = tb_download         " table data to b downlaoded
      EXCEPTIONS
        FILE_WRITE_ERROR              = 1
        NO_BATCH                      = 2
        GUI_REFUSE_FILETRANSFER       = 3
        INVALID_TYPE                  = 4
        NO_AUTHORITY                  = 5
        UNKNOWN_ERROR                 = 6
        HEADER_NOT_ALLOWED            = 7
        SEPARATOR_NOT_ALLOWED         = 8
        FILESIZE_NOT_ALLOWED          = 9
        HEADER_TOO_LONG               = 10
        DP_ERROR_CREATE               = 11
        DP_ERROR_SEND                 = 12
        DP_ERROR_WRITE                = 13
        UNKNOWN_DP_ERROR              = 14
        ACCESS_DENIED                 = 15
        DP_OUT_OF_MEMORY              = 16
        DISK_FULL                     = 17
        DP_TIMEOUT                    = 18
        FILE_NOT_FOUND                = 19
        DATAPROVIDER_EXCEPTION        = 20
        CONTROL_FLUSH_ERROR           = 21
        OTHERS                        = 22
    IF SY-SUBRC <> 0.
          MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
           WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    Regards
    Pankaj

  • Passing '**********' to screen field value instead of internal table value

    Hi All,
    I have written BDC, in which when i pass value for second screen "Description type field"  it's passing '*************************' instead of internal table value.
    It's picking correct value for first internal table value. Could anyone please give an idea why it's happening?
    Please find the code:
    LOOP AT it_record.
    header data for BDC
       AT NEW CLASS.
        IF sy-tabix <> 1.
            perform bdc_dynpro      using 'SAPLCLMO' '7777'.
            perform bdc_field       using 'BDC_OKCODE'
                                    '=SAVE'.
            CALL TRANSACTION 'CLWM' USING bdcdata
                          MODE p_mode
                          UPDATE 'S'
                          MESSAGES INTO messtab.
            clear : bdcdata[],bdcdata.
        ENDIF.
        perform bdc_dynpro      using 'SAPLCLMO' '0200'.
        perform bdc_field       using 'BDC_CURSOR'
                                      'RMCLM-CLASS'.
        perform bdc_field       using 'BDC_OKCODE'
                                      '/00'.
        perform bdc_field       using 'RMCLM-CLASS'
                                      it_record-class.
        perform bdc_dynpro      using 'SAPLCLMO' '7777'.
        perform bdc_field       using 'BDC_OKCODE'
                                      '/00'.
        perform bdc_field       using 'BDC_CURSOR'
                                      'RMCLM-KLBEZ'.
        perform bdc_field       using 'RMCLM-KLBEZ'
                                      it_record-klbez.
        perform bdc_field       using 'RMCLM-STATU'
                                      '1'.
        perform bdc_dynpro      using 'SAPLCLMO' '7777'.
        perform bdc_field       using 'BDC_OKCODE'
                                      '=MERK'.
        perform bdc_field       using 'BDC_CURSOR'
                                      'RMCLM-KLBEZ'.
        perform bdc_field       using 'RMCLM-KLBEZ'
                                      it_record-klbez.
        perform bdc_field       using 'RMCLM-STATU'
                                      '1'.
        MOVE 1 TO IDX.
        ENDAT.
    line item data for BDC
            perform bdc_dynpro      using 'SAPLCLMO' '7777'.
            perform bdc_field       using 'BDC_OKCODE'
                                       '/00'.
            perform bdc_field       using 'BDC_CURSOR'
                                        'RMCLM-RELEV(02)'.
            CONCATENATE 'RMCLM-MERKMA(' IDX ')' INTO FNAM.
            perform bdc_field       using FNAM
                                        it_record-merkma.
            CONCATENATE 'RMCLM-RELEV(' IDX ')' INTO FNAM.
            perform bdc_field       using   FNAM
                                       it_record-relev.
            IDX = IDX + 1.
      ENDLOOP.
    Thanks,
    Ujjwal

    Hi Ujjwal
    The reason behind this is that you are using AT NEW.... ENDAT block in your coding.
    When you use AT NEW field statements, the fields in the work area after the field get converted into ********.
    Check values in your work area I_RECORD in debugging inside AT NEW statement and you will understand what I am saying.
    In your case all the fields from header line of I_RECORDS which come after field CLASS are getting converted into *******,
    hence the error.
    Try using a temporary work area, say w_record. Pass value of I_record to w_record before AT NEW statement.
    And use w_record-fields instead of I_record-fields. And your program should work.

  • Initializing values in an internal table

    hi
    how to initialize values in a internal table
    according to my requirement i need to initialize (both character and currency) values present in the internal table based on certain conditions
    vamsi

    hi
    As i understood you want to clear only selected fileds not the complet record..
    create a Field symobl the loop at the table.. inside the loop check the condtion the just clear the filed.
    example: you have itab type mara.
    then
    FIELD-SYMOBOLS <FS_WA_ITAB> TYPE MARA.
    LOOP AT ITAB ASSIGNING <FS_WA_ITAB>.
    IF X = XXX (YOUR CONDITION)
    CLEAR: <FS_WA_ITAB>-FIELD2,
                 <FS_WA_ITAB>-FIELD3. (If u want to clear only filed2 and field3)
    clear <FS_WA_ITAB>. (if you want to cleatr the complete record)
    ENDIF.
    ENDLOOP.
    Why iam suggestin the filed-symobol is.. it is direcltly work on internal table body so u no need to update the table agian
    Please Close this thread.. when u r problem is solved
    Reward if Helpful
    Regards
    Naresh Reddy K

  • How to check a field value within an Internal table

    Hi Friends,
    My requirement is:
    I have a line item of PO records, in that each line item of Plant field should not diffe with other line items. If it differs or say the records have different plant values line items, then I have to throw an error message.
    Below example for better understanding.
    lineitem Plant
    010       ABC
    020       ABC
    030       XYZ
    040       LKG
    So, my report will throw an error like "All line items must be identical'.
    How to do proceed it.Please advise.
    Thanks & Regards
    Sankar.

    Hi Sankar
    first you need to fetch all the values in one internal table from your PO.
    After that create an internal table with only plant field and move all the plan values in this table.
    let assume ITAB is a table with all the values. and ITAB1 with plant only.
    wa_itab is the work area for ITAB and wa_itab1 is WA for ITAB1.
    ITAB has all the values and ITAB1 has all the values only for plant.
    delete adjacent duplicate from itab1 compairing plant.
    loop at itab1 into wa_itab1. " this will fetch all the plant values in workarea.
    read table itab into wa_itab where wa_itab-plant = wa_itab1-plant.  " this will fetch only the values matching to the table itab1
    if su-subrc <> 0.       
    message 'plants are not similar' TYPE 'E'.
    elseif sy-subrc = 0.
    write your code*.
    endif.
    endloop.
    hope this will help you.
    Thanks
    Lalit Gupta

  • Transferring checkbox values on ALV to value in the internal table?

    Hi,
    I'm using an ALV grid (CL_GUI_ALV_GRID) to display an internal table.  I want users to be able to select one or many rows and those checked lines to be marked as X in my internal table.  I have a field, check(1), in my internal table displayed on the ALV, but when I tick one line on the ALV and debug, I don't see an X in the check field on that line in my internal table.
    I've successfully written code to select and deselect all lines and those values copy back to my internal table so why don't the single lines?
    CASE sy-ucomm.
        WHEN 'SELECT_ALL'.
    *   select all lines
          LOOP AT tbl_data INTO wa_data.
            MOVE 'X' TO wa_data-check.
            MODIFY tbl_data FROM wa_data.
          ENDLOOP.
        WHEN 'DESELECT'.
    *   deselect all lines
          LOOP AT tbl_data INTO wa_data.
            CLEAR wa_data-check.
            MODIFY tbl_data FROM wa_data.
          ENDLOOP.
    ENDCASE.
    Do I have to add some code in the PAI to transfer the values?
    Any suggestions welcome,
    Gill

    Yes, I have.
    The checkbox is appearing on the screen and is populated/cleared when I click the select/deselect buttons (this transfers the values in my internal table to the screen).  But when I just tick one line and then debug that line isn't showing as having X in the check field in my internal table.
    Somehow I need to transfer the tick values on screen to my internal table.

  • Problem in Summing the value in one internal table. Its very urgent.

    Hi Experts,
    I have 10 fields in one internal table and based on the 8th field changing, I have to sum the 3rd field.
    I am unable to use AT END OF <FIELD8>, because any of the fields from 1 to 7 are changing, then this control break statement triggering.
    Could any body tell me, how I have to do this.
    Thanks,
    bsv.

    Hi,
    I think it could be as simple as below.
    DATA: l_field8 TYPE bla bla.
    READ TABLE itab
         INTO wa_itab
         INDEX 1.
    l_field8 = wa_itab-field8.
    LOOP AT itab INTO wa_itab.
         IF l_field8 NE wa_itab-field8.
              "Do the sum here
         ENDIF.
    ENDLOOP.
    Regards,
    Teddy
    Edited by: Teddy Kurniawan on Jan 25, 2008 8:38 AM

  • Display data to edit based on fields and its value defined in internal tabl

    I need to display data in a internal table for editing in a screen.
    you have a internal table with field name , data types and its value. I need to display data in a screen ( sceen painter not in a report) row by row in vrtical format.
    The internal table's structure not fix. you can have any number of fields in the internal table.
    Can you please send me code if it is available with you or send me any senario in SAP if any ...so that i can debug to extract the code..
    have to display data vertically as below in editable format,
    for example,
    Airline
    Flight Number
    Flight date
    Flight price
    Airline Currency
    Plane Type
    Maximum capacity
    Occupied econ.
    Total
    No of fields will change.
    also F4 help needs to be attached with each field.
    I think it can be done through step loop. can anybody give sample code or tell me where to find in SAP or somewhere else?
    it will be great help to me..
    Sanjeev

    Hi
    just check out this program DEMO_DYNPRO_STEP_LOOP.

  • BRFplus: Problem updating values in an internal table in a loop expression

    Hi
    I'm looking into the loop expression type of BRFplus and I have come across a problem updating an internal table, I'm trying to create and populate the table using a loop, here is the functionality I'm trying to achieve:
    In a rule set create an internal MONTH_TBL table containing 12 rows of two columns: MONTH_NUM containing values 1 through 12 and MONTH_VAL containing an amount (initially 0,00 EUR in all 12 rows).
    After initializing the table traverse through SFLIGHT table and for each row add PRICE from the table to MONTH_VAL in the row of MONTH_TBL corresponding to the month of FLDATE field in SFLIGHT.
    The initialization of MONTH_TBL works as intended, as does the traversal of and retrieval of values from SFLIGHT. The problem however is the update of the internal table MONTH_TBL (defined as result data object for the function). I don't get an error, but the tables does not get updated, and I cannot seem to find out what the problem is. I would have attached an XML extract of the function + ruleset for information, but it dosen't seem like that is possible, I could e-mail it on request (for SAP employees with access to system QU5 the function is LOOP_TEST in application Z_KLAUS_TEST).
    I hope that this is sufficient information to understand the issue that I'm dealing with.
    best regards
    Klaus Stenbæk, KMD

    Hi Klaus,
    The Loop expression is part of NW 7.02 which is not yet released. When you experience the problem as part of a test you should have a contact at SAP for dealing with problems/errors. Usually SAP-internal messages are used for this purpose. Please clarify with your SAP contact how the model is.
    BR,
    Carsten

  • Summing fields in an Internal table

    Hello,
    I have an internal table in the following format:
    Prod Order    Material    Req Qty   Used Qty  
    A1                  M1           2              2
    A1                  M2           1              0
    A2                  M3           3              3
    A3                  M1           4              0
    I need to find out the material usage i.e. the no. of production orders the material was used in along with the sum of the required qty and used qty.
    In the example above, the results will be
    Material     Req Qty    Used Qty    PO count
    M1              6                2                2
    M2              1                0                1
    M3              3                3                1
    I tried the following code:
      SORT mat_comp_list_tmp BY matnr.
      LOOP AT mat_comp_list_tmp INTO wa_comp_list_tmp.
    Store the work area.
        wa_comp_list_final = wa_comp_list_tmp.
        AT END OF matnr.
          SUM.
    Move the quantity.
          wa_comp_list_final-req_qty = wa_comp_list_tmp-req_qty.
          wa_comp_list_final-used_qty = wa_comp_list_tmp-used_qty.
          wa_comp_list_final-cnt_aufnr = sy-dbcnt.
          MODIFY mat_comp_list_tmp FROM wa_comp_list_final.
        ENDAT.
      ENDLOOP.
    But this gives me a PO count per material per Prod. Order. This is not desired.
    Is there any other way to acheive this. Any help will be greatly appreciated.
    Thanks,
    Rugmani

    Hi .. I try this.
    DATA: l_cont TYPE i,
               itab TYPE mat_comp_list_tmp OCCURS 0 WITH HEADER LINE.
    SORT mat_comp_list_tmp BY matnr.
    LOOP AT mat_comp_list_tmp INTO wa_comp_list_tmp.
      AT NET matnr.
        CLEAR: l_cont, itab.
      ENDAT.
      ADD 1 TO l_cont.
      ADD wa_comp_list_tmp-req_qty TO itab-req_qty.
      ADD wa_comp_list_tmp-used_qty TO itab-used_qty.
      AT END OF matnr.
        itab_cnt_aufnr = l_cont.
        APPEND itab.
      ENDAT.
    ENDLOOP.
    PD: itab must have matnr as first field
    Thanks and Regards.
    David Carballido

  • How to search for a field and its value in an internal table

    Hi,
    I want to search for a field(which i dont know whether it exists or not) in an internal table and on finding that field, I have to update the value of that field. How do I do it? I think its similar to how SEARCH works but i wanted to know the internal table eqivalent of it.

    Hi Sujay,
    this code will help ful to u, just gi through it,
    TABLES : KNA1,VBAK,VBAP.
    ***********INTERNAL TABLE DECLARATIONS****************
    DATA : IT_KNA1 TYPE TABLE OF KNA1,
           WA_KNA1 TYPE KNA1.
    DATA : IT_VBAK TYPE TABLE OF VBAK,
           WA_VBAK TYPE VBAK.
    DATA : IT_VBAP TYPE TABLE OF VBAP,
           WA_VBAP TYPE VBAP.
    START-OF-SELECTION.
      SELECT * FROM KNA1
      INTO TABLE IT_KNA1
      WHERE KUNNR = P_CUST.
      IF NOT IT_KNA1 IS INITIAL.
        SELECT * FROM VBAK
        INTO TABLE IT_VBAK
        FOR ALL ENTRIES IN IT_KNA1
        WHERE KUNNR = IT_KNA1-KUNNR.
        IF NOT IT_VBAK IS INITIAL.
          SELECT * FROM VBAP
          INTO TABLE IT_VBAP
          FOR ALL ENTRIES IN IT_VBAK
          WHERE VBELN = IT_VBAK-VBELN.
        ELSE.
          WRITE : / 'Customer',P_CUST,'does not exist ......'.
        ENDIF.
      ELSE.
        WRITE: / 'sales order does not exist for',P_CUST.
      ENDIF.
    Rewards points plz if useful
    Ganesh.

  • How to Fill values in BAPI internal table ?

    I am creating sales order from ABAP Dynpro , all the values are getting passed to bapi except those in internal table, it gives lead selection error and whn i change the cardinality of the Node to 1.1 to shows the page but whenever i create the SO it gives WRONG_DATA error . I debugged it and found the data in the internal table for material is not getting passed.

    Hi Jasjit,
    Could you be a bit more clear about the issue you are facing.
    Try using the cardinality 0:n for node that holds the data that you are passing as internal table to bapi.
    Regards,
    Sravan Varagani

  • SET_TABLE_FOR_DISPLAY - Edited value from dynamic internal table need to be captured

    Hi all,
    I have created  2 tabstrip screns which contain ALV GRID DISPLAY  in a container with dynamic internal table and editable columns .I want to capture the edited value from this ALV GRID display.I have used SET_TABLE_FOR_DISPLAY  and for this dynamc internal table is passed which is Field symbol and editable columns have to be captured for further updation into another ztable.
    When i used check_changed_data  i am getting dump as field symbol not assigned.
    Below is the code :  How can i get edited column value from below code
    call method alv_list->set_table_for_first_display
        exporting
                is_layout                     = gs_layout
        changing
          it_outtab                     = <fs_dynamic_table>
          it_fieldcatalog               = it_fieldcat[]
        exceptions
          invalid_parameter_combination = 1
          program_error                 = 2
          too_many_lines                = 3
          others                        = 4.
      if sy-subrc <> 0.
    * Implement suitable error handling here
      endif.
    Kindly help me to solve this.
    With Thanks,
    Dina.

    please provide more info about the dump to try to help you
    as max said, it could be because the field symbol is not global and if its global maybe you are not refering well to the column
    i assume that you are using "ASSIGN COMPONENT comp OF STRUCTURE struc TO <fs>" to capture the value changed
    validate always the sy-subrc after the assignment.
    but the check changed data have parameters that have the old and new values
    please provide more info...
    Regards

  • Replace single values in a internal table

    Hi all,
    I have two internal tables.
    In the first table (itab) I have some values which I have to "decode" using the second table (itabtext).
    This means that I have to pick every line and replace in the itab a value like "01" with "text for 01" from itabtext.
    In the itabtext "01" is the key for  "text for 01".
    What is the best way to handle this?
    Thanks a lot,
    Fabian

    Thanks for your answer but I still have the problem. The tables (two texttables instead of one what I wrote in the first message) are the following:
    DATA: BEGIN OF lt_proclocktexts OCCURS 0.
    DATA: lockprocid(2) TYPE c,
          text(40) TYPE c.
    DATA: END OF lt_proclocktexts.
    DATA: BEGIN OF lt_lockreastexts OCCURS 0.
    DATA: lockprocid(2) TYPE c,
          lockreason(2) TYPE c,
          text(40) TYPE c.
    DATA: END OF lt_lockreastexts.
    The table where I want to replace fields are the following:
    DATA: BEGIN OF lt_proclocks OCCURS 0.
    DATA: mandt type MANDT,
          lockreason(40) TYPE c,
          lockprocid(40) TYPE c,
          GPART type GPART_KK,
          LOOBJ type LOOBJ_KK.
    DATA: END OF lt_proclocks.
    When lt_proclocks-lockprocid similar to a lt_proclocktexts-lockprocid the lt_proclocks-lockprocid should be replaced by the lt_proclocktexts-text.
    When lt_proclocks-lockreason AND lt_proclocks-lockprocid is similar to a combination in the lt_lockreastexts the ID in field lt_proclocks-lockreason should be also replaced (additionally to the lt_proclocks-lockprocid field).
    Thanks,
    Fabian

Maybe you are looking for