Tuesday, 27 August 2013

AUGUST 27

 SAP ALV:

ALV stands for ABAP List Viewer. ALV gives us a standard List format and user interface to all our ABAP reports. ALV is created by a set of standard function modules provided by SAP.
ALV provides a lot of inbuilt functions to our reports and some of the functions  are listed below.
  • Sorting of records
  • Filtering of records
  • Totals and Sub-totals
  • Download the report output to Excel/HTML
  • Changing the order of the columns in the report
  • Hide the unwanted columns  from the report
Some of the function modules used to create ALV reports are listed below.
FUNCTION MODULEDESCRIPTION
REUSE_ALV_LIST_DISPLAYDisplay an ALV list
REUSE_ALV_GRID_DISPLAYDisplay an ALV grid
REUSE_ALV_COMMENTARY_WRITEOutput List header information
REUSE_ALV_VARIANT_F4Display variant selection dialog box
REUSE_ALV_VARIANT_EXISTENCEChecks whether a variant exists
REUSE_ALV_FIELDCATALOG_MERGECreate field catalog from dictionary structure or internal table
Simple ALV report.
Example:

DATA: it_spfli TYPE TABLE OF spfli.

SELECT * FROM spfli INTO TABLE it_spfli.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
  EXPORTING
    i_structure_name = 'SPFLI'
  TABLES
    t_outtab         = it_spfli.

An ALV report is created using the standard function modules provided by SAP.
An ALV report can be created using the following steps.

  • Include SLIS type pool – SLIS type pool contains all the data types required by ALV function modules.
  • Data retrieval – Code the logic to fetch the data from database table into an Internal Table.
  • Build Field Catalog – Add the columns into an internal that you want to display in the ALV output list.
  • Pass the data table and field catalog table to ALV function module
TYPE-POOLS: slis.  " SLIS contains all the ALV data types

*&---------------------------------------------------------------------*
*& Data Declaration
*&---------------------------------------------------------------------*
DATA: it_sbook     TYPE TABLE OF sbook.
DATA: it_fieldcat  TYPE slis_t_fieldcat_alv,
      wa_fieldcat  TYPE slis_fieldcat_alv.
*&---------------------------------------------------------------------*
*& START-OF-SELECTION
*&---------------------------------------------------------------------*
START-OF-SELECTION.

*Fetch data from the database

  SELECT * FROM sbook INTO TABLE it_sbook.

*Build field catalog

  wa_fieldcat-fieldname  = 'CARRID'.    " Field name in the data table
  wa_fieldcat-seltext_m  = 'Airline'.         " Column description in the output
  APPEND wa_fieldcat TO it_fieldcat.

  wa_fieldcat-fieldname  = 'CONNID'.
  wa_fieldcat-seltext_m  = 'Con. No.'.
  APPEND wa_fieldcat TO it_fieldcat.

  wa_fieldcat-fieldname  = 'FLDATE'.
  wa_fieldcat-seltext_m  = 'Date'.
  APPEND wa_fieldcat TO it_fieldcat.

  wa_fieldcat-fieldname  = 'BOOKID'.
  wa_fieldcat-seltext_m  = 'Book. ID'.
  APPEND wa_fieldcat TO it_fieldcat.

  wa_fieldcat-fieldname  = 'PASSNAME'.
  wa_fieldcat-seltext_m  = 'Passenger Name'.
  APPEND wa_fieldcat TO it_fieldcat.

*Pass data and field catalog to ALV function module to display ALV list

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      it_fieldcat   = it_fieldcat
    TABLES
      t_outtab      = it_sbook
Output:



  

Monday, 26 August 2013

AUGUST 26

Few more concepts used with ABAP internal Tables:

DESCRIBE TABLE is the statement to get the attributes like number of lines, line width of each row etc. of the internal table. 
Syntax:

DESCRIBE TABLE <internal table> [LINES <lines>].

SORT is the statement to sort an ABAP internal table. We can specify the direction of the sort using the additions ASCENDING and DESCENDING. The default is ascending.
Syntax:

