PP General Procedure and Tcodes

SAP/ABAP 개발 2010. 6. 28. 19:29 Posted by KindKay

Process    :Tcode [XXCreate/Change/Display]

________________________________________________________________

Material Master                  : MM01/02/03
BOM                                        : CS01/02/03
                                                                                                                                   

Material Master

WorkCenter                          : CR01/02/03
Routing                                  : CA01/02/03

--------------------------------------------------------------------------------------
Sales Order                           : MC87/88/89


PIR (Demand Mgt)             : MD61/62/63                    
MRP Run                       : MD01/02/03                                                           

Sales Planning
MRP Evaluation              : Stock Req. List : MD04
MRP List                          : MD05
Order Conversion            : From Stock Req. List : MD04 or 
                                                                  : CO40

------------------------------------------------------------------------------------

Create Prod. Order            : CO01/02/03

Confirmation                      : For Order             : CO15
                                              : For Operation     : CO11N
                                              : Error Processing: COGI

Good's Issue                       : MB1A                      Production Execution

Good's Receipt                  : MB31

TECO                                    : CO02         

The SQL Trace (ST05) – Quick and Easy

SAP/ABAP 개발 2010. 6. 28. 17:12 Posted by KindKay

The SQL Trace, which is part of the Performance Trace (transaction ST05), is the most important tool to test the performance of the database. Unfortunately, information on how to use the SQL Trace and especially how to interpret its results is not part of the standard ABAP courses. This weblog tries to give you a quick introduction to the SQL Trace. It shows you how to execute a trace, which is very straightforward. And it tells how you can get a very condensed overview of the results--the SQL statements summary--a feature that many are not so familiar with. The usefulness of this list becomes obvious when the results are interpreted. A short discussion of the ‘database explain’ concludes this introduction to the SQL Trace. 


1. Using the SQL Trace

Using the SQL trace is very straightforward:

  1. Call the SQL trace in a second mode
  2. Make sure that your test program was executed at least once, or even better, a few times, to fill the buffers and caches. Only a repeated execution provides reproducible trace results. Initial costs are neglected in our examination
  3. Start the trace
  4. Execute your test program in the first mode
  5. Switch off the trace. Note, that only one SQL trace can be active on an application server, so always switch your trace off immediately after your are finished.
  6. Display the trace results
  7. Interpretation of the results

image

Note, the trace can also be switched on for a different user.

=> In this section we showed how the SQL trace is executed. The execution is very straightforward and can be performed without any prior knowledge. The interpretation of the results, however, requires some experience. More on the interpretation will come in the next section.


2. Trace Results – The Extended Trace List

image

 

When the trace result is displayed the extended trace list comes up. This list shows all executed statements in the order of execution (as extended list it includes also the time stamp). One execution of a statement can result in several lines, one REOPEN and one or several FETCHES. Note that you also have PREPARE and OPEN lines, but you should not see them, because you only need to analyze traces of repeated executions. So, if you see a PREPARE line, then it is better to repeat the measurement, because an initial execution has also other effects, which make an analysis difficult.

If you want to take the quick and easy approach, the extended trace list is much too detailed. To get a good overview you want to see all executions of the same statement aggregated into one line. Such a list is available, and can be called by the menu ‘Trace List -> Summary by SQL Statements’.

=> The extended trace list is the default result of the SQL Trace. It shows a lot of and very detailed information. For an overview it is much more convenient to view an aggregated list of the trace results. This is the Summarized SQL Statements explained in the next section.


3. Trace Results - Summarized SQL Statements

This list contains all the information we need for most performance tuning tasks.

image

The keys of the list are ‘Obj Name’ (col. 12), i.e. table name, and ‘SQL Statement’ (col. 13). When using the summarized list, keep the following points in mind:

  • Several coding positions can relate to the same statement:
  • The statement shown can differ from its Open SQL formulation in ABAP.
  • The displayed length of the field ‘Statement’ is restricted, but sometimes the displayed text is identical.
  • In this case, the statements differ in part that is not displayed.

The important measured values are ‘Executions’ (col. 1), ‘Duration’ (col. 3) and ‘Records’ (col. 4). They tell you how often a statement was executed, how much time it needed in total and how many records were selected or changed. For these three columns also the totals are interesting; they are displayed in the last line. The other totals are actually averages, which make them not that interesting.

Three columns are direct problem indicators. These are ‘Identical’ (col. 2), ‘BfTp’ (col. 10), i.e. buffer type, and ‘MinTime/R.’ (col. 8), the minimal time record.

