100% found this document useful (2 votes)
2K views

Display Alv Report With Header and Item

The document describes how to display a purchase order report using an ALV grid. It declares internal tables and work areas to store header and item data from purchase documents. It defines a structure to consolidate item data and appends fields to a catalog for the ALV grid. When a user selects a record, it loops through items, reads descriptions, and appends consolidated data to a table for output in a second ALV report.

Uploaded by

ramya
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
2K views

Display Alv Report With Header and Item

The document describes how to display a purchase order report using an ALV grid. It declares internal tables and work areas to store header and item data from purchase documents. It defines a structure to consolidate item data and appends fields to a catalog for the ALV grid. When a user selects a record, it loops through items, reads descriptions, and appends consolidated data to a table for output in a second ALV report.

Uploaded by

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

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

DATA: itab_ekpo TYPE TABLE OF Z17EKPO, "Internal table for purch


ase item table
wa_ekpo TYPE Z17EKPO. "work area for purchase
item table

DATA: itab_makt TYPE TABLE OF Z17MAKT, "Internal table for materi


al description table
wa_makt TYPE Z17MAKT. "WOrk area for material ta
ble
DATA: itab_cons_ekpo TYPE TABLE OF ty_ekpo_pur, "Purchase item table
consolidated table
wa_cons_ekpo TYPE ty_ekpo_pur. "Purchase item table
work area

"Field catalog
DATA: itab_fieldcat TYPE slis_t_fieldcat_alv, "internal table
wa_fieldcat TYPE slis_fieldcat_alv. "WOrk area

"ALV report header internal table and work area


DATA: itab_header TYPE slis_t_listheader,
wa_header TYPE slis_listheader,

"ALV report sort internal table and work area


itab_sort TYPE slis_t_sortinfo_alv,
wa_sort TYPE slis_sortinfo_alv.

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

*--------------------------------------------------------------------------
-----------------------------

SELECT-OPTIONS: lv_date FOR ekko-


bedat OBLIGATORY . "Selct options for bedat

PARAMETERS: lv_ekorg TYPE ekorg OBLIGATORY, "Input for Purchase o


rganization
lv_max TYPE int2. "Maximum number of r
ecords

logic :
*& Include ZI17_INC_PURCHASE_BL
*&---------------------------------------------------------------------*

lv_tdate = sy-datum. "Current date


CONCATENATE 'Date:'
lv_tdate+6(2) '/'
lv_tdate+4(2) '/'
lv_tdate(4)
INTO lv_date_con. "Concatenate the date with text
*--------------------------------------------------------------------------
----

IF lv_date IS NOT INITIAL.


IF lv_ekorg NE 0 AND lv_max NE 0. "Exceptions

CALL FUNCTION 'Z17_FM_PURCHASE_SPEC' "Function module


EXPORTING
ziekko = lv_date[] "Rage of values
z_ekorg = lv_ekorg "Locations
zn_res = lv_max "Maximum no.of records
TABLES
zitb_ekko = itab_ekko
zitb_ekpo = itab_ekpo
zitb_makt = itab_makt.

ELSE.
MESSAGE 'Pls fill all the fields' TYPE 'I'. "Exceptions

ENDIF.

IF itab_ekko IS NOT INITIAL . "Check whether the internal t


able is have any records
SORT itab_ekko. "Sort the intenral table
"Subroutine
PERFORM firstreport. "Perform First ALV report

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.

ENDLOOP. "End loop

ENDIF.

IF itab_cons_ekpo IS NOT INITIAL . "Check the table consolidated


table is not empty
PERFORM secondoutput. "Execute the subroutine second rep
ort

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. "Clear the wo


rk area fieldcatalog
wa_fieldcat-fieldname = 'BUKRS'.
wa_fieldcat-seltext_m = 'COmpany code'.
APPEND wa_fieldcat TO itab_fieldcat.

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.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' "ALV GRid report


EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER = ' '
* I_BUFFER_ACTIVE = ' '
i_callback_program = w_repid "Current
program
* I_CALLBACK_PF_STATUS_SET = ' '
i_callback_user_command = 'USER-COMMAND'
i_callback_top_of_page = 'TOP-OF-
PAGE' "Header for the reprort
* I_CALLBACK_HTML_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_END_OF_LIST = ' '
* I_STRUCTURE_NAME =
* I_BACKGROUND_ID = ' '
i_grid_title = 'Purchase Header Documents' "Title
of the report
* I_GRID_SETTINGS =
* IS_LAYOUT =
it_fieldcat = itab_fieldcat "Field
catalog for the ALV report
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
* I_SAVE = ' '
* 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 = itab_ekko "Consolidated
the table print the values
* EXCEPTIONS
* PROGRAM_ERROR = 1
* OTHERS = 2
.
* IF sy-subrc <> 0.
** Implement suitable error handling here
* ENDIF.

ENDFORM. " FIRSTREPORT

*&---------------------------------------------------------------------*
*& Form SECONDOUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM secondoutput . "Second output of the ALV Grid
report

CLEAR: wa_fieldcat, itab_fieldcat. "Clear the fieldcatalog for in


ternal table and work area
wa_fieldcat-fieldname = 'EBELN'. "Field name
wa_fieldcat-seltext_m = 'Purchase doc Number'. "Field short descriptions
wa_fieldcat-emphasize = 'C113'. "Field color
APPEND wa_fieldcat TO itab_fieldcat. "Append the field catalog valu
es

CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'EBELP'.
wa_fieldcat-emphasize = 'C666'.
wa_fieldcat-seltext_m = 'Item doc Number'.

APPEND wa_fieldcat TO itab_fieldcat.

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

APPEND wa_fieldcat TO itab_fieldcat.

"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

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' "ALV grrid report


EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER = ' '
* I_BUFFER_ACTIVE = ' '
i_callback_program = w_repid "Current program
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
i_callback_top_of_page = 'TOP-OF-PAGE1' "Header
* I_CALLBACK_HTML_TOP_OF_PAGE = ''
* I_CALLBACK_HTML_END_OF_LIST = ' '
* I_STRUCTURE_NAME =
* I_BACKGROUND_ID = ' '
i_grid_title = 'Purchase Item Document' "Title
* I_GRID_SETTINGS =
* IS_LAYOUT =
it_fieldcat = itab_fieldcat "Field catalog
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
it_sort = itab_sort "SOrt
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
* I_SAVE = ' '
* 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 = itab_cons_ekpo "Output table
* EXCEPTIONS
* PROGRAM_ERROR = 1
* OTHERS = 2
.
* IF sy-subrc <> 0.
** Implement suitable error handling here
* ENDIF.

ENDFORM. " SECONDOUTPUT

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

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE' "ALV header


EXPORTING
it_list_commentary = itab_header
i_logo = 'VIDHAI_LOGO' "LOGO
* I_END_OF_LIST_GRID = ''
* I_ALV_FORM =
.

ENDFORM. " TOP-OF-PAGE

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

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE' "ALV header


EXPORTING
it_list_commentary = itab_header
i_logo = 'VIDHAI_LOGO' "LOGO
* I_END_OF_LIST_GRID = 'X'
* I_ALV_FORM =
.

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

RANGES: ran_ekko FOR ekko-bedat. "Range values

IF ziekko IS NOT INITIAL. "Check if the RAN_EKKO is not ini


tial
"Append the values into ran_ekko using work area
LOOP AT ziekko INTO wa_ekko.
ran_ekko-sign = wa_ekko-sign.
ran_ekko-option = wa_ekko-option.
ran_ekko-low = wa_ekko-low.
ran_ekko-high = wa_ekko-high.
APPEND ran_ekko.

ENDLOOP.

"Retreiving the EKKO table values based on the Range


SELECT ebeln
bukrs
bsart
aedat
bedat
ernam
lifnr
ekorg
ekgrp
angnr
FROM ekko
INTO CORRESPONDING FIELDS OF TABLE zitb_ekko "Corrosponding fields f
rom the structure
UP TO zn_res ROWS "Specify no of rows
WHERE bedat IN ran_ekko "Checking the range of values
AND ekorg EQ z_ekorg. "Purchase organization

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.

"Selecting the makt table values


SELECT matnr
maktx
FROM makt
INTO TABLE zitb_makt "Destination table
FOR ALL ENTRIES IN zitb_ekpo "Check the all entries into pur
chase item table
WHERE matnr EQ zitb_ekpo-matnr. "Condition

ENDIF.
ENDIF.

ENDIF.

ENDFUNCTION.

You might also like