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

Populate Dynamic Table using field symbol

Former Member
0 Likes
1,077

hi,

I'm newbie in dynamic table.

I have 1 internal table called ta_output as defined below:

data : begin of ta_ouput occurs 0,

rowPos(10) type i,

colPos(10) type i,

level(1) type i,

text(200) type c,

end of ta_output.

Ta_OUTPUT has been populated like below:

rowPos colPos level text

1 1 A Shop

1 2 A Condominium

1 3 A School

2 1 B 100

2 2 B 5

2 3 B 12

3 1 B 40

3 2 B 16

3 3 B 10

4 1 B 0

4 2 B 25

4 3 B 7

How to populate dynamic listing like below using that ta_output:

Shop Condominium School

100 5 12

40 16 10

0 25 7

2 REPLIES 2
Read only

Former Member
0 Likes
427

Hi,

Check this code

type-pools : abap.


field-symbols: <dyn_table> type standard table,
               <dyn_wa>,
               <dyn_field>.

data: dy_table type ref to data,
      dy_line  type ref to data,
      xfc type lvc_s_fcat,
      ifc type lvc_t_fcat.

data : idetails type abap_compdescr_tab,
       xdetails type abap_compdescr.

data : ref_table_des type ref to cl_abap_structdescr.
data : begin of ta_ouput occurs 0,
rowPos(10) type i,
colPos(10) type i,
level(1) type i,
text(200) type c,
end of ta_output.

* Get the structure of the table.

    xfc-fieldname = 'ROWPOS' .
    xfc-inttype = 'CHAR'.
    xfc-intlen = '10'.
    append xfc to ifc.

    xfc-fieldname = 'COLPOS' .
    xfc-inttype = 'CHAR'.
    xfc-intlen = '10'.
    append xfc to ifc.

    xfc-fieldname = 'LEVEL' .
    xfc-inttype = 'CHAR'.
    xfc-intlen = '1'.
    append xfc to ifc.

    xfc-fieldname = 'TEXT' .
    xfc-inttype = 'CHAR'.
    xfc-intlen = '200'.
    append xfc to ifc.

* Create dynamic internal table and assign to FS
  call method cl_alv_table_create=>create_dynamic_table
               exporting
                  it_fieldcatalog = ifc
               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>.

* MOVE oyur data accordingly into it.

* Write out data from table.
  loop at <dyn_table> into <dyn_wa>.
    do.
      assign component  sy-index  
         of structure <dyn_wa> to <dyn_field>.
      if sy-subrc <> 0.
        exit.
      endif.
      if sy-index = 1.
        write:/ <dyn_field>.
      else.
        write: <dyn_field>.
      endif.
    enddo.
  endloop.

hope this helps.

Thanks,

Prashanth

Read only

Former Member
0 Likes
427

DATA : wa_fcat TYPE lvc_s_fcat,

it_fcat TYPE lvc_t_fcat.

FIELD-SYMBOLS: <fs_table> TYPE table,

<fs_any> TYPE ANY,

<fs_wa> TYPE ANY,

DATA : it_tab TYPE REF TO data.

*creating the structure

wa_fcat-fieldname = 'MATNR'.

wa_fcat-tabname = 'IT_TAB'.

wa_fcat-reptext = 'Material'.

wa_fcat-outputlen = 15.

APPEND wa_fcat TO it_fcat.

wa_fcat-fieldname = 'MAKTX'.

wa_fcat-tabname = 'IT_TAB'.

wa_fcat-reptext = 'Material Desc.'.

wa_fcat-outputlen = 35.

APPEND wa_fcat TO it_fcat.

*method for dynamic table

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

  • i_style_table =

it_fieldcatalog = it_fcat

  • i_length_in_byte =

IMPORTING

ep_table = it_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 it_tab->* TO <fs_table> .

CREATE DATA wa_line LIKE LINE OF <fs_table>.

ASSIGN wa_line->* TO <fs_wa>.

loop at it_final into wa_final. "table in which ur data is there

*material

ASSIGN COMPONENT c_mat OF STRUCTURE <fs_wa> TO <fs_any>.

<fs_any> = wa_final-matnr.

UNASSIGN <fs_any>.

*mat. desc

ASSIGN COMPONENT c_mat_desc OF STRUCTURE <fs_wa> TO <fs_any>.

<fs_any> = wa_final-maktx.

UNASSIGN <fs_any>.

APPEND <fs_wa> TO <fs_table>.

endloop.

call function to display list.

Regards,

Anagha Deshmukh