SORT <internal table> [ASCENDING|DESCENDING]

We can also delete the adjacent duplicates from an internal table by using the following statement.
Syntax:

DELETE ADJACENT DUPLICATE ENTRIES FROM <internal table>
                 [COMPARING <f1> <f2> ... |ALL FIELDS].

COMPARING ALL FIELDS is the default. If we do not specify the COMPARING addition, then the system compares all the fields of both the lines. If we specify fields in the COMPARING clause, then the system compares only the fields specified after COMPARING of both the lines. 

Example:
*--------------------------------------------------------------*
*Data Types
*--------------------------------------------------------------*
TYPES: BEGIN OF ty_student,
       id(5)     TYPE n,
       name(10)  TYPE c,
       place(10) TYPE c,
       age       TYPE i,
       END OF ty_student.

*--------------------------------------------------------------*
*Data Declaration
*--------------------------------------------------------------*
DATA: gwa_student TYPE ty_student.
DATA: it  TYPE TABLE OF ty_student.
DATA: gv_lines TYPE i.

gwa_student-id     = 1.
gwa_student-name   = 'JOHN'.
gwa_student-place  = 'London'.
gwa_student-age    = 20.
APPEND gwa_student TO it.

gwa_student-id     = 2.
gwa_student-name   = 'JIM'.
gwa_student-place  = 'New York'.
gwa_student-age    = 21.
APPEND gwa_student TO it.

gwa_student-id     = 3.
gwa_student-name   = 'JACK'.
gwa_student-place  = 'Bangalore'.
gwa_student-age    = 20.
APPEND gwa_student TO it.

gwa_student-id     = 4.
gwa_student-name   = 'ROB'.
gwa_student-place  = 'Bangalore'.
gwa_student-age    = 22.
APPEND gwa_student TO it.

gwa_student-id     = 2.
gwa_student-name   = 'JIM'.
gwa_student-place  = 'New York'.
gwa_student-age    = 21.
APPEND gwa_student TO it.

DESCRIBE TABLE it LINES gv_lines.
WRITE:/ 'No. of lines in IT : ', gv_lines.

WRITE:/ 'SY-TFILL : ', sy-tfill.
WRITE:/ 'SY-TLENG : ', sy-tleng.

WRITE:/ 'Values in IT before SORT' COLOR 4.

WRITE:/ 'ID' COLOR 5,7 'Name' COLOR 5, 18 'Place' COLOR 5,
        37 'Age' COLOR 5.
LOOP AT it INTO gwa_student.
  WRITE:/ gwa_student-id, gwa_student-name, gwa_student-place,
          gwa_student-age.
ENDLOOP.

WRITE:/ 'Values in IT after SORT' COLOR 4.

*SORT by name

SORT it BY name DESCENDING.

WRITE:/ 'ID' COLOR 5,7 'Name' COLOR 5, 18 'Place' COLOR 5,
        37 'Age' COLOR 5.
LOOP AT it INTO gwa_student.
  WRITE:/ gwa_student-id, gwa_student-name, gwa_student-place,
          gwa_student-age.
ENDLOOP.

WRITE:/ 'Values in IT after deleting duplicates' COLOR 4.

*Delete duplicates

SORT it.
DELETE ADJACENT DUPLICATES FROM it.

WRITE:/ 'ID' COLOR 5,7 'Name' COLOR 5, 18 'Place' COLOR 5,
        37 'Age' COLOR 5.
LOOP AT it INTO gwa_student.
  WRITE:/ gwa_student-id, gwa_student-name, gwa_student-place,
          gwa_student-age.
ENDLOOP.

WRITE:/ 'Values in IT after deleting duplicates comparing place' COLOR 4.

*Delete duplicates comparing only place

SORT it BY place.
DELETE ADJACENT DUPLICATES FROM it COMPARING place.

WRITE:/ 'ID' COLOR 5,7 'Name' COLOR 5, 18 'Place' COLOR 5,
        37 'Age' COLOR 5.
