Classical Report of Multiple Tables


After creating a classic report for single table it's time to create a report which will contain multiple tables.
I’m created a report which contains multiple tables like EKPO and EKKO. The EKPO table contain Purchasing Document Item details and EKKO tables Purchasing Document Header details.

Coding of the classical report:-


REPORT ZPURCHASING_DETAILS.

*-------Declaring database tables---------------------*
tables: EKPO , EKKO.

*-----Declaring work areas & internal tables----------*
types: begin of itab,
      ebeln type ekpo-ebeln,
      ebelp type ekpo-ebelp,
      matnr type ekpo-matnr,
      bukrs type ekko-bukrs,
      ernam type ekko-ernam,
    end of itab.

DATA: it_itab TYPE TABLE OF itab WITH HEADER LINE,
      wa_itab TYPE itab.

data: Prog_name TYPE sy-repid, "Program name
      Date TYPE sy-datum, "Current date
      Time TYPE sy-uzeit. "Current time

*------Event initialization---------------------------*
INITIALIZATION.
  Prog_name = sy-repid.
  Date      = sy-datum.
  Time      = sy-uzeit.

*-----------Declaring selection screen with select option for input----*

selection-screen begin of block block1 with frame title text-001.
select-options: EBELN FOR EKPO-EBELN.
parameter       p_bukrs like ekpo-bukrs.
selection-screen end of block block1.

*-----Event start of selection-----------------------------------------*
START-OF-SELECTION.
  PERFORM get_data.

*---Event end of selection---------------------------------------------*
END-OF-SELECTION.
  PERFORM display.
  PERFORM get_output.


*---Event top of page--------------------------------------------------*
TOP-OF-PAGE.
  PERFORM top_of_page.

*&---------------------------------------------------------------------*
*&      Form  GET_TAB
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form get_data .
  IF EBELN IS NOT INITIAL.
   SELECT
    ekpo~EBELN
    ekpo~ebelp
    ekpo~matnr
    ekko~bukrs
    ekko~ernam
     INTO TABLE it_itab from ekpo
     inner join ekko on ekpo~EBELN = ekko~EBELN
      where ekpo~EBELN in EBELN and
            ekko~bukrs = p_bukrs.

    IF sy-subrc = 0.
      SORT it_itab BY EBELN.
    ELSE.
      MESSAGE 'Document Number doesn''t exist' TYPE 'I'.
    ENDIF.
  ENDIF.


endform.
*&---------------------------------------------------------------------*
*&      Form  GET_OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form get_output .

  LOOP AT IT_ITAB INTO WA_ITAB.
      WRITE:/ WA_ITAB-EBELN, 18 sy-vline,
              WA_ITAB-EBELP, 38 sy-vline,
              WA_ITAB-MATNR, 56 sy-vline,
              WA_ITAB-BUKRS, 75 sy-vline,
              WA_ITAB-ERNAM.

    ENDLOOP.

endform.
*&---------------------------------------------------------------------*
*&      Form  DISPLAY
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form display .

write: 'Document Number' COLOR ,
    20 'Item Numbe' COLOR ,
    40 'Material' COLOR ,
    57 'Company Code' COLOR ,
    78 'Name of Person' COLOR 5.
uline.

endform.
*&---------------------------------------------------------------------*
*&      Form  TOP_OF_PAGE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form top_of_page .
write: / Prog_name,
       / Date DD/MM/YYYY,
       / Time .
ULINE.
endform.

Selection Screen
























OUTPUT SCREEN




ABAP Classical Report with Programming Example


Report is a presentation of data in an organized structure. Many database management systems include report writer that enables you to design and generate reports. SAP applications support report
creation.

SAP ABAP Classical Reports are the most basic ABAP reports that contain both selection screen and an output screen. Classical reports are executed based on events, and not executed on a line-by-line basic. In simple language “It’s nothing but to display the entire information in single list”.



