SlideShare a Scribd company logo
Lecture 6 Internal Tables BCO5647 Applications Programming Techniques (ABAP)
Readings & Objectives Readings Keller & Kruger   Chapter 4 Section  4.7.1 – 4.7.3 Objectives This lecture will Introduce the structure of an Internal Table Explore ways of defining an Internal Table in ABAP Explore ways of filling an Internal Table in ABAP Examine how to sort an Internal Table  Examine how to retrieve lines form an Internal Table
What is an internal table ? Internal tables (arrays) are data objects that allow you to retain several data records within the same structure in working memory. Internal tables have the same general structure as a database table, but are held in memory, and initially contain no records. The number of data records stored in an internal table is only restricted by the capacity limits the computer system. An internal table consists of a  body  and an optional  header line . The header line holds the current line of the table. Internal tables are used to process large data sets in a structured manner: Temporarily storing data from database tables for future processing; Structuring and formatting data for output; Formatting data for the use of other services.
Defining an Internal Table Basic ways of defining internal tables with and without header lines. data: itabsbook like sbook occurs 0.  ( no header) data: itabsbook like sbook occurs 0  with header line.  ( header ) data: begin of itabsbook occurs 0, f1, f2, f3, end of itabsbook.  ( header) data: itabsbook type table of sbook, wa_sbookinfo like line of itabsbook.  (user-defined work area in place of header)
Filling an internal table Tables can be filled with data by: Reading data from a database table  e.g tables: vendor. data vendtab like vendor occurs 0   with header line. select * from vendor into table vendtab.  Or s elect * from vendor appending table vendtab . Appending lines  e.g data:  begin of vendtab  occurs 0, no(6) type n, name(20) type c,  end of vendtab. select * from vendor.   vendtab-no = vendor-no.   vendtab-name = vendor-name.   append vendtab. endselect.
Filling an internal table – Example 1 A table  customers  has the following fields : cnum customer number cname customer name caddress customer address cphone customer phone no. report  intabex. tables: customers. data: begin of itabcust occurs 0,   cnum  like  customers-cnum,   cname like  customers-cname, end of itabcust. select  *  from customers.   move-corresponding customers to itabcust.   append itabcust. endselect.
Filling an internal table – Example 2 A table  customers  has the following fields : cnum customer number cname customer name caddress customer address cphone customer phone no. report  intabex. tables: customers. data: begin of itabcust occurs 0,   cnum  like  customers-cnum,   cname like  customers-cname, end of itabcust. select  cnum cname  from customers   into table itabcust.
Filling an internal table  (cont’d) Inserting lines at a specified position. Single lines or a block of lines can be inserted in a table before a specified line number.  All subsequent entries are moved down. Examples : insert vendtab index 3. The contents of the header line will be inserted before line 3. insert lines of new_vend   from 2 to 5   into vendtab index 3. Lines 2 to 5 of the internal table new_vend will be inserted before line 3 of vendtab.
Filling an internal table  (cont’d) Moving complete tables An internal table can be filled with the contents of another one in a single step by using the  move  command. Examples : move new_vend to vendtab. Note : If an internal table with a header line is involved, this header line (but not the internal table itself) is copied by move.
Sorting an Internal Table Data in an internal table can be sorted in a number of ways: Examples: data stud_tab like student occurs 10. 1) sort stud_tab. 2) sort stud_tab by studname, studid. 3) sort stud_tab by stud_id descending.
Retrieving lines Once an internal table has been filled, data can be retrieved by reading each line of the table using a loop, or reading individual lines. Examples : 1) loop at stud_tab. write / stud_tab-studid. write stud_tab-studname. endloop. 2) loop at stud_tab where studname = ‘Smith’. write / stud_tab-studid. endloop.
Retrieving lines (cont’d) 3) read table stud_tab index 5. if sy-subrc = 0. write / stud_tab-studid. else. write / ‘Record not found’. endif. 4) read table stud_tab  with key studid = 3064537. if sy-subrc ………. 5) read table stud_tab with key studname = ‘Smith’   course = ‘BGCC’. 6) read table stud_tab with key studid = 3165432 binary search.
Changing an internal table The contents of a given line in an internal table can be updated using the  modify  command.  For example : read table stud_tab  with key studid = 3354631. if sy-subrc = 0. stud_tab-course = ‘BBBC’. modify stud_tab index sy-tabix. endif. Lines can also be  insert ed into a table and  delete d from a  table.
Changing an internal table  -  Example. report  chgtabex. tables: customers. data: cust_info  like  customers occurs 0 with header line. select  *  from customers into table cust_info. sort cust_info by cnum. read  table cust_info with key cnum = 3456755 binary search. if  sy-subrc = 0. cust_info-cphone = ‘9654-2345’. modify cust_info index sy-tabix. endif. loop  at cust_info.   write: / cust_info-cnum, cust_info-cname. endloop.
Other table commands clear  tablename. Clears the header record of the internal table. refresh  tablename. Removes all the line records in a table (not the header). describe  tablename. Provides information on attributes of the internal table such as number of lines used. free   tablename. Deletes the internal table and releases the storage.

