Display Alv Report With Header and Item
Display Alv Report With Header and Item
Declaration part:
*&---------------------------------------------------------------------*
*& Include ZI17_INC_PURCHASE_STR
*&---------------------------------------------------------------------*
TYPE-POOLS: slis.
*--------------------------------------------------------------------------
----------
TABLES: ekko, "Purchade order Header table
ekpo. "Purchase order item table
*--------------------------------------------------------------------------
------------
"Declaring the Structures
TYPES: BEGIN OF ty_ekpo_pur,
ebeln TYPE ebeln, "Purchase document number
ebelp TYPE ebelp, "Item document nummber
menge TYPE bstmg, "Quantity
werks TYPE ewerk, "Plant
lgort TYPE lgort_d, "Storage Locations
aedat TYPE aedat, "Document item change date
netpr TYPE netpr, "Net price
netwr TYPE netwr, "Net order values
maktx TYPE maktx, "Material description
matnr TYPE matnr, "Material number
END OF ty_ekpo_pur.
*--------------------------------------------------------------------------
------
*Declaring the internal tables and work areas
DATA: itab_ekko TYPE TABLE OF ZSKKO, "Internal table for purchas
e header table
wa_ekko TYPE ZSKKO. "Worka area for purchase he
ader table
"Field catalog
DATA: itab_fieldcat TYPE slis_t_fieldcat_alv, "internal table
wa_fieldcat TYPE slis_fieldcat_alv. "WOrk area
*--------------------------------------------------------------------------
---------
DATA: w_repid LIKE sy-repid. "Current program
"Local variables
DATA: lv_date_con(15) TYPE c,
lv_tdate TYPE d.
w_repid = sy-repid.
*--------------------------------------------------------------------------
-----------------------------
logic :
*& Include ZI17_INC_PURCHASE_BL
*&---------------------------------------------------------------------*
ELSE.
MESSAGE 'Pls fill all the fields' TYPE 'I'. "Exceptions
ENDIF.
ENDIF.
ENDIF.
*&---------------------------------------------------------------------*
*& Form USER-COMMAND
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM user-
command USING "Subroutine
r_ucmmd LIKE sy-
ucomm "User command
rs_selfield TYPE slis_selfield. "Selec
t field
CASE r_ucmmd. "Check th
e value for user command
WHEN '&IC1' .
IF rs_selfield-tabindex > 0 AND rs_selfield-
sumindex LE 0. "Table index is not equal to zero
"Clear the internl table and work area
CLEAR: wa_cons_ekpo,
itab_cons_ekpo.
"Read the internl table for purchasing header
READ TABLE itab_ekko INTO wa_ekko INDEX rs_selfield-tabindex.
IF sy-
subrc = 0. "Condtions for previous statement executed successfully
SORT itab_ekpo. "Sort the table
LOOP AT itab_ekpo INTO wa_ekpo WHERE ebeln = wa_ekko-
ebeln . "Start Loop
READ TABLE itab_ekpo INTO wa_ekpo WITH KEY ebeln = wa_ekpo-
ebeln. "Read the table purchase item document
IF sy-
subrc = 0."Condtions for previous statement executed successfully
SORT itab_makt. "Sort internal table
READ TABLE itab_makt INTO wa_makt WITH KEY matnr = wa_ekpo-
matnr. "Read the table for material description
IF sy-
subrc = 0."Condtions for previous statement executed successfully
wa_cons_ekpo-ebeln = wa_ekpo-ebeln.
wa_cons_ekpo-ebelp = wa_ekpo-ebelp.
wa_cons_ekpo-menge = wa_ekpo-menge.
wa_cons_ekpo-werks = wa_ekpo-werks.
wa_cons_ekpo-lgort = wa_ekpo-lgort.
wa_cons_ekpo-aedat = wa_ekpo-aedat.
wa_cons_ekpo-netpr = wa_ekpo-netpr.
wa_cons_ekpo-netwr = wa_ekpo-netwr.
wa_cons_ekpo-maktx = wa_makt-maktx.
wa_cons_ekpo-matnr = wa_makt-matnr.
APPEND wa_cons_ekpo TO itab_cons_ekpo. "Append the values
to consolidated table
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDCASE. "End case
* WRITE:'hello'.
ENDFORM.
Print:
*&---------------------------------------------------------------------*
*& Include ZI17_INC_PURCHASE_RPT
*&---------------------------------------------------------------------*
*PERFORM firstreport.
*&---------------------------------------------------------------------*
*& Form FIRSTREPORT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM firstreport .
"Append the Field catalog
wa_fieldcat-fieldname = 'EBELN'. "Fieldname
wa_fieldcat-
seltext_m = 'Purchase document Number'. "Field short descriptions
wa_fieldcat-hotspot = 'X'.
APPEND wa_fieldcat TO itab_fieldcat. "Append the f
ield catalog from work area into internal table
CLEAR: wa_fieldcat.
wa_fieldcat-fieldname = 'BSART'.
wa_fieldcat-seltext_m = 'Purcahse doc type'.
APPEND wa_fieldcat TO itab_fieldcat.
CLEAR: wa_fieldcat.
wa_fieldcat-fieldname = 'AEDAT'.
wa_fieldcat-seltext_m = 'Date of Record created'.
APPEND wa_fieldcat TO itab_fieldcat.
CLEAR: wa_fieldcat.
wa_fieldcat-fieldname = 'BEDAT'.
wa_fieldcat-seltext_m = 'Purchase Doc date'.
APPEND wa_fieldcat TO itab_fieldcat.
CLEAR: wa_fieldcat.
wa_fieldcat-fieldname = 'ERNAM'.
wa_fieldcat-seltext_m = 'Name of the person'.
APPEND wa_fieldcat TO itab_fieldcat.
CLEAR: wa_fieldcat.
wa_fieldcat-fieldname = 'LIFNR'.
wa_fieldcat-seltext_m = 'Customer Number'.
APPEND wa_fieldcat TO itab_fieldcat.
CLEAR: wa_fieldcat.
wa_fieldcat-fieldname = 'EKORG'.
wa_fieldcat-seltext_m = 'Purchase Org.'.
APPEND wa_fieldcat TO itab_fieldcat.
CLEAR: wa_fieldcat.
wa_fieldcat-fieldname = 'BKGRP'.
wa_fieldcat-seltext_m = 'Purchase Group'.
APPEND wa_fieldcat TO itab_fieldcat.
CLEAR: wa_fieldcat.
wa_fieldcat-fieldname = 'ANGNR'.
wa_fieldcat-seltext_m = 'Quotation Number'.
APPEND wa_fieldcat TO itab_fieldcat.
*&---------------------------------------------------------------------*
*& Form SECONDOUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM secondoutput . "Second output of the ALV Grid
report
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'EBELP'.
wa_fieldcat-emphasize = 'C666'.
wa_fieldcat-seltext_m = 'Item doc Number'.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'MENGE'.
wa_fieldcat-seltext_m = 'Quantity'.
* wa_fieldcat-do_sum = 'X'.
APPEND wa_fieldcat TO itab_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'WEKRS'.
wa_fieldcat-seltext_m = 'Plant'.
APPEND wa_fieldcat TO itab_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'LGORT'.
wa_fieldcat-seltext_m = 'Storage Location'.
APPEND wa_fieldcat TO itab_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'AEDAT'.
wa_fieldcat-seltext_m = 'Doc Item Change Date'.
APPEND wa_fieldcat TO itab_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'MATNR'.
wa_fieldcat-seltext_m = 'Material Number'.
APPEND wa_fieldcat TO itab_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'MAKTX'.
wa_fieldcat-seltext_m = 'Material Description'.
APPEND wa_fieldcat TO itab_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'NETPR'.
wa_fieldcat-seltext_m = 'Net price'.
* wa_fieldcat-do_sum = 'X'.
APPEND wa_fieldcat TO itab_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'NETWR'.
wa_fieldcat-seltext_m = 'Net order values'.
"Sort the report values based on the purchase item document number
wa_sort-spos = 1.
wa_sort-fieldname = 'EBELN'.
wa_sort-up = 'X'.
wa_sort-group = 'X'.
wa_sort-subtot = 'X'.
APPEND wa_sort TO itab_sort. "Append the sort work area values
*PERFORM TOP-OF-PAGE.
*&---------------------------------------------------------------------*
*& Form TOP-OF-PAGE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM top-of-
page. "Header for the ALV Grid report
"Clear the internla table and work area
CLEAR: wa_header,
itab_header.
wa_header-typ = 'H'. "Font Size
wa_header-info = 'VIDHAI TECHNOLOGIES PVT LTD,..'. "Header title
APPEND wa_header TO itab_header.
CLEAR: wa_header.
wa_header-typ = 'S'.
wa_header-info = lv_date_con.
APPEND wa_header TO itab_header.
*PERFORM top-of-page1.
*&---------------------------------------------------------------------*
*& Form TOP-OF-PAGE1
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM top-of-page1.
CLEAR: wa_header,
itab_header.
wa_header-typ = 'H'. "Font Size
wa_header-
info = 'VIDHAI TECHNOLOGIES, BAWA ROAD, CHENNAI 600 024'. "Header title
APPEND wa_header TO itab_header.
CLEAR: wa_header.
wa_header-typ = 'S'.
wa_header-info = lv_date_con.
APPEND wa_header TO itab_header.
ENDFORM.
In function module:
FUNCTION z17_fm_purchase_spec.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(ZIEKKO) TYPE ZTPUR
*" REFERENCE(Z_EKORG) TYPE EKORG
*" REFERENCE(ZN_RES) TYPE INT2
*" TABLES
*" ZITB_EKKO TYPE ZTBEKKO
*" ZITB_EKPO TYPE ZTBEKPO
*" ZITB_MAKT TYPE ZTBMAKT
*"----------------------------------------------------------------------
DATA: wa_ekko LIKE LINE OF ziekko. "Range work area and internal t
able
ENDLOOP.
IF sy-subrc = 0.
"Reteriving the EKPO table values based on the Zitab_ekko table values
SELECT ebeln
ebelp
menge
matnr
werks
lgort
aedat
netwr
netpr
FROM ekpo
INTO TABLE zitb_ekpo "Destination table
FOR ALL ENTRIES IN zitb_ekko "For all entries
WHERE ebeln EQ zitb_ekko-ebeln."Condition
IF sy-subrc = 0.
ENDIF.
ENDIF.
ENDIF.
ENDFUNCTION.