Saturday, August 31, 2013

SAP Tables & Inter Relationship between them

I found the following document from internet which is very useful for all SAP learners.


SAP Tables & Interrelationships between them by Debesh Swain

Saturday, June 1, 2013

OOP in ABAP Part 2 (Examples on Constructor, Class Constructor, Inheritance & Interface )

 1.       Constructor
Constructor is a special instance method and always named CONSTRUCTOR. It is automatically called at runtime with CREATE OBJECT statement. It must be defined in public area. It can have only importing parameters and exceptions. On the other hand static constructor or class constructor is always named CLASS_CONSTRUCTOR. It is called automatically when the class is accessed for the first time. It can’t have parameters or exceptions. It can’t be called explicitly.

Example on constructor:

2.       Inheritance
A class can inherits all properties from another class termed as super class. The subclass can add new components and can replace the implementation of inherited methods. Here the relationship is IS A relation and also termed as specialization. In ABAP there is no multiple inheritance as only one superclass can be specified directly above a class. A superclass is a generalization of subclass. Inheritance is a one sided relationship i.e. the subclass can recognize the superclass but the parent class can’t recognize the child class. During redefinition the signature of superclass method can’t be changed. To access the original components of the parent class subclass can use SUPER. For constructor both the signature and implementation can be changed. Constructor of direct superclass must be called within the constructor of subclass.
Only protected and public components are visible in subclass. Static methods of superclass can’t be redefined. Private components of super class only are accessed via public and protected methods.
Assignments of instance of subclass back to superclass instance is called narrowing cast or up cast and the reverse is called widening cast or downcast.in downcast the instance can only access the shared components. For widening cast error CX_SY_MOSVE_CAST_ERROR is triggered when there is a mismatch of content requirement.

Example on inheritance:

3.       Interface & Abstract Class
In simple words interface can be referred as superclass which can’t be instantiated and have no implementation part with only public section.  So interface has no implementation. It has only empty method declaration and its components are always public. But the visibility of components can be changed within implementing class using aliases.
If a new method is added to the interface then all the classes which implement the interface have to implement the new method else it will throw an error.

Abstract class is a special kind of class which can’t be instantiated .Abstract class should contain at least one abstract method (method without implementation) ,it can have methods with implementation. The subclass of abstract class can be instantiated if they are not abstract.
Unlike interface when a new non abstract method is added to class there is no need of redefining the same in subclasses.

Interface should be used when working with a wide range of objects which enforces no default behavior as it has no implementation and Abstract class is used when there is a need of closely related classes with partial default implementation.

Example on interface:

4.       Multiple Inheritance
Although a class can’t get inherited from two different classes but it can have more than one interface in its definition. The procedure to achieve multiple inheritance is shown pictorially below.

Pictorial View

Monday, May 27, 2013

SAP ABAP interview Questions & Answers (Part 1)

