Dynamic access to the fields of an internal table

Hi,
Currently i'm having 10 fields in 1 internal table, and i need to validate this 10 fields but i dont like have too many "if and endif" statement. Is there any option to write an dynamic code.
Example
Data: begin of table,
           field1 type c,
           field2 type c,
           field3 type c,
           field4 type c,
           field10 type c,
         end of table.
Let say i want to fill field1 with 1, field2 with 2,........................... field10 with 10.
So instead of using this code
table-field1 = '1'.
table-field2 = '2'.
table-field3 = '3'.
table-field10 = '10'.
Can i do something dynamic like this
DO 10 times.
Dynamic coding, any idea ?
ENDDO.
<Modified the subject line>
Edited by: Suhas Saha on Jul 12, 2011 4:27 PM

Hi,
Sorry may my question is not detail enough. I would like to read the field from the internal table dynamically.
Data: begin of table,
field1 type c,
field2 type c,
field3 type c,
field4 type c,
field10 type c,
end of table.
Let say i want to fill field1 with 1, field2 with 2,........................... field10 with 10.
So instead of using this code
table-field1 = '1'.
table-field2 = '2'.
table-field3 = '3'.
table-field10 = '10'.
IF table-field1 < 0,
endif.
IF table-field2 < 0,
endif.
IF table-field3 < 0,
endif.
         |
IF table-field10 < 0,
endif.
Can i do something dynamic like this
DO 10 times.
Dynamic coding, any idea ?
ENDDO.

