SlideShare a Scribd company logo
Lecture 2 Reading Database Tables BCO5647 Applications Programming Techniques (ABAP)
Readings & Objectives Readings Keller & Kruger  Chapter 8 Section 8.1.1 – 8.1.4 Objectives This lecture will Introduce the ABAP dictionary as part of SAP Introduce ABAP Open SQL Explore reading DB Tables using ABAP SELECT statements Introduce System Variables and examine how they can be incorporated   into an ABAP program Examine program documentation options
The  ABAP  Dictionary The  ABAP  Dictionary  administers  the database tables.  The ABAP dictionary contains current information about a database table’s   technical attributes. When you look at a table in the  ABAP  Dictionary, you are looking at the   DESCRIPTION  of a table in the underlying database.
ABAP Open SQL In a report program you use ABAP  Open SQL  to read data from the   database.
ABAP Open SQL Open SQL is SAP’s version of Standard SQL. Open SQL  statements are converted into database-specific native    SQL statements.   Open SQL makes you code portable and fast.
Using SELECT to Retrieve Data 1 The SELECT clause describes whether the result of the selection will comprise several lines or a single line of data. The FROM clause names the database from which data is to be selected. The INTO clause determines the internal data objects into which the selected data is to be placed. The WHERE clause defines the conditions that the selection results must fulfil. Reading by Single Record ACCESS
Using SELECT to Retrieve Data 2 Reading several rows using a loop.
Using SELECT to Retrieve Data 3 Reading several rows using an Array Fetch
Reusable Components for Data Retrieval If reusable components that encapsulate complex data retrieval are available, you should use them. There are four possible techniques: Calling methods of global classes; Calling methods of business objects; Calling function modules; Including logical databases.
Reading Data from the   Database 1. report y234802a. 2. tables: sbook. 3. select * from sbook. 4.  write: / sbook-carrid, sbook-fldate. 5. endselect. In the example above the  tables  statement: allocates a table work area called sbook; gives the program access to the database table: sbook. The  select  statement begins a loop. The  endselect   marks the end of the loop. Code between  select  and  endselect   are executed once for each row returned from the database .
Using WHERE to limit the Data returned with SELECT 1. report y234802b. 2. tables sbook. 3. select * from sbook 4.  where carrid = ’LH’. 5.  write: / sbook-carrid, sbook-fldate. 6. endselect. The  where  clause allows the program to specify which rows of data are to   be returned by the  select  command. 1. report y234802c. 2. tables sbook. 3. select * from sbook 4.  where carrid = ’LH’ 5. and connid = ’0400’. 6.  write: / sbook-carrid, sbook-fldate. 7. endselect.
Using ORDER BY to sort the Data returned with SELECT 1. report y234802d. 2. tables spfli. 3. select * from spfli 4.  order by cityfrom. 5.  write: / spfli-carrid, spfli-connid, 6.   spfli-cityfrom. 7. endselect. The  order by  clause returns the result of a  select  loop in ascending order by the nominated field.
Working with System Variables SAP’s R/3 system provides a number of system variables which are always available to your program. All system variables have been defined in the Data Dictionary. All system variables begin with the prefix  sy- For example: sy-datum  the current system date. sy-uzeit the current time. Two system variables useful when using the  select  statement are: sy-subrc sy-dbcnt
Working with System Variables sy-subrc  can be used to test whether any rows from the database table were returned after using a  select  statement. If rows were found, the value of  sy–subrc  is 0. If no rows were found, the value of  sy–subrc  is 4. 1. report y234802e. 2. tables sbook. 3. select * from sbook 4.  where carrid = ’LH’. 5.  write: / sbook-carrid, sbook-fldate. 6. endselect. 7. if sy-subrc ne 0. 8.  write / ’No records found’. 9. endif.
Working with System Variables sy-dbcnt  can be used to determine the number of rows returned by a  select statement. sy-dbcnt  can also be used as a loop counter. 1. report y234802f. 2. tables t001. 3. select * from t001. 4.  write: / sy-dbcnt, t001-compyname. 5.  endselect. 6. write: / sy-dbcnt, ’records found’.
Using the SELECT SINGLE statement The  select single  statement retrieves one row (record) from the database table. select single  does not start a loop and so there is no  endselect  statement. A  where  clause must be included containing the value of a primary key that would uniquely identify one row in the database table. 1. report y234802g. 2. tables t001. 3. select single * from t001 4.   where compycode = ’A0125’. 5. if sy-subrc = 0. 6.  write: / t001-compycode, t001-compyname. 7.  else. 8.   write: / ’record not found’. 9. endif.
Commenting Code and Formal Documentation An * (asterisk) in column one indicates that the entire line is a comment. “  (double quotes) anywhere on a line indicates that the remainder of the line is a comment.  Formal documentation can be made in the documentation component of the program. Go to the  ABAP  Editor :  Initial Screen; Click on the Documentation radio button; Press Change; Type in your documentation; Press Save.
Commenting Code and Formal Documentation *----------------------------------------------* * Report Name: y234802h * Author:  John Verbatum * Date:  February  2007 *----------------------------------------------* * Description: * This program will ………… *----------------------------------------------* report y234802h. *----------------------------------------------* * Tables *----------------------------------------------* tables: bsis,  “Index for G/L Accounts kna1,  “Data in Customer Master vbrp.  “Billing: Item Data *----------------------------------------------* * Variables *----------------------------------------------* data: w_buzei(3) type n,  “Line item number w_monat(2) type n.  “Fiscal Period

