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

Dynamic SELECT

Former Member
0 Likes
1,096

Hey experts,

I have defined these table_wa's from dtabs


TABLES: zbr_t_autori, zbr_t_aut_knihy, zbr_t_fakulty, zbr_t_jazyky,

         zbr_t_kategorie, zbr_t_knihy, zbr_t_kn_vo_vyp, zbr_t_odbory,

         zbr_t_odb_stud, zbr_t_univerzity, zbr_t_vydavatels,

         zbr_t_vypozicky, zbr_t_zakaznici.

I have a variable if_table_name what contains one of the dtabs name and I want to make a dynamic select like this


SELECT SINGLE * FROM (if_table_name) INTO (if_table_name)

where (conditions).

but after INTO i can't use the (if_table_name) and I want to avoid the hundred CASE or IF statements.

So how could I solve this?

For better understand.

For example if_table_name contains 'ZBR_T_AUTORI'

so the select would be

SELECT SINGLE * FROM ZBR_T_AUTORI INTO ZBR_T_AUTORI

where (conditions).

but after FROM the ZBR_T_AUTORI is a dtab and after INTO it's a workarea and I don't know how to achieve it to be dynamic with if_table_name.

If something is not clear just ask me.

Regards,

Robert

1 ACCEPTED SOLUTION
Read only

Private_Member_7726
Active Contributor
0 Likes
1,061

Hi,


Something like this, via creating data reference and de-referencing it to field-symbol:

DATA if_table_name TYPE string VALUE 'T100' .

DATA it_cond TYPE STANDARD TABLE OF string .
DATA it_from TYPE STANDARD TABLE OF string .
DATA rf_into TYPE REF TO data .
FIELD-SYMBOLS: <fs_into> TYPE any .

CREATE DATA rf_into TYPE (if_table_name) .
ASSIGN rf_into->* TO <fs_into> .

APPEND if_table_name TO it_from .

APPEND 'SPRSL = SY-LANGU AND' TO it_cond .
APPEND 'ARBGB = ''00'' AND' TO it_cond .
APPEND 'MSGNR = ''001''' TO it_cond .

SELECT SINGLE * FROM (it_from) INTO <fs_into>
  WHERE (it_cond) .

Also, check out SELECT, Dynamic Token Specification in ABAP Docu. The type specification for creating data reference can come from RTTI.


I'm sure you'd have found it yourself, had you searched a bit more

cheers

Janis

9 REPLIES 9
Read only

Former Member
0 Likes
1,061

Why are you doing a select from the variable(if_table_name) to the variable(if_table_name)?

Rfer to the discussion below:

Regards,

Ashvin

Read only

0 Likes
1,061

I'm doing a double_click event handle in OO ALV and I want to fill the fields generated from the dtab on my screen, that's why I want to do this select.

I checked that link, but no help ia there for my problem.

Read only

0 Likes
1,061

Search on F4IF_INT_TABLE_VALUE_REQUEST.

Read only

Private_Member_7726
Active Contributor
0 Likes
1,062

Hi,


Something like this, via creating data reference and de-referencing it to field-symbol:

DATA if_table_name TYPE string VALUE 'T100' .

DATA it_cond TYPE STANDARD TABLE OF string .
DATA it_from TYPE STANDARD TABLE OF string .
DATA rf_into TYPE REF TO data .
FIELD-SYMBOLS: <fs_into> TYPE any .

CREATE DATA rf_into TYPE (if_table_name) .
ASSIGN rf_into->* TO <fs_into> .

APPEND if_table_name TO it_from .

APPEND 'SPRSL = SY-LANGU AND' TO it_cond .
APPEND 'ARBGB = ''00'' AND' TO it_cond .
APPEND 'MSGNR = ''001''' TO it_cond .

SELECT SINGLE * FROM (it_from) INTO <fs_into>
  WHERE (it_cond) .

Also, check out SELECT, Dynamic Token Specification in ABAP Docu. The type specification for creating data reference can come from RTTI.


I'm sure you'd have found it yourself, had you searched a bit more

cheers

Janis

Read only

