Read Table ITAB with key Dynamic Value = Value

Here is sample Intenral table
Columnname-C01 / C02 / C03
Value-123 / 456 /789
I would like to search value of the internal table according to dynamic value given by the code.
i.e.
read table ITAB with key <Dynamic Value> index 1.

Hi Rupesh,
Just try the following piece of code:
TYPES: BEGIN OF str,
        A TYPE C,
        B TYPE I,
        C(2) TYPE C,
       END OF STR.
DATA itab TYPE TABLE OF str WITH HEADER LINE.
itab-A = 'X'.
itab-B = '100'.
itab-C = 'YZ'.
APPEND itab.
PERFORM c_itab_read USING 'A' 'X'.
PERFORM c_itab_read USING 'B' '100'.
PERFORM c_itab_read USING 'C' 'YZ'.
FORM c_itab_read USING key TYPE ANY val TYPE ANY.
  READ TABLE itab WITH KEY (KEY) = val.
  IF SY-SUBRC IS INITIAL.
    WRITE: 'Hurray!'.
  ENDIF.
ENDFORM.
Hope this helps.
Reqard points if query answered.
Cheers,
~i1

Similar Messages

  • Read Table ITAB with key Dynamic Value index 1

    Here is sample Intenral table
    Columnname-C01 / C02 / C03
    Value-123 / 456 /789
    I would like to search value of the internal table according to dynamic value given by the code.
    i.e.
    read table ITAB with key <Dynamic Value> index 1.

    Hi,
    Apart from read, you can also use <b>SEARCH</b> statement.
    Syntax
    SEARCH
    Searches for strings.
    Syntax
    SEARCH <f>|<itab> FOR <g> [ABBREVIATED]
                              [STARTING AT <n1>]
                              [ENDING AT <n2>]
                              [AND MARK]
                              [IN BYTE MODE|IN CHARACTER MODE].
    Searches the field <f> or table <itab> for the string in the field <g>. The result is stored in SY-FDPOS. The additions let you hide intermediate characters, search from and to a particular position, and convert the found string into uppercase. In Unicode programs, you must specify whether the statement is a character or byte operation, using the IN BYTE MODE or IN CHARACTER MODE (default) additions.
    Hope this information is useful to you.
    Regards,
    Saumya

  • Read table itab with key

    Hi,
    Unfortunately i've been almost a year out of abap,so its kinda rusty, so pls bear with my question. I've to develop this upload program, which would read from file, but the catchy part is that to filter out the records by either pernr, bukrs, subty or any of the criteria simultaneously. I'm using select-options for  pernr, subty, bukrs, but the problem is how do i filter it out, what sort of logic/ algorithm should i be using, READ TABLE itab WITH KEY or a LOOP statement, could any 1 give any suggestions as to how i should be designing the logic. please advise

    Hi
    You want to upload data from a file on the basis of some criteria.
    In this case I think you need to upload all the data from the file to an internal table.
    Now the internal table contains all the data from the file.
    then filter the data from that table on the basis of PERNR, BUKRS or SUBTY.
    Like Below:
    delete ITAB where PERNR not in S_PERNR (S_PERNR is your select option).
    similarly for SUBTY or BUKRS.
    Or if you want all these 3 fields together then use OR condition.
    Like:
    delete ITAB where PERNR not in S_PERNR  OR
    delete ITAB where PERNR not in S_SUBTY OR
    delete ITAB where PERNR not in S_BUKRS.
    the above code will delete all the data from ITAB where the data doesn't match with the entries in S_PERNR, S_SUBTY and S_BUKRS.
    I hope this will work for you,
    If you didn't get it then post your code.
    Thanks
    LG

  • What is the difference between READ TABLE ITAB WITH KEY  and  TABLE KEY

    Hi Experts,
    what is the difference between
    READ TABLE <ITAB> WITH KEY <K1> = <C1>
                                                    <Kn> = <Cn> .
    and 
    READ TABLE <ITAB> WITH TABLE KEY <K1> = <C1>
                                                              <Kn> = <Cn> .
    Thanks
    Akash.

    Hi akashdeep,
    Nice question. I also tried to find out, but no much success. My opinion is that for practical purposes there is no difference.
    It may have difference in case of searching, especially sorted tables. (binary search or normal linear search).
    Case1: If our table is sorted table with defined key fields, and we give WITH TABLE KEY, then faster binary search is used.
    Case2 : If our table is sorted table with defined key fields, and we give WITH  KEY, (and no field contained in the keys), then normal linear search is used.
    regards,
    amit m.

  • READ TABLE bdcmsg WITH KEY msgtyp = 'E' msgtyp = 'A'.

    In the ECC6.0 system,the following code is showing syntax error (msgtyp should be used only once)
        READ TABLE bdcmsg WITH KEY msgtyp = 'E' msgtyp = 'A'.
    Can anyone pls give me a solution.
    Regards
    Sajid

    HI,
    you can read the table only with different keys.
    e.g.
    READ TABLE bdcmsg WITH KEY msgtyp = 'E' msgart = 'A'.
    I think you need to work with an workingarea so that you can go over more then one msgtyp.
    e.g.
    DATA: spfli_tab TYPE SORTED TABLE OF spfli
                    WITH UNIQUE KEY carrid connid,
          spfli_key LIKE LINE OF spfli_tab.
    FIELD-SYMBOLS <spfli> TYPE spfli.
    SELECT *
           FROM spfli
           INTO TABLE spfli_tab
           WHERE carrid = 'LH'.
    spfli_key-carrid = 'LH'.
    spfli_key-connid = '0400'.
    READ TABLE spfli_tab FROM spfli_key ASSIGNING <spfli>.
    IF sy-subrc = 0.
    ENDIF.
    regards
    Nicole
    Edited by: Nicole Lorenz on Mar 18, 2008 5:44 AM
    Edited by: Nicole Lorenz on Mar 18, 2008 5:45 AM

  • Read Table into WITH KEY

    Hi GURUS,
    Need your help, I wrote  the below piece of code in my report program and I DINT GET ANY DATA IN "wa_it_ekpo"???
    and there is no syntactical error when I execute the program pls help me get data into   "wa_it_ekpo"..
    LOOP AT it_lips into wa_it_lips.
    MOVE-CORRESPONDING  wa_it_lips TO wa_asnmain_ref.
    SORT it_ekpo DESCENDING by ebeln ebelp .
    READ TABLE it_ekpo  INTO wa_it_ekpo WITH KEY ebeln = wa_it_lips-vgbel  ebelp = wa_it_lips-vgpos .
    MOVE-CORRESPONDING  wa_it_ekpo TO wa_asnmain_ref.
    *APPEND wa_it_ekpo to it_ekpo.
    *MOVE-CORRESPONDING
    *CONCATENATE wa_it_lips wa_it_ekpo INTO WA_ASNMAIN_ref.
    *CLEAR wa_it_lips.
    ENDLOOP.
    Thanks,
    Dep

    I call form populate_data passing value Suppose s_vbeln = u2018180000056u2019.
    FORM populate_data USING val_vbeln.
    s_vbeln = val_vbeln.
    SELECT single likpVBELN likpTRMTYP likpLIFNR likpERNAM likp~BLDAT from likp
      into (wa_ittab1-vbeln , wa_ittab1-trmtyp, wa_ittab1-lifnr, wa_ittab1-ernam, wa_ittab1-bldat ) where vbeln = s_vbeln.
    APPEND wa_ittab1 to it_tab1.
    SELECT single LIPSWERKS LIPSVGBEL FROM lips into (wa_ittab4-werks , wa_ittab4-vgbel) where lips~vbeln = s_vbeln.
    APPEND wa_ittab4 to it_tab4.
    SELECT SINGLE NAME1 FROM T001W INTO WA_ITTAB3-NAME1T WHERE T001W~WERKS = WA_ITTAB4-WERKS.
    SELECT SINGLE BEDAT FROM EKKO INTO WA_ITTAB3-BEDAT WHERE EKKO~EBELN = WA_ITTAB4-VGBEL.
    SELECT SINGLE NAME1 FROM LFA1 INTO WA_ITTAB3-NAME1 WHERE LFA1~LIFNR = WA_ITTAB1-LIFNR.
    SELECT SINGLE ADRNR FROM EKPO INTO WA_ITTAB3-ADRNR WHERE EKPO~EBELN = WA_ITTAB4-VGBEL.
    DATA it_ekpo_unf    TYPE ekpo OCCURS 0.
    DATA wa_it_ekpo_unf TYPE ekpo.
    DATA it_ekpo        TYPE ekpo OCCURS 0.
    DATA wa_it_ekpo     TYPE ekpo.
    DATA it_lips_unf    TYPE lips OCCURS 0.
    DATA wa_it_lips_unf TYPE lips.
    DATA it_lips        TYPE lips OCCURS 0.
    DATA wa_it_lips     TYPE lips.
    SELECT VGBEL VGPOS MATNR EAN11 ARKTX LGORT  FROM lips INTO CORRESPONDING FIELDS OF TABLE it_lips_unf WHERE lips~vgbel = WA_ITTAB4-VGBEL.
    LOOP AT it_lips_unf into wa_it_lips_unf.
    SHIFT wa_it_lips_unf-vgpos LEFT DELETING LEADING '0'.
    APPEND wa_it_lips_unf to it_lips.
    ENDLOOP.
    SELECT EBELN EBELP MENGE MEINS UMREZ  FROM EKPO INTO CORRESPONDING FIELDS OF TABLE it_ekpo_unf WHERE ekpo~ebeln = WA_ITTAB4-VGBEL.
    LOOP AT it_ekpo_unf into wa_it_ekpo_unf.
    SHIFT wa_it_ekpo_unf-ebelp LEFT DELETING LEADING '0'.
    APPEND wa_it_ekpo_unf to it_ekpo.
    ENDLOOP.
    LOOP AT it_lips into wa_it_lips.
    MOVE-CORRESPONDING  wa_it_lips TO wa_asnmain_ref.
    SORT it_ekpo DESCENDING by ebeln ebelp .
    READ TABLE it_ekpo  INTO wa_it_ekpo WITH KEY ebeln = wa_it_lips-vgbel  ebelp = wa_it_lips-vgpos .
    MOVE-CORRESPONDING  wa_it_ekpo TO wa_asnmain_ref.
    ENDLOOP.

  • Error in reading table TFK056A with interest key

    While posting interest I am getting the following error "Error in reading table TFK056A with interest key". I have configured my interest keys well. Please assist.

    Hi Panashesean,
    The reason for this error could be you have in the line items an interest key (ikey) which is missing in table TFK056A. Though you have a different interest key in the master record the system will consider the line item first.
    Interest Key Documentation states:
    "If more than one interest key is defined for a line item, these interest keys are normally prioritized as follows:
    1. Interest key in line item
    2. Interest key that is defined for transactions identified as additional receivables
       An interest can depend on the operative company code in the rule for
       additional receivables.
    3. Interest key in dunning level
    4. Interest key in contract account master record"
    You need to remove the interest key in the line item for the system to use the master record ikey OR or define (ikey) in table TFK056A.
    I hope this works.
    regards,
    David

  • XML FORM  -  How to save read-only controls with a default value

    Hello everybody,
    I have a 3 xml forms, each one to create one type of news. I need to use 3 because each of this forms has their own controls. But the control which indicates the type of news (asociated with a KM Predefined Property) must be common in the 3 forms, in order to use it on searches.
    The question is, how can I include in this forms a control:
      - Visible for the user
      - With a default value defined in the control properties (each form has a different value, corresponding with the type of news)
      - Read-only mode
      - The value showed in the control must be saved in the associated KM Predefined Property when the user clicks the Save button. 
    Anyone knows how to do this?
    What control can I use?
    I was thinking of trying with text boxes, but I don't find the way to make them unwritable (Read only mode).
    It is posible using labels?
    Thanks.
    Kind regards

    Hello Jose,
    I know you responded with a question... I see it in the email, but I don't see it here!  Very odd... but in response:
    The first thing I do when I open the Edit.xsl file is do a 'find' for the name of the text field that I want to be read-only (in my test case, it's 'location').  Repeat the find until you see something like:
    [code]<!--
    field location
    -->[/code]
    Below there is where I put the new code.  Mine looks like this:
    [code]- <xsl:choose>
    - <xsl:when test="location='' and ($editmode='create')">
    - <xsl:choose>
    - <xsl:when test="./xf:ValidationError/@tagname='location'">
    - <input name="location" size="30" type="text" class="urEdfiTxtEnbl" id="field_1157467268006">
    - <xsl:attribute name="tabindex">
    - <xsl:choose>
      <xsl:when test="$accessibilitymode='true'">21</xsl:when>
      <xsl:otherwise>3792</xsl:otherwise>
      </xsl:choose>
      </xsl:attribute>
    - <xsl:attribute name="value">
      <xsl:value-of select="''" />
      </xsl:attribute>
    - <xsl:attribute name="readonly">true</xsl:attribute>
      </input>
      </xsl:when>
    - <xsl:otherwise>
    - <input name="location" size="30" type="text" tabindex="3792" class="urEdfTxtEnbl" id="field_1157467268006">
    - <xsl:attribute name="value">
      <xsl:value-of select="''" />
      </xsl:attribute>
    - <xsl:attribute name="readonly">true</xsl:attribute>
      </input>
      </xsl:otherwise>
      </xsl:choose>[/code]
    I put the <xsl:attribute name="readonly"> in both places (when test, and when not test).  I'm not entirely sure if that's necessary, but that worked for me.
    Hope this helps,
    Fallon

  • Copy table structure with default column values

    Hi....
    I created a table by copying another table structure by using below query.....
    SQL> CREATE TABLE SAMPLE_TEMP AS SELECT * FROM SAMPLE WHERE 1=2;
    But my problem is " the default column values are not copied to new table"
    Suggest a query like that it should " copy a table structure and default values on columns "
    Thanks in advance

    hi,
    One more option would be "dbms_redefinition' - it would work as per your requirement.
    refer further to documentation : http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_redefi.htm
    - Pavan Kumar N

  • How to replace a table name with an item value in report region SQL query?

    I've got a SQL query in a report region that goes like this:
    SELECT :P30_HIDDEN FROM v_dms_dataset
    GROUP BY :P30_HIDDEN
    P30_HIDDEN is populated from a textfield input. Why doesn't this work, and is there a way to achieve what I'm trying to do here? I really need the ability to dynamically generate SQL queries in this way.

    Ben - you could either:
    1. case when :P30_HIDDEN = 'COL1' then col1 else ... end
    in order to determine which column to select (only really useful if you have a small number of predetermined columns to select from), or
    2. generate the SQL dynamically.
    Set the report region to SQL Query (PL/SQL function body returning SQL query), then have something like:
    declare
    l_sql VARCHAR2(4000);
    begin
    l_sql := 'SELECT ' || :P30_HIDDEN || ' FROM v_dms_dataset
    GROUP BY ' || :P30_HIDDEN;
    return l_sql;
    exception
    etc.
    end;
    John.

  • Calling a Table type with a specified value.

    Hi Everyone,
    Please do have a look at this and help me understand.
    Inside a procedure I found a table type
            TYPE r_rates IS RECORD(
            low_rate       growth_rates.low_growth%TYPE  DEFAULT 0
           ,mid_rate       growth_rates.mid_growth%TYPE  DEFAULT 0
           ,high_rate      growth_rates.high_growth%TYPE DEFAULT 0
           ,real_rate      growth_rates.real_growth%TYPE DEFAULT 0);But some where I found this table type has been called like
    r_rates(5)What's the meaning of this? Please explain me.
    Regards,
    BS2012

    Hi Jeneesh,
    Please see the exact code. Please do have a look at the second line from the execution block.
    lr_member_record := lpt_group_data(ln_ind).member_table(pv_mbr_name);
    What does it mean lpt_group_data(ln_ind) ?
    lpt_group_data   t_group_table;
    TYPE t_group_table IS TABLE OF pck_grp_types.r_group_record INDEX BY PLS_INTEGER;
    TYPE r_group_record IS RECORD(
    group_data   st_group_string
    ,initial_data st_group_string
    ,member_table t_member_table
    ,full_reset   BOOLEAN);
    FUNCTION tonumber(pv_owner    IN sd_groups.owner%TYPE
                         ,pv_grp_name IN sd_groups.groupname%TYPE
                         ,pv_mbr_name IN sd_groups.varname%TYPE) RETURN NUMBER IS
            ln_ind   PLS_INTEGER;
            lr_member_record pck_grp_types.r_member_record;
            lv_val   VARCHAR2(40);
            lv_last  VARCHAR2(1);
            ln_sign  PLS_INTEGER := 1;
        BEGIN
            ln_ind   := f_get_grp_index(pv_owner, pv_grp_name);
            lr_member_record := lpt_group_data(ln_ind).member_table(pv_mbr_name);
            lv_val   := SUBSTR(lpt_group_data(ln_ind).group_data, lr_member_record.start_pos, lr_member_record.entry_length - 1);
            lv_last  := SUBSTR(lpt_group_data(ln_ind).group_data, lr_member_record.start_pos + lr_member_record.entry_length - 1, 1);
            IF lv_last IN ('p','q','r','s','t','u','v','w','x','y','}','J','K','L','M','N','O','P','Q','R')
            THEN
                lv_val := lv_val || translate(lv_last,'pqrstuvwxy}JKLMNOPQR','01234567890123456789');
                IF (lr_member_record.entry_type = pck_grp_types.GCV_SIGNED_NUMERIC)
                THEN
                    ln_sign := -1;
                END IF;
            ELSE
                lv_val := lv_val || translate(lv_last,'{ABCDEFGHI','0123456789');
            END IF;
            RETURN(stp.tonumber(lv_val) * ln_sign / lr_member_record.scale);
        END tonumber;

  • Fill a table column with an empty value as the column is not existing in the data file

    Hello,
    I m new to SQL loader
    I have a table like this :
    CREATE table ListeEcriture
    ( "NUMERO" varchar2 (8 bytes)
    "dateEcr" varchar (10 byte)
    "CodeOp" Varchar2 (10 byte)
    "LibOp" varchar (32 byte)
    "CodeVal" varchar (12 byte)
    "NumCompte" varchar (8 bytes)
    This is my control file :
    load data
    infile 'C:\ReQ\FR00010303.txt'
    into table ListeEcriture
    fields terminated by ";"
    (numero, DateEcr, CodeOp, libOp, CodeVal "FR00010303", NumCompte)
    The problem is thataslo if possible to ignore the file header it would be really great

    You might be after SQL*Loader Control File Reference
    Check SQL*Loader Concepts for the big picture.
    Regards
    Etbin

  • Read table field with getString()

    public String[] getExportSParams(JCO.Function function, String structure,
                   String[]tablefield) {
              JCO.ParameterList export = function.getExportParameterList();
              JCO.Structure structures = export.getStructure(structure);
              String[] exportField = null;
              for (int i =0; i<tablefield.length;i++){
                   exportField<i> = structures.getString(tablefield<i>);
              return exportField;

    Bit confusing.
    Assuming that what ever you had given in your question is exactly the "copy paste" from your code...
    ?Both "tableField" and "exportField" are arrays right.  Why are you using those variables directly in places where you are supposed to use a "String".
    ?You are trying to put some string into exportField (which is an array) which is not yet initialized.
    Can you try this out -
    /* I guess, you are trying to extract the content of the structure into an array of strings and send it back */
    public String[] getExportSParams(JCO.Function function, String structure,
    String[]tablefield) {
    JCO.ParameterList export = function.getExportParameterList();
    JCO.Structure structures = export.getStructure(structure);
    String[] exportField = null;
    if(tablefield!=null && tablefield.length>0)
            exportField=new String[tablefield.length];
            for (int i =0; i<tablefield.length;i++){
            exportField<i> = structures.getString(tablefield<i>);
    return exportField;

  • Is it possible to use dynamic 'with key' conditions of 'READ itab' ??

    Hi~
    I want to try to set  'with key'  conditions dynamically..
    READ TABLE itab WITH KEY <...>.
    In this <...> phrase, the condition keys could be 2 or 3( don't know at yet this point)
    so i want to make it dynamic with importing data.
    Is it possible?
    Please help me!
    thank you in advance~

    Hey,
    You could write 2 READ statements instead of trying to write a dynamic READ statement.
    IF CONDITION FOR 2 KEYS IS MET.
    READ TABLE WITH KEY1 = (value1) KEY2 = (value2).
    ELSE.
    READ TABLE WITH KEY1 = (value1) KEY2 = (value2) KEY3 = (value3).
    ENDIF.
    ~Kiran

  • Read table with key doubt

    Hi guys!
    Please, what can i do when i use the
    Read table xxxx WITH KEY tab_key = value ASSIGNING <fs>
    statement and there is more than one entry with the specified selection criteria? How can i return the values to an internal table?
    I need to get all the entries and i don't have the full table key.
    thanks!

    Hi Fabio,
    An efficient way to do this is to have your table sorted by a specific key.  Let's say I have a table with the feild material number.
    You can do this:
    data: lv_index like sy-tabix.
    sort itab by material_number.
    ready table itab with key material_number = yournumber
    binary search.
    if sy-subrc eq 0.
      move sy-tabix to lv_index. " this holds the index of your first material record
    now we loop at the table start at that index
      loop at itab index lv_index.
    perform your processing
    if we come accross a different material number - exit the loop.
      if itab-material_number ne yournumber.
        exit.
      endif.
    endloop.
    endif.
    This way you only processes the records you are looking for.
    thanks.
    JB

Maybe you are looking for

  • Data Socket

    I am reposting this message and hope someone can help me.... I have been using Data Socket to pass information from a control computer to two remote computers. At various times throughout the day the connections, between the control computer and the

  • Date selection and date format in MSSQL

    i have to make a select transaction with a microsoft SQL db. I have to select the entry in a given range of time. So i've made my little form with the datepicker of jquery. The datetime field in the database has this output: Jan 1 2014 12:00:00:000AM

  • Getting Problem in Flat File to IDoc Scenario.

    Hi, I am facing problem which is as follows. Test Flat File Contain Data As Follow Field1,Field2,Field3 Field4,Field5,Field6 Field1,Field2,Field3 Field4,Field5,Field6 Field1,Field2,Field3 Field4,Field5,Field6 Source structure has only one segment wit

  • Spotlight search

    Does anyone know how we can get spotlight to search the web like before?

  • Screen resolution on BT Yahoo browser

    My 'Windows Internet Explorer provided by Yahoo' (i.e. BT) browser has suddenly started displaying in a larger font as if the screen resolution has changed (images are also affected). No other application on my laptop is affected. I've tried changing