Events in classical reports : -

1. Initialization
2. At selection-screen
3. At selection-screen on
4. Start-of-selection
5. End-of-selection
6. Top-of-page
7. End-of-page

Initialization: -
It’s an event which is triggered before displaying the selection-screen.
USE: - it’s used to provide the default values to the selection-screen.

At Selection-Screen: -
It’s an event which is triggered after provide the input to the screen & before leaving the selection-screen.
USE: - This is used to validate the given input.

At Selection-Screen On: -
It’s an event which is triggered at the selection-screen based on particular input field.
USE: - This is used to validate the particular input field.
SYNTAX: - AT SELECTION-SCREEN ON  <parameter name>. “Validate an input parameter

Start-Of-Selection: -
It’s an event which is triggered after leaving the selection-screen & before display the output.
USE: - This is used to fetch the data from data base & place into internal table.

End-Of-Selection: -
It’s an event which is triggered after completion of the logic.
USE: - This is used to display the output.

Top-Of-Page: -
It’s an event which is triggered of the top of the each page.
USE: - It’s used to display the header information.

End-of-page: -
It’s an event which is triggered of the end of each page.
USE: - It’s used to display the footer information.

Some more events in classical report: -
1. At selection-screen output
2. At selection-screen on value-request
3. At selection-screen on help-request

At Selection-Screen Output: -
It’s an event which is triggered at the selection-screen based on the user action.
USE: - This is used to modify the selection-screen.

At Selection-Screen On Value-Request: -
It’s an event which is triggered at the time of click on F4 button.
USE: - This is used to provide the list of possible values to the input variables.
SYNTAX:-  At selection-screen on value-request for <parameter name>.  “input search help for a parameters

At Selection-Screen On Help-Request: -
It’s an event which is triggered at the time of click on F1 button.
USE: - This is used to provide the help document to the input variable
At selection-screen output is the first triggering event in the selection-screen.
SYNTAX:- At Selection-Screen On Help-Request For <parameter name>. “Input (F1) help for a input parameters


Process flow of events: -











SYNTAX EXAMPLE OF CLASSICAL REPORT

*&---------------------------------------------------------------------*
*&
*& Report:-  ZSAN_CUSTOMER
*& Author:-  Sangeeta yadav
*&
*&---------------------------------------------------------------------*

REPORT  ZSAN_CUSTOMER.
tables: kna1.

data: begin of itab occurs 0,
             ort01 type kna1-ort01,
             land1 type kna1-land1,
             telfx type kna1-telfx,
             name1 type kna1-name1,
             regio type kna1-regio,
             pstlz type kna1-pstlz,
             telf1 type kna1-telf1,
             stras type kna1-stras,
             end of itab.


selection-screen begin of block block1 with frame title text-001.
select-options: s_name1 for kna1-name1.
select-options: s_stras for kna1-stras.
select-options: s_ort01 for kna1-ort01.
select-options: s_regio for kna1-regio.

selection-screen end of block block1.


START-OF-SELECTION.
  SELECT
  kna1~ort01
  kna1~land1
  kna1~telfx
  kna1~name1
  kna1~regio
  kna1~pstlz
  kna1~telf1
  kna1~stras
  INTO CORRESPONDING FIELDS OF TABLE itab
  FROM kna1 where ort01 in s_ort01.


WRITE: 'Name' COLOR 35 'Add' COLOR 53 'City' COLOR 65 'State' COLOR ,
73 'Country' COLOR ,81'Pin' COLOR ,92'phone' COLOR 100'Fax' COLOR 1.
uline.

loop at itab.
write : / itab-name1,33 sy-vline, 35 itab-stras, 50 sy-vline,  53 itab-ort01, 62  sy-vline,
 65 itab-regio, 70 sy-vline, 73 itab-land1, 77 sy-vline, 81 itab-pstlz, 87 sy-vline, 95 itab-telf1,
