0% found this document useful (1 vote)
317 views

Reports Sap Abap

The document discusses different types of ABAP reports including classical reports, interactive reports, ALV reports, and LDB reports and describes the structure and events used in classical reports such as Initialization, Selection Screen, Start of Selection, End of Selection, Top of Page, and End of Page. Classical reports maintain output in a single basic list while interactive reports use multiple interactive lists, and events like AT LINE-SELECTION and GET CURSOR are used to navigate between lists in interactive reports.

Uploaded by

Ashutosh Jha
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
317 views

Reports Sap Abap

The document discusses different types of ABAP reports including classical reports, interactive reports, ALV reports, and LDB reports and describes the structure and events used in classical reports such as Initialization, Selection Screen, Start of Selection, End of Selection, Top of Page, and End of Page. Classical reports maintain output in a single basic list while interactive reports use multiple interactive lists, and events like AT LINE-SELECTION and GET CURSOR are used to navigate between lists in interactive reports.

Uploaded by

Ashutosh Jha
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 22

REPORTS

ABAP Reports:
In real time ABAP Reports are designed for analysis & based on the that
analysis decision making will done
In real time every report is designed based on certain format & every report
have 3 parts
1. Input
2. Processing Logic
3. Output

Selection-Screen Processing Logic Output

Databa
se

The reports that will designed up to now are without a proper structured format
Design the same reports in a proper structure format (with events)

Types of Reports:
1. Classical Reports
2. Interactive Reports
3. ALV Reports (ABAP List Viewer)
4. LDB Reports (Logical Data Base) ------- for HR module only
5. SAP Query Reports
Classical Reports:
In classical reporting the entire output is maintained in a single list called Basic
list

Events in Classical Reporting:


1. INITIALIZATION
2. AT SELECTION-SCREEN
3. START-OF-SELECTION
4. END-OF-SELECTION
5. TOP-OF-PAGE
6. END-OF-PAGE

INITIALIZATION:
It triggers before selection-screen display
Note:
Use this event for initializing
1. Default values in selection-screen
2. Texts on push buttons in selection-screen
3. Texts for blocks, radio buttons, check boxes…………..etc

AT SELECTION-SCREEN:
It triggers once the control leaves from selection-screen & still selection-screen
is in active mode
i.e. It triggers at end of PAI when all the values are passed from selection-screen
to program variables

It is further divided into 5 types


a) AT SELECTION-SCREEN OUTPUT
b) AT SELECTION-SCREEN ON <field name>
c) AT SELECTION-SCREEN ON VALUE-REQUEST
d) AT SELECTION-SCREEN ON HELP-REQUEST
e) AT SELECTION-SCREEN ON <radio button>

AT SELECTION-SCREEN OUTPUT:
 It triggers after initialization & before selection-screen display
 Use this event for modifying selection-screen

AT SELECTION-SCREEN ON <field name>:


It triggers once selection-screen is being processed & still the selection-screen is
in active mode

AT SELECTION-SCREEN ON VALUE-REQUEST:
 It triggers when you apply F4 function key on selection-screen fields
 Use this event for Search Help

AT SELECTION-SCREEN ON HELP-REQUEST:
 It triggers when you apply F1 function key on selection-screen fields
 Use this event for Help Documentation

AT SELECTION-SCREEN ON <radio button>:


It triggers when validating radio buttons

START-OF-SELECTION:

 This event will triggers once your selection-screen is processed


 It triggers when you select F8 function key
 It triggers before reading data from database
 It triggers for all processing blocks in a program
 It is a default event triggered before extracting data from database

Note:
In your program no need to provide this event
But when you are writing INITIALIZATION (or) AT SELECTION-SCREEN
it is mandatory to use START-OF-SELECTION

END-OF-SELECTION:
It triggers once all the data is read from logical database

Note:
Use this event in HR ABAP for displaying HR data
You can use this event for writing one time logics (Display data…………..etc)

TOP-OF-PAGE:
It triggers before 1st record is output in Output List

Note:
Use this event for maintaining headers in ABAP reports

END-OF-PAGE:
It triggers after last record is at output in the Output List

Note:
Use this event for maintaining footers in ABAP reports

Ques-1: Suppose there are 20 pages in my report. How many times


INITIALIZATION will triggers & TOP-OF-PAGE will triggers?
Ans:
INITIALIZATION will triggers only 1 time
TOP-OF-PAGE will triggers 20 times

Ques-2: What is LOAD-OF-PROGRAM event?


Ans:
This event will triggers before INITIALIZATION & once your program is
loaded into memory

