Sunday 15 May 2011

Introduction to Reporting


ABAP is a programming language created and used by SAP for the development of application programs, including: Reports, Module Pool Programming, Interfaces, Data conversions, User Exits & BADI.
All of R/3s applications and even parts of its basis system were developed in ABAP. ABAP is an event-driven programming language.  User actions and system events control the execution of an application. ABAP used to be called ABAP/4.  The “4” stood for “fourth generation language”.
ABAP Workbench
The ABAP Workbench is used by SAP for the development of standard and custom application software. The ABAP Workbench is also used to create dictionary objects. It consists of the following components:
  • ABAP Editor is used to maintain programs.
  • ABAP Dictionary is used to maintain Dictionary objects.
  • Repository Browser is used to display a hierarchical structure of the components in a package.
  • Menu Painter is used to develop graphical user interfaces, including menubars and toolbars.
  • Screen Painter is used to maintain screen components for an online program.
  • Repository Information System contains information about development and runtime objects, such as data models, dictionary types and table structures, programs, and functions.
  • Test and Analysis Tools, such as the Syntax Check and the Debugger.
  • Function Builder, which allows you to create and maintain function groups and function modules.
  • Data Modeler, a tool which supports graphical modeling.
  • Workbench Organizer, which maintains multiple development projects and manages their distribution.
Reporting
Report programs produce lists and can be divided into conventional reports and interactive reports. Conventional reports do not allow interaction by the user; therefore, the basic list contains extensive information that the user must often sort through to find the relevant data.
Interactive reports allow interaction by the user; therefore, the user can produce secondary, detailed lists off of the basic list by choosing the relevant data and requesting more information.

Module Pool Programming
Module pool programming (or online programming) involves the creation of a module pool (a collection of ABAP modules) and one or more screens. The modules are called by the screen processor during program execution.
Batch input processing is used to ensure the safe transfer of data into the SAP system. This process is an automatic, protected data transfer to the SAP system which uses SAP transactions to validate data as it populates the SAP database. ABAP contains statements which conform to CPI-C standards (Common Program Interface - Communications).  These are used for programming communications programs. ABAP can read and write sequential data sets.


ABAP is an event-driven programming language. The general flow of an ABAP program is controlled by events. These events are defined in an ABAP program using event keywords. All statements between event keywords or between an event keyword and a FORM statement form processing blocks.
For clarity of reading code, it is good programming practice to code event processing blocks in the order in which they will be triggered during execution.  However, they do not have to be coded in a sequential order.  Within an ABAP Processing Block, statements are processed sequentially (top to bottom).
Finally, the code in the END-OF-SELECTION processing block is executed.
All ABAP statements that are not written as part of a processing block (after an event keyword) or a FORM-ENDFORM block are automatically part of the Start-of Selection processing block if they are coded above all other event keywords or subroutines.
Following are the system-triggered events which occur during the run time of a report program . These events are presented in the order in which they are processed. These are called run time events.
Run time Event: Initialization
If a report has a selection screen defined (either explicitly or by default through the use of a logical database), the ABAP processor processes the selection screen first.  A programmer can execute another block of code before the selection screen by using the event keyword INITIALIZATION. This processing block can be used to define characteristics of the selection screen. Examples include : setting default values on selection fields, setting a title bar, assigning text to push buttons, etc.
Run time Event: AT SELECTION-SCREEN
AT SELECTION-SCREEN occurs when the user triggers a function code on the selection screen (i.e., by clicking on push-button, hitting a function key, etc.). Checks can be made on selection screen fields and appropriate messages sent back to the user (error, confirmation, warning messages), or the program can be terminated. After the user enters new information, AT SELECTION-SCREEN is triggered again.
Run time Event: START-OF-SELECTION
START-OF-SELECTION is triggered after the selection screen is processed, and before any GET events or any other event processing blocks. If no event keywords are coded in a report program, the report statement automatically starts START-OF-SELECTION processing (it can be explicitly coded, but need not be). All ABAP statements that are not part of a processing block (after an event keyword) or a FORM-ENDFORM block are automatically part of the START-OF-SELECTION processing block if they are coded above all other event keywords or subroutines. The Syntax Check will offer a warning if it detects that a line of code is inaccessible due to being severed from an event processing block.
START-OF-SELECTION can be used to set default values of program-defined variables, or to code WRITE statements to be output to the screen.

