Dynamic select statement
I have this input field called IO_TABLE and a button. When the user key in the database name into IO_TABLE and press the button, the records/data in the database will be written out.
Here is my codes:
REPORT ZA_FIELD.
DATA IO_TABLE(30) TYPE C.
FIELD-SYMBOLS: <FS_INPUT> TYPE ANY,
<FS_ITAB> TYPE ANY TABLE.
START-OF-SELECTION.
CALL SCREEN 9000.
MODULE STATUS_9000 OUTPUT.
SET PF-STATUS 'SCREEN_9000'.
SET TITLEBAR 'TITLE_9000'.
ENDMODULE. "STATUS_9002 OUTPUT
MODULE USER_COMMAND_9000 INPUT.
IF SY-UCOMM = 'SAVE'.
ELSEIF SY-UCOMM = 'EXIT' OR SY-UCOMM = 'CANCEL'.
LEAVE PROGRAM.
ELSEIF SY-UCOMM = 'PUSH'.
ASSIGN IO_TABLE TO <FS_INPUT>.
SELECT * FROM <FS_INPUT> INTO TABLE <FS_ITAB>.
WRITE <FS_ITAB> .
" SUBMIT ZFINAL_2.
ENDIF.
ENDMODULE. "USER_COMMAND_9002 INPUT
As shown <FS_INPUT> is the field symbol that store the value of IO_TABLE. What am I suppose to replace my dynamic internal table for my codes?
dynamic internal table is needed to display out the values in it.
However, I got this error at my statement as shown at my link http://img337.imageshack.us/img337/3791/screenez4.png
What am I suppose to do to solve this problem?
Unfortunately -- it's not not quite that simple although still easy enough.
In order to use a dynamic table you need to create a field catalog first for the fields, build the dynamic table and then populate it.
Here's how to do it.
1) define some data we'll need for the process.
* Define any structure
TYPES: BEGIN OF s_elements,
vbeln TYPE vapma-vbeln,
posnr TYPE vapma-posnr,
matnr TYPE vapma-matnr,
kunnr TYPE vapma-kunnr,
werks TYPE vapma-werks,
vkorg TYPE vapma-vkorg,
vkbur TYPE vapma-vkbur,
status TYPE c,
END OF s_elements.
* end of your structure
DATA:wa_elements TYPE s_elements.
DATA: ord_nr TYPE vapma-vbeln,
mat_nr TYPE vapma-matnr,
cus_nr TYPE vapma-kunnr.
DATA lr_rtti_struc TYPE REF TO cl_abap_structdescr .
DATA:
zog LIKE LINE OF lr_rtti_struc->components .
DATA:
zogt LIKE TABLE OF zog,
wa_it_fldcat TYPE lvc_s_fcat,
it_fldcat TYPE lvc_t_fcat ,
dy_line TYPE REF TO data,
dy_table TYPE REF TO data.
DATA: dref TYPE REF TO data.
FIELD-SYMBOLS: <fs> TYPE ANY,
<dyn_table> TYPE STANDARD TABLE,
<dyn_wa>.
2) now build the fcat, create the dynamic table and populate it.
START-OF-SELECTION.
*now I want to build a field catalog
* First get your data structure into a field symbol
CREATE DATA dref TYPE s_elements.
ASSIGN dref->* TO <fs>.
lr_rtti_struc ?= cl_abap_structdescr=>describe_by_data( <fs> ).
* Now get the structure details into a table.
* table zogt[] contains the structure details
* From which we can build the field catalog
zogt[] = lr_rtti_struc->components.
LOOP AT zogt INTO zog.
CLEAR wa_it_fldcat.
wa_it_fldcat-fieldname = zog-name .
wa_it_fldcat-datatype = zog-type_kind.
wa_it_fldcat-inttype = zog-type_kind.
wa_it_fldcat-intlen = zog-length.
wa_it_fldcat-decimals = zog-decimals.
wa_it_fldcat-coltext = zog-name.
wa_it_fldcat-lowercase = 'X'.
IF wa_it_fldcat-fieldname = 'VBELN'.
wa_it_fldcat-hotspot = 'X'.
ENDIF.
APPEND wa_it_fldcat TO it_fldcat.
ENDLOOP.
* You can perform any modifications / additions to your field catalog
* here such as your own column names etc.
* Now using the field catalog created above we can
* build a dynamic table
* and populate it
* First build the dynamic table
* the table will contain entries for
* our structure defined at the start of the program
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_fldcat
IMPORTING
ep_table = dy_table.
ASSIGN dy_table->* TO <dyn_table>.
CREATE DATA dy_line LIKE LINE OF <dyn_table>.
ASSIGN dy_line->* TO <dyn_wa>.
* Now fill our table with data
SELECT vbeln posnr matnr kunnr werks vkorg vkbur
UP TO 200 ROWS
FROM vapma
INTO CORRESPONDING FIELDS OF TABLE <dyn_table>.
3) now if you want to say use a "classical" table all you need to do is
define a standard table of type s_elements and code something simple like
my_itab[] = <dyn_table>.
Then you could get the <dyn_table> after creation into yoour own table for further processing.
You can also display the <dyn_table> in a grid simply via some type of code such as
CALL METHOD grid1->set_table_for_first_display
EXPORTING is_layout = struct_grid_lset
CHANGING
it_outtab = <dyn_table>
it_fieldcatalog = it_fldcat.
You'll need to "instantiate" the class (have grid1 as a ref to cl_gui_alv_grid) and do some other work --that's a topic for another post - however since you now have the field catalog and the table in principle if you need a grid display you've done 90% of the work.
cheers
jimbo
Similar Messages
-
Hello Gurus,
We have a dynamic SELECT statement in our BW Update Rules where the the Selection Fields are populated at run-time and so are the look-up target and also the WHERE clause. The code basically looks like below:
SELECT (lt_select_flds)
FROM (lf_tab_name)
INTO CORRESPONDING FIELDS OF TABLE <lt_data_tab>
FOR ALL ENTRIES IN <lt_source_data>
WHERE (lf_where).
In this instance, we are selecting 5 fields from Customer Master Data and the WHERE condition for this instance of the run is as below:
WHERE: DIVISION = <lt_source_data>-DIVISION AND DISTR_CHAN = <lt_source_data>-DISTR_CHAN AND SALESORG = <lt_source_data>-SALESORG AND CUST_SALES = <lt_source_data>-SOLD_TO AND OBJVERS = 'A'
This code was working fine till yesterday when we encountered serious performance problems and the Basis team had to do some changes at the DB level [Oracle]. Ever since, when we execute our data load, we get the CX_SY_DYNAMIC_OSQL_SEMANTICS.
Is setting changes at the Oracle level cause issues with how the data is being read at the DB. If yes, can you suggest what can we do to this code to get is working correctly [in case Basis can't revert back their changes]?
Would appreciate any help we can get here.You don't understand - this error comes up when we run specific BEx queries. It was working yesterday, but today it is not. Our support package did not change from yesterday. We did not apply any OSSnotes.
We are however doing pre-prepare on our Prod system.
The temporary table is used to store SIDs for use in the join. the table exists in the dictionary, but not at an Oracle level. -
DYnamic select statement in JDBC adapter?
Hi guys,
Is it possible so send dynamic select statement in jdbc adapter?
XIerAamir,
The poster did not specify whether this was sender or receiver channel, but it would only make sense that a "dynamic query" must be on the receiver communication channel since if it was on the sender channel, the channel would have to intelligently determine how to do dynamic queries.
Also, the poster asked if there was a way to "send a dynamic query" to the channel. This seems to imply that the channel is receiving information from somewhere to determine the query, which could only mean it is a receiver channel.
If you would like more information on the JDBC sender communication channel, please open a new thread. -
CX_SY_DYNAMIC_OSQL_SEMANTICS error with dynamic SELECT statement
Hello Gurus,
We have a dynamic SELECT statement in our BW Update Rules where the the Selection Fields are populated at run-time and so are the look-up target and also the WHERE clause. The code basically looks like below:
SELECT (lt_select_flds)
FROM (lf_tab_name)
INTO CORRESPONDING FIELDS OF TABLE <lt_data_tab>
FOR ALL ENTRIES IN <lt_source_data>
WHERE (lf_where).
In this instance, we are selecting 5 fields from Customer Master Data and the WHERE condition for this instance of the run is as below:
WHERE: DIVISION = <lt_source_data>-DIVISION AND DISTR_CHAN = <lt_source_data>-DISTR_CHAN AND SALESORG = <lt_source_data>-SALESORG AND CUST_SALES = <lt_source_data>-SOLD_TO AND OBJVERS = 'A'
This code was working fine till we were in BW 3.5 and is causing issues after we moved to BW 7.31 recently. Ever since, when we execute our data load, we get the CX_SY_DYNAMIC_OSQL_SEMANTICS. THE ERROR TEXT SAYS 'Unable to interpret '<LT_SOURCE_data>-DOC_NUMBER'.
Can you pleasesuggest what can we do to this code to get is working correctly ? What has changed in ABAP Objects that has been introduced from BI 7.0 that could be causing this issue?
Would appreciate any help we can get here.
Thanks
ArvindHi,
Please try this.
data: lv_where type string.
concatenate 'vbeln' 'in' 'r_vbeln' into lv_where separated by space.
select *from table into itab where (lv_where).
Also please check this sample code.
REPORT ZDYNAMIC_WHERE .
TABLES: VBAK.
DATA: CONDITION TYPE STRING.
DATA: BEGIN OF ITAB OCCURS 0,
VBELN LIKE VBAK-VBELN,
POSNR LIKE VBAP-POSNR,
END OF ITAB.
SELECT-OPTIONS: S_VBELN FOR VBAK-VBELN.
CONCATENATE 'VBELN' 'IN' 'S_VBELN.'
INTO CONDITION SEPARATED BY SPACE.
SELECT VBELN POSNR FROM VBAP INTO TABLE ITAB
WHERE (CONDITION).
LOOP AT ITAB.
WRITE 'hello'.
ENDLOOP.
Regards,
Ferry Lianto -
Need to wite pl sql procedure for dynamic select statement
Need pl sql procedure for a Dynamic select statement which will drop tables older than 45 days
select 'Drop table'||' ' ||STG_TBL_NAME||'_DTL_STG;' from IG_SESSION_LOG where substr(DTTM_STAMP, 1, 9) < current_date - 45 and INTF_STATUS=0 order by DTTM_STAMP desc;I used this to subtract any data older than 2 years, adjustments can be made so that it fits for forty five days, you can see how I changed it from the originaln dd-mon-yyyy to a "monyy", this way it doesn't become confused with the Static data in the in Oracle, and call back to the previous year when unnecessary:
TO_NUMBER(TO_CHAR(A.MV_DATE,'YYMM')) >= TO_NUMBER(TO_CHAR(SYSDATE - 365, 'YYMM')) -
Autonumbers through dynamic SELECT statement
Trying to get an autonumber from an order table. The order_id I need from the table is only uniquely identified by the customer_id and the date/time. I've been advised that you cannot get an autonumber back from access without going via a select statement.
I've tried to do a dynamic select statement by getting the date (short i.e.DD/MM/YY) from the server using a JSP custom tag and then putting this value into a hidden form field on the previous web page.
However, when I load the next page the data gets input into the order table okay but the web page displayed is blank i.e. it doesn't display the order_id or the form to input credit card details. There are no error messages
Code below, any ideas?
<%@ page language="java" contentType="text/html"
import="ShoppingBasket,Product,java.util.*"
errorPage="errorpage.jsp"%>
<jsp:useBean id="basket" class="ShoppingBasket" scope="session"/>
<html>
<head>
<title>Your Order Has Been Received</title>
</head>
<body>
<%
String customer_id = request.getParameter("customer_id");
String total_value = request.getParameter("total_value");
String order_date = request.getParameter("order_date");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
java.sql.Connection connection = java.sql.DriverManager.getConnection("jdbc:odbc:Novbase","","");
java.sql.Statement Stmt = connection.createStatement();
String query = ("INSERT INTO Orders (customer_id, total_value) VALUES ("+customer_id+", "+total_value+")");
Stmt.executeUpdate(query);
java.sql.Statement Stmt2 = connection.createStatement();
java.sql.ResultSet RS = Stmt2.executeQuery("SELECT order_id FROM Orders WHERE customer_id = "+customer_id+" AND time_date LIKE '"+order_date+"%'" );
while(RS.next())
String order_id = RS.getString("order_id");
%>
your order id is <%=order_id %>. Please input your credit card details in the form below:
<form name="form1" method="post" action="shop-postorder4.jsp">
<table width="90%" border="0" cellspacing="1" cellpadding="5">
<tr>
<td width="5%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"></font></td>
<td width="25%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Credit
Card Type</font></td>
<td width="70%"> <font face="Verdana, Arial, Helvetica, sans-serif" size="2">
<select name="card_type">
<option value="AMERICAN EXPRESS">American Express</option>
<option value="MASTER CARD">Master Card</option>
<option value="SWITCH">Switch</option>
<option value="VISA">Visa</option>
</select>
*</font></td>
</tr>
<tr>
<td width="5%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"></font></td>
<td width="25%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Credit
Card No.</font></td>
<td width="70%"> <font face="Verdana, Arial, Helvetica, sans-serif" size="2">
<input type="text" name="card_number" size=18 maxlength="18">
*</font></td>
</tr>
<tr>
<td width="5%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"></font></td>
<td width="25%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Issue
No. <font size="1"><br>
(Switch card holders<br>
only)</font></font></td>
<td width="70%"> <font face="Verdana, Arial, Helvetica, sans-serif" size="2">
<input type="text" name="issue_no" size="2" maxlength="2">
</font></td>
</tr>
<tr>
<td width="5%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"></font></td>
<td width="25%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Valid
From</font></td>
<td width="70%"> <font face="Verdana, Arial, Helvetica, sans-serif" size="2">
<input type="text" name="valid_from" size="4" maxlength="4">
e.g. 0502</font></td>
</tr>
<tr>
<td width="5%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"></font></td>
<td width="25%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Validy
To</font></td>
<td width="70%"> <font face="Verdana, Arial, Helvetica, sans-serif" size="2">
<input type="text" name="valid_to" size="4" maxlength="4">
* e.g. 0105</font></td>
</tr>
</table>
<input type="submit" name="Submit" value="Submit">
<input type="hidden" name="order_id" value="<%=order_id %>">
</form>
<a href=" <%= response.encodeURL(shop-products.jsp") %">">
<img src="images\toshop.gif" border="0" alt="Return to the Shop"></a>
<%
RS.close();
Stmt.close();
Stmt2.close();
connection.close();
%>
</body>
</html>
</a>String query = ("INSERT INTO Orders (customer_id, total_value) VALUES ("+customer_id+", "+total_value+")");
the data gets input into the order table okay
java.sql.ResultSet RS = Stmt2.executeQuery("SELECT order_id FROM Orders WHERE customer_id = "+customer_id+" AND time_date LIKE '"+order_date+"%'" );It is a field name as <B>time_date </B>in Orders table? And should you insert some value ?
It seems your select return nothing.
When your RS.next() is false, so you get blank. Add some HTNL code or just <HR> after while {} block so your would see it. -
JDBC: Dynamic select statement
Hi,
I am working on a JDBC to SAP integration. I am trying to SELECT data from table for a specific time interval.
In the JDBC configuration i am using the Query SQL Statement
For example: select * from X where time='20080808'
Now is it possible to use for example the system date and time of the server where pi is installed or any other dynamic data?
Maybe like this: select * from X where time =@sysdate
If it is possible how? If not why?
I appreciate your help.
Thanks in advance...Hi,
In case of receiver JDBC you can map todays date to the select statement and make the select statement dynamic, however in the sender it can't be done. The work around may be to call the stored procedure from the sender adapter and using the stored procedure construct the select query dynamically.
Thanks
SaNv... -
Getting result of dynamic select statement into variable
I have a function that builds a dynamic sql statement. I then want to take the result of that statement and insert it into a variable. I have tried this
execute immediate strSQL USING OUT intCounter;but that is giving me an error on that line of code. The SQL is a select count(*) and works fine. It is just how to get it into the variable that is tripping me up.
Thanks,
EvaSure. Version 11g. The complete procedure reads as follows:
CREATE OR REPLACE FUNCTION VALIDATIONQUESTIONRESULT
p_ShortName VARCHAR2,
p_SiteID VARCHAR2
RETURN NUMBER IS
strSQL VARCHAR2(5000);
strTableName VARCHAR2(200);
strPatIDFieldName VARCHAR2(200);
intCounter NUMBER;
BEGIN
select VALIDATIONSQL into strSQL from vwvalidationquestions where upper(shortname) = upper(p_ShortName);
select
case UPPER(DBTABLENAME)
when 'CPTICODES' then 'CPTIPATID'
when 'CPTIICODES' then 'CPTIIPATID'
when 'DEMOGRAPHICS' then 'PATID'
when 'FAMILYHISTORY' then 'FHPATID'
when 'GCODES' then 'GCODEPATID'
when 'HOSPITALIZATION' then 'HPATID'
when 'MEDICALHISTORY' then 'MHPATID'
when 'MEDICATIONS' then 'MPATID'
when 'PROCEDURES' then 'PPATID'
when 'VISITS' then 'VPATID' end into strPatIDFieldName
from DATASPECIFICATIONS where UPPER(SHORTNAME) = UPPER(p_ShortName);
strSQL := strSQL||' and '||strPatIDFieldName||' in (select PATID from DEMOGRAPHICS where PARTICID = '||p_SiteID||');';
execute immediate strSQL into intCounter;
return intCounter;
END VALIDATIONQUESTIONRESULT; strSQL when checked builds perfectly. I get 100% what I expect from it. An example of what I am getting from strSQL is:
select count(*) from Procedures where TO_CHAR(ProcdDt, 'MM') = TO_CHAR(ADD_MONTHS(SYSDATE, -1), 'MM') and TO_CHAR(ProcdDt, 'YYYY') = TO_CHAR(ADD_MONTHS(SYSDATE, -12), 'YYYY') and PPATID in (select PATID from DEMOGRAPHICS where PARTICID = 12);I am getting the number I would expect from this. I just need to put that number into intCounter. I tried altering strSQL so it looked like this:
select count(*) into intCounter from Procedures where TO_CHAR(ProcdDt, 'MM') = TO_CHAR(ADD_MONTHS(SYSDATE, -1), 'MM') and TO_CHAR(ProcdDt, 'YYYY') = TO_CHAR(ADD_MONTHS(SYSDATE, -12), 'YYYY') and PPATID in (select PATID from DEMOGRAPHICS where PARTICID = 12);but that gave me an error on the execute immediate line as well.
Sorry, I thought it would be simple so that was why I only put that bit of info. I guess it is more complicated than it at first appeared!
Eva -
Inner Join for Dynamic Select statement
Hi All,
Can some one please help me in rewriting the below select statement where i have to remove the existing table1 by putting a dynamic table name which has the same table structure.
select a~zfield1
a~zfield2
from ztab1 as a
inner join ztab2 as b
on b~ztab1-zfield3 = a~ztab2-zfield3
where a~zfield4 = 'A'.
I am looking something as below. But encountering an error when using the below statement
select a~zfield1
a~zfield2
from (v_ztab1) as a
inner join ztab2 as b
on b~ztab1-zfield3 = a~ztab2-zfield3
where a~zfield4 = 'A'.
No Separate selects please. Please help me in rewriting the same select statement itself.
Regards,
PSKhi,
What error you are getting ?
Also INTO is missing from the statement.
SELECT pcarrid pconnid ffldate bbookid
INTO TABLE itab
FROM ( spfli AS p
INNER JOIN sflight AS f ON pcarrid = fcarrid AND
pconnid = fconnid )
WHERE p~cityfrom = 'FRANKFURT' AND
p~cityto = 'NEW YORK' .
thanks -
Cursor - dynamic select statement?
Hello!
I am passing a string into a function, and my string is a sql select statement. Is it possible to create a cursor using the string that is passed to the function?
Ex:
create or replace function "GETCOUNT"
(sqlstring in VARCHAR2)
return NUMBER
is
rec_count NUMBER; --I eventually want to return a count of the rows returned from my sqlstring
cursor c1 is sqlstring <--this is what I'd like to do...but how?
begin
... -- I haven't gotten to this point yet
end;
The error I get says 'Encountered the symbol "sqlstring" when expecting on of the following: ( select '
Thanks in advance!!Something like this ->
create or replace procedure gen_cur(str in varchar2,rc in out sys_refcursor)
is
str1 varchar2(500);
begin
str1 := 'select empno,ename,hiredate,sal
from emp
where '||str;
open rc for str1;
exception
when others then
dbms_output.put_line(sqlerrm);
end;
variable b refcursor
declare
src varchar2(300);
begin
src:= 'sal between 2000 and 7000';
gen_cur(src,:b);
exception
when others then
dbms_output.put_line(sqlerrm);
end;
print bRegards.
Satyaki De. -
Workarea in dynamic select-statement
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...
HelmutHi 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. -
Cursor - Suggestions for Dynamic select statements
Hey,
Am trying to define a cursor like this -
cursor c1 is
select table_name from dba_tables INTERSECT select table_name from dba_tables@SOME_DBLINKMy need is to pass this dblink as IN parameter to the procedure and use it in the select statement for cursor. How can I do this?
Any suggestion is highly appreciated. Thanks!Well that was meant to be my point. If you had two, you wouldn't (I hope) call the second one "c2" - you would be forced to think about what it represented, and name it "c_order_history" or something. Sticking "1" on the end does not make an extensible naming convention for cursors any more than it does for variables, procedures, tables or anything else, and so the "1" in "c1" is redundant because there will never be a c2.
-
Dynamic Select statements (Joins)
Hi friends the following is the Source code in my FUNCTION MODULE and this i have few parameters in my report
MARKET
MEMBER
EFFECTIVE DATE
STATUS
COUNTRY
ADMISSION TYPE
I need the output from Different Select options (PARAMETER OPTIONS) from the User point of view..this is Just one market's (XETRA) selections .. I have 13 markets... Kindly anyone help me with the similar output I need a dynamic selection ...
SAMPLE or EXAMPLE CODE appreciated...
CASE iv_market.
WHEN lc_xtra_market.
lv_table = 'ZTGP_MEMBER_XTRA'.
IF iv_member_id IS INITIAL AND iv_country IS INITIAL AND iv_adm_type IS INITIAL.
SELECT ztgp_member_xtra~xetra_id
ztgp_member_xtra~admission
ztgp_member_xtra~partner
ztgp_member_xtra~status
ztgp_member_xtra~adm_type
ztgp_member_xtra~object_id
ztgp_member_xtra~addrnumber
ztgp_member_xtra~beg_dat
adrc~country
INTO (lt_member-member_id, lt_member-admission, lt_member-partner, lt_member-status, lt_member-adm_type,
lt_member-object_id, lt_member-addrnumber, lt_member-beg_dat,lt_member-country)
FROM ztgp_member_xtra JOIN adrc ON ztgp_member_xtraaddrnumber = adrcaddrnumber WHERE ztgp_member_xtrastatus EQ iv_status AND ztgp_member_xtrabeg_dat LE iv_date_effective AND
ztgp_member_xtra~end_dat GE iv_date_effective.
APPEND lt_member.
ENDSELECT.
ELSEIF NOT iv_member_id IS INITIAL AND iv_country IS INITIAL AND iv_adm_type IS INITIAL.
SELECT ztgp_member_xtra~xetra_id
ztgp_member_xtra~admission
ztgp_member_xtra~partner
ztgp_member_xtra~status
ztgp_member_xtra~adm_type
ztgp_member_xtra~object_id
ztgp_member_xtra~addrnumber
ztgp_member_xtra~beg_dat
adrc~country
INTO (lt_member-member_id, lt_member-admission, lt_member-partner, lt_member-status, lt_member-adm_type,
lt_member-object_id, lt_member-addrnumber, lt_member-beg_dat,lt_member-country)
FROM ztgp_member_xtra JOIN adrc ON ztgp_member_xtraaddrnumber = adrcaddrnumber
WHERE ztgp_member_xtra~xetra_id EQ iv_member_id AND
ztgp_member_xtra~status EQ iv_status AND
ztgp_member_xtra~beg_dat LE iv_date_effective AND
ztgp_member_xtra~end_dat GE iv_date_effective.
APPEND lt_member.
ENDSELECT.
ELSEIF NOT iv_member_id IS INITIAL AND NOT iv_country IS INITIAL AND iv_adm_type IS INITIAL.
SELECT ztgp_member_xtra~xetra_id
ztgp_member_xtra~admission
ztgp_member_xtra~partner
ztgp_member_xtra~status
ztgp_member_xtra~adm_type
ztgp_member_xtra~object_id
ztgp_member_xtra~addrnumber
ztgp_member_xtra~beg_dat
adrc~country
INTO (lt_member-member_id, lt_member-admission, lt_member-partner, lt_member-status, lt_member-adm_type,
lt_member-object_id, lt_member-addrnumber, lt_member-beg_dat,lt_member-country)
FROM ztgp_member_xtra JOIN adrc ON ztgp_member_xtraaddrnumber = adrcaddrnumber
WHERE ztgp_member_xtra~xetra_id EQ iv_member_id AND
adrc~country EQ iv_country AND
ztgp_member_xtra~status EQ iv_status AND
ztgp_member_xtra~beg_dat LE iv_date_effective AND
ztgp_member_xtra~end_dat GE iv_date_effective.
APPEND lt_member.
ENDSELECT.
ELSEIF iv_member_id IS INITIAL AND NOT iv_country IS INITIAL AND iv_adm_type IS INITIAL.
SELECT ztgp_member_xtra~xetra_id
ztgp_member_xtra~admission
ztgp_member_xtra~partner
ztgp_member_xtra~status
ztgp_member_xtra~adm_type
ztgp_member_xtra~object_id
ztgp_member_xtra~addrnumber
ztgp_member_xtra~beg_dat
adrc~country
INTO (lt_member-member_id, lt_member-admission, lt_member-partner, lt_member-status, lt_member-adm_type,
lt_member-object_id, lt_member-addrnumber, lt_member-beg_dat,lt_member-country)
FROM ztgp_member_xtra JOIN adrc ON ztgp_member_xtraaddrnumber = adrcaddrnumber
WHERE adrc~country EQ iv_country AND
ztgp_member_xtra~status EQ iv_status AND
ztgp_member_xtra~beg_dat LE iv_date_effective AND
ztgp_member_xtra~end_dat GE iv_date_effective.
APPEND lt_member.
ENDSELECT.
ELSEIF iv_member_id IS INITIAL AND iv_country IS INITIAL AND NOT iv_adm_type IS INITIAL.
SELECT ztgp_member_xtra~xetra_id
ztgp_member_xtra~admission
ztgp_member_xtra~partner
ztgp_member_xtra~status
ztgp_member_xtra~adm_type
ztgp_member_xtra~object_id
ztgp_member_xtra~addrnumber
ztgp_member_xtra~beg_dat
adrc~country
INTO (lt_member-member_id, lt_member-admission, lt_member-partner, lt_member-status, lt_member-adm_type,
lt_member-object_id, lt_member-addrnumber, lt_member-beg_dat,lt_member-country)
FROM ztgp_member_xtra JOIN adrc ON ztgp_member_xtraaddrnumber = adrcaddrnumber
WHERE ztgp_member_xtra~adm_type EQ iv_adm_type AND
ztgp_member_xtra~status EQ iv_status AND
ztgp_member_xtra~beg_dat LE iv_date_effective AND
ztgp_member_xtra~end_dat GE iv_date_effective.
APPEND lt_member.
ENDSELECT.
ENDIF.
WHEN lc_repo_market.
WHEN lc_eurex_market.
When lc_fwb_market.
and so on... 13 markets..
ENDIF.
IF sy-subrc NE 0.
ENDIF.
WHEN OTHERS.
EXIT.
ENDCASE.In your case your internal tables seems to have constant and same structure so it can be defined statically.
lv_table & lv_where_cond are variables.
SELECT F1 F2 FROM (lv_table)
INTO CORRESPONDING FIELDS OF TABLE itab
WHERE (lv_where_cond). -
PARAMETERS: p_table LIKE dd02t-tabname OBLIGATORY.
SELECT *
FROM (p_table) CLIENT SPECIFIED
INTO CORRESPONDING FIELDS OF TABLE <dyn_table>
WHERE mandt = '800'.
mandt is the system client number as 800.
dyn_table: dynamic internal table
p_table = mara.
runtime error occurs at this statement.
SQL error in the database when accessing a table.
Kindly guide.Try
CASE xdetails-type_kind.
WHEN 'C'.
xfc-datatype = 'CHAR'.
WHEN 'N'.
xfc-datatype = 'NUMC'.
WHEN 'D'.
xfc-datatype = 'DATE'.
WHEN 'P'.
xfc-datatype = 'PACK'.
WHEN OTHERS.
xfc-datatype = xdetails-type_kind.
ENDCASE.
instead of
xfc-datatype = xdetails-type_kind.
You can also check this link:
http://wiki.sdn.sap.com/wiki/display/ABAP/DynamicInternaltable
Or try to do it like this:
http://wiki.sdn.sap.com/wiki/display/Snippets/Howtocreateadinamicinternaltable
It means to use FM REUSE_ALV_FIELDCATALOG_MERGE instead of using cl_abap_typedescr.
Adrian -
Dynamic select-statement with ranges
Good morning experts,
I just wanted to know if this is possible:
I had a report with a selection-screen where I can enter a table-name and one ore more filed-names (separated by ;).
After that, I create a table like my entered (for example MARA)
CREATE DATA gt_table TYPE TABLE OF (p_tab).
ASSIGN gt_table->* TO <gt_table>.
Then I split my entered fields (at and for each filed I made a selection (with function COMPLEX_SELECTIONS_DIALOG).
Result of this is for each field a range-tab which I write in a new table - first column is the name of the field, second column is a range-tab:
TYPES: BEGIN OF t_ranges,
sign TYPE tkeppllevs-sign,
opt TYPE tkeppllevs-opt,
low TYPE rsdslow,
high TYPE rsdslow,
END OF t_ranges.
DATA: BEGIN OF gs_conditions,
fieldname TYPE string,
ranges TYPE TABLE OF t_ranges.
DATA: END OF gs_conditions.
DATA: gt_conditions LIKE TABLE OF gs_conditions.
Now I want to make a select on the entered table (MARA).
So I make a loop on my gt_conditions:
LOOP AT gt_conditions INTO gs_conditions.
l_index = sy-tabix.
CONCATENATE 'gt_conditions[' l_index ']-ranges' INTO l_condition.
CONDENSE l_condition NO-GAPS.
CONCATENATE gs_conditions-fieldname 'IN' l_condition INTO lt_condition SEPARATED BY space.
IF sy-tabix > 1.
CONCATENATE 'AND' lt_condition INTO lt_condition SEPARATED BY space.
ENDIF.
APPEND lt_condition.
ENDLOOP.
If I look at it after the loop, it looks correct:
MATNR IN gt_conditions[1]-ranges
AND ERSDA IN gt_conditions[2]-ranges
But this wont work because of "gt_conditions[1]-ranges". I know, i can work with the "table in table", because gs_conditions-ranges works (I already tested this).
Has anybody any idea how to make my idea work?@Hymavathi:
Error is the following:
An exception occurred that is explained in detail below.
The exception, which is assigned to class 'CX_SY_DYNAMIC_OSQL_SEMANTICS', was
not caught and
therefore caused a runtime error.
The reason for the exception is:
The current ABAP program has tried to execute an Open SQL statement
which contains a WHERE, ON or HAVING condition with a dynamic part.
The part of the WHERE, ON or HAVING condition specified at runtime in
a field or an internal table, contains the invalid value
"GT_CONDITIONS[1]-RANGES".
@Hymavathi, second time:
This is the whole code for the select:
LOOP AT gt_conditions INTO gs_conditions.
l_index = sy-tabix.
CONCATENATE 'gt_conditions[' l_index ']-ranges' INTO l_condition.
CONDENSE l_condition NO-GAPS.
CONCATENATE gs_conditions-fieldname 'IN' l_condition INTO lt_condition SEPARATED BY space.
IF sy-tabix > 1.
CONCATENATE 'AND' lt_condition INTO lt_condition SEPARATED BY space.
ENDIF.
APPEND lt_condition.
ENDLOOP.
SELECT * FROM (p_tab)
INTO TABLE <gt_table>
WHERE (lt_condition).
You can see, the select is after the loop. So gs_conditions-ranges wouldn't be right, then the where statement would only use the last range-tab from my table gt_conditions. (loop at...endloop => gs-conditions-range = last gt_conditions-range).
Maybe you are looking for
-
Hi Experts, Collection of messages in BPM is not working,IP is executing for each Idoc.Actually i have done the sceanrio Idoc to File,Here I am getting multiple IDocs of same type from R3 when run a transaction and i would be generate a single file f
-
Can you change the hotkeys in Apple DVD Player?
I'm trying to change the hotkeys in Apple DVD Player. Really, all I want to do is add a hotkey for slow motion. I need the hotkeys because I'm using a ShuttleXpress shuttle mouse and I want to beable to click a button to put it in slow motion instead
-
Integration between WLC 5508 and Microsoft NPS 2008
Hi guys, Any of you, have working guidance for WLC 5508 and Microsoft NPS 2008 integration? I managed to configure Wireless 802.1x feature (PEAP) but it failed. I'm running software ver. 7.0.116.0. Is there any bug related 802.1x on this software ver
-
I bought my first Mac in february and I love everything about it. that said, I've been trying to get my hands on as much software as possible and I'm interested in learning about xCode. is there somewhere I can get started, right from scratch? I don'
-
My iphone has malfuctioned and is not useable, but everything is saved to icloud. I cannot figure how to access the photo stream from iCloud from the iphone camera , onto the new iMac. I was able to download my entire iTunes library onto my new iMac