Вы находитесь на странице: 1из 48

Re: What is the diffrence between select single * and Select upto 1 row? Answer select single f1 f2 f3 ...

into # 1 <wa> from <dbtab> where 0 Chittidi [IBSS INC]

<condition>. this where condition is important to fetch exact record from database . for thsi purpose we provide entire primary key combination in whrere conditon. by using this statement to read exact information . select f1 f2 f3 .... into <wa> from <dbtab> up to 1 rows where <condition> endselect. it reads the first record found which may not be exact . the where condition can be part of primary key combination. it is mainly used to validate the INPUT. IF WE ARE NOT PASSING ENTIRE COMBINATION OF PRIMARY KEY IN SELET * SINGLE IT SIMPLY ACTS AS SELECT * UP TO 1 ROWS.
2 Yes 3 No

Is This Answer Correct ?

Re: What is the diffrence between select single * and Select upto 1 row? Answer Select Single * -- 1) Will 0 Kiran # 2 never have endselect.2) Kumar V Applicable key fields are

mentioned in Where clause.3) It retrieves the first record which matches the condition.

Select upto 1 row -- 1) Will have endselect. 2)Where clause is not mandatory. 3) Pull up all the records and display the first record in the list.
4 Yes 3 No

Is This Answer Correct ?

Re: What is the diffrence between select single * and Select upto 1 row? Answer If i know the answer, i would 0 M Raj # 3 have got the better job. 12 Yes 5 No

Is This Answer Correct ?

Re: What is the diffrence between select single * and Select upto 1 row? Answer The SELECT SINGLE statement 0 Ad # 4 selects the first record in the

database table depending on the condition mentioned in the WHERE clause. Only the first record is returned and may not be unique. ENDSELECT keyword is not needed here. But for the case of SELECT UPTO 1 ROW, all relevant records are being selected depending on the WHERE clause. Then any aggregate or grouping or ordering condition is applied to them and only the 1st record from the resultant set is

being returned. ENDSELECT is must here. SELECT SINGLE should be used for selecting with full primary key combination but SELECT UP TO 1 ROWS is the special case of SELECT UP TO n ROWS and can be used with any WHERE condition. As regarding the speed or performance it depends on various conditions. If your database table contains several entries, then SELECT UPTO 1 ROWS might take a longer time to fetch and order all relevant records. But for limited entries check for full primary key combination takes more time in case of SELECT SINGLE. If you donot provide all primary keys in SELECT SINGLE you will get message during extended syntax check (SLIN).
3 Yes 0 No

Is This Answer Correct ?

Re: What is the diffrence between select single * and Select upto 1 row? Answer I am agree with the above # 5 answers given but I am to add

few lines. Select Single can give you best performace when it is fired with full primary key. Select up to 1 rows is a special case of select up to n

rows. there is almost no difference in performace in small database. select single is used to check the avaviility of particular record in database.

Difference Between Select Single and Select UpTo One Rows


What is the differences between select single * and selct up to 1 row? Select Single * will pickup only one matching record from the database into the buffer, and returns the same to the internal table. Select upto 1 rows will pickup all the records matching the condition into the buffer, but return the top record to the internal table. For this reason, performance wise select upto 1 row is better than select upto 1 row. According to SAP Performance course the SELECT UP TO 1 ROWS is faster than SELECT SINGLE because you are not using all the primary key fields. select single is a construct designed to read database records with primary key. In the absence of the primary key, it might end up doing a sequential search, whereas the select up to 1 rows may assume that there is no primary key supplied and will try to find most suitable index. The best way to find out is through sql trace or runtime analysis. Use "select up to 1 rows" only if you are sure that all the records returned will have the same value for the field(s) you are interested in. If not, you will be reading only the first record which matches the criteria, but may be the second or the third record has the value you are looking for. The System test result showed that the variant Single * takes less time than Up to 1 rows as there is an additional level for COUNT STOP KEY for SELECT ENDSELECT UP TO 1 ROWS. The 'SELECT SINGLE' statement selects the first row in the database that it finds that fulfils the 'WHERE' clause If this results in multiple records then only the first one will be returned and therefore may not be unique. Mainly: to read data from The 'SELECT .... UP TO 1 ROWS' statement is subtly different. The database selects all of the relevant records that are defined by the WHERE clause, applies any aggregate, ordering or grouping functions to them and then returns the first record of the result set. Mainly: to check if entries exist. ABAP Tips by: Anjali Devi What is the difference between SELECT SINGLE and SELECT ... UP TO 1 ROWS?

SELECT SINGLE returns the first matching row for the given condition and it may not be unique, if there are more matching rows for the given condition. SELECT ... UP TO 1 ROWS retrieves all the matching aggregation and ordering and returns the first record. records and applies

Inorder to check for the existence of a record then it is better to use SELECT SINGLE than using SELECT ... UP TO 1 ROWS since it uses low memory and has better performance

Difference between select single and select upto.


Link to this Page Link Tiny Link OK Wiki Markup Cancel Close Click to select the Move Page Diff Search Error reading the

Set Page Location Move Recently View ed

There w ere no re Know n Location You must make a

The specified pag Brow se Failed to retrieve

You could try relo HTTP Status Move failed. Ther Wiki Unknow n user or

There w ere no pa Show ing <b>{0}< HOME

You cannot move Difference betw e You cannot move Page Ordering Page Restrictions Editing restricted Back Cancel Reorder Close

Move Save

Page restrictions apply Added by Anversha s, last edited by BI Buddy on Aug 13, 2008 (view change) Comment:

view

This is a very fequently asked question in SDN. Kinldy check this soltion as a reference. According to SAP Performance course the SELECT UP TO 1 ROWS is faster than SELECT SINGLE because you are not using all the primary key fields. select single is a construct designed to read database records with primary key. In the absence of the primary key, it might end up doing a sequential search, whereas the select up to 1 rows may assume that there is no primary key supplied and will try to find most suitable index. The best way to find out is through sql trace or runtime analysis. Use "select up to 1 rows" only if you are sure that all the records returned will have the same value for the field(s) you are interested in. If not, you will be reading only the first record which matches the criteria, but may be the second or the third record has the value you are looking for. The System test result showed that the variant Single * takes less time than Up to 1 rows as there is an additional level for COUNT STOP KEY for SELECT ENDSELECT UP TO 1 ROWS.

The 'SELECT SINGLE' statement selects the first row in the database that it finds that fulfils the 'WHERE' clause. If this results in multiple records then only the first one will be returned and therefore may not be unique. Mainly: to read data from the 'SELECT .... UP TO 1 ROWS' statement is subtly different. The database selects all of the relevant records that are defined by the WHERE clause, applies any aggregate, ordering or grouping functions to them and then returns the first record of the result set. ex code Differnece Between select single * and select upto n rows, Select Single * 1.It will fetch only one record from the data base in which it satisfies the where condition. 2.It has high performance compare to select upto n rows. 3.Syntax :select single * from lfa1 into table l_wa_lfa1. *********** Report Z_Difference Message-id 38 Line-Size 80 Line-Count 0 No Standard Page Heading. * Start-Of-Selection. Data: w_Single type Posnr, t_Rows type standard table of Posnr initial size 0 with header line. * Select single Posnr from zDifference into w_Single. * Select Posnr into table t_Rows Select upto n rows 1.It will fetch all the records with which the where condition satisfies and displays thefirst record among the selected records. 2.Lower in performance,because this statement will look all the related key field values in a given table. 3.Syntax : select * from lfa1 upto 1 rows into table l_t_lfa1..

from zDifference up to 1 rows order by Posnr descending. * Write :/ 'Select single:', w_Single. Skip 1. Write :/ 'Up to 1 rows :'. Loop at t_Rows. Write t_Rows. EndLoop.

================================================== ==============
select single v/s select up to 1 row
Posted: Feb 3, 2007 5:36 AM

Reply

Hi, I have an academic question.... what is the performance difference between SELECT SINGLE and SELECT UP TO 1 ROW Regards Mahesh.

Narendran Muthu...
Posts: 7,682 Registered: 11/21/04

Re: select single v/s select up to 1 row

Reply

Posted: Feb 3, 2007 5:39 AM

in response to:

mahesh kumar
Hi, Check this link..

Forum Points: 19,156


Top of Form

Bottom of Form

http://www.sap-img.com/abap/difference-between-select-single-andselect-upto-one-rows.htm
Thanks,

Naren

Subbu P
Posts: 1,709 Registered: 4/29/05

