Monday, 4 June 2012

Tutorial on Interactive Reports in ALV List/Grid

Here is the Interactive Report for ALV's.


Below code contains few Function Modules related to ALV's.
Just go through the below code where i have mentioned proper comments. Which helps you to make your work easy.


REPORT  ZALV_INTERACTIVE_REPORT2.

*//TABLES DECLARATION
TABLES: MARA.

*// FUNCTION GROUP TO HOLD ALV EVENTS
TYPE-POOLS: SLIS.

*//TYPES DECLARATION FOR MARA TABLE
TYPES: BEGIN OF TY_MARA,
       MATNR TYPE MARA-MATNR,"MATERIAL NUMBER
       ERSDA TYPE MARA-ERSDA,"CREATED ON
       ERNAM TYPE MARA-ERNAM,"CREATED BY
       END   OF TY_MARA.

DATA: IT_MARA TYPE STANDARD TABLE OF TY_MARA,
      WA_MARA TYPE TY_MARA.

*//TYPES DECLARATION FOR MARC TABLE
TYPES: BEGIN OF TY_MARC,
       MATNR TYPE MARC-MATNR,"MATERIAL NUMBER
       WERKS TYPE MARC-WERKS,"PLANT
       PSTAT TYPE MARC-PSTAT,"STATUS
       END   OF TY_MARC.

DATA: IT_MARC TYPE STANDARD TABLE OF TY_MARC,
      WA_MARC TYPE TY_MARC.

*//DECLARATIONS FOR FIELDCATALOGS
DATA: IT_FCAT1 TYPE SLIS_T_FIELDCAT_ALV,
      WA_FCAT1 TYPE SLIS_FIELDCAT_ALV.

DATA: IT_FCAT2 TYPE SLIS_T_FIELDCAT_ALV,
      WA_FCAT2 TYPE SLIS_FIELDCAT_ALV.

*//VARIABLE TO HOLD REPORT NAME
*//USED IN FUNCTION MODULE REUSE_ALV_GRID_DISPLAY
DATA: V_REPID TYPE SY-REPID VALUE 'ZALV_INTERACTIVE_REPORT2'.

*//TABLE AND WORKAREA FOR CATCHING EVENTS
*//USED IN FUNCTION MODULE REUSE_ALV_EVENTS_GET
DATA: IT_EVENTS TYPE SLIS_T_EVENT,
      WA_EVENTS TYPE SLIS_ALV_EVENT.

*//ALV LIST HEADER
*//USED IN FUNCTION MODULE REUSE_ALV_COMMENTRY_WRITE
DATA: IT_LISTHEADER1 TYPE SLIS_T_LISTHEADER,
      IT_LISTHEADER2 TYPE SLIS_T_LISTHEADER.

*//VARIABLES FOR READING DOUBLE CLICK EVENTS
DATA: R_UCOMM TYPE SY-UCOMM,
      RS_SELFIELD TYPE SLIS_SELFIELD.

*//VARIABLES FOR DISPLAYING ALV GRID TITLE
DATA:  I_TITLE_MARA TYPE LVC_TITLE VALUE 'FIRST LIST DISPLAYED'.
DATA:  I_TITLE_MARC TYPE LVC_TITLE VALUE 'SECONDARY LIST DISPLAYED'.
DATA:  v_layout TYPE slis_layout_alv.
DATA: MATNR_VAL TYPE MARA-MATNR.

SELECT-OPTIONS: S_MATNR FOR MARA-MATNR.

START-OF-SELECTION.
V_REPID = SY-REPID.
PERFORM BUILD_VALUES.     "RETRIEVING DATA
PERFORM BUILD_FCAT.       "FILLING FIELD CATALOG
PERFORM TOP_OF_PAGE.      "TOP OF PAGE
PERFORM GET_EVENTS.       "RETRIEVING EVENTS IN OUR REPORT
PERFORM POPULATE_EVENTS.  "POPULATING THE REQUIRED EVENTS
PERFORM DISPLAY_FCAT.     "DISPLAYING FIELDCATALOG
PERFORM USER_COMMAND USING R_UCOMM RS_SELFIELD.  "FOR LINE SELECTION


