Wednesday, April 25, 2012

BLOCKED ALV :

Here is a code to implement Blocked ALV display. I hope this code will help u.


*&---------------------------------------------------------------------*
*& Report  ZALV_BLOCKED
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT ZALV_BLOCKED.

include ZALV_BLOCKED_TOP.
include ZALV_BLOCKED_SEL.
include ZALV_BLOCKED_SUB.

INITIALIZATION.

PERFORM LIST_INIT.

START-OF-SELECTION.

PERFORM FETCH_MARD CHANGING I_MARD.

PERFORM FETCH_MARC USING I_MARD CHANGING I_MARC.

PERFORM FETCH_MARA USING I_MARD CHANGING I_MARA.

PERFORM BUILD_FIELDCAT1 CHANGING I_FIELDCAT.

PERFORM BUILD_FIELDCAT2 CHANGING I_FIELDCAT1.

PERFORM BUILD_FIELDCAT3 CHANGING I_FIELDCAT2.

PERFORM DISPLAY_MARA USING I_MARA.

PERFORM DISPLAY_MARC USING I_MARC.

PERFORM DISPLAY_MARD USING I_MARD.

PERFORM DISPLAY_BLOCK.


TYPE-POOLS : SLIS.

TYPES : BEGIN OF TY_MARA,
        MATNR TYPE MATNR,
        MTART TYPE MTART,
        MBRSH TYPE MBRSH,
        MATKL TYPE MATKL,
        END OF TY_MARA,
      TY_T_MARA TYPE STANDARD TABLE OF TY_MARA,
        BEGIN OF TY_MARC,
          MATNR TYPE MATNR,
          WERKS TYPE WERKS_D,
          EKGRP TYPE EKGRP,
        END OF TY_MARC,
      TY_T_MARC TYPE STANDARD TABLE OF TY_MARC,
        BEGIN OF TY_MARD,
          MATNR TYPE MATNR,
          WERKS TYPE WERKS_D,
          LGORT TYPE LGORT_D,
          LABST TYPE LABST,
        END OF TY_MARD,
      TY_T_MARD TYPE STANDARD TABLE OF TY_MARD.

DATA : I_MARA TYPE TY_T_MARA,
       I_MARC TYPE TY_T_MARC,
       I_MARD TYPE TY_T_MARD.

DATA : GV_MATNR TYPE MATNR.

DATA : I_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
       I_FIELDCAT1 TYPE SLIS_T_FIELDCAT_ALV,
       I_FIELDCAT2 TYPE SLIS_T_FIELDCAT_ALV.

DATA: I_EVENTS TYPE SLIS_T_EVENT,
      W_EVENT TYPE SLIS_ALV_EVENT.

DATA : I_LAYOUT TYPE SLIS_LAYOUT_ALV.


*&---------------------------------------------------------------------*
*&  Include           ZALV_BLOCKED_SEL
*&---------------------------------------------------------------------*

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.

  SELECT-OPTIONS : S_MATNR FOR GV_MATNR.

SELECTION-SCREEN END OF BLOCK B1.


*&---------------------------------------------------------------------*
*&  Include           ZALV_BLOCKED_SUB
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  FETCH_MARA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_I_MARA  text
*----------------------------------------------------------------------*
FORM FETCH_MARA USING FP_I_MARD TYPE TY_T_MARD
                CHANGING FP_I_MARA TYPE TY_T_MARA.

IF NOT FP_I_MARD IS INITIAL.
SELECT MATNR
       MTART
       MBRSH
       MATKL
  INTO TABLE FP_I_MARA
  FROM MARA
  FOR ALL ENTRIES IN FP_I_MARD
  WHERE MATNR = FP_I_MARD-MATNR.

ENDIF.

ENDFORM. " FETCH_MARA
*&---------------------------------------------------------------------*
*&      Form  FETCH_MARC
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_I_MARA  text
*      <--P_I_MARC  text
*----------------------------------------------------------------------*
FORM FETCH_MARC USING FP_I_MARD TYPE TY_T_MARD
                 CHANGING FP_I_MARC TYPE TY_T_MARC.

  IF NOT FP_I_MARD IS INITIAL.
    SELECT MATNR
           WERKS
           EKGRP
      INTO TABLE FP_I_MARC
      FROM MARC
      FOR ALL ENTRIES IN FP_I_MARD
      WHERE MATNR = FP_I_MARD-MATNR.
  ENDIF.

