Updating internal table in dynamic way

Hi,
I want to update one internal table dynamically.I have two internal table.
One internal table has the records which are field names of the 2nd internal table.
suppose:
Itab1 is as follows:
F1                                           F2
aaa                                        bbb
Itab2 as follows:
aaa                         bbb
This means the ITAB1 records are the fields of ITB1.Now I want to update ITAB2 when I found ITAB1-F1 is the field of ITAB2 dynamically.
Can anyone give some code hint to do so.

you can use below code for this. I write it in notepad some changes may be necessary.
data: lv_c(30).
field-symbols: <f1> type any.
loop at itab1.
concatenate 'itab2' itab1-fieldname into lv_c.
assign (lv_c) to <f1>.
if assign successful this means this field exists
if sy-subrc = 0
move value to <f1>.
*modify itab2.
endif.
endloop.
Edited by: Gungor Ozcelebi on Jul 1, 2009 3:37 PM

Similar Messages

  • Determining internal table structure dynamically

    Hi,
    I have a number of internal tables in my program which I declare using types. As an example:
    TYPES: begin of ty_hierarchy,
                   control_id(6)   type c,
                   node_id(10)     type c,
                   node_name       type bezei40,
                   material        type matnr,
                   node_level      type prodh_stuf,
                   node_parent(10) type c,
                end of ty_hierarchy.
    DATA: it_hierarchy type ty_hierarchy occurs 0.
    Further down my program I need to determine the structure of internal table IT_HIERARCHY dynamically. Because I have a number of internal tables, I need to determine which internal table is being processed. Therefore it's important that I know the structure of the table that I'm currently processing.
    I am aware of CL_ABAP* classes and functions like GET_COMPONENT_LIST. However because I have declared my tables using the TYPE statement the method/function cannot read my table structure correctly. If I changed my declaration to be as below, the method/function work! However I don't want to do this as I use field symbols to reference my internal tables and need to use the TYPE statement.
    DATA: begin of ty_hierarchy,
                   control_id(6)   type c,
                   node_id(10)     type c,
                   node_name       type bezei40,
                   material        type matnr,
                   node_level      type prodh_stuf,
                   node_parent(10) type c,
                end of ty_hierarchy.
    DATA: begin of it_hierarchy occurs 0.
                 include structure ty_hierarchy
    DATA: end of it_hierarchy.
    Does anyone know on how I can determine my  internal table structure dynamically but still keeping my internal table declarations using TYPE statement?
    Any help would be greatly appreciated with reward points .....
    Thanks
    Liam

    Hello Liam
    Both the ABAP-OO as well as the FM-based approach described by Eswar work well with your way of defining the itabs. I described three different ways how to get the structure of your itab dynamically:
    - directly using the itab
    - using a field symbol
    - using a data reference
    REPORT  zus_sdn_dynamic_itabs.
    TYPE-POOLS: abap.
    TYPES: BEGIN OF ty_hierarchy,
    control_id(6) TYPE c,
    node_id(10) TYPE c,
    node_name TYPE bezei40,
    material TYPE matnr,
    node_level TYPE prodh_stuf,
    node_parent(10) TYPE c,
    END OF ty_hierarchy.
    DATA:
      gs_hierarchy    TYPE ty_hierarchy,
      it_hierarchy    TYPE ty_hierarchy OCCURS 0.
    DATA:
      gt_comp         TYPE abap_compdescr_tab,
      gs_comp_a       LIKE LINE OF gt_comp,
      gd_type         TYPE abap_typekind,
      gs_comp    TYPE rstrucinfo,
      it_comp TYPE TABLE OF rstrucinfo.
    DATA:
      go_struct    TYPE REF TO cl_abap_structdescr,
      go_table     TYPE REF TO cl_abap_tabledescr,
      gdo_data     TYPE REF TO data.
    FIELD-SYMBOLS:
      <gt_itab>    TYPE table.
    START-OF-SELECTION.
      GET REFERENCE OF it_hierarchy INTO gdo_data.
      ASSIGN gdo_data->* TO <gt_itab>.
    * (1) Describe directly by using the itab
    *  go_table  ?= cl_abap_structdescr=>describe_by_data( it_hierarchy ).
    * (2) Describe indirectly by using field symbol
    *  go_table  ?= cl_abap_structdescr=>describe_by_data( <gt_itab> ).
    * (3) Describe by data reference to itab
      go_table  ?= cl_abap_structdescr=>describe_by_data_ref( gdo_data ).
      go_struct ?= go_table->get_table_line_type( ).
      WRITE: / 'ABAP-OO Version:'.
      gt_comp = go_struct->components.
      LOOP AT gt_comp INTO gs_comp_a.
        WRITE: / gs_comp_a-name,
                 gs_comp_a-length,
                 gs_comp_a-type_kind,
                 gs_comp_a-decimals.
      ENDLOOP.
      SKIP 2.
      CALL FUNCTION 'GET_COMPONENT_LIST'
        EXPORTING
          program    = sy-repid
          fieldname  = 'GS_HIERARCHY'
        TABLES
          components = it_comp.
      WRITE: / 'Function Module Version:'.
      LOOP AT it_comp INTO gs_comp.
        WRITE: / gs_comp-compname,
                 gs_comp-level,
                 gs_comp-leng,
                 gs_comp-type,
                 gs_comp-olen,
                 gs_comp-decs.
      ENDLOOP.
    END-OF-SELECTION.
    Regards
      Uwe

  • Internal table with Dynamic and Non dynamic fileds

    Hi Experts,
    How to get the internal table with Dynamic and Non-Dynamic Fields.
    Could u please help me.
    Thanks,
    Varun

    Hi,
       Execute the below sample code or analyze it there is appropriate description provided.
    *& Report  ZTEST_PRM_DYN_ALV
    REPORT  ZTEST_PRM_DYN_ALV.
    type-pools: slis.
    field-symbols: <dyn_table> type standard table,
    <dyn_wa>.
    data: alv_fldcat type slis_t_fieldcat_alv,
    it_fldcat type lvc_t_fcat.
    selection-screen begin of block b1 with frame title text-001.
    parameters: p_flds(5) type c.
    selection-screen end of block b1.
    start-of-selection.
    *build the dynamic internal table
    perform build_dyn_itab.
    *write 5 records to the alv grid
    do 5 times.
    perform build_report.
    enddo.
    *call the alv grid.
    perform call_alv.
    *Build_dyn_itab
    form build_dyn_itab.
    data: new_table type ref to data,
    new_line type ref to data,
    wa_it_fldcat type lvc_s_fcat.
    *Create fields .
    clear wa_it_fldcat.
    wa_it_fldcat-fieldname = 'name1'.
    wa_it_fldcat-datatype = 'mara-matnr'.
    wa_it_fldcat-intlen = 5.
    append wa_it_fldcat to it_fldcat .
    *clear wa_it_fldcat.
    wa_it_fldcat-fieldname = sy-index.
    wa_it_fldcat-datatype = 'CHAR'.
    wa_it_fldcat-intlen = 5.
    append wa_it_fldcat to it_fldcat .
    do p_flds times.
    clear wa_it_fldcat.
    wa_it_fldcat-fieldname = sy-index.
    wa_it_fldcat-datatype = 'CHAR'.
    wa_it_fldcat-intlen = 6.
    append wa_it_fldcat to it_fldcat .
    enddo.
    *Create dynamic internal table and assign to FS
    call method cl_alv_table_create=>create_dynamic_table
    exporting
    it_fieldcatalog = it_fldcat
    importing
    ep_table = new_table.
    assign new_table->* to <dyn_table>.
    *Create dynamic work area and assign to FS
    create data new_line like line of <dyn_table>.
    assign new_line->* to <dyn_wa>.
    endform.
    *Form build_report
    form build_report.
    data: fieldname(20) type c.
    data: fieldvalue(5) type c.
    data: index(3) type c.
    field-symbols: <fs1>.
    do p_flds times.
    index = sy-index.
    *Set up fieldvalue
    concatenate 'FLD' index into
    fieldvalue.
    condense fieldvalue no-gaps.
    assign component index of structure <dyn_wa> to <fs1>.
    <fs1> = fieldvalue.
    enddo.
    *Append to the dynamic internal table
    append <dyn_wa> to <dyn_table>.
    endform.
    *CALL_ALV
    form call_alv.
    data: wa_cat like line of alv_fldcat.
    *clear wa_cat.
    wa_cat-fieldname = 'matnr'.
    wa_cat-seltext_s = sy-index.
    wa_cat-outputlen = '10'.
    append wa_cat to alv_fldcat.
    do p_flds times.
    clear wa_cat.
    wa_cat-fieldname = sy-index.
    wa_cat-seltext_s = sy-index.
    wa_cat-outputlen = '6'.
    append wa_cat to alv_fldcat.
    enddo.
    *Call ABAP List Viewer (ALV)
    call function 'REUSE_ALV_GRID_DISPLAY'
    exporting
    it_fieldcat = alv_fldcat
    tables
    t_outtab = <dyn_table>.
    endform.
    Hope this will help, reward if found usefull.
    Cheers,
    Ram.

  • Populating values to internal table created dynamically

    Hi,
    I am creating an internal table(it1) dynamically and assigned it to a field symbol. now i want to upload values
    which are present in a field of another internal table being populated from a Funct Module.Could you tell me
    how to assign those values across the fields of field symbol?
    loop at itab_char.
    LS_ALV_CAT-FIELDNAME = itab_char-charact.
    append LS_ALV_CAT to I_ALV_CAT.
    endloop.
    CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
      EXPORTING
        IT_FIELDCATALOG = I_ALV_CAT
      IMPORTING
        EP_TABLE        = D_REF.
    ASSIGN D_REF->* TO <F_FS>.
    (Above my int tab is generated and now stored in <f_FS>)
    loop at itab into w_lifnr.
    CALL FUNCTION 'CLAF_CLASSIFICATION_OF_OBJECTS'
      EXPORTING
       CLASS                      = p_cname
       CLASSTYPE                  = w_ctype
       OBJECT                     = w_lifnr
      TABLES
        T_CLASS                    = t_class
        T_OBJECTDATA               = t_objectdata
    w-lifnr is vendor number. and here we are populating t_objectdata with that vendor related datas. now i want to pass t_objectdata-ausp1 values for each vendor across the fields in <F_FS>.
    FIELD-SYMBOLS : <F_FS> TYPE TABLE.
    Please refer me the solution to this problem.
    Thanks

    Check below code and try to add in ur code....
        IF NOT it_bom_expl[] IS INITIAL.
    The material number data varies from run to run. For this purpose
    the data is been used to build dynamic internal table which stores the
    material number data along the x-axis
          PERFORM build_matnr_table.
    The material numbers data which is stored in the temp internal table
    is been assigned to the dynamic internal table created along the
    x-axis for the materials
          PERFORM assign_matnr_val_fields.
    The component data which is stored in the internal table needs to be
    moved to the dynamic internal table
          PERFORM move_bom_data_to_matnr_table.
    *&      Form  build_matnr_table
    Using the material number data the dynamic internal tables are been
    built which holds the material number data along x-axis. Here the
    first 3 columns are always constant which are Components-List,
    Description, Count. From 4th column it depends on number of materials
    FORM build_matnr_table .
      DATA: l_val(3) TYPE n,
            lf_mat(18) TYPE c.
    Moving the Components-List details to the internal table 1st column
    which will be used for creation of dynamic internal table
      CLEAR gf_xfc.
      gf_xfc-fieldname = text-t03.
      gf_xfc-datatype = c_val_c.
      gf_xfc-inttype = c_val_c.
      gf_xfc-intlen = 18.
      gf_xfc-decimals = 0.
      APPEND gf_xfc TO gf_ifc.
      APPEND gf_xfc TO gf_ipc.
      CLEAR gf_xfc.
    Moving the Description details to the internal table 2nd column
    which will be used for creation of dynamic internal table
      gf_xfc-fieldname = text-t04.
      gf_xfc-datatype = c_val_c.
      gf_xfc-inttype = c_val_c.
      gf_xfc-intlen = 40.
      gf_xfc-decimals = 0.
      APPEND gf_xfc TO gf_ipc.
      CLEAR gf_xfc.
    Moving the Count details to the internal table 3rd column which will
    be used for creation of dynamic internal table
      gf_xfc-fieldname = text-t05.
      gf_xfc-datatype = c_val_c.
      gf_xfc-inttype = c_val_c.
      gf_xfc-intlen = 5.
      gf_xfc-decimals = 0.
      APPEND gf_xfc TO gf_ifc.
      APPEND gf_xfc TO gf_ipc.
    Moving the Material numbers are moved to the internal table from 4th
    column onwards till all the material numbers are moved to the columns
    which will be used for creation of dynamic internal table. Here
    columns will be reffered to as Material001 ..... Materialxxn
      LOOP AT it_mat.
        CLEAR gf_xfc.
        l_val = l_val + 1.
        CONCATENATE text-t06 l_val INTO lf_mat.
        gf_xfc-fieldname = lf_mat.
        gf_xfc-datatype = c_val_c.
        gf_xfc-inttype = c_val_c.
        gf_xfc-intlen = 18.
        gf_xfc-decimals = 0.
        APPEND gf_xfc TO gf_ifc.
        APPEND gf_xfc TO gf_ipc.
      ENDLOOP.
    Using the above data dynamic internal table is been created
      CALL METHOD cl_alv_table_create=>create_dynamic_table
        EXPORTING
          it_fieldcatalog = gf_ifc
        IMPORTING
          ep_table        = gf_table.
    The dynamic internal table which is created is been assigned to
    field-symbol which holds the data of the columns of X-axis
      ASSIGN gf_table->* TO <fs_dyn_table>.
    Dynamic work area is been created usng the reference to the
    field-symbol which has the data and the line item is been assign to
    field-symbol to hold line item data for reading purposes line by line
      CREATE DATA gf_line LIKE LINE OF <fs_dyn_table>.
      ASSIGN gf_line->* TO <fs_dyn_wa>.
    Using the above data dynamic internal table is been created
      CALL METHOD cl_alv_table_create=>create_dynamic_table
        EXPORTING
          it_fieldcatalog = gf_ipc
        IMPORTING
          ep_table        = gf_table1.
    The dynamic internal table which is created is been assigned to
    field-symbol which holds the data of the columns of X-axis
      ASSIGN gf_table1->* TO <fs_dyn_table1>.
    Dynamic work area is been created usng the reference to the
    field-symbol which has the data and the line item is been assign to
    field-symbol to hold line item data for reading purposes line by line
      CREATE DATA gf_line1 LIKE LINE OF <fs_dyn_table1>.
      ASSIGN gf_line1->* TO <fs_dyn_wa1>.
    Using the above data dynamic internal table is been created
      CALL METHOD cl_alv_table_create=>create_dynamic_table
        EXPORTING
          it_fieldcatalog = gf_ifc
        IMPORTING
          ep_table        = gf_table2.
    The dynamic internal table which is created is been assigned to
    field-symbol which holds the data of the columns of X-axis
      ASSIGN gf_table2->* TO <fs_dyn_table2>.
    Dynamic work area is been created usng the reference to the
    field-symbol which has the data and the line item is been assign to
    field-symbol to hold line item data for reading purposes line by line
      CREATE DATA gf_line2 LIKE LINE OF <fs_dyn_table2>.
      ASSIGN gf_line2->* TO <fs_dyn_wa2>.
    ENDFORM.                    " build_matnr_table
    *&      Form  assign_matnr_val_fields
    The material numbers data stored in the temp internal table needs to
    be assigned to the dynamic internal table along x-axis as the first
    record. The temp internal table is been looped and using the field
    symbol concept the data is moved to the dynamic internal table
    FORM assign_matnr_val_fields .
      DATA: l_cnt(3) TYPE n,
            l_nam(12),
            g_total(3) TYPE n.
      DESCRIBE TABLE it_mat LINES g_total.
      CLEAR l_cnt.
    Looping the temp internal table and concatenating material as
    material001 and the same is been checked against the dynamic
    internal table and the material number value is moved to the
    internal table. Finally, the data is been appened as first record.
      LOOP AT it_mat.
        l_nam = c_mat.
        l_cnt = l_cnt + 1.
        CONCATENATE l_nam l_cnt INTO l_nam.
    Material which is in form Materialxxn is been assigned to the field
    symbol which is checked against the field of dynamic internal table
    and the value of the Material Number is been passed to the dynamic
    internal table field value.
    After all materials are been assigned the record is been appended
    to the dynamic internal table.
        ASSIGN COMPONENT l_nam OF STRUCTURE <fs_dyn_wa> TO <fs_field>.
        <fs_field> = it_mat-matnr.
        IF l_cnt = g_total.
          INSERT <fs_dyn_wa> INTO TABLE <fs_dyn_table>.
        ENDIF.
      ENDLOOP.
    Looping the temp internal table and concatenating material as
    material001 and the same is been checked against the dynamic
    internal table and the material number value is moved to the
    internal table. Finally, the data is been appened as first record.
    This is been used for downloading of data to excel sheet as it
    contains additional field which is Description field.
      CLEAR l_cnt.
      LOOP AT it_mat.
        l_nam = c_mat.
        l_cnt = l_cnt + 1.
        CONCATENATE l_nam l_cnt INTO l_nam.
    Material which is in form Materialxxn is been assigned to the field
    symbol which is checked against the field of dynamic internal table
    and the value of the Material Number is been passed to the dynamic
    internal table field value.
    After all materials are been assigned the record is been appended
    to the dynamic internal table.
        ASSIGN COMPONENT l_nam OF STRUCTURE <fs_dyn_wa1> TO <fs_field>.
        <fs_field> = it_mat-matnr.
        IF l_cnt = g_total.
          INSERT <fs_dyn_wa1> INTO TABLE <fs_dyn_table1>.
        ENDIF.
      ENDLOOP.
    The contents of one internal table is passed on to other internal
    table for use while moving the component data for count purposes.
      <fs_dyn_table2>[] = <fs_dyn_table>[].
    ENDFORM.                    " assign_matnr_val_fields
    *&      Form  move_bom_data_to_matnr_table
    The component data is been appended to the dynamic internal table
    The component is checked against a material and if exists the corresp-
    onding level is been appended to the record
    The total count is derived as the in how many materials the component
    exists
    FORM move_bom_data_to_matnr_table .
      DATA: l_cnt(2) TYPE n,
            l_cnt1(3) TYPE n,
            l_nam(12),
            l_con(18) TYPE c,
            l_con1(18) TYPE c,
            lf_mat TYPE matnr.
      SORT it_bom_expl BY bom_comp bom_mat level.
      CLEAR: l_cnt1, <fs_dyn_wa>.
    Looping the component internal table
      LOOP AT it_bom_expl INTO gf_it_bom_expl.
        CLEAR: l_cnt1.
        AT NEW bom_comp.
          CLEAR: l_cnt, <fs_dyn_wa>, lf_mat.
    For every new bom component the material data is moved to
    temp material table which will be used for assigning the levels
    checking the count
          it_mat_temp[] = it_mat[].
    Component data is been assigned to the field symbol which is checked
    against the field of dynamic internal table and the value of the
    component number is been passed to the dynamic internal table field
    value.
          ASSIGN COMPONENT c_comp_list OF STRUCTURE <fs_dyn_wa> TO
          <fs_check>.
          <fs_check> = gf_it_bom_expl-bom_comp.
        ENDAT.
        AT NEW bom_mat.
          CLEAR l_con.
        ENDAT.
        lf_mat = gf_it_bom_expl-bom_mat.
    Looping the temp internal table and looping the dynamic internal table
    *by reading line by line into workarea, the materialxxn is been assigned
    to field symbol which will be checked and used.
        LOOP AT it_mat_temp.
          l_nam = c_mat.
          l_cnt1 = l_cnt1 + 1.
          CONCATENATE l_nam l_cnt1 INTO l_nam.
          LOOP AT <fs_dyn_table2> ASSIGNING <fs_dyn_wa2>.
            ASSIGN COMPONENT l_nam OF STRUCTURE <fs_dyn_wa2> TO <fs_xy>.
          ENDLOOP.
          IF <fs_xy> = lf_mat.
            CLEAR lf_mat.
            l_con1 = l_con.
          ENDIF.
    Checking whether the material exists for a component and if so it is
    been assigned to the field symbol which is checked against the field
    of dynamic internal table and the level of the component number
    against material is been passed to the dynamic internal table field
    value.
          IF <fs_xy> = gf_it_bom_expl-bom_mat.
            ASSIGN COMPONENT l_nam OF STRUCTURE <fs_dyn_wa> TO <fs_check>.
            CLEAR l_con.
            MOVE gf_it_bom_expl-level TO l_con.
            CONCATENATE c_val_l l_con INTO l_con.
            CONDENSE l_con NO-GAPS.
            IF l_con1 NE space.
              CONCATENATE l_con1 l_con INTO l_con SEPARATED BY c_comma.
              CLEAR l_con1.
              l_cnt = l_cnt - 1.
            ENDIF.
            <fs_check> = l_con.
            l_cnt = l_cnt + 1.
          ENDIF.
        ENDLOOP.
        AT END OF bom_comp.
    At end of every new bom component the count is moved to the field
    symbol which is checked against the field of dynamic internal table
    and the count is been passed to the dynamic internal table field
    value.
          ASSIGN COMPONENT c_count OF STRUCTURE <fs_dyn_wa> TO <fs_check>.
          <fs_check> = l_cnt.
          INSERT <fs_dyn_wa> INTO TABLE <fs_dyn_table>.
        ENDAT.
      ENDLOOP.
    Looping the component internal table. This is used for the additional
    Description field which is shown in the excel sheet
      LOOP AT it_bom_expl INTO gf_it_bom_expl.
        CLEAR: l_cnt1.
        AT NEW bom_comp.
          CLEAR: l_cnt, <fs_dyn_wa1>, lf_mat.
    For every new bom component the material data is moved to
    temp material table which will be used for assigning the levels
    checking the count
          it_mat_temp[] = it_mat[].
    Component data is been assigned to the field symbol which is checked
    against the field of dynamic internal table and the value of the
    component number is been passed to the dynamic internal table field
    value.
          ASSIGN COMPONENT c_comp_list OF STRUCTURE <fs_dyn_wa1> TO
          <fs_check>.
          <fs_check> = gf_it_bom_expl-bom_comp.
        ENDAT.
        AT NEW bom_mat.
          CLEAR l_con.
        ENDAT.
        lf_mat = gf_it_bom_expl-bom_mat.
    Looping the temp internal table and looping the dynamic internal table
    *by reading line by line into workarea, the materialxxn is been assigned
    to field symbol which will be checked and used.
        LOOP AT it_mat_temp.
          l_nam = c_mat.
          l_cnt1 = l_cnt1 + 1.
          CONCATENATE l_nam l_cnt1 INTO l_nam.
          LOOP AT <fs_dyn_table2> ASSIGNING <fs_dyn_wa2>.
            ASSIGN COMPONENT l_nam OF STRUCTURE <fs_dyn_wa2> TO <fs_xy>.
          ENDLOOP.
          IF <fs_xy> = lf_mat.
            CLEAR lf_mat.
            l_con1 = l_con.
          ENDIF.
    Checking whether the material exists for a component and if so it is
    been assigned to the field symbol which is checked against the field
    of dynamic internal table and the level of the component number
    against material is been passed to the dynamic internal table field
    value.
          IF <fs_xy> = gf_it_bom_expl-bom_mat.
            ASSIGN COMPONENT l_nam OF STRUCTURE <fs_dyn_wa1> TO <fs_check>.
            CLEAR l_con.
            MOVE gf_it_bom_expl-level TO l_con.
            CONCATENATE c_val_l l_con INTO l_con.
            CONDENSE l_con NO-GAPS.
            IF l_con1 NE space.
              CONCATENATE l_con1 l_con INTO l_con SEPARATED BY c_comma.
              CLEAR l_con1.
              l_cnt = l_cnt - 1.
            ENDIF.
            <fs_check> = l_con.
            l_cnt = l_cnt + 1.
          ENDIF.
        ENDLOOP.
    The description is moved to the field symbol which is checked against
    the field of dynamic internal table and the count is been passed to
    the dynamic internal table field value.
        ASSIGN COMPONENT c_description OF STRUCTURE <fs_dyn_wa1> TO
        <fs_check>.
        <fs_check> = gf_it_bom_expl-ojtxp.
    At end of every new bom component the count is moved to the field
    symbol which is checked against the field of dynamic internal table
    and the count is been passed to the dynamic internal table field
    value.
        AT END OF bom_comp.
          ASSIGN COMPONENT c_count OF STRUCTURE <fs_dyn_wa1> TO <fs_check>.
          <fs_check> = l_cnt.
          INSERT <fs_dyn_wa1> INTO TABLE <fs_dyn_table1>.
        ENDAT.
      ENDLOOP.
    ENDFORM.                    " move_bom_data_to_matnr_table

  • Change internal table structure dynamically

    Dear Experts , I have a requirement to add an attribute to already declared internal table which is declared in standard SAP code, is it possible to change internal table structure dynamically.
    my internal table is of type merel_t_grid2 which is standard table type in SAP , now I want to add an attribute of type  LVC_T_STYL in my internal table so that I can modify the cell property of ALV grid.
    I cant append LVC_T_STYL in standard structure because enhancement category of merel_t_grid2 is of type char and not deep
    my internal table contains data to be displayed in ALV.
    please help

    Dear Experts , I have a requirement to add an attribute to already declared internal table which is declared in standard SAP code, is it possible to change internal table structure dynamically.
    my internal table is of type merel_t_grid2 which is standard table type in SAP , now I want to add an attribute of type  LVC_T_STYL in my internal table so that I can modify the cell property of ALV grid.
    I cant append LVC_T_STYL in standard structure because enhancement category of merel_t_grid2 is of type char and not deep
    my internal table contains data to be displayed in ALV.
    please help

  • Dynamic internal table with dynamic header

    Hi Members,
    I have created a dynamic report ie In the selection screen i will give set of GL accounts.
    Based on the GL it will separate a col like Sales GL, PF GL , Discount Gl etc. In the header portion  first 3 col is constant ie it  will show the vendor name and material and text remaining col is based on the GL entered in the screen it will cumulate the Total Amount and display accordingly.
    This is working fine in ALV grid display, but i required to download the data to excel , while downloading to excel i am getting only the values without header,
    ie title of the each col not getting . kindly guide me to solve this issue.
    If i entered only sales GLs (100,101,102 ) then  my output should be
    vendor   material    mateial text   100       101      102
    ddddd    11100       Raw salt      2000    1000     2500
    Regards,
    Mee.S

    Hi Meenakshi,
    As per my knowledge two ways of doing it...
    1. when u get the final internal table..check for the fields with not initial...again update the header internal table dynamically..
    2. if you get GL or PF or any such thing you can hardcode the header and display it on to excel..
    Regards,
    Vamshi

  • Update internal table data from table control

    Hi GURUS,
    I need help regarding one of my requirement.
    I need to display data from the internal table on the screen and when the user selects a record/multiple records from screen and clicks on approve button i need to update one of the field from N to Y in the corresponding Ztable. Once the record is updated from Ztable , that should no longer be visible for the user on the screen.
    I am using table control wizard to display data. I am able to update the Ztable, but that record is not refreshing from the user screen. Any suggestions would be approved.
    Also please let me know if table control is the best way to do this/ alv grid control??

    hi
       REFRESH CONTROL Control-Name FROM SCREEN '0100'  -> use this command to refresh the table control
    to know more, read into
    https://forums.sdn.sap.com/click.jspa?searchID=2934287&messageID=673474
    Re: URGENT HELP REQ IN TABLE CONTROL WIZARD
    if helpful, reward
    Sathish. R

  • Populate Final internal table from Dynamic internal table

    Hello,
    I have ti display data in ALV grid whose structure is fixed. I am dynamically selecting data iin an internal table.
    Now from this dynamic internal table, i need to populate my final internal table whose structurte is fixed.
    Please help.
    Rgds,
    Himanshu

    Hello Himanshu,
    When you say dynamic internal table there are two things one is the actual structure and other one is field table that holds information for all the fields used to create dynamic internal table.
    No if you want to move data from dynamic table to fixed internal table then you can try as follows:
    1.
    field-symbols <field_name> TYPE C.
    field-symbols <field_value> TYPE C.
    Now you either use
    LOOP AT fields_itab.
    ASSIGN fields_itab-fieldname to <field_name>.
    ASSIGN COMPONENT <field_name> OF STRUCTURE <structure_name> TO <field_value>
    Now you move value from <field_value> to required field in fixed internal table.
    i.e.
    itab-fieldname = <field_value>.
    Other way to do this:
    If you fields order is constant then you can also use index in assign component statement.
    do <no_of_fields> times.
        ASSIGN COMPONENT sy-index OF STRUCTURE <structure_name> TO <field_value>.
    rest is same as first method.
    Hope this help!
    I have given sudo code and you need to work on it little.
    Thanks,
    Augustin.

  • Data allocation for internal table rows Dynamically

    Hi Friends
    I have requirement like below:
    I have one internal table with 400 amounts columns, I will get the value from another program
    that indicates to which column I have to add the values. I dont want to write the case statement
    because I need to write 400 WHEN statements.
    Is there any alternative way dynamically I can choose the internal table column and assign the value which
    I am getting from external program.
    Please help on this as soon as possible.
    Points will be rewarded
    Thanks
    Praveen

    Hi Praveen,
    you may use the ASSIGN COMPONENT ... OF STRUCTURE ... statement.
    It allows to assign the field by name or by sequence.
    Assume you columns have names like amount_001 to amount_999 and are fields of structure ls_amounts. The do as decribed here roughly:
    data:
      lv_fieldseq type NUMC_3,
      lv_fieldname type fieldname,
      lv_amount type (???).
    fieldsymbols:
      <amount> type any.
    * fetch amount and field sequence from external data into  lv_amount and lv_fieldseq
    concatenate 'AMOUNT_' lv_fieldseq into lv_fieldname.
    * <amount> is something like a pointer
    assign component (lv_fieldname) of structure ls_amounts to <amount>.
    add lv_amount  to <amount>. 
    if you are sure you have the correct position of the amount field in the structure stored in variable lv_position, you may use
    assign component lv_position of structure ls_amounts to <amount>.
    I prefer the ASSIGN (fieldname) for reasons of more transparency and less danger in case of structural changes.
    Regards,
    Clemens
    Regards,
    Clemens

  • ALV GRID update internal table

    Hi all,
    I have an internal table display in a ALV GRID. Only one column is editable. When I change the field value, ALV GRID display the change, but when I click on refresh return the old value.
    I've checked in DEBUG mode and when I click on refresh (in the PAI module), the internal table haven't data modified.
    For example: the field qta have value 15. I change it in 18 and then press Refresh. In debug, the field qta still have the value 15.
    What I have to do?

    Hi
    The Example prg is using Classes, then you need to use the same approach in the way i mentioned below...
    You need to Update the ITAB with the Modifeid values.
    *       CLASS lcl_event_handler DEFINITION
    CLASS LCL_EVENT_HANDLER DEFINITION .
      PUBLIC SECTION .
        METHODS:
    **Handler to Check the Data Change
        HANDLE_DATA_CHANGED FOR EVENT DATA_CHANGED
                             OF CL_GUI_ALV_GRID
                             IMPORTING ER_DATA_CHANGED
                                       E_ONF4
                                       E_ONF4_BEFORE
                                       E_ONF4_AFTER.
    ENDCLASS.                    "lcl_event_handler
    DEFINITION
    **Handle Data Change
      METHOD HANDLE_DATA_CHANGED.
        DATA: X_CHANGE TYPE LVC_S_MODI,
              X_FINAL TYPE T_FINAL,
              X_OCRC TYPE ZSD_OC_HOLD,
              L_FLAG.
        LOOP AT ER_DATA_CHANGED->MT_GOOD_CELLS INTO X_CHANGE.
          IF X_CHANGE-FIELDNAME = 'ZZOCHOLDRC'.
            READ TABLE IT_FINAL INTO X_FINAL INDEX X_CHANGE-ROW_ID.
            IF SY-SUBRC = 0.
              READ TABLE IT_OCRC INTO X_OCRC WITH KEY
                                             ZZOCHOLDRC = X_CHANGE-VALUE
                                            TRANSPORTING ZZRCDESC.
              IF SY-SUBRC = 0.
                X_FINAL-ZZRCDESC = X_OCRC-ZZRCDESC.
                MODIFY IT_FINAL FROM X_FINAL INDEX X_CHANGE-ROW_ID
                                             TRANSPORTING ZZRCDESC.
                L_FLAG = 'X'.
              ENDIF.
            ENDIF.
          ENDIF.
          IF X_CHANGE-FIELDNAME = 'ZZPROMDT'.
            READ TABLE IT_FINAL INTO X_FINAL INDEX X_CHANGE-ROW_ID.
            IF SY-SUBRC = 0.
              X_FINAL-ZZPROMDT = X_CHANGE-VALUE.
              MODIFY IT_FINAL FROM X_FINAL INDEX X_CHANGE-ROW_ID
                                           TRANSPORTING ZZPROMDT.
              L_FLAG = 'X'.
            ENDIF.
          ENDIF.
        ENDLOOP.
        IF L_FLAG = 'X'.
          CLEAR V_DATA_CHANGE.
          V_DATA_CHANGE = 'X'.
        ENDIF.
      ENDMETHOD.                    "data_changed
    **you need to SET the HANDLER after the method first display.
      CREATE OBJECT G_HANDLER.
      SET HANDLER G_HANDLER->HANDLE_DATA_CHANGED FOR G_GRID.
    try this
    vijay

  • Is it possible to update internal table from database table

    Hello All:
              I know how to update database table from internal table in one shot (batch) but is the reverse possible? Can I update some fields in an internal table from a database table in one shot (without looping) because my internal table is huge? Could you please provide me any ideas how to acheive something like this? Thanks in advance and answers will be rewarded.
    thanks.
    Mithun

    Hello my friend,
    You can do it MAYBE , i think you can reverse the update doing a ROLLBACK, but only after you update....not after the program finishes..
    To update some fields at once use:
    UPDATE DBTABLE FROM TABLE IT_TABLE
    Hope this helps!!
    Gabriel

  • Need to make the internal table structure dynamic

    Hi ,
    I need to upload data from an excel file, the columns in the excel keep on varying
    E.g the number of columns in one excel file can be 10, in the second excel file it can be 15.
    So in order to upload the data into an internal table the structre of internal table needs to be dynamic and change according to the number of fields in the input file .
    Is it possible by using field symbols or is there any other method to do the same
    Thanks.
    Nishant
    Edited by: nishant patel on Sep 17, 2009 10:48 AM

    Hi Nishant,
    According to ur requirement, dynamic internal table can be created like below. But database table name has to passed dynacimally.
        DATA: ftab TYPE STANDARD TABLE OF ddfield,
              ftab_wa TYPE ddfield,
              fcat_itab TYPE lvc_t_fcat,
              fcat_wa TYPE lvc_s_fcat,
              poi_itab TYPE REF TO data.
    FIELD-SYMBOLS: <itab> TYPE STANDARD TABLE.
        CALL FUNCTION 'DD_NAMETAB_TO_DDFIELDS'
          EXPORTING
            tabname  = p_table  " Pass database table name dynamically
          TABLES
            ddfields = ftab.
        LOOP AT ftab INTO ftab_wa.
          fcat_wa-fieldname = ftab_wa-fieldname.
          fcat_wa-ref_field = ftab_wa-fieldname.
          fcat_wa-ref_table = p_table.
          APPEND fcat_wa TO fcat_itab.
        ENDLOOP.
        CALL METHOD cl_alv_table_create=>create_dynamic_table
          EXPORTING
            it_fieldcatalog           = fcat_itab
          IMPORTING
            ep_table                  = poi_itab
          EXCEPTIONS
            generate_subpool_dir_full = 1
            OTHERS                    = 2.
        ASSIGN poi_itab->* TO <itab>.  " <itab> is dynamic internal table
    Might help u.
    Thanks.
    Edited by: Sap Fan on Sep 17, 2009 1:19 PM

  • How to convert internal table with dynamic fields to XML

    Dear all,
    I met a problem like the following:
    The aim is to transform the following parameter to XML
    IT_FIELD stores the dynamic filed name of the internal table,with these fields, the dynamic internal can be created by cl_abap_tabledescr=>create(it_field)
    IT_VALUE stores the value of the internal table dynamically created with dynamic fields.
    For example
    IT_FIELD =>
    line1: FIELD1
    line2: FIELD2
    line3: FIELD3,
    three lines in this internal table.
    dynamically created internal table structure FIELD1 FIELD2 FIELD3
    And IT_VALUE=>
    1          2          3   (First line)
    11        22        33
    two lines of data.
    Do you have any idea about how to transform the IT_VALUE to XML here? And also the transformed XML to the IT_VALUE.( we may need remember IT_FIELD here for later XML to IT_VALUE.)
    Hope I describe the problem clearly.
    Any inputs will be appreciated.
    Edited by: Max Tang on Jan 12, 2009 3:46 PM
    Edited by: Max Tang on Jan 12, 2009 4:14 PM

    Hi,
    you need to implement a bit of coding for that.
    With the 'do varying' statement abap provides a loop over those fields. Within this loop you can build up a new internal table with one entry for each period and amount.
    kind regards
    Siggi
    PS: I am not very familiar with CO, but I guess there will be a standard extractor for that.

  • Updating internal table with CSV file

    I have a flat file as below:
    aaaa, bbbb, asdc, dfgfhg, sdfsg, sdf, sdf, sdf, dfg, sdf, sgf, drgftfgh, sgf, drgtf, swftgd, sgf,
    'sjhdfjhf','2003-10-11 07:52:37','167','alkjd',NULL,NULL,NULL,NULL,NULL,'MX1',NULL,NULL,'dkjffdj ,',NULL,NULL,NULL,'1',NULL,NULL,'AR, dfkj ',
    Where we can see it is separated by commas.I want to upload this one into onr internal table.I used GUI_UPLOAD and gave the logic as folows:
    TYPES: BEGIN OF ttab,
    rec(1000) TYPE c,
    END OF ttab.
    TYPES: BEGIN OF tdat,
    aaaa type char10
    bbbb type char10,
    asdc  type char10,
    dfgfhg  type char10,
    sdfsg  type char10,
    sdf  type char10,
    sdf  type char10,
    sdf  type char10,
    dfg   type char10,
    sdf    type char10,
    sgf  type char10,
    drgftfgh  type char10,
    sgf  type char10,
    drgtf  type char10,
    swftgd  type char10,
    sgf  type char10,
    END OF tdat.
    DATA: itab TYPE TABLE OF ttab WITH HEADER LINE.
    DATA: idat TYPE TABLE OF tdat WITH HEADER LINE.
    DATA: file_str TYPE string.
    PARAMETERS: p_file TYPE localfile.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
    CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
    EXPORTING
    static = 'X'
    CHANGING
    file_name = p_file.
    START-OF-SELECTION.
    file_str = p_file.
    CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
    filename = file_str
    TABLES
    data_tab = itab
    EXCEPTIONS
    file_open_error = 1
    file_read_error = 2
    no_batch = 3
    gui_refuse_filetransfer = 4
    invalid_type = 5
    no_authority = 6
    unknown_error = 7
    bad_data_format = 8
    header_not_allowed = 9
    separator_not_allowed = 10
    header_too_long = 11
    unknown_dp_error = 12
    access_denied = 13
    dp_out_of_memory = 14
    disk_full = 15
    dp_timeout = 16
    OTHERS = 17.
    LOOP AT itab.
    CLEAR idat.
    SPLIT itab-rec AT ',' INTO idat-aaaa
    idat-bbbb ,
    idat-asdc  ,
    idat-dfgfhg  ,
    idat-sdfsg  ,
    idat-sdf  ,
    idat-sdf  ,
    idat-sdf  ,
    idat-dfg   ,
    idat-sdf    ,
    idat-sgf  ,
    idat-drgftfgh  ,
    idat-sgf  ,
    idat-drgtf  ,
    idat-swftgd  ,
    idat-sgf  ,
    APPEND idat.
    ENDLOOP.
    Now the issue is when I use the statement SPLIT itab-rec AT ',' this is not updating the table idat properly.Because the flat file contains the value as 'dkjffdj ,', too.
    Can anyone give me some solution to update the internal table.

    hI
    or you delete ' from csv file before uploading it or after uploading it, in this last case u can use statament replace:
    REPLACE ''' WITH SPACE INTO ITAB-FIELD.
    Max

  • Dynamic internal table and dynamic read statements.

    Hi,
    My Scenario :
    I have two dynamic internal tables.
    I am looping at one internal table and trying to read another table.
    In the read statement how do I mention the key dyamically.
    Example code below :
      LOOP AT <dyn_table> ASSIGNING <dyn_wa>.
    read second  dynamic internal table.
      enloop.
    The key which I want use for reading say it is keyed in the selection criteria....
    Also based on the value I read I want to modify the first internal table field value.
    Remember I dont want to explicity mention the key
    How do I do that?
    Thanks
    Krishna.

    Hi
    U need to use the field-symbol, but u can't use a WHERE option, but u need to use the CHECK statament into the second loop:
    LOOP AT <dyn_table> ASSIGNING <dyn_wa>.
        LOOP AT <DYN_TABLE2> ASSIGNING <DYN_WA2>.
            ASSIGN COMPONENT <COMPONENT> OF STRUCTURE   <DYN_WA2> TO <FS>.
            CHECK <FS> IN (=) .......
                ASSIGN COMPONENT <COMPONENT> OF STRUCTURE   <DYN_WA> TO <FS2>.
                <FS2> = .......
                EXIT.
        ENDLOOP.
    ENDLOOP.
    Max

Maybe you are looking for

  • Youtube is not working on my Safari. I have an iPad 3 wifi. Help please!

    Youtube videos are not working on my Safari browser. But can be played on the Youtube app. Any suggestions?

  • Help with Subscriber Services Reset

    What are Subscriber Services on iPad? and where would I find the 26 digit Authentication Key?

  • Jsf + cocoon

    Hi, I need links / resource which will give me some information and example on how to integrate jsf and cocoon. ( i have searched with google, but not much helpful, got a few articles about integration advantages, but seldom examples). I am using jbo

  • Can I increase the number of downloads greater than 6?

    I am downloading a bunch of short films roughly 25 to 40 minutes each. I am using Time Warner Cable with a download speed of 30 mpbs. I noticed that I can only download 6 films at one time using Firefox. When one of them is finished, then I can downl

  • Server not found pops up several times when trying to get anywhere.

    Every time I click on the Mozilla Firefox icon to bring up the basic page with the Google bar and I enter a Q for my home page or a Q for my university (Grand Canyon), which uses Firefox, hence my reason for using Firefox, or even if I am just using