Example:
*&---------------------------------------------------------------------*
*& Report  ZEVENT_PRAYAG
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT zevent_prayag.

TABLES:ekpo.

SELECTION-SCREEN: BEGIN   OF   BLOCK   b1   WITH   FRAME   TITLE   text-
000.
SELECT-OPTIONS: s_matnr   FOR   ekpo-matnr,
                s_werks   FOR   ekpo-werks.
SELECTION-SCREEN: END   OF   BLOCK   b1.

**********************************************************************
*  Structure Declare
**********************************************************************

TYPES: BEGIN   OF   ty_ekpo,
    ebeln   TYPE   ebeln,
    matnr   TYPE   matnr,
    menge   TYPE   menge_d,
    netpr   TYPE   netpr,
  END   OF   ty_ekpo.

TYPES: BEGIN   OF ty_t001w,
      werks   TYPE  werks_d,
    END OF ty_t001w.

TYPES: BEGIN   OF   ty_mara,
       matnr   TYPE matnr,
      END   OF   ty_mara.

**********************************************************************
*      Declare the workarea and internal table
**********************************************************************
 DATA: wa_ekpo   TYPE   ty_ekpo,
  wa_mara   TYPE   ty_mara,
  it_mara   TYPE   TABLE   OF   ty_mara,
  it_ekpo   TYPE   TABLE   OF   ty_ekpo,
  it_t001w   TYPE   TABLE   OF   ty_t001w.

 INITIALIZATION.

*s_werks-low  =  '1000'.
*s_werks-high  =  '1001'.
*s_werks-sign  =  'I'.
*s_werks-option  =  'BT'.
*APPEND  s_werks.

SELECT matnr FROM mara   INTO TABLE it_mara   WHERE   mtart   IN ('FERT').

 LOOP AT it_mara INTO wa_mara.
s_matnr-low  =  wa_mara-matnr.
s_matnr-sign  =  'I'.
s_matnr-option  =  'EQ'.
APPEND   s_matnr.
ENDLOOP.

AT  SELECTION-SCREEN   OUTPUT.  "" Event

LOOP  AT SCREEN.

IF
* screen-name   EQ   'S_WERKS-LOW'
*OR   screen-name   EQ   'S_WERKS-HIGH'
   screen-name   EQ   'S_MATNR-LOW'
OR   screen-name   EQ   'S_MATNR-HIGH'.
screen-input  =  0.
MODIFY   SCREEN.
ENDIF.
ENDLOOP.

AT   SELECTION-SCREEN   ON   s_werks.

  SELECT werks  FROM  t001w
    INTO   TABLE   it_t001w
      WHERE   werks   IN   s_werks.

    IF it_t001w IS INITIAL.
MESSAGE 'Invalid Plant' TYPE 'E'.
LEAVE LIST-PROCESSING.
    ENDIF.

START-OF-SELECTION.

SELECT  ebeln
        matnr
        menge
        netpr
    FROM   ekpo
    INTO   TABLE     it_ekpo
    WHERE   matnr  IN   s_matnr
    AND   werks   IN   s_werks.

  LOOP   AT   it_ekpo   INTO   wa_ekpo.
  WRITE:/10   wa_ekpo-ebeln,
    30   wa_ekpo-matnr,
    50   wa_ekpo-menge,
    70   wa_ekpo-netpr.
ENDLOOP.

TOP-OF-PAGE.
WRITE:/40  'PO Details Report'   COLOR   1.
SKIP.
ULINE.

END-OF-PAGE.
WRITE:/10   'page no', sy-pagno.

Ques: What is the flow of events?

Ans:
INITIALIZATION
AT SELECTION-SCREEN OUTPUT
START-OF-SELECTION
Interactive Reporting:
 In Classical Reporting the entire output is maintained in a single output
list called Basic List.
 In Interactive Reporting you will find N number of output lists called
Interactive Lists (or) Secondary Lists.
 In one interactive reporting you can maintain 20 secondary lists in
sequence.

AT LINE-SELECTION:
It triggers whenever user interacts with a list

HIDE Keyword:
It holds the records selected by user in interactive reporting

System Fields in Interactive Reporting:


1. SY-LSIND
2. SY-LISEL

SY-LSIND:
It returns current list index

SY-LISEL:
It returns list of contents selected by user from output list

GET CURSOR keyword:


It fetches the field name & value selected by user from output list

Syntax:
GET CURSOR FIELD <field name> VALUE <value>.
SAP Memory:
Using SAP memory concept we can transfer the data from ABAP program to
standard application

SET PARAMETER keyword:

Syntax:
SET PARAMETER ID <id> FIELD <value>.

Example:
SET PARAMETER ID ‘mat’ FIELD f001.

TOP-OF-PAGE DURING LINE-SELECTION event:


Use this event for providing Headers in interactive reporting
Object:
Invoice Details based on Customers

Input:
S_kunrg (so) ------ customer number
S_matnr (so)------- Material Number
S_werks (so)------- Plant
S_ekdat (so) --------- bill date

Output:
Basic list screen 0

Customer Customer Customer Customer Telephone


number name city street number
C001
C002

When you click on C001 then the control will goes to Interactive list 1
Interactive list 1
Bill number Bill date Material code Bill quantity Bill amount
400103 01.02.2019 100-101 150 120000
400104 10.10.2019 200-201 500 9500000
When you click on 200-201 then the control will goes to Interactive list 2
When you click 400103 on then the control will goes to T code VF03
Interactive list 2
Material code Material text Material type

VF03

Invoice number:
Solution:
Go to SE38
Program: ZSD_CUSTOMER_INVOICE_DETAILS
Create
Title: Customer Invoice Details Report
Type: Executable Program
Enter
Packge: ZABAP
Enter
*&---------------------------------------------------------------------*
*& Report  ZINTERACTIVE_PRAYAG
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT zinteractive_prayag.

TABLES: vbrk, vbrp, adrc, kna1.

SELECTION-SCREEN: BEGIN   OF   BLOCK   b1   WITH   FRAME   TITLE   text-
000.
SELECT-OPTIONS: s_kunrg    FOR   vbrk-kunrg,
                s_matnr   FOR   vbrp-matnr,
                s_werks   FOR   vbrp-werks,
                s_fkdat   FOR   vbrk-fkdat.
SELECTION-SCREEN: END      OF   BLOCK   b1.

**  Strucutre Declaration

TYPES: BEGIN   OF   ty_vbrk,
      vbeln   TYPE   vbeln_vf,
      fkdat    TYPE   fkdat,
      matnr   TYPE   matnr,
      fkimg   TYPE fkimg,
      netwr   TYPE   netwr,
    END   OF   ty_vbrk.

    TYPES: BEGIN   OF   ty_kna1,
          kunnr     TYPE   kunnr,  "" Cust No
          name1     TYPE   name1,   "" Cust Name
          city1     TYPE   ort01, "" city
          street    TYPE   stras, "" Street
          tel_number TYPE  ad_tlnmbr,"" Tel Number
     END  OF   ty_kna1.

TYPES: BEGIN   OF   ty_mara,
      matnr    TYPE  matnr,
      maktx    TYPE  maktx,
      mtart    TYPE  mtart,
    END   OF   ty_mara.
** Declare the workarea and internal table

DATA: wa_mara  TYPE   ty_mara,
      wa_vbrk  TYPE   ty_vbrk,
      wa_kna1  TYPE   ty_kna1,
      it_mara  TYPE   TABLE   OF   ty_mara,
      it_vbrk  TYPE   TABLE   OF   ty_vbrk,
      it_kna1  TYPE   TABLE   OF   ty_kna1.

* Declare the local variable as per the requirement
DATA: v_kunnr      TYPE   kunnr,
      v_matnr         TYPE   matnr,
      v_fnam(20)   TYPE   c,
      v_fval(20)     TYPE   c.

START-OF-SELECTION.

SELECT   kna1~kunnr
         kna1~name1
         adrc~city1
         adrc~street
         adrc~tel_number
         FROM   kna1  INNER   JOIN   adrc
         ON   kna1~adrnr = adrc~addrnumber
         INTO   TABLE   it_kna1
         WHERE   kna1~kunnr IN s_kunrg.

WRITE: /10 'Customer Number',
        30 'Customer Name',
        60 'Customer City',
        80 'Customer Street',
        100 'Customer Tel Number'.
SKIP.
ULINE.

LOOP   AT   it_kna1   INTO   wa_kna1.
WRITE:/10   wa_kna1-kunnr   HOTSPOT,
       30   wa_kna1-name1,
       60   wa_kna1-city1,
       80   wa_kna1-street,
       100  wa_kna1-tel_number.
ENDLOOP.

