Sunday, April 7, 2013

0 Alv Interactive Reports In ABAP


Alv Interactive Reports In ABAP Example 
Creating alv – classical report in real time senorio
Create pgm in se 38


here I am going to paste the code wt ever we have to write in se 38
* ---------------------------------------------------------------------*
* Report  ZALV_INTARACTIVE
* Program Name      :
* Author            :
* Description       :
* Creation Date     :
* Last Changed      :
* Transport Req No  :
* Version           :
* ---------------------------------------------------------------------*

REPORT  zalv_intaractive NO STANDARD PAGE HEADING MESSAGE-ID zkmsg.

*// Initialization Event
INITIALIZATION.

*// Include program for Data type declaration
  
INCLUDE zalvdata_declaration.

*// Include program for Subroutines
  
INCLUDE zlav_subroutines.

START-
OF-SELECTION.

*// Subroutine for Purchase Order details
  
PERFORM f_purchasedata.

*// Subroutine for Fieldcatlog
  
PERFORM f_fieldcatlog.

*// Subroutine for Populate data
  
PERFORM f_populate_data.

*// Subroutine for Display Output
  
PERFORM f_display_output.
Double click on zalvdata_declaration
*// Type Pools declaration
TYPE-POOLS slis.

*// Table declaration.
TABLES : ekko,ekpo.

*// Types declaration for ekko.
TYPES : BEGIN OF ty_ekko,
        ebeln 
TYPE  ebeln,
        bukrs 
TYPE  bukrs,
        bstyp 
TYPE  ebstyp,
        bsart 
TYPE  esart,
        
END OF ty_ekko.

*// Types declaration for ekpo.
TYPES : BEGIN OF ty_ekpo,
        ebeln 
TYPE  ebeln,
        ebelp  
TYPE ebelp,
        loekz  
TYPE eloek,
        statu  
TYPE astat,
        aedat  
TYPE paedt,
        
END OF ty_ekpo.

*// Types declaration for final internal table.
TYPES : BEGIN OF ty_final,
        ebeln 
TYPE  ebeln,
        bukrs 
TYPE  bukrs,
        bstyp 
TYPE  ebstyp,
        bsart 
TYPE  esart,
        ebelp  
TYPE ebelp,
        loekz  
TYPE eloek,
        statu  
TYPE astat,
        aedat  
TYPE paedt,
        
END OF ty_final.

*// Internal table declaration.
DATA : lt_ekko     TYPE TABLE OF ty_ekko,
       lt_ekpo     
TYPE TABLE OF ty_ekpo,
       lt_final    
TYPE TABLE OF ty_final,
       lt_fieldcat 
TYPE slis_t_fieldcat_alv.



*// Workarea declaration.
DATA : wa_ekko     TYPE ty_ekko,
       wa_ekpo     
TYPE ty_ekpo,
       wa_final    
TYPE ty_final,
       wa_fieldcat 
TYPE slis_fieldcat_alv.

*// lOCAL sTRUCTURE DECLARATION
DATA : ls_layout TYPE slis_layout_alv.

*// Selection screen design.
SELECTION-
SCREEN : BEGIN OF BLOCK blk1 WITH FRAME.
SELECT-OPTIONS : s_ebeln FOR ekko-ebeln.
SELECTION-
SCREEN : END OF BLOCK blk1.
*// radio Button Creation
SELECTION-
SCREEN : BEGIN OF BLOCK blk2 WITH FRAME TITLE text-100.
PARAMETERS : p_rad1 RADIOBUTTON GROUP rad1,
             p_rad2 
RADIOBUTTON GROUP rad1.
SELECTION-
SCREEN : END OF BLOCK blk2.
Double click on INCLUDE zlav_subroutines.
It contains 4 subcourtines
  • PERFORM f_purchasedata.
  • PERFORM f_fieldcatlog.
  • PERFORM f_populate_data.
  • PERFORM f_display_output.

*&---------------------------------------------------------------------*
*&  Include           ZLAV_SUBROUTINES
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  f_fieldcatlog
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM f_fieldcatlog .
*// PO Number
  wa_fieldcat-col_pos   = 
1.
  wa_fieldcat-fieldname = 
'EBELN'.
  wa_fieldcat-outputlen = 
10.
  wa_fieldcat-seltext_m = 
'PO NUMBER'.
  
APPEND wa_fieldcat TO lt_fieldcat.
  
CLEAR wa_fieldcat.

*// Company Code
  wa_fieldcat-col_pos   = 
2.
  wa_fieldcat-fieldname = 
'BUKRS'.
  wa_fieldcat-outputlen = 
15.
  wa_fieldcat-seltext_m = 
'COMPANY CODE'.
  
APPEND wa_fieldcat TO lt_fieldcat.
  
CLEAR wa_fieldcat.

*// Category
  wa_fieldcat-col_pos   = 
3.
  wa_fieldcat-fieldname = 
'BSTYP'.
  wa_fieldcat-outputlen = 
10.
  wa_fieldcat-seltext_m = 
'CATEGORY'.
  
APPEND wa_fieldcat TO lt_fieldcat.
  
CLEAR wa_fieldcat.

*// Document Type
  wa_fieldcat-col_pos   = 
4.
  wa_fieldcat-fieldname = 
'BSART'.
  wa_fieldcat-outputlen = 
15.
  wa_fieldcat-seltext_m = 
'DOCUMENT TYPE'.
  
APPEND wa_fieldcat TO lt_fieldcat.
  
CLEAR wa_fieldcat.