More Related Content

DOCX
The internals
PPTX
Introduction to oracle optimizer
DOCX
Not in vs not exists
PPTX
Sap abap
PPTX
PLSQL Advanced
PPT
DOC
Pl sql using_xml
PPTX
Oracle: Cursors
The internals
Introduction to oracle optimizer
Not in vs not exists
Sap abap
PLSQL Advanced
Pl sql using_xml
Oracle: Cursors

What's hot (20)

PDF
Migration
PPT
Lecture 2c stacks
DOCX
10053 - null is not nothing
PPTX
SAP Modularization techniques
PPTX
Sap abap-data structures and internal tables
PPT
Internal tables
PPTX
Data Structures - Lecture 7 [Linked List]
PPT
Oracle: PLSQL
PPT
PPT
Oracle Baisc Tutorial
PDF
BCS4L1-Database Management lab.pdf
PDF
Symbol table in compiler Design
PPT
linked list
DOCX
Interview Preparation
PPTX
Oracle: Procedures
PDF
EBS R12 Concurrent program tracing
DOC
Sql Queries
PDF
05 internal tables
PPT
Stacks & Queues
PPT
Rana Junaid Rasheed
Migration
Lecture 2c stacks
10053 - null is not nothing
SAP Modularization techniques
Sap abap-data structures and internal tables
Internal tables
Data Structures - Lecture 7 [Linked List]
Oracle: PLSQL
Oracle Baisc Tutorial
BCS4L1-Database Management lab.pdf
Symbol table in compiler Design
linked list
Interview Preparation
Oracle: Procedures
EBS R12 Concurrent program tracing
Sql Queries
05 internal tables
Stacks & Queues
Rana Junaid Rasheed
Ad

Viewers also liked (20)

PPT
Chapter 01 overview of abap dictionary1
PPT
Chapter 02 abap dictionary objects1
PPT
Chapter 05 adding structures1
PPT
Chapter 04 abap dictionary tables in relational databases1
PPT
Chapter 06 abap repository information system1
PPT
data modelling1
PPT
Chapter 07 abap dictionary changes1
PPT
cardinality1
PPT
Ale Idoc
PPT
Chapter 08 abap dictionary objects views1
PPT
Chapter 10 online help & documentation1
PPT
0106 debugging
PPT
0104 abap dictionary
PDF
Sujith ~ cross applications
PPT
Chapter 03 foreign key relationships1
PDF
Bapi jco[1]
PPT
PPT
table maintenance generator1
PPT
Abap function module help
PPTX
Abap course chapter 3 basic concepts
Chapter 01 overview of abap dictionary1
Chapter 02 abap dictionary objects1
Chapter 05 adding structures1
Chapter 04 abap dictionary tables in relational databases1
Chapter 06 abap repository information system1
data modelling1
Chapter 07 abap dictionary changes1
cardinality1
Ale Idoc
Chapter 08 abap dictionary objects views1
Chapter 10 online help & documentation1
0106 debugging
0104 abap dictionary
Sujith ~ cross applications
Chapter 03 foreign key relationships1
Bapi jco[1]
table maintenance generator1
Abap function module help
Abap course chapter 3 basic concepts
Ad