97 sy-vline,  100 itab-telfx.
endloop.


SELECTION SCREEN














OUTPUT SCREEN





THANKS.


TABLES, DATA ELEMENT & DOMAIN


Tables
Tables can be defined independently of the database in the ABAP Dictionary. The fields of the
table are defined with their (database-independent) data types and lengths.

           When the table is activated, a physical table definition is created in the database for the table
definition stored in the ABAP Dictionary. The table definition is translated from the ABAP
Dictionary to a definition of the particular database.
Table Fields
You must define the following for a table field in the ABAP Dictionary:
1 Field name: The field name can have a maximum of 16 places and may contain letters,
digits and underscores. The field name must begin with a letter.
2 Key flag: determines whether the field should belong to the table key.
3 Field type: data type of the field in the ABAP Dictionary.
4 Field length: number of valid places in the field.
5 Decimal places: number of places after the decimal point, specifying numeric data
types.
6 Short text: short text describing the meaning of the field.

Technical requirement to create the table: -
1. Name of the table starts with ‘y’ or ‘z’ because a x reserved for SAP.
2. Provide list of fields, data types and lengths.
3. Provide the delivery class.
4. Provide the Technical settings.

Delivery class: - It defines the owner of the table as well as it controls the transport of the data from one table to another table.

Technical setting is nothing but combination of DATA CLASS & SIZE OF THE CATEGORY.

Data class: - Data class defines the physical area of the database in where our table is logically stored. Some of the important data classes are:-

APPL 0:- Master data class
APPL 1:-Transaction data class
APPL 2:- Organization data class 

Master data class: - Master data class is the data, which data we can access frequently as well as update rarely.
Ex: - customer master data, employee master data

Transaction data: - It’s the data, which data we can access frequently as well as updated frequently.
Ex: - Sales order data, purchase order data

Technical data is dependent data. 

Organizational data: - It’s the data, which data we can access frequently & updated rarely. Organizational data is created at the time system configures.
Ex: - Company data, branches data

Size category: - The size category defines the expected space required for the table in the database. You can choose a size category from 0 to 4 for your table. Each category is assigned a certain fixed
memory size in the database, which depends on the database system used.

Steps to create the table: -

1. In the initial screen of the ABAP Dictionary, select object class Database table, enter the
table name and choose Create.
The maintenance screen for the table is displayed.
2. Enter an explanatory short text in the field Short text.
You can for example find the table at a later time using this short text.
3. On the Attributes tab page, enter the delivery class of the table.
4. On the Fields tab page, enter the table fields. Perform the following steps for each table field:
Enter a name for the table field in the column Fields.
Select the Key column if the field should be part of the table key.
Enter the name of a data element in field Field type.
5. Maintain the technical settings for the table. The corresponding maintenance
screen is displayed with
 Goto _ Technical settings.
6. Save the table.
A dialog box appears in which you have to assign the table a development class.
7. ACTIVATE your table Ctrl + F3.

As Example below
Field       Key       Data type      Length       Short Description
Eid                        CHAR            10                Employee ID
Ename                  CHAR             25                Name of the employee

Eadd                     CHAR             35                Address of employee 


Steps to provide the data to the table directly: -
In the menu bar click on utilities - table contents - provide the data. Click on save. Repeat same steps for all employees.

Steps to display the data from table: -
In the menu bar click on utilities - Table contents display. Click on execute.


Data Elements & Domain
Data element is the collection of domain with short description or
A data element describes either an elementary type or a reference type.

An elementary type is defined by the built-in data type, length and possibly the number of
decimal places. These type attributes can either be defined directly in the data element or copied
from a domain.

Domain
Domain is the collection of data types & lengths.
A domain is assigned to a data element. All table fields or
structure components that use this data element then have the value range defined by the
domain. The relationship between the field or component and the domain is thus defined by the
data element of the field or component.

Steps to create the domain: -

