Wednesday 27 December 2017

Difference Between Select Single and Select upto 1 row

A lot of people use the SELECT SINGLE statement to check for the existence of a value in a database.
Other people prefer to use the 'UP TO 1 ROWS' variant of the SELECT statement.

SELECT  SINGLE: 
Select single statement only selects the first record of any series of records from a database table.
That means this statement can read a single record from a database table that fulfils the 'WHERE' clause.
If this results in multiple records then only the first one will be returned and therefore may not be unique.

In below example we are fetching records of material, plant, storage location and unrestricted(quantity) from table MARD where material no is 612965 .
The database contains only 4 items for this Material no.



Example.

REPORT  ZTEST9 NO STANDARD PAGE HEADING
        LINE-SIZE 120.

TABLES: MARD.

TYPES: BEGIN OF TY_MARD,
        MATNR LIKE MARD-MATNR,
        WERKS LIKE MARD-WERKS,
        LGORT LIKE MARD-LGORT,
        LABST LIKE MARD-LABST,
      END OF TY_MARD.

DATA : WA_MARD TYPE TY_MARD.

START-OF-SELECTION.
  PERFORM GET_DATA.

*----------------------------------------------------------------------*
*       TOP-OF-PAGE
*----------------------------------------------------------------------*
TOP-OF-PAGE.

  PERFORM BUILD_PAGE_HEADER.


END-OF-SELECTION.
  PERFORM SHOW_LIST.


*&---------------------------------------------------------------------*
*&      Form  GET_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM GET_DATA.
  SELECT SINGLE MATNR
        WERKS
        LGORT
        LABST FROM MARD INTO WA_MARD WHERE MATNR = '000000000000612965'.
ENDFORM.                    " GET_DATA
*&---------------------------------------------------------------------*
*&      Form  BUILD_PAGE_HEADER
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM BUILD_PAGE_HEADER .
  FORMAT INTENSIFIED ON COLOR COL_HEADING.
  ULINE AT (105).
  WRITE:SY-VLINE,
          'Material No',
       20 SY-VLINE,
          'Plant',
       50 SY-VLINE,
          'Str.Loc',
       80 SY-VLINE,
          'Qty',
      105 SY-VLINE.
  ULINE AT (105).
  FORMAT RESET.
ENDFORM.                    " BUILD_PAGE_HEADER
*&---------------------------------------------------------------------*
*&      Form  SHOW_LIST
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM SHOW_LIST .

    WRITE:/ SY-VLINE,
            WA_MARD-MATNR,
         20 SY-VLINE,
           WA_MARD-WERKS,
         50 SY-VLINE,
            WA_MARD-LGORT,
         80 SY-VLINE,
            WA_MARD-LABST,
        105 SY-VLINE.
  ULINE AT (105).


ENDFORM.                    " SHOW_LIST

output

SELECT UP TO 1 ROWS:
The 'SELECT -- UP TO 1 ROWS' statement is selects all of the relevant records that are defined by the WHERE clause,
applies any aggregate, ordering or grouping functions to them and then returns the first record of the result set.

example.
here i write same code for select up to 1 rows with order by .

REPORT  ZTEST9 NO STANDARD PAGE HEADING
        LINE-SIZE 120.

TABLES: MARD.

TYPES: BEGIN OF TY_MARD,
        MATNR LIKE MARD-MATNR,
        WERKS LIKE MARD-WERKS,
        LGORT LIKE MARD-LGORT,
        LABST LIKE MARD-LABST,
      END OF TY_MARD.

DATA : WA_MARD TYPE TY_MARD.

START-OF-SELECTION.
  PERFORM GET_DATA.

*----------------------------------------------------------------------*
*       TOP-OF-PAGE
*----------------------------------------------------------------------*
TOP-OF-PAGE.

  PERFORM BUILD_PAGE_HEADER.


END-OF-SELECTION.
  PERFORM SHOW_LIST.


*&---------------------------------------------------------------------*
*&      Form  GET_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM GET_DATA.
  SELECT MATNR
                 WERKS
                 LGORT
                 LABST UP TO 1 ROWS FROM MARD INTO WA_MARD
                                   WHERE MATNR = '000000000000612965'
                                  ORDER BY WERKS DESCENDING.

   ENDSELECT.
