04-12-2013 12:55 PM
Dear Gurus,
I am looking for a select query to get multiple fields in single field...
like if I have to retrieve first name, middle name and last name in single field name...
e.g. ::
SELECT FNAME MNAME LNAME AS NAME "here fname mname lname take in name and try to get in name field..
INTO NAME
FROM YEMPMST
WHERE EMPCD = '12345'.
ENDSELECT.
NOTE: here select query is incorrect, I just wrote here to make you easier to understand what I want...
Many Thanks / Himanshu Gupta
04-12-2013 1:11 PM
Hi Himanshu,
You can fetch the fields in different variables and use a concatenate to get them all as a single field.
Regards,
Sonal Singh
04-12-2013 1:19 PM
Hi Sonal,
Thanks for reply....
I know this but I am looking for a query so it make my life easier and also help me in future....
If any type of query available here in SAP ABAP
Many Thanks / Himanshu Gupta
04-12-2013 1:24 PM
Hi Himanshu,
What sonal said is correct.try the below code
data: lv_string type string.
SELECT FNAME MNAME LNAME
into (lv_FNAME,lv_ NAME,lv_LNAME)
FROM YEMPMST
WHERE EMPCD = '12345'.
concatenate lv_FNAME lv_ NAME lv_LNAME into lv_string.
ENDSELECT.
04-12-2013 1:18 PM
like you said,
if I have to retrieve first name, middle name and last name in single field name...
best way for this is get the three fields in single select query and pass to three variables and concatenate those variables to single field,and display it in output.
CONCATENATE name1 name2 name3 INTO name.
WRITE name.
Regards,
Bastin.G
04-12-2013 1:21 PM
Hi Bastin,
Thanks for reply....
I know this but I am looking for a query so it make my life easier and also help me in future....
If any type of query available here in SAP ABAP
Many Thanks / Himanshu Gupta
04-12-2013 1:27 PM
are you expecting following query ?
data:name1(20),
name2(20),
var3 type string.
select single name1 name2 from kna1 into var1 var2 where kunnr = '100000'.
concatenate var1 var2 into var3 separated by space.
04-12-2013 1:42 PM
Hi Bastin,
Plz look below query use in .net or php other languages...
Select cat_name as cat_1, cat_2_name as cat_2, CONCAT(cat_name.' '.cat_2_name) as name_combo from `table`
here cat_name and cat_2_name are concatenate in select statement as in variable name_combo....
So, I want same in SAP ABAP....
Many Thanks / Himanshu Gupta
04-12-2013 1:23 PM
Hi Himanshu,
PLease see the below code..
DATA:
W_FNAME type YEMPMST-Fname,
W_MNAME type YEMPMST-Mname,
W_LNAME type YEMPMST-Lname,
w_fullname type char255.
Select SINGLE Fname Mname Lname
FROM <table name>
INTO ( w_fname, w_Mname, w_Lname )
WHERE EMPCD = '12345'.
CONCATENATE w_fname w_Mname w_Lname INTO w_fullname SEPARATED BY space.
hope this helps u...
Regards,
Azharuddin
04-12-2013 1:33 PM
Hi Himanshu,
There is no select query who will internally concatenate all the 3 variables in to single field atleast not in the select statement.
1) Create a function module and then concatenate all the 3 fields (importing paramteres) into single field (exporting paramater).
You can use this function module in future whenever you want this single field.
2) search if there is BAPI for the same. Sometimes BAPI have structure where it internally concatenates similar fields. For ex: Name1, Name2 & Name3 generally will be put in a single name.
Thank you.
Best Regards,
Varun D.
04-12-2013 1:46 PM
Hi
Unfortunately ABAP Open SQL has very limited syntax, and there is virtually no field calculations (except aggregate functions). In your case you can for example do the following (not the best one though, as SELECT...ENDSELECT should be avoided if possible):
FROM EMP
INTO (FN, MN . LN).or
Can u just check with the below query
SELECT CONCAT(first_name, midde_name, last_name) AS full_name FROM table_name;
04-12-2013 2:04 PM
Hii Sivaramakrishna,
I am very thankful to you to help me clarify that such type of facility or function is not available in SAP ABAP,
Now I will work it simple as usual...
And also thanks to all others who lights on this discussion...
Many Thanks / Himanshu Gupta