Re: select single v/s select up to 1 row

Reply

Posted: Feb 3, 2007 5:53 AM

in response to:

mahesh kumar
Hi, Performance wise, Select Up To 1 Row is best, because...when the program encounters a SELECT Single query for the first time, the query goes to the Database and fetches the data. This happens for each and every time select single is encountered. SO, what happens in select up to 1 row, the record resides in the memory itself after the execution of the query. When again the select up to 1 row is executed, the debugger checks the memory first if not found then only the query is hit at the database. This improves the performance and reduces the database hits. Regards Subramanian

Forum Points: 2,802


Top of Form

Bottom of Form

mahesh kumar
Posts: 131 Registered: 1/9/07

Re: select single v/s select up to 1 row

Reply

Posted: Feb 3, 2007 2:08 PM

in response to:

Subbu P
Hi, Thanks for ur replies.... I am working on selection screen validations( both PARAMETERS & SELECT-OPTIONS) so please suggest me what to use whether SELECT UP TO 1 ROW or SELECT SINGLE and why? Thanks and Regards Mahesh.

Forum Points: 14
Top of Form

Bottom of Form

Rahul Patni
Posts: 367 Registered: 1/19/07

Re: select single v/s select up to 1 row

Reply

Posted: Feb 4, 2007 10:24 AM

in response to:

mahesh kumar

Forum Points: 516


Top of Form

Hi Mahesh, For the Selection Screen Validation SELECT SINGLE * would be a better option as it would be called only once in the execution that is at the beginning of the report. Rest info is already provided to you.

Bottom of Form

Thanks.
muralikrishna k...
Posts: 2,429 Registered: 9/11/06

Re: select single v/s select up to 1 row

Reply

Posted: Feb 5, 2007 5:26 AM

in response to:

mahesh kumar
Mahesh,

Forum Points: 3,678


Top of Form

Bottom of Form

SELECt SINGLE : 1.select single is based on PRIMARY KEY 2.It will take the first record directly without searching of all relevant records.(Though you have lot of records for given condition) SELECT UPTO 1 ROW : It will check all records for given condition and take the first record . Means in select single no searching , where as other searching. So select single more efficient than UPTO 1 ROW. Pls.ark if useful.

Shiva H

Re: select single v/s select up to 1 row

Reply

Posted: Feb 5, 2007 6:14 AM Posts: 2,545 Registered: 9/15/05

in response to:

mahesh kumar
Hi, According to SAP Performance course the SELECT UP TO 1 ROWS is faster than SELECT SINGLE because you are not using all the primary key fields.

Forum Points: 3,168


Top of Form

Bottom of Form

select single is a construct designed to read database records with

primary key. In the absence of the primary key, it might end up doing a sequential search, whereas the select up to 1 rows may assume that there is no primary key supplied and will try to find most suitable index. The best way to find out is through sql trace or runtime analysis. Use "select up to 1 rows" only if you are sure that all the records returned will have the same value for the field(s) you are interested in. If not, you will be reading only the first record which matches the criteria, but may be the second or the third record has the value you are looking for. The System test result showed that the variant Single * takes less time than Up to 1 rows as there is an additional level for COUNT STOP KEY for SELECT ENDSELECT UP TO 1 ROWS. The 'SELECT SINGLE' statement selects the first row in the database that it finds that fulfils the 'WHERE' clause If this results in multiple records then only the first one will be returned and therefore may not be unique. Mainly: to read data from The 'SELECT .... UP TO 1 ROWS' statement is subtly different. The database selects all of the relevant records that are defined by the WHERE clause, applies any aggregate, ordering or grouping functions to them and then returns the first record of the result set. Mainly: to check if entries exist. Thanks Shiva
Anversha s
Posts: 3,326 Registered: 6/10/06

Re: select single v/s select up to 1 row

Reply

Posted: Feb 5, 2007 6:26 AM

in response to:

mahesh kumar
hi mahesh, chk this.

Forum Points: 5,414


Top of Form

Bottom of Form

ex code *********** Report Z_Difference Message-id 38 Line-Size 80 Line-Count 0

No Standard Page Heading. * Start-Of-Selection. Data: w_Single type Posnr, t_Rows type standard table of Posnr initial size 0 with header line. * Select single Posnr from zDifference into w_Single. * Select Posnr into table t_Rows from zDifference up to 1 rows order by Posnr descending. * Write :/ 'Select single:', w_Single. Skip 1. Write :/ 'Up to 1 rows :'. Loop at t_Rows. Write t_Rows. EndLoop. ******************************************* According to SAP Performance course the SELECT UP TO 1 ROWS is faster than SELECT SINGLE because you are not using all the primary key fields. select single is a construct designed to read database records with primary key. In the absence of the primary key, it might end up doing a sequential search, whereas the select up to 1 rows may assume that there is no primary key supplied and will try to find most suitable index. The best way to find out is through sql trace or runtime analysis. Use "select up to 1 rows" only if you are sure that all the records returned will have the same value for the field(s) you are interested in. If not, you will be reading only the first record which matches the criteria, but may be the second or the third record has the value you are looking for. The System test result showed that the variant Single * takes less time than Up to 1 rows as there is an additional

level for COUNT STOP KEY for SELECT ENDSELECT UP TO 1 ROWS. The 'SELECT SINGLE' statement selects the first row in the database that it finds that fulfils the 'WHERE' clause If this results in multiple records then only the first one will be returned and therefore may not be unique. Mainly: to read data from The 'SELECT .... UP TO 1 ROWS' statement is subtly different. The database selects all of the relevant records that are defined by the WHERE clause, applies any aggregate, ordering or grouping functions to them and then returns the first record of the result set. Mainly: to check if entries exist.

You can refer to the below link.. http://www.sap-img.com/abap/difference-between-select-single-andselect-upto-one-rows.htm rgds anver if helped mark points

mahesh kumar
Posts: 131 Registered: 1/9/07

Re: select single v/s select up to 1 row

Reply

Posted: Feb 5, 2007 6:43 AM

in response to:

Anversha s
Hi all, I read all the concerned messages from you people...thanks for all.. I am still in a confusion... my straight forward question is what I have to use SELECTION-SCREEN validation? either SELECT SINGLE or SELECT UP TO 1 ROW ? ..what is the best option is? Thanks and Regards Mahesh.

Forum Points: 14
Top of Form

Bottom of Form

Rajiv Krishna
Posts: 111 Registered: 11/21/06

Re: select single v/s select up to 1 row

Reply

Posted: Feb 5, 2007 6:49 AM

in response to:

mahesh kumar

Forum Points: 92
Top of Form

Hi Mahesh, Please use SELECT SINGLE for the validation of the parameters and selectoptions,, Thanks Rajiv

Bottom of Form

Rahul Patni
Posts: 367 Registered: 1/19/07

Re: select single v/s select up to 1 row

Reply

Posted: Feb 5, 2007 9:18 AM

in response to:

mahesh kumar
Mahesh, As replied before, For the Selection Screen Validation SELECT SINGLE * would be a better option as it would be called only once in the execution that is at the beginning of the report.

Forum Points: 516


Top of Form

Bottom of Form

Thanks.
Sreenivasulu Po...
Posts: 1,593 Registered: 3/10/06

Re: select single v/s select up to 1 row

Reply

Posted: Feb 5, 2007 2:43 PM

in response to:

mahesh kumar
Hi Mahesh, According to SAP Performance course the SELECT UP TO 1 ROWS is faster than SELECT SINGLE because you are not using all the primary key fields. select single is a construct designed to read database records with primary key. In the absence of the primary key, it might end up doing a sequential search, whereas the select up to 1 rows may assume that there is no primary key supplied and will try to find most suitable index. The best way to find out is through sql trace or runtime analysis. Use "select up to 1 rows" only if you are sure that all the records returned will have the same value for the field(s) you are interested in. If not, you will be reading only the first record which matches the criteria, but may be the second or the third record has the value you are looking for. The System test result showed that the variant Single * takes less time than

Forum Points: 1,802


Top of Form

Bottom of Form

Up to 1 rows as there is an additional level for COUNT STOP KEY for SELECT ENDSELECT UP TO 1 ROWS. The 'SELECT SINGLE' statement selects the first row in the database that it finds that fulfils the 'WHERE' clause If this results in multiple records then only the first one will be returned and therefore may not be unique. Mainly: to read data from The 'SELECT .... UP TO 1 ROWS' statement is subtly different. The database selects all of the relevant records that are defined by the WHERE clause, applies any aggregate, ordering or grouping functions to them and then returns the first record of the result set. Mainly: to check if entries exist.

