Concatenate name in select query...
Hi Pals,
I was wondering how to directly concetenate client name in the select query itself...
Currently the code says :
SELECT SINGLE NAME1 NAME2
INTO (V_NAME1,V_NAME2)
FROM KNA1
WHERE KUNNR = I_PROJ-ZZCLIENT.
CONCATENATE V_NAME1 V_NAME2 INTO I_PROJ-CLNAME SEPARATED BY SPACE.
Can we say some thing like...
SELECT SINGLE ( NAME1 + ' ' + NAME2 ) AS CLNAME
INTO I_PROJ-CLNAME
FROM KNA1
WHERE KUNNR = I_PROJ-ZZCLIENT.
But its giving error...
Basically i need a single select query which would give me space seperated clientname in I_PROJ directly
Please help me...
Regards,
Abhishek B.
Hi Abhishek,
OPEN SQL.
1. Sap works on the concept of Open Sql.
ie. Sql is database independent.
2. ABAP Syntax does not have provision for
using such EXPRESSIONS (like concatenate)
directly in SQL.
3. However u may use them in Native Sql.
4. In open sql one can use aggregate functions
like SUM COUNT etc.
But Concatenate is not allowed.
Hope u find the answer useful.
(To newbees)
U may please award points (if u find the reply useful)
by clicking on the STAR on the left of the reply.
Regards,
Amit M.
Similar Messages
-
How to assign table name for select query in loop.
Hi friends my requirement is count the no of records of all the database table which comes into an internal table ."Check the below coding". Iam fetching the tables from dd03l table into an internal table .plz give me a sujjesion how to assign a table name in select query in a loop.
SELECT tabname FROM dd09l
INTO TABLE i_dd09l
WHERE protokoll = 'X'.
IF sy-subrc = 0.
SORT i_dd09l BY tabname.
ENDIF.
LOOP AT i_dd09l.
SELECT COUNT(*) INTO val FROM i_dd09l-tabname.
IF sy-subrc = 0.
i_dd09l-count = val.
ENDIF.
MODIFY i_dd09l INDEX sy-index.
CLEAR val.
ENDLOOP.
error : 'I_DD09L-TABNAME' is not defined in the abap dictionary as a table.data: dy_table type ref to data,
dy_line type ref to data,
xfc type lvc_s_fcat,
ifc type lvc_t_fcat,
dy_field type ref to data.
LOOP AT i_dd09l.
perform get_structure using i_dd09l-tabname .
CREATE DATA dy_table TYPE TABLE OF (_dd09l-tab_name).
UNASSIGN <dyn_table>.
ASSIGN dy_table->* TO <dyn_table>.
SELECT COUNT(*) INTO val FROM <dyn_table>.
IF sy-subrc = 0.
i_dd09l-count = val.
ENDIF.
MODIFY i_dd09l INDEX sy-index.
CLEAR val.
ENDLOOP.
form get_structure using p_table.
data : idetails type abap_compdescr_tab,
xdetails type abap_compdescr.
data : ref_table_des type ref to cl_abap_structdescr.
Get the structure of the table.
ref_table_des ?=
cl_abap_typedescr=>describe_by_name( p_table ).
idetails = ref_table_des->components.
loop at idetails into xdetails.
clear xfc.
xfc-fieldname = xdetails-name .
xfc-datatype = xdetails-type_kind.
xfc-inttype = xdetails-type_kind.
xfc-intlen = xdetails-length.
xfc-decimals = xdetails-decimals.
append xfc to ifc.
endloop.
endform. "get_structure
Try like this hope it will work.
Regards,
madan. -
ORA-00904: invalid column name in select query by using abstract datatype
Hi,
I had created abstract datatype as PERSON_TY and ADDRESS_TY ,
after inserting the record . i'm tryng to select the column but i got the error , even i refferd all those thing. they are given that same please look this finde me a result.
SQL> DESC PERSON_TY
Name Null? Type
NAME VARCHAR2(25)
ADDRESS ADDRESS_TY
SQL> DESC ADDRESS_TY
Name Null? Type
STREET VARCHAR2(30)
CITY VARCHAR2(25)
STATE CHAR(2)
COUNTRY VARCHAR2(15)
SQL> SELECT * FROM EMPLOYE
2 ;
EMP_CODE
PERSON(NAME, ADDRESS(STREET, CITY, STATE, COUNTRY))
10
PERSON_TY('VENKAT', ADDRESS_TY('112: BLUE MOUNT', 'CHENNAI', 'TN', 'INDIA'))
20
PERSON_TY('SRINI', ADDRESS_TY('144: GREEN GARDEN', 'THAMBARAM', 'TN', 'INDIA'))
SQL> SELECT PERSON.NAME FROM EMPLOYE
2 ;
SELECT PERSON.NAME FROM EMPLOYE
ERROR at line 1:
ORA-00904: invalid column name
regards
venkiSELECT PERSON.NAME FROM EMPLOYEIf you look in the documentation, you will see that we need to alias the table in order to make this work:
select e.person.name from employees e
/Cheers, APC
Blog : http://radiofreetooting.blogspot.com -
How to pass the feild names of a select query dynamically?
Hi
How can we pass the feilds names in select query dynamically?
For example in my selection screen i wil be giving the table name, and feilds in that table.....
those feilds should be taken in my select query...
instead of
PARAMETERS : tab_name TYPE ddobjname .
SELECT *
FROM (tab_name)
INTO TABLE <newtab>
UP TO 25 ROWS.
parametrs : feild1 like-------
feild2----
i need select feild1 feild2 feild3 FROM (tab_name)
INTO TABLE <newtab>
UP TO 25 ROWS.by the way, contrary to popular belief there is no performance problem when using
SELECT * FROM dbtab INTO CORRESPONDING FIELDS OF TABLE itab WHERE ...
as long as the structure of itab contains only the required fields.
I ran some benchmarks against this and above construct is maybe 0.1% slower (Oracle 10g) than a
SELECT f1 f2 f3 f4 ... FROM dbtab INTO TABLE itab WHERE ...
but is saves you from maintaining a potentially very long field list in your code. So when you need additional fields later on, you just add them to the DDIC structure or type definition and that's it.
Maybe something you want to factor in here.
Cheers
Thomas -
How to select Subpartition name in a Select query?
Hi,
I have a table that is partitioned on date range and subpartitioned based on and ID list. Lets assume the table name is something like: MY_TABLE
The partition name would look like: P_20110126160527
The subpartition list is as follows: GB, IN, AU, US etc. The sub partition name for GB would look like
P_20110126160527_GB
I need to run a select query to fetch data from MY_TABLE along with Sub partition name. The result set needs to look like:
Name|Location|SubPartition
Sam|UK|P_20110126160527_GB
Tom|UK|P_20110126160527_GB
Dave|AU|P_20110126160527_AU
The data available in ALL_TAB_SUBPARTITIONS and USER_TAB_SUBPARTITIONS can't be used just because the only join condition available is the TABLE Name but we would also have to join on SUBPARTITION KEY. I am not sure how to achieve this.
Does anyone here have a clue?In a pinch, you could do something like this.
select col1, col2, col3, 'PARTITION_1' from your_table where key_col in <values for partition_1>
union all
select col1, col2, col3, 'PARTITION_2' from your_table where key_col in <values for partition_2>
union all
select col1, col2, col3, 'PARTITION_3' from your_table where key_col in <values for partition_3>
union all
...Or better yet:
select col1, col2, col3, case when key_col = 'x' then 'PARTITION_1'
when key_col = 'y' then 'PARTITION_2'
when key_col = 'z' then 'PARTITION_3'
end
from ...Of course, none of these would be "dynamic". -
Dynamic Select query is failing with error "Invalid Table Name"
OPEN rc FOR 'SELECT count(*) from :s' USING tab_name;
fetch rc into rec_count;
CLOSE rc;
my requirement is to build dynamic select query to retrieve the total count of rows in each table ( variable tab_name contains the table_name )
But I am getting stuck by this errror, not sure if there is any alternative !
ORA-00903: invalid table name
ORA-06512: at line 43OPEN rc FOR 'SELECT count(*) from '||tab_name;
fetch rc into rec_count;
CLOSE rc;
-- This will work
1. Create a sql statement.
2. Open ref cursor for that statement. -
Can we use concatenate in where clause of a select query
I have a select query as follows....
SELECT ebeln ebelp belnr vgabe bwart DMBTR
FROM ekbe
INTO TABLE i_ekbe
FOR ALL ENTRIES IN i_blck
WHERE ebeln = i_blck-ebeln AND ebelp =
i_blck-ebelp.
Now i want to retrieve data from BKPF ..can i write a select query something like....
select * from BKPF into itab
FOR ALL ENTRIES IN i_ekbe
where awkey = ( conatenate i_ekbe-belnr i_ekbe-gjahr )
OR ELSE...is there any other way to link table ekbe and bseg ???Hi Poonam,
SELECT ebeln ebelp belnr vgabe bwart DMBTR
FROM ekbe
INTO TABLE i_ekbe
FOR ALL ENTRIES IN i_blck
WHERE ebeln = i_blck-ebeln
AND ebelp = i_blck-ebelp.
select *
from BKPF
into table itab
FOR ALL ENTRIES IN i_ekbe
where belnr = i_ekbe-belnr.
If u want to check with AWKEY concatenate into seperate field and then use to check in where condition.
data: lw_awkey(20) type c.
CONCATENATE i_ekbe-belnr i_ekbe-gjahr INTO lw_awkey.
select *
from BKPF
into table itab
FOR ALL ENTRIES IN i_ekbe
where awkey = lw_awkey
Best regards,
raam -
Unknown Column Name "XYZ" not detemined untill runtime.Select query.
Hi,
I have written a query in ABAP.I am getting following error.Can some one help me resolve this.There is a column "LANDX" in standard table T005 of PI which i need to get values from. The problem is that the column is visible only at runtime and not otherwise.How can i fetch data from this coulmn writing a select query for this.
Query written is:
SELECT landx from T005 into table it_t005.
Error:
"Unknown column name "XYZ" not determined untill runtime,you cannot specify a field list."Hi Deepika u were right. that there is a landx field but it is included in that table.
so u cant exactly get it.
now u can get ur country name and iso code just like this.
tables: t005t , t005.
data: BEGIN OF it OCCURS 100,
landx like t005t-landx,
intca like t005-intca,
END OF it.
SELECT t005t~landx t005~intca into CORRESPONDING FIELDS OF TABLE it
from T005t
INNER JOIN t005 on ( t005t~land1 = t005~land1 ).
it is fulfilling ur need.
Edited by: Matt on Feb 3, 2009 7:49 AM - Please don't use txtspk -
Select query to get table names
Hi,
Can i retrieve a table name from a select query if i know value of one of the columns in the table?
GlenCan't you take a look at the source code and see what table those values are coming from? That's likely the easiest solution.
Barring that, you could use dynamic SQL, but it's going to be awfully inefficient. Something like
FOR x IN (SELECT * FROM user_tab_cols WHERE data_type = 'VARCHAR2')
LOOP
EXECUTE IMMEDIATE
'SELECT COUNT(*) FROM ' || x.table_name ||
' WHERE ' || x.column_name || ' = <<literal value>>'
INTO l_cnt;
IF( l_cnt > 1 )
THEN
DBMS_OUTPUT.PUT_LINE( 'Found the value' );
END IF;
END LOOP;This assumes that you know at least what data type the value is stored in. It's also going to generate a tremendous number of full table scans, so it'll be slow as molasses on a system of any size.
Justin -
How to dynamically add field name in where clause of select query in web dynpro?
Hello,
Can any body tell me how i can use select query with dynamic wheere condition.
i have a requirement like there are multiple input fields and i want to select data from two database
and condition may vary .Hi
In the where clause you need to write like
WHERE NAME LIKE 'DE%'
Regards
Sudheer -
Hi ABAPers,
Can you please tell me how to concatenate this two select qureies.
select ebeln knumv from ekko INTO
TABLE tt_knumv
where ebeln = p_ebeln.
select ebeln knumv from eslh INTO TABLE
tt_knumv FOR ALL ENTRIES IN tt_esll
where packno = tt_esll-sub_packno.
Regards
Abhinab MishraHi,
I dont think inner join is possible in this case since you are selecting the same fields from the two different tables into the single internal table vertically. It can be used to collect the data into the internal table horizontally but that would make no sense in this case. May be you can try something like this
data: t_temp type table of tt_knumv.
select ebeln knumv
from eslh
INTO TABLE tt_knumv
FOR ALL ENTRIES IN tt_esll
where packno = tt_esll-sub_packno.
select ebeln knumv
from ekko
INTO TABLE t_temp
where ebeln = p_ebeln.
loop at t_temp.
move-corresponding t_temp to tt_knumv.
append tt_knumv.
endloop.
Regards,
Vik -
Dynamic Select Query including Dynamic Tables with For all Entries
Hello everyone,
I need to create a select query which involves using of Dynamic Tables.
Suppose I have a dynamic table <d1> which consist of let say 10 records.
Now i need to make a select query putting data into another dynamic table <d2>
CONCATENATE keyfield '=' '<d1>' INTO g_condition SEPARATED BY space.
CONCATENATE g_condition '-' keyfield INTO g_condition.
SELECT * FROM (wa_all_tables-name) INTO CORRESPONDING FIELDS OF TABLE <d1>
FOR ALL ENTRIES IN <d1>
WHERE (g_condition).
But it is giving dump.
Please help me on this....Short text
A condition specified at runtime has an unexpected format.
What happened?
Error in the ABAP Application Program
The current ABAP program "ZNG_CUSTOMWRITE" had to be terminated because it has
come across a statement that unfortunately cannot be executed.
Error analysis
An exception occurred that is explained in detail below.
The exception, which is assigned to class 'CX_SY_DYNAMIC_OSQL_SEMANTICS', was
not caught in
procedure "WRITE_ARCHIVE_PROD" "(FORM)", nor was it propagated by a RAISING
clause.
Since the caller of the procedure could not have anticipated that the
exception would occur, the current program is terminated.
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 "ZCOURIER-ZCOURIERID".
CONCATENATE keyfield '=' g_header INTO g_condition SEPARATED BY space.
CONCATENATE g_condition '-' keyfield INTO g_condition.
SELECT * FROM (wa_all_tables-name) INTO CORRESPONDING FIELDS OF TABLE <dyn_table1>
FOR ALL ENTRIES IN <dyn_table>
WHERE (g_condition). -
Hi Team,
I have to select dynamic fields from database table GLT0.
This depends on period value given on screen.
If period is 01 then fields will be hsl01.
If period is 02 then fields will be hsl01 and hsl02.
If period is 03 then fields will be hsl01,hsl02 and hsl03 .
so on...till 12..
My code is throwing exception at select query.
"Error in module RSQL of the database interface."
My code :
*" Type declaration to store field name as per given period
TYPES : BEGIN OF y_fieldname ,
fieldname(10) TYPE c ,
END OF y_fieldname .
data t_fieldname TYPE STANDARD TABLE OF y_fieldname .
DO p_monat TIMES.
clear w_count .
MOVE sy-index TO w_count
IF sy-index LE c_9.
CONCATENATE c_hsl
c_0
w_count
INTO e_fieldname-fieldname.
APPEND e_fieldname TO t_fieldname.
ELSE.
CONCATENATE c_hsl
w_count
INTO e_fieldname-fieldname.
APPEND e_fieldname TO t_fieldname.
ENDIF.
ENDDO.
Get Local Currency Amounts
from table glt0 depending on period
SELECT (t_fieldname)
FROM glt0
INTO TABLE t_glto_with_saknr
FOR ALL ENTRIES IN t_bukrs
WHERE rldnr EQ c_00
AND rrcty EQ c_0
AND rvers EQ c_001
AND bukrs EQ t_bukrs-bukrs
AND ryear EQ p_gjahr
AND racct IN r_saknr.
Please guide me.
Thanking u in advance.
Sangeeta VermaHi Asik,
I m selecting all fields now as suggestd by u so in one record i have hsl01 to hsl12.
I have to calculate balance into e_glt0_bal-bal .This balance is summation of e_glt0_bal-hsl01 till e_glt0_bal-hsl12 (depending on monat).
I m using logic in process then
my code now :
data: w_monat_bal type string .
DO p_monat TIMES.
MOVE c_01 TO w_count .
CONCATENATE 'e_glt0_bal-hsl'
w_count
INTO w_monat_bal.
ASSIGN w_monat_bal TO <fs_monat_bal>.
e_glt0_bal-bal = e_glt0_bal-bal + <fs_monat_bal>.
w_count = w_count + c_01.
ENDDO.
But <fs_monat_bal> can not be added.
Giving exception :
Unable to interpret "e_glt0_bal-hsl01" as a number.
If I do <fs_monat_bal> type GLT0-hslvt instead to type any
Then assigning from w_monat_bal is not possible. -
I need to know the proper syntax for my SELECT query, please.
Hello All,
Quick one for you:
Let's say that I have several columns in a table with names such as subject_1, subject_2, subject_3, etc. The table's name is subject_names.
The number in each of the three column name examples is also a value passed along a query string, the user can select choices, 1, 2 or 3. That query string's variable is $qs.
So, what I want is a SELECT query that uses the query string value as follows (KEEP IN MIND, I know this is not the proper syntax):
"SELECT subject_[$qs]
FROM subject_names";
I have tried all sorts of cominations of quotes (single and double), dots, brackets, braces and parenthesis. I just want to know how to include such a variable within this code.
Any and all help is sincerely appreciated!
Cheers,
wordmanWell, I did give you the syntax though.
$query = 'SELECT ' . $qs . ' FROM tbl_name';
I put spaces between the periods this time to make it more clear.
If you put the actual word 'subject' in there and just want your form to name it's options as the numbers available you could do this:
$query = 'SELECT subject_' . $qs . ' FROM tbl_name';
In PHP you can use either single or double quotes around your query string, I always just use single quotes. I see a lot of other use double quotes.
Double quotes would look like:
$query = "SELECT subject_' . $qs . ' FROM tbl_name";
Or when using double quotes you can actually just place the variable right in the string without having to concatenate multiple strings like above.
Since you mentioned that you are good with passing variables I probably don't have to mention that you need to set the value attribute of your option tags (if you are using a select) to the value you want them to pass.
Ex:
<select name="choices">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
If you have that part all figured out then you can use the syntax above for your query string.
Good luck. -
Dynamic select query with dynamic where condition
Hi all,
I want to use the dynamic select query with dynamic where condition. For that I used the below code but I am getting dump when using this code.
Please advice, if there is any other way to achieve this requirement.
Thanks,
Sanket Sethi
Code***************
PARAMETERS: p_tabnam TYPE tabname,
p_selfl1 TYPE edpline,
p_value TYPE edpline,
p_where1 TYPE edpline .
DATA: lt_where TYPE TABLE OF edpline,
lt_sel_list TYPE TABLE OF edpline,
l_wa_name TYPE string,
ls_where TYPE edpline,
l_having TYPE string,
dref TYPE REF TO data,
itab_type TYPE REF TO cl_abap_tabledescr,
struct_type TYPE REF TO cl_abap_structdescr,
elem_type TYPE REF TO cl_abap_elemdescr,
comp_tab TYPE cl_abap_structdescr=>component_table,
comp_fld TYPE cl_abap_structdescr=>component.
TYPES: f_count TYPE i.
FIELD-SYMBOLS : <lt_outtab> TYPE ANY TABLE,
* <ls_outtab> TYPE ANY,
<l_fld> TYPE ANY.
struct_type ?= cl_abap_typedescr=>describe_by_name( p_tabnam ).
elem_type ?= cl_abap_elemdescr=>describe_by_name( 'F_COUNT' ).
comp_tab = struct_type->get_components( ).
comp_fld-name = 'F_COUNT'.
comp_fld-type = elem_type.
APPEND comp_fld TO comp_tab.
struct_type = cl_abap_structdescr=>create( comp_tab ).
itab_type = cl_abap_tabledescr=>create( struct_type ).
l_wa_name = 'l_WA'.
CREATE DATA dref TYPE HANDLE itab_type.
ASSIGN dref->* TO <lt_outtab>.
*CREATE DATA dref TYPE HANDLE struct_type.
*ASSIGN dref->* TO <ls_outtab>.
* Creation of the selection fields
APPEND p_selfl1 TO lt_sel_list.
APPEND 'COUNT(*) AS F_COUNT' TO lt_sel_list.
** Creation of the "where" clause
*CONCATENATE p_selfl1 '= '' p_value ''.'
* INTO ls_where
* SEPARATED BY space.
*APPEND ls_where TO lt_where.
* Creation of the "where" clause
APPEND p_where1 TO lt_where.
* Creation of the "having" clause
l_having = 'count(*) >= 1'.
* THE dynamic select
SELECT (lt_sel_list)
FROM (p_tabnam)
INTO CORRESPONDING FIELDS OF TABLE <lt_outtab>.
* WHERE (lt_where).Hi Sanket,
The above given logic of mine works for you, put the code in the If condition and try-
just like below:
IF NOT P_EBELN IS INITIAL.
lt_where = '& = ''&'' '.
REPLACE '&' WITH p_ebeln INTO lt_where.
REPLACE '&' WITH field_value INTO lt_where.
SELECT (lt_sel_list) INTO CORRESPONDING FIELDS OF TABLE <lt_outtab>
FROM (p_tabnam)
WHERE (lt_where).
ENDIF.
thanks\
Mahesh
Maybe you are looking for
-
R507 Digital Camera with Windows 7
HELP! I have an HP R507 digital camera with a SunDisk 64 MB memory card. Recently, I upgraded my O/S to Windows 7 , updated the drivers, and replaced the batteries in the camera. For some reason, the camera's memory will not empty after I downlo
-
What the data type of this variant? (in the following)
What's the datatype of the following variant (use probe and indicator): value -> 1356.00 I want to tranfer it to numerical data. When I tranfer it using "variant to data" function (the datatype used is string or numerical), An error occured: ERROR 9
-
HELP! My ipad screen is showing some kind of "snowy-white noise TV effect" it looks kind of "grainy". This happened when i was reading a pdf an zooming in for a better view, now this "snowy, grainy" screen is also showing up in the home screen...This
-
I can read NEF and RAW photos in iPhoto but not Aperature. What's up ?
How do I read and print NEF and RAW files ? Aperature is saying that the file format is incorrect but iPhoto reads them fine.
-
Having trouble with apple tv device!!
Having trouble with my apple tv device. Bought just before Christmas so practically brand new. Only used about 6 times. When I went to turn on today the light on the box is flashing and its asking to connect my hdmi cable to what looks like an itunes