Counting of values in the internal table.

Hi experts,
             kindly give the logic.
i have 2 internal table, i_itab and itab2 and itab3. itab consists of different categorie form table "pa0233" say A,B,C.
ITAB2 consists of gender frm pa0002 say F or M. itab3 contains no.of trainees.i have requirement to see for a particular categorie say A for which how many f has belongs to ... ie. my output should get.
categorie  gender    no.of. trainees(total no. of trainees belongs to particular categorie for particular gender)
   A       -      f          -         7
   B       -       f           -        9
   A       -       m         -        16
   B       -        m         -       21
Thanks,
Priya.
Edited by: Priyadharshini Veluswamy on Sep 17, 2008 9:03 AM

Hi,
   Please find the code below I have framed it, as per my understanding of your requirement. Hope you will get valuable help to sove your problem from code below.
REPORT  Z_COMP.
data: begin of itab1 occurs 0,
      f1 type c,
      f2 type c,
      end of itab1.
data: begin of itab2 occurs 0,
      f1 type c,
      *** type c,
      end of itab2.
data: v_count1 type i,
      v_count2 type i.
data: begin of itab3 occurs 0,
      f1 type c,
      *** type c,
      count type i,
      end of itab3.
itab1-f1 = 'A'.
itab1-f2 = 'Z'.
append itab1.
clear itab1.
itab1-f1 = 'B'.
itab1-f2 = 'Z'.
append itab1.
clear itab1.
itab1-f1 = 'C'.
itab1-f2 = 'Z'.
append itab1.
clear itab1.
itab2-f1 = 'A'.
itab2-*** = 'M'.
append itab2.
clear itab2.
itab2-f1 = 'A'.
itab2-*** = 'F'.
append itab2.
clear itab2.
itab2-f1 = 'A'.
itab2-*** = 'F'.
append itab2.
clear itab2.
itab2-f1 = 'B'.
itab2-*** = 'M'.
append itab2.
clear itab2.
itab2-f1 = 'B'.
itab2-*** = 'F'.
append itab2.
clear itab2.
itab2-f1 = 'B'.
itab2-*** = 'F'.
append itab2.
clear itab2.
itab2-f1 = 'C'.
itab2-*** = 'M'.
append itab2.
clear itab2.
itab2-f1 = 'C'.
itab2-*** = 'F'.
append itab2.
clear itab2.
loop at itab1.
clear v_count1.
clear v_count2.
AT NEW F1.
loop at itab2 where f1 eq itab1-f1.
if itab2-*** = 'F'.
v_count1 = v_count1 + 1.
else.
v_count2 = v_count2 + 1.
endif.
endloop.
itab3-f1 = itab1-f1.
itab3-*** = 'F'.
itab3-count = v_count1.
append itab3.
itab3-f1 = itab1-f1.
itab3-*** = 'M'.
itab3-count = v_count2.
append itab3.
ENDAT.
ENDLOOP.
loop at itab3.
write:/ itab3-f1,
        itab3-***,
        itab3-count.
endloop.
With best wishes,
Murthy.