You can refer to the below link.. http://www.sap-img.com/abap/difference-between-select-single-andselect-upto-one-rows.htm Regards Sreeni

Sharmila Subram...
Posts: 131 Registered: 1/13/06

Re: select single v/s select up to 1 row

Reply

Posted: Feb 6, 2007 10:28 AM

in response to:

mahesh kumar
Hi Mahesh, Whether it is Selection screen validation or anything else, if you need to check a single row, Selection should be considered on the following basis. SELECT SINGLE should be used when you consider all the key fields of the table in the selection criteria of select statement. Otherwise, you should go for SELECT UP TO 1 ROWS. Regards, Sharmila

Forum Points: 80
Top of Form

Bottom of Form

Sunil Yarlagadda
Posts: 166 Registered: 12/11/06

Re: select single v/s select up to 1 row

Reply

Posted: Feb 6, 2007 12:43 PM

in response to:

Rahul Patni
Hi Rahul,

Forum Points: 214

Top of Form

Any where in ABAP. If u r providing full primary key then go for SELECT SINGLE. ofherwise UP TO 1 ROWS best as performence wise, Regards, Sunil

Bottom of Form

mahesh kumar
Posts: 131 Registered: 1/9/07

Re: select single v/s select up to 1 row

Reply

Posted: Feb 6, 2007 2:14 PM

in response to:

Sunil Yarlagadda
Hi, Thanks all... I decided to go for SELECT SINGLE for selection screen validation as if the FULL PRIMARY KEY is available or SELECT UP TO 1 ROW if not. Is SELECT SINGLE work for partial primary key also? I mean some part of the primary key because primary key is a composite key for most of the transparent tables. Thanks and Regards Mahesh.

Forum Points: 14
Top of Form

Bottom of Form

Difference between select single and up to 1 row


Can any one tell what is the difference between select single * from kna1 and select * from kna1 up to 1 row. Raghavender Its reallly good question: Select single * from KNA1 where clause ---It fetches single record from the database, based on the condition you specified in the where clause. Where as select * from kna1 up to 1 row ---Fetches first record if the condition specified in the where clause is satisfied, otherwise it doesn't fetch any record. Janadhan

Whats The Difference. SELECT SINGLE or UP TO 1 ROWS, Whats The Difference ? A lot of people use the SELECT SINGLE statement to check for the existence of a value in a database prior to running a large report. Select singles are also used to look up values from a database where that value is going to be constant for the duration of the program run, or the value is being used to validate some user entry. Other people prefer to use the 'UP TO 1 ROWS' variant of the SELECT statement. So what's the difference between using 'SELECT SINGLE' statement as against a 'SELECT .... UP TO 1 ROWS' statement ? If you're considering the statements Code: SELECT SINGLE field INTO w_field FROM table. and Code: SELECT field INTO w_field FROM table UP TO 1 ROWS. ENDSELECT. then looking at the result, not much apart from the extra ENDSELECT statement. Look at the run time and memeory usage and they may be worlds apart. Why is this ?? The answer is simple. The 'SELECT SINGLE' statement selects the first row in the database that it finds that fulfils the 'WHERE' clause If this results in multiple records then only the first one will be returned and therefore may not be unique. The 'SELECT .... UP TO 1 ROWS' statement is subtly different. The database selects all of the relevant records that are defined by the WHERE clause or lack of, applies any aggregate, ordering or grouping functions to them and then returns the first record of the resultant result set. Get the difference ?? If not, then create a Ztable called ZDifference with 2 fields in it, MANDT of type MANDT and POSNR of type POSNR. Make sure both of these are keys. Also create a table maintenance dialog for it (SE11->Utilities->Table Maintenance Generator). Fill the table with ten rows 000001-000010. Then run the program shown below: Code:
************************************************************************ * * Program: Z_Difference * * Purpose: A program that demonstrates the difference * between SELECT SINGLE and SELECT UP TO n ROWS. *

* This program requires the data table Z_DIFFERENCE * to have been created according to the structure * outlined in the text above and populated with * at least 10 records. * * Creation Date: 21/04/2004 * * Requested By: * * Reference Doc: * * Author: R Harper * * Modification History: * * Date Reason Transport Who * ************************************************************************ Report Z_Difference Message-id 38 Line-Size 80 Line-Count 0 No Standard Page Heading. * Start-Of-Selection. Data: w_Single type Posnr, t_Rows * type standard table of Posnr initial size 0 with header line.

Select single Posnr from zDifference into w_Single. Select into from up to order Posnr table t_Rows zDifference 1 rows by Posnr descending.

Write :/ 'Select single:', w_Single. Skip 1. Write :/ 'Up to 1 rows :'. Loop at t_Rows. Write t_Rows. EndLoop.

You should see the output: Code: Select single: 000001 Up to 1 rows : 000010

The first 'SELECT' statement has selected the first record in the database according to any selection criteria in the 'WHERE' clause. This is what a 'SELECT SINGLE' does. The second 'SELECT' has asked the database to reverse the order of the records before returning the first row of the result. In order to be able to do this the database has read the entire table, sort it and then return the first record. If there was no ORDER BY clause then the results would have been identical (ie both '000001') but the second select if given a big enough table to look at would be far slower. Now. This causes a problem in the Extended Program Check in that if the full key is not specified in a 'SELECT SINGLE' you get a message like this: Quote: Program: Z_DIFFERENCE Line : 39 Syntax check warning This warning is only displayed in SLIN. Select single Posnr ^ Messages: In "SELECT SINGLE ...", the WHERE condition for the key field "POSNR" does not test for equality. Therefore, the single record you are searching for may not be unique. If you haven't specified a full key and your QA person is complaining that your Extended Check has warnings tell him "Yes. I can get rid of the warning but the program will run slower and consume more memory." You could always tell him to "Get Lost" but it's always better to have a valid reason before you do that! ======================================================
http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb3ac8358411d1829f000 0e829fbfe/frameset.htm ================================================== ==================

After Observing many interviews. Finally i come up with the following questions which are mostly asked in all the Big companies including SAP Labs, Accenture, IBM , Deloitte , TCS , Infosys etc 1. Can we write the code both call transaction and session method in single program? Ans. Yes it is possible to write call transaction and session in one program. 2. Which BDC you prefer? Ans. If we want to transfer large amount of data and when we need to use more than one transaction code we prefer session method. For small or less amount of data and for single transaction use call transaction. (This is more genric answer but you can add more on to this if you have worked on BDC) 3. When u prefer LSMW?

Ans. When we need to update medium amount of data we use LSMW. LSMW is also used when the person like functional consultant has less programming language. 5. Difference between .include and .append? Ans. Include structure allows to add one or more structure into structure or table.Also placed positioning anywhere. Upto 6 include structure can be used in a table. Append structure can be placed only at the end of a structure or table which also stops further insertion of fields.Only one append structure can be used 6. Preformance techniques Ans. 1. The sequence of fields must be same as per database table 2. During writing select query write all fields in sequence as per database table. 3. Never write select statements inside loop.endloop. 4. Use st05 SQL trace, se30 run time analysis, code inspector, slin,etc. 5. Use select single * statement instead of select * 6. Always use primary key 7. Use binary search but before using binary search sort that table. 7. How to debug sapscripts ? Ans. Two ways to debug sapscript . first way is goto SE 71 and from menu bar select Utilities>activate debugger .then goto SE38 execute the print program ,it automatically goes to debugging mode ..the other way is , run the program RSTXDBUG in se 38 . execute it . a message will show that debugger is activated .now open the print program in se 38 u vll notice that the print prgm is automatically diverted to debugging mode. 8. What is partner selection? Ans. This concept is mainly used in IDOC where u select the partner profile using Tcode We20 .with Tcode SM59 you create RFC(remote function call) to create communication link to a remote system. 10. What is occurs in internal table? Ans. Occurs addition to the Declaration will give initial size to that table.occur statement allocates 8kb of memory to the internal table. 11. What is page window? Ans : page window is nothing but a container of a page ,which uniquely identifies a set of data for example while creating invoice we create logo window , billing document header window , customer window , terms and condition window etc 12. What is the difference between scrolling a table horizontally and vertically..?? Ans: In table control when you scroll a table vertically presentation server needs to call application server to fetch the next record and display in the table while in case of horizontal scroll there is no need to call application server.