ENDFORM.                    " GET_DATA
*&---------------------------------------------------------------------*
*&      Form  BUILD_PAGE_HEADER
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM BUILD_PAGE_HEADER .
  FORMAT INTENSIFIED ON COLOR COL_HEADING.
  ULINE AT (105).
  WRITE:SY-VLINE,
          'Material No',
       20 SY-VLINE,
          'Plant',
       50 SY-VLINE,
          'Str.Loc',
       80 SY-VLINE,
          'Qty',
      105 SY-VLINE.
  ULINE AT (105).
  FORMAT RESET.
ENDFORM.                    " BUILD_PAGE_HEADER
*&---------------------------------------------------------------------*
*&      Form  SHOW_LIST
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM SHOW_LIST .

    WRITE:/ SY-VLINE,
            WA_MARD-MATNR,
         20 SY-VLINE,
           WA_MARD-WERKS,
         50 SY-VLINE,
            WA_MARD-LGORT,
         80 SY-VLINE,
            WA_MARD-LABST,
        105 SY-VLINE.
  ULINE AT (105).


ENDFORM.                    " SHOW_LIST

output



Friday 22 December 2017

How to Work With Check, Countinue, Exit, Stop and Return in SAP ABAP Program

1. Check Statement:
   Check Statement in ABAP is used to terminates a loop or Processing block based on a condition.
If the condition in the CHECK statement is false then all the remaining statements in the statement block after the CHECK statement are ignored, and the next loop pass starts.

Example1 :

DATA : VAR1 TYPE I VALUE 0.

WHILE  VAR1 < 5.

  VAR1 = VAR1 + 1.

  CHECK  VAR1 NE 2.

  WRITE / VAR1.

ENDWHILE.

output :
         1
         3
         4
         5

here is another example of check statement with subroutines.

Example2:
DATA : VAR1 TYPE I,
       VAR2 TYPE I,
       RESULT TYPE P DECIMALS 2.

VAR1 = 20. VAR2 = 4.
PERFORM DIVISION_RESULT USING VAR1 VAR2 CHANGING RESULT.
*&---------------------------------------------------------------------*
*&      Form  DIVISION_RESULT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_VAR1    text
*      -->P_VAR2    text
*      <--P_RESULT  text
*----------------------------------------------------------------------*
FORM DIVISION_RESULT  USING  P_VAR1
                             P_VAR2
                             CHANGING P_RESULT.
  CHECK P_VAR2 NE 0.

  P_RESULT = P_VAR1 / P_VAR2.
  WRITE :/ 'RESULT = ', P_RESULT.
ENDFORM.                    " DIVISION_RESULT

output : RESULT=      5.00


suppose if i assign 0 to var2 then the the output is nothing Because check statemnt check condition and ignored the FORM-ENDFORM Block,
and WIthout check Statement it will give the runtime errror.


2. Countinue Statement : 
CONTINUE statement is used to skip execution of a record inside loop-endloop, do-endo, while-endwhile etc.
CONTINUE terminates the current loop pass, returns the processing to the beginning of the loop and starts the next loop pass,
the execution of the remaining statements in the current processing loop is stopped and the next loop pass is processed.
This keyword will only be used in loops.

Example :
DATA : VAR1 TYPEVALUE 0.

WHILE  VAR1 < 5.

  VAR1 = VAR1 + 1.

  IF VAR1 = 2.
   CONTINUE.
  ENDIF.

  WRITE / VAR1.

ENDWHILE.

output :
         1
         3
         4
         5

3. Exit Statement :
EXIT statement is used to terminate an entire loop or Processing block based on a condition.
The behavior of Exit Statement is depends on where you use it.
If you use Exi  inside IF-ENDIF., it will comes out of the program.
If you use Exit inside LOOP-ENDLOOP., it will come out of loop.
If you use Exit inside FORM-ENDFORM., it will comes out of Subroutines.

Example:
DATA : VAR1 TYPE I VALUE 0.

WHILE  VAR1 < 5.

  VAR1 = VAR1 + 1.

  IF VAR1 = 2.
   EXIT.
  ENDIF.

  WRITE / VAR1.

ENDWHILE.

OUTPUT : 1


4. Stop Statement :
The STOP statement is only to be used in executable program and in the following event blocks:
 AT SELECTION-SCREEN
 START-OF-SELECTION
 GET
If I have two events START-OF-SELECTION and END-OF-SELECTION in executable program, If I use STOP Statement in START-OF-SELECTION, the Statement exit start-of-selection and goes to END-OF-SELECTION.