ENDFORM. " FETCH_MARC
*&---------------------------------------------------------------------*
*&      Form  FETCH_MARD
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_I_MARD  text
*      <--P_PERFORM  text
*      <--P_FETCH_MARA  text
*      <--P_I_MARA  text
*----------------------------------------------------------------------*
FORM FETCH_MARD CHANGING FP_I_MARD TYPE TY_T_MARD.

  SELECT MATNR
         WERKS
         LGORT
         LABST
    INTO TABLE FP_I_MARD
    FROM MARD
    WHERE MATNR IN S_MATNR.

ENDFORM. " FETCH_MARD
*&---------------------------------------------------------------------*
*&      Form  BUILD_FIELDCAT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_I_FIELDCAT  text
*----------------------------------------------------------------------*
FORM BUILD_FIELDCAT1 CHANGING FP_I_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.

  DATA : W_FIELDCAT TYPE SLIS_FIELDCAT_ALV.

w_fieldcat-col_pos = 1.
w_fieldcat-tabname = 'ty_t_mara'.
w_fieldcat-fieldname = 'MATNR'.
w_fieldcat-seltext_m = 'MATERIAL NUMBER'.

append w_fieldcat to i_fieldcat.
clear w_fieldcat.

w_fieldcat-col_pos = 2.
w_fieldcat-tabname = 'ty_t_final'.
w_fieldcat-fieldname = 'MTART'.
w_fieldcat-seltext_m = 'MATERIAL TYPE'.

append w_fieldcat to i_fieldcat.
clear w_fieldcat.

w_fieldcat-col_pos = 3.
w_fieldcat-tabname = 'ty_t_final'.
w_fieldcat-fieldname = 'MBRSH'.
w_fieldcat-seltext_m = 'INDUSTRY SECTOR'.

append w_fieldcat to i_fieldcat.
clear w_fieldcat.

w_fieldcat-col_pos = 4.
w_fieldcat-tabname = 'ty_t_final'.
w_fieldcat-fieldname = 'MATKL'.
w_fieldcat-seltext_m = 'MATERIAL GROUP'.

append w_fieldcat to i_fieldcat.
clear w_fieldcat.

ENDFORM. " BUILD_FIELDCAT
*&---------------------------------------------------------------------*
*&      Form  BUILD_FIELDCAT2
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_I_FIELDCAT1  text
*----------------------------------------------------------------------*
FORM BUILD_FIELDCAT2 CHANGING FP_I_FIELDCAT1 TYPE SLIS_T_FIELDCAT_ALV.

  DATA : W1_FIELDCAT TYPE SLIS_FIELDCAT_ALV.

w1_fieldcat-tabname = 'ty_t_marc'.
w1_fieldcat-fieldname = 'MATNR'.
w1_fieldcat-seltext_m = 'MATERIAL NUMBER'.

append w1_fieldcat to i_fieldcat1.
clear w1_fieldcat.

w1_fieldcat-tabname = 'ty_t_marc'.
w1_fieldcat-fieldname = 'WERKS'.
w1_fieldcat-seltext_m = 'PLANT'.

append w1_fieldcat to i_fieldcat1.
clear w1_fieldcat.

w1_fieldcat-tabname = 'ty_t_marc'.
w1_fieldcat-fieldname = 'EKGRP'.
w1_fieldcat-seltext_m = 'PURCHASING GROUP'.

append w1_fieldcat to i_fieldcat1.
clear w1_fieldcat.

ENDFORM. " BUILD_FIELDCAT2
*&---------------------------------------------------------------------*
*&      Form  BUILD_FIELDCAT3
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_I_FIELDCAT2  text
*----------------------------------------------------------------------*
FORM BUILD_FIELDCAT3 CHANGING FP_I_FIELDCAT2 TYPE SLIS_T_FIELDCAT_ALV.

  DATA : W2_FIELDCAT TYPE SLIS_FIELDCAT_ALV.

w2_fieldcat-tabname = 'ty_t_mard'.
w2_fieldcat-fieldname = 'MATNR'.
w2_fieldcat-seltext_m = 'MATERIAL NUMBER'.