13. What are Field Groups? Ans: A group that combines several fields fewer than one name, at runtime, the INSERT command is used to define which data fields are assigned to which field group are called Field Groups. It should always be a HEADER field group that defines how the extracted data will be sorted; the fields grouped under the HEADER field group sort the data. 14. List the events in ABAP/4 Language? Ans: The events in ABAP/4 are load of program ,Initialization, Selection Screen, Start of Selection, End of Selection, Top of page, Line selection, User command, End, First. 15.How the values will be passed to RFC Function module PassbyValue or Passbyreference? Ans: always Pass by Value. RFC is Remote Function call so it cant access the values with Pass by reference. 16. Buffering concept usage? Ans: There are three type of buffer 1 single record 2 generic buffer 3 full buffer Buffering is use for improve performance. it improves performance 10 to 100 times more 17. Select up to 1 row and select single difference ? Ans: Select single fetches first matching record. If more than one matching records are there then only the first matching record will be considered other records will not be taken into account. Where as select up to 1 rows will fetch all the matching records from the database. (Again it will assign only One Record to the internal table/Work area) 18. What are the different buffering methods? There are two different buffering methods The system ensures that data transfer between the R/3 System and the database system is as efficient as possible. To do this, it uses the following techniques: Table buffering: The program accesses data from the buffer of the application server. Database request buffering: Individual database entries are not read or passed to the database until required by an OPEN SQL statement. 19. Different types of locks? v Read lock (shared lock) Protects read access to an object. The read lock allows other transactions read access but not write access to the locked area of the table. v o Write lock (exclusive lock) Protects write access to an object. The write lock allows other transactions neither read nor write access to the locked area of the table. v o Enhanced write lock (exclusive lock without cumulation)

Works like a write lock except that the enhanced write lock also protects from further accesses from the same transaction. 20. CHAIN END CHAIN? Ans: Chain and end chain are used for multiple field validation in Module pool programming .It is written inside the screen flow logic. 21.How to Debug RFC Function module? Ans: SE38 > Utilities > Settings > ABAP Editor > Debugging Activate the external debugging and choose the New Debugger option in ABAP debugger. Go to the particular place in the code and put break point, pop will appear then choose the HTTP break point. If you are triggering the RFC from SAP portal make sure that both the user ID should be same If the users are different then provide the XI/Portal User ID in the users field. 22.Why sapscripts are client dependent and smartforms are client independent.? Ans-: Smartforms create its own function module so it doesnt need to transport the request through SCC1.As all the Development Object are stored in client independent tables. Whereas Script doesnt generate any function module while executing so we need to transport the request number through SCC1.Sap script is stroed in side the client depended table as a TEXT.so sapscripts are client dependent and smartforms are client independent. 23. Difference between user exit and BADIs? Ans: User exit is for single implementation and it is procedural approach while BADIs are for multiple implementation and object oriented approach. Multiple implementation means Reusability because we use OOps Concepts for BADI. 24. Control break events in ABAP:1. AT-FIRST: This is used when we want to execute the statements before records are processed. 2. AT-LAST: This event is used when we want to execute the statements after all records are processed. 3. AT-NEW: This event is used when we want to execute the statement before group of records are processed. 4. AT-END: This event is used when we want to execute the statements after processing of group of records. 25.I am uploading 100 records out of which say 59th record has error so what will happen if i am using synchronous or asynchronous method of BDC? Can we update the database using local update mode how? 26. Suppose i am writing following code then what will be output? LOAD-OF-PROGRAM. WRITE:/HELLO. Ans: HELLO

(Explain the importance of LOAD-OF-PROGRAM Event.If you dont know Tell the interviewer as this event is used in such cases when you want to clear sum buffers or something Before calling that Program) 27. What is TMG? Ans. TMG stands for Table Maintenance generator. It is a tool available in abap by which we can add or delete multiple records at a time and it is executed or triggered by the transaction code SM30. 28. Difference between select option and ranges ? Ans. The main difference between select option and ranges is that ranges implicitly or automatically creates internal table with fields like OPTION,LOW,HIGH,SIGN,etc . Where as in case of select option we have to explicitly create internal table. When u declares a select options it will implicitly declare an internal table (ranges) for you. While using RANGES syntax u can declare internal table explicitly. The only need of declaring ranges is when you r not taking input from the user but you want make limit based selection at that time it will be use full e.g. SELECT ** from ** where MATNR in val_range. here u can use select-option or ranges : val_range. 29. is it possible to bring select option in module pool screens? Ans.Create a SELECT-OPTIONS in module pool screen using two methods as shown. Method 1:a) Create a subscreen area in your screen layout where you want to create the select options. b) In the top include of your module pool program declare a selection screen as a subscreen e.g. SELECTION-SCREEN BEGIN OF SCREEN 100 AS SUBSCREEN. select-options s_matnr for mara-matnr. SELECTION-SCREEN END OF SCREEN. c) In the PBO and PAI of the main screen where the select options needs to be created do a call subscreen of the above screen (100). CALL SUBCREEN sub_area INCLUDING <program> <screen> This CALL SUBSCREEN statement is necessary for transport of values between screen and program. Note: All validations of the selection screen fields e.g. the s_matnr field created above should be done in selection screen events like AT SELECTION-SCREEN etc and not in PAI. These selection screen validations etc should be done in the top include only. Method 2:a) Create 2 separate fields in your screen layout one for the low value and one for the high value. Insert an icon beside the high value which will call the multiple selections popup screen on user command. Use function module COMPLEX_SELECTIONS_DIALOG to achieve this. continued struc_tab_and_field-fieldname = con_cust. KUNNR struc_tab_and_field-tablename = con_kna1. KNA1.

CALL FUNCTION COMPLEX_SELECTIONS_DIALOG EXPORTING* TITLE = text = g_titl1 Customers tab_and_field = struc_tab_and_field TABLES RANGE = rng_kunnr EXCEPTIONS NO_RANGE_TAB = 1 CANCELLED = 2 INTERNAL_ERROR = 3 INVALID_FIELDNAME = 4 OTHERS = 5. IF NOT rng_kunnr[] IS INITIAL. * Read the very first entry of the range table and pass it to * dynpro screen field *READ TABLE rng_kunnr INDEX 1. IF sy-subrc = 0. g_cust = rng_kunnr-low. ENDIF. ENDIF. You can use the return table rng_kunnr to populate your own internal range table with the values entered by the user. Basically here you are just simulating the work of a select-options parameter by module pool screen elements. 30.how we can retrive data using secondary index.explain with simple example Ans: First create secondary indexes on required fields of a particular database table. We can create one primary index and 15 secondary indexes.Once the respective secondary indexes are created write select queries and within select queries specify secondary indexes field name with where clause. 31.How can we handle table control in BDC? Ans.We can handle table control using line index Line index indicates which line of Table control is to be use for BDC transaction Ex perform bdc_field using RC29K-AUSKZ(01) Indicates 1st line of table control is going to be used for transaction which is Line index of Table Control 32. If i want to execute a BDC program only in background not in foreground is there any option for this? Ans.The sm37 transaction can be used for running a program in the background. Also in the session method while processing the session you can specify the processing type as background or foreground. 33.How Can We upload a text file having Delimiters in to Legacy System Ans.For up loading text file we use the pre-defined FM gui_upload. in that FM we have the parameter has_field_seperator for that we assign the default delimiter x. HAS_FIELD_SEPERATOR X

X can provide the Whatever delimiter we used in flat file for separation. 34. What is the land scape in sap. Ans. In every organisation sap landscape involves three servers viz, Development server, Quality server and Production server. Whatever new development we do as per clients requirement is done in development server. Later to test the developed object we move it to quality server for testing and finally once everything goes clear then the object is moved to production server ,production server data is ready for final business use. 35. Workbench request are client dependent or client independent Ans. Workbench request are client independent. (Common Man Workbench request holds the Program , FM etc. How it can be Client Dependent!!!!) 36. Tell me about workbench request and customization requests. Ans.Workbench (ABAP Dev) request is client independent when you import it into one system it reflact it in all client in same system, but customized request has to import in that client perticular client where it is created, actually it is client dependent. Other Interview questions SAP SCRIPTS & FORMS 1. Can we write the code/program inside sap script? 2. How will u create sapscripts & smartforms in multiple language? 3.How to execute sap script & smart forms in Background? 4.How to do total & subtotal in scripts & forms? ================================================= DATA DICTIONARY 1.Apart from .include & .append how will u do table enhancement? 2.what r the events of table maintainence generator? 3.what will happen if i use projection view and maintainence view together? 4. I created ZEMP table now i want to add more data but prev. data should not disturb how can i do this? ===================================================== REPORTS 1.How will u print footers in alv report? 2.How will u edit fields from output list of alv? ==================================================== BDC 1.what r the fields u took during recording for mmo1,me21n? 2.If u want to do bdc for xd01 explain me how will be the flow? =================================================