*&---------------------------------------------------------------------*
*&      Form  BUILD_VALUES
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form BUILD_VALUES .
SELECT MATNR ERSDA ERNAM
       FROM MARA
       INTO TABLE IT_MARA
       WHERE MATNR IN S_MATNR.
endform.                    " BUILD_VALUES
*&---------------------------------------------------------------------*
*&      Form  BUILD_FCAT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form BUILD_FCAT .
  WA_FCAT1-TABNAME = 'IT_MARA'.
  WA_FCAT1-FIELDNAME = 'MATNR'.
  WA_FCAT1-SELTEXT_M = 'MATERIAL NO'.
  APPEND WA_FCAT1 TO IT_FCAT1.
  CLEAR WA_FCAT1.
  WA_FCAT1-TABNAME = 'IT_MARA'.
  WA_FCAT1-FIELDNAME = 'ERSDA'.
  WA_FCAT1-SELTEXT_M = 'CREATED ON'.
  APPEND WA_FCAT1 TO IT_FCAT1.
  CLEAR WA_FCAT1.
  WA_FCAT1-TABNAME = 'IT_MARA'.
  WA_FCAT1-FIELDNAME = 'ERNAM'.
  WA_FCAT1-SELTEXT_M = 'CREATED BY'.
  APPEND WA_FCAT1 TO IT_FCAT1.
  CLEAR WA_FCAT1.
endform.                    " BUILD_FCAT

*&---------------------------------------------------------------------*
*&      Form  TOP_OF_PAGE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form TOP_OF_PAGE .
DATA: WA_LISTHEADER TYPE SLIS_LISTHEADER.

*//HEADER TEXT
WA_LISTHEADER-INFO =  'ALV REPORT FOR MATERIALS'.
WA_LISTHEADER-TYP  =  'H'.
APPEND WA_LISTHEADER TO IT_LISTHEADER1.
CLEAR WA_LISTHEADER.

*//SUB-ITEMS
WA_LISTHEADER-TYP  =  'S'.
WA_LISTHEADER-KEY  =  'DATE: '.
WA_LISTHEADER-INFO =  SY-DATUM.
APPEND WA_LISTHEADER TO IT_LISTHEADER1.
CLEAR WA_LISTHEADER.

WA_LISTHEADER-TYP  =  'S'.
WA_LISTHEADER-KEY  =  'TIME: '.
WA_LISTHEADER-INFO =  SY-UZEIT.
APPEND WA_LISTHEADER TO IT_LISTHEADER1.
CLEAR WA_LISTHEADER.

WA_LISTHEADER-TYP  =  'S'.
WA_LISTHEADER-KEY  =  'EXECUTED BY: '.
WA_LISTHEADER-INFO =  SY-UNAME.
APPEND WA_LISTHEADER TO IT_LISTHEADER1.
CLEAR WA_LISTHEADER.

  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      it_list_commentary       = IT_LISTHEADER1
     I_LOGO                    = 'VENKAT_LOGO'
*     I_END_OF_LIST_GRID       =
*     I_ALV_FORM               =
            .
  REFRESH IT_LISTHEADER1.
endform.                    " TOP_OF_PAGE

*&---------------------------------------------------------------------*
*&      Form  DISPLAY_FCAT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form DISPLAY_FCAT .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
   EXPORTING
     i_callback_program                = v_repid
     i_callback_user_command           = 'USER_COMMAND'
     i_callback_top_of_page            = 'TOP_OF_PAGE'
    I_GRID_TITLE                       = I_TITLE_MARA
     is_layout                         = v_layout
     it_fieldcat                       = it_fcat1
*     IS_VARIANT                        = VARIANT
*     I_SAVE                            = 'U'
    IT_EVENTS                          = IT_EVENTS
    TABLES
      t_outtab                          = IT_MARA
 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_FCAT
*&---------------------------------------------------------------------*
*&      Form  GET_EVENTS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form GET_EVENTS .
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
 EXPORTING
   I_LIST_TYPE           = 0
 IMPORTING
   ET_EVENTS             = IT_EVENTS
 EXCEPTIONS
   LIST_TYPE_WRONG       = 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.                    " GET_EVENTS
