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

Fill a dynamic table by column

former_member215107
Active Participant
0 Likes
877

Dear All,

I search without success how i can fill a dynamic table or a table by column.

I have an internal table of a column and a dynamic table of 100 column.

I want make a loop to fill each column of the dynamic table from the column of my internal table (values change for each loop)

Thanks for your help

Rodolphe.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
825

You can do it by using ASSIGN statement with option COMPONENT comp OF STRUCTURE struc.

Check this link for more details.

[http://help.sap.com/saphelp_wp/helpdata/en/fc/eb3923358411d1829f0000e829fbfe/content.htm]

Dear All,

I search without success how i can fill a dynamic table or a table by column.

I have an internal table of a column and a dynamic table of 100 column.

I want make a loop to fill each column of the dynamic table from the column of my internal table (values change for each loop)

Thanks for your help

Rodolphe.

4 REPLIES 4
Read only

Former Member
0 Likes
826

You can do it by using ASSIGN statement with option COMPONENT comp OF STRUCTURE struc.

Check this link for more details.

[http://help.sap.com/saphelp_wp/helpdata/en/fc/eb3923358411d1829f0000e829fbfe/content.htm]

Read only

former_member585060
Active Contributor
0 Likes
825

Hi,

Try with below code.

* Data declaration for Internal table creation
DATA: i_new_table  TYPE REF TO data,             " Internal Table
      wa_new_line  TYPE REF TO data,             " Workarea
      wa_lvc_cat   TYPE lvc_s_fcat,               " Fieldcatalog LS
      i_lvc_cat    TYPE lvc_t_fcat.               " Fieldcatalog IT

* Field symbols
FIELD-SYMBOLS: <i_table>  TYPE table,            " For Table
               <wa_line>  TYPE ANY,              " For Workarea
               <v_field>  TYPE ANY.              " For Field


LOOP AT i_column INTO wa_column.

     lv_cpos = lv_cpos + 1.

      wa_lvc_cat-fieldname = wa_column-field.
      wa_lvc_cat-reptext = wa_column-field.
      wa_lvc_cat-coltext   = wa_column-field.
      wa_lvc_cat-outputlen = 10.
      wa_lvc_cat-col_pos   = lv_cpos.
      APPEND wa_lvc_cat TO i_lvc_cat.

CLEAR : wa_column, wa_lvc_cat.

ENDLOOP.


* Create a new Table
  CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING
      it_fieldcatalog = i_lvc_cat
    IMPORTING
      ep_table        = i_new_table.

* Assign the table to a field symbol
  ASSIGN i_new_table->* TO <i_table>.

* Create a workarea of table structure
  CREATE DATA wa_new_line LIKE LINE OF <i_table>. " Internal table

* Assign to a field symbol
  ASSIGN wa_new_line->* TO <wa_line>.        " Work area

If you have field length and text as well in your column internal table pass them.

Regards

Bala Krishna

Read only

former_member215107
Active Participant
0 Likes
825

Hello,

When I try the following code, here the result in my table:

COLUMN1__COLUMN2__COLUMN3

A

B

C

______________D

______________E

______________F

________________________G

I would like this result:

COLUMN1__COLUMN2__COLUMN3

A____________D_________G

B____________E_________

C____________F_________

Here my code:

DATA: dy_table TYPE REF TO data,

dy_line TYPE REF TO data.

FIELD-SYMBOLS: <dyn_table> TYPE STANDARD TABLE,

<dyn_wa>,

<fs>.

  • Compute the total length of ZTABLE_CHECK_ROL

select * from ZTABLE_CHECK_ROL.

endselect.

i_table_length = sy-dbcnt.

  • Create Field Catalog

ICount = 1.

DO i_table_length TIMES.

c_tmpchar = ICount.

concatenate 'COL' c_tmpchar into ls_fcat-fieldname.

CONDENSE ls_fcat-fieldname NO-GAPS.

ls_fcat-ref_field = 'NAMEROLE'.

ls_fcat-ref_table = 'ZTABLE_CHECK_ROL'.

APPEND ls_fcat TO lt_fcat.

CLEAR: ls_fcat, c_tmpchar.

ICount = ICount + 1.

ENDDO.

  • Create dynamic internal table and assign to FS

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = lt_fcat

IMPORTING

ep_table = dy_table.

ASSIGN dy_table->* TO <dyn_table>.

  • Create dynamic work area and assign to FS

CREATE DATA dy_line LIKE LINE OF <dyn_table>.

ASSIGN dy_line->* TO <dyn_wa>.

  • 1- Create internal table which lists a role and its associated users

  • 2- Affect the internal table to a column of an internal table

ICount = 1.

select * from ZTABLE_CHECK_ROL into wa_ZTABLE_CHECK_ROL.

  • select UNAME from AGR_USERS into table INTERNTABLE_USERLIST

select UNAME from AGR_USERS into wa_uname

where AGR_NAME = wa_ZTABLE_CHECK_ROL-NAMEROLE.

c_tmpchar = ICount.

concatenate 'COL' c_tmpchar into l_col.

CONDENSE l_col NO-GAPS.

ASSIGN COMPONENT l_col OF STRUCTURE <dyn_wa> TO <fs>.

IF SY-SUBRC = 0.

  • <fs> = INTERNTABLE_USERLIST.

<fs> = wa_uname.

ENDIF.

UNASSIGN <fs>.

APPEND <dyn_wa> TO <dyn_table>.

endselect.

  • Treatment of the next role

ICount = ICount + 1.

endselect.

Thanks a lot for your help

Rodolphe.

Read only

0 Likes
825

Hi,

In your code for preparing the fieldcatalog, the column position is missing, add that.

DO i_table_length TIMES.

c_tmpchar = ICount.
concatenate 'COL' c_tmpchar into ls_fcat-fieldname.
CONDENSE ls_fcat-fieldname NO-GAPS.

ls_fcat-ref_field = 'NAMEROLE'.
ls_fcat-ref_table = 'ZTABLE_CHECK_ROL'.
ls_fcat-col_pos = ICount.                           " this missing in your code, it will specify the field column no

APPEND ls_fcat TO lt_fcat.
CLEAR: ls_fcat, c_tmpchar.
ICount = ICount + 1.

ENDDO.

Instead of SELECT and ELDSELECT, try to fetch all the records in single hit to database and then loop that table, as with your code, for each entry it will access the database that many times, it may effect the performance of the program.

Regards

Bala Krishna