More Related Content

PPT
Internal tables
PDF
Internal tables in sap
PPTX
Sap abap-data structures and internal tables
DOCX
Internal tables
PDF
05 internal tables
PPTX
Excel spreadsheet
PPTX
CREATING SAVING & OPENING SPREADSHEET USING WORKSHEET https://youtu.be/r8Qj5D...
PPT
Spreadhsheets 1
Internal tables
Internal tables in sap
Sap abap-data structures and internal tables
Internal tables
05 internal tables
Excel spreadsheet
CREATING SAVING & OPENING SPREADSHEET USING WORKSHEET https://youtu.be/r8Qj5D...
Spreadhsheets 1

What's hot (20)

PPT
Spread sheet tools presentation
PDF
good practices in formatting ms excel spreadsheets
PPT
spreadsheet program
PPTX
Microsoft Office Excel
PPT
Tabulation
PPT
Ppt Lesson 13
PPT
Devry bis 155 week 3 quiz data analysis
PPT
Lecture 6 spreadsheets
PPTX
Spreadsheet advanced functions ppt (2)
PPT
Database Fundamentals
PPT
Intro to Data warehousing Lecture 04
PPTX
Use of Excel Spreadsheets in Computing Grades
PPT
Database Fundamentals
PPTX
Std 10 Computer Chapter 5 Introduction to Calc
PPT
Dervy bis-155-week-5-quiz-new
PPT
Spreadsheet for Year 8
PPTX
Abap report
PPT
Powerpoint school
Spread sheet tools presentation
good practices in formatting ms excel spreadsheets
spreadsheet program
Microsoft Office Excel
Tabulation
Ppt Lesson 13
Devry bis 155 week 3 quiz data analysis
Lecture 6 spreadsheets
Spreadsheet advanced functions ppt (2)
Database Fundamentals
Intro to Data warehousing Lecture 04
Use of Excel Spreadsheets in Computing Grades
Database Fundamentals
Std 10 Computer Chapter 5 Introduction to Calc
Dervy bis-155-week-5-quiz-new
Spreadsheet for Year 8
Abap report
Powerpoint school
Ad

Viewers also liked (20)

PPT
Lecture08 abap on line
PPT
Lecture09 abap on line
PPT
Lecture12 abap on line
PPT
Lecture05 abap on line
PPT
Lecture04 abap on line
PDF
control techniques
PPT
Lecture13 abap on line
PPT
0100 welcome
PPT
Lecture16 abap on line
PPT
Lecture14 abap on line
PPT
Chapter 04 sap script - output program
PDF
Abap slide lockenqueuedataclustersauthchecks
PDF
Abap slide exceptionshandling
PPT
0103 navigation
PPT
Abap slide class3
PDF
Abap slide lock Enqueue data clusters auth checks
PDF
Abap slides set1
PPT
Lecture11 abap on line
PPT
0106 debugging
PDF
Abap slide class4 unicode-plusfiles
Lecture08 abap on line
Lecture09 abap on line
Lecture12 abap on line
Lecture05 abap on line
Lecture04 abap on line
control techniques
Lecture13 abap on line
0100 welcome
Lecture16 abap on line
Lecture14 abap on line
Chapter 04 sap script - output program
Abap slide lockenqueuedataclustersauthchecks
Abap slide exceptionshandling
0103 navigation
Abap slide class3
Abap slide lock Enqueue data clusters auth checks
Abap slides set1
Lecture11 abap on line
0106 debugging
Abap slide class4 unicode-plusfiles
Ad