*&---------------------------------------------------------------------*
*&      Form  POPULATE_EVENTS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form POPULATE_EVENTS .
READ TABLE IT_EVENTS INTO WA_EVENTS WITH KEY NAME = 'TOP_OF_PAGE'.
IF SY-SUBRC EQ 0.
  WA_EVENTS-FORM = 'TOP_OF_PAGE'.
  MODIFY IT_EVENTS FROM WA_EVENTS
         TRANSPORTING FORM WHERE NAME = WA_EVENTS-NAME.
  CLEAR WA_EVENTS.
ENDIF.

READ TABLE IT_EVENTS INTO WA_EVENTS WITH KEY NAME = 'USER_COMMAND'.
IF SY-SUBRC EQ 0.
  WA_EVENTS-FORM = 'USER_COMMAND'.
  MODIFY IT_EVENTS FROM WA_EVENTS
         TRANSPORTING FORM WHERE NAME = WA_EVENTS-NAME.
  CLEAR WA_EVENTS.
ENDIF.
endform.                    " POPULATE_EVENTS
*&---------------------------------------------------------------------*
*&      Form  USER_COMMAND
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_R_UCOMM  text
*      -->P_TYPE  text
*      -->P_SY_UCOMM  text
*      -->P_RS_SELFIELD  text
*      -->P_TYPE  text
*      -->P_SLIS_SELFIELD  text
*----------------------------------------------------------------------*
form USER_COMMAND  using    R_UCOMM RS_SELFIELD TYPE SLIS_SELFIELD .
CASE R_UCOMM.
  WHEN '&IC1'.
      IF RS_selfield-FIELDNAME = 'MATNR'.
       READ TABLE IT_MARA INTO WA_MARA INDEX RS_selfield-tabindex.
       MOVE RS_SELFIELD-VALUE TO MATNR_VAL.
       ENDIF.
    PERFORM BUILD_VALUES_MARC.
    PERFORM BUILD_FCAT_MARC.
    PERFORM TOP_OF_PAGE_MARC.
    PERFORM GET_EVENTS_MARC.
    PERFORM POPULATE_EVENTS_MARC.
    PERFORM DISPLAY_FCAT_MARC.
ENDCASE.
REFRESH IT_FCAT2.
endform.                    " USER_COMMAND
*&---------------------------------------------------------------------*
*&      Form  BUILD_FCAT_MARC
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form BUILD_FCAT_MARC .
  WA_FCAT1-TABNAME = 'IT_MARC'.
  WA_FCAT1-FIELDNAME = 'MATNR'.
  WA_FCAT1-SELTEXT_M = 'MATERIAL NUMBER'.
  APPEND WA_FCAT1 TO IT_FCAT2.
  CLEAR WA_FCAT1.
  WA_FCAT1-TABNAME = 'IT_MARC'.
  WA_FCAT1-FIELDNAME = 'WERKS'.
  WA_FCAT1-SELTEXT_M = 'PLANT'.
  APPEND WA_FCAT1 TO IT_FCAT2.
  CLEAR WA_FCAT1.
  WA_FCAT1-TABNAME = 'IT_MARC'.
  WA_FCAT1-FIELDNAME = 'PSTAT'.
  WA_FCAT1-SELTEXT_M = 'STATUS'.
  APPEND WA_FCAT1 TO IT_FCAT2.
  CLEAR WA_FCAT1.

endform.                    " BUILD_FCAT_MARC
*&---------------------------------------------------------------------*
*&      Form  BUILD_VALUES_MARC
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form BUILD_VALUES_MARC .
REFRESH IT_MARC.
  SELECT SINGLE  MATNR WERKS PSTAT
         FROM MARC
         INTO WA_MARC
         WHERE MATNR = MATNR_VAL.
APPEND WA_MARC TO IT_MARC.
CLEAR WA_MARC.
endform.                    " BUILD_VALUES_MARC
*&---------------------------------------------------------------------*
*&      Form  TOP_OF_PAGE_MARC
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form TOP_OF_PAGE_MARC .
DATA: WA_LISTHEADER1 TYPE SLIS_LISTHEADER.
REFRESH IT_LISTHEADER1.
WA_LISTHEADER1-INFO =  'ALV REPORT FOR PLANTS'.
WA_LISTHEADER1-TYP  =  'H'.
APPEND WA_LISTHEADER1 TO IT_LISTHEADER2.
CLEAR  WA_LISTHEADER1.

