*&---------------------------------------------------------------------*
*& Report ZIAN02
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
report ZIAN02 .
tables : EKKO .
type-pools : SLIS . "ALV Declarations
*Data Declaration
*----------------
data : begin of T_EKKO occurs 0 ,
EBELN type EKPO -EBELN ,
EBELP type EKPO -EBELP ,
STATU type EKPO -STATU ,
AEDAT type EKPO -AEDAT ,
MATNR type EKPO -MATNR ,
MENGE type EKPO -MENGE ,
MEINS type EKPO -MEINS ,
NETPR type EKPO -NETPR ,
PEINH type EKPO -PEINH ,
COLTAB type SLIS_T_SPECIALCOL_ALV ,
end of T_EKKO .
data : IT_EKKO like T_EKKO occurs 0 with header line ,
WA_EKKO like T_EKKO occurs 0 with header line .
*ALV data declarations
data : FIELDCATALOG type SLIS_T_FIELDCAT_ALV with header line ,
GD_TAB_GROUP type SLIS_T_SP_GROUP_ALV ,
GD_LAYOUT type SLIS_LAYOUT_ALV ,
GD_REPID like SY -REPID .
************************************************************************
*Start-of-selection.
start-of-selection .
perform DATA_RETRIEVAL .
perform BUILD_FIELDCATALOG .
perform BUILD_LAYOUT .
perform DISPLAY_ALV_REPORT .
*&---------------------------------------------------------------------*
*& Form BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
* Build Fieldcatalog for ALV Report
*----------------------------------------------------------------------*
form BUILD_FIELDCATALOG .
* There are a number of ways to create a fieldcat.
* For the purpose of this example i will build the fieldcatalog manualy
* by populating the internal table fields individually and then
* appending the rows. This method can be the most time consuming but can
* also allow you more control of the final product.
* Beware though, you need to ensure that all fields required are
* populated. When using some of functionality available via ALV, such as
* total. You may need to provide more information than if you were
* simply displaying the result
* I.e. Field type may be required in-order for
* the 'TOTAL' function to work.
FIELDCATALOG -FIELDNAME = 'EBELN' .
FIELDCATALOG -SELTEXT_M = 'Purchase Order' .
FIELDCATALOG -COL_POS = 0 .
FIELDCATALOG -OUTPUTLEN = 10 .
FIELDCATALOG -EMPHASIZE = 'X' .
FIELDCATALOG - KEY = 'X' .
append FIELDCATALOG to FIELDCATALOG .
clear FIELDCATALOG .
FIELDCATALOG -FIELDNAME = 'EBELP' .
FIELDCATALOG -SELTEXT_M = 'PO Item' .
FIELDCATALOG -COL_POS = 1 .
append FIELDCATALOG to FIELDCATALOG .
clear FIELDCATALOG .
FIELDCATALOG -FIELDNAME = 'STATU' .
FIELDCATALOG -SELTEXT_M = 'Status' .
FIELDCATALOG -COL_POS = 2 .
append FIELDCATALOG to FIELDCATALOG .
clear FIELDCATALOG .
FIELDCATALOG -FIELDNAME = 'AEDAT' .
FIELDCATALOG -SELTEXT_M = 'Item change date' .
FIELDCATALOG -COL_POS = 3 .
append FIELDCATALOG to FIELDCATALOG .
clear FIELDCATALOG .
FIELDCATALOG -FIELDNAME = 'MATNR' .
FIELDCATALOG -SELTEXT_M = 'Material Number' .
FIELDCATALOG -COL_POS = 4 .
append FIELDCATALOG to FIELDCATALOG .
clear FIELDCATALOG .
FIELDCATALOG -FIELDNAME = 'MENGE' .
FIELDCATALOG -SELTEXT_M = 'PO quantity' .
FIELDCATALOG -COL_POS = 5 .
append FIELDCATALOG to FIELDCATALOG .
clear FIELDCATALOG .
FIELDCATALOG -FIELDNAME = 'MEINS' .
FIELDCATALOG -SELTEXT_M = 'Order Unit' .
FIELDCATALOG -COL_POS = 6 .
append FIELDCATALOG to FIELDCATALOG .
clear FIELDCATALOG .
FIELDCATALOG -FIELDNAME = 'NETPR' .
FIELDCATALOG -SELTEXT_M = 'Net Price' .
FIELDCATALOG -COL_POS = 7 .
FIELDCATALOG -OUTPUTLEN = 15 .
FIELDCATALOG -DATATYPE = 'CURR' .
append FIELDCATALOG to FIELDCATALOG .
clear FIELDCATALOG .
FIELDCATALOG -FIELDNAME = 'PEINH' .
FIELDCATALOG -SELTEXT_M = 'Price Unit' .
FIELDCATALOG -COL_POS = 8 .
append FIELDCATALOG to FIELDCATALOG .
clear FIELDCATALOG .
endform . " BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*& Form BUILD_LAYOUT
*&---------------------------------------------------------------------*
* Build layout for ALV grid report
*----------------------------------------------------------------------*
form BUILD_LAYOUT .
GD_LAYOUT -NO_INPUT = 'X' .
GD_LAYOUT -COLWIDTH_OPTIMIZE = 'X' .
GD_LAYOUT -TOTALS_TEXT = 'Totals' ( 201 ) .
* Set layout field for row attributes(i.e. color)
GD_LAYOUT -COLTAB_FIELDNAME = 'COLTAB' .
endform . " BUILD_LAYOUT
*&---------------------------------------------------------------------*
*& Form DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
* Display report using ALV grid
*----------------------------------------------------------------------*
form DISPLAY_ALV_REPORT .
GD_REPID = SY -REPID .
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
I_CALLBACK_PROGRAM = GD_REPID
* i_callback_top_of_page = 'TOP-OF-PAGE' "see FORM
* i_callback_user_command = 'USER_COMMAND'
* i_grid_title = outtext
IS_LAYOUT = GD_LAYOUT
IT_FIELDCAT = FIELDCATALOG[]
* it_special_groups = gd_tabgroup
* IT_EVENTS = GT_XEVENTS
I_SAVE = 'X'
* is_variant = z_template
tables
T_OUTTAB = IT_EKKO
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_ALV_REPORT
*&---------------------------------------------------------------------*
*& Form DATA_RETRIEVAL
*&---------------------------------------------------------------------*
* Retrieve data form EKPO table and populate itab it_ekko
*----------------------------------------------------------------------*
form DATA_RETRIEVAL .
data : LD_COLOR ( 1 ) type C .
select EBELN EBELP STATU AEDAT MATNR MENGE MEINS NETPR PEINH
into corresponding fields of IT_EKKO from EKPO .
append IT_EKKO .
clear IT_EKKO .
endselect .
*Populate field with color attributes
data L_ALVCOLOR type SLIS_SPECIALCOL_ALV .
loop at IT_EKKO into WA_EKKO .
* Colour cells
if WA_EKKO -EBELP = '000030' .
clear GD_LAYOUT .
L_ALVCOLOR -FIELDNAME = 'EBELP' .
L_ALVCOLOR - COLOR -COL = 6 . "<--- colour number
L_ALVCOLOR - COLOR -INT = 0 . "<--- intensified flag
L_ALVCOLOR -NOKEYCOL = 'X' . "<--- key column flag
append L_ALVCOLOR to WA_EKKO -COLTAB .
endif .
* CLEAR l_alvcolor.
* l_alvcolor-fieldname = 'EBELN'.
* l_alvcolor-color-col = 6. "<--- colour number
* l_alvcolor-color-int = 1. "<--- intensified flag
* l_alvcolor-nokeycol = SPACE. "<--- key column flag
* APPEND l_alvcolor TO WA_EKKO-coltab.
modify IT_EKKO from WA_EKKO .
endloop .
endform . " DATA_RETRIEVAL
*& Report ZIAN02
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
report ZIAN02 .
tables : EKKO .
type-pools : SLIS . "ALV Declarations
*Data Declaration
*----------------
data : begin of T_EKKO occurs 0 ,
EBELN type EKPO -EBELN ,
EBELP type EKPO -EBELP ,
STATU type EKPO -STATU ,
AEDAT type EKPO -AEDAT ,
MATNR type EKPO -MATNR ,
MENGE type EKPO -MENGE ,
MEINS type EKPO -MEINS ,
NETPR type EKPO -NETPR ,
PEINH type EKPO -PEINH ,
COLTAB type SLIS_T_SPECIALCOL_ALV ,
end of T_EKKO .
data : IT_EKKO like T_EKKO occurs 0 with header line ,
WA_EKKO like T_EKKO occurs 0 with header line .
*ALV data declarations
data : FIELDCATALOG type SLIS_T_FIELDCAT_ALV with header line ,
GD_TAB_GROUP type SLIS_T_SP_GROUP_ALV ,
GD_LAYOUT type SLIS_LAYOUT_ALV ,
GD_REPID like SY -REPID .
************************************************************************
*Start-of-selection.
start-of-selection .
perform DATA_RETRIEVAL .
perform BUILD_FIELDCATALOG .
perform BUILD_LAYOUT .
perform DISPLAY_ALV_REPORT .
*&---------------------------------------------------------------------*
*& Form BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
* Build Fieldcatalog for ALV Report
*----------------------------------------------------------------------*
form BUILD_FIELDCATALOG .
* There are a number of ways to create a fieldcat.
* For the purpose of this example i will build the fieldcatalog manualy
* by populating the internal table fields individually and then
* appending the rows. This method can be the most time consuming but can
* also allow you more control of the final product.
* Beware though, you need to ensure that all fields required are
* populated. When using some of functionality available via ALV, such as
* total. You may need to provide more information than if you were
* simply displaying the result
* I.e. Field type may be required in-order for
* the 'TOTAL' function to work.
FIELDCATALOG -FIELDNAME = 'EBELN' .
FIELDCATALOG -SELTEXT_M = 'Purchase Order' .
FIELDCATALOG -COL_POS = 0 .
FIELDCATALOG -OUTPUTLEN = 10 .
FIELDCATALOG -EMPHASIZE = 'X' .
FIELDCATALOG - KEY = 'X' .
append FIELDCATALOG to FIELDCATALOG .
clear FIELDCATALOG .
FIELDCATALOG -FIELDNAME = 'EBELP' .
FIELDCATALOG -SELTEXT_M = 'PO Item' .
FIELDCATALOG -COL_POS = 1 .
append FIELDCATALOG to FIELDCATALOG .
clear FIELDCATALOG .
FIELDCATALOG -FIELDNAME = 'STATU' .
FIELDCATALOG -SELTEXT_M = 'Status' .
FIELDCATALOG -COL_POS = 2 .
append FIELDCATALOG to FIELDCATALOG .
clear FIELDCATALOG .
FIELDCATALOG -FIELDNAME = 'AEDAT' .
FIELDCATALOG -SELTEXT_M = 'Item change date' .
FIELDCATALOG -COL_POS = 3 .
append FIELDCATALOG to FIELDCATALOG .
clear FIELDCATALOG .
FIELDCATALOG -FIELDNAME = 'MATNR' .
FIELDCATALOG -SELTEXT_M = 'Material Number' .
FIELDCATALOG -COL_POS = 4 .
append FIELDCATALOG to FIELDCATALOG .
clear FIELDCATALOG .
FIELDCATALOG -FIELDNAME = 'MENGE' .
FIELDCATALOG -SELTEXT_M = 'PO quantity' .
FIELDCATALOG -COL_POS = 5 .
append FIELDCATALOG to FIELDCATALOG .
clear FIELDCATALOG .
FIELDCATALOG -FIELDNAME = 'MEINS' .
FIELDCATALOG -SELTEXT_M = 'Order Unit' .
FIELDCATALOG -COL_POS = 6 .
append FIELDCATALOG to FIELDCATALOG .
clear FIELDCATALOG .
FIELDCATALOG -FIELDNAME = 'NETPR' .
FIELDCATALOG -SELTEXT_M = 'Net Price' .
FIELDCATALOG -COL_POS = 7 .
FIELDCATALOG -OUTPUTLEN = 15 .
FIELDCATALOG -DATATYPE = 'CURR' .
append FIELDCATALOG to FIELDCATALOG .
clear FIELDCATALOG .
FIELDCATALOG -FIELDNAME = 'PEINH' .
FIELDCATALOG -SELTEXT_M = 'Price Unit' .
FIELDCATALOG -COL_POS = 8 .
append FIELDCATALOG to FIELDCATALOG .
clear FIELDCATALOG .
endform . " BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*& Form BUILD_LAYOUT
*&---------------------------------------------------------------------*
* Build layout for ALV grid report
*----------------------------------------------------------------------*
form BUILD_LAYOUT .
GD_LAYOUT -NO_INPUT = 'X' .
GD_LAYOUT -COLWIDTH_OPTIMIZE = 'X' .
GD_LAYOUT -TOTALS_TEXT = 'Totals' ( 201 ) .
* Set layout field for row attributes(i.e. color)
GD_LAYOUT -COLTAB_FIELDNAME = 'COLTAB' .
endform . " BUILD_LAYOUT
*&---------------------------------------------------------------------*
*& Form DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
* Display report using ALV grid
*----------------------------------------------------------------------*
form DISPLAY_ALV_REPORT .
GD_REPID = SY -REPID .
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
I_CALLBACK_PROGRAM = GD_REPID
* i_callback_top_of_page = 'TOP-OF-PAGE' "see FORM
* i_callback_user_command = 'USER_COMMAND'
* i_grid_title = outtext
IS_LAYOUT = GD_LAYOUT
IT_FIELDCAT = FIELDCATALOG[]
* it_special_groups = gd_tabgroup
* IT_EVENTS = GT_XEVENTS
I_SAVE = 'X'
* is_variant = z_template
tables
T_OUTTAB = IT_EKKO
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_ALV_REPORT
*&---------------------------------------------------------------------*
*& Form DATA_RETRIEVAL
*&---------------------------------------------------------------------*
* Retrieve data form EKPO table and populate itab it_ekko
*----------------------------------------------------------------------*
form DATA_RETRIEVAL .
data : LD_COLOR ( 1 ) type C .
select EBELN EBELP STATU AEDAT MATNR MENGE MEINS NETPR PEINH
into corresponding fields of IT_EKKO from EKPO .
append IT_EKKO .
clear IT_EKKO .
endselect .
*Populate field with color attributes
data L_ALVCOLOR type SLIS_SPECIALCOL_ALV .
loop at IT_EKKO into WA_EKKO .
* Colour cells
if WA_EKKO -EBELP = '000030' .
clear GD_LAYOUT .
L_ALVCOLOR -FIELDNAME = 'EBELP' .
L_ALVCOLOR - COLOR -COL = 6 . "<--- colour number
L_ALVCOLOR - COLOR -INT = 0 . "<--- intensified flag
L_ALVCOLOR -NOKEYCOL = 'X' . "<--- key column flag
append L_ALVCOLOR to WA_EKKO -COLTAB .
endif .
* CLEAR l_alvcolor.
* l_alvcolor-fieldname = 'EBELN'.
* l_alvcolor-color-col = 6. "<--- colour number
* l_alvcolor-color-int = 1. "<--- intensified flag
* l_alvcolor-nokeycol = SPACE. "<--- key column flag
* APPEND l_alvcolor TO WA_EKKO-coltab.
modify IT_EKKO from WA_EKKO .
endloop .
endform . " DATA_RETRIEVAL