Similar Messages

  • 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.

  • Count of Data in the Internal Table

    I have a internal table which has a field 'X'.
    Now in this internal table i have couple of values with field 'X' as a key field.
    I want the count of the rows against the key field.
    For eg
    Row   Field 'X'
    1          A
    2          A
    3          A
    4          B
    5          B
    6          C
    Count of A = 3
    Count of B = 2
    Count of C = 1

    loop at itab into is.
    case is-f_x.
      when  'A'.
       c_a = c_a + 1.
      when 'B'.
       C_b = c_b + 1.
      when 'C'.
       c_c = c_c + 1.
    endloop.
    write /  : c_a, c_b, c_b.
    c_a, c_b,c_c are type I.

  • Removing a character in a value from the internal table

    Hi guys!
    <b>example: i_table-field = "10,20"</b>
    I want to remove " " because creating csv creates this automatically because it has a value that includes comma. I am also using comma separator for my program so if I would remove the " " before splitting the values there will also be an effect on my program... can anyone can help me with this?
    thanks in advance! good day guys!

    Hi Michael,
    In the scenario of yours, you are left with two options.
    1. Format the XLS file properly before converting it to CSV. here If you convert the quantity, currency columns to the text columns then you will not get " into CSV file.
    2. Define the quantity, currency fields in your internal table as of type char. For eg. Curr of length 18, should be defined as fields of CHAR20 (two characters for " "), then once you separate all the fields based on comma, just repalce all the occurances of " using REPLACE.
    But what I suggest is better use option 1. The decision is totally depend on the number of time you want to use the program.
    Reward points if useful.
    Regards,
    Atish

  • Changing the values in the internal table .

    Hi all,
    i am having a  internal  IT_LINEITEM
    Fields in the table IT_LINEITEM are   serialno,linenumber and  taxcode
    Value for the LINENUMBER field for the first record will be 1, for second record the line number will be 2 , for third record linenumber will be 3, for fourth record value will be 4 and for fifth record value wuii be 5 and so on..............
    TAXCODE field is optional in the table
    My requirement is that if the TAXCODE field is filled(not initial) only  in the 5th and 7th records then the linenumber values should be changed to 2 and 3 for  that  5th and 7th records
    Actually the linenumber values will be 5 and 7 for  the 5th and 7th record but i need to change the linenumber value to 2 and 3 instead of 5 an 7.
    Please help me.
    Thanks in advance
    regards
    Ajay

    Hi,
    Do u want to change only 5th and 7th record ?
    if yes then use this.
    sort itab.
    read itab with index 5 .
    if sy-subrc = 0 and taxcode is not initial.
    modify itab ------------.
    endif.
    same for record 7.
    rhea.

  • Followup Question: Removing a character in a value from the internal table

    Hi guys!
    example: i_table-field = "10,20"
    I want to remove " " because creating csv creates this automatically because it has a value that includes comma. I am also using comma separator for my program so if I would remove the " " before splitting the values there will also be an effect on my program... can anyone can help me with this?
    thanks in advance! good day guys!
    Follow-up:
    I have resolved with my problem regarding " " but I found out that splitting the file with comma splits the "10,20" which is a single value for a field.
    it was also split into two values: (before removing the " ")
    "10
    20"
    can anyone can help me with this? thanks in advance! good day guys!

    Hi Atish,
    1. Format the XLS file properly before converting it to CSV. here If you convert the quantity, currency columns to the text columns then you will not get " into CSV file.
    What do you mean convert the quantity, currency columns to the text columns? Does this mean by changing the cell format into currency? when I made this the format change other values ie: 150000000772 turned to 150,000,000,772. Which I think will also split to values:
    150
    000
    000
    772
    But converting from xls to csv really removed the " ".
    So I resolved removing the " " with your answers before.. my problem now is that in a single field value 10,20. they are also separated. I need them to be in a singe value. thanks!

  • Number of entries in the internal table for perticular field value

    hi All,
    Is this possible to get the count of records from the internal table for a perticular field value.
    currently my requirement is to get the entries from the internal table which does not have two records for perticular field value (say a = 123) whose status is active (say b = 'X').
    also suggets should use LOOP or DELETE or DESCRIBE for a internal table to ful fill this requirement.
    Thanks in advance.
    Pradeep

    Try like this..
    Create another table itab2 with same structure as itab1 & move the contents of itab1 to itab2
    ITAB2[] = ITAB1[].
    Then delete entries from itab2
    Delete itab2 whete a = '123' and b = 'X'
    Then use Describe statement to get the no of entries
    Describe table itab2 lines v_lines.
    Hope this helps...

  • Value not moved to work are of the internal table

    HI
    I have one internal table declared with occurs 2500.
    i am selecting the values from a z table into this internal table.
    now i want to move the values in the table to another internal table for download.here except one field all the other fields are moving to the new internal table.When i debugged i could see the value in the internal table but its not getting moved to work area of that internal table (or the header line).
    I could not see the value when i use itab[]-field in debugger mode instead when i use itab[1]-field i could see that field value.
    please do suggest.

    There is no need to move your data from one internal table to another with fixed structure. All you need to do is take each row's components skipping the column you don't want to download and concatenate this to some string. Then append to string table and download it. Sample:
    "let's say your column is on 3rd place in the table
    data l_row_string type string.
    data lt_string_tab type table of string.
    Loop at itab assigning <wa>.
      do.
        check sy-index ne 3. "skip this column
        assign component sy-index of structure <wa> to <comp>.
        if sy-subrc = 0.
          CONCATENATE l_row_string <comp> INTO l_row_string SEPARATED BY cl_abap_char_utilities=>horizontal_tab.
        else.
          "no more component in row
          append l_row_string to lt_string_tab.
          clear l_row_string.
          exit.     
        endif.
    enddo.
    endloop.
    Now all you need is to downlaod your lt_string_tab as your text file (extension TXT).
    Regards
    Marcin

  • Summing the internal table values

    Hi Experts,
    I have requirement in report to add the values in the internal table based on document no.
    for example
    Document no         date                         Amount                Exchange Rate
    190000012         05.04.2009                     100                                1
    190000012         05.04.2009                     200                                1
    190000012         05.04.2009                     300                                1
    190000013         05.04.2009                     100                                1
    190000013         05.04.2009                     200                                1
    190000014         05.04.2009                     100                                1
    If i use Collect or  On change statements , the exchange rate is also adding
    Document no         date                         Amount                Exchange Rate
    190000012         05.04.2009                     600                                3
    190000013         05.04.2009                     300                                2
    190000014         05.04.2009                     100                                1
    But i want to add only the amount field not the exchange rate .Please suggest me the best solutions.
    I want to display as
    Document no         date                         Amount                Exchange Rate
    190000012         05.04.2009                     600                                1
    190000013         05.04.2009                     300                                1
    190000014         05.04.2009                     100                                1
    Thanks in advance
    satish

    hi,
    check this
    Sort itab by documentno.
    Loop at itab1.
    on change of itab1-dcno.
    clear total.
    move itab1-docno to itab2-docno.
    itab2-total = itab-amont.
    move itab1-total to itab2-total.
    move itab1-date to itab2-date.
    move itab1-rate to itab2-rate.
    flag = '  '.
    append itab2.
    clear itab2.
    else.
    itab2-total = itab2-total + itab-amont.
    endon
    Endloop.
    it will work for  adjest append statement according to the out put .
    ~linganna

  • Change the Value of column of the internal table at run time

    Hello Experts,
    With the below code i am able to determine the value hold
    by internal table at run time for a sepcific column but i am not getting the way
    of how to update the internal if one of the value is changed,
      lr_desc_table ?= cl_abap_typedescr=>describe_by_data( itab  ).
      lr_desc_struc ?= lr_desc_table->get_table_line_type( ).
    loop at itab assigning <fs_data>.
        loop at lr_desc_struc->components ASSIGNING <fs_comp_wa>.
          assign component  <fs_comp_wa>-name of structure <fs_data> to <fs_field>.
          lv_excel_row = <fs_field>.
         CALL FUNCTION 'SCP_REPLACE_STRANGE_CHARS'
            EXPORTING
              INTEXT  = lv_excel_row
            IMPORTING
              OUTTEXT = lv_excel_row.
          assign lv_excel_row to <fs_field>. "this is not changing the value actually hold in internal table
        endloop.
      endloop.

    Hi,
    Resolved this issue with the code mentioned below.
    Code:
    loop at lt_export_items assigning <fs_data>.
      ls_data = <fs_data>.
        loop at lr_desc_struc->components ASSIGNING <fs_comp_wa>.
          assign component  <fs_comp_wa>-name of structure <fs_data> to <fs_field>.
          lv_excel_row = <fs_field>.
          CALL FUNCTION 'SCP_REPLACE_STRANGE_CHARS'
            EXPORTING
              INTEXT  = lv_excel_row
            IMPORTING
              OUTTEXT = lv_excel_row.
              concatenate 'ls_data-' <fs_comp_wa>-name into  lv_var.
              assign (lv_var) to <fs_var>.
              <fs_var> = lv_excel_row.
        endloop.
        modify lt_export_items from ls_data .
        clear:ls_data.
      endloop.
    Take care,
    Sanju

  • Check the range of values of an internal table with the statement IN

    Hi,
    I'd like to know how to check if the current contents of a field are in the set described by an internal table.
    I know I have to use the statement <b>IN</b>, but I don't know exactly how to define the internal table. In my case, I have a single field (<i>tipo_doc</i>) in my internal table which stores 4 different values: C, I, K, L.
    I want to use the statement <b>IN</b> as shown next:
    SELECT * FROM VBFA APPENDING CORRESPONDING FIELDS OF TABLE it_flujo_docs WHERE ( VBELN = it_total_fact-vbeln )
                          AND ( VBTYP_V <b>IN</b> itab).
    Then I'd like to know how the internal table <i>itab</i> should be defined. It should be something like this I think, but it doesn't work:
    DATA: BEGIN OF itab OCCURS 0,
            tipo_doc LIKE zpedidos-tipo_doc,
            tipo_doc-sign = 'I',
            tipo_doc-option = 'EQ',
            tipo_doc-low = C,
            tipo_doc-high = L,
        END OF it_tipo_doc_ped.
    I'd appreciate if someone could tell me the proper way to define it.
    Thanks in advance,
    Gerard

    Hi,
    Please follow this.
    RANGES R_VBTYP FOR VBFA-VBTYP_V.
    R_VBTYP-SIGN = 'I'.
    R_VBTYP-OPTION = 'EQ'.
    R_VBTYP-LOW = 'C'.
    CLEAR R_VBTYP-HIGH.
    APPEND R_VBTYP.
    Do the same for value 'I', 'K' and 'L'.
    Now in the SELECT statement replace the following
    VBTYP_V IN itab
    with
    VBTYP_V IN R_VBTYP.
    Thanks
    Vinod

  • Getting the last record from the internal table

    When we use a READ statement it always picks up the first record which fulfill its condition but in my case I want to pick up the last record that fulfills it condition
    I have a internal table like
    id     type
    N1      A
    N1      T
    N1      A
    N1      6 ----> LAST RECORD
    my code is
    read table itab wIth key id = netobjid.
    for eg if netobjid = N1 , then I want to read the last record that corresponds to N1 ie ID N1 TYPE - 6...
    How to do that?

    HI
    actually i have done same requirement like this ...
    Take  one count variable into your internal table ..you pass the number of records into cont variable for every time  u enter the loop .
    Sort the internal table with count variable descending . ( AS we cant sort the internal table with sy-tabix)
    Then use read statement with sy-index = 1 .
    USe below logic ,............
    data  :  count  type i value '0'.
    LOOP at int .
    count = count + 1 .
    endloop.
    sort int count descending .
    read int  with  index = 1 .

  • 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.

  • Totals for the internal table field in alv

    Hi Gurus,
    I have an issue in displaying the totals in alv.
    I have an internal table with the three fields like below.
    scrap_code_001 like afru-xmnga, " Scrap Reason Qty.
    scrap_code_002 like afru-xmnga, " Scrap Reason Qty.
    scrap_code_003 like afru-xmnga, " Scrap Reason Qty.
    In the output table which i am passing to the fieldcatlog is having the three above fields with values 10,3,4 respectively.
    I am looping at the internal table
    loop at gt_grund.
    gv_tabix = sy-tabix.
    i_fieldcat-no_zero = gc_x.
    i_fieldcat-do_sum = gc_x.
    perform assign_alv_qty_format.
    if gt_grund-grund is initial.
    gt_grund = 'NONE'.
    gv_text = gt_grund.
    else.
    gv_text = gt_grund-grdtx.
    endif.
    gv_tabixn = gv_tabix.
    gv_scrap_code+11(03) = gv_tabixn.
    gv_fieldname = gv_scrap_code.
    translate gv_fieldname to upper case.
    perform bild_fieldcat using
    gv_fieldname 'GT_REPORT' 'AFRU' gv_text 'QUAN' '12' ' ' .
    endif.
    endloop.
    But in the output I am getting the totals but it displays totals for all the three columns as 17,17,17 (summing 10,3,4).
    How do I display total as 10,3,4 for each column separately.
    I appreciate you help and award points for the answer

    Hi,
    Please check if value fields i_fieldcat-ref_fieldname and i_fieldcat-ref_tabname regard to numc or curr type.
    EX: i_fieldcat-ref_fieldname = 'WRBTR'
           I_fieldcat-ref_tabname = 'BSEG'.
    Regards,
    Fernando

  • 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

Maybe you are looking for