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: 
Read only

Assinging values to a dynamic structure.

Former Member
0 Likes
1,399

I've created a dynamic table from an internal table only if certain conditions are met.

Unfortuantely once i've created this structure, i can't assing any values or create rows in the table because i don't know the fieldnames.

I want to access the component number of the structure or some how pass the pass the field name to the work area to assing values, is there a way to get around this ? i've been searching for a few days with no luck.

Any value i try to assign, goes to the first field of the dynamic table, i want to assign values to maybe 4th or 5th compoenent of the table.

DATA : lt_fieldcat type lvc_t_fcat,
            wt_fieldcat type lvc_s_fcat.

DATA : lt_table    type ref to data,
            lt_line     type ref to data.

FIELD-SYMBOLS : 

             <lt_ctc> type standard table,

              <wt_line>   type any,
              <wt_val>  type any,

DATA: l_tabledescr_ref TYPE REF TO cl_abap_tabledescr,
           l_descr_ref      TYPE REF TO cl_abap_structdescr,
           lt1 TYPE TABLE OF abap_compdescr,
           wt1 TYPE abap_compdescr.

Data :  wt_con(64)  type c value  'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ',

    LOOP AT lt_lgtxt assigning <wt_lgtxt>.
    CONDENSE <wt_lgtxt>-lgtxt no-gaps.
    IF <wt_lgtxt>-lgtxt CO wt_con.
      wt_fieldcat-col_pos = sy-tabix.
      wt_fieldcat-col_opt = 'X'.
      wt_fieldcat-inttype = 'STRING'.
      wt_fieldcat-reptext = <wt_lgtxt>-lgtxt.
      wt_fieldcat-fieldname = <wt_lgtxt>-lgtxt.
      APPEND wt_fieldcat to lt_fieldcat.
    ENDIF.
  ENDLOOP.

  

  CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING
      it_fieldcatalog = lt_fieldcat
    IMPORTING
      ep_table        = lt_table.

  ASSIGN lt_table->* TO <lt_ctc>.
  CREATE DATA lt_line LIKE LINE OF <lt_ctc>.
  ASSIGN lt_line->* TO <wt_line>.


  l_tabledescr_ref ?= cl_abap_typedescr=>describe_by_data( <lt_ctc> ).
  l_descr_ref ?= l_tabledescr_ref->get_table_line_type( ).

  LOOP AT l_descr_ref->components INTO wt1 .
    APPEND wt1 to lt1.
  ENDLOOP.


  LOOP AT lt_wages assigning <wt_wages>.
    ASSIGN COMPONENT <wt_wages>-cpos OF STRUCTURE <wt_line> TO <wt_val>.
    <wt_val> = <wt_wages>-bet02.
    MOVE <wt_val> to <wt_line>.
    Append <wt_line> to <lt_ctc>.
    CLEAR  <wt_line>.
  ENDLOOP.

In the last loop, i want to assing the value of say the 5th component of the structure to the 8 componenet of the dynamic table. But insterad it goes to the first.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,139

Hi,

Your fieldcatalog has all the fields in the Internal table. Do something like this.

LOOP AT lt_wages assigning <wt_wages>.

LOOP AT lt_fieldcat INTO ls_fieldcat.

ASSIGN COMPONENT ls_fieldcat-fieldname OF structure <wt_line> TO <wt_val>.

ASSIGN COMPONENT ls_fieldcat-fieldname OF structure <wt_wages> TO <wt_from>.

IF sy-subrc = 0

<wt_val> = <wt_from>.

ENDIF.

ENDLOOP.

Append <wt_line> to <lt_ctc>.

    CLEAR  <wt_line>.

ENDLOOP.

Thanks,

Shambu

Hi,

Your fieldcatalog has all the fields in the Internal table. Do something like this.

LOOP AT lt_wages assigning <wt_wages>.

LOOP AT lt_fieldcat INTO ls_fieldcat.

ASSIGN COMPONENT ls_fieldcat-fieldname OF structure <wt_line> TO <wt_val>.

ASSIGN COMPONENT ls_fieldcat-fieldname OF structure <wt_wages> TO <wt_from>.

IF sy-subrc = 0

<wt_val> = <wt_from>.

ENDIF.

ENDLOOP.

Append <wt_line> to <lt_ctc>.

    CLEAR  <wt_line>.

ENDLOOP.

Thanks,

Shambu

2 REPLIES 2
Read only

Former Member
0 Likes
1,140

Hi,

Your fieldcatalog has all the fields in the Internal table. Do something like this.

LOOP AT lt_wages assigning <wt_wages>.

LOOP AT lt_fieldcat INTO ls_fieldcat.

ASSIGN COMPONENT ls_fieldcat-fieldname OF structure <wt_line> TO <wt_val>.

ASSIGN COMPONENT ls_fieldcat-fieldname OF structure <wt_wages> TO <wt_from>.

IF sy-subrc = 0

<wt_val> = <wt_from>.

ENDIF.

ENDLOOP.

Append <wt_line> to <lt_ctc>.

    CLEAR  <wt_line>.

ENDLOOP.

Thanks,

Shambu

Read only

0 Likes
1,139

Thanks a lot.

You solved my problem.