Similar Messages

  • Difference between the Field Group  and Internal Table.

    Hi all,
    Can anybody tell me the difference between the Field group and Internal table and when they will used?
    Thanks,
    Sriram.

    Hi
    Internal Tables: They are used to store record type data in tabular form temporarily in ABAP programming. Or we can say, it stores multiple lines of records for temporary use in ABAP programming.
    A field group is a user-defined grouping of characteristics and basic key figures from the EC-EIS or EC-BP field catalog.
    Use
    The field catalog contains the fields that are used in the aspects. As the number of fields grows, the field catalog becomes very large and unclear. To simplify maintenance of the aspects, you can group fields in a field group. You can group the fields as you wish, for example, by subject area or responsibility area. A field may be included in several field groups.
    When maintaining the data structure of an aspect, you can select the field group that contains the relevant characteristics and basic key figures. This way you limit the number of fields offered.
    Regards
    Ashish

  • Moving the fields to final internal table

    hi experts,
       i have a single field in an internal table and i want to move it to final internal table.
    i tried this code but its not working.
      IF NOT it_ymmessr IS INITIAL.
        LOOP AT it_ymmessr into it_final..
          move it_ymmessr-srvpos to it_final-srvpos.
        ENDLOOP.
      ENDIF.
    there is dat in the it_ymmessr.
    i have five to six similar internal tables with 1 to 3 records and i have to move them to final internal table.
    regards,
    vinay

    Hi,
    IF NOT it_ymmessr IS INITIAL.
    LOOP AT it_ymmessr into it_final..
    <b>Have one more firld which is the common field for both the tables into it_ymmessr so that u can fill the record correctly.</b>
    READ TABLE it_ymmessr WITH key XXXX = it_final-XXXX.
    IF sy-subrc = 0.
    it_final-srvpos = it_ymmessr-srvpos.
    <b>MODIFY it_final.</b>
    ENDIF.
    CLAER it_final.
    ENDLOOP.
    ENDIF.

  • Appending All the fields of one internal table to other

    Hi,
    while running a FM I get three internal tables, my requirement is that I am running this FM at item level if it is possible to append all the tables datas get as a result of this FM to other internal table having same structure.
    I know it is possible while using loop, I need a solution with out using the loop
    Regards
    Nausal

    Move Itab1[] to itab2[].
    data: begin of itab occurs 0,
          Maktx LIKE MAKT-MAKTX,
      end of itab.
    data: begin of itab1 occurs 0,
          Maktx LIKE MAKT-MAKTX,
      end of itab1.
    select maktx from makt into table itab where maktx like 'M1%'.
    move itab[] to itab1[].
    loop at itab1.
      write:/ itab1-maktx.
    endloop.

  • Field catalog for internal table in ALV

    In my program the internal table consists many fields from various tables and structure doesn't belong to a single data table.
    In order to get output in ALV grid following FM has been used
    REUSE_ALV_GRID_DISPLAY
    for field catalog the fields are defined specifically.
      l_fieldcat-fieldname  = 'VBELN'.
      l_fieldcat-outputlen  = 10.
      l_fieldcat-seltext_l  = 'Billing doc'.
      l_fieldcat-no_zero = 'X'.
      l_fieldcat-hotspot = 'X'.
      append l_fieldcat to p_fieldtab.
    ..............and so on for all the fields.
    Just wanted to know is there any other method to display all the fields of this internal table automatically so each field is not specified specifically.
    anya

    Hi
    Try this instead:
    *& Form  create_fieldcatalog
    * Create a field catalogue from any internal table
    *      -->PT_TABLE     Internal table
    *      -->PT_FIELDCAT  Field Catalogue
    FORM  create_fieldcatalog
           USING     pt_table     TYPE ANY TABLE
           CHANGING  pt_fieldcat  TYPE lvc_t_fcat.
      DATA:
        lr_tabdescr TYPE REF TO cl_abap_structdescr
      , lr_data     TYPE REF TO data
      , lt_dfies    TYPE ddfields
      , ls_dfies    TYPE dfies
      , ls_fieldcat TYPE lvc_s_fcat
      CLEAR pt_fieldcat.
      CREATE DATA lr_data LIKE LINE OF pt_table.
      lr_tabdescr ?= cl_abap_structdescr=>describe_by_data_ref( lr_data ).
      lt_dfies = cl_salv_data_descr=>read_structdescr( lr_tabdescr ).
      LOOP AT lt_dfies
      INTO    ls_dfies.
        CLEAR ls_fieldcat.
        MOVE-CORRESPONDING ls_dfies TO ls_fieldcat.
        APPEND ls_fieldcat TO pt_fieldcat.
      ENDLOOP.
    ENDFORM.                    "create_fieldcatalog

  • Passing content of field symbol to internal table

    Hi experts,
    I need to pass the content of a field symbol to a internal table. Below is the following structure of the field symbol and internal table. But I'm encountering a short dump:
    TYPES: BEGIN OF fint_frange,
            fieldname    LIKE rsdstabs-prim_fname,
            fieldtype(1) TYPE c,
            selopt_t     TYPE fint_selopt_t,
           END OF fint_frange.
    TYPES: fint_frange_t TYPE fint_frange OCCURS 10.
    CONSTANTS: lc_save_selections(31) TYPE c VALUE '(RFINTITAR)GT_SAVE_SELECTIONS[]',
    FIELD-SYMBOLS: <fs_save_selections> TYPE STANDARD TABLE.
    ASSIGN (lc_save_selections) TO <fs_save_selections>.
    i_save_selections[] = <fs_save_selections>.
    Short dump: You attempted to move one data object to another.
    This is not possible here because the internal tables concerned
    are neither compatible nor convertible.
    Thanks in advance.

    Hi,
    what is ur internal table structure?
    if structure of both field symbol and internal table is not same,
    u can not put equal betwwen them.
    ur  <fs_save_selections> is having one constanat value lc_save_selections.
    and ur assaigning that to an internal table with some structure ......
    so structure is not same for both..........check it once.
    Regards,
    kk.

  • Changing the order of fields in an internal table

    Hi all,
    I'm using field symbol as internal table. this table has got a standard database structure.
    I want to make the 3rd column of this internal table as 1st colums keeping rest of the columns as it is.
    Is there any way to do this?
    Thanks,
    Anil.

    Hi
        Instead of directly taking the type as a standard structure , declare the FS  internal table as type of types structure.
    Data: fs_scarr like type_s_scarr.
    FIELD-SYMBOLS <scarr2> TYPE fs_scarr
    In the types put the third column as first one and use into corresponding in select query
    or else
    while displaying the internal table change the order of the columns
    Loop at itab into fs_itab.
    write : col3
    col2
    col4
    endloop.
    Thanks,
    Viquar Iqbal

  • When I upload a single file into a production in FCS I can access all the fields in the metadata set, when I upload a batch of files, I can only access a partial number of fields in the metadata set.  Does anyone know why this happens?

    When I upload a single file into a production in FCS, I can access all the fields in a metadata set.  When I upload a batch of files into the same production in FCS, I can all access part of the fields in the metadata set.  Does anyone know why this happens?

    dredcomm,
    Great answer, and it led me to where to solve the problem.  In the field definition screen there is a category drop down list.  If you choose something other than none from the category drop down list then that field won't appear in the list of fields when you attempt to batch import a group of files.
    Thanks,
    Dave

  • Add field in an internal table

    Hi There,
    How to add a field in an internal table created at the runtime using
    CREATE DATA D1 TYPE TABLE OF (VAR).
    where say var contains name of a DDIC table.
    Rgds,
    deb.

    after creating internal table use the method for creation of dynamic table and try , i am not sure
    DATA: LineType TYPE string,
          ItabRef  TYPE REF TO DATA.
    FIELD-SYMBOLS:   TYPE STANDARD TABLE.
    LineType = 'SFLIGHT'.
    " Create internal table and attach a field-symbol
    CREATE DATA ItabRef TYPE STANDARD TABLE OF (LineType).
    ASSIGN ItabRef->* TO .
    <b>after this check this and try</b>
    ******DATA DECLARATION*****************************
    FIELD-SYMBOLS : <it_final> TYPE STANDARD TABLE,
                    <wa_final> TYPE ANY,
                    <w_field> TYPE ANY.
    ***DYNAMIC CREATION OF FIELDCATALOG****************
    *FIRST 2 FIELDS FIELDS FIELD1 AND FIELD2 ARE CONSTANT, FIELDS OBTAINED IN THE LOOP ENDLOOP ARE DYNAMIC,
    *LIKEWISE DYNAMIC FIELDCATALOG IS CREATED
      wa_fieldcatalog-fieldname  = 'FIELD1'.
      wa_fieldcatalog-ref_table  = 'E070'.
      wa_fieldcatalog-outputlen  = '13'.
      wa_fieldcatalog-reptext    = 'Created On'.
      wa_fieldcatalog-seltext    = 'Created On'.
      APPEND wa_fieldcatalog TO it_fieldcatalog.
      CLEAR wa_fieldcatalog.
      wa_fieldcatalog-fieldname  = 'FIELD1'.
      wa_fieldcatalog-ref_table  = 'E070'.
      wa_fieldcatalog-outputlen  = '13'.
      wa_fieldcatalog-reptext    = 'Created On'.
      wa_fieldcatalog-seltext    = 'Created On'.
      APPEND wa_fieldcatalog TO it_fieldcatalog.
      CLEAR wa_fieldcatalog.
      LOOP AT it_mandt WHERE mandt IN s_mandt.
        CONCATENATE 'CLNT' it_mandt INTO wa_fieldcatalog-fieldname.
        wa_fieldcatalog-inttype    = 'NUMC'.
        wa_fieldcatalog-outputlen  = '14'.
        wa_fieldcatalog-reptext    = it_mandt.
        wa_fieldcatalog-seltext    = it_mandt.
        APPEND wa_fieldcatalog TO it_fieldcatalog.
        CLEAR :wa_fieldcatalog ,it_mandt.
      ENDLOOP.
    ********CREATE DYNAMIC TABLE************************
      CALL METHOD cl_alv_table_create=>create_dynamic_table
        EXPORTING
          it_fieldcatalog           = it_fieldcatalog
        IMPORTING
          ep_table                  = new_table
        EXCEPTIONS
          generate_subpool_dir_full = 1
          OTHERS                    = 2.
      IF sy-subrc <> 0.
    *  MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      ASSIGN new_table->* TO <it_final>.
    *********CREATE WORK AREA****************************
    CREATE DATA new_line LIKE LINE OF <it_final>.
      ASSIGN new_line->* TO <wa_final>.
    *********INSERTTING WORK AREAR TO INTERNAL TABLE******
        INSERT <wa_final> INTO TABLE <it_final>.
    *******POPULATING DATA******************************* 
      LOOP.
       ASSIGN COMPONENT 'FIELD1' OF STRUCTURE <wa_final> TO <w_field>.
       <w_field> = '12345'.
        ASSIGN COMPONENT 'FIELD2' OF STRUCTURE <wa_final> TO <w_field>.
       <w_field> = '21453DD'.
       FIELD1 AND FIELD2 ARE COMPONENTS OF FIELDCATALOG.
    ENDLOOP.     
      ENDLOOP.

  • Create an internal table with the rows of another internal table.

    Hi I want to know if posible to create an internal table structure with the  rows of another internal table?
    ex.
    If in i_tab column A has this values: row 1 = first, row 2 = second, row 3 = third.
    Now I want that the structure of my internal table be: first, second, third

    Hi,
    If you do this way then what will be the difference between the two table anyway?? First internal table has the same structure irrespective of which row you select. and you are going to store the data from each row to the rows of the second internal table. In that case, the structure of the internal table is the same as first table. and it would have same rows.
    Am I missing something here? or you want to declare the internal table with each field being the structure of the first table? In this case you'd have to do a dynamic declaration of data as the first table can have any no of rows then the second table would have any no of fields in the structure.
    Now if you know that your first internal table is going to have a fixed no of rows eg 3 rows then it becomes simple. Do the following then
    Data: begin of second_table occurs 0,
    first type <first_table type>,
    second type <first_table type>,
    third type <first_table type>,
    end of second_table.
    Regards
    Prasenjit

  • To access different lines in an in internal table

    Hi People,
    How can I access different lines of an internal table where there is not set index which I have to access? I have to write only the last occurence of each kunnr getting stored in the internal table. Can somebody help?
    Thanks,
    AM

    Hi AM,
       You have got multiple solutions, each one of those are based on some assumptions.
       1. At end - this solution will work if kunnr is the first field in your internal table (Sorted).
       2. Edde's solution will work if all the values for kunnr in the internal table are same.
       If not of this applies then you need write a piece of logic between LOOP and ENDLOOP, but the right solution will depend on the exact nature of your problem. More you explain your problem better are the chances of getting a solution.
    Regards,
    Sanjeev

  • Extract a value of a fields from an internal table

    hello everyone,
    i need to extract a value of a fields from an internal table, the fields is in a postion "sy-tabix" that i know, so i need to pick this value without using a loop
    thank you.

    Like this?
    DATA: FIELD1 TYPE C,
               FIELD2 TYPE C.
    READ TABLE T_TAB INDEX 3.
    FIELD1 = T_TAB-FIELD1.
    FIELD2 = T_TAB-FIELD2.
    Greetings,
    Blag.

  • Fields in an internal table

    How to find number of fields in an internal table ?
    my requirement is i have 20 internal tables and the data is being uploaded into an application server. so how to find no of fields in a particular internal table

    concatenate all the fields and move them to final internal table , call the function module "GET_COMPONENT_LIST" and pass the work area of the final internal table in the parameter fieldname
    ***For getting no of FIELDS in an internal table ********
    CALL FUNCTION 'GET_COMPONENT_LIST'
      EXPORTING
        PROGRAM          = syrepid
        FIELDNAME        = 't_payr'
      TABLES
        COMPONENTS       = fieldlist.
    describe table fieldlist lines pyr_no_fields.
    ********end of getting no of fields**********
    TRANSFER wa_mat_out_head TO P_FNAME.
    LOOP AT GT_PAYR.
    MOVE:  GT_payr-LIFNR TO T_payr-lifnr,
           GT_payr-ZBUKR TO T_payr-zbukr,
           GT_payr-LAUFD TO T_payr-LAUFD,
           GT_payr-CHECT TO T_payr-CHECT,
           GT_payr-RWBTR TO T_payr-RWBTR.
    Concatenate T_payr-lifnr  t_payr-zbukr T_payr-laufd T_payr-chect
                T_payr-rwbtr into wa_mat_out-rec SEPARATED by ',' .

  • Aggregate a numeric field in an internal table

    Hi All,
    I have a small requirement in ABAP…it goes in this fashion
    I need to aggregate a numeric field in an internal table, the table is as follows   
    FLD1        FLD2         NUM1       FLD3
    123A        B1             10            C1
    123A        B1             25            C1
    123B        B1             20            C2
    123C        B2            10             C3
    Note: FLD1, FLD2, FLD3 are of type numeric characters and NUM1 is of type number or integer
    I want the result to be as follows
    FLD1        FLD2        NUM1        FLD3
    123A        B1            35             C1
    123B        B1            20             C2
    123C        B2            10             C3
    i.e. values in field NUM1 should get add up when the values in all other fields are same…
    I am not able to use ‘_collect_’ for this as the fields contain numeric characters.
    Regards and Thanks,
    Antony

    Hi Antony
    collect here works like this:-
    use at new field
          sum
    end at.
    Pls reward points if it wil be helpful.
    Regards
    Depanker

  • I need to add check whether 21 fields of a internal table are empty or not.

    Hello,
    I need to add check whether 21 fields of a internal table are empty or not.How can we write a code for the same wand what would be the correct syntax for it.
    I tried entering all the fields in the IF loop with AND condition but its giving syntax error.Perhaps this is because the lenght of the IF condition would be more than the allowed one.

    Hi,
    After the select quiery.
    If not itab is initial.
    Message 'Table is not empty'    type 'I'.
    Endif.
    Regards,
    Jagadish.

Maybe you are looking for

  • How do I upload a file to a website instead of a image

    Hi I'm trying to upload my cv to a job website on my iPad 3, but when I click on the websites upload button, it only allows me to select from the photos file on my iPad. Does anyone know how to change this to upload files, from Dropbox as an example.

  • Ios8 failed update now iPad 2 is frozen, with iTunes icon on screen

    My kid saw that the iOS 8 update was available for my iPad 2 and he proceeded to try to do the update but after a while when he checked how it was going there was only a black screen with the iTunes icon in the middle and what looks like a cord point

  • Resizing Front Panel Objects

    Anybody, Is it possible to resize a group of selected objects to the same size? Thanks. Petter Kristiansen

  • Yosemite Install Woes

    I am hoping someone will be able to help please, after three days of battling an upgrade that went wrong. I've documented this as fully as I can since I see a lot of comments from people trying to help here asking for specific steps that we (those of

  • Can any one explain How transport mechanism happens

    explain the concept of Transporting objects or packages from dev to production