AT LINE-SELECTION.

  CASE sy-lsind.
    WHEN '1'.
      GET CURSOR FIELD v_fnam   VALUE v_kunnr.

        IF v_fnam = 'WA_KNA1-KUNNR'.
          CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
            EXPORTING
              input         = v_kunnr
           IMPORTING
             output        = v_kunnr
                    .

 SELECT  vbrk~vbeln
         vbrk~fkdat
         vbrp~matnr
         vbrp~fkimg
         vbrp~netwr
         FROM vbrk INNER JOIN vbrp
         ON vbrk~vbeln  = vbrp~vbeln
        INTO   TABLE   it_vbrk
        WHERE  vbrk~kunrg   EQ  v_kunnr
        AND   vbrp~werks   IN   s_werks
        AND vbrk~fkdat    IN    s_fkdat.

        LOOP   AT   it_vbrk   INTO  wa_vbrk.
       WRITE:/10   wa_vbrk-vbeln   HOTSPOT,
              30   wa_vbrk-fkdat,
              50   wa_vbrk-matnr    HOTSPOT,
              70   wa_vbrk-fkimg,
              90   wa_vbrk-netwr.
         ENDLOOP.

        ENDIF.

    WHEN '2'.
    GET CURSOR FIELD v_fnam VALUE v_matnr.

IF v_fnam = 'WA_VBRK-MATNR'.
  SELECT   mara~matnr
           makt~maktx
           mara~mtart
           FROM mara INNER JOIN makt
          ON   mara~matnr  =  makt~matnr
         INTO   TABLE   it_mara
         WHERE   mara~matnr   EQ   v_matnr
        AND    makt~spras    EQ  'EN'.

        LOOP   AT   it_mara   INTO   wa_mara.
           WRITE:/10  wa_mara-matnr,
             40   wa_mara-maktx,
             60   wa_mara-mtart.
        ENDLOOP.

ELSEIF v_fnam = 'WA_VBRK-VBELN'.

  GET  CURSOR   FIELD v_fnam VALUE v_fval.

SET  PARAMETER   ID 'VF'   FIELD  v_fval.

CALL   TRANSACTION  'VF03' .""AND SKIP FIRST  SCREEN.

ENDIF.

    WHEN OTHERS.
  ENDCASE.

TOP-OF-PAGE   DURING   LINE-SELECTION.

CASE   sy-lsind.
WHEN   1.
WRITE:/50 'Customer Invoice Details'   COLOR   1.
SKIP.
ULINE.

WHEN   2.
WRITE:/50   'Materials Details'   COLOR   3.
SKIP.
ULINE.
ENDCASE.

ALV Reporting:
ABAP List Viewer
ALV is advanced reporting with additional features of reporting

Advantages of ALV:
1. In traditional reporting you cannot maintain logos (pictures…………etc)
With ALV reporting you can maintain logos using ALV Function
Modules
2. With ALV reporting you can improve performance of programming by
avoiding LOOP…..ENDLOOP
3. Using ALV reporting you can maintain Main Headings, Sub
Headings……….etc
4. The main features of reporting are
i) Exporting Data
ii) Totals
iii) Sub Totals
iv) Filtering
v) Column Alignment
vi) Sorting ……………….etc

The above features requires large amount of coding with traditional reporting
Using ALV Function Modules you can minimize such coding

1. Layout Management
With traditional reporting you cannot select output fields dynamically (no
layout management)
Suppose in a company there are 10 departments & each department users
requires different fields from the same report
Using layout management you can create & save his own layout

2. Using ALV reporting you can maintain data in Tabular format

Simple ALV:
These are classified into 2 categories
1. Classical ALV
2. Interactive ALV

Classical ALV:

Object:
Open PO Details Report

Solution:
Go to SE38
Program: ZMM_PO_STATUS_DETAILS
Create
Title: PO Status Report
Type: Executable Program
Enter
Package: ZABAP
Enter

TABLES: LFA1, EKKO, EKET.

TYPE-POOLS    SLIS.

SELECTION-SCREEN: BEGIN   OF   BLOCK   b1   WITH   FRAME   TITLE   TEXT-
000.
SELECT-OPTIONS: S_lifnr      FOR   lfa1-lifnr,
           S_bukrs   FOR   ekko-bukrs,
           S_bedat    FOR  ekko-bedat.
SELECTION-SCREEN: END       OF    BLOCK   b1.

TYPES: BEGIN    OF   ty_final,
       Ebeln   TYPE   ebeln,
       bedat    TYPE   bedat,
       eindt     TYPE   eindt,
       lifnr      TYPE   lifnr,
       name1   TYPE   name1,
       menge   TYPE   menge_D,
       wemng  TYPE   wemng,
       open      TYPE   menge_D,
       status     TYPE   maktx,
       END        OF   ty_final.

TYPES: BEGIN    OF   ty_ekko,
       Ebeln   TYPE   ebeln,
       bedat    TYPE   bedat,
       lifnr      TYPE   lifnr,
       END        OF   ty_ekko.