Similar to Lecture02 abap on line (20)

PDF
DOC
DOC
Introduction to sql
DOC
SQLQueries
DOC
A must Sql notes for beginners
PPTX
PPTX
Sql basics
PPT
[PHPUGPH] PHP Roadshow - MySQL
PPT
AVB202 Intermediate Microsoft Access VBA
PPT
SAS Proc SQL
PDF
SQL Basics and Advanced for analytics.pdf
PDF
SQL_BASIC AND ADVANCED.pdf
PDF
Data Base Management System.pdf
PPTX
SQL(database)
DOCX
Sql intro
PPT
SQL200.1 Module 1
DOCX
PDF
DOCX
SQL Language
PPT
UNIT2.ppt
Introduction to sql
SQLQueries
A must Sql notes for beginners
Sql basics
[PHPUGPH] PHP Roadshow - MySQL
AVB202 Intermediate Microsoft Access VBA
SAS Proc SQL
SQL Basics and Advanced for analytics.pdf
SQL_BASIC AND ADVANCED.pdf
Data Base Management System.pdf
SQL(database)
Sql intro
SQL200.1 Module 1
SQL Language
UNIT2.ppt

More from Milind Patil (20)

PDF
Abap slide class4 unicode-plusfiles
PDF
Step by step abap_input help or lov
PDF
Step bystep abap_fieldhelpordocumentation
PDF
Step bystep abap_field help or documentation
PDF
Abap slides user defined data types and data
PDF
Abap slides set1
PPT
Abap slide class3
PDF
Abap slide lock Enqueue data clusters auth checks
PDF
Step bystep abap_changinga_singlerecord
PDF
Abap slide lockenqueuedataclustersauthchecks
PDF
Abap slide exceptionshandling
PDF
Step bystep abap_changinga_singlerecord
PDF
Abap reports
PPT
Lecture16 abap on line
PPT
Lecture14 abap on line
PPT
Lecture13 abap on line
PPT
Lecture12 abap on line
PPT
Lecture11 abap on line
PPT
Lecture10 abap on line
PPT
Lecture09 abap on line
Abap slide class4 unicode-plusfiles
Step by step abap_input help or lov
Step bystep abap_fieldhelpordocumentation
Step bystep abap_field help or documentation
Abap slides user defined data types and data
Abap slides set1
Abap slide class3
Abap slide lock Enqueue data clusters auth checks
Step bystep abap_changinga_singlerecord
Abap slide lockenqueuedataclustersauthchecks
Abap slide exceptionshandling
Step bystep abap_changinga_singlerecord
Abap reports
Lecture16 abap on line
Lecture14 abap on line
Lecture13 abap on line
Lecture12 abap on line
Lecture11 abap on line
Lecture10 abap on line
Lecture09 abap on line

Recently uploaded (20)

PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
sap open course for s4hana steps from ECC to s4
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
KodekX | Application Modernization Development
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Electronic commerce courselecture one. Pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
MIND Revenue Release Quarter 2 2025 Press Release
Chapter 3 Spatial Domain Image Processing.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Encapsulation_ Review paper, used for researhc scholars
Diabetes mellitus diagnosis method based random forest with bat algorithm
Advanced methodologies resolving dimensionality complications for autism neur...
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Programs and apps: productivity, graphics, security and other tools
sap open course for s4hana steps from ECC to s4
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
KodekX | Application Modernization Development
Mobile App Security Testing_ A Comprehensive Guide.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Electronic commerce courselecture one. Pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...