Example1 :
DATA: IT_MARA TYPE TABLE OF MARA,
      WA_MARA TYPE MARA.

START-OF-SELECTION.
  SELECT MATNR
         MTART
         MATKL FROM MARA INTO CORRESPONDING FIELDS OF TABLE IT_MARA UP TO 50 ROWS.
  STOP.

  LOOP AT IT_MARA INTO WA_MARA.
    WRITE:/ WA_MARA-MATNR, WA_MARA-MTART, WA_MARA-MATKL.
  ENDLOOP.

OUTPUT : here output is nothing Because before Write Statement the Stop statement exit the start-of-selection event Block.

Example2 :
DATA: IT_MARA TYPE TABLE OF MARA,
      WA_MARA TYPE MARA.

START-OF-SELECTION.
  SELECT MATNR
         MTART
         MATKL FROM MARA INTO CORRESPONDING FIELDS OF TABLE IT_MARA UP TO 50 ROWS.
 STOP.
 END-OF-SELECTION.
  LOOP AT IT_MARA INTO WA_MARA.
    WRITE:/ WA_MARA-MATNR, WA_MARA-MTART, WA_MARA-MATKL.
  ENDLOOP.

OUTPUT : here output is Show according to Your Mara Table Because Stop Statement Exit the start-of-selection event Block After Fatching the data, and goes to END-OF-SELECTION Event block Where We USe
Write Statement.

5. Return Statement :
The Return statement ends the current processing block immediately.
The RETURN statement is provided for exiting processing blocks early but correctly.
However, since RETURN behaves differently in GET events than when the event block is exited as usual, you should instead use the REJECT statement there, which has been designed especially for this purpose.

Example1:
DATA: IT_MARA TYPE TABLE OF MARA,
      WA_MARA TYPE MARA.

START-OF-SELECTION.
  SELECT MATNR
         MTART
         MATKL FROM MARA INTO CORRESPONDING FIELDS OF TABLE IT_MARA UP TO 50 ROWS.
  RETURN.

END-OF-SELECTION.
  LOOP AT IT_MARA INTO WA_MARA.
    WRITE:/ WA_MARA-MATNR, WA_MARA-MTART, WA_MARA-MATKL.
  ENDLOOP.
OUTPUT : here output is nothing.

Example2:
DATA: IT_MARA TYPE TABLE OF MARA,
      WA_MARA TYPE MARA.

START-OF-SELECTION.
  SELECT MATNR
         MTART
         MATKL FROM MARA  INTO CORRESPONDING FIELDS OF TABLE IT_MARA UP TO 50 ROWS.

END-OF-SELECTION.
  LOOP AT IT_MARA INTO WA_MARA.
    IF WA_MARA-MTART = 'FERT'.
    RETURN.
    ENDIF.
    WRITE:/ WA_MARA-MATNR, WA_MARA-MTART, WA_MARA-MATKL.
  ENDLOOP.
OUTPUT : here output is Show according to Your Mara Table and The Return statement ends the current processing block immediately when Condition is True.

Tuesday 19 December 2017

Types of pass value with Subroutines & How To Use Subroutines In SAP ABAP Program.

Introduction :   
A subroutine is a reusable section of code.
It is a modularization unit within the program where a function is encapsulated in the form of source code.
Subroutines are used to modularize the program.
Generally Subroutines are called by using PERFORM keyword and defined within FORM and ENDFORM block.
here are three ways to pass the values with Subroutines.

1. pass by value:
In this type, the actual and formal parameters will be referring to separate memory.
The formal parameter is changed, the actual parameter will not be changed.
The parameters which are passed in the perform call are known as actual parameters or actual arguments.
The parameters which are received by the called Form & endform  are known as formal parameters or formal arguments.
Example is shown below:

example1 : pass by value : using    - using value().

output


example2 : pass by value : changing - using value().

                                                             
                                                                 output

2. pass by reference:
In this type, the actual and formal parameters are referred to the same memory.
If the formal parameter is changed, the actual parameter is also changed.

example1 : pass by reference : using - using.



output


example2 : pass by reference : using - changing.


output



3. pass by value and return:
In this type, the actual and formal parameters will be referring to separate memories.
If the formal parameter is changed, the actual parameter is also changed after executing the FORM...ENDFORM.