user exits 1.what r enhancement points? 2.How to write customer exits? 3.what is routine? how it is different from user exits? ===================================================================== =====

Most frequently asked interview DIFFERENCES 1.sapscript and smartforms


Sap script is client dependent and smart form is client independent. Smartforms has Only 1 main window while Sap script has 99 main windows You can not print labels using smart forms In BDC we have to take care of field mapping whereas field mapping is taken care by sap in lsmw. BDC is mostly used for customised data upload while LSMW is used for uploading Master data. In BDC we need to write large code but in LSMW small coding is needed. BADI is business add ins, it is used to customize the standard business flow BAPI is Business application programming interface. It is nothing but Remote enabled function module which can be called from outside the SAP System. User exit is an include program given by SAP in that you can write your code , It needs Access key from SAP while key is not required in case of customer exit Select single will fetch only one record while select up to n row. Will fetch n rows from database To display the output in classical report you use WRITE Statement. To display the output in ALV we have different function modules and class like REUSE_ALV_GRID_DISPLAY , REUSE_ALV_LIST_DISPLAY and CL_SALV_TABLE. If you run the classical report in background after JOB finished you can see its output which stored in spool, While in case of ALV you need code extra to store the output as it will not generate the spool.

2.BDC and LSMW

3. BADI and BAPI

4.user exit and customer exit

5. Select single and select up to one row

6. Normal (Classical) report and ALV report

7. ALV list display and ALV grid display

You cannot retrieve the output for the report which is displayed using ALV GRID Display.As spool Request will not be created for the same. While in case of list display Report out put will be there in spool request. In classical report user cannot interact with report whereas in drill down report user can interact with report. Drill down facility is not provided in classical report while in drill down it is provided. If they ask you in detail then tell the interviewer that interact with the report means in drill down report we have one basic list and 20 secondary lists so we can directly go to 5th list or 10th list as per our requirement similarly we can come back to any list. Drill down means showing data in basic list first and when we double click on any field we get summarised list. NOTE:- to go to next list in drill down report use following syntax SY-LSIND = < list number> example: to go to 15th list SY-LSIND = 15 to come to 5th list from 15th list use F3 KEY OR PRESS BACK BUTTON BAPI is nothing but remote enabled function module BAPI is provided as a method of business objects SAP 4.7 is based on Web AS ECC 6.0 is based of Netweaver 7.0. Get cursor will provide the location cursor position in the report While hide is use to pass the data from basic list to secondary list You cannot call normal function module from outside the current system while RFC function module can be called from outside the SAP system. Subroutine is local to the program while function module is global. To call subroutine from outside its main program you need to write its main program name in the bracket At selection screen output is called first All dynamic commands and screen modification is done in AT selection screen output. The basic difference is validation is not done in direct input by pre defined function while in batch input it is coved. Synchronous mode will wait until the BDC session gets over while asynchronous mode will not wait for that

8. Classical and drill down report

9. BAPI and RFC function module

10.sap 4.7 and ECC 6.0

11. get cursor and hide in interactive report

12.normal function module and RFC

13. Subroutine and function modules.

14.At selection screen and At selection screen output.

15.direct input and batch input

16.synchronous and asynchronous in BDC

17.at selection screen and at selection on field name

At selection screen is used to validate the whole screen elements while at selection field is used to validate the particular field. When you display the error message in at selection on field the focus will be on that particular field while in case of At selection screen the focus will not be on any particular field. Process Before Output and Process after input. PBO will be called before the screen is displayed to the user while process after input is called once user interact with screen. If you use the STOP statement within an event block, the system stops processing the block Immediately. If you use the EXIT statement within an event block but not in a loop, the system stops Processing the block immediately If you use the CHECK <expr> statement within an event block but not within a loop, and the Condition <expr> is not fulfilled, the system exits the processing block immediately. <expr> can be any logical expression or the name of a selection table. If you specify a selection table and the contents of the corresponding table work are do.

18. PBO and PAI event in module pool


19. Stop , check and exit


20.free and refresh in internal table

You can use FREE to initialize an internal table (along with header line ) and release its memory space. REFRESH will only initialize an internal table (along with header line) The major difference is clear is used with internal table while delete is used with database table. COLLECT <line> INTO <itab>. The statement first checks whether the internal table contains an entry with the same key. If not,it acts like INSERT. If there is already a

21.clear and delete.

22. collect and sum

table entry with the same key, COLLECT does not inserta new line. Instead, it adds the values from the numeric fields of the work area <line> to thevalues in the corresponding fields of the existing table entry.

SUM.Can only be used in loops through internal tables. Calculates the sums of the numeric fields in alllines of the current control level and writes the results to the corresponding fields in the workarea. Call transaction is Synchronous Processing while session (classical) method is Asynchronous Processing In call transaction we can update the database both synchronously and asynchronously. We can specify the mode in the program. While in session method it is Synchronous Database update. In call transaction No batch input processing log is maintained while in session method details log is maintained. Call Transaction method is faster than the session method. As the name suggest AT FIRST executed for the first time while AT LAST executed in last. Both the enhancement-point and section are available for you to change standard SAP code. Difference is in fact that you use Enhancement-point to add ABAP code to standard SAP and enhancement-section to replace/extend standard SAP code. Top of page trigger when report encounter the first write, skip or new-line statements. End of page trigger when page size is over or report display gets over. Table has physical definition into the underline database while structure does exist physically in the data base. Table has data init while view does not contain data in it. Both exist in the data base. when u run the view it queries the database and gives the respective data. Inner join joins the table at database level whereas For..All..Entries joins the table at application level. In For..All..Entries when the condition gets satisfied data is fetched in one single shot from database table whereas in inner join data is fetched iteration by iteration It is always good programming practice to join tables at application level because if we join tables at database level then there might be performance issue

23. call transaction and session method

24. at first and at last control break event

25. Enhancement point and Enhancement Section

26.end of page and top of page

27. Table and structure

28. table and views

29.inner joins and for all entries


30. Transparent table pool table and cluster table

Transparent Table: Exists with the same structure both in the dictionary and database exactly with same data and fields. its to store transaction data. Its one to one Relation table Pool tables: These are logical tables must be assigned to a table pool when they are defined. Its use to store control data. its many to one relation table Clustered tables: these also logical tables and must be assigned to table cluster when they are defined. Its also used to store control data, temporary data or text ex., documentation. Its also many to one relation table. Top of page is triggered for the basic list while top of page at line selection triggers at secondary list. start_form function module is called if we want to use different forms with similar characteristics in a single spool request ,it must be closed by END_FORM function module Open dataset is use to read / write file into application server while close dataset is use to close that file. Domain gives technical details like length , decimal etc..while data elements gives description and business details Set screen <no> set the next screen value and temporarily override the next screen value in screen attribute. While call screen <no> jump to the screen specified in <no>. External session is nothing but the window you have opened in your screen .By Default you can open 6 external sessions( 6 windows = you can increase it via basiss setting). Internal session is created when you call any Functional module or any other task in your program. counts for internal sessions are 9. An Elementary Search help defines the flow of a standard input help. It is composed of a selection method that defines where to get the data that will make up the hit list, An interface consisting of search help parameters that define the exchange of data between the screen and the selection method and a dialog type that controls how the hit list will be displayed. A Collective Search help is a combination of several elementary search helps giving the user a different search paths. The interface parameters of the elementary search help are assigned to the parameters of the collective search.

31. Top of page and top of page during line selection

32. Start_form and End_form in sap script

33. open dataset and close dataset

34. data element and domains

35. set screen and call screen

36. Internal Session and External Session

37. Elementary and collective search help

38. What is the difference between Clustered Tables and Pooled Tables?