LOOP AT it INTO gwa_student.
  WRITE:/ gwa_student-id, gwa_student-name, gwa_student-place,
          gwa_student-age.
ENDLOOP.

We can exit out of LOOP/ENDLOOP processing using EXIT, CONTINUE and CHECK similar to all other LOOPS.
We can  also initialize the internal table using FREE, CLEAR and REFRESH statements. CLEAR and REFRESH just initializes the internal table where as FREE initializes the internal table and releases the memory space.
Example:

*--------------------------------------------------------------*
*Data Types
*--------------------------------------------------------------*
TYPES: BEGIN OF ty_student,
       id(5)     TYPE n,
       name(10)  TYPE c,
       place(10) TYPE c,
       age       TYPE i,
       END OF ty_student.

*--------------------------------------------------------------*
*Data Declaration
*--------------------------------------------------------------*
DATA: gwa_student TYPE ty_student.
DATA: it  TYPE TABLE OF ty_student.
DATA: gv_lines TYPE i.

gwa_student-id     = 1.
gwa_student-name   = 'JOHN'.
gwa_student-place  = 'London'.
gwa_student-age    = 20.
APPEND gwa_student TO it.

gwa_student-id     = 2.
gwa_student-name   = 'JIM'.
gwa_student-place  = 'New York'.
gwa_student-age    = 21.
APPEND gwa_student TO it.

WRITE:/ 'Values in IT before initializing' COLOR 4.

WRITE:/ 'ID' COLOR 5,7 'Name' COLOR 5, 18 'Place' COLOR 5,
        37 'Age' COLOR 5.
LOOP AT it INTO gwa_student.
  WRITE:/ gwa_student-id, gwa_student-name, gwa_student-place,
          gwa_student-age.
ENDLOOP.

*Initialize IT

CLEAR it.

SKIP.
WRITE:/ 'Values in IT before initializing' COLOR 4.
WRITE:/ 'ID' COLOR 5,7 'Name' COLOR 5, 18 'Place' COLOR 5,
        37 'Age' COLOR 5.
LOOP AT it INTO gwa_student.
  WRITE:/ gwa_student-id, gwa_student-name, gwa_student-place,
          gwa_student-age.
ENDLOOP.

*If no records are processed inside LOOP, then SY-SUBRC <> 0

IF sy-subrc <> 0.
  WRITE:/ 'No records found.'.
ENDIF.

SKIP.
*We can also use IS INITIAL to check any records found in IT

IF it IS INITIAL.
  WRITE:/ 'No records found in IT.'.
ENDIF.


Friday, 23 August 2013

AUGUST 23

Deleting Lines from an ABAP Internal Table:

DELETE is the statement to delete one or more lines from an ABAP Internal Table. Use the INDEX addition to delete a single line. If we use the INDEX addition and the operation is successful,  the  line with the corresponding index in the internal table will be deleted and the indexes of the subsequent lines will be reduced by one.
Syntax:
DELETE <internal table> [INDEX <index>].
We can also use the above DELETE statement without INDEX addition inside LOOP. Inside LOOP if we do not specify the INDEX, then the current loop line will be deleted.
We can use the WHERE clause to delete single or multiple lines. All the lines that meet the logical condition will be deleted
Syntax:
DELETE <internal table> [FROM <n1>] [TO <n2>] [WHERE <condition>].

With WHERE clause we can also specify the lines between certain indices that we want to delete by specifying indexes in FROM and TO additions.
Example:

*--------------------------------------------------------------*
*Data Types
*--------------------------------------------------------------*
TYPES: BEGIN OF ty_student,
       id(5)     TYPE n,
       name(10)  TYPE c,
       place(10) TYPE c,
       age       TYPE i,
       END OF ty_student.

*--------------------------------------------------------------*
*Data Declaration
*--------------------------------------------------------------*
DATA: gwa_student TYPE ty_student.
DATA: it  TYPE TABLE OF ty_student.