example1 : pass by value and return : using    - changing value().


output



example2 : pass by value and return : changing - changing value().


output


you can use subroutines according to your requirements.
this is a basic approach .

Saturday 16 December 2017

difference between type and like in sap abap program ?


when you take reference of any variable which is defined Using TYPES or elementry data type  just like ( I , C ,D ,T etc) then we use type.

We use like to take refrence of those Object which occupy memory.

Example:

Types: var1 type C.

data: var2 type var1. ( type is used because var1 is defined with TYPES and it

does not occupy any memory spce)

data: var3 like var2. ( like is used here because var2 is defined with DATA

so it does occupy space in memory ).

data: w_matnr like marc-matnr.  ( like is used here because marc-matnr is stored in memory)

and you Can Say like is  used for database table field  and dataelement.

Friday 15 December 2017

Types Of Control Break Statements in SAP ABAP ?

Control break statements are like events inside the loop.

There are 5 control break statements in ABAP. These are used within loop.
The control break ON CHANGE OF / ENDON, can be used in any loop, It can also be used in WHILE ... ENDWHILE.

There are Five control break statements :
At First / End At
At Last / end At
At New / End At
At End Of / End At
On Change Of / EndOn

1. At First / End At 
At First Will trigger at the first run of the loop.
it means At Firs triggers at the first loop iteration
The main purpose of this control break is to write some header information.
We can write some header info by using AT FIRST statement

2. At Last / end At
At Last triggers at the last loop iteration.
it means At Last will trigger at the last run of the loop.
The main purpose of this control break is to write some footer information.
We can write some footer info by using AT LAST statement.

3. At New / End At 
At New is one of a control break statements.
It works inside the LOOP – ENDLOOP.
When we use At new for a field, it will trigger whenever there is any change of fields’ data.
This statement triggers at the new occurrence of that value.

4. At End Of / End At
At End OF statement always triggers when there is any change of fields’ data.
This statement triggers at the last occurrence of that value.

5. On Change Of / EndOn
On change of it triggers only when there is any change in the particular field.
On change of can be used outside the loop too.
it actually works like AT NEW statement.
If there is any change of the value of the mentioned field then ON CHANGE OF will trigger.



Thursday 14 December 2017

What are the Events in ABAP Report Programming ?

SAP ABAP is an event driven programming language, ABAP programs executed based on events not line-by-line.

But There is no mandatory event in a report program.
Events are actually used to organize the statements and control the flow of the program.
If the program contains no explicitly defined event blocks, all the statements in the program form the entire event block START-OF-SELECTION.
ABAP runtime environment automatically introduces a START-OF-SELECTION at the first execution line.
Below are some of the events available within ABAP programming.

1. Load-of-praogram:
This event is used to load program into memory for execution and this is the first event in execution sequence.
The purpose of load of program is to load the program into system memory so that the program can be executed.
The event Load-of-praogram is triggered each time when a program is called.

2. Initialization:
This event is used to initialize variables, screen default values and other default actions.
But before these are displayed to the user.
So you can use it to initialize input fields of the selection screen or change the default values of these before the user gets to enter data into them.
And we can Also USe for Refresh Internal table and Clear work Area before using them.

3. At Selection-Screen output:
By using this event we can manipulate dynamic selection-screen changes.
This is triggered when the selection screen is loaded in memory before being displayed.
We can use it to modify selection screen, for example (hide & unhide )parameter, (enable & disable ) input parameter.
For Example ->
LOOP AT SCREEN.
  IF SCREEN-name = 'S_FIELd'.
    SCREEN-input = '0'.
    MODIFY SCREEN.
  ENDIF.
ENDLOOP.

4. At Selection-Screen:
This event is used to validate multiple input fields.
The event AT SELECTION-SCREEN get trigger while the selection screen is being processed.

Following are the AT SELECTION-SCREEN events-

       1. AT SELECTION-SCREEN ON 'field' 
       This event is used to validate a single selection-screen input parameter.
       Syntax: AT SELECTION-SCREEN ON <parameter name>. "Validate a input parameter

       2. AT SELECTION-SCREEN ON VALUE-REQUEST for 'Field' 
       This event is used to provide value help ( field help ) for a input field.
       Syntax: AT SELECTION-SCREEN ON VALUE REQUEST FOR <parameter name>. "(i.e.           When press F4)

       3. AT SELECTION-SCREEN ON HELP-REQUEST for 'field'
       By using this event we can provide F1 help for a input field.
       Syntax: AT SELECTION-SCREEN ON HELP REQUEST FOR <parameter name>. "(i.e. When          press F1)