TYPES: BEGIN    OF   ty_lfa1,
       lifnr      TYPE   lifnr,
       name1   TYPE   name1,
       END        OF   ty_lfa1.

TYPES: BEGIN    OF   ty_eket,
       Ebeln   TYPE   ebeln,
       eindt     TYPE   eindt,
       menge   TYPE   menge_D,
       wemng  TYPE   wemng,
       END        OF   ty_eket.

DATA: wa_ekko   TYPE   ty_ekko,
     wa_lfa1     TYPE   ty_lfa1,
     wa_eket     TYPE   ty_eket,
     wa_final    TYPE   ty_final,
     it_ekko      TYPE   TABLE   OF   ty_ekko,
     it_lfa1        TYPE   TABLE   OF   ty_lfa1,
     it_eket       TYPE   TABLE   OF   ty_eket,
     it_final      TYPE   TABLE   OF   ty_final.

* provide ALV declaration
DATA: WA_FCAT          TYPE   SLIS_FIELDCAT_ALV,
              WA_LAYOUT   TYPE   SLIS_LAYOUT_ALV,
              IT_FCAT            TYPE   SLIS_T_FIELDCAT_ALV.

PERFORM   get_ekko.
PERFORM   get_lfa1.
PERFORM   get_eket.
PERFORM   fill_cat.
PERFORM   combine_data.
PERFORM   layout.
PERFORM   display.

FORM   get_ekko.
SELECT   ebeln   bedat   lifnr   FROM   EKKO   INTO   TABLE   it_ekko
WHERE   lifnr     IN   s_lifnr
AND        bukrs   IN   s_bukrs
AND        bedat   IN   s_bedat.
ENDFORM.

FORM    get_lfa1.
IF   it_ekko   IS   NOT   INITIAL.
SELECT   lifnr   name1   FROM   LFA1   INTO   TABLE   it_lfa1
FOR   ALL   ENTRIES   IN   it_ekko
WHERE   lifnr  =  it_ekko-lifnr.
ENDIF.
ENDFORM.

FORM    get_eket.
IF   it_ekko   IS   NOT   INITIAL.
SELECT   ebeln   menge   wemng   FROM   EKET   INTO   TABLE   it_eket
FOR   ALL   ENTRIES   IN   it_ekko
WHERE   ebeln  =  it_ekko-ebeln.
ENDIF.
ENDFORM.

FORM   combine_data.
LOOP   AT   it_eket   INTO   wa_eket.
wa_final-ebeln  =  wa_eket-ebeln.
wa_final-eindt  =  wa_eket-eindt.
wa_final-menge  =  wa_eket-menge.
wa_final-wemng  =  wa_eket-wemng.
wa_final-open  =  wa_eket-menge  -  wa_eket-wemng.

IF   wa_eket-menge   GT   wa_eket-wemng.
wa_final-status  =  'Not delivered'.
ELSE.
wa_final-status  =  'delivered'.
ENDIF.
READ   TABLE   it_ekko   INTO   wa_ekko   WITH   KEY   ebeln  =  wa_eket-
ebeln.
IF sy-subrc = 0.

wa_final-lifnr  =  wa_ekko-lifnr.
wa_final-bedat  =  wa_ekko-bedat.

ENDIF.

READ   TABLE   it_lfa1   INTO   wa_lfa1   WITH   KEY   lifnr  =  wa_ekko-
lifnr.
IF sy-subrc = 0 .

wa_final-name1  =  wa_lfa1-name1.

ENDIF.
APPEND   wa_final   TO   it_final.
ENDLOOP.
ENDFORM.

FORM   fill_cat.
WA_FCAT-FIELDNAME  =  'EBELN'.
WA_FCAT-SELTEXT_M  =  'PO Number'.
APPEND   WA_FCAT   TO   IT_FCAT.

WA_FCAT-FIELDNAME  =  'EINDT'.
WA_FCAT-SELTEXT_M  =  'Delivery date'.
APPEND   WA_FCAT   TO   IT_FCAT.

WA_FCAT-FIELDNAME  =  'lifnr'.
WA_FCAT-SELTEXT_M  =  'Vendor Number'.
APPEND   WA_FCAT   TO   IT_FCAT.

WA_FCAT-FIELDNAME  =  'NAME1'.
WA_FCAT-SELTEXT_M  =  'Vendor name'.
APPEND   WA_FCAT   TO   IT_FCAT.

