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

Moving Values to the Dynamic table

Former Member
0 Likes
1,718

I have create the Dynamic table <fs_table> depending upon the requirements it will have few columns as compared to my i_out table as i_out table has lot of columns.

Now i wanto to move the Corresponding vlues of i_out to <fs_table> how to go for that....


DATA : it_field    TYPE  lvc_t_fcat,
            is_fieldcat LIKE  LINE OF it_field.

DATA : dyn_table TYPE REF TO data,
       dyn_line  TYPE REF TO data.

FIELD-SYMBOLS: <fs_table> TYPE ANY TABLE,
               <fs_line>  TYPE ANY,
               <fs_field> TYPE ANY.

  CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING
      it_fieldcatalog = it_field
    IMPORTING
      ep_table        = dyn_table.

  ASSIGN dyn_table->* TO <fs_table>.
  CREATE DATA dyn_line LIKE LINE OF <fs_table>.
  ASSIGN dyn_line->* TO <fs_line>.

  LOOP AT i_out.
    MOVE-CORRESPONDING i_out TO <fs_table>.
  ENDLOOP.

1 ACCEPTED SOLUTION
Read only

venkat_o
Active Contributor
0 Likes
1,328

Hi Abhishek, I created one program when i was working on HR Appraisal. It might be helpful to u. But I have one question for u . When u want to create dynamic table by calling the method u used, first u have to pass fieldcatalog. But I cant see in ur code. Any how check the below code.


REPORT  zvenkat_hrhap_tables NO STANDARD PAGE HEADING .
"Declarations.
"----------------------------------------------------------------------
"variable
DATA:
      g_table TYPE ddobjname,
      i_table TYPE REF TO data.
TYPES:
      t_dfies TYPE dfies.
DATA:
      w_dfies TYPE t_dfies.
DATA:
      i_dfies TYPE STANDARD TABLE OF t_dfies.

"Field symbols
FIELD-SYMBOLS:
      <i_table> TYPE STANDARD TABLE.
" ALV Declarations
* Types Pools
TYPE-POOLS:
      slis.
" Types
TYPES:
      t_fieldcat_d       TYPE lvc_s_fcat,
      t_events           TYPE slis_alv_event,
      t_layout           TYPE slis_layout_alv.
" Workareas
DATA:
      w_fieldcat_d       TYPE t_fieldcat_d,
      w_events           TYPE t_events,
      w_layout           TYPE t_layout.
" Internal Tables
DATA:
      i_fieldcat_d       TYPE STANDARD TABLE OF t_fieldcat_d,
      i_events           TYPE STANDARD TABLE OF t_events.

" selection-screen
"----------------------------------------------------------------------
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE f_title1.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT (15) text_003 FOR FIELD table.
PARAMETERS :table TYPE rsrd1-tbma_val OBLIGATORY.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN POSITION 1.
PARAMETERS: alv_list RADIOBUTTON GROUP list USER-COMMAND list DEFAULT 'X'.
SELECTION-SCREEN COMMENT (20) text_001 FOR FIELD alv_list.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN POSITION 1.
PARAMETERS : alv_grid RADIOBUTTON GROUP list.
SELECTION-SCREEN COMMENT (20) text_002 FOR FIELD alv_grid.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK b1.

"Initialization
"---------------------------------------------------------------------

INITIALIZATION.

  f_title1 = 'Report Category'.
  text_001 = 'ALV List'.
  text_002 = 'ALV GRID'.
  text_003 = 'Table Name'.

  "Start-of-selection.
*---------------------------------------------------------------------

START-OF-SELECTION.

  " Get Table information given on Selection-screen.
  g_table = table.
  CALL FUNCTION 'DDIF_NAMETAB_GET'
    EXPORTING
      tabname   = g_table
    TABLES
      dfies_tab = i_dfies.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ELSE.
    "Build fieldcatalog to create Dynamic Internal table
    LOOP AT i_dfies INTO w_dfies.
      w_fieldcat_d-fieldname   = w_dfies-fieldname.
      w_fieldcat_d-tabname     = table.
      w_fieldcat_d-ref_table   = table.
      APPEND w_fieldcat_d TO i_fieldcat_d.
      CLEAR  w_fieldcat_d.
    ENDLOOP.
    "Create Dynamic Internal table for the DB table given on Selection-screen.
    CALL METHOD cl_alv_table_create=>create_dynamic_table
      EXPORTING
        it_fieldcatalog = i_fieldcat_d
      IMPORTING
        ep_table        = i_table.
    "Assign dynamic table to field-symbol
    ASSIGN i_table->* TO <i_table>.
    "Get Data from Database table .
    SELECT *
      FROM (table)
      INTO TABLE <i_table>.
  ENDIF.

  "End-of-selection.
  "---------------------------------------------------------------------