append w2_fieldcat to i_fieldcat2.
clear w2_fieldcat.

w2_fieldcat-tabname = 'ty_t_mard'.
w2_fieldcat-fieldname = 'WERKS'.
w2_fieldcat-seltext_m = 'PLANT'.

append w2_fieldcat to i_fieldcat2.
clear w2_fieldcat.

w2_fieldcat-tabname = 'ty_t_mard'.
w2_fieldcat-fieldname = 'LGORT'.
w2_fieldcat-seltext_m = 'STORAGE LOCATION'.

append w2_fieldcat to i_fieldcat2.
clear w2_fieldcat.

w2_fieldcat-tabname = 'ty_t_mard'.
w2_fieldcat-fieldname = 'LABST'.
w2_fieldcat-seltext_m = 'VALUATED STOCK'.

append w2_fieldcat to i_fieldcat2.
clear w2_fieldcat.

ENDFORM. " BUILD_FIELDCAT3
*&---------------------------------------------------------------------*
*&      Form  DISPLAY_MARA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_I_MARA  text
*----------------------------------------------------------------------*
FORM DISPLAY_MARA USING FP_I_MARA TYPE TY_T_MARA.

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
  EXPORTING
    IS_LAYOUT                        = I_LAYOUT
    IT_FIELDCAT                      = I_FIELDCAT
    I_TABNAME                        = 'MARA'
    IT_EVENTS                        = I_EVENTS
*   IT_SORT                          =
*   I_TEXT                           = ' '
  TABLES
    T_OUTTAB                         = FP_I_MARA
* EXCEPTIONS
*   PROGRAM_ERROR                    = 1
*   MAXIMUM_OF_APPENDS_REACHED       = 2
*   OTHERS                           = 3
          .
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.


ENDFORM. " DISPLAY_MARA
*&---------------------------------------------------------------------*
*&      Form  LIST_INIT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM LIST_INIT .

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'
  EXPORTING
    I_CALLBACK_PROGRAM             = SY-REPID
*   I_CALLBACK_PF_STATUS_SET       = ' '
*   I_CALLBACK_USER_COMMAND        = ' '
*   IT_EXCLUDING                   =
          .


ENDFORM. " LIST_INIT
*&---------------------------------------------------------------------*
*&      Form  DISPLAY_MARC
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_I_MARC  text
*----------------------------------------------------------------------*
FORM DISPLAY_MARC USING FP_I_MARC TYPE TY_T_MARC.

  CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
    EXPORTING
      IS_LAYOUT                        = I_LAYOUT
      IT_FIELDCAT                      = I_FIELDCAT1
      I_TABNAME                        = 'MARC'
      IT_EVENTS                        = I_EVENTS
*     IT_SORT                          =
*     I_TEXT                           = ' '
    TABLES
      T_OUTTAB                         = FP_I_MARC
*   EXCEPTIONS
*     PROGRAM_ERROR                    = 1
*     MAXIMUM_OF_APPENDS_REACHED       = 2
*     OTHERS                           = 3
            .
  IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.


ENDFORM. " DISPLAY_MARC
*&---------------------------------------------------------------------*
*&      Form  DISPLAY_MARD
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_I_MARD  text
*----------------------------------------------------------------------*
FORM DISPLAY_MARD USING FP_I_MARD TYPE TY_T_MARD.

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
  EXPORTING
    IS_LAYOUT                        = I_LAYOUT
    IT_FIELDCAT                      = I_FIELDCAT2
    I_TABNAME                        = 'MARD'
    IT_EVENTS                        = I_EVENTS
*   IT_SORT                          =
*   I_TEXT                           = ' '
  TABLES
    T_OUTTAB                         = FP_I_MARD
* EXCEPTIONS
*   PROGRAM_ERROR                    = 1
*   MAXIMUM_OF_APPENDS_REACHED       = 2
*   OTHERS                           = 3
          .
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.


ENDFORM. " DISPLAY_MARD
*&---------------------------------------------------------------------*
*&      Form  DISPLAY_BLOCK
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM DISPLAY_BLOCK .

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'
* EXPORTING
*   I_INTERFACE_CHECK             = ' '
*   IS_PRINT                      =
*   I_SCREEN_START_COLUMN         = 0
*   I_SCREEN_START_LINE           = 0
*   I_SCREEN_END_COLUMN           = 0
*   I_SCREEN_END_LINE             = 0
* IMPORTING
*   E_EXIT_CAUSED_BY_CALLER       =
*   ES_EXIT_CAUSED_BY_USER        =
* EXCEPTIONS
*   PROGRAM_ERROR                 = 1
*   OTHERS                        = 2
          .
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.


