Application Development and Automation 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: 

create dynamic table assigning field symbol problem

Former Member
0 Kudos
878

Hi floks,

i declared dynamic tyble and got structure . but when i going to assigning data from work area ti internal table i am getting error . igiven below code and error . please help me out . how to assign it and how to get back to it internal table or out put..

ref_table_des ?=

cl_abap_typedescr=>describe_by_name( 'YPPLAN_DOWNL_UPL_STRUCT1' ).

idetails[] = ref_table_des->components[].

loop at idetails into xdetails.

clear xfc.

xfc-fieldname = xdetails-name .

xfc-datatype = xdetails-type_kind.

xfc-inttype = xdetails-type_kind.

xfc-intlen = xdetails-length.

xfc-decimals = xdetails-decimals.

append xfc to ifc.

endloop.

call method cl_alv_table_create=>create_dynamic_table

exporting

it_fieldcatalog = ifc

importing

ep_table = dy_table.

assign dy_table->* to <gt_output_dy>.

assign dy_table->* to <gt_imp_exp>.

create data dy_line like line of <gt_output_dy>.

assign dy_line->* to <fs_output>.

LOOP AT <gt_output_dy> ASSIGNING <fs_output>.

wa_matnr_list-matnr = <fs_output>-matnr.

wa_matnr_list-werks = <fs_output>-werks.

IF wa_matnr_list-matnr CO '0123456789. '.

SHIFT wa_matnr_list-matnr RIGHT DELETING TRAILING space.

OVERLAY wa_matnr_list-matnr WITH lpad18.

ENDIF.

APPEND wa_matnr_list TO it_matnr_list.

ENDLOOP.

+Error: The data object "<FS_OUTPUT>" has no structure and therefore no component called "MATNR".

<removed_by_moderator>

thanks ,

Sunitha +

Edited by: Julius Bussche on Jul 28, 2008 9:34 PM

6 REPLIES 6

Former Member
0 Kudos
244

Check the sample code

REPORT  ytest_dynamic.
TYPE-POOLS : abap.
DATA : table_des TYPE REF TO cl_abap_structdescr.
DATA : ifields TYPE abap_compdescr_tab,
       wa_field LIKE LINE OF ifields.
DATA: it_fieldcat TYPE lvc_t_fcat,
      wa_fieldcat TYPE lvc_s_fcat.
data: i_tab type ref to data.

      field-symbols: <fs> type standard table.

PARAMETERS: p_table(30) type c default 'SFLIGHT'.


"Table definiton using the table name
table_des ?= cl_abap_typedescr=>describe_by_name( p_table ).
"Now Read all the fields to a table.
ifields = table_des->components.


LOOP AT ifields INTO wa_field.
clear wa_fieldcat.
  wa_fieldcat-fieldname = wa_field-name .
    wa_fieldcat-datatype = wa_field-type_kind.
    wa_fieldcat-inttype = wa_field-type_kind.
    wa_fieldcat-intlen = wa_field-length.
    wa_fieldcat-decimals = wa_field-decimals.
    APPEND  wa_fieldcat TO it_fieldcat.
ENDLOOP.

CALL METHOD cl_alv_table_create=>create_dynamic_table
  EXPORTING
    it_fieldcatalog           = it_fieldcat
*    i_length_in_byte          =
  IMPORTING
    ep_table                  = i_tab
*    e_style_fname             =
  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 i_tab->* to <fs>.

*-fill the data

select  *
into table <fs>
from (p_table)
up to 20 rows.

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos
244

You can not reference those fields, because the structure if built dynamically at runtime, so you must use the ASSIGN COMPONENT statement.

Field-symbols: <fs_field> type any.

LOOP AT <gt_output_dy> ASSIGNING <fs_output>.

assign component 'MATNR' of structure <fs_output> to <fs_field>.
if sy-subrc = 0.
  wa_matnr_list-matnr  = <fs_field>.
endif.

assign component 'WERKS' of structure <fs_output> to <fs_field>.
if sy-subrc = 0.
  wa_matnr_list-werks  = <fs_field>.
endif.

IF wa_matnr_list-matnr CO '0123456789. '.
SHIFT wa_matnr_list-matnr RIGHT DELETING TRAILING space.
OVERLAY wa_matnr_list-matnr WITH lpad18.
ENDIF.
APPEND wa_matnr_list TO it_matnr_list.
ENDLOOP.

Regards,

Rich Heilman

0 Kudos
244

Hi,

Thanks for the quick responce...

Still I have problem.

field-symbols: <gt_output_dy> type standard table,

<gt_imp_exp> type standard table,

<fs_imp_exp>,

<fs_output> type any,

<wa_imp_exp>,

<wa_output>.

LOOP AT <gt_output_dy> ASSIGNING <fs_output>.

assign component 'MATNR' of structure <fs_output> to <fs_field>.

if sy-subrc = 0.

wa_matnr_list-matnr = <fs_field>.

endif.

ENDLOOP.

Actually the other side 'wa_matnr_list-matnr' dynamic table. Then how to assign the value for this...

0 Kudos
244

can you elaborate you're question a bit more ?? I don't understand what is the problem in the code of rich that you don't understand <field> contains the value of matnr !

kind regards

arthur de smidt

Former Member
0 Kudos
244

For accessing the components with out referring to the Fieldnames

you can do this way...

field-symbols: <fs_wa>  ,
                     <fs_field> .
data: wa_line type ref to data.

* Create dynamic work area 
  CREATE DATA wa_line LIKE LINE OF <fs>.
  ASSIGN wa_line->* TO <fs_wa>.

  LOOP AT <fs> INTO <fs_wa>.
    DO.
      ASSIGN COMPONENT sy-index
      OF STRUCTURE <fs_wa> TO <fs_field>.
      IF sy-subrc ne 0.
        EXIT.
      ENDIF.
      IF sy-index = 1.
        WRITE:/ <fs_field>.
      ELSE.
        WRITE: <fs_field>.
      ENDIF.
    ENDDO.
  ENDLOOP.

Regards

Vijay Babu Dudla

former_member705122
Active Contributor
0 Kudos
244

Hi,

Check this sample code,

DATA:
  o_ref TYPE REF TO data.
FIELD-SYMBOLS:
  <lt_table> TYPE STANDARD TABLE,
  <fs>       TYPE ANY,
  <field>    TYPE ANY,
  <field1>   TYPE ANY.
PARAMETERS:
  p_tab       TYPE tabname,           " Table name (eg: MARA)
  p_field(20) TYPE c.                 " Field name (eg: MATNR)

START-OF-SELECTION.
  CREATE DATA o_ref TYPE TABLE OF (p_tab).

  ASSIGN p_field TO <field1>.
  ASSIGN o_ref->* TO <lt_table>.

  SELECT *
    INTO TABLE <lt_table>
    FROM (p_tab).

  LOOP AT <lt_table> ASSIGNING <fs>.
    ASSIGN COMPONENT <field1> OF STRUCTURE <fs>
                  TO <field>.
    IF sy-subrc = 0.
      WRITE:/ <field>.
    ENDIF.
  ENDLOOP.

*-----------------------------------------------*
*  give input as :
*  p_tab   : mara
*  p_field : matnr.
*-----------------------------------------------*

for more info check this link:

https://www.sdn.sap.com/irj/sdn/profile?editmode=true&userid=3767537

Regards

Adil

Regards

Adil