Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

update table from dynamic internal table

Former Member
0 Kudos

Hi all.

i will explain my requirement briefly, i have to create an dynamic ALV report, in selection screen user will give the table name and one field i.e date.

i am displaying all the records of the table given by the user, and one more column at the end (in alv output) . User will update only this last column, and i have to update the DATBI field of that table from this one, as this last field in alv is not there in the table, no data gets updated.

some tables has many key fields .

My internal table is field symbols type standard table, hence i can not change its fields value. as the type is unknown.

i want to swap the values of the fields of this field symbol. the last field value user will change with the datbi field of that table .

3 REPLIES 3

rosenberg_eitan
Active Contributor
0 Kudos

Hi,

How did you crate this internal table ?

If the target table is known you can create dynamic internal table table based on fields from this table .

You can use RTTS .

Do a google using search operators:

site:scn.sap.com cl_abap_structdescr=>create

site:scn.sap.com cl_abap_tabledescr=>create

regards. 

0 Kudos

i have created my internal table in this manner only using the rtts. but in the output i am showing one extra field, which needs to be assigned to the datbi field of the table which the user will give.

also till the runtime the structure of the internal table is unknown .

rosenberg_eitan
Active Contributor
0 Kudos

Hi,

I hope that you change only Z tables .

Here is a sample program fragment that update a field (none key field) based on table name and field name .

Regards.

REPORT  y_r_eitan_test_04_09.

TYPE-POOLS: abap .

START-OF-SELECTION .

  PERFORM at_start_of_selection .

*----------------------------------------------------------------------*

*----------------------------------------------------------------------*

FORM at_start_of_selection .

* table creation .

  CONSTANTS: c_tabname   TYPE dd03l-tabname   VALUE 'SFLIGHT' .

  CONSTANTS: c_fieldname TYPE dd03l-fieldname VALUE 'PRICE'   .

  DATA: it_dfies  TYPE ddfields .

  FIELD-SYMBOLS: <st_dfies> LIKE LINE OF it_dfies .

  CALL FUNCTION 'DDIF_FIELDINFO_GET'

    EXPORTING

      tabname        = c_tabname

    TABLES

      dfies_tab      = it_dfies

    EXCEPTIONS

      not_found      = 1

      internal_error = 2

      OTHERS         = 3.

  DATA: it_component TYPE abap_component_tab .

  DATA: st_component LIKE LINE OF it_component .

  LOOP AT it_dfies ASSIGNING <st_dfies> .

    st_component-name = <st_dfies>-fieldname .

    st_component-type ?= cl_abap_elemdescr=>describe_by_name( <st_dfies>-rollname ).

    APPEND st_component TO it_component.

  ENDLOOP .

  DATA: ob_abap_structdescr TYPE REF TO cl_abap_structdescr,

        ob_abap_tabledescr  TYPE REF TO cl_abap_tabledescr .

  TRY.

      ob_abap_structdescr = cl_abap_structdescr=>create( p_components = it_component ).

    CATCH cx_sy_struct_creation .

  ENDTRY.

  TRY.

      ob_abap_tabledescr = cl_abap_tabledescr=>create( ob_abap_structdescr ).

    CATCH cx_sy_table_creation .

  ENDTRY.

  DATA: r_data_tab    TYPE REF TO data,

        r_data_str    TYPE REF TO data.

  CREATE DATA: r_data_tab TYPE HANDLE ob_abap_tabledescr  ,

               r_data_str TYPE HANDLE ob_abap_structdescr .

  FIELD-SYMBOLS: <it_data> TYPE INDEX TABLE,

                 <st_data>    TYPE ANY.

  ASSIGN: r_data_tab->* TO <it_data> ,

          r_data_str->* TO <st_data> .

  SELECT * INTO CORRESPONDING FIELDS OF TABLE <it_data>

  FROM (c_tabname) UP TO 10 ROWS .

* Assuming at this point that the data is presenterd to the user via cl_gui_alv_grid .

* We know the table structure so we can also generate the field catalog .

* We simulate it by changing the data in the internal table

  FIELD-SYMBOLS: <component> TYPE ANY .

  LOOP AT <it_data> ASSIGNING <st_data> .

    ASSIGN COMPONENT c_fieldname OF STRUCTURE <st_data> TO <component> .

    <component> = sy-tabix * 100 + '0.55'  .

  ENDLOOP.

* Now it is time to update the table .

  BREAK-POINT .

  MODIFY (c_tabname) FROM TABLE <it_data> .

  COMMIT WORK AND WAIT .

* We can regenarate the data using  SAPBC_DATA_GENERATOR

ENDFORM .                    "at_start_of_selection