WA_LISTHEADER1-TYP  =  'S'.
WA_LISTHEADER1-KEY  =  'DATE: '.
WA_LISTHEADER1-INFO =  SY-DATUM.
APPEND WA_LISTHEADER1 TO IT_LISTHEADER2.
CLEAR WA_LISTHEADER1.

WA_LISTHEADER1-TYP  =  'S'.
WA_LISTHEADER1-KEY  =  'TIME: '.
WA_LISTHEADER1-INFO =  SY-UZEIT.
APPEND WA_LISTHEADER1 TO IT_LISTHEADER2.
CLEAR WA_LISTHEADER1.

WA_LISTHEADER1-TYP  =  'S'.
WA_LISTHEADER1-KEY  =  'EXECUTED BY: '.
WA_LISTHEADER1-INFO =  SY-UNAME.
APPEND WA_LISTHEADER1 TO IT_LISTHEADER2.
CLEAR WA_LISTHEADER1.

  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      it_list_commentary       = IT_LISTHEADER2
      I_LOGO                   = 'VENKAT_LOGO'
*     I_END_OF_LIST_GRID       =
*     I_ALV_FORM               =
            .
  REFRESH IT_LISTHEADER2.
endform.                    " TOP_OF_PAGE_MARC
*&---------------------------------------------------------------------*
*&      Form  GET_EVENTS_MARC
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form GET_EVENTS_MARC .
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
 EXPORTING
   I_LIST_TYPE           = 0
 IMPORTING
   ET_EVENTS             = IT_EVENTS
 EXCEPTIONS
   LIST_TYPE_WRONG       = 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.                    " GET_EVENTS_MARC
*&---------------------------------------------------------------------*
*&      Form  POPULATE_EVENTS_MARC
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form POPULATE_EVENTS_MARC .
READ TABLE IT_EVENTS INTO WA_EVENTS WITH KEY NAME = 'TOP_OF_PAGE'.
IF SY-SUBRC EQ 0.
  WA_EVENTS-FORM = 'TOP_OF_PAGE_MARC'.
  MODIFY IT_EVENTS FROM WA_EVENTS
         TRANSPORTING FORM WHERE NAME = WA_EVENTS-NAME.
  CLEAR WA_EVENTS.
ENDIF.

endform.                    " POPULATE_EVENTS_MARC
*&---------------------------------------------------------------------*
*&      Form  DISPLAY_FCAT_MARC
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form DISPLAY_FCAT_MARC .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
   EXPORTING
     i_callback_program                = v_repid
     i_callback_top_of_page            = 'TOP_OF_PAGE_MARC'
    I_GRID_TITLE                      = I_TITLE_MARC
     is_layout                         = v_layout
     it_fieldcat                       = it_fcat2
    TABLES
      t_outtab                          = IT_MARC
 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_FCAT_MARC


------------------------------------------------------------------------------------------------------------      
           NOTE: If you have any queries, leave comments so that i acn get back to you.
           Thanks.
------------------------------------------------------------------------------------------------------------


Interactive Report Tutorial in SAP-ABAP

Here is the Tutorial which gives you clear picture about Interactive reports.


In this tutorial we are going to use 3 Database tables:
MARA 
MARC & 
MARD


And few select queries for retrieving data from the database tables.
We are going to make use of few Interactive Report events like 
AT-LINE-SELECTION


Here is the piece of code snippet which helps you to explore even more.


*&---------------------------------------------------------------------*
*& Report  ZINTERACTIVE_REPORT_SAP
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZINTERACTIVE_REPORT_SAP LINE-SIZE 145.