Run time Event: GET and GET LATE
GET <table> events can only be used for the basic list in an interactive report. The GET event is triggered each time a row is read from a logical database table. The data for this record is loaded into the table work area. A GET event keyword can only be coded once for any one table in the logical database program.
The GET <table> LATE event, if coded, occurs just before the next row (record) of the table specified in the GET event  is selected from the database.  It also occurs after any other GET or GET LATE events for tables lower in the hierarchy of the logical database program.
GET event processing requires that the logical database be specified as an attribute of the report program (while in the ABAP Editor, use the menu path Go to -> Attributes).

Run time Event: END-OF-SELECTION
END-OF-SELECTION is the last system event to be processed during the runtime of a report program.  It occurs after all logical database records have been read, and before any user-invoked events. END-OF-SELECTION occurs only once.
The other set of events that occur occur while the ABAP processor is processing the output list of a report program are called output events.
Output Event: TOP-OF-PAGE
TOP-OF-PAGE is used for page headers on the basic list only. TOP-OF-PAGE is triggered when the system encounters a WRITE, SKIP, or ULINE statement on the basic list. TOP-OF-PAGE occurs the moment the first line of the first page is written to the screen. NEW-PAGE also invokes the TOP-OF-PAGE event.
TOP-OF-PAGE DURING LINE-SELECTION allows a programmer to display headers for detail lists (other than the basic list).
TOP-OF-PAGE DURING LINE-SELECTION is triggered with a WRITE, SKIP or ULINE statement on a detail list.
Output Event: END-OF-PAGE
The END-OF-PAGE event is used for page footers. This event is triggered when the system encounters insufficient space on the current output page.  The LINE-COUNT statement within the REPORT statement specifies the size of the page area.  If a LINE-COUNT is not explicitly coded, the END-OF-PAGE event block will not be processed.
Proper usage of LINE-COUNT is to include the number of lines per page, as well as how many lines are reserved for the footer.
For example, the following statement will display 50 lines of output, and then 3 lines of footer information.

 REPORT YPROG LINE-COUNT 53(3)
.

There are some events that are invoked by the user when the system is displaying an output list from a report program. These are called "User Events"

User Event: AT PF##
The AT PF## event is triggered by when the system detects a PF## function code. This function code can be assigned to a function key, push-button, or menu item.
Most often, programmers assign a PF## function code to a function key on the keyboard, where ## corresponds to the number of the function key.
To use function keys above 12, (13-24), the user must hold down the shift key on the keyboard.  For example, to initiate AT PF14, the user holds down the shift key and presses F2.

User Event: AT LINE-SELECTION
The event AT LINE-SELECTION is triggered when the user selects a line and invokes the PICK function code. This can occur when the user:
  • Double-clicks on a line
  • Single clicks on a line and presses F2
  • Single clicks on a line and presses a PICK push-button on the list
User Event: AT USER-COMMAND
The AT USER-COMMAND event is triggered when the user invokes any function code except PICK and PF##.
The function code can be up to 20 characters long. This function code can be assigned to a push-button, menu item, or function key on the keyboard.
These user events will be explained in the further chapters in detail as these will be used by the ABAP programmers more frequently.

When the system detects a PF## function code, the “AT PF##” event is triggered (where ## corresponds to the same 2-digit number in the function code). When a report program contains an AT PF## event, the system supplies default assignments of certain function keys to corresponding PF## function codes.
For example, the following function codes are matched with their corresponding function keys : PF05 through PF09 and PF13, PF14, PF16, PF17, PF18, PF19 are matched with function keys F5 through F9 with shift key pressed.
This means that these function codes are preset, ready for you to use with their corresponding AT PF## events.

Here’s a simple example:
START-OF-SELECTION
  WRITE :/ 'Hi'.
AT PF06.
  Write :/ 'User Pressed F6 Key'.
AT PF07.
  Write :/ 'User Pressed F7 Key'.

If you want to write AT PF## events for function keys 13 through 24, the user will have to hold down the shift key on the keyboard. For example, to initiate the AT PF14 event the user must hold down the shift + F2 keys.
AT PF## events for function keys 1 through 12 do not require the user to hold down any additional keys.
The ABAP processor reserves some function keys.  The slide above contains a chart that shows the SAP reserved function keys..  
As a programmer, you are capable of writing code that reacts to virtually all of the function keys.  However some function keys are reserved for ABAP functions. This is done to maintain a certain level of consistency.
Example: F1 will always be used by the end-user to initiate the online help system.
Remember: Event processing blocks end when:
  •   Another event key word is encountered
  •   A subroutine (i.e., a FORM statement) is encountered
  •   The program ends
Creating a new Window:
Example: WINDOW STARTING AT 10 4  ENDING AT 77 12.
The above statement will create a new window starting at 10 4 and will end at 77 12. This statement is used to create new windows to open detail lists. 
Your program can have up to 20 detail lists open at one time.
To maintain the number of additional lists that are created by the user we use the system field SY-LSIND. SY-LSIND contains an index that increments whenever a user event (event which occurs during
 the list display) is triggered. SY-LSIND is incremented before the event processing block is executed.
