2009 Jan 01 10:51 AM
Hi Experts,
I am having string variable. This String Variable is holding a simple SELECT QUERY.
For Example.
String qry.
qry = select * into i_table from vbak.
Now i want this query inside this string to be executed.
Is there any Functional Module or Is there any other way by which I can achieve this.
Thanks in Advance.
Aslam
Hi Experts,
I am having string variable. This String Variable is holding a simple SELECT QUERY.
For Example.
String qry.
qry = select * into i_table from vbak.
Now i want this query inside this string to be executed.
Is there any Functional Module or Is there any other way by which I can achieve this.
Thanks in Advance.
Aslam
2009 Jan 01 10:58 AM
hi,
As of my knowledge you cannot execute the string which contains the select query...
Instead you can have the where clause in the variable.
select * into i_table from vbak where <var>.
2009 Jan 01 4:36 PM
2009 Jan 01 11:11 AM
Hi...
You can do it other way. Please check the sample code.
TYPES : BEGIN OF x_marc,
matnr TYPE matnr,
werks TYPE werks_d,
END OF x_marc.
DATA: i_marc TYPE STANDARD TABLE OF x_marc,
l_marc TYPE char40 VALUE 'MARC'.
DATA: l_field TYPE STANDARD TABLE OF string,
l_where TYPE STANDARD TABLE OF string,
wa_field TYPE string.
PARAMETERS: p_matnr TYPE matnr.
wa_field = 'MATNR'.
APPEND wa_field TO l_field.
CLEAR: wa_field.
wa_field = 'WERKS'.
APPEND wa_field TO l_field.
CLEAR: wa_field.
wa_field = 'MATNR = P_MATNR'.
APPEND wa_field TO l_where.
SELECT (l_field) FROM (l_marc)
INTO TABLE i_marc WHERE (l_where).
IF sy-subrc = 0.
ENDIF.
You put the select part in a perform. Use can use it as function module.
2009 Jan 01 4:09 PM
This is the code.
1. we can declare types dynamically
2. Internal table dynamically
3. Select querry dynamically
just copy paste this code
Here is the code for your question
DATA:v_fieldname
TYPE fieldname,
l_PROG TYPE string,
v_mess TYPE string,
l_sid TYPE string,
wa_ddfields TYPE dntab.
DATA i_tab TYPE STANDARD TABLE OF string.
DATA:l_str TYPE string,
l_str1 TYPE string.
PARAMETERS matnr type marc-matnr.
end-of-SELECTION.
*build the subroutine pool
APPEND 'PROGRAM subpool.' TO i_tab.
APPEND `LOAD-OF-PROGRAM.` TO i_tab.
APPEND `DATA i_tab1 TYPE TABLE OF vbak.` TO i_tab.
APPEND `DATA l_rows TYPE i.` TO i_tab.
APPEND `select * into table i_tab1 from vbak.` To i_tab.
append 'DESCRIBE TABLE i_tab1 LINES l_rows.' to i_tab.
append 'Write : l_rows .' to i_tab.
GENERATE SUBROUTINE POOL i_tab NAME l_PROG
MESSAGE v_mess
SHORTDUMP-ID l_sid.
IF sy-subrc = 0.
PERFORM ('LOOP_AT_TAB') IN PROGRAM (l_PROG) IF FOUND.
ELSEIF sy-subrc = 4.
MESSAGE v_mess TYPE 'I'.
ELSEIF sy-subrc = 8.
MESSAGE l_sid TYPE 'I'.
ENDIF.
Edited by: vijay wankhade on Jan 1, 2009 5:34 PM
Edited by: vijay wankhade on Jan 1, 2009 5:34 PM
2009 Jan 01 4:18 PM
Hi Aslam
You can use parts of the string and use it some thing similar to below snippet:
PARAMETERS: carr_id TYPE spfli-carrid,
conn_id TYPE spfli-connid.
DATA: where_clause TYPE STRING,
and(4),
wa_spfli TYPE spfli.
IF carr_id IS NOT INITIAL.
CONCATENATE 'CARRID = ''' carr_id '''' INTO where_clause.
and = ' AND'.
ENDIF.
IF conn_id IS NOT INITIAL.
CONCATENATE where_clause and ' CONNID = ''' conn_id ''''
INTO where_clause.
ENDIF.
SELECT * FROM spfli INTO wa_spfli WHERE (where_clause).
WRITE: / wa_spfli-carrid, wa_spfli-connid, wa_spfli-cityfrom,
wa_spfli-cityto, wa_spfli-deptime.
ENDSELECT.
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |