Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Select query to get multiple fields in single field...

himanshu_gupta13
Active Participant
0 Kudos

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

11 REPLIES 11

Former Member
0 Kudos

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

0 Kudos

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

0 Kudos

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.

bastinvinoth
Contributor
0 Kudos

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

0 Kudos

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

0 Kudos

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.

0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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.

former_member189845
Active Participant
0 Kudos

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):

SELECT FN MN LN

FROM EMP

INTO (FN, MN . LN).
CONCATENATE FN MN LN INTO somecharvariable.
ENDSELECT.where "FN, MN, LN somecharvariable" are your program variables.

or


Can u just check with the below query

SELECT CONCAT(first_name, midde_name, last_name) AS full_name FROM table_name;

himanshu_gupta13
Active Participant
0 Kudos

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