A detail list is created whenever a WRITE, SKIP, or ULINE statement is encountered in a user event.
If no WRITE, SKIP, or ULINE statement is encountered in a user event (and therefore no detail
   list created), SY-LSIND automatically decrements back to the previous level.

Wednesday 11 May 2011

Demo: working with SD Module (inner joins)

Predefined Tables Related to SALES and Distribution Module(SD)



·        Now We are working on SD Function Module.
·        Business flow of S.D(Sales & Distribution)
Having sales dept, Ware Housing Management Department (WM Dept) & Finance Dept(FICO).

·        In ware housing dept, raw material and finished goods can e stored.

·        Ware Housing dept is to maintain Raw Materials and Finished goods.
·        In SAP, if I say material type is ROH(Raw Material), if I say FERP(finished goods), HALB(semi finished goods



Starting Sales Dept(SD)

Here Business Partner is Customer, business Partner to Sales Dept is customer












·        Sales Dept wants to do business with Customer
·        Sales dept has to maintain customer data in SAP Database.
·        We know that it have 17000 predefined tables
·        From those 17000 tables one tables is to maintain customer tables that is KNA1.
KNA1: Customer Master Data.
o       It is a predefined Table to maintain customer data that is KNA1.
o       In this KNA1 Table, fields are:


      1. KUNNR( primary key)
     Customer Account no
      2. name1                                                              
      Name of customer
      3. ORT01
      City of customer

·        Business partner can place an order to sales department for fineshed goods
·        With reference of order sales dept can create sales order
·        With ref of sales order, sales dept can do ATP(Availability To do Promise) check on Finished goods. here ATP is SAP terminology.















·        Now ATP check OK means Finished Goods(FERT) available in Ware Housing Department.
If ATP CHECK ok then Goods can be issued to the customer.

·        In goods issue, picking, packing, delivery can be maintained.
·        After goods issued, sales dept can give bill and Invoice to the customer for payment. here bill & Invoice are almost are same.















With reference of invoice, In finance Department Account can be created.







·        Based on Account Document, Finance Dept can collect payment from Customer. This is nothing but AR Process. (account rec).























SALES ORDER APPLICATION FORMAT












·        In which table data is stored in KNA1 table
·        In selection screen item entered customer account no
·        Output is from so and so date to so..and so date list of sales order created.
·        Sales order data is available is in VBAK, it is a predefined Table for Sales Order Header details
·        Fields of VBAK ARE
                     
VBAK
     VBELN
      sales order no(primary key)
      ERDAT
       date on which sales order created
     KUNNR
      customer account no(foreign key)

·        In KNA1 table KUNNR is primary key where as in VBAK table it is a foreign key.

Requirements:

·        In selection screen, sales order number, if enter any sales order no, output should be item is having in items, materials having, qty, price also
·        Here VBAP is a predefined table for sales order Item details
·        Fields of VBAP are
VBAP
      POSNR
         item no(primary key)
        MATNR
         material no
      KWMENG
       Quantity(qty
       VBELN
       sales order(foreign key)

Relation between Master Data(VBAK) and Header Data(KNA1):
·        Based on Master Data user can maintain Header data
Example:
             Sales Order can be created based on customer information
·        Based on Header Data(VBAK) user can maintain Item Data(VBAP)
Example: Items information can be maintained under sales order No.
·        Master Data(KNA1)+ Header Data(VBAK)+ Item Data (VBAP)equals to Transactional Data.
i.e. KNA1 + VBAK + VBAP = Transactional Data
·        Sales Order Application is Transaction Data application, this can be used against Order placed by customer.
Requirement:
·        In Selection Screen I can enter customer account no



Customer Accno


Master data
          
sales


·        Output is the customer account no entered, here to this customer sales order, created by sales department on which date created.









·        That is in briefly:















·        Predefined tables using are: (i) KNA1 (2) VBAK.
·        Here we are using two tables so use Inner Join concept

INNER JOINS

·        Using INNER JOIN concepts data can be extracted from more than one table
·        Internal Table Keywords using are
·        Internal table Body have all records, where as Internal table work area has only last record only.









CLEAR:
             Is a keyword which can refreshed memory of Internal Table work area.
REFESH:
             Is a keyword which can clears Internal Table body memory
SORT:
             SORT is akeyword which can sort output data as per required column.
INITIAL:
             Means data is not there in body, it is keyword

NOT INITIAL:

             Means data there in body, it is a keyword.