Application Development 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: 

workarea in dynamic select-statement

helmut_sieberer
Participant
0 Kudos

Hello !

i hope i can get some help...

it should be possible to do a dynamic select like this:

SELECT * FROM (S_TABLE) INTO WA_TABLE.

but my Problem is:

how can i define (dynamic) the wa_table?

it should be the same structure like the table i selected before (the value is in s_table).

thanks very much...

Helmut

6 REPLIES 6

Former Member
0 Kudos

Hi helmut,

1. we need to construct dynamic internal table

for this purpose.

2. this program

gives a selection screen for entering

the TABLE NAME eg. T001.

3. then it SELECTS * from that table,

dynamically,

and gives the data in

<b> <dyntable></b>

4. Just copy paste in new program.

5.

rEPORT abc.

*----


COMPULSORY

FIELD-SYMBOLS: <dyntable> TYPE ANY TABLE.

FIELD-SYMBOLS: <dynline> TYPE ANY.

DATA: lt TYPE lvc_t_fcat.

DATA: ls TYPE lvc_s_fcat.

FIELD-SYMBOLS: <fld> TYPE ANY.

DATA : fldname(50) TYPE c.

*----


PARAMETERS : iname LIKE dd02l-tabname obligatory.

START-OF-SELECTION.

*----


GET INFO

DATA : ddfields LIKE ddfield OCCURS 0 WITH HEADER LINE.

CALL FUNCTION 'DD_NAMETAB_TO_DDFIELDS'

EXPORTING

tabname = iname

TABLES

ddfields = ddfields.

.

*----


CONSTRUCT FIELD LIST

LOOP AT ddfields.

ls-fieldname = ddfields-fieldname.

APPEND ls TO lt.

ENDLOOP.

*----


PERFORM

PERFORM mydyntable USING lt.

select * from (iname)

into table <dyntable>.

BREAK-POINT.

*----


  • INDEPENDENT FORM

*----


FORM mydyntable USING lt TYPE lvc_t_fcat .

*----


Create Dyn Table From FC

FIELD-SYMBOLS: <fs_data> TYPE REF TO data.

FIELD-SYMBOLS: <fs_1>.

FIELD-SYMBOLS: <fs_2> TYPE ANY TABLE.

DATA: lt_data TYPE REF TO data.

ASSIGN lt_data TO <fs_data>.

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = lt

IMPORTING

ep_table = <fs_data>

EXCEPTIONS

generate_subpool_dir_full = 1

OTHERS = 2.

IF sy-subrc <> 0.

ENDIF.

*----


Assign Dyn Table To Field Sumbol

ASSIGN <fs_data>->* TO <fs_1>.

ASSIGN <fs_1> TO <fs_2>.

ASSIGN <fs_1> TO <dyntable>.

ENDFORM. "MYDYNTABLE

regards,

amit m.

Former Member
0 Kudos

Hello Helmut,

Use this code...


tables: rsrd1.
DATA: LineType TYPE string,
      ItabRef  TYPE REF TO DATA.
FIELD-SYMBOLS: <fs>  TYPE STANDARD TABLE.

parameter tbl like RSRD1-TBMA_VAL.

linetype = tbl.
CREATE DATA ItabRef TYPE STANDARD TABLE OF (LineType).
ASSIGN ItabRef->* to <fs> .
SELECT * FROM (tbl) INTO table <fs>.

0 Kudos

Hi,

The code of can be used only from 4.7. The method given in the first post can be used in 4.6c systems

CREATE DATA ItabRef TYPE STANDARD TABLE OF (LineType)

In fact here you can replace LineType with tablename directly.

CREATE DATA ItabRef TYPE STANDARD TABLE OF Table.

ASSIGN ItabRef->* to <fs> .

SELECT * FROM (tbl) INTO table <fs>.

Regards,

Ravi

note :Please mark the helpful answers

helmut_sieberer
Participant
0 Kudos

Hello !

thanks for your very helpful answers.

because in all the solutions it is done with an internal table - one final question:

is there any chance to do it without an internal table?

how do i have to define the workarea in this case?

like:

SELECT * FROM (S_TABLE) INTO WA_TABLE.

...

endselect.

Thanks very much Helmut

0 Kudos

Hi,

Work area would be like line of internal_table.

Regards,

Tanveer.

Former Member
0 Kudos

Hello Helmut,

Just modify the code as follows...

tables: rsrd1.

DATA: LineType TYPE string,

ItabRef TYPE REF TO DATA,

lineRef TYPE REF TO DATA.

FIELD-SYMBOLS: <fs> TYPE STANDARD TABLE,

<fs1> type any.

parameter tbl like RSRD1-TBMA_VAL.

linetype = tbl.

CREATE DATA ItabRef TYPE STANDARD TABLE OF (LineType).

ASSIGN ItabRef->* to <fs> .

create data lineref like line of <fs>.

assign lineref->* to <fs1>.

SELECT * FROM (tbl) INTO <fs1>.

write <fs1>.

endselect.

SELECT * FROM (tbl) INTO table <fs>.