WA_FCAT-FIELDNAME  =  'MENGE'.
WA_FCAT-SELTEXT_M  =  'Quantity'.
APPEND   WA_FCAT   TO   IT_FCAT.

WA_FCAT-FIELDNAME  =  'WEMNG'.
WA_FCAT-SELTEXT_M  =  'Delivery Quantitý'.
APPEND   WA_FCAT   TO   IT_FCAT.

WA_FCAT-FIELDNAME  = 'open'.
WA_FCAT-SELTEXT_M  =  'Open quantity'.
APPEND   WA_FCAT   TO   IT_FCAT.

WA_FCAT-FIELDNAME  =  'status'.
WA_FCAT-SELTEXT_M  =  'Status'.
APPEND   WA_FCAT   TO   IT_FCAT.
ENDFORM.

FORM layout.

WA_LAYOUT-ZEBRA  =  'X'.
WA_LAYOUT-COLWIDTH_OPTIMIZE  =  'X'.

ENDFORM.

FORM   display.
CALL   FUNCTION  'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM  =  SY-REPID            "" ----- it returns current pro
gram name
IS_LAYOUT                           =  WA_LAYOUT
IT_FIELDCAT                        =  IT_FCAT
I_SAVE                                   =  'X'
TABLES
T_OUTTAB                            =  it_final.
ENDFORM.
Note: SLIS_LAYOUT_ALV is a standard SLIS structure for maintaining
layout settings for ALV reporting
It is having following fields
1. ZEBRA --------- alternate colors
2. COLWIDTH _OPTIMIZE ------- it will optimize the width of field
catalog automatically
based on domain length

Interactive ALV:

Object

Display list of materials for a material type with below options.


1. Add a hotspot for material number.
2. Whenever user double click on any material no, it should go to MM03
transaction to display material.

REPORT ztest453.

TYPE-POOLS SLIS .
TYPES : BEGIN OF TY_MARA,  "User defined internal table type
        MATNR TYPE MARA-MATNR,
        MTART TYPE MARA-MTART,
        MBRSH TYPE MARA-MBRSH,
        MEINS TYPE MARA-MEINS,
      END OF TY_MARA.

DATA : IT_MARA TYPE TABLE OF TY_MARA ."internal table
DATA : WA_MARA TYPE TY_MARA . "work area

DATA : IT_FCAT TYPE SLIS_T_FIELDCAT_ALV . "field catalog table
DATA : WA_FCAT LIKE LINE OF IT_FCAT . "field catalog work area

PARAMETERS : P_MTART TYPE MARA-MTART. "material type input

START-OF-SELECTION.
**get table data
  SELECT MATNR MTART MBRSH MEINS FROM MARA "get data from MARA
      INTO TABLE IT_MARA UP TO 50 ROWS
      WHERE MTART = P_MTART.
*** generate field catalogue
  WA_FCAT-COL_POS = '1' . "column position
  WA_FCAT-FIELDNAME = 'MATNR' . "column name
  WA_FCAT-TABNAME = 'IT_MARA' . "table
  WA_FCAT-SELTEXT_M = 'Material' . "Column label
  WA_FCAT-KEY = 'X' . "is a key field
  WA_FCAT-HOTSPOT = 'X' . "Set hotspot for matnr
  APPEND WA_FCAT TO IT_FCAT . "append to fcat
  CLEAR WA_FCAT .
  WA_FCAT-COL_POS = '2' .
  WA_FCAT-FIELDNAME = 'MBRSH' .
  WA_FCAT-TABNAME = 'IT_MARA' .
  WA_FCAT-SELTEXT_M = 'Industry Sec' .
  APPEND WA_FCAT TO IT_FCAT .
  CLEAR WA_FCAT .

  WA_FCAT-COL_POS = '3' .
  WA_FCAT-FIELDNAME = 'MTART' .
  WA_FCAT-TABNAME = 'IT_MARA' .
  WA_FCAT-SELTEXT_M = 'Material Type' .
  APPEND WA_FCAT TO IT_FCAT .
  CLEAR WA_FCAT .

  WA_FCAT-COL_POS = '4' .
  WA_FCAT-FIELDNAME = 'MEINS' .
  WA_FCAT-TABNAME = 'IT_MARA' .
  WA_FCAT-SELTEXT_M = 'Base.Unit' .
  WA_FCAT-REF_TABNAME = 'MARA' .
  APPEND WA_FCAT TO IT_FCAT .
  CLEAR WA_FCAT .
**display ALV
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      I_CALLBACK_PROGRAM      = SY-REPID
      I_CALLBACK_USER_COMMAND = 'USER_COMMAND' "user command form
      IT_FIELDCAT             = IT_FCAT "PASS FIELD CATALOG TO ALV
    TABLES
      T_OUTTAB                = IT_MARA. "output table

