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

how to create dynamic strcture for a interrnal table

Former Member
0 Likes
654

first i created one internal table . with five fields . suppose i want add two more fields in internal table.

what is the code for the this . if any one konow

first i created one internal table . with five fields . suppose i want add two more fields in internal table.

what is the code for the this . if any one konow

3 REPLIES 3
Read only

Former Member
0 Likes
621

REPORT ZTEST05.

PARAMETERS dbtab TYPE tabname DEFAULT 'SPFLI'.

TYPE-POOLS rsds.

DATA tadir_wa TYPE tadir.

DATA selid TYPE rsdynsel-selid.

DATA field_tab TYPE TABLE OF rsdsfields.

DATA table_tab TYPE TABLE OF rsdstabs.

DATA table LIKE LINE OF table_tab.

DATA cond_tab TYPE rsds_twhere.

DATA cond LIKE LINE OF cond_tab.

DATA dref TYPE REF TO data.

DATA alv TYPE REF TO cl_salv_table.

FIELD-SYMBOLS <table> TYPE STANDARD TABLE.

SELECT SINGLE *

FROM tadir

INTO tadir_wa

WHERE pgmid = 'R3TR' AND

object = 'TABL' AND

obj_name = dbtab.

IF sy-subrc <> 0.

MESSAGE 'Database not found' TYPE 'I' DISPLAY LIKE 'E'.

LEAVE PROGRAM.

ENDIF.

table-prim_tab = dbtab.

APPEND table TO table_tab.

CALL FUNCTION 'FREE_SELECTIONS_INIT'

EXPORTING

kind = 'T'

IMPORTING

selection_id = selid

TABLES

tables_tab = table_tab

EXCEPTIONS

OTHERS = 4.

IF sy-subrc <> 0.

MESSAGE 'Error in initialization' TYPE 'I' DISPLAY LIKE 'E'.

LEAVE PROGRAM.

ENDIF.

CALL FUNCTION 'FREE_SELECTIONS_DIALOG'

EXPORTING

selection_id = selid

title = 'Free Selection'

as_window = ' '

IMPORTING

where_clauses = cond_tab

TABLES

fields_tab = field_tab

EXCEPTIONS

OTHERS = 4.

IF sy-subrc <> 0.

MESSAGE 'No free selection created' TYPE 'I'.

LEAVE PROGRAM.

ENDIF.

READ TABLE cond_tab WITH KEY tablename = dbtab INTO cond.

IF sy-subrc <> 0.

MESSAGE 'Error in condition' TYPE 'I' DISPLAY LIKE 'E'.

LEAVE PROGRAM.

ENDIF.

CREATE DATA dref TYPE TABLE OF (dbtab).

ASSIGN dref->* TO <table>.

TRY.

SELECT *

FROM (dbtab)

INTO TABLE <table>

WHERE (cond-where_tab).

CATCH cx_sy_dynamic_osql_error.

MESSAGE 'Error in dynamic Open SQL' TYPE 'I' DISPLAY LIKE 'E'.

LEAVE PROGRAM.

ENDTRY.

TRY.

cl_salv_table=>factory(

IMPORTING r_salv_table = alv

CHANGING t_table = <table> ).

alv->display( ).

CATCH cx_salv_msg.

MESSAGE 'Error in ALV display' TYPE 'I' DISPLAY LIKE 'E'.

ENDTRY.

Read only

Former Member
0 Likes
621

hi,

first create the field catalog for the dynamic internal table using LVC_F_CAT.

then call the below class to create the dynamic internal table

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = t_fldcat

IMPORTING

ep_table = t_newtable.

ASSIGN t_newtable->* TO <t_dyntable>.

Pass the field catalog created.

thanks

sudheer

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
621

>

> first i created one internal table . with five fields . suppose i want add two more fields in internal table.

> what is the code for the this . if any one konow

How did you create your internal table ?