Application Development and Automation 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: 
Read only

how to call 50 fields from table example sflight into sql statement

0 Likes
5,476

hi experts  i have to write a prog with 3 tables and in 1st table I have to call 50 fields carrid connid fldate price......... till 50.

it takes lot of time to write each and every field.so, how to call those fields in sql statement any short cut or tips...

thank you in advance

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
5,357

It probably takes less time to type them in than asking the question here and waiting for an answer.

Rob

23 REPLIES 23
Read only

Former Member
0 Likes
5,358

It probably takes less time to type them in than asking the question here and waiting for an answer.

Rob

Read only

0 Likes
5,357

it doesn't matter with no. if i have to write 250 fields then it takes time right.

ex:-

select carrid connid fldate price........250th field.

how to write above mentioned example of sql stat

Read only

matt
Active Contributor
0 Likes
5,357

If you have to manually put in more than ~20 fields then you're doing something wrong. Maybe the spec is wrong, maybe the requirement is silly. But chances are - it isn't necessary.

Read only

0 Likes
5,357

Yea i know  that i dont have requirement with 50 fileds. If the requirement comes then what should i do.

Read only

matt
Active Contributor
0 Likes
5,357

What should you do? Question it strongly.

I've been doing ABAP since 1997. I've never encountered such a situation. So why worry about it?

Read only

Former Member
0 Likes
5,357

Hi Akshay,

Interesting requirement you have, one way off the top of my head i can think possible doing this would be to dynamically generate parts of the sql statement using concatenation of strings.

To do this i would use the FM GET_COMPONENT_LIST which will return all the details about your ITAB. Then use a loop to loop through the result set and concatenate the field names into a string variable. Once you have done that you just use the string variable in place of the field names in the sql statement and SAP will run the query. I've done this before when i had to take dynamic list of conditions into consideration.

The code for the sql should look something like this Select (select_condition) FROM table_name ....

the ( ) are required for ABAP to treat the string as actual input into the sql. Below is an example i've done in a program before

         TABLE = 'Z_SPL_AUDIT'.

         CONCATENATE WHERE_CLS_1 '=' STATUS INTO WHERE_CLS_1 SEPARATED BY ' '.

         CONCATENATE DATE_FIELD 'BETWEEN' DATE_LOW 'AND' DATE_HIGH INTO WHERE_CLS_2 SEPARATED BY ' '.      

         SELECT * FROM (TABLE) INTO CORRESPONDING FIELDS OF TABLE REPORT_T_FINAL

                  WHERE (WHERE_CLS_1) AND (WHERE_CLS_2).


The only unknown i have is i have not tried this dynamic approach in the actual Select portion only in the table and where clause but i would expect it to work still.

Hope this helps,

Geoffery

Read only

Former Member
0 Likes
5,357

Hi,

Is this an interview question?

Why not just use select * into corresponding.

The structure of the internal table though has to have the 50 fields with the exact same name that it appears in database.

Kind regards, Rob Dielemans

Read only

0 Likes
5,357

this is not a interview question.

if i use select *  into corresponding    then performance drops.

Regards

Akshay Labhishetty

Read only

0 Likes
5,357

No - INTO CORRESPONDING won't give much of a performance hit. There are plenty of discussions on that topic in the ABAP space.

Rob

Read only

matt
Active Contributor
0 Likes
5,357

SELECT * may be a performance hit - especially with HANA. I've had massive gains in non-HANA and HANA systems by replacing * with a field list. However, as I said above, I can't think I've ever had to do more that ~20 fields. The fact is very very few realistic programs actually need more data than that.

SELECT INTO TABLE and SELECT INTO CORRESPONDING FIELDS OF TABLE are, as you say, performance-wise pretty much identical.

Read only

matt
Active Contributor
0 Likes
5,357

SE11. Copy and paste. Simples.

Read only

0 Likes
5,357

how to cop from se11.

should i copy each and every field. if so, for n example i have 250 fields then what should i do.

my requirement is show below as example.

ex:-

select carrid connid fldate price........250th field.

how to write above mentioned example of sql stat

Read only

Former Member
0 Likes
5,357

Have you tried Ctrl + Y to copy the fields from SE11?

-Chandra

Read only

0 Likes
5,357

no. will it happen.

if so

i need particular fields then what shuld i do

Read only

Former Member
0 Likes
5,357

Are you saying that you need the first 50 fields in the structure or 50 particular fields?

In any event, I think you have enough answers to do this.

Rob

Read only

0 Likes
5,357

I need solution for both the case.

i.e For 1st 50 and for particular 50.

Read only

VenkatRamesh_V
Active Contributor
0 Likes
5,357

Hi Akshay,

Try,

DATA: BEGIN OF TY_MARA,

         MATNR TYPE MARA-MATNR,

         ERSDA TYPE MARA-ERSDA,

         ERNAM TYPE MARA-ERNAM,

         LAEDA TYPE MARA-LAEDA,

       END OF TY_MARA.


Just copy the fields to select Query.


Hope it helpful,


Regards,

Venkat.



Read only

0 Likes
5,357

bro i know that technique.

i want sol for the below shown example

ex:-

select carrid connid fldate price........250th field.

how to write above mentioned example of sql stat

Read only

matt
Active Contributor
0 Likes
5,357

If you cannot answer the question of why you need to have such a ridiculously high number of fields I will lock this thread.

You've already had a lot of guidance over what appears, frankly, to be quite a trivial issue.

Read only

0 Likes
5,357

My friend gave me a task to write a report of any table with all the fields present in it. So i am asking here.

Read only

0 Likes
5,357

Hi,

make the structure in your report in the way like Ventak suggested.

USE ALT+SHIFT+down arrow to select those fields..COPY them

paste after SELECT keyword that's all you can do (in the end).

thanks!!

Read only

0 Likes
5,357

Thanks Bro its working.

Read only

matt
Active Contributor
0 Likes
5,357

In that case, there's been enough discussion of a trivial, hypothetical question, so I'm locking the thread.