END-OF-SELECTION.
  "Build layout structure
  w_layout-zebra             = 'X'.
  w_layout-colwidth_optimize = 'X'.
  "Build events table
  w_events-name = 'TOP_OF_PAGE'.
  w_events-form = 'TOP_OF_PAGE'.
  APPEND w_events TO i_events.
  CLEAR  w_events.
  "Display data using ALV GRID
  PERFORM display_data.
*&---------------------------------------------------------------------*
*&      Form  display_data
*&---------------------------------------------------------------------*
FORM display_data .
  DATA:
       l_program   TYPE sy-repid,
       l_structure TYPE dd02l-tabname,
       l_function  TYPE rs38l-name.

  l_program = sy-repid.
  l_structure = table.
  IF alv_list = 'X'.
    l_function = 'REUSE_ALV_LIST_DISPLAY'.
  ELSEIF alv_grid = 'X'.
    l_function = 'REUSE_ALV_GRID_DISPLAY'.
  ENDIF.
  CALL FUNCTION l_function
    EXPORTING
      i_callback_program     = l_program
*      i_structure_name       = l_structure
      it_fieldcatalog        = i_fieldcat_d
      is_layout              = w_layout
      it_events              = i_events
    TABLES
      t_outtab               = <i_table>
    EXCEPTIONS
      program_error          = 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.


ENDFORM.                    " display_data
*&---------------------------------------------------------------------*
*&      Form  top_of_page
*&---------------------------------------------------------------------*
FORM top_of_page.
  DATA :
        i_header TYPE slis_t_listheader,
        w_header LIKE LINE OF i_header.

  w_header-typ = 'H'.
  CONCATENATE 'Table' ':' table INTO w_header-info.
  APPEND w_header TO i_header.
  CLEAR w_header.

  w_header-typ = 'H'.
  WRITE sy-datum TO w_header-info.
  APPEND w_header TO i_header.
  CLEAR w_header.

  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      it_list_commentary = i_header
      i_logo             = 'ENJOYSAP_LOGO'.

ENDFORM. "top_of_page
 
Regards, Venkat.O

I have create the Dynamic table <fs_table> depending upon the requirements it will have few columns as compared to my i_out table as i_out table has lot of columns.

Now i wanto to move the Corresponding vlues of i_out to <fs_table> how to go for that....


DATA : it_field    TYPE  lvc_t_fcat,
            is_fieldcat LIKE  LINE OF it_field.

DATA : dyn_table TYPE REF TO data,
       dyn_line  TYPE REF TO data.

FIELD-SYMBOLS: <fs_table> TYPE ANY TABLE,
               <fs_line>  TYPE ANY,
               <fs_field> TYPE ANY.

  CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING
      it_fieldcatalog = it_field
    IMPORTING
      ep_table        = dyn_table.

  ASSIGN dyn_table->* TO <fs_table>.
  CREATE DATA dyn_line LIKE LINE OF <fs_table>.
  ASSIGN dyn_line->* TO <fs_line>.

  LOOP AT i_out.
    MOVE-CORRESPONDING i_out TO <fs_table>.
  ENDLOOP.

4 REPLIES 4
Read only

Former Member
0 Likes
1,328

Please check the below code for different scenarios.

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.

selection-screen begin of block b1 with frame.

parameters: p_table(30) type c default 'T001'.

selection-screen end of block b1.

start-of-selection.

perform get_structure.

perform create_dynamic_itab. *********Creates a dyanamic internal table*********

perform get_data.

perform write_out.

form get_structure.

data : idetails type abap_compdescr_tab,

xdetails type abap_compdescr.

data : ref_table_des type ref to cl_abap_structdescr.

  • Get the structure of the table.

ref_table_des ?=

cl_abap_typedescr=>describe_by_name( p_table ).

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.

endform.

form create_dynamic_itab.

  • 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>.

endform.

form get_data.

  • Select Data from table.

select * into table <dyn_table>

from (p_table).

endform.

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.

-


REPORT ZCLUST1 .

  • Example: how to create a dynamic internal table

  • The dynamic internal table stucture

DATA: BEGIN OF STRUCT OCCURS 10,

FILDNAME(8) TYPE C,

ABPTYPE TYPE C,

LENGTH TYPE I,

END OF STRUCT.

  • The dynamic program source table

DATA: BEGIN OF INCTABL OCCURS 10,

LINE(72),