Additional, but less important information is given in the columns, ‘Time/exec’ (col. 5), ‘Rec/exec’ (col. 6), ‘AvgTime/R.’ (col. 7), ‘Length’ (col. 9) and ‘TabType’ (col. 11).

 

For each line four functions are possible:

image

  • The magnifying glass shows the statement details; these are the actual values that were used in the execution. In the summary the values of the last execution are displayed as an example.
  • The ‘DDIC information’ provides some useful information about the table and has links to further table details and technical settings.
  • The ‘Explain’ shows how the statement was processed by the database, particularly which index was used. More information about ‘Explain’ can be found in the last section.
  • The link to the source code shows where the statement comes from and how it looks in OPEN SQL. 

=> The Statement summary, which was introduced here, will turn out to be a powerful tool for the performance analysis. It contains all information we need in a very condensed form.  The next section explains what checks should be done.

 

4. Checks on the SQL Statements

For each line the following 5 columns should be checked, as tuning potential can be deduced from the information they contain. Select statements and changing database statements, i.e. inserts, deletes and updates, can behave differently, therefore also the conclusions are different.

For select statements please check the following:

  • Entry in ‘BfTy’ = Why is the buffer not used?
    The tables which are buffered, i.e. with entries ‘ful’’ for fully buffered, ‘gen’ for buffered by generic region and ‘sgl’ for single record buffer, should not appear in the SQL Trace, because they should use the table buffer. Therefore, you must check why the buffer was not used. Reasons are that the statement bypasses the buffer or that the table was in the buffer during the execution of the program. For the tables that are not buffered, but could be buffered, i.e. with entries starting with ‘de’ for deactivated (‘deful’, ‘degen’, ‘desgl’ or ;deact’) or the entry ‘cust’ for customizing table, check whether the buffering could not be switched on. 
  • Entry in ‘Identical’ = Superfluous identical executions
    The column shows the identical overhead as a percentage. Identical means that not only the statement, but also the values are identical. Overhead expresses that from 2 identical executions one is necessary, and the other is superfluous and could be saved.
  • Entry in ‘MinTime/R’ larger than 10.000 = Slow processing of statement
    An index-supported read from the database should need around 1.000 micro-seconds or even less per record. A value of 10.000 micro-seconds or even more is a good indication that there is problem with the execution of that statement. Such statements should be analyzed in detail using the database explain, which is explained in the last section.
  • Entry in ‘Records’ equal zero = No record found
    Although this problem is usually completely ignored, ‘no record found’ should be examined. First, check whether the table should actually contain the record and whether the customizing and set-up of the system is not correct. Sometimes ‘No record found’ is expected and used to determine program logic or to check whether keys are still available, etc. In these cases only a few calls should be necessary, and identical executions should absolutely not appear.
  • High entries in ‘Executions’ or ‘Records’ = Really necessary?
    High numbers should be checked. Especially in the case of records, a high number here can mean that too many records are read.

For changing statements, errors are fortunately much rarer. However, if they occur then they are often more serious:

  • Entry in ‘BfTy’ = Why is a buffered table changed?
    If a changing statement is executed on a buffered statement, then it is questionable whether this table is really suitable for buffering. In the case of buffered tables, i.e entries ‘ful’, ‘gen’ or ’sgl’’, it might be better to switch off the buffering. In the case of bufferable tables, the deactivation seems to be correct.
  • Entry in ‘Identical’ = Identical changes must be avoided
    Identical executions of changing statements should definitely be avoided.
  • Entry in ‘MinTime/R’ larger than 20.000 = Changes can take longer
    Same argument as above just the limit is higher for changing statements.
  • Entry in ‘Records’ equal zero = A change with no effect
    Changes should also have an effect on the database, so this is usually a real error which should be checked. However, the ABAP modify statement is realized on the database as an update followed by an insert if the record was not found. In this case one statement out of the group should have an effect.
  • High entries in ‘Executions’ and ‘Records’ = Really necessary?
    Same problems as discussed above, but in this case even more serious.

=> In this section we explained detailed checks on the statements of the SQL Statement Summary. The checks are slightly different for selecting and changing statements. They address questions such as why a statement does not use the table buffer, why statements are executed identically, whether the processing is slow, why a statement was executed but no record was selected or changed, and whether a statement is executed too often or selects too many records.


5. Understanding the Database Explain