**for to handle user command
FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
                        RS_SELFIELD TYPE SLIS_SELFIELD.
  CASE R_UCOMM.
    WHEN '&IC1'. "standard Function code for doubel click
      READ TABLE IT_MARA INTO WA_MARA INDEX RS_SELFIELD-TABINDEX.
      IF SY-SUBRC = 0.
        SET PARAMETER ID 'MAT' FIELD WA_MARA-MATNR. "set parameter id
        CALL TRANSACTION 'MM03' AND SKIP FIRST SCREEN. "call transaction
      ENDIF.
  ENDCASE.
ENDFORM.                    "user_command

Blocked ALV:

Requirement:

Develop a blocked list ALV to display list of materials for a material type and
also display material descriptions in another grid.

Analysis: 
For this requirement, we need to add one input parameter for material type, we
need to get materials from MARA, and from MAKT and display in two list
ALV`s using ALV blocked display.

Blocked list ALV is used to display multiple ALV`s on the same screen with
blocks.

List of Function Modules used for blocked list ALV

 REUSE_ALV_BLOCK_LIST_INIT
 REUSE_ALV_BLOCK_LIST_APPEND
 REUSE_ALV_BLOCK_LIST_DISPLAY

REUSE_ALV_BLOCK_LIST_INIT: is used to initialize blocked list ALV.

REUSE_ALV_BLOCK_LIST_APPEND: is used to add blocked list ALV's(we


can add multiple).

REUSE_ALV_BLOCK_LIST_DISPLAY: is used to display blocked list ALV.

TYPES: BEGIN OF TY_MARA, "user defined type for mara
        MATNR TYPE MARA-MATNR,
        MTART TYPE MARA-MTART,
        MBRSH TYPE MARA-MBRSH,
        MATKL TYPE MARA-MATKL,
        MEINS TYPE MARA-MEINS,
      END OF TY_MARA.
DATA : IT_MARA TYPE TABLE OF TY_MARA, "mara internal table
       WA_MARA TYPE TY_MARA. "mara work area
DATA : T_FCAT TYPE SLIS_T_FIELDCAT_ALV. "field catalog for MARA table
DATA : W_FCAT LIKE LINE OF T_FCAT.

TYPES: BEGIN OF TY_MAKT, "user defined type for MAKT
        MATNR TYPE MAKT-MATNR,
        SPRAS TYPE MAKT-SPRAS,
        MAKTX TYPE MAKT-MAKTX,
      END OF TY_MAKT.
DATA : IT_MAKT TYPE TABLE OF TY_MAKT, "makt internal table
       WA_MAKT TYPE TY_MAKT.
DATA : T_FCAT_MAKT TYPE SLIS_T_FIELDCAT_ALV. "makt field catalog
DATA : W_FCAT_MAKT LIKE LINE OF T_FCAT_MAKT.
PARAMETERS : P_MTART TYPE MARA-MTART. "material type input

START-OF-SELECTION.

  SELECT MATNR
         MTART
         MBRSH
         MATKL
         MEINS FROM MARA "get MARA data
    INTO TABLE IT_MARA UP TO 10 ROWS WHERE MTART = P_MTART.
  IF NOT IT_MARA IS INITIAL .
    SELECT MATNR
           SPRAS
           MAKTX FROM MAKT INTO TABLE IT_MAKT "get makt data
      FOR ALL ENTRIES IN IT_MARA WHERE MATNR = IT_MARA-MATNR.
  ENDIF.
***build fcat for MARA
  W_FCAT-COL_POS       = '1'. "coloum position
  W_FCAT-FIELDNAME     = 'MATNR'. "column name
  W_FCAT-TABNAME       = 'IT_MARA'. "table
  W_FCAT-REF_TABNAME   = 'MARA'. "table
  W_FCAT-REF_FIELDNAME = 'MATNR'. "referance field, it will show descripti