INITIALIZATION.
*//TYPES DECLARATION FOR MARA TABLE
TYPES: BEGIN OF   TY_MARA,
       MATNR TYPE MARA-MATNR, "MATERIAL NUMBER
       ERSDA TYPE MARA-ERSDA, "CREATED ON
       ERNAM TYPE MARA-ERNAM, "CREATED BY
       LAEDA TYPE MARA-LAEDA, "LAST CHANGE ON
       MTART TYPE MARA-MTART, "MATERIAL TYPE
       MATKL TYPE MARA-MATKL, "MATERIAL GROUP
       MEINS TYPE MARA-MEINS, "MATERIAL GROUP
       END   OF   TY_MARA.

DATA: IT_MARA TYPE STANDARD TABLE OF TY_MARA,
      WA_MARA TYPE TY_MARA.

*//TYPES DECLARATION FOR MARD TABLE
TYPES: BEGIN OF   TY_MARD,
       MATNR TYPE MARD-MATNR, "MATERIAL NUMBER
       LGORT TYPE MARD-LGORT, "STORAGE LOCATION
       WERKS TYPE MARD-WERKS, "PLANT
       END   OF   TY_MARD.

DATA: IT_MARD TYPE STANDARD TABLE OF TY_MARD,
      WA_MARD TYPE TY_MARD.

*//TYPES DECLARATION FOR MAKT TABLE
TYPES: BEGIN OF   TY_MAKT,
       MATNR TYPE MAKT-MATNR, "MATERIAL NUMBER
       MAKTG TYPE MAKT-MAKTG, "DESCRIPTION
       END   OF   TY_MAKT.

DATA: IT_MAKT TYPE STANDARD TABLE OF TY_MAKT,
      WA_MAKT TYPE TY_MAKT.


*//TYPES DECLARATION FOR FINAL TABLE
TYPES: BEGIN OF   TY_FINAL,
       MATNR TYPE MARA-MATNR, "MATERIAL NUMBER
       ERSDA TYPE MARA-ERSDA, "CREATED ON
       ERNAM TYPE MARA-ERNAM, "CREATED BY
       LAEDA TYPE MARA-LAEDA, "LAST CHANGE ON
       MTART TYPE MARA-MTART, "MATERIAL TYPE
       MATKL TYPE MARA-MATKL, "MATERIAL GROUP
       MEINS TYPE MARA-MEINS, "MATERIAL GROUP
       LGORT TYPE MARD-LGORT, "STORAGE LOCATION
       WERKS TYPE MARD-WERKS, "PLANT
       END   OF   TY_FINAL.

DATA: IT_FINAL TYPE STANDARD TABLE OF TY_FINAL,
      WA_FINAL TYPE TY_FINAL.

*//PARAMETERS FOR RETRIEVING DATA
*//BASED ON PLANT AND STORAGE LOC

PARAMETERS: P_PLANT TYPE MARD-WERKS, "PLANT
            P_STOR  TYPE MARD-LGORT. "STORAGE LOCATION


START-OF-SELECTION.

*//RETRIEVING DATA FROM MARD TABLE
SELECT MATNR LGORT WERKS
        FROM MARD
        INTO TABLE IT_MARD
       WHERE LGORT EQ P_STOR
         AND WERKS = P_PLANT.

*//CHECK WHETHER IT_MARD HAS DATA OR NOT
IF IT_MARD IS NOT INITIAL.
  SELECT MATNR MAKTG
         FROM MAKT
         INTO TABLE IT_MAKT
         FOR ALL ENTRIES IN IT_MARD
         WHERE MATNR EQ IT_MARD-MATNR
           AND SPRAS EQ 'E'.
ENDIF.

*//CHECK WHETHER IT_MAKT HAS DATA OR NOT
IF IT_MAKT IS NOT INITIAL.
  SELECT MATNR ERSDA ERNAM LAEDA MTART MATKL MEINS
         FROM MARA
         INTO TABLE IT_MARA
         FOR ALL ENTRIES IN IT_MAKT
         WHERE MATNR EQ IT_MAKT-MATNR.
ENDIF.


END-OF-SELECTION.

LOOP AT IT_MAKT INTO WA_MAKT.
  WRITE: /1 WA_MAKT-MATNR COLOR 1 HOTSPOT ON,
         40 WA_MAKT-MAKTG COLOR 5.
  HIDE WA_MAKT-MATNR.
ENDLOOP.

AT LINE-SELECTION.
REFRESH IT_FINAL.
CLEAR WA_FINAL.
ULINE.