The ‘database explain’ should show the SQL statement as it goes to the database, and the execution plan on the database. This view has a different layout for the different database platforms supported by SAP, and it can become quite complicated if the statement is complicated.

image

In this section we show as an example the ‘Explain’ for a rather simple index-supported table access, which is one of the most common table accesses:

  1. The database starts with step 1, index unique scan DD02L~0, where the three fields of the where-condition are used to find a record on the index DD02L~0 (‘~0’ denotes always the primary key).
  2. In step 2, table access by index rowed DD02L, the rowid is taken from the index to access the record in the table directly.

Some databases display the execution plan in a graphical layout, where a double-click on the table gives additional information, as shown on the right side. There the date of the last statistics update and the number of records in the table are displayed. Also all indexes are listed with their fields and the number of distinct values for each field, with this information it is possible to calculate the selectivity of an index.

From this example you should understand the principle of the ‘Explain’, so that you can also understand more complicated execution plans. Some database platforms do not use graphical layouts and are a bit harder to read, but still show all the relevant information. 

=> In this last section we showed an example of a database explain, which is the only way to find out whether a statement uses an index, and if so, which index. Especially in the case of a join, it is the proper index support that determines whether a statement needs fractions of seconds or even minutes to be finished.

  

Please try the SQL Trace by yourself. If there are any questions or problems, your feedback is always welcome!

 

More information on performance topics can be found in my new textbook on performance (published Nov 2009). However please note, that it is right now only available in German.

image


Chapter Overview:

  1. Introduction
  2. Performance Tools
  3. Database Know-How
  4. Optimal Database Programming
  5. Buffers
  6. ABAP - Internal Tables
  7. Analysis and Optimization
  8. Programs and Processes
  9. Further Topics
  10. Appendix

In the book you will find detailed descriptions of all relevant performance tools. An introduction to database processing, indexes, optimizers etc. is also given. Many database statements are discussed and different alternatives are compared. The resulting recommendations are supported by ABAP test programs which you can download from the publishers webpage (see below). The importance of the buffers in the SAP system are discussed in chaptr five. Of all ABAP statements mainly the usage of internal tables is important for a good performance. With all the presented knowledge you will able to analyse your programs and optimize them. The performance implications of further topics, such as modularisation, workprocesses, remote function calls (RFCs), locks & enqueues, update tasks and prallelization are explained in the eight chapter.

Even more information - including the test programs - can be found on the webpage of the publisher.

I would recommend you especially the examples for the different database statements. The file with the test program (K4a) and necessary overview with the input numbers (K4b) can even be used, if you do not speak German!

Siegfried Boes is a member of the SAP Performance, Data Management & Scalability team




 *&----------------------------------------------------------------*
*& Report  YRTEST0005
*&
*&----------------------------------------------------------------*
*&
*&  Run Program with Background job
*&----------------------------------------------------------------*

report  yrtest0005.

* Run Program with Background job
  data: l_number type tbtcjob-jobcount,
        l_name   type tbtcjob-jobname.

  concatenate 'Z00' '_'  sy-datum '_'  sy-uzeit
         into l_name.

  call function 'JOB_OPEN'
    exporting
      jobname          = l_name
    importing
      jobcount         = l_number
    exceptions
      cant_create_job  = 1
      invalid_job_data = 2
      jobname_missing  = 3
      others           4.

  check sy-subrc = 0.
*  submit zlmmm65010 with  pa_bukrs =  pi_bukrs
*                    with  pa_gbm   =  l_gbm
*                    with  pa_week  =  pi_planid
*                    with  pa_ck01  =  c_x
*                    user  sy-uname
*                    via job l_name number l_number
*                    and return.

  submit yrtest0006 user  sy-uname
                    via job l_name number l_number
                    and return.

  check sy-subrc eq 0.
  message s303(me) with 'Success'.

  call function 'JOB_CLOSE'
    exporting
      jobcount             = l_number
      jobname              = l_name
      strtimmed            = 'X'
    exceptions
      cant_start_immediate = 1
      invalid_startdate    = 2
      jobname_missing      = 3
      job_close_failed     = 4
      job_nosteps          = 5
      job_notex            = 6
      lock_failed          = 7
      others               8.
 




*&----------------------------------------------------------------*
*& Report  YRTEST0006
*&
*&----------------------------------------------------------------*
*&
*&
*&----------------------------------------------------------------*

report  yrtest0006.

*  include yrtest0006top.
*  include yrtest0006f01.