Similar to Lecture06 abap on line (20)

PPT
Aspire it sap abap training
PPT
Best SAP ABAP Training Institute with Placement in Pune | Aspire
DOC
Module 3
PDF
Oracle 10g Database Administrator Implementation and Administration 2nd Editi...
PDF
Oracle 10g Database Administrator Implementation and Administration 2nd Editi...
PDF
Oracle 10g Database Administrator Implementation and Administration 2nd Editi...
PDF
Oracle 10g Database Administrator Implementation and Administration 2nd Editi...
PDF
Oracle 10g Database Administrator Implementation and Administration 2nd Editi...
PPTX
Hive commands
PDF
Oracle 10g Database Administrator Implementation and Administration 2nd Editi...
PDF
BCS4L1-Database Management lab.pdf
PPT
Introduction to MySQL - Part 2
DOCX
Linked List
PPT
Myth busters - performance tuning 101 2007
PDF
full detailled SQL notesquestion bank (1).pdf
PPTX
MySQL Essential Training
PPTX
Sql server lesson6
PPT
Introduction to Data structures and Trees.ppt
PPT
Indexing
PPT
Sydney Oracle Meetup - indexes
Aspire it sap abap training
Best SAP ABAP Training Institute with Placement in Pune | Aspire
Module 3
Oracle 10g Database Administrator Implementation and Administration 2nd Editi...
Oracle 10g Database Administrator Implementation and Administration 2nd Editi...
Oracle 10g Database Administrator Implementation and Administration 2nd Editi...
Oracle 10g Database Administrator Implementation and Administration 2nd Editi...
Oracle 10g Database Administrator Implementation and Administration 2nd Editi...
Hive commands
Oracle 10g Database Administrator Implementation and Administration 2nd Editi...
BCS4L1-Database Management lab.pdf
Introduction to MySQL - Part 2
Linked List
Myth busters - performance tuning 101 2007
full detailled SQL notesquestion bank (1).pdf
MySQL Essential Training
Sql server lesson6
Introduction to Data structures and Trees.ppt
Indexing
Sydney Oracle Meetup - indexes

More from Milind Patil (15)

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
Step bystep abap_changinga_singlerecord
PDF
Step bystep abap_changinga_singlerecord
PDF
Abap reports
PPT
Lecture10 abap on line
PPT
Lecture07 abap on line
PPT
Lecture03 abap on line
PPT
Lecture02 abap on line
PPT
Lecture01 abap on line
PPT
Lecture15 abap on line
PPTX
Abap course chapter 6 specialities for erp software
PPTX
Abap course chapter 5 dynamic programs
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
Step bystep abap_changinga_singlerecord
Step bystep abap_changinga_singlerecord
Abap reports
Lecture10 abap on line
Lecture07 abap on line
Lecture03 abap on line
Lecture02 abap on line
Lecture01 abap on line
Lecture15 abap on line
Abap course chapter 6 specialities for erp software
Abap course chapter 5 dynamic programs

Recently uploaded (20)

PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Machine learning based COVID-19 study performance prediction
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Encapsulation theory and applications.pdf
PDF
Approach and Philosophy of On baking technology
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
Spectroscopy.pptx food analysis technology
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
sap open course for s4hana steps from ECC to s4
Machine learning based COVID-19 study performance prediction
Advanced methodologies resolving dimensionality complications for autism neur...
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
NewMind AI Weekly Chronicles - August'25 Week I
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
The Rise and Fall of 3GPP – Time for a Sabbatical?
Encapsulation theory and applications.pdf
Approach and Philosophy of On baking technology
Review of recent advances in non-invasive hemoglobin estimation
MIND Revenue Release Quarter 2 2025 Press Release
Building Integrated photovoltaic BIPV_UPV.pdf
Spectroscopy.pptx food analysis technology
Encapsulation_ Review paper, used for researhc scholars
20250228 LYD VKU AI Blended-Learning.pptx