ENDFORM. " DISPLAY_BLOCK
ALV Report Without declaring Fieldcatalog :


*&---------------------------------------------------------------------*
*& Report  ZALV_AA_GRID
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT ZALV_AA_GRID.

TYPES : BEGIN OF TY_MARA,
        MATNR TYPE MATNR,
        MTART TYPE MTART,
        MBRSH TYPE MBRSH,
        MATKL TYPE MATKL,
        MEINS TYPE MEINS,
        END OF TY_MARA,
      TY_T_MARA TYPE STANDARD TABLE OF TY_MARA.

DATA : I_MARA TYPE TY_T_MARA,
       GV_MATNR TYPE MATNR.

DATA : I_ALV TYPE REF TO CL_GUI_ALV_GRID.

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
  SELECT-OPTIONS : S_MATNR FOR GV_MATNR.
SELECTION-SCREEN END OF BLOCK B1.

SELECTION-SCREEN BEGIN OF SCREEN 9001.

SELECTION-SCREEN END OF SCREEN 9001.

SELECT MATNR
       MTART
       MBRSH
       MATKL
       MEINS
  INTO TABLE I_MARA
  FROM MARA
  WHERE MATNR IN S_MATNR.

CREATE OBJECT I_ALV EXPORTING I_PARENT = CL_GUI_CONTAINER=>SCREEN0.

          CALL METHOD I_ALV->SET_TABLE_FOR_FIRST_DISPLAY
          EXPORTING I_STRUCTURE_NAME = 'MARA'
          CHANGING IT_OUTTAB = I_MARA.

           CALL SELECTION-SCREEN 9001.
SAP ABAP  : How to get Started

Being able to use ABAP effectively requires more than just knowledge of the keywords. To be able to start with ABAP effectively you need to have a basic understanding of the architecture of the SAP NetWeaver Application Server ABAPand some of its strengths such as development on a central server or integrated software logistics (SAP Change and Transport system). And, of course, you need the knowledge of the basic tools of the ABAP development environment and ABAP itself as a language.
First of all try to write your first program i.e ''Hello World'' program in ABAP.
ABAP Flow of Events :

1. Load Of Program : When a program is called using SUBMIT or using a transaction code, then – at every call – a new internal session is opened and the event block is executed once at every call. You can initialize global data objects of the program here. The event block must be executed completely; otherwise, a runtime error will occur.Therefore, no statements are allowed to be executed that leave the event block without returning.At the first call of an external Procedure (sub-program or function module), the framework program of the called procedure is loaded into the internal session of the caller, thus triggering the event LOAD-OF-PROGRAM.

2. Initialization : This event keyword defines an event block whose event is triggered by the ABAP runtime environment during the flow of an executable program, directly after LOAD-OF-PROGRAM and before the selection screen processing of any existing standard selection screen. This gives you the one-time opportunity to initialize the input fields of the selection screen.

3. At Selection Screen :  The event keyword AT SELECTION-SCREEN provides you with several possibilities to carry out processing blocks while the system is processing the selection screen. To react on different events, that can occur when the selection screen is processed, the keyword AT SELECTION-SCREEN has various options. All the Validation Done on Selection Screen is done through this event. The AT SELECTION SCREEN event is triggered after the user enters value on the selection screen and presses enter or Executes it.

4. Start Of Selection : Start Of Selection is triggered after the selection screen is processed. In an executable program, all statements that are not declarations and that are listed before the first explicit processing block, or if the program does not contain any explicit processing blocks, then all functional statements of the program, are assigned to an implicit event block START-OF-SELECTION, which is inserted before any START-OF-SELECTION event blocks.If the program is linked to a logical database, preparatory tasks can be performed at START-OF-SELECTION before the logical database imports the data.

5. 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.

6. 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. This occurs when a new page is started – that is, immediately before the first line in a new page is to be output.

7. 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. So the LINE-COUNT is defined like this if the page contains 50 lines and 3 lines are for the footer then it should be written as LINE-COUNT 50(3).