end-of-selection.
  write: sy-uname, sy-datum, sy-uzeit.

FM to get Production Order user status (CO03) and system status

  *&----------------------------------------------------------------*
*& Report  YRTEST0003
*&
*&----------------------------------------------------------------*
*&
*&
*&----------------------------------------------------------------*

REPORT  YRTEST0003.

  data: lt_STATUS like TABLE OF JSTAT with header line,
        l_OBJNR   LIKE JSTO-OBJNR,
        l_aufnr   like afko-aufnr.


  clear: l_OBJNR, l_aufnr.

  l_aufnr = '60003649'.

  call function 'CONVERSION_EXIT_ALPHA_INPUT'
    exporting
      input         = l_aufnr
    IMPORTING
      OUTPUT        = l_aufnr.

  concatenate 'OR' l_AUFNR into l_OBJNR.

  call function 'STATUS_READ'
    exporting
      CLIENT                 = SY-MANDT
      objnr                  = l_OBJNR
      ONLY_ACTIVE            = 'X'
*   IMPORTING
*     OBTYP                  =
*     STSMA                  =
*     STONR                  =
   TABLES
     STATUS                 = lt_STATUS
   EXCEPTIONS
     OBJECT_NOT_FOUND       = 1
     OTHERS                 2.

  data: l_txt04 like tj02t-txt04,
        l_TXT30 like tj02t-TXT30.

  clear: l_txt04, l_TXT30.

  if sy-subrc eq 0.
    loop at lt_status.
      write: / lt_status-STAT.
      clear: l_txt04, l_TXT30.
      select single txt04 TXT30
        into (l_txt04, l_TXT30)
        from tj02t
       where ISTAT eq lt_status-STAT
         and SPRAS eq SY-LANGU.
      write: l_txt04, l_TXT30.
    endloop.
  else.
    message s303(me) with sy-subrc.
  endif.

*  if not IT_JEST[] is initial.
*    select ISTAT TXT04
*    from TJ02T
*    into table IT_TJ02T
*    for all entries in IT_JEST
*    where ISTAT = IT_JEST-STAT
*      and SPRAS = SY-LANGU.
*  endif.





*&----------------------------------------------------------------*
*& Report  YRTEST0002
*&
*&----------------------------------------------------------------*
*&
*&
*&----------------------------------------------------------------*

report  yrtest0002.

  data: ls_return      like bapiret1,
        lt_return      like table of bapi_coru_return with header line,
        lt_timetickets like table of bapi_pp_timeticket with header line.

end-of-selection.
  clear: ls_return, lt_return[], lt_timetickets[].
  clear: lt_timetickets.

*  lt_timetickets-conf_no   = '0000104074'.
  lt_timetickets-orderid   = '60003649'.
  lt_timetickets-operation = '0010'.
  lt_timetickets-yield     = 1.

  data: l_aufnr type aufnr.

  call function 'CONVERSION_EXIT_ALPHA_INPUT'
    exporting
      input         = lt_timetickets-orderid
    IMPORTING
      OUTPUT        = l_aufnr.

  select single rueck
    into lt_timetickets-conf_no
    from afru
   where aufnr eq l_aufnr
     and vornr eq lt_timetickets-operation.

  append lt_timetickets.

  call function 'BAPI_PRODORDCONF_CREATE_TT'
    importing
      return                   = ls_return
    tables
      timetickets              = lt_timetickets
      detail_return            = lt_return.

  read table lt_return with key type 'E'.
  if sy-subrc eq 0.
    call function 'BAPI_TRANSACTION_ROLLBACK'.
    message s303(me) display like 'E'
                     with lt_return-message.
  else.
    read table lt_return index 1.
    call function 'BAPI_TRANSACTION_COMMIT'.
    message s303(me) with lt_return-message.
  endif.




How to Use ALV Form Elements for Events

SAP/ABAP 개발 2010. 6. 26. 11:50 Posted by KindKay

SAP ABAP Programming.pdf

SAP/ABAP 개발 2010. 6. 26. 11:15 Posted by KindKay

Hi gurus, Is there any bapi for confirming production orders like in Tx. CO11N ?

Thanks a lot! :-)


Hi,

check that one:

BAPI_PRODORDCONF_CREATE_TT

Regards Vassko!


Hi,

Check the Bapis

BAPI_PRODORDCONF_CREATE_TT

BAPI_PRODORDCONF_CREATE_HDR.

Regards
Kiran Sure