Lecture06 abap on line

  • 1. Lecture 6 Internal Tables BCO5647 Applications Programming Techniques (ABAP)
  • 2. Readings & Objectives Readings Keller & Kruger Chapter 4 Section 4.7.1 – 4.7.3 Objectives This lecture will Introduce the structure of an Internal Table Explore ways of defining an Internal Table in ABAP Explore ways of filling an Internal Table in ABAP Examine how to sort an Internal Table Examine how to retrieve lines form an Internal Table
  • 3. What is an internal table ? Internal tables (arrays) are data objects that allow you to retain several data records within the same structure in working memory. Internal tables have the same general structure as a database table, but are held in memory, and initially contain no records. The number of data records stored in an internal table is only restricted by the capacity limits the computer system. An internal table consists of a body and an optional header line . The header line holds the current line of the table. Internal tables are used to process large data sets in a structured manner: Temporarily storing data from database tables for future processing; Structuring and formatting data for output; Formatting data for the use of other services.
  • 4. Defining an Internal Table Basic ways of defining internal tables with and without header lines. data: itabsbook like sbook occurs 0. ( no header) data: itabsbook like sbook occurs 0 with header line. ( header ) data: begin of itabsbook occurs 0, f1, f2, f3, end of itabsbook. ( header) data: itabsbook type table of sbook, wa_sbookinfo like line of itabsbook. (user-defined work area in place of header)
  • 5. Filling an internal table Tables can be filled with data by: Reading data from a database table e.g tables: vendor. data vendtab like vendor occurs 0 with header line. select * from vendor into table vendtab. Or s elect * from vendor appending table vendtab . Appending lines e.g data: begin of vendtab occurs 0, no(6) type n, name(20) type c, end of vendtab. select * from vendor. vendtab-no = vendor-no. vendtab-name = vendor-name. append vendtab. endselect.
  • 6. Filling an internal table – Example 1 A table customers has the following fields : cnum customer number cname customer name caddress customer address cphone customer phone no. report intabex. tables: customers. data: begin of itabcust occurs 0, cnum like customers-cnum, cname like customers-cname, end of itabcust. select * from customers. move-corresponding customers to itabcust. append itabcust. endselect.
  • 7. Filling an internal table – Example 2 A table customers has the following fields : cnum customer number cname customer name caddress customer address cphone customer phone no. report intabex. tables: customers. data: begin of itabcust occurs 0, cnum like customers-cnum, cname like customers-cname, end of itabcust. select cnum cname from customers into table itabcust.
  • 8. Filling an internal table (cont’d) Inserting lines at a specified position. Single lines or a block of lines can be inserted in a table before a specified line number. All subsequent entries are moved down. Examples : insert vendtab index 3. The contents of the header line will be inserted before line 3. insert lines of new_vend from 2 to 5 into vendtab index 3. Lines 2 to 5 of the internal table new_vend will be inserted before line 3 of vendtab.
  • 9. Filling an internal table (cont’d) Moving complete tables An internal table can be filled with the contents of another one in a single step by using the move command. Examples : move new_vend to vendtab. Note : If an internal table with a header line is involved, this header line (but not the internal table itself) is copied by move.
  • 10. Sorting an Internal Table Data in an internal table can be sorted in a number of ways: Examples: data stud_tab like student occurs 10. 1) sort stud_tab. 2) sort stud_tab by studname, studid. 3) sort stud_tab by stud_id descending.
  • 11. Retrieving lines Once an internal table has been filled, data can be retrieved by reading each line of the table using a loop, or reading individual lines. Examples : 1) loop at stud_tab. write / stud_tab-studid. write stud_tab-studname. endloop. 2) loop at stud_tab where studname = ‘Smith’. write / stud_tab-studid. endloop.
  • 12. Retrieving lines (cont’d) 3) read table stud_tab index 5. if sy-subrc = 0. write / stud_tab-studid. else. write / ‘Record not found’. endif. 4) read table stud_tab with key studid = 3064537. if sy-subrc ………. 5) read table stud_tab with key studname = ‘Smith’ course = ‘BGCC’. 6) read table stud_tab with key studid = 3165432 binary search.
  • 13. Changing an internal table The contents of a given line in an internal table can be updated using the modify command. For example : read table stud_tab with key studid = 3354631. if sy-subrc = 0. stud_tab-course = ‘BBBC’. modify stud_tab index sy-tabix. endif. Lines can also be insert ed into a table and delete d from a table.
  • 14. Changing an internal table - Example. report chgtabex. tables: customers. data: cust_info like customers occurs 0 with header line. select * from customers into table cust_info. sort cust_info by cnum. read table cust_info with key cnum = 3456755 binary search. if sy-subrc = 0. cust_info-cphone = ‘9654-2345’. modify cust_info index sy-tabix. endif. loop at cust_info. write: / cust_info-cnum, cust_info-cname. endloop.
  • 15. Other table commands clear tablename. Clears the header record of the internal table. refresh tablename. Removes all the line records in a table (not the header). describe tablename. Provides information on attributes of the internal table such as number of lines used. free tablename. Deletes the internal table and releases the storage.