8 At Line Selection : This statement defines an event block whose event is triggered by the ABAP runtime environment during the display of a screen list – provided the scren cursor is on a list line and you select a function using the function code PICK. Through the definition of this event block, the standard list status is automatically enhanced in such a way that the function code F2 and, with it, the double-click mouse function is linked up to the function code PICK.

9. At User Command : This statement defines an event block whose event is triggered by the ABAP runtime environment if, during the display of a screen list, a function with a self-defined function code was chosen.

10. At PFn : This statemet defines an event block whose event is triggered by the ABAP runtime environment during list display – provided the screen cursor is on a list line and a function is selected using the function code PFn. Here n stands for a number between 01 and 24. In the= standard list status, these function codes are assigned to the function keys of the input device.
How To Upload Logo in ALV ? 



 Logo should be uploaded into application server using transaction 'OAER'.
    1.     Go to Transaction OAER,
    2.     Give Class Name as PICTURES
    3.     Class type as OT
    4.     Object Key as the name of the Object u want to specify
    5.     Upon execution you would be prompted to give the file path details. Just upload which ever logo u want to display
    6.     Now you can use the same name in your ALV FM
    In your ALV program, you need to have event for TOP_OF_PAGE, and also this works only in case of Grid not in ALV LIS.
Sample of Simple ALV Report




---------------------------------------------------------------------*
*& Report  ZAASHISH_ALV
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZAASHISH_ALV.

type-pools: slis.

data: wa_num 
type matnr,
      wa_werks 
type werks_d.

types: 
begin of ty_mara,
    matnr 
type matnr,   "Material Number field of Mara Table
    meins 
type meins,   "Unit field of Mara Table
    mtart 
type mtart,   "Material Type field of Mara Table
    matkl 
type matkl,   "Unit of Issue field of Mara Table
    prdha 
type prodh_d, "Product Hierarchy field of Mara Table
    
end of ty_mara,
    ty_t_mara 
type standard table of ty_mara.

*Creating Structure for makt

types: 
begin of ty_makt,
    matnr 
type matnr,   "Material Number field of Makt Table
    maktx 
type maktx,   "Material Description field of Makt Table
  
end of ty_makt,
ty_t_makt 
type standard table of ty_makt.

*Creating Structure for marc
types: 
begin of ty_marc,
  matnr 
type matnr,   "Material Number field of Marc Table
  werks 
type werks,   "Plant field of Marc
  ekgrp 
type ekgrp,   "Purchasing group field of Marc Table
  ausme 
type ausme,   "Unit of Issue field of Marc Table
end of ty_marc,
ty_t_marc 
type standard table of ty_marc.

*Creating Structure for mard
types: 
begin of ty_mard,
  matnr 
type matnr,     "Material Number field of Mard Table
  werks 
type werks_d,   "Plants field in Mard Table
  lgort 
type lgort_d,   "Storage Location field of Mard Table
end  of ty_mard,
ty_t_mard 
type standard table of ty_mard.

*Creating output structure
types: 
begin of ty_list,
  matnr 
type matnr,
  meins 
type meins,
  mtart 
type mtart,
  matkl 
type matkl,
  pradh 
type prodh_d,
  maktx 
type maktx,
  werks 
type werks_d,
  ekgrp 
type ekgrp,
  ausme 
type ausme,
  lgort 
type lgort_d,
 
end of ty_list,
ty_t_list 
type standard table of ty_list.


*Declaring Wprk area

data: w_mara 
type ty_mara,
      w_marc 
type ty_marc,
      w_makt 
type ty_makt,
      w_mard 
type ty_mard,
      w_list 
type ty_list,
      w_fieldcatalog 
type slis_fieldcat_alv.

data: i_mara 
type ty_t_mara,
       i_marc 
type ty_t_marc,
       i_makt 
type ty_t_makt,
       i_mard 
type ty_t_mard,
       i_list 
type ty_t_list,
       i_fieldcatalog 
type slis_t_fieldcat_alv.


*Creates Selection Screen for werks & matnr

select-options gv_werks for wa_werks .
select-options gv_matnr for wa_num.


*Fetching  records from mara and placing into i_mara


  
select
    matnr
    meins
    mtart
    matkl
    prdha
  