gwa_student-id     = 1.
gwa_student-name   = 'JOHN'.
gwa_student-place  = 'London'.
gwa_student-age    = 20.
INSERT gwa_student INTO TABLE it.

gwa_student-id     = 2.
gwa_student-name   = 'JIM'.
gwa_student-place  = 'New York'.
gwa_student-age    = 21.
INSERT gwa_student INTO TABLE it.

gwa_student-id     = 3.
gwa_student-name   = 'JACK'.
gwa_student-place  = 'Bangalore'.
gwa_student-age    = 20.
INSERT gwa_student INTO TABLE it.

gwa_student-id     = 4.
gwa_student-name   = 'ROB'.
gwa_student-place  = 'Bangalore'.
gwa_student-age    = 22.
INSERT gwa_student INTO TABLE it.

WRITE:/ 'Values in IT before DELETE' COLOR 4.

WRITE:/ 'ID' COLOR 5,7 'Name' COLOR 5, 18 'Place' COLOR 5,
        37 'Age' COLOR 5.
LOOP AT it INTO gwa_student.
  WRITE:/ gwa_student-id, gwa_student-name, gwa_student-place,
          gwa_student-age.
ENDLOOP.

SKIP.
WRITE:/ 'Values in IT after DELETE' COLOR 4.

*Delete second line from IT

DELETE it INDEX 2.

WRITE:/ 'ID' COLOR 5,7 'Name' COLOR 5, 18 'Place' COLOR 5,
        37 'Age' COLOR 5.
LOOP AT it INTO gwa_student.
  WRITE:/ gwa_student-id, gwa_student-name, gwa_student-place,
          gwa_student-age.
ENDLOOP.

SKIP.
WRITE:/ 'Values in IT after DELETE using WHERE Clause' COLOR 4.

*Delete entries from IT where place is Bangalore

DELETE it WHERE place = 'Bangalore'.

WRITE:/ 'ID' COLOR 5,7 'Name' COLOR 5, 18 'Place' COLOR 5,
        37 'Age' COLOR 5.
LOOP AT it INTO gwa_student.
  WRITE:/ gwa_student-id, gwa_student-name, gwa_student-place,
          gwa_student-age.
ENDLOOP.

Output:







                                                                                                                                                                                    
                                               

Thursday, 22 August 2013

AUGUST 22

Changing Lines in ABAP Internal Tables:

MODIFY is the statement to change single or multiple lines in an internal table. Use the INDEX addition to change a single line. If we use the INDEX addition and the operation is successful,  the contents of the work area overwrites the contents of the line with the corresponding index.
Instead of changing all the values of a row we can specify the fields we want to change by specifying the field names in the TRANSPORTING addition.
Syntax:

MODIFY <internal table> FROM <work area> [INDEX <index>]
                              [TRANSPORTING <f1> <f2> ... ].

We can also use the above MODIFY statement without INDEX addition inside LOOP. Inside LOOP if we do not specify the INDEX, then the current loop line will be modified.
We can use the WHERE clause to change single or multiple lines. All the lines that meet the logical condition will be processed.
Syntax:

MODIFY <internal table> FROM <work area>
          TRANSPORTING <f1> <f2> ... WHERE <condition>.

Example:

*--------------------------------------------------------------*
*Data Types
*--------------------------------------------------------------*
TYPES: BEGIN OF ty_student,
       id(5)     TYPE n,
       name(10)  TYPE c,
       place(10) TYPE c,
       age       TYPE i,
       END OF ty_student.

*--------------------------------------------------------------*
*Data Declaration
*--------------------------------------------------------------*
DATA: gwa_student TYPE ty_student.
DATA: it  TYPE TABLE OF ty_student.

gwa_student-id     = 1.
gwa_student-name   = 'JOHN'.
gwa_student-place  = 'London'.
gwa_student-age    = 20.
INSERT gwa_student INTO TABLE it.

gwa_student-id     = 2.
gwa_student-name   = 'JIM'.
gwa_student-place  = 'New York'.
gwa_student-age    = 21.
INSERT gwa_student INTO TABLE it.