*// PO Item
  wa_fieldcat-col_pos   = 
5.
  wa_fieldcat-fieldname = 
'EBELP'.
  wa_fieldcat-outputlen = 
10.
  wa_fieldcat-seltext_m = 
'PO ITEM'.
  
APPEND wa_fieldcat TO lt_fieldcat.
  
CLEAR wa_fieldcat.

*// Indicator
  wa_fieldcat-col_pos   = 
6.
  wa_fieldcat-fieldname = 
'LOEKZ'.
  wa_fieldcat-outputlen = 
10.
  wa_fieldcat-seltext_m = 
'Indicator'.
  
APPEND wa_fieldcat TO lt_fieldcat.
  
CLEAR wa_fieldcat.

*// Status
  wa_fieldcat-col_pos   = 
7.
  wa_fieldcat-fieldname = 
'STATU'.
  wa_fieldcat-outputlen = 
10.
  wa_fieldcat-seltext_m = 
'Status'.
  
APPEND wa_fieldcat TO lt_fieldcat.
  
CLEAR wa_fieldcat.

*// Date
  wa_fieldcat-col_pos   = 
8.
  wa_fieldcat-fieldname = 
'AEDAT'.
  wa_fieldcat-outputlen = 
10.
  wa_fieldcat-seltext_m = 
'DATE'.
  
APPEND wa_fieldcat TO lt_fieldcat.
  
CLEAR wa_fieldcat.
ENDFORM.                    " f_fieldcatlog
*&---------------------------------------------------------------------*
*&      Form  f_populate_data
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM f_populate_data .
*// populating the data into final internal table.
  
LOOP AT lt_ekko INTO wa_ekko.
    
READ TABLE lt_ekpo INTO wa_ekpo WITH KEY ebeln  = wa_ekko-ebeln.
    wa_final-ebeln = wa_ekko-ebeln.
    wa_final-bukrs = wa_ekko-bukrs.
    wa_final-bstyp = wa_ekko-bstyp.
    wa_final-bsart = wa_ekko-bsart.
    wa_final-ebelp = wa_ekpo-ebelp.
    wa_final-loekz = wa_ekpo-loekz.
    wa_final-statu = wa_ekpo-statu.
    wa_final-aedat = wa_ekpo-aedat.
    
APPEND wa_final TO lt_final.
    
CLEAR wa_final.
  
ENDLOOP.
ENDFORM.                    " f_populate_data
*&---------------------------------------------------------------------*
*&      Form  f_purchasedata
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM f_purchasedata .
*// Selection screen frield validation
  
IF s_ebeln IS NOT INITIAL.
*// Retrive the data from ekko.
    
SELECT ebeln bukrs bstyp bsart
           
FROM ekko INTO TABLE lt_ekko
           
WHERE ebeln IN s_ebeln.

*// Retrive the data from ekpo.
    
SELECT ebeln ebelp loekz statu aedat
           
FROM ekpo
           
INTO TABLE lt_ekpo
           
FOR ALL ENTRIES IN lt_ekko
           
WHERE ebeln EQ lt_ekko-ebeln.
  
ELSE.
    
MESSAGE i006.
  
ENDIF.
ENDFORM.                    " f_purchasedata
*&---------------------------------------------------------------------*
*&      Form  f_display_output
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM f_display_output .
  
IF p_rad1 EQ 'X'.
*// Display output LIST format
    
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
      
EXPORTING
        i_callback_program      = sy-repid
        i_callback_user_command = 
'F_USER_COMMAND'
        is_layout               = ls_layout
        it_fieldcat             = lt_fieldcat
      
TABLES
        t_outtab                = lt_final
      
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.

  
ELSEIF p_rad2 EQ 'X'.

*// Display Output in GRID format
    
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
      
EXPORTING
        i_callback_program      = sy-repid
        i_callback_user_command = 
'F_USER_COMMAND' “(THIS WILL WE NEED TO
        is_layout               = ls_layout         
CODE WHICH IS BELO”)
        it_fieldcat             = lt_fieldcat
      
TABLES
        t_outtab                = lt_final
      
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.

  
ELSE.
    
EXIT.
  
ENDIF.
ENDFORM.                    " f_display_output

*// Subroutine for ALV Intaractive
FORM f_user_command USING ucomm    TYPE sy-ucomm
                          selfield 
TYPE slis_selfield.
  
CASE ucomm.
    
WHEN '&IC1'.
*     Read data table, using index of row user clicked on
      
READ TABLE lt_final INTO wa_final INDEX selfield-tabindex.
*     Set parameter ID for transaction screen field
      
SET PARAMETER ID 'BES' FIELD wa_final-ebeln.
*     Sxecute transaction ME23N, and skip initial data entry screen
      
CALL TRANSACTION 'ME23N' AND SKIP FIRST SCREEN.
    
WHEN OTHERS.
      
LEAVE TO SCREEN 0.
  
ENDCASE.

ENDFORM.                    "f_user_command

Save , check , activate , and pree f8, you will see o/p like this.


 Execute list display





 Display grid o/p
IF WE NEED A HISTORY FOR PO NUMBER 30000006, CAN WE DOUBLE CLOCK ON THAT NUMBER THEN WE FIND A NEW TRIGGER WINDOW LIKE THIS.
THIS IS THE ADDITIONAL INFORMATION WE WILL OBTAIN COMPARE TO ALV NORMAL REPORT.


 

SAP-ABAP Copyright © 2011 - |- Template created by Vishnu - |- Powered by Blogger Templates