into table i_mara
 
from mara
where matnr in gv_matnr.

  
if sy-subrc = and i_mara is not initial.
    
sort i_mara by matnr.

*Fetching records from marc and placing into i_marc

    
select
      matnr
      werks
      ekgrp
      ausme
    
into table
       i_marc
    
from marc
    
for all entries in i_mara
    
where matnr = i_mara-matnr.
    
if sy-subrc = and i_marc is not initial.
      
sort i_marc by matnr.


*Fetching records from mard and placing into i_mard

      
select
        matnr
        werks
        lgort
      
into table
        i_mard
      
from
        mard
      
for all entries in
        i_marc
      
where  matnr = i_marc-matnr.
      
if sy-subrc = and i_mard is not initial.
        
sort i_mard by matnr.
      endif.
*Fetching records from makt and placing into i_makt
    endif.

    
select
       matnr
      maktx
    
into table
      i_makt
    
from
      makt
    
for all entries in
      i_mara
    
where matnr = i_mara-matnr.
    
if sy-subrc = and i_makt is not initial.
      
sort i_makt by matnr.
    endif.
  endif.

*Creating loop to fetch one by one record from i_mara and placing into w_mara

  
loop at  i_mara into w_mara.
    w_list-matnr = w_mara-matnr.
    w_list-meins = w_mara-meins.
    w_list-mtart = w_mara-mtart.
    w_list-matkl = w_mara-matkl.
    w_list-pradh = w_mara-prdha.
    
read table i_marc into w_marc with key matnr = w_mara-matnr.
    w_list-werks = w_marc-werks.
    w_list-ekgrp = w_marc-ekgrp.
    
read table i_mard into w_mard with key matnr = w_mara-matnr.
    w_list-werks = w_mard-werks.
    w_list-lgort = w_mard-lgort.
    
read table i_makt into w_makt with key matnr = w_mara-matnr.
    w_list-maktx = w_makt-maktx.
    
append w_list to i_list.
  endloop.

w_fieldcatalog-col_pos = 
1.
w_fieldcatalog-tabname = 
'ty_t_list'.
w_fieldcatalog-fieldname = 
'MATNR'.
w_fieldcatalog-seltext_m = 
'material number'.

append w_fieldcatalog to i_fieldcatalog.
clear w_fieldcatalog.

w_fieldcatalog-col_pos = 
2.
w_fieldcatalog-tabname = 
'ty_t_list'.
w_fieldcatalog-fieldname = 
'MEINS'.
w_fieldcatalog-seltext_m = 
'Unit of Measure'.



append w_fieldcatalog to i_fieldcatalog.
clear w_fieldcatalog.
w_fieldcatalog-col_pos = 
3.
w_fieldcatalog-tabname = 
'ty_t_list'.
w_fieldcatalog-fieldname = 
'MTART'.
w_fieldcatalog-seltext_m = 
'Material Type'.

append w_fieldcatalog to i_fieldcatalog.
clear w_fieldcatalog.



w_fieldcatalog-col_pos = 
4.
w_fieldcatalog-tabname = 
'ty_t_list'.
w_fieldcatalog-fieldname = 
'AUSME'.
w_fieldcatalog-seltext_m = 
'Unit of Issue'.

*append w_fieldcatalog to i_fieldcatalog.

append w_fieldcatalog to i_fieldcatalog.
clear w_fieldcatalog.
w_fieldcatalog-col_pos = 
5.
w_fieldcatalog-tabname = 
'ty_t_list'.
w_fieldcatalog-fieldname = 
'MATKL'.
w_fieldcatalog-seltext_m = 
'Material Group'.



append w_fieldcatalog to i_fieldcatalog.
clear w_fieldcatalog.
w_fieldcatalog-col_pos = 
6.
w_fieldcatalog-tabname = 
'ty_t_list'.
w_fieldcatalog-fieldname = 
'PRADH'.
w_fieldcatalog-seltext_m = 
'Product Hierarchy'.



append w_fieldcatalog to i_fieldcatalog.
clear w_fieldcatalog.
w_fieldcatalog-col_pos = 
7.
w_fieldcatalog-tabname = 
'ty_t_list'.
w_fieldcatalog-fieldname = 
'WERKS'.
w_fieldcatalog-seltext_m = 
'plant'.