1. Select object type Domains in the initial screen of the ABAP Dictionary, enter the name of the
domain and choose Create.
The maintenance screen for domains appears.
2. Enter an explanatory short text in the field Short text.
You can for example find the domain at a later time using this short text.
3. On the Data type tab page, choose the data type, number of places (valid
positions without editing characters such as comma or period) and number of decimal places
(only needed for data types DEC, FLTP, QUAN and CURR).
Note that some data types have a fixed length. For example, the data type CLNT (client)
always has 3 places. If you enter an invalid number of places for such a data type, the
system corrects this automatically after issuing a warning.
4. If only certain input values are valid for the domain, you can enter them in the Value range
tab page as fixed values.
You can also define a value table as proposed value for foreign key checks
on this tab page.
5. Save the domain.
You are asked to assign the domain a development class.
6. Choose ACTIVATE or Ctrl + F3.


Steps to create the data element: - 

1. Select the radio button data type enter the data element name and choose Create.
2. Select the data element and enter.
The maintenance screen for data elements appears.
3. Enter an explanatory short text in the field Short text.
The short text appears as title in the F1 help for all the screen fields referring to this data
element.
4. On the Definition tab page, define the data type, number of places and
possibly the number of decimal places of the data element. You can define these
attributes by specifying a domain or by direct type entry.
If the data element should have the type attributes of a domain, you only have to select
Domain and enter the domain name in the corresponding field. You can also define a
new domain and create it by navigating to the domain maintenance screen by double-clicking
(see Creating Domains).
If you want to enter the type attributes directly, select Direct type entry. Entries are now
possible in the fields Data type, Number of places and Decimal places.
If the data element should be a reference to a class or an interface, select Reference
type. Enter the name of the class or interface in the Reference field. You can also enter
OBJECT or DATA if the data element should implement a generic reference to objects or
data objects.
5. On the Field label tab page you can (optionally) maintain text information
(short, medium, and long field labels and the title) for the data element.
You can use this text information in input templates to represent fields that refer to this
data element.
6. Save the data element.
You are asked to assign the data element a development class.
7. Choose ACTIVATE or Ctrl + F3.

DDIC OVERVIEW IN ABAP

        DATA DICTIONARY

Data dictionary is the central source of the database management system. The main functionality of the DDIC is to create or alter the tables.

Purpose
Data definitions (metadata) are created and managed in the ABAP Dictionary. The ABAP
Dictionary permits a central description of all the data used in the system without redundancies.
New or modified information is automatically provided for all the system components. This
ensures data integrity, data consistency and data security.
You can create the corresponding objects (tables or views) in the underlying relational database
using these data definitions. The ABAP Dictionary therefore describes the logical structure of the
objects used in application development and shows how they are mapped to the underlying
relational database in tables or views.
The ABAP Dictionary also provides standard functions for editing fields on the screen, for
example for assigning a screen field an input help.

What Information is Stored in the ABAP Dictionary?
The most important object types in the ABAP Dictionary are tables, views, types, domains,
search helps and lock objects.

Tables are defined in the ABAP Dictionary independently of the database. A table
having the same structure is then created from this table definition in the underlying database.

Views  are logical views on more than one table. The structure of the view is defined in
the ABAP Dictionary. A view on the database can then be created from this structure.

Types  are used in ABAP program. The structure of a type can be defined globally in
ABAP programs. Changes to a type automatically take effect in all the programs using the type.

Lock objects  are used to synchronize access to the same data by more than one
user. Function modules that can be used in application programs are generated from the
definition of a lock object in the ABAP Dictionary.

Different fields having the same technical type can be combined in domains. A
domain defines the value range of all table fields and structure components that refer to this
domain.

The ABAP Dictionary also contains the information displayed with the F1 and F4 help for a field
in an input template. The documentation about the field is created for a data element that describes
the meaning of the contents of a table field. The list of possible input values that appears for the
 input help is created by a foreign key  or a search help.