Lecture02 abap on line

  • 1. Lecture 2 Reading Database Tables BCO5647 Applications Programming Techniques (ABAP)
  • 2. Readings & Objectives Readings Keller & Kruger Chapter 8 Section 8.1.1 – 8.1.4 Objectives This lecture will Introduce the ABAP dictionary as part of SAP Introduce ABAP Open SQL Explore reading DB Tables using ABAP SELECT statements Introduce System Variables and examine how they can be incorporated into an ABAP program Examine program documentation options
  • 3. The ABAP Dictionary The ABAP Dictionary administers the database tables. The ABAP dictionary contains current information about a database table’s technical attributes. When you look at a table in the ABAP Dictionary, you are looking at the DESCRIPTION of a table in the underlying database.
  • 4. ABAP Open SQL In a report program you use ABAP Open SQL to read data from the database.
  • 5. ABAP Open SQL Open SQL is SAP’s version of Standard SQL. Open SQL statements are converted into database-specific native SQL statements. Open SQL makes you code portable and fast.
  • 6. Using SELECT to Retrieve Data 1 The SELECT clause describes whether the result of the selection will comprise several lines or a single line of data. The FROM clause names the database from which data is to be selected. The INTO clause determines the internal data objects into which the selected data is to be placed. The WHERE clause defines the conditions that the selection results must fulfil. Reading by Single Record ACCESS
  • 7. Using SELECT to Retrieve Data 2 Reading several rows using a loop.
  • 8. Using SELECT to Retrieve Data 3 Reading several rows using an Array Fetch
  • 9. Reusable Components for Data Retrieval If reusable components that encapsulate complex data retrieval are available, you should use them. There are four possible techniques: Calling methods of global classes; Calling methods of business objects; Calling function modules; Including logical databases.
  • 10. Reading Data from the Database 1. report y234802a. 2. tables: sbook. 3. select * from sbook. 4. write: / sbook-carrid, sbook-fldate. 5. endselect. In the example above the tables statement: allocates a table work area called sbook; gives the program access to the database table: sbook. The select statement begins a loop. The endselect marks the end of the loop. Code between select and endselect are executed once for each row returned from the database .
  • 11. Using WHERE to limit the Data returned with SELECT 1. report y234802b. 2. tables sbook. 3. select * from sbook 4. where carrid = ’LH’. 5. write: / sbook-carrid, sbook-fldate. 6. endselect. The where clause allows the program to specify which rows of data are to be returned by the select command. 1. report y234802c. 2. tables sbook. 3. select * from sbook 4. where carrid = ’LH’ 5. and connid = ’0400’. 6. write: / sbook-carrid, sbook-fldate. 7. endselect.
  • 12. Using ORDER BY to sort the Data returned with SELECT 1. report y234802d. 2. tables spfli. 3. select * from spfli 4. order by cityfrom. 5. write: / spfli-carrid, spfli-connid, 6. spfli-cityfrom. 7. endselect. The order by clause returns the result of a select loop in ascending order by the nominated field.
  • 13. Working with System Variables SAP’s R/3 system provides a number of system variables which are always available to your program. All system variables have been defined in the Data Dictionary. All system variables begin with the prefix sy- For example: sy-datum the current system date. sy-uzeit the current time. Two system variables useful when using the select statement are: sy-subrc sy-dbcnt
  • 14. Working with System Variables sy-subrc can be used to test whether any rows from the database table were returned after using a select statement. If rows were found, the value of sy–subrc is 0. If no rows were found, the value of sy–subrc is 4. 1. report y234802e. 2. tables sbook. 3. select * from sbook 4. where carrid = ’LH’. 5. write: / sbook-carrid, sbook-fldate. 6. endselect. 7. if sy-subrc ne 0. 8. write / ’No records found’. 9. endif.
  • 15. Working with System Variables sy-dbcnt can be used to determine the number of rows returned by a select statement. sy-dbcnt can also be used as a loop counter. 1. report y234802f. 2. tables t001. 3. select * from t001. 4. write: / sy-dbcnt, t001-compyname. 5. endselect. 6. write: / sy-dbcnt, ’records found’.
  • 16. Using the SELECT SINGLE statement The select single statement retrieves one row (record) from the database table. select single does not start a loop and so there is no endselect statement. A where clause must be included containing the value of a primary key that would uniquely identify one row in the database table. 1. report y234802g. 2. tables t001. 3. select single * from t001 4. where compycode = ’A0125’. 5. if sy-subrc = 0. 6. write: / t001-compycode, t001-compyname. 7. else. 8. write: / ’record not found’. 9. endif.
  • 17. Commenting Code and Formal Documentation An * (asterisk) in column one indicates that the entire line is a comment. “ (double quotes) anywhere on a line indicates that the remainder of the line is a comment. Formal documentation can be made in the documentation component of the program. Go to the ABAP Editor : Initial Screen; Click on the Documentation radio button; Press Change; Type in your documentation; Press Save.
  • 18. Commenting Code and Formal Documentation *----------------------------------------------* * Report Name: y234802h * Author: John Verbatum * Date: February 2007 *----------------------------------------------* * Description: * This program will ………… *----------------------------------------------* report y234802h. *----------------------------------------------* * Tables *----------------------------------------------* tables: bsis, “Index for G/L Accounts kna1, “Data in Customer Master vbrp. “Billing: Item Data *----------------------------------------------* * Variables *----------------------------------------------* data: w_buzei(3) type n, “Line item number w_monat(2) type n. “Fiscal Period