First 50 Interview Questions that I have faced in the Interviews.
The very first question everyone asks is tell me in which area you have worked in SAP ABAP. Try to consume as much time as you can because the next few minutes to few hours, the interviewer is going to spent on that.
1.      What is the difference between data element and domain?
Domain contains the technical definition of the field. It contains the type, length, range of the data field. Data element contains the semantic definition. It contains the short definition (meaning of the field in relation to business), field labels.
2.       Difference between Value table & Check table.
The field value range can be defined using value table in domain level. But validation does not occur until a foreign key is defined. Then the table becomes check table. Value table is just a proposal and if we accept it, it becomes our check table.
3.       Events in interactive reports.
Apart from normal events like Initialization, At selection screen, Start of selection, Top of page, End of page, End of selection the specific events that are there are:
Top of page during line selection: Using this event we can give the standard Header in the secondary list.
At line-selection: Using this event we can navigate the primary list into the secondary list.
At pF: function key from F5 to F12 to perform interactive action on the list. 
At user-command: It’s a user action command.
4.       How many kinds of tables are there?
Tables can be Transparent, Pool or Cluster. When the transparent table gets activated a table with the same name gets created in the database. In database the table name and field name remains same but the data types gets converted to corresponding database types. Functionally dependent data from certain tables can be stored in database as a cluster table with key as the intersection of table cluster keys. Tables with storage data that are not dependent on each other can be saved as Pool table in database with key as the concatenated value of the table name and key field. This is done so that the data stored in compressed form and database load gets reduced.
(Step by step procedure of these tables creation: http://debesh-exploringfacts.blogspot.in/2013/02/sap-data-dictionary.html)

5.       Difference between call transaction and session method.
If data volume is high we go for session else call transaction will do. The system executes a database commit immediately before and after the 'CALL TRANSACTION USING' statement whereas for the session method it goes for Asynchronous processing. During processing, no transaction is started until the previous transaction has been written to the database. In Session method no sy-subrc is returned, error log is created for error records, updation is always synchronous. Whereas in Call Transaction Method, immediate updation in the database table occurs, sy-subrc is returned, error need to be handled explicitly, updation can be synchronous as well as asynchronous.

6.       How do you write a field for input help on a selection screen with multiple discrete entries?
Select option with no interval.
7.       Syntax for join query.
If I need to use field A, B, Z from table X and C, D, Z from table Y
Select P~A   P~B   P~Z Q~C Q~D Q~Z from table X as P inner join table Y as Q on P~Z = Q~Z where .
(The interviewer didn’t asked this question directly. Rather he gave me two tables and told me to write code to extract the fields into a single table. I wrote the code using for all entries .Then he specifically asked in what other way you can do it)
8.       Difference between a table and a structure.
For table there is a corresponding object in database where no corresponding object is there for structure. Table can hold data whereas structure can’t hold data.
9.       Difference between RFC enabled function module and BAPI.
Technically speaking, both are remote enabled functions that can be accessed from outside of SAP. The difference between RFC and BAPI are business objects. Business Application Programming Interfaces (BAPIs) are standardized programming interfaces that provide external access to SAP business processes and data.  For an RFC to be available and used as a BAPI, it has to be registered in BOR as a method of a business object .
10.   Which one is better in select query when I use something equals to SPACE or not equals to ‘X’ in where condition?(Both give the same results)
Negations in the WHERE condition will usually prevent the optimizer from considering the field in question when searching for a suitable index. This makes it impossible to find a suitable search range, determining the corresponding hit-list can become very processing-intensive, resulting in long runtimes. Negations involving fields that are not contained in the index do not pose a problem.
11.    What is secondary Index?
When a table is activated, an index that is formed from all the key fields is created in addition to the table itself. This index is called the primary index. It is unique by definition.If the primary index cannot be used to determine selection result, (for example, the WHERE condition does not contain any primary index fields), the system searches the whole table. To prevent this, and determine the selection result by searching through a restricted number of database records, we create a secondary index.
12.   How to use RFC enabled FM?
RFC is bidirectional, using this SAP one can interact with external programs or vice versa. To use this one has to define RFC destination in SM59. The calling system while calling the FM also uses this destination in the call signature. The called system simply uses this.
13.   How many kinds of search help are there?
Mainly 2 types of search help are there.
Elementary Search Help: It defines the standard flow of an input help. It holds  
-- Selection method (where does the data displayed in the hit list come from)
-- Search helps parameters (what information should be displayed in the dialog box for value selection and in the hit list)
-- Dialog behavior (what dialog steps should be executed in the input help)

Collective Search Help: It combines several elementary search helps. The user can thus choose one of several alternative search paths with a collective search help. An append search help is used to enhance a collective search help 
(Detailed procedure to create search helps:
14.   Specific event for ALV?
Few events that are returned from 'REUSE_ALV_EVENTS_GET' are:
1. SLIS_EV_USER_COMMAND<=>USER_COMMAND
2. SLIS_EV_TOP_OF_PAGE<=>TOP_OF_PAGE
3. SLIS_EV_PF_STATUS_SET<=>PF_STATUS_SET
4. SLIS_EV_LIST_MODIFY<=>LIST_MODIFY
5. SLIS_EV_TOP_OF_LIST<=>TOP_OF_LIST
6. SLIS_EV_SUBTOTAL_TEXT<=>SUBTOTAL_TEXT
15.   How to make a cell editable in ALV?
In the field catalogue - don't set the edit property for the field.
Add a table for cell style type lvc_t_style to your list data table.
Now loop the list. When the field match occurs make the style enable and modify the grid table.
16.   Is it possible to display something in hierarchy in ALV? If not how will you do it?
REUSE_ALV_HIERSEQ_LIST_DISPLAY is used for the purpose.
(During my interview I didn’t have any idea about this FM. So I said NO. I answered that I can do it using parallel cursor where I have to loop the header table and display header and on change of header key field I have to loop the item table. Neither me nor the Interviewer are satisfied fully with the answerL)
17.   Tcode for SAP script?
SE71
18.   How to translate a text in script?
This can be done from SE63. There we have to go to the path translation->ABAP Objects->Other Long Text->Form. There we have to assign source and target language.
19.   How many secondary index, include structure, append structure possible for a table?
 There is no limit to create secondary indexes. There can be more than one append structure/include structure. (I did not know the exact answer; somewhere I found the answer 9. I will test this soon)
20.   What is the syntax for call transaction?
call transaction
using BDCDATA(STRUCTURE FOR DATA UPDATE)
UPDATE A/S(A=ASYNCHORONOUS ,S=SYNCHORONOUS)
MODE A/N/E(ALL DISPLAY,NO DISPLAY,ERROR DISPLAY)
MESSAGE INTO BDCMSGCOLL(STRUCTUR E FOR MESSAGES)
program->program name
dynpro->screen number
dynbegin->bdc screen start
fname->fieldname
fval ->field value 
21.   How to display an ALV table using OOPs concept?
First we need to create a container. Then create grid inside container.
For field catalog we have to use LVC_FIELD_CATALOG_MERGE and to display we use SET_TABLE_FOR_FIRST_DISPLAY.
(Link to the program:
22.   What is the structure of BDC data?
BDC DATA structure

23.   What are events in table maintenance?
While maintaining table entries there is a need of updation or change of certain fields in the background, that time we use events in TMG. After creating TMG for the table we need to follow the path Environment -> Modification -> Events .There we can choose any existing event or create a new one. If we create a new one then we have to write the logic for that in a subroutine which gets created in the function group assigned.
24.   What is a function group? When you have used it in your projects?
Function groups are containers for function modules. You cannot execute a function group. When you call a function module, the system loads the whole of its function group into the internal session of the calling program (if it has not already been loaded). Function group creates two includes with UXX and TOP (UXX contains all function modules names in that function group; TOP contains all global declaration of the function group). Also when we create TMG we need to assign a function group so that the TMG screens get saved there.
25.   What is a lock object?
Lock objects are use in SAP to avoid the inconsistency at the time of data is being insert/change into database. When you create a lock object System automatically creat two function module.
1. ENQUEUE_. to insert the object in a queue.
2. DEQUEUE_. To remove the object is being queued through above FM.
(For details:
26.   Explain about parameter ID.
Parameter Id is the one which holds the memory for the particular field. When we need to pass the field from one screen to another use the parameter Id.

The SAP Memory is a user-specific memory area of the application server, which is accessed by all main sessions of a user session at once. We can give value of variable to parameter ID. This will store value in SAP memory
SET PARAMETER ID FIELD .
GET PARAMETER ID FIELD .
27.   What is a type group?
 A TYPE GROUP /TYPE-POOL can be used as 'TEMPLATE' - which contains set of constants, Types, Includes.
28.   What are the visibility levels are there in OOPs concept?
Private, Public, Protected
29.   How many types of views are there?
Database views are implemented with an equivalent view on the database.
- Projection views are used to hide fields of a table (only projection).
- Help views can be used as selection method in search helps.
- Maintenance views permit you to maintain the data distributed on several tables for one application object at one time.
(For details:
30.   Name some tables that you have used in SD.
VBAK, VBAP, LIKP, LIPS, VBRK, VBRP
31.   Where in module pool table control is called?
In both PBO and PAI.
32.   How to use POV event?
The POV (Process on Value request) event is triggered when user clicks F4 function key. 
F4IF_INT_TABLE_VALUE_REQUEST can be used there.
(Link:
33.   What steps you should follow when using for all entries in select query?
The internal table used in for entries clause should not be entry and the duplicate records should be deleted from it based on where condition field.
34.   Syntax for Read statement?
Sort by .
Read table   into with key = binary search.
In binary search, it split the table and checks the extreme values.
35.   How many kinds of windows are there in SMARTFORMS?
Main Window, Secondary Window, Constant Window, Final Window
36.   How to find a BAdI?
Can be searched directly using package or using Get_Instance method of class Cl_Exit_handler.
(Link :
37.   What is a class constructor?
Class constructor is a static constructor which gets automatically accessed when system accesses the class for the first time.
38.   What are final class, abstract Class and assistance class?
Abstract class can’t be instantiated. Abstract class should contain at least one abstract method (method without implementation). The subclass of abstract class can be instantiated if they are not abstract. If wish to create multiple flavors of the object with some default operations, you should consider creating abstract class. Final class can’t be inherited further. All methods of final class are inherently final. Final method can’t be redefined further. If we do not want that, anyone change or override the functionality of that class, we can declare it as final. For each Web Dynpro component, one can create a uniquely assigned assistance class. This class should inherit from the abstract class CL_WD_COMPONENT_ASSISTANCE. The assistance class is automatically instantiated when a component is called. The instance is available to each controller of the component through the attribute WD_ASSIST.
39.   Is multiple inheritance possible in SAP ABAP?
As a class can have more than one interface in its definition so multiple inheritance is possible through interface.
40.   Can I access a private method outside a class?
One cannot call the private method directly. To call a private method, one should call a public method first, and then from that method call that private method. There are certain special cases where a class would want access to other classes private attributes and methods in such scenario we can make use of the friends concept in classes.  
41.   Please explain MVC architecture.
MVC stands for Model View Controller.
Model- Generate the application data without caring how to display it.
View – Visualize application data without caring how it was generated
Controller – Bind user and business interaction together.
Thus separating business, display and control logic is explained through MVC.
42.   What are hook methods and name them in the sequence they are called?
(I will use short forms like CC-Component controller, WC-Window Controller, VC- View controller; also I will skip WD from method names)
CC-DOINIT->WC-DOINIT->CC->DOBEFORENAVIGATION->VC-DOINIT->VC-DOMOFIFYVIEW
->CC-POSTPROCESSING->[VIEW GETS DISPLAYED]->VC-DOAFTERACTION->
CC-BEFORENAVIGATION->VC-MODIFYVIEW->CC-POSTPROCESSING->[CHANGED VIEW DISPLAYED]->VC-DOEXIT->CC-DOEXIT->[Application closed]
43.   How to display table in ALV format in WD?
Using component SLVC_WD_TABLE.
44.   Where to change the layout of a view in runtime in WD?
To make changes to the structure of a view layout, you must use the method WDDOMODIFYVIEW (or a method called within it).
45.   What is supply function in WD?
It is used to populate the child node in webdynpro application.
46.   How will you export a variable from one view to other?
Can be done using export parameters in outbound plug.
47.   What fields are there in FM?
Import, Export, Changing, Table, Exception
48.   Which best practices you follow while coding?
49.   What is a Narrowing Cast?
Assigning instance of a subclass back to the instance of super class.
50.   Do you have any idea about authorizations and roles?
Authority check is nothing but the authorization created for specific user or restrictions for users to particular transactions. Created through SU21. SAP Security will create the roles. These are assigned to user IDs creation from SU01.

Apart from ABAP related questions they ask few other questions whose answers they already knew but they try to hear something else.( e.g.  Why do you what to leave your current organization?). They even ask questions like in what way you can contribute to the organization. Anything you want to know? Do you have your breakfast? J

All the very best.
Debesh


Sunday, May 26, 2013

SAP SMARTFORM

The following document contains the
-  SMARTFORM developement procedure,
-  Use of BARCODE, LOGO, STANDARD TEXT
-  Driver Program
-  Logic to convert SMARTFORM to PDF

The result  will look like this.


Scribd Link :

Sunday, May 12, 2013

SAP ABAP Code Performance Check

The document contains sample code review check lists & Performance analysis tests( ABAP runtime analysis, SQL trace ,SLIN Check  Code Inspector check)

Scribd Link :
http://www.scribd.com/doc/140931405/ABAP-Performance-Check

Friday, May 10, 2013

Module Pool Programming (Part 1)



Key Points related to Module Pool Programming:

1.    Module pool can be considered as follows:
Collection of screens + Flow logic (Code behind the screen) + Code within main ABAP program.
2.    Screen is an interface through which user can interact with SAP.
3.    Module pool program is classified as Type M and these can’t be executed directly. (Executed by Transaction codes)
4.    For Module pool programming the screen design is done through Graphical Screen Painter (SE51) and GUI design is done from Menu Painter (SE41).
5.    In Module Pool screen can be Normal Screen (has min, max, close option), Sub screen (Screen within a screen), Modal Dialog Box (only close option).
6.    Screen Numbers:
         1000 – Selection Screen
   >= 9000 – Custom Screen
9000-9500 – SAP Partners
      >9500 – Customer Screen
7.    Screen painter.
Screen painter = screen attributes + screen layout + field attributes + flow logic.
8.    Menu Painter.
Menu painter = menu bar + standard tool bar + title bar.
9.    Function codes are assigned to screen attributes to make them interactive.
10. Flow Logic.
Dynpro processor controls the flow logic on screen. By default the flow logic has two specific events which are specific only for module pool programming
PBO and PAI. Apart from these it can have POV and POH.
11. PBO.
Process Before Output is triggered before the screen gets displayed.
It has one module which sets the status bar and title bar.
Module Status_ Output.
          Set PF_Status ‘XXXXXX’.
          Set Title Bar ‘XXXX’.
End module.
12. PAI.
Process After Input  is triggered after the user does some interaction.
It has one module.
Module User Command_ Input.
Inside this the system field SY-UCOMM holds the function code from interactive screens element and according the value different coding options are provided inside CASE –END CASE.
13. POV.
Process On Value request (F4 help).
Field Module on input.
14. POH.
Process On Help request (F1 Help)
Field Module on request.
15. Steps For Programming:
- create the main program
- create top include
- create first screen
- Define attributes
- Define graphical user interface
- Assign field attributes via field list
- Define flow logic using dialog flow logic syntax
- create follow up screens
(Same steps as first screen)
16. PBO module statements are followed by OUTPUT and PAI module statements are followed by INPUT.
17. Field names must be identical to screen field names for values to pass between the dialog processor and ABAP/4 processor at runtime.
18.  Message statements can be used in PAI.
19. Field statement keeps a single field open after an error or warning message is issued.
20. To keep multiple fields open for i/p after error/warning we use
Chain- - -End Chain.
21. All fields of current screen are stored in screen table. Use Modify Screen statement to modify attributes.
22. For table control there must be a loop statement in both PBO and PAI. It is because loop statement causes screen fields to be copied back and forth between ABAP program and the Screen Field.
At the time of PBO, the transport of the table control fields from the ABAP program to the screen takes place after every loop run in the flow logic. The remaining screen fields are filled, as usual, at the end of PBO processing.
At PAI time, first all the screen fields that do not belong to any table control and not listed in any FIELD statement are transported to identically-named fields of the ABAP program. The contents of the table control fields are transported, row by row at the beginning of the corresponding loop run, into the identically-names fields of the ABAP program. The fields that are listed in the FIELD statements are transported, as usual, directly from the corresponding FIELD statement.
Within the loops, two system fields are of importance.
sy-stepl contains the current line of the table control counted from the uppermost displayed line
sy-loopc contains the current number of table control rows on the screen


23. To call sub screen we use CALL SUBSCREEN statement in the PBO of main screen and also in PAI.
In PBO:
Call Subscreen including sy-repid .
In PAI:
Call Subscreen .
24.  For search help on a screen we can use a predefined search help on the search tab of dictionary attribute of the field.
25. For select options, create sub-screen area in your screen layout where you want to create the select options. In the top include of your module pool program declare a selection screen as a sub-screen
e.g.
SELECTION-SCREEN BEGIN OF SCREEN 100 AS SUBSCREEN.
Select-options s_matnr for mara-matnr.
SELECTION-SCREEN END OF SCREEN.
 In the PBO and PAI of the main screen where the select options needs to be created do a
call subscreen of the above screen (100).
CALL SUBCREEN sub_area INCLUDING.
This call subscreen statement is necessary for transport of values between screen and
program. All validations of the selection screen fields e.g. the s_matnr field created above should be done in selection screen events like AT SELECTION-SCREEN etc. and not in PAI. These selection screen validations etc. should be done in the top include only
.

Code Snippet :
Link : http://www.scribd.com/doc/140550815/Module-Pool-Programming



Wednesday, May 8, 2013

ABAP Interactive Report


Introduction:

When an ABAP report (Type 1) is executed, the program context and memory space variables are made available on the application server. The subsequent program flow is controlled by the ABAP runtime system. If the program contains a selection screen, the ABAP runtime system sends it to the presentation server at the start of the program.

When the user executes the report after entering selection fields, the data entered on the selection screen is automatically placed in the corresponding data objects. The ABAP runtime system takes over control of the program. Then the program sends information to the database about the records that should be read. The database returns the required database records and the runtime system ensures that the data is placed in the relevant data objects.

The list output is also programmed in the processing block. After the processing block finishes, the runtime system sends the list as a screen to the presentation server. The events START-OF-SELECTION, GET, END-OF-SELECTION, TOP-OF-PAGE and END-OFPAGE can be used only to create basic lists.

·         To create detail lists, use the events AT LINE-SELECTION or AT USER-COMMAND. We use   TOP-OF-PAGE DURING LINE-SELECTION for page headers on detail lists.
·         Each detail list event exists only once in the program and is shared by all detail lists. You must therefore ensure yourself, within the processing block, that the correct list is created. 
·         To do this, use a CASE structure that uses the system field sy-lsind. This system field contains the list index of the list that you are currently generating.
·         Use the statement HIDE global field to store the contents of the global data field
global_field for the current line.
·         If the user selects the line, the data field is automatically filled with the value that you retained for the line.
·         You do not have to display the field on the list in order to retain its value using HIDE.
·         The field can be a structure. However, deep structures (structures containing internal tables as components) are not supported.
·         When the user selects a line on an interactive list, all of the global data fields whose values you stored using the HIDE statement while you were creating the basic list are filled with those values.
·         The line selection is based on the cursor position when the AT LINE-SELECTION and AT USERCOMMAND events occur. (System field sy-lilli).
·         GET CURSOR gets the cursor position on a screen or in an interactive list event.  
Syntax : GET CURSOR FIELD [OFFSET ] [LINE ][VALUE ] [LENGTH ].      GET CURSOR LINE [OFFSET ] [VALUE ] [LENGTH ].
At a user action on a list or screen, the statement writes the position, value,  and displayed length of a field or line into the corresponding variables.
·         If you choose a line using the READ LINE... statement, the values are placed back in the original fields according to the line numbers.
·         To check whether the user selected a valid line, you can use the fact that the hide area only contains data for valid lines. When you have finished creating the list, initialize a suitable test field. 
·         This allows you to check before you create the detail list whether a value from the hide area has been placed in the test field.
·         Once you have created the detail list, re-initialize the test field to ensure that the user cannot choose an invalid line once he or she returns from the detail list and attempts to select another line for a new detail list.

An interactive report generally works in the following fashion:
1. Basic list is displayed.
2. User double clicks on any valid line
    or
    User selects a line and presses as button on the tool bar.
3. The corresponding event is triggered
4. Then in the code, the line on which action was done, is read.
5. Depending on the values in that selected line, a secondary list is displayed.
6. Steps from 2-5 are repeated till the end.

We can generate 19 secondary list of output. Hence a total of 20 output screen (1 Primary + 19 Secondary) can be generated by Interactive program.


Please find the example below :



Tuesday, May 7, 2013

All about ABAP List Viewer ( List Display, Grid Display, Using OOP)



ALV programming

Content:

Ø  Introduction
Ø  ALV List Display
Ø  ALV Grid Display
Ø  ALV Hierarchical Display
Ø  ALV using OOPs
Ø  Editing and coloring
Ø  Code snippets

Introduction:

ALV stands for ABAP List Viewer. The ABAP List Viewer standardizes and simplifies the use of lists and reports in the R/3 System. ALV provides a lot of inbuilt functions (like searching, sorting, printing filtering, totaling) to our reports that’s why it substantially decreases the report development time. ALV takes care of rendering the list and we can concentrate only on the data retrieval part.

Common Steps:
         - Data declarations
         - Fetch the required data form the tables
         - Prepare field catalog
         - Build up the event table if required
         - Display ALV output by Calling FM

All the definitions TYPES and STRUCTURES and CONSTANTS are defined in the TYPE-POOL ‘SLIS’, so it should be declared first.

ALV List Display:

      - Field catalog can be prepared manually (should contain at least TABNAME, FIELDNAME,    REF_TABNAME, SELTECT_M) or by using REUSE_ALV_FIELDCATALOG_MERGE.
    - To get all possible events REUSE_ALV_EVENTS_GET can be used.
    - To write proper comments use REUSE_ALV_COMMENTARY_WRITE.
    - To print the data REUSE_ALV_LIST_DISPLAY can be used.

ALV Grid Display:

    - The first 3 function modules mentioned above can be used and to print the data REUSE_ALV_GRID_DISPLAY is used.

Hierarchical ALV:

  -  Hierarchical display is used for displaying data that are related. Like sales order and item details.
  - REUSE_ALV_HIERSEQ_LIST_DISPLAY is used to print the data.

ALV Using OOPs:

- Create Docking/custom container.
- Create a grid inside container.
- Call function LVC_FIELDCATALOG_MERGE to get the field catalog.
- Call method SET_TABLE_FOR_FIRST_DISPLAY for o/p.


Editing and Coloring:


- Coloring an entire column

 To make an entire column be painted with the color you want, you can use  the "emphasize" option of the field catalog. Simply assign a color code to this field of the row added for your column. Color codes are constructed as follows:

Cxyz: - x: 1-7 (1 for example is gray-blue, 6 is red), y: intensified on/off, z: inverse on/off.

- Coloring an entire row

Coloring a row is a bit more complicated. To enable row coloring, you should add an additional field to your list data table. It should be of character type and at least 4 bit long. This field will contain the color code for the row. So for example:

DATA: BEGIN OF gt_list occurs 0.
INCLUDE STRUCTURE .
DATA rowcolor(4) TYPE c.
DATA: END OF gt_list.

As you guess, you should fill the color code to this field. Its format is as explained before. For second you must pass the name of the field to the layout structure:
E.g. ps_layout-info_fname = 'ROWCOLOR'.
- Coloring an individual cell: 
Likely coloring rows, you must append an internal table to each line of gt_list containing the color information:
DATA: BEGIN OF gt_list occurs 0.
INCLUDE STRUCTURE .
DATA cellcolors TYPE lvc_t_scol.
DATA: END OF gt_list.

If you want to modify the cell in the 5 row and the 2 column, you have to set:

DATA: cellcolor type line of lvc_t_scol.
READ TABLE gt_list INDEX 2.
cellcolor-fname = '.
cellcolor-color-col = '6'.
cellcolor-color-int = '0'.
APPEND cellcolor TO gt_list-cellcolors.
Modify GT_LIST INDEX 5. 
As like coloring rows, you have to pass the info for coloring cell to the layout-structure:
ps_layout-info_ctab_fname = 'CELLCOLOR'.

- Editing an entire column:

When you want to do edit only for particular column and not for the entire grid then you need to perform fieldcat in that particular column only. Loop the field catalog and for that column make the EDIT field of catalog as ‘X’ and then modify catalog.

- Editing a single cell:
Add a table to your list data table.

Data begin of gt_grid occurs 0.
data cellstyles type lvc_t_styl.
Data end of gt_grid.
Form make_field_edit using pt_grid like gt_grid[].
data: ls_grid like line of pt_grid,
ls_style type lvc_s_styl,
lt_style type lvc_t_styl.Loop at pt_grid into ls_grid.
If ls_grid-curr = xyz. 'your condition for the row
ls_style-fieldname = 'CURR'.
ls_style-style = cl_gui_alv_grid=>mc_style_enabled.
append ls_style to lt_style.
endif.


Insert lines of lt_style into ls_grid-celltyles.
modify pt_grid from ls_grid.

Endloop.
Endform.

Code Snippet for ALV List Display, Grid Display and Using OOP.

Link : http://www.scribd.com/doc/139934961/ABAP-ALV-Programming

ABAP ALV Programming by Debesh Swain