when calling BAPI_PRODORDCONF_GET_TT_PROP, set the parameter PROPOSE-GOODSMOVEMENT = 'X', this will fill the Goodsmovement internal table.





  report  yrtest0002.

  data: ls_return      like bapiret1,
        lt_return      like table of bapi_coru_return with header line,
        lt_timetickets like table of bapi_pp_timeticket with header line.

end-of-selection.
  clear: ls_return, lt_return[], lt_timetickets[].
  clear: lt_timetickets.

*  lt_timetickets-conf_no   = '0000104074'.
  lt_timetickets-orderid   = '60003649'.
  lt_timetickets-operation = '0010'.
  lt_timetickets-yield     = 1.

  data: l_aufnr type aufnr.

  call function 'CONVERSION_EXIT_ALPHA_INPUT'
    exporting
      input         = lt_timetickets-orderid
    IMPORTING
      OUTPUT        = l_aufnr.

  select single rueck
    into lt_timetickets-conf_no
    from afru
   where aufnr eq l_aufnr
     and vornr eq lt_timetickets-operation.

  append lt_timetickets.

  call function 'BAPI_PRODORDCONF_CREATE_TT'
    importing
      return                   = ls_return
    tables
      timetickets              = lt_timetickets
      detail_return            = lt_return.

  read table lt_return with key type 'E'.
  if sy-subrc eq 0.
    call function 'BAPI_TRANSACTION_ROLLBACK'.
    message s303(me) display like 'E'
                     with lt_return-message.
  else.
    read table lt_return index 1.
    call function 'BAPI_TRANSACTION_COMMIT'.
    message s303(me) with lt_return-message.
  endif.


Selecting Lines

SAP/ABAP 개발 2010. 6. 25. 10:35 Posted by KindKay

Selecting Lines  Locate the document in its SAP Library structure

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

This graphic is explained in the accompanying text

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>

Meaning

EQ

equal to

=

equal to

NE

not equal to

<>

not equal to

><

not equal to

LT

less than

<

less than

LE

less than or equal to

<=

less than or equal to

GT

greater than

>

greater than

GE

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

Example

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.

Example

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 'CITYFROM = ''' CITY1 '''' INTO COND.
APPEND COND TO ITAB.
CONCATENATE 'OR CITYFROM = ''' CITY2 '''' INTO COND.
APPEND COND TO ITAB.
CONCATENATE 'OR CITYFROM = ''' 'BERLIN' '''' INTO COND.
APPEND COND TO ITAB.

LOOP AT ITAB INTO COND.
  WRITE COND.
ENDLOOP.

SKIP.

SELECT CITYFROM
INTO   WA
FROM   SPFLI
WHERE  (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:

This graphic is explained in the accompanying text

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

Example

Tabular conditions

DATA: BEGIN OF LINE,
        CARRID   TYPE SPFLI-CARRID,
        CONNID   TYPE SPFLI-CONNID,
        CITYFROM TYPE SPFLI-CITYFROM,
        CITYTO   TYPE SPFLI-CITYTO,
      END OF LINE,
      ITAB LIKE TABLE 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 graphic is explained in the accompanying text

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.

Example

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 CARRID CONNID
INTO   CORRESPONDING FIELDS OF TABLE TAB_SPFLI
FROM   SPFLI
WHERE  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 graphic is explained in the accompanying text

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.

 



 
__BookData_02\capture.png


  report  yrtest0012.

  data: begin of itab_range_srvnr occurs 1,
          sign(1),
          option(2),
          low  like mara-matnr,
          high like mara-matnr,
        end of itab_range_srvnr.


*-----------------------------------------------------------------*
end-of-selection.
*-----------------------------------------------------------------*
  perform complex_srvnr_selection tables itab_range_srvnr
                                   using 'Material'
                                         'MAT1'.




*&----------------------------------------------------------------*
*&      Form  COMPLEX_SRVNR_SELECTION
*&-----------------------------------------------------------------*
*       text
*------------------------------------------------------------------*
form complex_srvnr_selection tables  p_range_tab
                              using  p_title
                                     p_help_field.

  call function 'COMPLEX_SELECTIONS_DIALOG'
    exporting
      title          = p_title
      search_help   =  p_help_field
    tables
      range          = p_range_tab
    exceptions
      no_range_tab   = 1
      cancelled      = 2
      internal_error = 3
      others         4.

endform.                               " COMPLEX_SRVNR_SELECTION