Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 8995

Re: How to create field symbol

$
0
0

Hello Eyup,

 

first off all, every time, I see such "strange" or complicated requirements, I think, that the solution has not been fully specificied, so that a lot of dynamic coding should solve every problem ;-)

 

Try to work with the database and reduce the complexity of your ABAP statement, for example.

 

At least, you will have to create your own types at runtime, when you will solve this in that dynamic way:

 

Imagine, you have a table

 

lt_accounts type table of zaccount.

 

Now, you can create a new table where the accounts are kolumns instead of keys:

 

    DATA:        table_type TYPE REF TO cl_abap_tabledescr,       struct_type TYPE REF TO cl_abap_structdescr,        comp_tab    TYPE cl_abap_structdescr=>component_table,        comp        LIKE LINE OF comp_tab,        r_data          TYPE REF TO data,        t_data          type ref to data,        oref        TYPE REF TO cx_sy_struct_creation.  FIELD-SYMBOLS: <account> TYPE zaccount.  LOOP AT lt_accounts TRANSPORTING NO FIELDS.    concatenate 'COLUMN' sy-tabix INTO comp-name.    comp-type ?= cl_abap_typedescr=>describe_by_name( ZACCOUNT' ).    APPEND comp TO comp_tab.  ENDLOOP.

* Create the structure ( lines ) 
  TRY.      struct_type = cl_abap_structdescr=>get( comp_tab ).      CREATE DATA r_data TYPE HANDLE struct_type.    CATCH cx_sy_struct_creation INTO oref.      MESSAGE oref TYPE 'I' DISPLAY LIKE 'E'.      RETURN.  ENDTRY.

* Create the table ( lines ) 
  TRY.      table_type = cl_abap_tabledescr=>create( struct_type ).      CREATE DATA t_data TYPE HANDLE table_type.    CATCH cx_sy_struct_creation INTO oref.      MESSAGE oref TYPE 'I' DISPLAY LIKE 'E'.      RETURN.  ENDTRY.

 

The reference "r_data" has now the desired structure with n account columns and t_data is a reference to standard table of lines of r_data.

 

At least: Transport the values:

  FIELD-SYMBOL:     <row>          TYPE any,    <table>          TYPE any table.  ASSIGN:      r_data->* TO <row>,     t_data->* TO <table>  LOOP AT lt_accounts ASSIGNING <ACCOUNT>.     CONCATENATE 'COLUMN' sy-tabix INTO l_column.     ASSIGN COMPONENT l_column OF  <row> TO <value>.     ASSERT sy-subrc = 0.     <value> = <account>.  ENDLOOP.  INSERT <row> INTO TABLE <table>.

 

Kind regards,

Hendrik


Viewing all articles
Browse latest Browse all 8995

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>