gwa_student-id     = 3.
gwa_student-name   = 'JACK'.
gwa_student-place  = 'Bangalore'.
gwa_student-age    = 20.
INSERT gwa_student INTO TABLE it.

gwa_student-id     = 4.
gwa_student-name   = 'ROB'.
gwa_student-place  = 'Bangalore'.
gwa_student-age    = 22.
INSERT gwa_student INTO TABLE it.

WRITE:/ 'Values in IT before MODIFY' COLOR 4.

WRITE:/ 'ID' COLOR 5,7 'Name' COLOR 5, 18 'Place' COLOR 5,
        37 'Age' COLOR 5.
LOOP AT it INTO gwa_student.
  WRITE:/ gwa_student-id, gwa_student-name, gwa_student-place,
          gwa_student-age.
ENDLOOP.

SKIP.
WRITE:/ 'Values in IT after MODIFY' COLOR 4.

gwa_student-id     = 4.
gwa_student-name   = 'ROB'.
gwa_student-place  = 'Mumbai'.
gwa_student-age    = 25.

*Change all the columns of row 4 with work area values
MODIFY it FROM gwa_student INDEX 4.

WRITE:/ 'ID' COLOR 5,7 'Name' COLOR 5, 18 'Place' COLOR 5,
        37 'Age' COLOR 5.
LOOP AT it INTO gwa_student.
  WRITE:/ gwa_student-id, gwa_student-name, gwa_student-place,
          gwa_student-age.
ENDLOOP.

SKIP.
WRITE:/ 'Values in IT after Transporting addition' COLOR 4.

gwa_student-id     = 9.
gwa_student-name   = 'TOM'.
gwa_student-place  = 'Bangalore'.
gwa_student-age    = 30.
*Change specific columns of row 4 with work area values by
*using TRANSPORTING addition
MODIFY it FROM gwa_student INDEX 4 TRANSPORTING place.

WRITE:/ 'ID' COLOR 5,7 'Name' COLOR 5, 18 'Place' COLOR 5,
        37 'Age' COLOR 5.
LOOP AT it INTO gwa_student.
  WRITE:/ gwa_student-id, gwa_student-name, gwa_student-place,
          gwa_student-age.
ENDLOOP.

SKIP.
WRITE:/ 'Values in IT after MODIFY using WHERE Clause' COLOR 4.

gwa_student-place  = 'Mumbai'.

*Change multiple rows using WHERE clause
MODIFY it FROM gwa_student TRANSPORTING place
                           WHERE place = 'Bangalore'.

WRITE:/ 'ID' COLOR 5,7 'Name' COLOR 5, 18 'Place' COLOR 5,
        37 'Age' COLOR 5.
LOOP AT it INTO gwa_student.
  WRITE:/ gwa_student-id, gwa_student-name, gwa_student-place,
          gwa_student-age.

ENDLOOP.

Wednesday, 14 August 2013

AUGUST 14

Today I only revised all the concepts studied so far.  There were continuous holidays due to independence day , weekend off , raksha bandhan holiday. I have taken half day leave so that i could board the train to my home.So, practically I did nothing new today. Only a brief go-through over all the topics.

I was back on August 21 morning. Though it was a tiresome journey,still I went for my training classes. But to my unfortunate luck, there was some electric fault and no networks were available to work. And hence got one more day off. Overall , I enjoyed the holidays from August 14 to August 21.

Tuesday, 13 August 2013

AUGUST 13

Inserting lines into Internal Tables:
We can insert one or more lines to ABAP internal tables using the INSERT statement. To insert a single line, first place the values we want to insert in a work area and use the INSERT statement to insert the values in the work area to internal table.
Syntax to insert a line to internal table

INSERT <work area> INTO TABLE <internal table>.
                       OR
INSERT <work area> INTO <internal table> INDEX <index>.

The first INSERT statement without INDEX addition will simply add the record to the end of the internal table. But if we want to insert the line to specific location i.e. if we want to insert it as second record then we need to specify 2 as the index in the INSERT statement.