IF SY-LSIND = 1.
  WRITE:     /1 SY-VLINE,  'MATERIAL NO' COLOR 2,
             22 SY-VLINE, 'CREATED ON' COLOR 3,
             34 SY-VLINE, 'CREATED BY',
             52 SY-VLINE, 'DATE OF LIST' ,
             67 SY-VLINE, 'MATERIALTYPE',
             82 SY-VLINE, 'MATGROUP' ,
             92 SY-VLINE, 'UNITOFMEASURE',
             112 SY-VLINE, 'STORLOCATION' COLOR 4,
             132 SY-VLINE, 'PLANT' COLOR 5,
             145 SY-VLINE.
  ULINE.
ENDIF.

LOOP AT IT_MARA INTO WA_MARA WHERE MATNR EQ WA_MAKT-MATNR.
  WA_FINAL-MATNR = WA_MARA-MATNR.
  WA_FINAL-ERSDA = WA_MARA-ERSDA.
  WA_FINAL-ERNAM = WA_MARA-ERNAM.
  WA_FINAL-LAEDA = WA_MARA-LAEDA.
  WA_FINAL-MTART = WA_MARA-MTART.
  WA_FINAL-MATKL = WA_MARA-MATKL.
  WA_FINAL-MEINS = WA_MARA-MEINS.

  READ TABLE IT_MARD INTO WA_MARD WITH KEY MATNR = WA_MAKT-MATNR.

  WA_FINAL-LGORT = WA_MARD-LGORT.
  WA_FINAL-WERKS = WA_MARD-WERKS.
  APPEND WA_FINAL TO IT_FINAL.
  CLEAR WA_FINAL.
ENDLOOP.

LOOP AT IT_FINAL INTO WA_FINAL.
  WRITE:     /1 SY-VLINE,  WA_FINAL-MATNR COLOR 2,
             22 SY-VLINE, WA_FINAL-ERSDA COLOR 3,
             34 SY-VLINE, WA_FINAL-ERNAM,
             52 SY-VLINE, WA_FINAL-LAEDA,
             67 SY-VLINE, WA_FINAL-MTART,
             82 SY-VLINE, WA_FINAL-MATKL,
             92 SY-VLINE, WA_FINAL-MEINS,
             112 SY-VLINE, WA_FINAL-LGORT COLOR 4,
             132 SY-VLINE, WA_FINAL-WERKS COLOR 5,
             145 SY-VLINE.
ENDLOOP.
ULINE.
TOP-OF-PAGE.
WRITE: /1 'MATERIAL NUMBER' COLOR 1,
       40 'MATERIAL DESCRIPTION' COLOR 5.
ULINE.


Ways to Declare Internal Table in SAP-ABAP

Internal Table Definition:
                                         Internal Table is a collection of fields which are of different types.Where we can store multiple records at a time.
The data in the internal table is going to be stored for temporary.


Here are the few ways of declaring Internal tables:



*&---------------------------------------------------------------------*
*& Report  ZINT_TAB_DECLARATIONS
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZINT_TAB_DECLARATIONS.

*// INTERNAL TABLE DECLARATION BY REFERRING STANDARD DATABASE TABLE
DATA: IT_MARA TYPE STANDARD TABLE OF MARA WITH HEADER LINE.

*// DECLARING INTERNAL TABLE BY USING INCLUDE STRUCTURE
DATA: BEGIN OF IT_MARA1 OCCURS 0.
      INCLUDE STRUCTURE MARA.
DATA:  END   OF IT_MARA1.

*// DECLARING INTERNAL TABLE BY USING TYPES DECLARATION
TYPES: BEGIN OF TY_MARA,
       MATNR TYPE MARA-MATNR,
       ERSDA TYPE MARA-ERSDA,
       END   OF TY_MARA.

DATA: IT_MARA2 TYPE STANDARD TABLE OF TY_MARA.


*// INTERNAL TABLE DECLARATION BY USING NORMAL METHOD
DATA:  BEGIN OF IT_MARA3 OCCURS 0,
       MATNR TYPE MARA-MATNR,
       ERSDA TYPE MARA-ERSDA,
       END   OF IT_MARA3.