ons automatically
  APPEND W_FCAT TO T_FCAT.
  CLEAR W_FCAT.

  W_FCAT-COL_POS       = '2'.
  W_FCAT-FIELDNAME     = 'MTART'.
  W_FCAT-TABNAME       = 'IT_MARA'.
  W_FCAT-REF_TABNAME   = 'MARA'.
  W_FCAT-REF_FIELDNAME = 'MTART'.
  APPEND W_FCAT TO T_FCAT.
  CLEAR W_FCAT.

  W_FCAT-COL_POS       = '3'.
  W_FCAT-FIELDNAME     = 'MBRSH'.
  W_FCAT-TABNAME       = 'IT_MARA'.
  W_FCAT-REF_TABNAME   = 'MARA'.
  W_FCAT-REF_FIELDNAME = 'MBRSH'.
  APPEND W_FCAT TO T_FCAT.
  CLEAR W_FCAT.

  W_FCAT-COL_POS       = '4'.
  W_FCAT-FIELDNAME     = 'MATKL'.
  W_FCAT-TABNAME       = 'IT_MARA'.
  W_FCAT-REF_TABNAME   = 'MARA'.
  W_FCAT-REF_FIELDNAME = 'MATKL'.
  APPEND W_FCAT TO T_FCAT.
  CLEAR W_FCAT.

  W_FCAT-COL_POS       = '5'.
  W_FCAT-FIELDNAME     = 'MEINS'.
  W_FCAT-TABNAME       = 'IT_MARA'.
  W_FCAT-REF_TABNAME   = 'MARA'.
  W_FCAT-REF_FIELDNAME = 'MEINS'.
  APPEND W_FCAT TO T_FCAT.
  CLEAR W_FCAT.

***build fcat for MAKT
  W_FCAT_MAKT-COL_POS       = '1'.
  W_FCAT_MAKT-FIELDNAME     = 'MATNR'.
  W_FCAT_MAKT-TABNAME       = 'IT_MAKT'.
  W_FCAT_MAKT-REF_TABNAME   = 'MAKT'.
  W_FCAT_MAKT-REF_FIELDNAME = 'MATNR'.
  APPEND W_FCAT_MAKT TO T_FCAT_MAKT.
  CLEAR W_FCAT_MAKT.
  W_FCAT_MAKT-COL_POS       = '2'.
  W_FCAT_MAKT-FIELDNAME     = 'SPRAS'.
  W_FCAT_MAKT-TABNAME       = 'IT_MAKT'.
  W_FCAT_MAKT-REF_TABNAME   = 'MAKT'.
  W_FCAT_MAKT-REF_FIELDNAME = 'SPRAS'.
  APPEND W_FCAT_MAKT TO T_FCAT_MAKT.
  CLEAR W_FCAT_MAKT.
  W_FCAT_MAKT-COL_POS       = '3'.
  W_FCAT_MAKT-FIELDNAME     = 'MAKTX'.
  W_FCAT_MAKT-TABNAME       = 'IT_MAKT'.
  W_FCAT_MAKT-REF_TABNAME   = 'MAKT'.
  W_FCAT_MAKT-REF_FIELDNAME = 'MAKTX'.
  APPEND W_FCAT_MAKT TO T_FCAT_MAKT.
  CLEAR W_FCAT_MAKT.
*  * init
  CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT' "initialize Block List ALV
    EXPORTING
      I_CALLBACK_PROGRAM = SY-REPID.

  DATA S_EVENTS TYPE SLIS_T_EVENT.
  DATA S_LAYOUT TYPE SLIS_LAYOUT_ALV.
  S_LAYOUT-ZEBRA = 'X'.
  CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND' "append ALV lists
    EXPORTING
      IS_LAYOUT   = S_LAYOUT "set layout
      IT_FIELDCAT = T_FCAT "set field catalog
      I_TABNAME   = 'IT_MARA' "table
      IT_EVENTS   = S_EVENTS "events
*     IT_SORT     =
*     I_TEXT      = ' '
    TABLES
      T_OUTTAB    = IT_MARA "out put table
*   EXCEPTIONS
*     PROGRAM_ERROR                    = 1
*     MAXIMUM_OF_APPENDS_REACHED       = 2
*     OTHERS      = 3
    .
  IF SY-SUBRC <> 0.
* Implement suitable error handling here
  ENDIF.

  CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND' "append ALV lists
    EXPORTING
      IS_LAYOUT   = S_LAYOUT "set layout
      IT_FIELDCAT = T_FCAT_MAKT "set field catalog
      I_TABNAME   = 'IT_MAKT' "table
      IT_EVENTS   = S_EVENTS "events
*     IT_SORT     =
*     I_TEXT      = ' '
    TABLES
      T_OUTTAB    = IT_MAKT "out put table
*   EXCEPTIONS
*     PROGRAM_ERROR                    = 1
*     MAXIMUM_OF_APPENDS_REACHED       = 2
*     OTHERS      = 3
    .
  IF SY-SUBRC <> 0.
* Implement suitable error handling here
  ENDIF.
  CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY' . "display blocked list

You might also like