Example:
*--------------------------------------------------------------*
*Data Types
*--------------------------------------------------------------*
TYPES: BEGIN OF ty_student,
       id(5)    TYPE n,
       name(10) TYPE c,
       END OF ty_student.

*--------------------------------------------------------------*
*Data Declaration
*--------------------------------------------------------------*
DATA: gwa_student TYPE ty_student.
DATA: it TYPE TABLE OF ty_student.

gwa_student-id    = 1.
gwa_student-name  = 'JOHN'.
INSERT gwa_student INTO TABLE it.

gwa_student-id    = 2.
gwa_student-name  = 'JIM'.
INSERT gwa_student INTO TABLE it.

gwa_student-id    = 3.
gwa_student-name  = 'JACK'.
INSERT gwa_student INTO TABLE it.

WRITE:/ 'ID' COLOR 5,7 'Name' COLOR 5.
LOOP AT it INTO gwa_student.
  WRITE:/ gwa_student-id, gwa_student-name.
ENDLOOP.

SKIP.
WRITE:/ 'After using Index addition' COLOR 4.

gwa_student-id    = 4.
gwa_student-name  = 'RAM'.
INSERT gwa_student INTO it INDEX 2.

WRITE:/ 'ID' COLOR 5,7 'Name' COLOR 5.
LOOP AT it INTO gwa_student.
  WRITE:/ gwa_student-id, gwa_student-name.
ENDLOOP.

We can also insert multiple lines to an internal table with a single INSERT statement i.e. we can insert the lines of one internal table to another internal table.

Syntax to insert multiple lines to internal table

INSERT LINES OF <itab1> [FROM <index 1>] [TO <index 2>] INTO TABLE <itab2>.
                                        OR
INSERT LINES OF <itab1> [FROM <index 1>] [TO <index 2>] INTO
<itab2> INDEX <index>.

Example:
*--------------------------------------------------------------*
*Data Types
*--------------------------------------------------------------*
TYPES: BEGIN OF ty_student,
       id(5)    TYPE n,
       name(10) TYPE c,
       END OF ty_student.

*--------------------------------------------------------------*
*Data Declaration
*--------------------------------------------------------------*
DATA: gwa_student TYPE ty_student.
DATA: it  TYPE TABLE OF ty_student,
      it2 TYPE TABLE OF ty_student,
      it3 TYPE TABLE OF ty_student,
      it4 TYPE TABLE OF ty_student.

gwa_student-id    = 1.
gwa_student-name  = 'JOHN'.
INSERT gwa_student INTO TABLE it.

gwa_student-id    = 2.
gwa_student-name  = 'JIM'.
INSERT gwa_student INTO TABLE it.

gwa_student-id    = 3.
gwa_student-name  = 'JACK'.
INSERT gwa_student INTO TABLE it.

gwa_student-id    = 4.
gwa_student-name  = 'ROB'.
INSERT gwa_student INTO TABLE it.

WRITE:/ 'Inserting all the lines of IT to IT2' COLOR 4.

INSERT LINES OF it INTO TABLE it2.

WRITE:/ 'Display values of IT2' COLOR 1.
WRITE:/ 'ID' COLOR 5,7 'Name' COLOR 5.
LOOP AT it2 INTO gwa_student.
  WRITE:/ gwa_student-id, gwa_student-name.
ENDLOOP.

SKIP.
WRITE:/ 'Inserting only lines 2 & 3 of IT to IT3' COLOR 4.

INSERT LINES OF it FROM 2 TO 3 INTO TABLE it3.

WRITE:/ 'Display values of IT3' COLOR 1.
WRITE:/ 'ID' COLOR 5,7 'Name' COLOR 5.
LOOP AT it3 INTO gwa_student.
  WRITE:/ gwa_student-id, gwa_student-name.
ENDLOOP.

gwa_student-id    = 1.
gwa_student-name  = 'RAM'.
INSERT gwa_student INTO TABLE it4.