append w_fieldcatalog to i_fieldcatalog.
clear w_fieldcatalog.
w_fieldcatalog-col_pos = 
8.
w_fieldcatalog-tabname = 
'ty_t_list'.
w_fieldcatalog-fieldname = 
'EKGRP'.
w_fieldcatalog-seltext_m = 
'Purchasing Group'.

append w_fieldcatalog to i_fieldcatalog.
clear w_fieldcatalog.
w_fieldcatalog-col_pos = 
9.
w_fieldcatalog-tabname = 
'ty_t_list'.
w_fieldcatalog-fieldname = 
'LGORT'.
w_fieldcatalog-seltext_m = 
'Storage Location'.

append w_fieldcatalog to i_fieldcatalog.
clear w_fieldcatalog.


w_fieldcatalog-col_pos = 
10.
w_fieldcatalog-tabname = 
'ty_t_list'.
w_fieldcatalog-fieldname = 
'MAKTX'.
w_fieldcatalog-seltext_m = 
'Material Description'.

append w_fieldcatalog to i_fieldcatalog.
clear w_fieldcatalog.


  data: t_header 
type  slis_t_listheader,
  wa_header 
type slis_listheader,
  t_line 
like wa_header-info,
  id_lines 
type i,
  id_linesc(10) 
type c.

*title

  wa_header-typ = 
'H'.
wa_header-info = 
'Material Table Report'.
append wa_header to t_header.
clear wa_header.

*Date
wa_header-typ = 
'S'.
wa_header-key = 
'Date: '.
CONCATENATE sy-datum+6(2) '.'
sy-datum+4(2) 
'.'
sy-datum(4) 
INTO wa_header-info. "todays date
append wa_header to t_header.
clear: wa_header.





CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
 
EXPORTING
*   I_INTERFACE_CHECK                 = ' '
*   I_BYPASSING_BUFFER                = ' '
*   I_BUFFER_ACTIVE                   = ' '
   I_CALLBACK_PROGRAM                =  SY-REPID
*   I_CALLBACK_PF_STATUS_SET          = ' '
*   I_CALLBACK_USER_COMMAND           = ' '
   I_CALLBACK_TOP_OF_PAGE            = 
'SUB_TOP_OF_PAGE '
*   I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
*   I_CALLBACK_HTML_END_OF_LIST       = ' '
*   I_STRUCTURE_NAME                  =
*   I_BACKGROUND_ID                   = ' '
*   I_GRID_TITLE                      =
*   I_GRID_SETTINGS                   =
*   IS_LAYOUT                         =
   IT_FIELDCAT                       = i_fieldcatalog
*   IT_EXCLUDING                      =
*   IT_SPECIAL_GROUPS                 =
*   IT_SORT                           =
*   IT_FILTER                         =
*   IS_SEL_HIDE                       =
*   I_DEFAULT                         = 'X'
   I_SAVE                            = 
'X'
*   IS_VARIANT                        =
*   IT_EVENTS                         =
*   IT_EVENT_EXIT                     =
*   IS_PRINT                          =
*   IS_REPREP_ID                      =
*   I_SCREEN_START_COLUMN             = 0
*   I_SCREEN_START_LINE               = 0
*   I_SCREEN_END_COLUMN               = 0
*   I_SCREEN_END_LINE                 = 0
*   I_HTML_HEIGHT_TOP                 = 0
*   I_HTML_HEIGHT_END                 = 0
*   IT_ALV_GRAPHICS                   =
*   IT_HYPERLINK                      =
*   IT_ADD_FIELDCAT                   =
*   IT_EXCEPT_QINFO                   =
*   IR_SALV_FULLSCREEN_ADAPTER        =
* IMPORTING
*   E_EXIT_CAUSED_BY_CALLER           =
*   ES_EXIT_CAUSED_BY_USER            =
  
TABLES
    T_OUTTAB                          = i_list
* EXCEPTIONS
*   PROGRAM_ERROR                     = 1
*   OTHERS                            = 2
          .
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

perform sub_top_of_page.

form SUB_top_of_page.
  
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    
EXPORTING
      IT_LIST_COMMENTARY       = t_header
   I_LOGO                   = 
'AASHISH'
*     I_END_OF_LIST_GRID       =
*     I_ALV_FORM               =
            .

endform.