5. Start-of-Selection:
This is default event which is used to write actual business logic.
This event is called when If the user executes the program either by pressing the execute button or F8 this is the first event triggered after all screen selection processing has been completed.

6. Top-of-Page:
TOP-OF-PAGE is used for page headers on the basic list only.
This event prints constant heading for all pages.
This is called when a new page is started with an ABAP list and is used to display a header for the list.

7. End-of-Page:
The END-OF-PAGE event is used for page footers.
Before using this event, we need to reserve some lines for displaying footer.
Example: REPORT YTESTPROGRAM LINE-COUNT 38(5). " Here we reserve 5 lines for footer

8. End-of-Selection:
We can use this event just to state that start-of-selection is ended, this event is used with logical databases, logical databases are in HR ABAP only.
In normal ABAP we don`t have much importance .
If your report is linked to a logical database this event is called after the logical database has completely finished its work.
Otherwise this event is trigged after the START-OF-SELECTION event so you would generally use it to processes the data retrieved in that event.

The above events are available under classical report and interactive reports, there will be more events in interactive reports.

1.AT LINE-SELECTION:
This event will trigger whenever the user double click on any list line.

2.TOP-OF-PAGE DURING LINE-SELECTION:
This event is used to write something on top of every page of individual secondary lists.

3.At pF: 
This event will trigger whenever user clicks on any function buttons.

3.AT USER-COMMAND: 
This event will trigger whenever user clicks on any custom buttons of the GUI.

How to Use FIELD SYMBOLS in ABAP PROGRAM


INTRODUCTION : A field symbol (in SAP) is a mechanism in which applications are created with flexibility.
 As placeholders that do not reserve physical data field space but direct and point to its contents,Field symbols are similar to dereferenced pointers in C (that is, pointers to which the content operator * is applied).
Internal table processing is essential part of any ABAP program.
Generally, we use the explicit work area to process the internal table like append & modifying records.
We can reduce the time and improve the performance of the program by using the field-symbols.

In programs, field symbols are identified by angle brackets, which are part of the field symbol syntax.
Field symbols may be created with or without type specifications.
If the type is not declared, the field symbol inherits all technical characteristics of the assigned field.
If the type is specified, the field symbol and data object type compatibility is checked in the ASSIGN statement.

EXAMPLE :


OUTPUT:

Assigning Components of Structures to a Field Symbol:
SYNTAX:
ASSIGN COMPONENT compo OF STRUCTURE struct TO <fs>.

EXAMPLE :

OUTPUT:



Advantages of Field Symbols :


When you read from an internal table, there are no overheads for copying the table line to the work area.
When you change an internal table with the MODIFY statement, you must first fill a work area with values,
and then assign them to the internal table. If you work with field symbols instead, you do not have this overhead.

This can improve performance if you have large or complex internal tables. It also makes it easier to process nested internal tables.




Tuesday 12 December 2017

Copy an Internal Table into another Internal Table


Addition of rows can be done either by using append or insert command.
You can copy one or more rows of an internal table into another internal table by using the statement INSERT LINES OF or APPEND LINES OF.

APPEND is used to add entries to end of the internal table. Append will not work for Hashed tables.
example : APPEND WA_KNA1 TO IT_KNA1.

APPEND LINES OF can be used to Copies the contents of several rows of an internal table to another internal table Which is having same structure.

example : Append lines of IT_KNA1 TO IT2_KNA1.

INSERT is used to add entries to internal table in the index(row Number) specified.

example: INSERT WA_KNA1 INTO IT_KNA1 INDEX 8.

INSERT LINES OF can be used to copy another internal table contents having same structure to the internal table.

example:  INSERT LINES OF IT_KNA1 INTO TABLE IT2_KNA1 INDEX 8.



Types of internal tables in SAP ABAP ?

Internal table is a data object in ABAP that exists only at run time of a program.

Internal table has three parts
1.       Rows are the line type of internal table.
2.       Columns are the fields of internal table.
3.       The most important part of an internal table is work area  . Work area is basically the line type of an internal table.
         it has the same structure of the rows of internal table. Work area contains the same fields of same type of the rows.

There are three types of internal tables in SAP ABAP programming, an ABAPER  must know and understand before using them in ABAP programs.

1. Standard Internal Tables
2. Sorted Internal Tables
3. Hashed Internal Tables


1. Standard Internal Tables-> These are default internal tables. Standard tables have a linear index. You can access them using either the index or the key.
   To read a record we use either key or index operation. If we want to access the internal table by the key then the key must be defined otherwise default key would be considered.
   To search for a record, we can use either linear search or binary search. We can use insert and append to add records.

TYPES : BEGIN OF TY_MARA,
         MATNR  TYPE MATNR,                                          "Material
         MTART  TYPE MTART,                                          "Material Type
        END OF TY_MARA.

Here we have declared a local structure ty_mara. This is the row of the internal table. It means the table will contain rows which has two field (MATNR & MTART).
We declare the internal table it_mara with this structure. We also can declare with standard structure and customized structure .

The declaration of Standard Internal table is defined as follows :

DATA: IT_MARA TYPE STANDARD TABLE OF TY_MARA WITH NON-UNIQUE KEY MATNR.

                               OR

DATA: IT_MARA TYPE TABLE OF TY_MARA WITH NON-UNIQUE KEY MATNR.

If we don’t enter “Standard” then by default the system takes it as a standard internal table. We can enter data into a standard internal table by using the APPEND statement.
Append always enters data at the last row of the table.
The key of a standard table is always non-unique, and you may not include any specification for the uniqueness in the table definition.
SO, we can Defined Standard internal Table as .

DATA: IT_MARA TYPE STANDARD TABLE OF TY_MARA .
                             
                                      OR

DATA: IT_MARA TYPE TABLE OF TY_MARA.


2. Sorted Internal Tables-> These are a special type of internal tables, where data is already sorted when we insert the record.
   To read a record we use either key or index operation.
   To search for a record, we use binary search as data is already sorted.
   it's another kind of index table which has unique & non unique key. It also can be accessed via index or key.
   We only use insert, not append we fill the table using the (INSERT) statement, according to the sort sequence defined in the table key.
 
TYPES : BEGIN OF TY_KNA1,
         KUNNR  TYPE KUNNR,                                           "Customer Number
         NAME1  TYPE NAME1_GP,                                        "Name
        END OF TY_KNA1.

Here we have declared a local structure ty_kna1. This is the row of the internal table. It means the table will contain rows which has two field (KUNNR & NAME1).

The declaration of Sorted Internal table is defined as follows :

DATA: IT_KNA1 TYPE SORTED TABLE OF TY_KNA1 WITH UNIQUE KEY KUNNR.

DATA: IT_KNA1 TYPE SORTED TABLE OF TY_KNA1 WITH NON-UNIQUE KEY KUNNR.

Unique key means the KUNNR will must be unique. If same Customer number is inserted then a run time error will happen.
However we can declare the sorted table with non unique key also. In this case same Customer number can be entered but it will be sorted after entering the number.
Here the sorted table behaves like a sorted standard table. We use INSERT statement to enter any records to the sorted table.

3. Hashed Internal Tables-> These are used with logical databases  with all fields and all records.
   Here the index operation is not allowed, we only use key operation.
   To search for a record we use hashed algorithm.
   Here the declaration of internal table  key is must and also the key must be unique. Hence no duplicate entry will be in the hashed table. We can access records only by the key.
   You cannot access hashed tables using the index.
   Similar to sorted tables data can be inserted here by INSERT statement. Hashed tables are used when the internal table contains huge amount of data.

TYPES : BEGIN OF TY_kNA1,
         KUNNR  TYPE KUNNR,                                           "Customer Number
         NAME1  TYPE NAME1_GP,                                        "Name
        END OF TY_KNA1.

The declaration of Hashed Internal table is defined as follows :

DATA: IT_KNA1 TYPE HASHED TABLE OF TY_KNA1 WITH UNIQUE KEY KUNNR.

Internal tables are not DB tables. Standard and Sorted tables in combined are basically called as Index tables and there nothing else.
                                     
                                         ANY TABLE 
                                               | 
                    ------------------------------------ 
                    |                                              | 
             Index Tables                         Hashed Table 
                     |           
    ------------------------------------  
    |                                               | 
Standard Table                      Sorted Table

In this post we use some basics Events  and Control Break Statements for Generating Classical Report Based On single Table. If You want so...