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

Create an internal table from a variable

Former Member
0 Likes
3,125

Can anyone help with the following issue that I am facing?

Requirement:

Check that a record exists in a database table:

The table name, table fields, field values are passed in a customising table

I have build the dynamic query

SELECT SINGLE *
         FROM (lw_passed_table)
         INTO lw_query_return
         WHERE (lw_where_clause).

     IF ( sy-subrc <> 0 ).
*     Pass value not found in passed table using passed parameters
*     Write error message here
     ENDIF.



The issue is lw_query_return I have to hard code the type, in this case the query will check the existance of a vendor in LFB1 so in my code I have

DATA: lw_query_return TYPE LFB1

         .


What I need to do is set the type of lw_query_return to the table that is stored in the vaibale lw_passed_table.


I have search for a long time and could not find any help with this.


Has anyone any idea how I can achieve what I need?


Thanking all in advance


Ian

1 ACCEPTED SOLUTION
Read only

rosenberg_eitan
Active Contributor
0 Likes
2,545

Hi,

Try:

FORM test_04 .

  CONSTANTS: name TYPE tabname VALUE 'SCARR' .

* Table

  DATA: ref_table TYPE REF TO data.
  FIELD-SYMBOLS: <it_data> TYPE STANDARD TABLE .

  CREATE DATA ref_table TYPE STANDARD TABLE OF (name) ." WITH NON-UNIQUE DEFAULT KEY.
  ASSIGN ref_table->* TO <it_data>  .

  SELECT * INTO TABLE <it_data>
    FROM (name)
    WHERE
      ('CARRID IN (''LH'',''AA'')').

* Structure .

  DATA: ref_struct TYPE REF TO data.
  FIELD-SYMBOLS: <st_data> TYPE ANY .

  CREATE DATA ref_struct TYPE (name) ." WITH NON-UNIQUE DEFAULT KEY.
  ASSIGN ref_struct->* TO <st_data>  .

  SELECT SINGLE * INTO <st_data>
  FROM (name)
  WHERE
    ('CARRID EQ ''LH'' ').

  BREAK-POINT .

* Debug <st_data>,<it_data>

ENDFORM .                                                   "test_04

Add sample selects

5 REPLIES 5
Read only

Former Member
0 Likes
2,545

something like this will help u?

DATA: it_mara type standard table of mara.

perform f_form USING it_mara.


form f_form using itab type standard table.
   select * from mara up to 10 rows
     into table itab.
endform.


or


DATA: it_mara type standard table of mara,
       wa_mara type mara.

perform f_form USING wa_mara.
form f_form using wa .
   select single * from mara
     into wa.
endform.

Read only

yogendra_bhaskar
Contributor
0 Likes
2,545

Hi Ian ,

Try variable by assigning name of type DD02L-TABNAME

then use a field symbol

FIELD-SYMBOLS : <IT_TABLE>    TYPE STANDARD TABLE.

You have to assign the structure of table to it .

Regards

Yogendra

Read only

rosenberg_eitan
Active Contributor
0 Likes
2,546

Hi,

Try:

FORM test_04 .

  CONSTANTS: name TYPE tabname VALUE 'SCARR' .

* Table

  DATA: ref_table TYPE REF TO data.
  FIELD-SYMBOLS: <it_data> TYPE STANDARD TABLE .

  CREATE DATA ref_table TYPE STANDARD TABLE OF (name) ." WITH NON-UNIQUE DEFAULT KEY.
  ASSIGN ref_table->* TO <it_data>  .

  SELECT * INTO TABLE <it_data>
    FROM (name)
    WHERE
      ('CARRID IN (''LH'',''AA'')').

* Structure .

  DATA: ref_struct TYPE REF TO data.
  FIELD-SYMBOLS: <st_data> TYPE ANY .

  CREATE DATA ref_struct TYPE (name) ." WITH NON-UNIQUE DEFAULT KEY.
  ASSIGN ref_struct->* TO <st_data>  .

  SELECT SINGLE * INTO <st_data>
  FROM (name)
  WHERE
    ('CARRID EQ ''LH'' ').

  BREAK-POINT .

* Debug <st_data>,<it_data>

ENDFORM .                                                   "test_04

Add sample selects

Read only

rahul_gaikwad1
Explorer
0 Likes
2,545

Hi Ian,

There are many posts over dynamic type creation

Still,it can be achieved as below

Data: lo_ref TYPE REF TO DATA.

Field-Symbols: <fs_struct> TYPE ANY.

**Create Structure of type mentioned in varialble lw_query_return

CREATE DATA lo_ref TYPE (lw_query_return).

ASSIGN lo_ref->* To <fs_struct>.

So you can use <fs_struct> in place of INTO

Read only

Former Member
0 Likes
2,545

Thanks guys, problem solved, Eitan solution worked a treat 🙂