A pooled table is used to combine several logical tables in the ABAP/4 dictionary. Pooled tables are logical tables that must be assigned to a table pool when they are defined. Cluster table are logical tables that must be assigned to a table cluster when they are defined. Cluster table can be used to store control data they can also used to store temporary data or text such as documentation. User exit is sap defined includes so to modify it we need key from SAP.while customer exit like function exit , screen exit we dont need any key. Sapscript is client dependent whereas smartform is client independent. Main window is compulsory in scripts whereas main window not compulsory in form. Smartform output can be seen in web while in scripts it is not possible. smartform generates function module while scripts dont generate function module. Screen has its own gui status while subscreen does not have any gui status.Subscreens are part of main screen. Standard table can be accessed by key as well as index while You can only access hashed tables by specifying the key. The system has its own hash algorithm for managing the table.

39. user exits and customer exit.

40. sapscript smart forms and adobe forms

41. screen and subscreens in module pool.

42. standard table and hashed tables.

==========================================================

SELECT - lines
Syntax
... { SINGLE [FOR UPDATE] } | { [DISTINCT] { } } ... .

Alternatives:
1. ... SINGLE [FOR UPDATE] 2. ... [DISTINCT] { } Effect The data in lines specifies that the resulting set has either multiple lines or a single line.

Alternative 1
... SINGLE [FOR UPDATE]

Effect If SINGLE is specified, the resulting set has a single line. If the remaining additions to the SELECT command select more than one line from the database, the first line that is found is entered into the resulting set. The data objects specified after INTO may not be internal tables, and the APPENDING addition may not be used. The addition ORDER BY can also not be used. An exclusive lock can be set for this line using the FOR UPDATE addition when a single line is being read with SINGLE. The SELECT command is used in this case only if all primary key fields in logical expressions linked by AND are checked to make sure they are the same in the WHERE condition. Otherwise, the resulting set is empty and sy-subrc is set to 8. If the lock causes a deadlock, an exception occurs. If the FOR UPDATE addition is used, the SELECT command circumvents SAP buffering. Notes When SINGLE is being specified, the lines to be read should be clearly specified in the WHERE condition, for the sake of efficiency. When the data is read from a database table, the system does this by specifying comparison values for the primary key.

If accessing tables for which SAP buffering is planned for single records, the SAP buffer is bypassed if the addition SINGLE is not specified. This behavior depends on the current implementation of the database interface and may change in future releases. In particular, it should not be used to bypass the SAP buffer. You should use the explicit addition BYPASSING BUFFER for this instead. The addition SINLGE is not permitted in a subquery.

Alternative 2
... [DISTINCT] { }

Effect If SINGLE is not specified and if columns does not contain only aggregate expressions, the resulting set has multiple lines. All database lines that are selected by the remaining additions of the SELECT command are included in the resulting list. If the ORDER BY addition is not used, the order of the lines in the resulting list is not defined and, if the same SELECT command is executed multiple times, the order may be different each time. A data object specified after INTO can be an internal table and the APPENDING addition can be used. If no internal table is specified after INTO or APPENDING, the SELECT command triggers a loop that has to be closed using ENDSELECT. If multiple lines are read without SINGLE, the DISTINCT addition can be used to exclude duplicate lines from the resulting list. If DISTINCT is used, the SELECT command circumvents SAP buffering. DISTINCT cannot be used in the following situations:


Notes

If a column specified in columns has the type STRING, RAWSTRING, LCHAR or LRAW If the system tries to access pool or cluster tables and single columns are specified in columns.

When specifying DISTINCT, note that this requires the execution of sort operations in the database system, and the SELECT statement therefore bypasses the SAP buffer.

Syntax Diagram

SELECT - source
Syntax
... FROM { {dbtab [AS tabalias]} | join | {(dbtab_syntax) [AS tabalias]} } [UP TO n ROWS] [CLIENT SPECIFIED] [BYPASSING BUFFER] [CONNECTION {con|(con_syntax)}] ... .

Alternatives:
1.... dbtab [AS tabalias] 2.... join 2.... (dbtab_syntax) [AS tabalias]

Extras:
1.... UP TO n ROWS 2.... CLIENT SPECIFIED 3.... BYPASSING BUFFER 4.... CONNECTION {con|(con_syntax)} Effect Entries in source specify whether a database table or a view, or if many database tables or views are accessed by a join expression. Optional additions execute the client handling, specify whether the SAP buffering is avoided, and determine the maximum number of rows to be read.

Alternative 1
... dbtab [AS tabalias]

Effect A database table or a view defined in the ABAP Dictionary can be specified for dbtab. An alternative table name tabalias can be assigned to the database table or the view using the addition AS. This name can have a maximum of 14 characters and is valid during the SELECT statement only. It must be used in all other locations instead of the actual name. Note If a database table or a view appears multiple times after FROM in a join expression, you must use the alternative name to avoid ambiguities. Example

Reading from the database table spfli and assigning the alternative name s. In this case, the specification of the prefix s~ after ORDER BY can also be omitted, because only one database table is read and the column name carrid is unique. The prefix spfli~ can no longer be used when assigning the alternative name. DATA wa TYPE spfli. SELECT * FROM spfli AS s INTO wa ORDER BY s~carrid. WRITE: / wa-carrid, wa-connid. ENDSELECT.

Alternative 2
... join

Effect Specification of a Join expression that links several database tables or views with one another.

Alternative 3
... (dbtab_syntax) [AS tabalias]

Effect Instead of static specifications, a data object dbtab_syntax can be specified in brackets. When executing the statement, it must contain the syntax displayed during the static specification. The data object dbtab_syntax can be a character-type data object or an internal table with a character-type data object. The syntax in dbtab_syntax is not case-sensitive as in the ABAP Editor. The syntax can be spread over many rows when specifying an internal table. The addition AS can be specified only if dbtab_syntax exclusively contains the name of a single database table or a view. The addition has the same meaning for this database table or view as in a static specification. When specifying the syntax in dbtab_syntax, the following restrictions apply:


Notes

Only a list of fields and no selection table can be specified in a join condition after the language element IN. No database table containing columns of the type RAWSTRING, SSTRING, or STRING can be used in a join expression. If dbtab_syntax is an internal table with a header line, the header line and not the table body is evaluated. Prior to release 6.10, you can specify only a flat, character-type data object for dbtab_syntax and it can contain only the name of a single database table or a view in upper case letters.

Example Dynamic specification of the inner joins. The column specification after SELECT is also dynamic.

PARAMETERS: p_cityfr TYPE spfli-cityfrom, p_cityto TYPE spfli-cityto. DATA: BEGIN OF wa, fldate TYPE sflight-fldate, carrname TYPE scarr-carrname, connid TYPE spfli-connid, END OF wa. DATA itab LIKE SORTED TABLE OF wa WITH UNIQUE KEY fldate carrname connid. DATA: column_syntax TYPE string, dbtab_syntax TYPE string. column_syntax = `c~carrname p~connid f~fldate`. dbtab_syntax = `( ( scarr AS c ` & ` INNER JOIN spfli AS p ON p~carrid = c~carrid` & ` AND p~cityfrom = p_cityfr` & ` AND p~cityto = p_cityto )` & ` INNER JOIN sflight AS f ON f~carrid = p~carrid ` & ` AND f~connid = p~connid )`. SELECT (column_syntax) FROM (dbtab_syntax) INTO CORRESPONDING FIELDS OF TABLE itab. LOOP AT itab INTO wa. WRITE: / wa-fldate, wa-carrname, wa-connid. ENDLOOP.

Addition 1
... UP TO n ROWS Effect This addition restricts the number of rows in the result set. A data object of the Type i is expected for n. A positive number in n indicates the maximum number of rows in the result set. If n contains the value 0, all selected rows are passed to the result set. If n contains a negative number, an exception that cannot be handled is raised. Notes If the addition ORDER BY is also specified, the rows of the hit list are sorted on the database server and only the number of sorted rows specified in n are passed to the result set. If the addition ORDER BY is not specified, n is filled with any number of rows in the result set that meet the WHERE condition.

If the addition FOR ALL ENTRIES is also specified, the number of rows is not restricted on the database system, but on the application server, after all selected rows have been read.

Addition 2
... CLIENT SPECIFIED Effect

This addition switches off the automatic client handling of Open SQL. When specifying a single database table or a single view, the addition must be inserted directly after dbtab of the join condition. When specifying a join expression, it must be inserted after the last addition ON of the join condition. When using the addition CLIENT SPECIFIED, the first column of the client-dependent database tables can be specified in the WHERE condition to determine the client identifier. In the addition ORDER BY, the column can be sorted explicitly according to client identifier. Note If the addition CLIENT SPECIFIED is specified, but the client ID in the WHERE condition is not, the SELECT statement circumvents the SAP buffering.