gwa_student-id    = 4.
gwa_student-name  = 'RAJ'.
INSERT gwa_student INTO TABLE it4.

SKIP.
WRITE:/ 'Inserting only lines 2 & 3 of IT to IT4 at 2' COLOR 4.

INSERT LINES OF it FROM 2 TO 3 INTO it4 INDEX 2.

WRITE:/ 'Display values of it4' COLOR 1.
WRITE:/ 'ID' COLOR 5,7 'Name' COLOR 5.
LOOP AT it4 INTO gwa_student.
  WRITE:/ gwa_student-id, gwa_student-name.
ENDLOOP.



Monday, 12 August 2013

AUGUST 12

Deleting Values from Database Tables:

DELETE is the open SQL statement to delete entries from database table. First we declare a work area as the line structure of database table and fill the work area with the  specific key that we want to delete from the database table. Then delete the entries from the database table using DELETE statement.
The syntax for the DELETE statement is as follows.
DELETE <database table> FROM <work area>
If the database table contains a line with the same primary key as specified in the work area, the operation is completed successfully.
Example:
DATA: gwa_employee TYPE zemployee.

gwa_employee-id      = 6.
gwa_employee-name    = 'JOSEPH'.
gwa_employee-place   = 'FRANKFURT'.
gwa_employee-phone   = '7897897890'.
gwa_employee-dept_id = 5.


DELETE zemployee FROM gwa_employee.


We can also multiple lines from the table using the WHERE clause in the DELETE statement.
DELETE FROM <database table> WHERE <condition>
Example:
DELETE FROM zemployee WHERE dept_id = 2. 

Internal Tables

An Internal table is a temporary table gets created in the memory of application server during program execution and gets destroyed once the program ends. It is used to hold data temporarily or manipulate the data. It contains one or more rows with same structure.
An internal table can be defined using the keyword TABLE OF in the DATA statement. Internal table can be defined by the following ways.
Example:
TYPES: BEGIN OF ty_student,
       id(5)    TYPE n,
       name(10) TYPE c,
       END OF ty_student.

DATA: gwa_student TYPE ty_student.

"Referring to local data type
DATA: it1 TYPE TABLE OF ty_student.
"Referring to local data object
DATA: it2 LIKE TABLE OF gwa_student.
"Referring to data type in ABAP dictionary
DATA: it3 TYPE TABLE OF mara.

we use the APPEND statement to add data to internal table. First we define the work area i.e. define a field string with a structure similar to row of the internal table , then place the data in the work area and use the APPEND statement to add the data from work area to internal table.
Example:
DATA: gwa_student TYPE ty_student.

*--------------------------------------------------------------*
*Data Declaration
*--------------------------------------------------------------*
"Referring to local data type
DATA: it TYPE TABLE OF ty_student.

gwa_student-id    = 1.
gwa_student-name  = 'JOHN'.
APPEND gwa_student TO it.                                                                                       

gwa_student-id    = 2.
gwa_student-name  = 'JIM'.
APPEND gwa_student TO it.

gwa_student-id    = 3.
gwa_student-name  = 'JACK'.

APPEND gwa_student TO it.

Usually internal tables are used to hold data from database tables temporarily for displaying on the screen or further processing. To fill the internal table with database values, we can use SELECT statement to read the records from the database one by one, place it in the work area and then APPEND the values in the work area to internal table.
Example:
DATA: gwa_employee TYPE zemployee,
      gt_employee  TYPE TABLE OF zemployee.

SELECT * FROM zemployee INTO gwa_employee.
  APPEND gwa_employee TO gt_employee.
ENDSELECT.

After ENDSELECT the internal table GT_EMPLOYEE contains all the records that are present in table ZEMPLOYEE.
Using INTO TABLE addition to SELECT statement we can also read multiple records directly into the internal table directly. No work area used in this case. This select statement will not work in loop, so no ENDSELECT is required.
Example:
SELECT * FROM zemployee INTO TABLE gt_employee.