END OF INCTABL.

DATA: LNG TYPE I, TYPESRTING(6).

  • Sample dynamic internal table stucture

STRUCT-FILDNAME = 'field1'. STRUCT-ABPTYPE = 'c'. STRUCT-LENGTH = '6'.

APPEND STRUCT. CLEAR STRUCT.

STRUCT-FILDNAME = 'field2'. STRUCT-ABPTYPE = 'd'.

APPEND STRUCT. CLEAR STRUCT.

STRUCT-FILDNAME = 'field3'. STRUCT-ABPTYPE = 'i'.

APPEND STRUCT. CLEAR STRUCT.

  • Create the dynamic internal table definition in the dyn. program

INCTABL-LINE = 'program zdynpro.'. APPEND INCTABL.

INCTABL-LINE = 'data: begin of dyntab occurs 10,'. APPEND INCTABL.

LOOP AT STRUCT.

INCTABL-LINE = STRUCT-FILDNAME.

LNG = STRLEN( STRUCT-FILDNAME ).

IF NOT STRUCT-LENGTH IS INITIAL .

TYPESRTING(1) = '('.

TYPESRTING+1 = STRUCT-LENGTH.

TYPESRTING+5 = ')'.

CONDENSE TYPESRTING NO-GAPS.

INCTABL-LINE+LNG = TYPESRTING.

ENDIF.

INCTABL-LINE+15 = 'type '.

INCTABL-LINE+21 = STRUCT-ABPTYPE.

INCTABL-LINE+22 = ','.

APPEND INCTABL.

ENDLOOP.

INCTABL-LINE = 'end of dyntab. '.

APPEND INCTABL.

  • Create the code processes the dynamic internal table

INCTABL-LINE = ' '. APPEND INCTABL.

INCTABL-LINE = 'dyntab-field1 = ''aaaaaa''.'. APPEND INCTABL.

INCTABL-LINE = 'dyntab-field1 = ''19970814''.'. APPEND INCTABL.

INCTABL-LINE = 'dyntab-field1 = 1.'. APPEND INCTABL.

INCTABL-LINE = 'append dyntab.'. APPEND INCTABL.

INCTABL-LINE = ' '. APPEND INCTABL.

INCTABL-LINE = 'loop at dyntab.'. APPEND INCTABL.

INCTABL-LINE = 'write: / dyntab.'. APPEND INCTABL.

INCTABL-LINE = 'endloop.'. APPEND INCTABL.

  • Create and run the dynamic program

INSERT REPORT 'zdynpro'(001) FROM INCTABL.

SUBMIT ZDYNPRO.

-


or Just try out this simpler dynamic internal tables

DATA: itab TYPE STANDARD TABLE OF spfli,

wa LIKE LINE OF itab.

DATA: line(72) TYPE c,

list LIKE TABLE OF line(72).

START-OF-SELECTION.

*line = ' CITYFROM CITYTO '.

line = ' AIRPTO '.

APPEND line TO list.

SELECT DISTINCT (list)

INTO CORRESPONDING FIELDS OF TABLE itab

FROM spfli.

IF sy-subrc EQ 0.

LOOP AT itab INTO wa.

  • WRITE: / wa-cityfrom, wa-cityto.

WRITE 😕 wa-airpto.

ENDLOOP.

ENDIF.

Reward if useful.......................

Read only

Former Member
0 Likes
1,328

I want to move values from one internal table to the Dynamic table..

Read only

0 Likes
1,328

any clues???

Read only

venkat_o
Active Contributor
0 Likes
1,329

Hi Abhishek, I created one program when i was working on HR Appraisal. It might be helpful to u. But I have one question for u . When u want to create dynamic table by calling the method u used, first u have to pass fieldcatalog. But I cant see in ur code. Any how check the below code.


REPORT  zvenkat_hrhap_tables NO STANDARD PAGE HEADING .
"Declarations.
"----------------------------------------------------------------------
"variable
DATA:
      g_table TYPE ddobjname,
      i_table TYPE REF TO data.
TYPES:
      t_dfies TYPE dfies.
DATA:
      w_dfies TYPE t_dfies.
DATA:
      i_dfies TYPE STANDARD TABLE OF t_dfies.

"Field symbols
FIELD-SYMBOLS:
      <i_table> TYPE STANDARD TABLE.
" ALV Declarations
* Types Pools
TYPE-POOLS:
      slis.
" Types
TYPES:
      t_fieldcat_d       TYPE lvc_s_fcat,
      t_events           TYPE slis_alv_event,
      t_layout           TYPE slis_layout_alv.