Editor's Notes

  • #4: The ABAP Dictionary The ABAP Dictionary is part of SAP. It contains definitions of tables found in the database (table name, field names, type, length etc.) Each table has a unique name within the SAP system. SAP comes with over 8000 table descriptions in the ABAP Dictionary. During implementation of an SAP system, specialist consultants use many of these tables to map to the organisation's existing database tables. The ABAP Dictionary sits on top of a database such as Oracle or Informix and acts like a remote control generating and sending SQL statements to it. For example, when you create a table definition in the ABAP Dictionary, SQL statements are generated and sent to the database, causing it to create the actual table in the database. When you want to modify the table, you must modify the table definition in the Data Dictionary - this generates more SQL causing the database to modify the table. When you look at a table in the ABAP Dictionary , you are looking at the DESCRIPTION of a table in the underlying DB.
  • #5: ABAP Open SQL Reading data from the database is probably the most common activity in an ABAP program . A report program usually consists of a selection screen on which you define the dataset you wish to display . The user’s selection is integrated into an ABAP open SQL statement to extract the relevant data from the database. This data is then displayed as a “list” or “report”. Demonstrate zbmclec002a_demo What is OPEN SQL ?
  • #6: ABAP Open SQL Open SQL statements are a version of Standard SQL. Open SQL goes beyond standard SQL by offering variants of the statements that only operate in ABAP programs and can simply or accelerate database access . Open SQL statements allow you to access the database in a uniform way from your programs, regardless of the database system being used. This is achieved because Open SQL statements are converted into database-specific (native) SQL statements by the database interface. For example, if you were running an Oracle database, your ABAP Open SQL would be converted by the database interface to Oracle SQL statements. Open SQL allows your ABAP programs to be portable between databases. For example, if your company wanted to switch from an Oracle DB to an Informix DB, it could change the database, and your ABAP code would continue to run without modification. Open SQL makes your code fast . SAP’s database interface buffers information from the database. When data is read from the database, it can be stored in buffers. If a request is made to access the same records, the request can be satisfied without having to go to the database. This buffering technique reduces the load on the database server and can speed up database access times by a factor of 10 to 100 times.
  • #7: You use the Open SQL statement SELECT to program database read access. The SELECT statement contains a series of clauses, each of which has a different task: The SELECT clause describes whether the result of the selection will comprise several lines or a single line of data. The FROM clause names the database from which data is to be selected. The INTO clause determines the internal data objects into which the selected data is to be placed. The WHERE clause defines the conditions that the selection results must fulfil. Reading by Single Record ACCESS The SELECT SINGLE * statement allows you to read a single record from the database table. To ensure a unique access, all key fields must be filled in the WHERE clause. The * informs the database interface that all columns in that row of the database table should be read. If you only wish a specific selection of columns, you can list the required fields instead. In the INTO clause, enter the destination to where the database interface is to copy the data. The target area should have a structure identical to the columns of the database table being read.
  • #8: Reading several rows using a loop If you do not use the SINGLE addition with the SELECT statement, the system reads multiple records from the database. In this example, the field list determines the columns whose data is to be read from the database. The number of requested rows to be read can be restricted using the WHERE clause. In the WHERE clause, you enter only the field names of the database table. The name of the database table that is accessed is found in the FROM clause. The database delivers the data to the database interface in packages. The ABAP runtime system copies the data records to the target area row by row using a loop. It also enables sequential processing of all the statements between SELECT and ENDSELECT.
  • #9: Reading Several Rows Using an Array Fetch The INTO TABLE addition causes the ABAP runtime system to copy the contents of the database interface directly to the specified internal table. This is called an array fetch . Since the array fetch is not executed as a loop, you must not program an ENDSELECT statement.
  • #10: Methods of global classes (covered later) Methods of business objects (NOT covered in this subject but Adv ABAP) Function modules (covered later) Logical databases (covered later)
  • #11: Reading Data from the Database Line 1 - the report statement is required as the first line of a report program. Line 2 - the tables statement does 2 things: First, it allocates a memory area called the table work area. The name of this work area is called sbook . Second, it gives the program access to the database table called sbook . Note the program has 2 things named sbook : a work area and a table. Line 3 - Select is a looping command when it is used in conjunction with endselect . The select statement returns all rows contained in the named table, one at a time. The first row is returned and placed in the work area and made available for processing during the first pass of the loop. The second row is available during the second pass of the loop and so on, until all rows have been read from the table. The “*” means that ALL fields in each row of the database table are returned and stored in the table work area. Line 4 - the write statement is executed once for each row that is read from the database table into the table work area. Note that only two fields for each table row retrieved are printed. Also note that the field names are preceded by the table work area name and a hyphen.
  • #12: Using WHERE to limit the Data returned with SELECT A where clause can be added to the select statement to restrict the number of rows returned from the database. In the first program, the only rows read from the table are those where the table field CARRID has the value LH. The and operator can be used to include more than one condition. The or operator can also be used in the where clause.
  • #13: Using ORDER BY to sort the Data returned with SELECT Order By can have more than one field included Fields must be separated by spaces not commas, e.g. order by cityfrom cityto.
  • #14: Working with System Variables SAP’s R/3 system makes system variables available within your program. You don’t have to define anything to access them, they are always available. They begin with the prefix sy- and are usually called sy (sigh) fields for short. All system variables are defined in the ABAP Dictionary.
  • #15: Working with System Variables - sy-subrc To determine if the select statement returned any rows, you can test the system variable sy-subrc (sigh-sub-are-see) after the endselect statement If rows were found, the value of sy-subrc will be 0. If no rows were found, the value will be 4. If you code a select statement and want to test the value of sy-subrc , your test must come after the endselect statement. WHY? Answer: The code between the select and endselect is executed once for each row returned from the database. If no rows are returned from the database, the code between select and endselect is never executed. Therefore, you must code the test for sy-subrc AFTER the endselect . Demonstrate zbmclec002b_demo
  • #16: Working with System Variables - sy-dbcnt The system variable sy-dbcnt keeps a count of the number of rows returned from a select statement. By testing the value of sy-dbcnt after the ENDSELECT statement, you can determine the number of rows returned. sy-dbcnt can also be used as a loop counter; between the SELECT and ENDSELECT it contains a count of the current loop. For the first row returned, sy-dbcnt will be 1, for the second it will be 2, and so on. After the ENDSELECT, it will retain its value and so will contain the number of rows selected. What output would result from the sample program? 1 Acme Australia 2 Acme North America 3 Acme Asia 4 Acme Europe 4 records found
  • #17: Using the SELECT SINGLE statement You can use the SELECT SINGLE statement when you want a single row of data. For example, if you have a student number and you want to look up the student details. No ENDSELECT is needed because only one row is returned. If you know that only one row of data will always be returned, use this option as it is much faster more efficient than SELECT/ENDSELECT . To ensure that one unique row is returned, you should specify a primary field value in the WHERE clause.
  • #18: Commenting Code and Formal Documentation All programs should be fully documented. There are 2 ways to put comments into your code: An * in column one indicates that the entire line is a comment. It will turn red within the editor to indicate that it is a full-line comment. “ anywhere on a line indicates that the remainder of the line is a comment. There is no end-comment character. That means, when you begin a comment, the remainder of the line will be a comment only. No more code can follow on that line. The comment ends at the end of the current line. Aside from comments, you can formally document your code in the documentation component of the program.