Editor's Notes

  • #4: Multitudes of records can be processed using internal tables – a very important part of ABAP programming ! Because internal tables are held in the current program’s memory space, the access time to read and process the data stored inside the internal tables is significantly less than a read of the database table. The trade-off is CPU time. The header record space holds a copy of whichever record has been read or modified, as well as any new record being added to the table. Individual data records in an internal table are known as table rows or table entries. Individual components in a row are referred to as columns of the internal table.
  • #5: To define an internal table body, use occurs n on the definitions of any field string. To define an internal table with a header line, you must include either begin of or with header line in the definition. The only time you would create an internal table without a header line is in the case of a nested internal table. The body of the internal table and the header line have the same name. Where you use that name determines what you are referring to. Example : data: begin of table1 occurs 0, fld1(1), fld2(2), end of table1. The fieldnames in the above example will be prefixed by the table name. Example : table1-fld1. If you cannot estimate the size of a table, set it to zero. The system will increase it as required. A table set to occurs 0 takes up 8-16K,
  • #6: You can read specific fields directly into an internal table using: select no name from vendor into table vendtab. Normally the previous content of the internal table is overwritten by the new data. If appending is used, the new lines are added at the end of the table. The append statement adds the content of the header line to the end of the internal table. The contents of an internal table can be appended to another table using the addition lines of . e.g. append lines of table1 from 10 to 20 to table2.
  • #11: In example 1, the order is implicitly determined by the sequence of fields in the line structure of the record; i.e. the left-most column represents the highest sort criterion. Note that only non-numeric fields are considered as sort criteria in this form of the statement. In example 2, studname takes precedence, within that the table is sorted by studid.
  • #12: Example 1. These statements display the student id and name for all entries of the internal table stud_tab. During the loop, the header line is filled with the current line of the table at each step. Example 2. The where clause can support all conditional operators that are supported for the if statement. During the loop the current line number is held in sy-tabix. Loops in internal tables can be nested. In addition you can specify the range of lines you want to work with. e.g. loop at stud_tab from 10 to 20.
  • #13: Reading single lines. Example 3. This reads the fifth line in the table. If the table does not have at least 5 entries, the return code sy-subrc returns a non-zero result. Example 4. If this read is successful, the index of the line is returned in sy-tabix. Example 5. Use of multiple keys. Example 6. The binary search algorithm requires that the table entries are sorted according to the specified key. This is a much faster way of locating entries in large tables.
  • #15: Insert : e.g. insert stud_tab index sy-tabix. Inserts before the current line. Delete : e.g. delete stud_tab index sy-tabix.
  • #16: Advanced commands - ref. to on-line Help.