" Workareas
DATA:
      w_fieldcat_d       TYPE t_fieldcat_d,
      w_events           TYPE t_events,
      w_layout           TYPE t_layout.
" Internal Tables
DATA:
      i_fieldcat_d       TYPE STANDARD TABLE OF t_fieldcat_d,
      i_events           TYPE STANDARD TABLE OF t_events.

" selection-screen
"----------------------------------------------------------------------
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE f_title1.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT (15) text_003 FOR FIELD table.
PARAMETERS :table TYPE rsrd1-tbma_val OBLIGATORY.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN POSITION 1.
PARAMETERS: alv_list RADIOBUTTON GROUP list USER-COMMAND list DEFAULT 'X'.
SELECTION-SCREEN COMMENT (20) text_001 FOR FIELD alv_list.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN POSITION 1.
PARAMETERS : alv_grid RADIOBUTTON GROUP list.
SELECTION-SCREEN COMMENT (20) text_002 FOR FIELD alv_grid.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK b1.

"Initialization
"---------------------------------------------------------------------

INITIALIZATION.

  f_title1 = 'Report Category'.
  text_001 = 'ALV List'.
  text_002 = 'ALV GRID'.
  text_003 = 'Table Name'.

  "Start-of-selection.
*---------------------------------------------------------------------

START-OF-SELECTION.

  " Get Table information given on Selection-screen.
  g_table = table.
  CALL FUNCTION 'DDIF_NAMETAB_GET'
    EXPORTING
      tabname   = g_table
    TABLES
      dfies_tab = i_dfies.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ELSE.
    "Build fieldcatalog to create Dynamic Internal table
    LOOP AT i_dfies INTO w_dfies.
      w_fieldcat_d-fieldname   = w_dfies-fieldname.
      w_fieldcat_d-tabname     = table.
      w_fieldcat_d-ref_table   = table.
      APPEND w_fieldcat_d TO i_fieldcat_d.
      CLEAR  w_fieldcat_d.
    ENDLOOP.
    "Create Dynamic Internal table for the DB table given on Selection-screen.
    CALL METHOD cl_alv_table_create=>create_dynamic_table
      EXPORTING
        it_fieldcatalog = i_fieldcat_d
      IMPORTING
        ep_table        = i_table.
    "Assign dynamic table to field-symbol
    ASSIGN i_table->* TO <i_table>.
    "Get Data from Database table .
    SELECT *
      FROM (table)
      INTO TABLE <i_table>.
  ENDIF.

  "End-of-selection.
  "---------------------------------------------------------------------

END-OF-SELECTION.
  "Build layout structure
  w_layout-zebra             = 'X'.
  w_layout-colwidth_optimize = 'X'.
  "Build events table
  w_events-name = 'TOP_OF_PAGE'.
  w_events-form = 'TOP_OF_PAGE'.
  APPEND w_events TO i_events.
  CLEAR  w_events.
  "Display data using ALV GRID
  PERFORM display_data.
*&---------------------------------------------------------------------*
*&      Form  display_data
*&---------------------------------------------------------------------*
FORM display_data .
  DATA:
       l_program   TYPE sy-repid,
       l_structure TYPE dd02l-tabname,
       l_function  TYPE rs38l-name.

  l_program = sy-repid.
  l_structure = table.
  IF alv_list = 'X'.
    l_function = 'REUSE_ALV_LIST_DISPLAY'.
  ELSEIF alv_grid = 'X'.
    l_function = 'REUSE_ALV_GRID_DISPLAY'.
  ENDIF.
  CALL FUNCTION l_function
    EXPORTING
      i_callback_program     = l_program
*      i_structure_name       = l_structure
      it_fieldcatalog        = i_fieldcat_d
      is_layout              = w_layout
      it_events              = i_events
    TABLES
      t_outtab               = <i_table>
    EXCEPTIONS
      program_error          = 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.


ENDFORM.                    " display_data
*&---------------------------------------------------------------------*
*&      Form  top_of_page
*&---------------------------------------------------------------------*
FORM top_of_page.
  DATA :
        i_header TYPE slis_t_listheader,
        w_header LIKE LINE OF i_header.

  w_header-typ = 'H'.
  CONCATENATE 'Table' ':' table INTO w_header-info.
  APPEND w_header TO i_header.
  CLEAR w_header.

  w_header-typ = 'H'.
  WRITE sy-datum TO w_header-info.
  APPEND w_header TO i_header.
  CLEAR w_header.

  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      it_list_commentary = i_header
      i_logo             = 'ENJOYSAP_LOGO'.

ENDFORM. "top_of_page
 
Regards, Venkat.O