How to read from an internal table with multiple key fields.

Hi All!!
I want to read from an internal table having keys as k1,k2,k3.
How can I use read statement to read an entry having this as the key fields.
Thanks in adavance..
Prabhas Jha

hi there
use:
sort itab by K1 K2 K3.
read table itab into wa with key K1 = value 1
                                              K2 = value2
                                              K3 = value 3
                                               BINARY SEARCH.
where:
itab is ur internal table
wa is the work area with the same line type as the itab
cheers
shivika

Similar Messages

  • Search help with multiple key fields

    Hi,
    I want to dispaly search help on a field from a internal table have multiple key fields i.e combination of fld1 + fld2 +fld3 makes one single row. Therfore can any one tell me how to return that single row , because if I am using function F4IF_INT_TABLE_VALUE_REQUEST I get only one return field that I select by which I can't get the actual line that I have selected as there may be more that one line for that field.
    please suggest any way through programming not by creating any search help through se11.
    thanks

    Hi,
    Use select query to select the fields & display them.
    In the following code i've selected only a single field in select query but u can do it for more than 1 & proceed similarly.i've tried it before using this code.
    SELECT WERKS
             NAME1
             FROM T001W
             INTO TABLE ITEMP
             WHERE IWERK = 'M011'.
      CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
           EXPORTING
                  DDIC_STRUCTURE   = ' '
                RETFIELD         = 'WERKS'
                  PVALKEY          = ' '
                  DYNPPROG         = ' '
                  DYNPNR           = ' '
                  DYNPROFIELD      = ' '
                  STEPL            = 0
                  WINDOW_TITLE     =
                  VALUE            = ' '
               VALUE_ORG        = 'S'
                  MULTIPLE_CHOICE  = ' '
                  DISPLAY          = ' '
                  CALLBACK_PROGRAM = ' '
                  CALLBACK_FORM    = ' '
           TABLES
                VALUE_TAB        = ITEMP
                  FIELD_TAB        =
               RETURN_TAB       = T_RETURN
                  DYNPFLD_MAPPING  =
             EXCEPTIONS
                  PARAMETER_ERROR  = 1
                  NO_VALUES_FOUND  = 2
                  OTHERS           = 3
      IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      S_WERK-LOW = T_RETURN-FIELDVAL.
    Hope this helps.
    Reward if helpful.
    Regards,
    Sipra

  • Get the Common from Two Internal Tables with same structure

    Hi ,
    I need to get the Common data from Two Internal Tables with same structure with using the looping method.
    For e.g.
    I have two internal table say ITAB1 and ITAB2.
    ITAB1 has values A,B,C,D,E,F
    ITAB2 has values A,H,B,Y,O
    Output at runtime should be : A,B

    Hi mohit,
    1. If u want to compare all fields,
       for matching purpose,
       then we can do like this.
    2.
    report abc.
    data : a like t001 occurs 0 with header line.
    data : b like t001 occurs 0 with header line.
    loop at a.
      LOOP AT B.
        IF A = B.
          WRITE :/ 'SAME'.
        ENDIF.
      endloop.
    ENDLOOP.
    regards,
    amit m.

  • How to fill internal table with selection screen field.

    Hi all,
    i am new to sap . pls tell me how to fill internal table with selection screen field.

    Hi,
    Please see the example below:-
    I have used both select-options and parameter on the selection-screen.
    Understand the same.
    * type declaration
    TYPES: BEGIN OF t_matnr,
            matnr TYPE matnr,
           END OF t_matnr,
           BEGIN OF t_vbeln,
             vbeln TYPE vbeln,
           END OF t_vbeln.
    * internal table declaration
    DATA : it_mara  TYPE STANDARD TABLE OF t_matnr,
           it_vbeln TYPE STANDARD TABLE OF t_vbeln.
    * workarea declaration
    DATA : wa_mara  TYPE t_matnr,
           wa_vbeln TYPE t_vbeln.
    * selection-screen field
    SELECTION-SCREEN: BEGIN OF BLOCK b1.
    PARAMETERS : p_matnr TYPE matnr.
    SELECT-OPTIONS : s_vbeln FOR wa_vbeln-vbeln.
    SELECTION-SCREEN: END OF BLOCK b1.
    START-OF-SELECTION.
    * I am adding parameter value to my internal table
      wa_mara-matnr = p_matnr.
      APPEND wa_mara TO it_mara.
    * I am adding select-options value to an internal table
      LOOP AT s_vbeln.
        wa_vbeln-vbeln =  s_vbeln-low.
        APPEND  wa_vbeln TO  it_vbeln.
      ENDLOOP.
    Regards,
    Ankur Parab

  • How to use Read table with out key fields

    Hi Experts,
    I need to retrieve the 2 internal tables data into single table.
    I have 3 common fields between the 2 tables but I don't have the Key fields. Then how to use the read table in this.
    Thanks in Advance.
    Edited by: satish4abap on Mar 10, 2010 9:39 AM

    Hi Satish,
    Key fields are nothing but the common fields with which you can pick the data from the second internal table.
    If you can paste your Internal table fields then we will be able to assit you better.
    However, in genral scenarios you can use it as below :
    In this scenario, we are putting data from 3 internal table to another single internal table.
    LOOP AT T_PRGEN INTO WA_PRGEN.
           WA_FINAL-GUID_PR       = WA_PRGEN-GUID_PR.
           WA_FINAL-ATTR20A       = WA_PRGEN-ATTR20A.
           WA_FINAL-ATTR05A       = WA_PRGEN-ATTR05A.
           WA_FINAL-ATTR05B       = WA_PRGEN-ATTR05B.
           WA_FINAL-ATTR05C       = WA_PRGEN-ATTR05C. " + DG1K902190
           WA_FINAL-ATTR10A       = WA_PRGEN-ATTR10A.
        READ TABLE T_V_TCAV201 INTO WA_V_TCAV201 WITH KEY ATTRV20 = WA_PRGEN-ATTR20A BINARY SEARCH.
        IF SY-SUBRC = 0.
          WA_FINAL-TEXT1   = WA_V_TCAV201-TEXT1.    "SUBID-TEXT1
        ENDIF.
        READ TABLE T_PNTPR INTO WA_PNTPR WITH KEY GUID_PR = WA_PRGEN-GUID_PR BINARY SEARCH.
        IF SY-SUBRC = 0.
           WA_FINAL-PRVSY  = WA_PNTPR-PRVSY.   "PROD NO
           WA_FINAL-GRVSY  = WA_PNTPR-GRVSY.   "LOGICAL SYS GROUP
        ENDIF.
      append wa_final to t_final.
    endloop.

  • How to create an dynamic internal table with the structure of a ddic table

    Hi all,
    I want to fill ddic-tables (which I already created) in my abap dictionary with data out of CSV-files (which are located on the CRM-Server).  The ddic tables have different amount of fields.
    I started with creating a table which contains the name of the tables and the path to the matching CSV-file.
    At the beginning I'm filling an internal table with part of this data (the name of the ddic-tables) - after that I am looping at this internal table.
    LOOP AT lt_struc ASSIGNING <lfs_struc>.
         LOOP AT lv_itab1 INTO lv_wa1 WHERE ztab_name = <lfs_struc>.
         lv_feld = lv_wa1-zdat_name.
        ENDLOOP.
        CONCATENATE 'C:\-tmp\Exportierte Tabellen\' lv_feld INTO lv_pfad.
        Do.
        OPEN DATASET lv_pfad FOR INPUT IN TEXT MODE ENCODING NON-UNICODE IGNORING CONVERSION ERRORS.
        READ DATASET lv_pfad INTO lv_rec.
        IF sy-subrc NE 0.
          EXIT.
        ENDIF.
        enddo.
        REPLACE ALL OCCURRENCES OF '"' IN lv_rec WITH ''.
        SPLIT lv_rec AT ';' INTO TABLE lt_str_values.
        INSERT into (<lfs_struc>) values lr_str_value.
        CLOSE DATASET lv_pfad.
    endloop.
    This is not the whole code, but it's working until
    SPLIT lv_rec AT ';' INTO TABLE lt_str_values.
    I want to split all the data of lv_rec into an internal table which has the structure of the current ddic-table, but I didn't find out how to do give the internal table the structure of the ddic-table. In the code I used an internal tyble type string but I should be the structure of the matching tabel.
    If I try to create an internal table by using a fiel symbol, I am told, that the data types are not matching.
    Has anyone an idea?

    Hi Mayari,
    though you were successfull with
    METHOD cl_alv_table_create=>create_dynamic_table
    I must warn you not to use it. The reason is that the number of tables created is limited, the method uses GENERATE SUBROUTINE statement and this triggers an unwanted database commit.
    If you know the DDIC structure, it is (starting with ECC6.0) much easier:
    field-symbols:
      <table> type standard table.
    data:
      lr_data type ref to data.
    Create data lr_data type table of (<DDIC structure>).
    assign lr_data->* to <table>.
    The split code can be simplified gaining speed loosing complexity not loosing functionality.
    field-symbols:<fs_s> type any.
    field-symbols:<fs_t> type any.
    SPLIT lv_rec AT ';' INTO table it_string.
    loop at it_string assigning <fs_s>.
      assign component sy-tabix of wa_string to <fs_t>.
    if sy-subrc = 0.
      <fs_t> = <fs_s>.
    endif.
    at last.
      append <fs_itwa3> to <ft_itab3>.
    endat.
    endloop.
    Though it may work as Keshav.T suggested, there is no need to do that way.     
    Regards,
    Clemens

  • Reg - Reading internal table with multiple record in a single field

    Dear Guru's,
                        i want to read a internal table with field having mutilple entries like
    read table READ TABLE LT_T2 INTO LT_T2_WA WITH KEY HKONT IN ( '0001152430', '0001152930', '0001152410' ).
    But it says comma without preceding colon (after READ?).
    please guide me.....
    thanks & Regards,
    Balaji.S

    ya this is inside the loop.
    plz check....
    loop at lt_t2 into lt_t2_wa.
    READ TABLE LT_T2 INTO LT_T2_WA WITH KEY HKONT IN ( '0001152430', '0001152930', '0001152410' ).
    endloop.
    thanks & Regards,
    Balaji.S

  • Diff Between Internal Table with Occurs 0 & Field Groups

    Hi,
    Is there really any difference between just using an internal table with an OCCURS 0 statement-- which would write the entire table to paging space-- and using field-groups? How is Field-Groups is more effective than Internal tables with occurs 0 when it comes to performance?
    Could anybody please give some information regarding above question?
    Thanks,
    Mohan.

    hi,
    occurs 0 means it wont create any extra memory. based on the records only the memory is allocated to internal tables at run time. but when an internal table is created it can hold data of type to which it is declared.
    i.e data: itab like mara occurs 0 with header line.
    can take data only from mara table
    we can also do in another way as using types keyword we can declare a standard structure and create a internal table of that type. its also not that useful as we have to change the structure depending on changes for storing data.
    for this purpose field symbols are used. field symbols can hold any data means that they can point to tables, fields, any standard or user-defined types. field symbols actually points to respective types by which we can directly access to that types using field symbols.
    filed symbols works more faster than internal tables.
    if helpful reward some points.
    with regards,
    Suresh.A

  • How to create a view on tables with different keys?

    I have to create a View on:
    Z3PVR: Transparent Table
    BSEG: Cluster Table
    CKIS: Transparent Table
    BKPF: Transparent Table
    RV61A: Structure
    T001: Transparent Table
    All the tables have different "Key Fields" and the structure has no "Key Fields". When i create the view, what do I mention in the "JOIN FIELDS" tab. and how do i create the view with the structure?
    Please advise.

    How to create a view on a Non-Transparent Tables.
    how to create view?
    HELP.. How to create a view with the tables with ALV

  • How to insert record in child table with foreign key

    Hi,
    I am using Jdeveloper 11.1.2.0. I have two master table one child table.
    How to insert and update a record in child table with foreign key ?
    I have created VO based on three EO(one eo is updatable other two eo are references) by using joined query.
    Thanks in Advance
    Edited by: 890233 on Dec 24, 2011 10:40 PM

    ... And here is the example to insert using sequenceimpl by getting the primary key of the master record and insert master and detail together.
    Re: Unable to insert a new row with a sequence generated column id
    -Arun

  • Multiple entries in a Z table with same key fields

    Hi
    I do have a ZTABLE, with 3 key fields defined earlier. It consists of around 1 lakh records. Later onwards, two of the non keyfields have been made to key fields.
    This table is being populated with records at the time of saving a ztransaction.
    But some times, the system is updating the same records, some times twice, sometimes thrice, etc. I got to know that all fields (both key fields and non-key fields) of the record are same. That is, records are being updated in to the database table n number of times may be depending of some false logic in the program.
    If I tried to enter the same using SM30, it is showing me an error message stating that the record is already existing.
    What can be the reson?

    Hi,
    It seems there is some kind of data inconsistency..try to get all the records and then delete the duplicate entries through program....Now once u r done , from now onwards there won't be any duplicate entiers.,also before updating table use filters to avoid the duplication..
    Regards,
    Nagaraj

  • Read from a internal table whose name is decided in runtime

    Dear ABAPers
    I've an internal table's name in a variable, the name is populated in runtime (user_command->ls_selfield-tabname). Now that using the name (in the variable) i need to read a row from that particular internal table (which is populated into the variable). How can i do that.
    Regards
    Prabumanoharan

    hi see the coding and do the changes accordingly...
    report ztests .
    DATA:
      o_ref TYPE REF TO data.
    FIELD-SYMBOLS:
      <lt_table> TYPE STANDARD TABLE,
      <fs>       TYPE ANY,
      <field>    TYPE ANY,
      <field1>   TYPE ANY.
    PARAMETERS:
      p_tab       TYPE tabname default 'MARA', " Table name (eg: MARA)
      p_field(20) TYPE c default 'MATNR'.      " Field name (eg: MATNR)
    START-OF-SELECTION.
      CREATE DATA o_ref TYPE TABLE OF (p_tab).
      ASSIGN p_field TO <field1>.
      ASSIGN o_ref->* TO <lt_table>.
      SELECT *
        INTO TABLE <lt_table>
        FROM (p_tab).
      LOOP AT <lt_table> ASSIGNING <fs>.
        ASSIGN COMPONENT <field1> OF STRUCTURE <fs>
                      TO <field>.
        IF sy-subrc = 0.
          WRITE:/ <field>.
        ENDIF.
      ENDLOOP.

  • How to make copies of internal table with unknown structure?

    Dis is the detailed description of a problem i have and i
    tried all i can to solve it without satisfied results.
    I want to copy an internal table of a type defined in the
    ABAP program itself, not dictionary. I have a function
    that is supposed to accept the internal table as a
    parameter of type 'any table'. The function should create
    the new internal table using the field catalog of the
    passed 'any table' and then create a new internal table
    using "create_dynamic_table" and return the DATA pointer.
    If anyone knows how it is done pls help me out.
    I would like to get the field catalog of the following
    internal table automatically by using some sap function..
    TYPES:
    BEGIN OF MYTYPE,
      NAME TYPE SOMEZTABLE-NAME,
      AGE TYPE SOMEZTABLE-AGE,
    END OF MYTYPE.
    DATA:
    IT_TABLE TYPE TABLE OF MYTABLE INITIAL SIZE 0.
    DATA:
    COPY_OF_IT_TABLE TYPE REF TO DATA.
    SELECT NAME AGE INTO TABLE IT_TABLE FROM S0MEZTABLE.
    PERFORM CREATECOPY USING IT_TABLE CHANGING COPY_OF_IT_TABLE.
    FORM CREATECOPY
      USING
        IT_TABLE <b>TYPE ANY TABLE</b>
      CHANGING
        COPY_OF_IT_TABLE TYPE REF TO DATA.
    <i>[ Here i would like to create a copy the passed
    internal table and return a reference to it. I donot want
    to refer to the same table passed. I guess the use of
    function CREATE_DYNAMIC_TABLE in the CL_ALV_TABLE_CREATE
    clss is required. ]</i>
    ENDFORM.

    Ravi,
    If all you want to do is to copy this into another table, why can't do something like this.
    TYPES:
    BEGIN OF MYTYPE,
      NAME TYPE SOMEZTABLE-NAME,
      AGE TYPE SOMEZTABLE-AGE,
    END OF MYTYPE.
    DATA:
    IT_TABLE TYPE TABLE OF MYTABLE INITIAL SIZE 0.
    DATA: COPY_OF_IT_TABLE TYPE REF TO DATA.
    SELECT NAME AGE INTO TABLE IT_TABLE FROM S0MEZTABLE.
    FIELD-SYMBOLS : <FT_COPY_TABLE> TYPE ANY TABLE.
    Call Method CL_ALV_TABLE_CREATE->CREATE_DYNAMIC_TABLE
    Exporting
    IT_FIELDCATALOG = T_FIELDCAT
    Importing
    EP_TABLE = COPY_OF_IT_TABLE
    ASSIGN COPY_OF_IT_TABLE->* TO <FT_COPY_TABLE>
    However, this is provided you already have a field catalog. Now in this case we have not created a field catalog. So, for that
    data : BEGIN OF MYTABLE OCCURS 0 WITH HEADER LINE
      NAME TYPE SOMEZTABLE-NAME,
      AGE TYPE SOMEZTABLE-AGE,
    END OF MYTABLE.
    Now, create the field catalog.
    CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
    EXPORTING
      I_BUFFER_ACTIVE              =
      I_STRUCTURE_NAME             =
      I_CLIENT_NEVER_DISPLAY       = 'X'
      I_BYPASSING_BUFFER           =
        I_INTERNAL_TABNAME           = 'MYTABLE'
      CHANGING
        CT_FIELDCAT                  = T_FIELDCAT
    EXCEPTIONS
      INCONSISTENT_INTERFACE       = 1
      PROGRAM_ERROR                = 2
      OTHERS                       = 3
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    This should create the field catalog.
    Regards,
    Ravi

  • Reading data from BSEG table with Non-key fields in where clause

    Hi All,
        I have to read data from BSEG table based on WBS element field (PROJK). As I'm not passing key fields to WHERE clause system couldnt run the select statement. Since BSEG is a cluster table I cant even create secondary index on PROJK field.
       Could you please tell me, how to improve its performance.
    Regards
    Jaker.

    SELECT bukrs
                 belnr
                 gjahr
                 shkzg
                 dmbtr
                 hkont
                 lifnr
                 matnr
                 werks
                 menge
                 meins
                 ebeln
            FROM bseg
            INTO TABLE it_bseg
            PACKAGE SIZE 10
            FOR ALL ENTRIES IN it_final
            WHERE  bukrs EQ it_final-bukrs
               AND belnr EQ it_final-belnr
               AND gjahr EQ it_final-gjahr
               AND buzei EQ it_final-buzei
               AND hkont EQ it_final-hkont
               AND werks IN s_werks.
    By using package and fetch from BSEG table. gathering all other information to a final internal table.This will reduce the hit to database.And also try to put that data in hashed internal table which is it_bseg....then definetly improve the performance.
    <REMOVED BY MODERATOR>
    Dara.
    Edited by: Alvaro Tejada Galindo on Apr 21, 2008 12:47 PM

  • How to read from a WD table to another WD table?

    Hi
    I need to read a WD table of multiple values and transfer in to different WD Table.
    I tried to get size of first table and could not move forward programmatically? Please help with some sample code.
    Thanks
    Praveen

    hi ,
      Just one clarification , Are both tables of same structure (as in fields) ??
    If yes , then you can read the context node bound to the source table using get_static_attributes_table() method
    and then bind this data(internal table) to the context of destination table.
    Thnks,
    aditya.

Maybe you are looking for