0 Likes
1,061

I know all of these things, but I want to select those data into these following workareas:


TABLES: zbr_t_autori, zbr_t_aut_knihy, zbr_t_fakulty, zbr_t_jazyky,

         zbr_t_kategorie, zbr_t_knihy, zbr_t_kn_vo_vyp, zbr_t_odbory,

         zbr_t_odb_stud, zbr_t_univerzity, zbr_t_vydavatels,

         zbr_t_vypozicky, zbr_t_zakaznici.

not to <fs_into>, but I have an idea now, I will try to assign the above workareas to a field symbol.

If it will not work a post another more detailed post about my problem.

Read only

0 Likes
1,061

It's working my part of the code is the following:


CLASS gcl_event_receiver IMPLEMENTATION.

   METHOD on_double_click.

     DATA: conditions TYPE string,

           fieldname TYPE string,

           it_fields type TABLE OF dfies,

           wa_fields type dfies.

     FIELD-SYMBOLS: <wa_id1> TYPE zbr_t_autori-id_kniznice,

                    <wa_id2> TYPE zbr_t_autori-id_kniznice,

                    <wa_dynprofields> type any.

     CALL FUNCTION 'DDIF_FIELDINFO_GET'

       EXPORTING

         tabname        = if_table_name

       TABLES

         dfies_tab      = it_fields

       EXCEPTIONS

         not_found      = 1

         internal_error = 2

         OTHERS         = 3.

     LOOP AT it_fields INTO wa_fields.

       IF wa_fields-keyflag EQ 'X' AND wa_fields-fieldname NE 'ID_KNIZNICE' AND wa_fields-fieldname NE 'MANDT'.

         MOVE wa_fields-fieldname TO fieldname.

         EXIT.

       ENDIF.

     ENDLOOP.

     READ TABLE <table> INTO <wa_table> INDEX e_row.

     ASSIGN COMPONENT 2 OF STRUCTURE <wa_table> TO <wa_id1>.

     ASSIGN COMPONENT 3 OF STRUCTURE <wa_table> TO <wa_id2>.

     ASSIGN (if_table_name) to <wa_dynprofields>.

     CLEAR conditions.

     CONCATENATE 'ID_KNIZNICE' 'EQ' <wa_id1> 'AND' fieldname 'EQ' <wa_id2> INTO conditions SEPARATED BY space.

     SELECT SINGLE * FROM (if_table_name) INTO <wa_dynprofields>

       where (conditions).

     perform call_screen_30x.


...

I try to explain it better to everyone. I was trying to fill the fields of different screens. These screens are called in form call_screen_30x. To fill the fields of the dynpro which was generated from different dtabs I needed to fill one of these work areas:


TABLES: zbr_t_autori, zbr_t_aut_knihy, zbr_t_fakulty, zbr_t_jazyky,

         zbr_t_kategorie, zbr_t_knihy, zbr_t_kn_vo_vyp, zbr_t_odbory,

         zbr_t_odb_stud, zbr_t_univerzity, zbr_t_vydavatels,

         zbr_t_vypozicky, zbr_t_zakaznici.

The it_table_name variable contained the name one of the above workares which is needed to fill. Because only these workareas was linked with the fields on the dynpros.

Read only

0 Likes
1,061

Yes, sorry, I have been reading the post 'diagonally' If all the work areas are defined there is no need to create them dynamically, and a dynamic ASSIGN (if_table_name) TO <fs> is enough.

cheers

Jānis

Read only

0 Likes
1,061

Wait a moment, if I create those work areas dynamically will be they still linked with the fields on the screens, if they are generated from dtabs? I mean if I will fill that <fs> does the fields on screen will be filled too automatically?

Read only

0 Likes
1,061

I'm struggling a bit to explain why, but nope - I don't think it's possible to link up the dynpro fields (something "addressed" via a static name) with a dynamic data object. I guess my best explanation why I feel it should not be possible is the fact that dynamic data objects have no name, can only be adressed via data reference variable and the content is accessible only by dereferencing the reference variable to a field symbol.

cheers

Jānis