‎2014 Oct 22 11:26 AM
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
‎2014 Oct 22 11:56 AM
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
‎2014 Oct 22 11:38 AM
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.
‎2014 Oct 22 11:43 AM
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
‎2014 Oct 22 11:56 AM
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
‎2014 Oct 22 12:08 PM
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
‎2014 Oct 22 12:20 PM
Thanks guys, problem solved, Eitan solution worked a treat 🙂