Addition 3
... BYPASSING BUFFER Effect This addition causes the SELECT statement to avoid the SAP buffering and to read directly from the database and not from the buffer on the application server.

Addition 4
... CONNECTION {con|(con_syntax)} Note This addition is for internal use only. It cannot be used in application programs Effect The Open SQL command is not executed on the standard database but on the specified secondary database connection. The database connection can be specified statically with con or dynamically as the content of con_syntax, where the field con_syntax must belong to the type c or string. The database connection must be specified with a name that is in column CON_NAME in table DBCON. The addition CONNECTION must be specified immediately after the name of the database table or after the addition CLIENT SPECIFIED. Note If the Open SQL command is to be possible on a secondary database connection, the table definitions in the connection must be the same as those on the standard database.

Selecting Lines
The WHERE clause restricts the number of lines selected by specifying conditions that must be met.

As well as in the SELECT statement, the WHERE clause is also used in the OPEN CURSOR, UPDATE, and DELETE statements. The general form of the WHERE clause is: SELECT ... WHERE <cond> ... The <cond> conditions in the WHERE clause can be comparisons or a series of other special expressions. You can combine a series of conditions into a single condition. Conditions may also be programmed dynamically. The conditions <cond> in the WHERE clause are often like logical expressions, but not identical, since the syntax and semantics follow that of Standard SQL. In the conditions in the WHERE clause, you name columns using a field name as in the SELECT clause. In the following descriptions, <s> always represents a column of one of the database tables named in the FROM clause. The result of a condition may be true, false, or unknown. A line is only selected if the condition is true for it. A condition is unknown if one of the columns involved contains a null value.

Comparisons for All Types


To compare the value of a column of any data type with another value, use the following: SELECT ... WHERE <s> <operator> <f> ... <f> can be another column in a database table from the FROM clause, a data object, or a scalar subquery. You can use the following expressions for the relational operator: <operator> EQ = NE <> Meaning equal to equal to not equal to not equal to

>< LT < LE <= GT > GE >=

not equal to less than less than less than or equal to less than or equal to greater than greater than greater than or equal to greater than or equal to

The values of the operands are converted if necessary. The conversion may be dependent on the platform and codepage.

Values in Intervals
To find out whether the value of a column lies within a particular interval, use: SELECT ... WHERE <s> [NOT ] BETWEEN <f 1> AND <f 2> ... The condition is true if the value of column <s> is [not] between the values of the data objects <f1> and <f 2>. You cannot use BETWEEN in the ON condition of the FROM clause.

Comparing Strings
To find out whether the value of a column matches a pattern, use: SELECT ... WHERE <s> [NOT ] LIKE <f> [ESCAPE <h>] ... The condition is true if the value of the column <s> matches [does not match] the pattern in the data object <f>. You can only use this test for text fields. The data type of the column must be alphanumeric. <f> must have data type C. You can use the following wildcard characters in <f>: % for a sequence of any characters (including spaces). _ for a single character.

For example, ABC_EFG% matches the strings ABCxEFGxyz and ABCxEFG, but not ABCEFGxyz. If you want to use the two wildcard characters explicitly in the comparison, use the ESCAPE option. ESCAPE <h> specifies an escape symbol <h>. If preceded by <h>, the wildcards and the escape symbol itself lose their usual function within the pattern <f>. The use of _ and % corresponds to Standard SQL usage. Logical expressions elsewhere in ABAP use other wildcard characters (+ and *). You cannot use LIKE in the ON condition of the FROM clause.

Checking Lists of Values


To find out whether the value of a column is contained in a list of values, use: SELECT ... WHERE <s> [NOT ] IN (<f 1>, ......, <f n>) ... The condition is true if the value of column <s> is [not] in the list <f1> ... <f n>.

Checking Subqueries
To find out whether the value of a column is contained in a scalar subquery, use:

SELECT ... WHERE <s> [NOT ] IN <subquery> ... The condition is true if the value of <s> is [not] contained in the results set of the scalar subquery <subquery>. To find out whether the selection of a subquery contains lines at all, use: SELECT ... WHERE [ NOT ] EXISTS <subquery> ... This condition is true if the result set of the subquery <subquery> contains at least one [no] line. The subquery does not have to be scalar. You cannot check a subquery in the ON condition of the FROM clause.

Checking Selection Tables


To find out whether the value of a column satisfies the conditions in a selection table, use: SELECT ... WHERE <s> [NOT ] IN <seltab> ... The condition is true if the value of <s> [does not] satisfy the conditions stored in <seltab>. <seltab> can be either a real selection table or a RANGES table. You cannot check a selection table in the ON condition of the FROM clause.

Checking for Null Values


To find out whether the value of a column is null, use: SELECT ... WHERE <s> IS [NOT ] NULL ... The condition is true if the value of <s> is [not] null.

Negating Conditions
To negate the result of a condition, use: SELECT ... WHERE NOT <cond> ... The condition is true if <cond> is false, and false if <cond> is true. The result of an unknown condition remains unknown when negated.

Linking Conditions
You can combine two conditions into one using the AND and OR operators: SELECT ... WHERE <cond 1> AND <cond 2> ... This condition is true if < cond1 > and < cond2 > are true. SELECT ... WHERE <cond 1> OR <cond 2> ... This condition is true if one or both of < cond1 > and < cond2 > are true. NOT takes priority over AND, and AND takes priority over OR. However, you can also control the processing sequence using parentheses.

Dynamic Conditions
To specify a condition dynamically, use: SELECT ... WHERE (<itab>) ... where <itab> is an internal table with line type C and maximum length 72 characters. All of the conditions listed above except for selection tables, can be written into the lines of <itab>. However, you may only use literals, and not the names of data objects. The internal table can also be left empty. If you only want to specify a part of the condition dynamically, use: SELECT ... WHERE <cond> AND (<itab>) ... You cannot link a static and a dynamic condition using OR. You may only use dynamic conditions in the WHERE clause of the SELECT statement.

Tabular Conditions
The WHERE clause of the SELECT statement has a special variant that allows you to derive conditions from the lines and columns of an internal table: SELECT ... FOR ALL ENTRIES IN <itab> WHERE <cond> ... <cond> may be formulated as described above. If you specify a field of the internal table <itab> as an operand in a condition, you address all lines of the internal table. The comparison is then performed for each line of the internal table. For each line, the system selects the lines from the database table that satisfy the condition. The result set of the SELECT statement is the union of the individual selections for each line of the internal table. Duplicate lines are automatically eliminated from the result set. If <itab> is empty, the addition FOR ALL ENTRIES is disregarded, and all entries are read. The internal table <itab> must have a structured line type, and each field that occurs in the condition <cond> must be compatible with the column of the database with which it is compared. Do not use the operators LIKE, BETWEEN, and IN in comparisons using internal table fields. You may not use the ORDER BY clause in the same SELECT statement. You can use the option FOR ALL ENTRIES to replace nested select loops by operations on internal tables. This can significantly improve the performance for large sets of selected data.

Examples

Conditions in the WHERE clause: ... WHERE CARRID = 'UA'. This condition is true if the column CARRID has the contents UA. ... WHERE NUM GE 15. This condition is true if the column NUM contains numbers greater than or equal to 15. ... WHERE CITYFROM NE 'FRANKFURT'. This condition is true if the column CITYFROM does not contain the string FRANKFURT. ... WHERE NUM BETWEEN 15 AND 45. This condition is true if the column NUM contains numbers between 15 and 45. ... WHERE NUM NOT BETWEEN 1 AND 99. This condition is true if the column NUM contains numbers not between 1 and 99. ... WHERE NAME NOT BETWEEN 'A' AND 'H'. This condition is true if the column NAME is one character long and its contents are not between A and H. ... WHERE CITY LIKE '%town%'. This condition is true if the column CITY contains a string containing the pattern town. ... WHERE NAME NOT LIKE '_n%'. This condition is true if the column NAME contains a value whose second character is not n. ... WHERE FUNCNAME LIKE 'EDIT#_%' ESCAPE '#'. This condition is true if the contents of the column FUNCNAME begin with EDIT_. ... WHERE CITY IN ('BERLIN', 'NEW YORK', 'LONDON'). This condition is true if the column CITY contains one of the values BERLIN, NEW YORK, or LONDON.

... WHERE CITY NOT IN ('FRANKFURT', 'ROME'). This condition is true if the column CITY does not contain the values FRANKFURT or ROME. ... WHERE ( NUMBER = '0001' OR NUMBER = '0002' ) AND NOT ( COUNTRY = 'F' OR COUNTRY = 'USA' ). This condition is true if the column NUMBER contains the value 0001 or 0002 and the column COUNTRY contains neither F nor USA.