Ways to Declare Workarea/Structure in SAP-ABAP

Definition Of Structure or Workarea:


                          Structure/Workarea is a collection of fields which can be of different datatypes. And we can store maximum of one record at a time.


Data Storage in workarea is temporary.


 Few ways of declaring Workarea/Structure are:


*&---------------------------------------------------------------------*
*& Report  ZWA_DECLARATION_TYPES
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZWA_DECLARATION_TYPES.

*// WORK AREA DECLARATION BY REFERRING STANDARD DATABASE TABLE
DATA: WA_MARA TYPE MARA.

*// DECLARING WORKAREA BY USING INCLUDE STRUCTURE
DATA: BEGIN OF WA_MARA1.
             INCLUDE STRUCTURE MARA.
DATA:  END   OF WA_MARA1.

*// DECLARING WORKAREA BY USING TYPES DECLARATION
TYPES: BEGIN OF TY_MARA,
              MATNR TYPE MARA-MATNR,
              ERSDA TYPE MARA-ERSDA,
              END   OF TY_MARA.

DATA: WA_MARA2 TYPE TY_MARA.


*// WORKAREA DECLARATION BY USING NORMAL METHOD
DATA:  BEGIN OF WA_MARA3,
              MATNR TYPE MARA-MATNR,
              ERSDA TYPE MARA-ERSDA,
              END   OF WA_MARA3.


Saturday, 2 June 2012

Basic Programming Guide Lines to be followed

What is the use of it ? 


Whenever we are developing any report we have to follow certain terminologies(it's not must but for best practice and professionals follow this). So, that it will be helpful for us in future to make any changes. Also, it will be helpful for fellow mates to understand the whole purpose of the report and in future it will be helpful for them to make changes.


Basis Guidelines:


-> Always use comment lines *&----------&*
Before developing the report at the top mention the purpose of the report.
Like:
*& The purpose of this Report is to fetch &*
*& Data from MARA Table                      &*  
Report ZMARA.


While declaring Internal Tables, Work areas specify the table names.
Like: 
*// Internal Table to hold MARA fields
DATA: IT_MARA TYPE STANDARD TABLE OF TY_MARA.


Write comments for every field.
Like:
*// Types declaration for MARA Table //*
Types: Begin of ty_mara,
            matnr type mara-matnr    "Material Number
            ersda  type mara-ersda     "Created On
            End of ty_mara.
Also, please use comment lines before declaring any functionmodules etc.
---------------------------------------------------------------------------------
NOTE: The above mentioned data is according to my understanding and knowledge.


If you want to add anything please leave comments. So, that it will be helpful for the readers.
Thanks.



   



SAP R3 Architecture - Sapgui, Application server and Database server

SAP is having a 3 tier (R3) client-server architecture, which consists of :

  • Presentation Server
  • Application  Server
  • Database Server

Presentation Server:      Actually presentation server is  a program named sapgui.exe, which is usually installed on user's workstation.
This program is responsible for sending all the user inputs to the application server and for retrieving the data from the application server and also it displays the screens.

To start it, user should double click on it. 
Sap Logon


Application Server: Application Server is responsible for interpreting the ABAP/4 programs. It consists of many executable programs which gets started automatically whenever the application server gets started.


Each application server has a profile that specifies its characteristics when it start ups and when it is running.

An Application server profile mainly contains:

  • Number and type of each process.
  • Amount of memory used for each process.
  • Length of time a user is inactive before being automatically logged off.


Database Server:   The database server consists of several executable files to process the requests from Application server. After processing the requests these requests are passed to RDBMS (Relational Database Management System). RDBMS will send the data back to the database server and database server will forward this data to the Application server. This Application server inturn passes the data to the ABAP/4 program.



  





History of SAP



What is SAP?


SAP stands for -
  
  " Systems, Applications and Products in Data Processing "


Founded in1972 by 5 Ex-IBM engineers.


What is it's purpose?


Purpose: It creates a common centralized database for all the applications running in an organization. The application has been assembled in such a way that it handles all the functional departments within an organization.


                  Today major companies including Microsoft and IBM are using SAP's products to run their own businesses.