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

Reg: Internal table

0 Likes
447

Hi,

I have one internal table say itab1 with one field(material number). The field contains values say for eg : 5 values (5 material numbers).

Now i want to create another internal table with the above 5 material numbers as 5 fields.

How can i do this?

Can anyone help me in this regard.

Thanks

Vijayasree

1 ACCEPTED SOLUTION
Read only

MarcinPciak
Active Contributor
0 Likes
409

Hi,

You have to use dynamic table for this:


DATA: BEGIN OF it_matnr OCCURS 0,
        matnr TYPE afpo-matnr,
      END OF it_matnr.

DATA: it_fcat TYPE lvc_t_fcat WITH HEADER LINE.   "fieldcatalog for dynamic table

FIELD-SYMBOLS: <fs_matnr> TYPE afpo-matnr,
                           <fs_dyntab> TYPE table, <fs_watab>.

"pointer to dynamic table
DATA: it_dyn TYPE REF TO data.

LOOP AT it_matnr.
  ASSIGN it_matnr-pernr TO <fs_matnr>.
  it_fcat-fieldname = <fs_matnr>.
  it_fcat-ref_field = 'MATNR'.
  it_fcat-ref_table = 'AFPO'.
  APPEND it_fcat.
ENDLOOP.

"create dynamic table based on values as fields
CALL METHOD cl_alv_table_create=>create_dynamic_table
  EXPORTING
    it_fieldcatalog           = it_fcat[]
  IMPORTING
    ep_table                  = it_dyn
  EXCEPTIONS
    generate_subpool_dir_full = 1
    OTHERS                    = 2.

IF sy-subrc = 0.
  "dereference dynamic table
  ASSIGN it_dyn->* TO <fs_dyntab>.
  LOOP AT <fs_dyntab> ASSIGNING <fs_watab>.
     "here <fs_watab> will have line of the table but no structure!
  ENDLOOP.
ENDIF.

Regards

Marcin

2 REPLIES 2
Read only

Former Member
0 Likes
409

Hi

Declare 2 internal tables of same type

itab1[] = itab2[]

Read only

MarcinPciak
Active Contributor
0 Likes
410

Hi,

You have to use dynamic table for this:


DATA: BEGIN OF it_matnr OCCURS 0,
        matnr TYPE afpo-matnr,
      END OF it_matnr.

DATA: it_fcat TYPE lvc_t_fcat WITH HEADER LINE.   "fieldcatalog for dynamic table

FIELD-SYMBOLS: <fs_matnr> TYPE afpo-matnr,
                           <fs_dyntab> TYPE table, <fs_watab>.

"pointer to dynamic table
DATA: it_dyn TYPE REF TO data.

LOOP AT it_matnr.
  ASSIGN it_matnr-pernr TO <fs_matnr>.
  it_fcat-fieldname = <fs_matnr>.
  it_fcat-ref_field = 'MATNR'.
  it_fcat-ref_table = 'AFPO'.
  APPEND it_fcat.
ENDLOOP.

"create dynamic table based on values as fields
CALL METHOD cl_alv_table_create=>create_dynamic_table
  EXPORTING
    it_fieldcatalog           = it_fcat[]
  IMPORTING
    ep_table                  = it_dyn
  EXCEPTIONS
    generate_subpool_dir_full = 1
    OTHERS                    = 2.

IF sy-subrc = 0.
  "dereference dynamic table
  ASSIGN it_dyn->* TO <fs_dyntab>.
  LOOP AT <fs_dyntab> ASSIGNING <fs_watab>.
     "here <fs_watab> will have line of the table but no structure!
  ENDLOOP.
ENDIF.

Regards

Marcin