Dynamic conditions DATA: COND(72) TYPE C, ITAB LIKE TABLE OF COND. PARAMETERS: CITY1(10) TYPE C, CITY2(10) TYPE C. DATA WA TYPE SPFLI-CITYFROM. CONCATENATE APPEND COND CONCATENATE APPEND COND CONCATENATE APPEND COND 'CITYFROM = ''' CITY1 '''' INTO COND. TO ITAB. 'OR CITYFROM = ''' CITY2 '''' INTO COND. TO ITAB. 'OR CITYFROM = ''' 'BERLIN' '''' INTO COND. TO ITAB.

LOOP AT ITAB INTO COND. WRITE COND. ENDLOOP. SKIP. SELECT INTO FROM WHERE CITYFROM WA SPFLI (ITAB).

WRITE / WA. ENDSELECT. If the user enters FRANKFURT and BERLIN for the parameters CITY1 and CITY2 on the selection screen, the list display is as follows:

The first three lines show the contents of the internal table ITAB. Exactly the corresponding table lines are selected.

Tabular conditions DATA: BEGIN OF LINE, CARRID TYPE CONNID TYPE CITYFROM TYPE CITYTO TYPE END OF LINE, ITAB LIKE TABLE SPFLI-CARRID, SPFLI-CONNID, SPFLI-CITYFROM, SPFLI-CITYTO, OF LINE.

LINE-CITYFROM = 'FRANKFURT'. LINE-CITYTO = 'BERLIN'. APPEND LINE TO ITAB. LINE-CITYFROM = 'NEW YORK'. LINE-CITYTO = 'SAN FRANCISCO'. APPEND LINE TO ITAB. SELECT CARRID CONNID CITYFROM CITYTO INTO CORRESPONDING FIELDS OF LINE FROM SPFLI FOR ALL ENTRIES IN ITAB WHERE CITYFROM = ITAB-CITYFROM AND CITYTO = ITAB-CITYTO. WRITE: / LINE-CARRID, LINE-CONNID, LINE-CITYFROM, LINE-CITYTO. ENDSELECT. The output is as follows:

This example selects all lines in which the following conditions are fulfilled: The CITYFROM column contains FRANKFURT and the CITYTO column contains BERLIN. The CITYFROM column contains NEW YORK and the CITYTO column contains SAN FRANCISCO.

Tabular conditions DATA: TAB_SPFLI TYPE TABLE OF SPFLI, TAB_SFLIGHT TYPE SORTED TABLE OF SFLIGHT WITH UNIQUE KEY TABLE LINE, WA LIKE LINE OF TAB_SFLIGHT. SELECT INTO FROM WHERE CARRID CONNID CORRESPONDING FIELDS OF TABLE TAB_SPFLI SPFLI CITYFROM = 'NEW YORK'.

SELECT CARRID CONNID FLDATE INTO CORRESPONDING FIELDS OF TABLE TAB_SFLIGHT FROM SFLIGHT FOR ALL ENTRIES IN TAB_SPFLI

WHERE

CARRID = TAB_SPFLI-CARRID AND CONNID = TAB_SPFLI-CONNID.

LOOP AT TAB_SFLIGHT INTO WA. AT NEW CONNID. WRITE: / WA-CARRID, WA-CONNID. ENDAT. WRITE: / WA-FLDATE. ENDLOOP. The output is as follows:

This example selects flight data from SFLIGHT for all connections for which the column CITYFROM in table SPFLI has the value NEW YORK. You could also use a join in the FROM clause to select the same data in a single SELECT statement.

Dynamic where condition in Select statement


Posted: Feb 18, 2011 7:57 AM

Reply

Hi, I have 10 fields on selection-screeen. In which ever field the user enters single values or ranges,i should pick that field dynamically and pass that field along with value range to Where condition of Select statement.How can i achieve this? Please help. Regards K Srinivas

Krupaji

Re: Dynamic where condition in Select statement


Posted: Feb 18, 2011 8:07 AM in response to:

Reply

Posts: 372 Registered: 12/30/09

srinivasukoppada
call function 'RH_DYNAMIC_WHERE_BUILD' exporting dbtable tables condtab where_clause exceptions empty_condtab no_db_field unknown_db = 01 = 02 = 03 = gt_condtab = gt_where_clauses = space " can be empty

Forum Points: 292


Top of Form

Bottom of Form

wrong_condition = 04. .

select matnr from mara into table itab where (gt_where_clauses).

srinivasukoppada
Posts: 6 Registered: 2/18/11

Re: Dynamic where condition in Select statement


Posted: Feb 18, 2011 9:02 AM in response to:

Reply

Forum Points: 0
Top of Form

Krupaji
Thanks for the reply.How the entries should be populated to gt_condtab and gt_where_clauses.When im executing the FM,entering db name im not getting values in gt_condtab and gt_where_clauses. Pls help. Regards K Srinivas

Bottom of Form

Krupaji

Re: Dynamic where condition in Select statement


Posted: Feb 18, 2011 9:07 AM in response to:

Reply

Posts: 372 Registered: 12/30/09

srinivasukoppada
see the following example: data : begin of itab occurs 0, matnr like mara-matnr, end of itab.

Forum Points: 292


Top of Form

Bottom of Form

ypes: begin of ty_s_clause. types: line(72) type c.

types: end of ty_s_clause.

data : begin of gt_condtab occurs 0. include structure hrcond. data : end of gt_condtab.

FIELD-SYMBOLS <fs_wherecond> TYPE ty_s_clause. data: gt_where_clauses ty_s_clause type standard table of with default key.

gt_condtab-field = 'MATNR'. gt_condtab-opera = 'EQ'. gt_condtab-low = '000000000000000111'. append gt_condtab.

clear

gt_condtab.

call function 'RH_DYNAMIC_WHERE_BUILD' exporting dbtable tables condtab where_clause exceptions empty_condtab no_db_field unknown_db = 01 = 02 = 03 = gt_condtab = gt_where_clauses = space " can be empty

wrong_condition = 04. .

select matnr from mara into table itab where (gt_where_clauses).

Avinash Kodarapu
Posts: 4,031 Registered: 11/23/05

Re: Dynamic where condition in Select statement


Posted: Feb 18, 2011 9:13 AM in response to:

Reply

srinivasukoppada
Hi, Simply check the fields whether they are populated or not and build the where clause.

Forum Points: 7,598


Top of Form

Bottom of Form

Dynamic Where Clause

Deepak Kumar Gu...


Posts: 34 Registered: 2/22/07

Re: Dynamic where condition in Select statement


Posted: Feb 18, 2011 9:24 AM in response to:

Reply

Krupaji Forum Points: 56


Top of Form

We can use a simple STRING concatenated also. Example: DATA : l_where TYPE string, i_marc TYPE STANDARD TABLE OF marc.

Bottom of Form

CONSTANTS: l_quote TYPE char1 VALUE ''''.

PARAMETERS : p_plant TYPE marc-werks.

CONCATENATE 'WERKS' space '=' space l_quote p_plant l_quote space 'AND' space 'PERKZ' space '=' space l_quote 'M' l_quote INTO l_where RESPECTING BLANKS.

SELECT * FROM marc INTO TABLE i_marc WHERE (l_where).

Suhas Saha

Re: Dynamic where condition in Select statement


Posted: Feb 18, 2011 9:25 AM in response to:

Reply

srinivasukoppada
Posts: 5,426 Registered: 7/31/07

Hello, Are the screen elements PARAMETERS or SELECT-OPTIONS? If they are all SELECT-OPTIONS you can use all the elements in the WHERE clause of the SELECT statement e.g., SELECT field1 field2 field3

Forum Points: 9,214


Top of Form

Bottom of Form

FROM dbtable INTO TABLE itab WHERE field1 = s_elem1 AND field2 = s_elem2 AND field3 = s_elem3 .... so on & so forth

BR, Suhas

Thomas Zloch

Re: Dynamic where condition in Select statement


Posted: Feb 18, 2011 4:02 PM in response to:

Reply

Suhas Saha
Posts: 6,417 Registered: 8/28/04

Forum Points: 10,048


Top of Form

I also have a strange feeling that the IN operator has been re-invented in this thread...just slightly more complicated. Thomas

Bottom of Form

Вам также может понравиться