This report displays purchase order and its related goods receipt details as per data entered in the selection screen.
REPORT /xxxsep/fap001 NO STANDARD PAGE HEADING.
INCLUDE /xxxsep/fap001_top. " Data Declarations
INCLUDE /xxxsep/fap001_sel. " Selection Screen Definition
INCLUDE /xxxsep/fap001_routine. " Subroutines
***********************************************************************
* Validations *
***********************************************************************
AT SELECTION-SCREEN ON s_bukrs.
PERFORM validate_com_code.
AT SELECTION-SCREEN ON s_werks.
PERFORM validate_plant.
AT SELECTION-SCREEN ON s_ebeln.
PERFORM validate_pur_order.
AT SELECTION-SCREEN ON s_ekgrp.
PERFORM validate_pur_group .
AT SELECTION-SCREEN ON s_matkl.
PERFORM validate_mat_group .
AT SELECTION-SCREEN ON s_bewtp.
PERFORM validate_po_history_cat.
AT SELECTION-SCREEN ON s_bwart.
PERFORM validate_mov_type.
AT SELECTION-SCREEN ON s_grund.
PERFORM validate_movement_reason.
AT SELECTION-SCREEN ON s_bednr.
PERFORM validate_track_no.
AT SELECTION-SCREEN ON s_lifnr.
PERFORM validate_vendor.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_layout.
PERFORM sub_f4_layout USING if_salv_c_layout=>restrict_none
CHANGING p_layout.
***********************************************************************
* START-OF-SELECTION *
***********************************************************************
START-OF-SELECTION.
PERFORM get_data.
***********************************************************************
* END-OF-SELECTION *
***********************************************************************
END-OF-SELECTION.
PERFORM populate_final_data.
PERFORM populate_display_data.
IF t_final_dis IS NOT INITIAL.
PERFORM display_alv.
ELSE.
MESSAGE text-t13 TYPE 'I'.
ENDIF.
***********************************************************************
Include - /xxxSEP/FAP001_TOP
***********************************************************************
* Type Declarations
***********************************************************************
TYPES:
* Strcture type to declare selection screen
BEGIN OF type_s_sel,
bukrs TYPE t001-bukrs, " Company Code
werks TYPE t001w-werks, " Plant
ebeln TYPE ekko-ebeln, " Purchasing Document Number
aedat TYPE ekko-aedat, " Created on
ekgrp TYPE ekko-ekgrp, " Purchasing Group
loekz TYPE ekko-loekz, " Deletion Indicator
matkl TYPE ekpo-matkl, " Material Group
bewtp TYPE ekbe-bewtp, " PO History Category
bwart TYPE t156-bwart, " Movement Type
grund TYPE t157d-grund, " Reason for Movement
bednr TYPE ekpo-bednr, " Requirement Tracking Number
lifnr TYPE ekko-lifnr, " Vendor Account Number
END OF type_s_sel,
* Strcture type to declare purchasing document header data
BEGIN OF type_s_ekpo,
ebeln TYPE ebeln, " Purchasing Document Number
bukrs TYPE bukrs, " Company Code
bsart TYPE esart, " Purchasing Document Type
loekz TYPE eloek, " Deletion Indicator
aedat TYPE erdat, " Created on
ernam TYPE ernam, " Created By
lifnr TYPE elifn, " Vendor Account Number
ekgrp TYPE bkgrp, " Purchasing Group
waers TYPE waers, " Currency Key
ebelp TYPE ebelp, " Purchasing Document Item
txz01 TYPE txz01, " Short Text
werks TYPE ewerk, " Plant
bednr TYPE bednr, " Requirement Tracking Number
matkl TYPE matkl, " Material Group
menge TYPE bstmg, " PO Quantity
meins TYPE bstme, " Unit of Measure
brtwr TYPE bbwert, " Gross Order Value
weunb TYPE weunb, " GR Non-Valuated
afnam TYPE afnam, " Name of Requisitioner
END OF type_s_ekpo,
* Strcture type to declare schedule lines data
BEGIN OF type_s_eket,
ebeln TYPE ebeln, " Purchasing Document Number
ebelp TYPE ebelp, " Purchasing Document Item
eindt TYPE eindt, " Item Delivery Date
END OF type_s_eket,
* Strcture type to declare purchasing document History
BEGIN OF type_s_ekbe,
ebeln TYPE ebeln, " Purchasing Document Number
ebelp TYPE ebelp, " Purchasing Document Item
gjahr TYPE mjahr, " Material Document Year
belnr TYPE mblnr, " Material Document
buzei TYPE mblpo, " Material Document Item
bewtp TYPE bewtp, " PO History Category
bwart TYPE bwart, " Movement Type
budat TYPE budat, " Posting Date
menge TYPE bstmg, " PO Quantity
dmbtr TYPE dmbtr, " Amount in Local Currency
shkzg type shkzg, "
END OF type_s_ekbe,
* Strcture type to declare material document data
BEGIN OF type_s_mseg,
mblnr TYPE mblnr, " Material Document
mjahr TYPE mjahr, " Material Document Year
zeile TYPE mblpo, " Material Document Item
weunb TYPE weunb, " GR Non-Valuated
bwart TYPE bwart, " Movement Type
* shkzg TYPE shkzg, " D/C Indicator "
grund TYPE mb_grbew, " Reason for Movement
END OF type_s_mseg,
* Strcture type to declare vendor data
BEGIN OF type_s_lfa1,
lifnr TYPE lifnr, " Vendor Account Number
name1 TYPE name1, " Vendor Name
END OF type_s_lfa1,
* Strcture type to declare reason for movement data
BEGIN OF type_s_t157e,
bwart TYPE bwart,
grund TYPE mb_grbew, " Reason for Movement
grtxt TYPE grtxt, " Reason Descriptions
END OF type_s_t157e,
* Strcture type to declare final data
BEGIN OF type_s_final,
ebeln TYPE ebeln, " Purchasing Document Number
ebelp TYPE ebelp, " Purchasing Document Item
bsart TYPE esart, " Purchasing Document Type
aedat TYPE erdat, " Created on
ernam TYPE ernam, " Created By
lifnr TYPE lifnr, " Vendor Account No
name1 TYPE name1, " Vendor Name
ekgrp TYPE bkgrp, " Purchasing Group
werks TYPE ewerk, " Plant
txz01 TYPE txz01, " Short Text
matkl TYPE matkl, " Material Group
bednr TYPE bednr, " Requirement Tracking Number
poqty TYPE bstmg, " PO Quantity
meins TYPE bstme, " Unit of Measure
brtwr TYPE bbwert, " Gross Order Value
waers TYPE waers, " Currency Key
afnam TYPE afnam, " Name of Requisitioner
eindt TYPE eindt, " Item Delivery Date
bewtp TYPE bewtp, " PO History Category
budat TYPE budat, " Posting Date
belnr TYPE mblnr, " GRN Doc no
grqty TYPE bstmg, " GR Quantity
bwart TYPE bwart, " Movement Type
weunb TYPE weunb, " GR Non-Valuated
shkzg TYPE shkzg, " D/C Indicator "
dmbtr TYPE dmbtr, " Amount in Local Currency
grund TYPE mb_grbew, " Reason for Movement
grtxt TYPE grtxt, " Reason Description
END OF type_s_final,
BEGIN OF type_s_final_dis,
ebeln TYPE ebeln, " Purchasing Document Number
bsart TYPE esart, " Purchasing Document Type
aedat TYPE erdat, " Created on
ernam TYPE ernam, " Created By
lifnr TYPE lifnr, " Vendor Account No
name1 TYPE name1, " Vendor Name
ekgrp TYPE bkgrp, " Purchasing Group
ebelp TYPE ebelp, " Purchasing Document Item
txz01 TYPE txz01, " Short Text
matkl TYPE matkl, " Material Group
bednr TYPE bednr, " Requirement Tracking Number
poqty TYPE bstmg, " PO Quantity
unit1 TYPE bstme, " Unit of Measure
brtwr TYPE bbwert, " Gross Order Value
cuky1 TYPE waers, " Currency Key
unit2 TYPE bstme, " Unit of Measure
afnam TYPE afnam, " Name of Requisitioner
bewtp TYPE bewtp, " PO History Category
eindt TYPE eindt, " Item Delivery Date
budat TYPE budat, " Posting Date
grqty TYPE bstmg, " GR Quantity
unit3 TYPE bstme, " Unit of Measure
weunb TYPE weunb, " GR Non-Valuated
dmbtr TYPE dmbtr, " Amount in Local Currency
cuky2 TYPE waers, " Currency Key
shkzg TYPE shkzg, " D/C Indicator
bwart TYPE bwart, " Movement Type
grund TYPE mb_grbew, " Reason for Movement
grtxt TYPE grtxt, " Reason Description
END OF type_s_final_dis.
***********************************************************************
* Work areas
***********************************************************************
DATA:
* Work area to declare selection screen
w_sel TYPE type_s_sel,
* Work area to declare purchasing document header and item data
w_ekpo TYPE type_s_ekpo,
* Work area to declare purchasing document history
w_ekbe TYPE type_s_ekbe,
* Work area to declare Schedule lines data
w_eket TYPE type_s_eket,
* Work area to declare vendor data
w_lfa1 TYPE type_s_lfa1,
* Work area to declare material document data
w_mseg TYPE type_s_mseg,
* Work area to declare reason for movement dat
w_t157e TYPE type_s_t157e,
* Work area to declare final data
w_final TYPE type_s_final,
w_final_dis TYPE type_s_final_dis.
***********************************************************************
* INTERNAL TABLES
***********************************************************************
DATA:
* Internal table to hold purchasing document header data and item data
t_ekpo TYPE STANDARD TABLE
OF type_s_ekpo,
t_ekpo_temp TYPE STANDARD TABLE
OF type_s_ekpo,
* Internal table to hold schedule lines data
t_eket TYPE SORTED TABLE
OF type_s_eket
WITH NON-UNIQUE KEY ebeln ebelp,
* Internal table to hold purchase order history category data
t_ekbe TYPE SORTED TABLE
OF type_s_ekbe
WITH NON-UNIQUE KEY ebeln ebelp,
* Internal table to hold material document data
t_mseg TYPE STANDARD TABLE
OF type_s_mseg,
t_mseg_temp TYPE STANDARD TABLE
OF type_s_mseg,
* Internal table to hold reason for movement data
t_t157e TYPE STANDARD TABLE
OF type_s_t157e,
* Internal table to hold vendor data
t_lfa1 TYPE SORTED TABLE
OF type_s_lfa1
WITH UNIQUE KEY lifnr,
* Internal table to hold final data
t_final TYPE STANDARD TABLE
OF type_s_final,
t_final_Dis TYPE STANDARD TABLE
OF type_s_final_dis.
***********************************************************************
* Objects
***********************************************************************
DATA:
obj_column TYPE REF TO cl_salv_column_table,
obj_columns TYPE REF TO cl_salv_columns_table,
obj_layout TYPE REF TO cl_salv_layout,
obj_display TYPE REF TO cl_salv_display_settings,
obj_functions TYPE REF TO cl_salv_functions,
obj_alv_table TYPE REF TO cl_salv_table.
***********************************************************************
Include - /xxxSEP/FAP001_SEL
***********************************************************************
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-t00.
SELECT-OPTIONS:
s_bukrs FOR w_sel-bukrs " Company Code
OBLIGATORY,
s_werks FOR w_sel-werks, " Plant
s_ebeln FOR w_sel-ebeln, " Purchasing Document Number
s_aedat FOR w_sel-aedat, " Created on
s_ekgrp FOR w_sel-ekgrp, " Purchasing Group
s_loekz FOR w_sel-loekz, " Deletion Indicator
s_matkl FOR w_sel-matkl, " Material Group
s_bewtp FOR w_sel-bewtp, " PO History Category
s_bwart FOR w_sel-bwart, " Movement Type
s_grund FOR w_sel-grund. " Reason for Movement
SELECTION-SCREEN END OF BLOCK b1.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-t01.
SELECT-OPTIONS:
s_bednr FOR w_sel-bednr, " Requirement Tracking Number
s_lifnr FOR w_sel-lifnr. " Vendor Account Number
SELECTION-SCREEN END OF BLOCK b2.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN BEGIN OF BLOCK blk3 WITH FRAME TITLE text-b03.
PARAMETERS
p_layout TYPE disvariant-variant. " Layout
SELECTION-SCREEN END OF BLOCK blk3.
************************************************************************
Include - /SBDSEP/FAP001_ROUTINE
************************************************************************
*---------------------------------------------------------------------*
* Form VALIDATE_COMP_CODE *
*---------------------------------------------------------------------*
* This subroutine is used to validate company code *
*---------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine *
*---------------------------------------------------------------------*
FORM validate_com_code .
IF NOT s_bukrs IS INITIAL.
SELECT SINGLE bukrs
INTO w_sel-bukrs
FROM t001
WHERE bukrs IN s_bukrs[].
IF sy-subrc <> 0.
MESSAGE text-t02 TYPE 'E'.
ENDIF.
ENDIF.
ENDFORM. " VALIDATE_COM_CODE
*---------------------------------------------------------------------*
* Form VALIDATE_PLANT *
*---------------------------------------------------------------------*
* This subroutine is used to validate plant *
*---------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine *
*---------------------------------------------------------------------*
FORM validate_plant .
IF NOT s_werks IS INITIAL.
SELECT SINGLE werks
INTO w_sel-werks
FROM t001w
WHERE werks IN s_werks[].
IF sy-subrc <> 0.
MESSAGE text-t03 TYPE 'E'.
ENDIF.
ENDIF.
ENDFORM. " VALIDATE_PLANT
*---------------------------------------------------------------------*
* Form VALIDATE_PUR_ORDER
*---------------------------------------------------------------------*
* This subroutine is used to validate purchase order *
*---------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine *
*---------------------------------------------------------------------*
FORM validate_pur_order .
IF NOT s_ebeln IS INITIAL.
SELECT SINGLE ebeln
INTO w_sel-ebeln
FROM ekko
WHERE ebeln IN s_ebeln[].
IF sy-subrc <> 0.
MESSAGE text-t04 TYPE 'E'.
ENDIF.
ENDIF.
ENDFORM. " VALIDATE_PUR_ORDER
*&---------------------------------------------------------------------*
*& Form SUB_VALIDATE_PUR_GROUP
*---------------------------------------------------------------------*
* This subroutine is used to validate deletion indicator *
*---------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine *
*---------------------------------------------------------------------*
FORM validate_pur_group .
IF NOT s_ekgrp IS INITIAL.
SELECT SINGLE ekgrp
FROM t024
INTO w_sel-ekgrp
WHERE ekgrp IN s_ekgrp[].
IF sy-subrc <> 0.
MESSAGE text-t05 TYPE 'E'.
ENDIF.
ENDIF.
ENDFORM. " VALIDATE_PUR_GROUP
*---------------------------------------------------------------------*
* Form VALIDATE_MAT_GROUP *
*---------------------------------------------------------------------*
* This subroutine is used to validate material group *
*---------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine *
*---------------------------------------------------------------------*
FORM validate_mat_group .
IF NOT s_matkl IS INITIAL.
SELECT SINGLE matkl
INTO w_sel-matkl
FROM t023
WHERE matkl IN s_matkl[].
IF sy-subrc <> 0.
MESSAGE text-t07 TYPE 'E'.
ENDIF.
ENDIF.
ENDFORM. " VALIDATE_MAT_GROUP
*---------------------------------------------------------------------*
* Form VALIDATE_PO_HISTORY_CAT *
*---------------------------------------------------------------------*
* This subroutine is used to validate PO history category *
*---------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine *
*---------------------------------------------------------------------*
FORM validate_po_history_cat.
IF NOT s_bewtp IS INITIAL.
SELECT SINGLE bewtp
INTO w_sel-bewtp
FROM t163b
WHERE bewtp IN s_bewtp[].
IF sy-subrc <> 0.
MESSAGE text-t08 TYPE 'E'.
ENDIF.
ENDIF.
ENDFORM. " VALIDATE_PO_HISTORY_CAT
*---------------------------------------------------------------------*
* Form VALIDATE_MOV_TYPE *
*---------------------------------------------------------------------*
* This subroutine is used to validate movement type *
*---------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine *
*---------------------------------------------------------------------*
FORM validate_mov_type .
IF NOT s_bwart IS INITIAL.
SELECT SINGLE bwart
INTO w_sel-bwart
FROM t156
WHERE bwart IN s_bwart[].
IF sy-subrc <> 0.
MESSAGE text-t09 TYPE 'E'.
ENDIF.
ENDIF.
ENDFORM. " VALIDATE_MOV_TYPE
*---------------------------------------------------------------------*
* Form VALIDATE_MOVEMENT_REASON *
*---------------------------------------------------------------------*
* This subroutine is used to validate reason for movement *
*---------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine *
*---------------------------------------------------------------------*
FORM validate_movement_reason .
IF NOT s_grund IS INITIAL.
SELECT grund UP TO 1 ROWS
INTO w_sel-grund
FROM t157d
WHERE grund IN s_grund[].
ENDSELECT.
IF sy-subrc <> 0.
MESSAGE text-t10 TYPE 'E'.
ENDIF.
ENDIF.
ENDFORM. " VALIDATE_MOVEMENT_REASON
*---------------------------------------------------------------------*
* Form VALIDATE_TRACK_NO *
*---------------------------------------------------------------------*
* This subroutine is used to validate requirement tracking number *
*---------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine *
*---------------------------------------------------------------------*
FORM validate_track_no .
IF NOT s_bednr IS INITIAL.
SELECT bednr UP TO 1 ROWS
INTO w_sel-bednr
FROM ekpo
WHERE bednr IN s_bednr[].
ENDSELECT.
IF sy-subrc <> 0.
MESSAGE text-t11 TYPE 'E'.
ENDIF.
ENDIF.
ENDFORM. " VALIDATE_TRACK_NO
*---------------------------------------------------------------------*
* Form VALIDATE_VENDOR *
*---------------------------------------------------------------------*
* This subroutine is used to validate vendor account no *
*---------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine *
*---------------------------------------------------------------------*
FORM validate_vendor .
IF NOT s_lifnr IS INITIAL.
SELECT SINGLE lifnr
INTO w_sel-lifnr
FROM lfa1
WHERE lifnr IN s_lifnr[].
IF sy-subrc <> 0.
MESSAGE text-t12 TYPE 'E'.
ENDIF.
ENDIF.
ENDFORM. " VALIDATE_VENDOR
*---------------------------------------------------------------------*
* Form GET_DATA *
*---------------------------------------------------------------------*
* This subroutine is used to retrieve data from all necessary tables *
*---------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine *
*---------------------------------------------------------------------*
FORM get_data .
PERFORM get_pdoc_data.
IF t_ekpo IS NOT INITIAL.
PERFORM get_vendor_data.
PERFORM get_schedule_lines.
PERFORM get_pdoc_history_data.
ENDIF.
IF t_ekbe IS NOT INITIAL.
PERFORM get_matdoc_item_data.
ENDIF.
IF t_mseg IS NOT INITIAL.
PERFORM get_reason_desc.
ENDIF.
ENDFORM. " GET_DATA
*---------------------------------------------------------------------*
* Form GET_PDOC_HEADER_DATA *
*---------------------------------------------------------------------*
* This subroutine retrieves necessary purchasing document header *
* data from table EKKO *
*---------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine *
*---------------------------------------------------------------------*
FORM get_pdoc_data .
SELECT ekko~ebeln
ekko~bukrs
ekko~bsart
ekko~loekz
ekko~aedat
ekko~ernam
ekko~lifnr
ekko~ekgrp
ekko~waers
ekpo~ebelp
ekpo~txz01
ekpo~werks
ekpo~bednr
ekpo~matkl
ekpo~menge
ekpo~meins
ekpo~brtwr
ekpo~weunb
ekpo~afnam
INTO TABLE t_ekpo
FROM ekko INNER JOIN ekpo
ON ekko~ebeln EQ ekpo~ebeln
WHERE ekko~ebeln IN s_ebeln
AND ekko~bukrs IN s_bukrs
AND ekko~loekz IN s_loekz
AND ekko~aedat IN s_aedat
AND ekko~lifnr IN s_lifnr
AND ekko~ekgrp IN s_ekgrp
AND ekpo~werks IN s_werks
AND ekpo~bednr IN s_bednr
AND ekpo~matkl IN s_matkl.
IF sy-subrc EQ 0.
SORT t_ekpo BY ebeln ebelp.
ENDIF.
ENDFORM. " GET_PDOC_HEADER_DATA
*---------------------------------------------------------------------*
* Form GET_VENDOR_DATA *
*---------------------------------------------------------------------*
* This subroutine retrieves necessary vendor details from table LFA1 *
*---------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine *
*---------------------------------------------------------------------*
FORM get_vendor_data .
* Read table LFA1 using the values from T_EKPO
APPEND LINES OF t_ekpo TO t_ekpo_temp.
SORT t_ekpo_temp BY lifnr.
DELETE ADJACENT DUPLICATES FROM t_ekpo_temp
COMPARING lifnr.
IF t_ekpo_temp IS NOT INITIAL.
SELECT lifnr
name1
FROM lfa1
INTO TABLE t_lfa1
FOR ALL ENTRIES IN t_ekpo_temp
WHERE lifnr EQ t_ekpo_temp-lifnr.
IF sy-subrc EQ 0.
FREE t_ekpo_temp.
ENDIF.
ENDIF.
ENDFORM. " GET_VENDOR_DATA
*---------------------------------------------------------------------*
* Form GET_SCHEDULE_LINES *
*---------------------------------------------------------------------*
* This subroutine retrieves necessary schedule lines information *
* from table EKET *
*---------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine *
*---------------------------------------------------------------------*
FORM get_schedule_lines .
* Read table EKET using the values from the IT_EKPO + selection screen
SELECT ebeln
ebelp
eindt
FROM eket
INTO TABLE t_eket
FOR ALL ENTRIES IN t_ekpo
WHERE ebeln EQ t_ekpo-ebeln
AND ebelp EQ t_ekpo-ebelp.
IF sy-subrc EQ 0. "#EC NEEDED
*
ENDIF.
ENDFORM. " GET_SCHEDULE_LINES
*---------------------------------------------------------------------*
* Form GET_PDOC_HISTORY_DATA *
*---------------------------------------------------------------------*
* This subroutine retrieves necessary purchasing document history *
* category from table EKBE *
*---------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine *
*---------------------------------------------------------------------*
FORM get_pdoc_history_data .
* Read table EKBE using the values from the IT_EKPO + selection screen
SELECT ebeln
ebelp
gjahr
belnr
buzei
bewtp
bwart
budat
menge
dmbtr
shkzg
FROM ekbe
INTO TABLE t_ekbe
FOR ALL ENTRIES IN t_ekpo
WHERE ebeln EQ t_ekpo-ebeln
AND ebelp EQ t_ekpo-ebelp
AND bewtp IN s_bewtp
AND bwart IN s_bwart
AND grund IN s_grund
AND werks IN s_werks.
IF sy-subrc EQ 0. "#EC NEEDED
*
ENDIF.
ENDFORM. " GET_PDOC_HISTORY_DATA
*---------------------------------------------------------------------*
* Form GET_MATDOC_ITEM_DATA *
*---------------------------------------------------------------------*
* This subroutine retrieves material document segment data from *
* table MSEG *
*---------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine *
*---------------------------------------------------------------------*
FORM get_matdoc_item_data .
* Read table MSEG using the values from the IT_EKBE + selection screen
SELECT mblnr
mjahr
zeile
weunb
bwart
* shkzg
grund
FROM mseg
INTO TABLE t_mseg
FOR ALL ENTRIES IN t_ekbe
WHERE mblnr EQ t_ekbe-belnr
AND mjahr EQ t_ekbe-gjahr
AND zeile EQ t_ekbe-buzei
AND bwart IN s_bwart
AND werks IN s_werks
AND lifnr IN s_lifnr
AND ebeln IN s_ebeln
AND bukrs IN s_bukrs
AND grund IN s_grund.
IF sy-subrc EQ 0.
SORT t_mseg BY mblnr mjahr.
ENDIF.
ENDFORM. " GET_MATDOC_ITEM_DATA
*---------------------------------------------------------------------*
* Form GET_REASON_DESC *
*---------------------------------------------------------------------*
* This subroutine retrieves descriptions for reason for movement *
* from table T157E *
*---------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine *
*---------------------------------------------------------------------*
FORM get_reason_desc .
* Read table T157E using the values from the IT_MSEG + selection screen
APPEND LINES OF t_mseg TO t_mseg_temp.
SORT t_mseg_temp BY bwart
grund.
DELETE ADJACENT DUPLICATES FROM t_mseg_temp
COMPARING bwart
grund.
IF t_mseg_temp IS NOT INITIAL.
SELECT bwart
grund
grtxt
FROM t157e
INTO TABLE t_t157e
FOR ALL ENTRIES IN t_mseg_temp
WHERE spras EQ sy-langu
AND bwart EQ t_mseg_temp-bwart
AND grund EQ t_mseg_temp-grund.
IF sy-subrc EQ 0.
SORT t_t157e.
FREE t_mseg_temp.
ENDIF.
ENDIF.
ENDFORM. " GET_REASON_DESC
*---------------------------------------------------------------------*
* Form POPULATE_FINAL_DATA *
*---------------------------------------------------------------------*
* This subroutine is used for populating final data *
*---------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine. *
*---------------------------------------------------------------------*
FORM populate_final_data.
LOOP AT t_ekpo INTO w_ekpo.
* Populate purchase order data
w_final-ebeln = w_ekpo-ebeln.
w_final-ebelp = w_ekpo-ebelp.
w_final-txz01 = w_ekpo-txz01.
w_final-werks = w_ekpo-werks.
w_final-bednr = w_ekpo-bednr.
w_final-matkl = w_ekpo-matkl.
w_final-poqty = w_ekpo-menge.
w_final-meins = w_ekpo-meins.
w_final-brtwr = w_ekpo-brtwr.
w_final-afnam = w_ekpo-afnam.
w_final-bsart = w_ekpo-bsart.
w_final-lifnr = w_ekpo-lifnr.
w_final-aedat = w_ekpo-aedat.
w_final-ernam = w_ekpo-ernam.
w_final-ekgrp = w_ekpo-ekgrp.
w_final-waers = w_ekpo-waers.
* Populate vendor name
READ TABLE t_lfa1 INTO w_lfa1
WITH KEY lifnr = w_ekpo-lifnr
BINARY SEARCH.
IF sy-subrc EQ 0.
w_final-name1 = w_lfa1-name1.
ENDIF.
* Populate item delivery date
READ TABLE t_eket INTO w_eket
WITH KEY ebeln = w_ekpo-ebeln
ebelp = w_ekpo-ebelp
BINARY SEARCH.
IF sy-subrc EQ 0.
w_final-eindt = w_eket-eindt.
ENDIF.
*----------------------------------------------
* Populate purchase order history category
READ TABLE t_ekbe INTO w_ekbe
WITH KEY ebeln = w_ekpo-ebeln
ebelp = w_ekpo-ebelp
BINARY SEARCH.
IF sy-subrc EQ 0.
LOOP AT t_ekbe INTO w_ekbe FROM sy-tabix.
IF w_ekbe-ebeln EQ w_ekpo-ebeln
AND w_ekbe-ebelp EQ w_ekpo-ebelp.
w_final-budat = w_ekbe-budat.
w_final-belnr = w_ekbe-belnr.
w_final-dmbtr = w_ekbe-dmbtr.
w_final-bwart = w_ekbe-bwart.
w_final-bewtp = w_ekbe-bewtp.
w_final-grqty = w_ekbe-menge.
w_final-shkzg = w_ekbe-shkzg.
* Populate material document data
READ TABLE t_mseg INTO w_mseg
WITH KEY mblnr = w_ekbe-belnr
mjahr = w_ekbe-gjahr
zeile = w_ekbe-buzei
BINARY SEARCH.
IF sy-subrc EQ 0.
w_final-grund = w_mseg-grund.
w_final-weunb = w_mseg-weunb.
* w_final-shkzg = w_mseg-shkzg.
* Populate Reason descriptions
CLEAR w_t157e.
READ TABLE t_t157e INTO w_t157e
WITH KEY bwart = w_mseg-bwart
grund = w_mseg-grund
BINARY SEARCH.
IF sy-subrc EQ 0.
w_final-grtxt = w_t157e-grtxt.
ENDIF.
ENDIF.
APPEND w_final TO t_final.
CLEAR:
w_final-grund,
w_final-weunb,
* w_final-shkzg,
w_final-grtxt,
w_t157e,
w_mseg,
w_ekbe.
ELSE.
EXIT.
ENDIF.
ENDLOOP.
ELSE.
APPEND w_final TO t_final.
ENDIF.
CLEAR :
w_ekbe,
w_eket,
w_lfa1,
w_ekpo,
w_final.
ENDLOOP.
FREE:
t_ekpo,
t_eket,
t_ekbe,
t_mseg,
t_lfa1,
t_t157e.
*------------------------------------------------------------
* LOOP AT t_ekpo INTO w_ekpo.
** Populate purchase order data
* w_final-ebeln = w_ekpo-ebeln.
* w_final-ebelp = w_ekpo-ebelp.
* w_final-txz01 = w_ekpo-txz01.
* w_final-werks = w_ekpo-werks.
* w_final-bednr = w_ekpo-bednr.
* w_final-matkl = w_ekpo-matkl.
* w_final-poqty = w_ekpo-menge.
* w_final-meins = w_ekpo-meins.
* w_final-brtwr = w_ekpo-brtwr.
* w_final-afnam = w_ekpo-afnam.
* w_final-bsart = w_ekpo-bsart.
* w_final-lifnr = w_ekpo-lifnr.
* w_final-aedat = w_ekpo-aedat.
* w_final-ernam = w_ekpo-ernam.
* w_final-ekgrp = w_ekpo-ekgrp.
* w_final-waers = w_ekpo-waers.
** Populate vendor name
* CLEAR w_lfa1.
* READ TABLE t_lfa1 INTO w_lfa1
* WITH KEY lifnr = w_ekpo-lifnr
* BINARY SEARCH.
* IF sy-subrc EQ 0.
* w_final-name1 = w_lfa1-name1.
* ENDIF.
** Populate item delivery date
* CLEAR w_eket.
* READ TABLE t_eket INTO w_eket
* WITH KEY ebeln = w_ekpo-ebeln
* ebelp = w_ekpo-ebelp
* BINARY SEARCH.
* IF sy-subrc EQ 0.
* w_final-eindt = w_eket-eindt.
* ENDIF.
** Populate purchase order history category
* clear w_ekbe.
* READ TABLE t_ekbe INTO w_ekbe
* WITH KEY ebeln = w_ekpo-ebeln
* ebelp = w_ekpo-ebelp
* BINARY SEARCH.
* IF sy-subrc EQ 0.
* LOOP AT t_ekbe INTO w_ekbe FROM sy-tabix.
*
* IF w_ekbe-ebeln EQ w_ekpo-ebeln
* AND w_ekbe-ebelp EQ w_ekpo-ebelp.
*
* w_final-budat = w_ekbe-budat.
* w_final-belnr = w_ekbe-belnr.
* w_final-dmbtr = w_ekbe-dmbtr.
* w_final-bwart = w_ekbe-bwart.
* w_final-bewtp = w_ekbe-bewtp.
* w_final-grqty = w_ekbe-menge.
*
** Populate material document data
* clear w_mseg.
* READ TABLE t_mseg INTO w_mseg
* WITH KEY mblnr = w_ekbe-belnr
* mjahr = w_ekbe-gjahr
* zeile = w_ekbe-buzei
* BINARY SEARCH.
* IF sy-subrc EQ 0.
* w_final-grund = w_mseg-grund.
* w_final-weunb = w_mseg-weunb.
* w_final-shkzg = w_mseg-shkzg.
** Populate Reason descriptions
* clear w_t157e.
* READ TABLE t_t157e INTO w_t157e
* WITH KEY bwart = w_mseg-bwart
* grund = w_mseg-grund
* BINARY SEARCH.
* IF sy-subrc EQ 0.
* w_final-grtxt = w_t157e-grtxt.
* ENDIF.
* ELSE.
* CLEAR:
* w_final-grund,
* w_final-weunb,
* w_final-shkzg,
* w_final-grtxt.
* ENDIF.
* APPEND w_final TO t_final.
* CLEAR:
* w_t157e,
* w_mseg,
* w_ekbe.
* ELSE.
* EXIT.
* ENDIF.
* ENDLOOP.
* ELSE.
* APPEND w_final TO t_final.
* CLEAR :
* w_ekbe,
* w_eket,
* w_lfa1,
* w_ekpo,
* w_final.
* ENDIF.
* ENDLOOP.
* FREE:
* t_ekpo,
* t_eket,
* t_ekbe,
* t_mseg,
* t_lfa1,
* t_t157e.
ENDFORM. " POPULATE FINAL_DATA
*---------------------------------------------------------------------*
* Form DISPLAY_ALV *
*---------------------------------------------------------------------*
* This subroutine is used for displaying ALV *
*---------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine. *
*---------------------------------------------------------------------*
FORM display_alv .
* Local Data Declaration
DATA:
lw_err_msg TYPE REF TO cx_salv_msg,
lw_key TYPE salv_s_layout_key.
TRY.
* 1. Instantiate the ALV Global Class
* -----------------------------------------
cl_salv_table=>factory(
IMPORTING
r_salv_table = obj_alv_table
CHANGING
t_table = t_final_dis ).
* 2. This Function is for the Tool Bar
* -----------------------------------------
* Get Object Reference to the Tool Bar Functions
CALL METHOD obj_alv_table->get_functions
RECEIVING
value = obj_functions.
* Activate all ALV Tool Bar Functions
CALL METHOD obj_functions->set_all
EXPORTING
value = if_salv_c_bool_sap=>true.
* Set the Key fields for the Report Display
* Get the Object Reference for Column
CALL METHOD obj_alv_table->get_columns
RECEIVING
value = obj_columns.
* 3. This is for the ALV Layout Functions
* -----------------------------------------
* Get the Object Reference for the ALV Layout
CALL METHOD obj_alv_table->get_layout
RECEIVING
value = obj_layout.
* Set the Key
lw_key-report = sy-repid.
obj_layout->set_key( lw_key ).
* Set the Save Layout Option
obj_layout->set_save_restriction(
if_salv_c_layout=>restrict_none ).
* Activate Option of Saving Default Setting
obj_layout->set_default( abap_true ).
* If there is a Selection Screen Entry for Layout then Set The Layout
IF NOT p_layout IS INITIAL.
obj_layout->set_initial_layout( p_layout ).
ENDIF.
* 4. Update Column Related Data
* -----------------------------------------
TRY.
* Purchasing Document Number - Set Column Text
obj_column ?= obj_columns->get_column( columnname = 'EBELN' ).
obj_column->set_long_text('Purchasing Document Number' ).
obj_column->set_medium_text('PO Number' ).
obj_column->set_short_text('PO Number' ).
obj_column->set_output_length( 25 ).
* Puchase Order Type - Set Column Text
obj_column ?= obj_columns->get_column( columnname = 'BSART' ).
obj_column->set_long_text('Purchasing Document Type' ).
obj_column->set_medium_text('PO Type' ).
obj_column->set_short_text('PO Type' ).
obj_column->set_output_length( 21 ).
* PO Created Date - Set Column Text
obj_column ?= obj_columns->get_column( columnname = 'AEDAT' ).
obj_column->set_long_text('Date on which the record was created' ).
obj_column->set_medium_text('PO Created Date' ).
obj_column->set_short_text('Created on' ).
obj_column->set_output_length( 30 ).
* PO Created By - Set Column Text
obj_column ?= obj_columns->get_column( columnname = 'ERNAM' ).
obj_column->set_long_text('Name of Person who Created the Object' ).
obj_column->set_medium_text('PO Created By' ).
obj_column->set_short_text('Created By' ).
obj_column->set_output_length( 32 ).
* Vendor's account number - Set Column Text
obj_column ?= obj_columns->get_column( columnname = 'LIFNR' ).
obj_column->set_long_text('Vendors account number' ).
obj_column->set_medium_text('Vendor No' ).
obj_column->set_short_text('Vendor No' ).
obj_column->set_output_length( 20 ).
* Vendor Name - Set Column Text
obj_column ?= obj_columns->get_column( columnname = 'NAME1' ).
obj_column->set_long_text('Name 1' ).
obj_column->set_medium_text('Name 1' ).
obj_column->set_short_text('Name 1' ).
obj_column->set_output_length( 10 ).
* Purchasing group - Set Column Text
obj_column ?= obj_columns->get_column( columnname = 'EKGRP' ).
obj_column->set_long_text('Purchasing Group' ).
obj_column->set_medium_text('Purchasing Group' ).
obj_column->set_short_text('Pur. Group' ).
obj_column->set_output_length( 15 ).
* PO Item Number - Set Column Text
obj_column ?= obj_columns->get_column( columnname = 'EBELP' ).
obj_column->set_long_text('Item Number of Purchasing Document' ).
obj_column->set_medium_text('PO Item No' ).
obj_column->set_short_text('PO Item' ).
obj_column->set_output_length( 35 ).
* Short text - Set Column Text
obj_column ?= obj_columns->get_column( columnname = 'TXZ01' ).
obj_column->set_long_text('Short Text' ).
obj_column->set_medium_text('Short Text' ).
obj_column->set_short_text('Short Text' ).
obj_column->set_output_length( 10 ).
* Material group - Set Column Text
obj_column ?= obj_columns->get_column( columnname = 'MATKL' ).
obj_column->set_long_text('Material Group' ).
obj_column->set_medium_text('Material Group' ).
obj_column->set_short_text('Mat. Group' ).
obj_column->set_output_length( 14 ).
* Req. Tracking Number - Set Column Text
obj_column ?= obj_columns->get_column( columnname = 'BEDNR' ).
obj_column->set_long_text('Requirement Tracking Number' ).
obj_column->set_medium_text('Req. Tracking Number' ).
obj_column->set_short_text('Req. Tr No' ).
obj_column->set_output_length( 25 ).
* Purchase order quantity - Set Column Text
obj_column ?= obj_columns->get_column( columnname = 'POQTY' ).
obj_column->set_long_text('Purchase order quantity' ).
obj_column->set_medium_text('PO Quantity' ).
obj_column->set_short_text('PO Qty' ).
obj_column->set_output_length( 19 ).
* Order unit - Set Column Text
obj_column ?= obj_columns->get_column( columnname = 'UNIT1' ).
obj_column->set_long_text('Order Unit' ).
obj_column->set_medium_text('Order Unit' ).
obj_column->set_short_text('Order Unit' ).
obj_column->set_output_length( 10 ).
* Gross order value in PO currency - Set Column Text
obj_column ?= obj_columns->get_column( columnname = 'BRTWR' ).
obj_column->set_long_text('Gross order value in PO currency' ).
obj_column->set_medium_text('Gross value' ).
obj_column->set_short_text('Gross val.' ).
obj_column->set_output_length( 35 ).
* Currency Key - Set Column Text
obj_column ?= obj_columns->get_column( columnname = 'CUKY1' ).
obj_column->set_long_text('Currency Key' ).
obj_column->set_medium_text('Currency Key' ).
obj_column->set_short_text('Curr. Key' ).
obj_column->set_output_length( 13 ).
* Order unit - Set Column Text
obj_column ?= obj_columns->get_column( columnname = 'UNIT2' ).
obj_column->set_long_text('Order Unit' ).
obj_column->set_medium_text('Order Unit' ).
obj_column->set_short_text('Order Unit' ).
obj_column->set_output_length( 10 ).
* Name of requisitioner - Set Column Text
obj_column ?= obj_columns->get_column( columnname = 'AFNAM' ).
obj_column->set_long_text('Name of Requisitioner' ).
obj_column->set_medium_text('Requisitioner' ).
obj_column->set_short_text('Req. Name' ).
obj_column->set_output_length( 20 ).
* PO history category - Set Column Text
obj_column ?= obj_columns->get_column( columnname = 'BEWTP' ).
obj_column->set_long_text('PO History Category' ).
obj_column->set_medium_text('PO history category' ).
obj_column->set_short_text('Hist. Cat.' ).
obj_column->set_output_length( 20 ).
* Item delivery date - Set Column Text
obj_column ?= obj_columns->get_column( columnname = 'EINDT' ).
obj_column->set_long_text('Item Delivery Date' ).
obj_column->set_medium_text('Delivery Date' ).
obj_column->set_short_text('Del. Date' ).
obj_column->set_output_length( 17 ).
* GRN Date - Set Column Text
obj_column ?= obj_columns->get_column( columnname = 'BUDAT' ).
obj_column->set_long_text('Posting Date in the Document' ).
obj_column->set_medium_text('GRN Date' ).
obj_column->set_short_text('GRN Date' ).
obj_column->set_output_length( 25 ).
* GR Quantity - Set Column Text
obj_column ?= obj_columns->get_column( columnname = 'GRQTY' ).
obj_column->set_long_text('Quantity' ).
obj_column->set_medium_text('Quantity' ).
obj_column->set_short_text('GR Qty' ).
obj_column->set_output_length( 10 ).
* Order unit - Set Column Text
obj_column ?= obj_columns->get_column( columnname = 'UNIT3').
obj_column->set_long_text('Order Unit' ).
obj_column->set_medium_text('Order Unit' ).
obj_column->set_short_text('Order Unit' ).
obj_column->set_output_length( 10 ).
* Goods Receipt, Non-Valuated - Set Column Text
obj_column ?= obj_columns->get_column( columnname = 'WEUNB' ).
obj_column->set_long_text('Goods Receipt, Non-Valuated' ).
obj_column->set_medium_text('GR, Non-Valuated' ).
obj_column->set_short_text('GR,Non-Val' ).
obj_column->set_output_length( 25 ).
** Debit/Credit Indicator - Set Column Text
* obj_column ?= obj_columns->get_column( columnname = 'SHKZG'
*).
* obj_column->set_long_text('Debit/Credit Ind.' ).
* obj_column->set_medium_text('Debit/Credit Ind.' ).
* obj_column->set_short_text('D/C Indic.' ).
* obj_column->set_output_length( 10 ).
* Amount in local currency - Set Column Text
obj_column ?= obj_columns->get_column( columnname = 'DMBTR' ).
obj_column->set_long_text('Amount in Local Currency' ).
obj_column->set_medium_text('Amt in Local Curr.' ).
obj_column->set_short_text('Amt in LC' ).
obj_column->set_output_length( 22 ).
* Currency Key - Set Column Text
obj_column ?= obj_columns->get_column( columnname = 'CUKY2' ).
obj_column->set_long_text('Currency Key' ).
obj_column->set_medium_text('Currency Key' ).
obj_column->set_short_text('Curr. Key' ).
obj_column->set_output_length( 13 ).
* Debit/Credit Indicator - Set Column Text
obj_column ?= obj_columns->get_column( columnname = 'SHKZG' ).
obj_column->set_long_text('Debit or Credit' ).
obj_column->set_medium_text('Debit or Credit' ).
obj_column->set_short_text('D/C Indic.' ).
obj_column->set_output_length( 17 ).
* Movement Type - Set Column Text
obj_column ?= obj_columns->get_column( columnname = 'BWART' ).
obj_column->set_long_text('Movement Type' ).
obj_column->set_medium_text('Movement Type' ).
obj_column->set_short_text('Mov. Type' ).
obj_column->set_output_length( 13 ).
* Reason for movement - Set Column Text
obj_column ?= obj_columns->get_column( columnname = 'GRUND' ).
obj_column->set_long_text('Reason code' ).
obj_column->set_medium_text('Reason code' ).
obj_column->set_short_text('Reason' ).
obj_column->set_output_length( 11 ).
* Reason for goods movement description - Set Column Text
obj_column ?= obj_columns->get_column( columnname = 'GRTXT' ).
obj_column->set_long_text('Reason Descriptions' ).
obj_column->set_medium_text('Reason Descriptions' ).
obj_column->set_short_text('RDesc' ).
obj_column->set_output_length( 19 ).
CATCH cx_salv_not_found. "#EC NO_HANDLER
* Do Nothing
ENDTRY.
* 5. Modify Display Settings
* -----------------------------------------
CALL METHOD obj_alv_table->get_display_settings
RECEIVING
value = obj_display.
obj_display->set_striped_pattern( abap_true ).
* 6. Display the ALV Data
* -----------------------------------------
IF obj_alv_table IS BOUND.
obj_alv_table->display( ).
ENDIF.
* Exceptions
* -----------------------------------------
CATCH cx_salv_msg INTO lw_err_msg.
ENDTRY.
ENDFORM. " DISPLAY_ALV
*---------------------------------------------------------------------*
* Form SUB_F4_LAYOUT *
*---------------------------------------------------------------------*
* This subroutine is for providing f4 help for layout *
*---------------------------------------------------------------------*
* -->P_IF_SALV_C_LAYOUT=>RESTRICT_NON text *
* <--P_P_LAYOUT text *
*---------------------------------------------------------------------*
FORM sub_f4_layout USING im_restrict TYPE salv_de_layout_restriction
CHANGING ch_layout TYPE disvariant-variant.
DATA: lw_layout TYPE salv_s_layout_info,
lw_key TYPE salv_s_layout_key.
lw_key-report = sy-repid.
lw_layout = cl_salv_layout_service=>f4_layouts(
s_key = lw_key
restrict = im_restrict ).
ch_layout = lw_layout-layout.
ENDFORM. " SUB_F4_LAYOUT
*---------------------------------------------------------------------*
* Form POPULATE_DISPLAY_DATA *
*---------------------------------------------------------------------*
* This subroutine populates T_FINAL_DIS based on T_FINAL *
*---------------------------------------------------------------------*
FORM populate_display_data .
LOOP AT t_final INTO w_final.
w_final_dis-ebeln = w_final-ebeln.
w_final_dis-bsart = w_final-bsart.
w_final_dis-aedat = w_final-aedat.
w_final_dis-ernam = w_final-ernam.
w_final_dis-lifnr = w_final-lifnr.
w_final_dis-name1 = w_final-name1.
w_final_dis-ekgrp = w_final-ekgrp.
w_final_dis-ebelp = w_final-ebelp.
w_final_dis-txz01 = w_final-txz01.
w_final_dis-matkl = w_final-matkl.
w_final_dis-bednr = w_final-bednr.
w_final_dis-poqty = w_final-poqty.
w_final_dis-unit1 = w_final-meins.
w_final_dis-brtwr = w_final-brtwr.
w_final_dis-cuky1 = w_final-waers.
w_final_dis-unit2 = w_final-meins.
w_final_dis-afnam = w_final-afnam.
w_final_dis-bewtp = w_final-bewtp.
w_final_dis-eindt = w_final-eindt.
w_final_dis-budat = w_final-budat.
w_final_dis-grqty = w_final-grqty.
w_final_dis-unit3 = w_final-meins.
w_final_dis-weunb = w_final-weunb.
w_final_dis-dmbtr = w_final-dmbtr.
w_final_dis-shkzg = w_final-shkzg.
w_final_dis-cuky2 = w_final-waers.
w_final_dis-bwart = w_final-bwart.
w_final_dis-grund = w_final-grund.
w_final_dis-grtxt = w_final-grtxt.
APPEND w_final_dis TO t_final_dis.
CLEAR w_final_dis.
ENDLOOP.
REFRESH t_final.
ENDFORM. " POPULATE_DISPLAY_DATA
REPORT /xxxsep/fap001 NO STANDARD PAGE HEADING.
INCLUDE /xxxsep/fap001_top. " Data Declarations
INCLUDE /xxxsep/fap001_sel. " Selection Screen Definition
INCLUDE /xxxsep/fap001_routine. " Subroutines
***********************************************************************
* Validations *
***********************************************************************
AT SELECTION-SCREEN ON s_bukrs.
PERFORM validate_com_code.
AT SELECTION-SCREEN ON s_werks.
PERFORM validate_plant.
AT SELECTION-SCREEN ON s_ebeln.
PERFORM validate_pur_order.
AT SELECTION-SCREEN ON s_ekgrp.
PERFORM validate_pur_group .
AT SELECTION-SCREEN ON s_matkl.
PERFORM validate_mat_group .
AT SELECTION-SCREEN ON s_bewtp.
PERFORM validate_po_history_cat.
AT SELECTION-SCREEN ON s_bwart.
PERFORM validate_mov_type.
AT SELECTION-SCREEN ON s_grund.
PERFORM validate_movement_reason.
AT SELECTION-SCREEN ON s_bednr.
PERFORM validate_track_no.
AT SELECTION-SCREEN ON s_lifnr.
PERFORM validate_vendor.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_layout.
PERFORM sub_f4_layout USING if_salv_c_layout=>restrict_none
CHANGING p_layout.
***********************************************************************
* START-OF-SELECTION *
***********************************************************************
START-OF-SELECTION.
PERFORM get_data.
***********************************************************************
* END-OF-SELECTION *
***********************************************************************
END-OF-SELECTION.
PERFORM populate_final_data.
PERFORM populate_display_data.
IF t_final_dis IS NOT INITIAL.
PERFORM display_alv.
ELSE.
MESSAGE text-t13 TYPE 'I'.
ENDIF.
***********************************************************************
Include - /xxxSEP/FAP001_TOP
***********************************************************************
* Type Declarations
***********************************************************************
TYPES:
* Strcture type to declare selection screen
BEGIN OF type_s_sel,
bukrs TYPE t001-bukrs, " Company Code
werks TYPE t001w-werks, " Plant
ebeln TYPE ekko-ebeln, " Purchasing Document Number
aedat TYPE ekko-aedat, " Created on
ekgrp TYPE ekko-ekgrp, " Purchasing Group
loekz TYPE ekko-loekz, " Deletion Indicator
matkl TYPE ekpo-matkl, " Material Group
bewtp TYPE ekbe-bewtp, " PO History Category
bwart TYPE t156-bwart, " Movement Type
grund TYPE t157d-grund, " Reason for Movement
bednr TYPE ekpo-bednr, " Requirement Tracking Number
lifnr TYPE ekko-lifnr, " Vendor Account Number
END OF type_s_sel,
* Strcture type to declare purchasing document header data
BEGIN OF type_s_ekpo,
ebeln TYPE ebeln, " Purchasing Document Number
bukrs TYPE bukrs, " Company Code
bsart TYPE esart, " Purchasing Document Type
loekz TYPE eloek, " Deletion Indicator
aedat TYPE erdat, " Created on
ernam TYPE ernam, " Created By
lifnr TYPE elifn, " Vendor Account Number
ekgrp TYPE bkgrp, " Purchasing Group
waers TYPE waers, " Currency Key
ebelp TYPE ebelp, " Purchasing Document Item
txz01 TYPE txz01, " Short Text
werks TYPE ewerk, " Plant
bednr TYPE bednr, " Requirement Tracking Number
matkl TYPE matkl, " Material Group
menge TYPE bstmg, " PO Quantity
meins TYPE bstme, " Unit of Measure
brtwr TYPE bbwert, " Gross Order Value
weunb TYPE weunb, " GR Non-Valuated
afnam TYPE afnam, " Name of Requisitioner
END OF type_s_ekpo,
* Strcture type to declare schedule lines data
BEGIN OF type_s_eket,
ebeln TYPE ebeln, " Purchasing Document Number
ebelp TYPE ebelp, " Purchasing Document Item
eindt TYPE eindt, " Item Delivery Date
END OF type_s_eket,
* Strcture type to declare purchasing document History
BEGIN OF type_s_ekbe,
ebeln TYPE ebeln, " Purchasing Document Number
ebelp TYPE ebelp, " Purchasing Document Item
gjahr TYPE mjahr, " Material Document Year
belnr TYPE mblnr, " Material Document
buzei TYPE mblpo, " Material Document Item
bewtp TYPE bewtp, " PO History Category
bwart TYPE bwart, " Movement Type
budat TYPE budat, " Posting Date
menge TYPE bstmg, " PO Quantity
dmbtr TYPE dmbtr, " Amount in Local Currency
shkzg type shkzg, "
END OF type_s_ekbe,
* Strcture type to declare material document data
BEGIN OF type_s_mseg,
mblnr TYPE mblnr, " Material Document
mjahr TYPE mjahr, " Material Document Year
zeile TYPE mblpo, " Material Document Item
weunb TYPE weunb, " GR Non-Valuated
bwart TYPE bwart, " Movement Type
* shkzg TYPE shkzg, " D/C Indicator "
grund TYPE mb_grbew, " Reason for Movement
END OF type_s_mseg,
* Strcture type to declare vendor data
BEGIN OF type_s_lfa1,
lifnr TYPE lifnr, " Vendor Account Number
name1 TYPE name1, " Vendor Name
END OF type_s_lfa1,
* Strcture type to declare reason for movement data
BEGIN OF type_s_t157e,
bwart TYPE bwart,
grund TYPE mb_grbew, " Reason for Movement
grtxt TYPE grtxt, " Reason Descriptions
END OF type_s_t157e,
* Strcture type to declare final data
BEGIN OF type_s_final,
ebeln TYPE ebeln, " Purchasing Document Number
ebelp TYPE ebelp, " Purchasing Document Item
bsart TYPE esart, " Purchasing Document Type
aedat TYPE erdat, " Created on
ernam TYPE ernam, " Created By
lifnr TYPE lifnr, " Vendor Account No
name1 TYPE name1, " Vendor Name
ekgrp TYPE bkgrp, " Purchasing Group
werks TYPE ewerk, " Plant
txz01 TYPE txz01, " Short Text
matkl TYPE matkl, " Material Group
bednr TYPE bednr, " Requirement Tracking Number
poqty TYPE bstmg, " PO Quantity
meins TYPE bstme, " Unit of Measure
brtwr TYPE bbwert, " Gross Order Value
waers TYPE waers, " Currency Key
afnam TYPE afnam, " Name of Requisitioner
eindt TYPE eindt, " Item Delivery Date
bewtp TYPE bewtp, " PO History Category
budat TYPE budat, " Posting Date
belnr TYPE mblnr, " GRN Doc no
grqty TYPE bstmg, " GR Quantity
bwart TYPE bwart, " Movement Type
weunb TYPE weunb, " GR Non-Valuated
shkzg TYPE shkzg, " D/C Indicator "
dmbtr TYPE dmbtr, " Amount in Local Currency
grund TYPE mb_grbew, " Reason for Movement
grtxt TYPE grtxt, " Reason Description
END OF type_s_final,
BEGIN OF type_s_final_dis,
ebeln TYPE ebeln, " Purchasing Document Number
bsart TYPE esart, " Purchasing Document Type
aedat TYPE erdat, " Created on
ernam TYPE ernam, " Created By
lifnr TYPE lifnr, " Vendor Account No
name1 TYPE name1, " Vendor Name
ekgrp TYPE bkgrp, " Purchasing Group
ebelp TYPE ebelp, " Purchasing Document Item
txz01 TYPE txz01, " Short Text
matkl TYPE matkl, " Material Group
bednr TYPE bednr, " Requirement Tracking Number
poqty TYPE bstmg, " PO Quantity
unit1 TYPE bstme, " Unit of Measure
brtwr TYPE bbwert, " Gross Order Value
cuky1 TYPE waers, " Currency Key
unit2 TYPE bstme, " Unit of Measure
afnam TYPE afnam, " Name of Requisitioner
bewtp TYPE bewtp, " PO History Category
eindt TYPE eindt, " Item Delivery Date
budat TYPE budat, " Posting Date
grqty TYPE bstmg, " GR Quantity
unit3 TYPE bstme, " Unit of Measure
weunb TYPE weunb, " GR Non-Valuated
dmbtr TYPE dmbtr, " Amount in Local Currency
cuky2 TYPE waers, " Currency Key
shkzg TYPE shkzg, " D/C Indicator
bwart TYPE bwart, " Movement Type
grund TYPE mb_grbew, " Reason for Movement
grtxt TYPE grtxt, " Reason Description
END OF type_s_final_dis.
***********************************************************************
* Work areas
***********************************************************************
DATA:
* Work area to declare selection screen
w_sel TYPE type_s_sel,
* Work area to declare purchasing document header and item data
w_ekpo TYPE type_s_ekpo,
* Work area to declare purchasing document history
w_ekbe TYPE type_s_ekbe,
* Work area to declare Schedule lines data
w_eket TYPE type_s_eket,
* Work area to declare vendor data
w_lfa1 TYPE type_s_lfa1,
* Work area to declare material document data
w_mseg TYPE type_s_mseg,
* Work area to declare reason for movement dat
w_t157e TYPE type_s_t157e,
* Work area to declare final data
w_final TYPE type_s_final,
w_final_dis TYPE type_s_final_dis.
***********************************************************************
* INTERNAL TABLES
***********************************************************************
DATA:
* Internal table to hold purchasing document header data and item data
t_ekpo TYPE STANDARD TABLE
OF type_s_ekpo,
t_ekpo_temp TYPE STANDARD TABLE
OF type_s_ekpo,
* Internal table to hold schedule lines data
t_eket TYPE SORTED TABLE
OF type_s_eket
WITH NON-UNIQUE KEY ebeln ebelp,
* Internal table to hold purchase order history category data
t_ekbe TYPE SORTED TABLE
OF type_s_ekbe
WITH NON-UNIQUE KEY ebeln ebelp,
* Internal table to hold material document data
t_mseg TYPE STANDARD TABLE
OF type_s_mseg,
t_mseg_temp TYPE STANDARD TABLE
OF type_s_mseg,
* Internal table to hold reason for movement data
t_t157e TYPE STANDARD TABLE
OF type_s_t157e,
* Internal table to hold vendor data
t_lfa1 TYPE SORTED TABLE
OF type_s_lfa1
WITH UNIQUE KEY lifnr,
* Internal table to hold final data
t_final TYPE STANDARD TABLE
OF type_s_final,
t_final_Dis TYPE STANDARD TABLE
OF type_s_final_dis.
***********************************************************************
* Objects
***********************************************************************
DATA:
obj_column TYPE REF TO cl_salv_column_table,
obj_columns TYPE REF TO cl_salv_columns_table,
obj_layout TYPE REF TO cl_salv_layout,
obj_display TYPE REF TO cl_salv_display_settings,
obj_functions TYPE REF TO cl_salv_functions,
obj_alv_table TYPE REF TO cl_salv_table.
***********************************************************************
Include - /xxxSEP/FAP001_SEL
***********************************************************************
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-t00.
SELECT-OPTIONS:
s_bukrs FOR w_sel-bukrs " Company Code
OBLIGATORY,
s_werks FOR w_sel-werks, " Plant
s_ebeln FOR w_sel-ebeln, " Purchasing Document Number
s_aedat FOR w_sel-aedat, " Created on
s_ekgrp FOR w_sel-ekgrp, " Purchasing Group
s_loekz FOR w_sel-loekz, " Deletion Indicator
s_matkl FOR w_sel-matkl, " Material Group
s_bewtp FOR w_sel-bewtp, " PO History Category
s_bwart FOR w_sel-bwart, " Movement Type
s_grund FOR w_sel-grund. " Reason for Movement
SELECTION-SCREEN END OF BLOCK b1.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-t01.
SELECT-OPTIONS:
s_bednr FOR w_sel-bednr, " Requirement Tracking Number
s_lifnr FOR w_sel-lifnr. " Vendor Account Number
SELECTION-SCREEN END OF BLOCK b2.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN BEGIN OF BLOCK blk3 WITH FRAME TITLE text-b03.
PARAMETERS
p_layout TYPE disvariant-variant. " Layout
SELECTION-SCREEN END OF BLOCK blk3.
************************************************************************
Include - /SBDSEP/FAP001_ROUTINE
************************************************************************
*---------------------------------------------------------------------*
* Form VALIDATE_COMP_CODE *
*---------------------------------------------------------------------*
* This subroutine is used to validate company code *
*---------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine *
*---------------------------------------------------------------------*
FORM validate_com_code .
IF NOT s_bukrs IS INITIAL.
SELECT SINGLE bukrs
INTO w_sel-bukrs
FROM t001
WHERE bukrs IN s_bukrs[].
IF sy-subrc <> 0.
MESSAGE text-t02 TYPE 'E'.
ENDIF.
ENDIF.
ENDFORM. " VALIDATE_COM_CODE
*---------------------------------------------------------------------*
* Form VALIDATE_PLANT *
*---------------------------------------------------------------------*
* This subroutine is used to validate plant *
*---------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine *
*---------------------------------------------------------------------*
FORM validate_plant .
IF NOT s_werks IS INITIAL.
SELECT SINGLE werks
INTO w_sel-werks
FROM t001w
WHERE werks IN s_werks[].
IF sy-subrc <> 0.
MESSAGE text-t03 TYPE 'E'.
ENDIF.
ENDIF.
ENDFORM. " VALIDATE_PLANT
*---------------------------------------------------------------------*
* Form VALIDATE_PUR_ORDER
*---------------------------------------------------------------------*
* This subroutine is used to validate purchase order *
*---------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine *
*---------------------------------------------------------------------*
FORM validate_pur_order .
IF NOT s_ebeln IS INITIAL.
SELECT SINGLE ebeln
INTO w_sel-ebeln
FROM ekko
WHERE ebeln IN s_ebeln[].
IF sy-subrc <> 0.
MESSAGE text-t04 TYPE 'E'.
ENDIF.
ENDIF.
ENDFORM. " VALIDATE_PUR_ORDER
*&---------------------------------------------------------------------*
*& Form SUB_VALIDATE_PUR_GROUP
*---------------------------------------------------------------------*
* This subroutine is used to validate deletion indicator *
*---------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine *
*---------------------------------------------------------------------*
FORM validate_pur_group .
IF NOT s_ekgrp IS INITIAL.
SELECT SINGLE ekgrp
FROM t024
INTO w_sel-ekgrp
WHERE ekgrp IN s_ekgrp[].
IF sy-subrc <> 0.
MESSAGE text-t05 TYPE 'E'.
ENDIF.
ENDIF.
ENDFORM. " VALIDATE_PUR_GROUP
*---------------------------------------------------------------------*
* Form VALIDATE_MAT_GROUP *
*---------------------------------------------------------------------*
* This subroutine is used to validate material group *
*---------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine *
*---------------------------------------------------------------------*
FORM validate_mat_group .
IF NOT s_matkl IS INITIAL.
SELECT SINGLE matkl
INTO w_sel-matkl
FROM t023
WHERE matkl IN s_matkl[].
IF sy-subrc <> 0.
MESSAGE text-t07 TYPE 'E'.
ENDIF.
ENDIF.
ENDFORM. " VALIDATE_MAT_GROUP
*---------------------------------------------------------------------*
* Form VALIDATE_PO_HISTORY_CAT *
*---------------------------------------------------------------------*
* This subroutine is used to validate PO history category *
*---------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine *
*---------------------------------------------------------------------*
FORM validate_po_history_cat.
IF NOT s_bewtp IS INITIAL.
SELECT SINGLE bewtp
INTO w_sel-bewtp
FROM t163b
WHERE bewtp IN s_bewtp[].
IF sy-subrc <> 0.
MESSAGE text-t08 TYPE 'E'.
ENDIF.
ENDIF.
ENDFORM. " VALIDATE_PO_HISTORY_CAT
*---------------------------------------------------------------------*
* Form VALIDATE_MOV_TYPE *
*---------------------------------------------------------------------*
* This subroutine is used to validate movement type *
*---------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine *
*---------------------------------------------------------------------*
FORM validate_mov_type .
IF NOT s_bwart IS INITIAL.
SELECT SINGLE bwart
INTO w_sel-bwart
FROM t156
WHERE bwart IN s_bwart[].
IF sy-subrc <> 0.
MESSAGE text-t09 TYPE 'E'.
ENDIF.
ENDIF.
ENDFORM. " VALIDATE_MOV_TYPE
*---------------------------------------------------------------------*
* Form VALIDATE_MOVEMENT_REASON *
*---------------------------------------------------------------------*
* This subroutine is used to validate reason for movement *
*---------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine *
*---------------------------------------------------------------------*
FORM validate_movement_reason .
IF NOT s_grund IS INITIAL.
SELECT grund UP TO 1 ROWS
INTO w_sel-grund
FROM t157d
WHERE grund IN s_grund[].
ENDSELECT.
IF sy-subrc <> 0.
MESSAGE text-t10 TYPE 'E'.
ENDIF.
ENDIF.
ENDFORM. " VALIDATE_MOVEMENT_REASON
*---------------------------------------------------------------------*
* Form VALIDATE_TRACK_NO *
*---------------------------------------------------------------------*
* This subroutine is used to validate requirement tracking number *
*---------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine *
*---------------------------------------------------------------------*
FORM validate_track_no .
IF NOT s_bednr IS INITIAL.
SELECT bednr UP TO 1 ROWS
INTO w_sel-bednr
FROM ekpo
WHERE bednr IN s_bednr[].
ENDSELECT.
IF sy-subrc <> 0.
MESSAGE text-t11 TYPE 'E'.
ENDIF.
ENDIF.
ENDFORM. " VALIDATE_TRACK_NO
*---------------------------------------------------------------------*
* Form VALIDATE_VENDOR *
*---------------------------------------------------------------------*
* This subroutine is used to validate vendor account no *
*---------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine *
*---------------------------------------------------------------------*
FORM validate_vendor .
IF NOT s_lifnr IS INITIAL.
SELECT SINGLE lifnr
INTO w_sel-lifnr
FROM lfa1
WHERE lifnr IN s_lifnr[].
IF sy-subrc <> 0.
MESSAGE text-t12 TYPE 'E'.
ENDIF.
ENDIF.
ENDFORM. " VALIDATE_VENDOR
*---------------------------------------------------------------------*
* Form GET_DATA *
*---------------------------------------------------------------------*
* This subroutine is used to retrieve data from all necessary tables *
*---------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine *
*---------------------------------------------------------------------*
FORM get_data .
PERFORM get_pdoc_data.
IF t_ekpo IS NOT INITIAL.
PERFORM get_vendor_data.
PERFORM get_schedule_lines.
PERFORM get_pdoc_history_data.
ENDIF.
IF t_ekbe IS NOT INITIAL.
PERFORM get_matdoc_item_data.
ENDIF.
IF t_mseg IS NOT INITIAL.
PERFORM get_reason_desc.
ENDIF.
ENDFORM. " GET_DATA
*---------------------------------------------------------------------*
* Form GET_PDOC_HEADER_DATA *
*---------------------------------------------------------------------*
* This subroutine retrieves necessary purchasing document header *
* data from table EKKO *
*---------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine *
*---------------------------------------------------------------------*
FORM get_pdoc_data .
SELECT ekko~ebeln
ekko~bukrs
ekko~bsart
ekko~loekz
ekko~aedat
ekko~ernam
ekko~lifnr
ekko~ekgrp
ekko~waers
ekpo~ebelp
ekpo~txz01
ekpo~werks
ekpo~bednr
ekpo~matkl
ekpo~menge
ekpo~meins
ekpo~brtwr
ekpo~weunb
ekpo~afnam
INTO TABLE t_ekpo
FROM ekko INNER JOIN ekpo
ON ekko~ebeln EQ ekpo~ebeln
WHERE ekko~ebeln IN s_ebeln
AND ekko~bukrs IN s_bukrs
AND ekko~loekz IN s_loekz
AND ekko~aedat IN s_aedat
AND ekko~lifnr IN s_lifnr
AND ekko~ekgrp IN s_ekgrp
AND ekpo~werks IN s_werks
AND ekpo~bednr IN s_bednr
AND ekpo~matkl IN s_matkl.
IF sy-subrc EQ 0.
SORT t_ekpo BY ebeln ebelp.
ENDIF.
ENDFORM. " GET_PDOC_HEADER_DATA
*---------------------------------------------------------------------*
* Form GET_VENDOR_DATA *
*---------------------------------------------------------------------*
* This subroutine retrieves necessary vendor details from table LFA1 *
*---------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine *
*---------------------------------------------------------------------*
FORM get_vendor_data .
* Read table LFA1 using the values from T_EKPO
APPEND LINES OF t_ekpo TO t_ekpo_temp.
SORT t_ekpo_temp BY lifnr.
DELETE ADJACENT DUPLICATES FROM t_ekpo_temp
COMPARING lifnr.
IF t_ekpo_temp IS NOT INITIAL.
SELECT lifnr
name1
FROM lfa1
INTO TABLE t_lfa1
FOR ALL ENTRIES IN t_ekpo_temp
WHERE lifnr EQ t_ekpo_temp-lifnr.
IF sy-subrc EQ 0.
FREE t_ekpo_temp.
ENDIF.
ENDIF.
ENDFORM. " GET_VENDOR_DATA
*---------------------------------------------------------------------*
* Form GET_SCHEDULE_LINES *
*---------------------------------------------------------------------*
* This subroutine retrieves necessary schedule lines information *
* from table EKET *
*---------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine *
*---------------------------------------------------------------------*
FORM get_schedule_lines .
* Read table EKET using the values from the IT_EKPO + selection screen
SELECT ebeln
ebelp
eindt
FROM eket
INTO TABLE t_eket
FOR ALL ENTRIES IN t_ekpo
WHERE ebeln EQ t_ekpo-ebeln
AND ebelp EQ t_ekpo-ebelp.
IF sy-subrc EQ 0. "#EC NEEDED
*
ENDIF.
ENDFORM. " GET_SCHEDULE_LINES
*---------------------------------------------------------------------*
* Form GET_PDOC_HISTORY_DATA *
*---------------------------------------------------------------------*
* This subroutine retrieves necessary purchasing document history *
* category from table EKBE *
*---------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine *
*---------------------------------------------------------------------*
FORM get_pdoc_history_data .
* Read table EKBE using the values from the IT_EKPO + selection screen
SELECT ebeln
ebelp
gjahr
belnr
buzei
bewtp
bwart
budat
menge
dmbtr
shkzg
FROM ekbe
INTO TABLE t_ekbe
FOR ALL ENTRIES IN t_ekpo
WHERE ebeln EQ t_ekpo-ebeln
AND ebelp EQ t_ekpo-ebelp
AND bewtp IN s_bewtp
AND bwart IN s_bwart
AND grund IN s_grund
AND werks IN s_werks.
IF sy-subrc EQ 0. "#EC NEEDED
*
ENDIF.
ENDFORM. " GET_PDOC_HISTORY_DATA
*---------------------------------------------------------------------*
* Form GET_MATDOC_ITEM_DATA *
*---------------------------------------------------------------------*
* This subroutine retrieves material document segment data from *
* table MSEG *
*---------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine *
*---------------------------------------------------------------------*
FORM get_matdoc_item_data .
* Read table MSEG using the values from the IT_EKBE + selection screen
SELECT mblnr
mjahr
zeile
weunb
bwart
* shkzg
grund
FROM mseg
INTO TABLE t_mseg
FOR ALL ENTRIES IN t_ekbe
WHERE mblnr EQ t_ekbe-belnr
AND mjahr EQ t_ekbe-gjahr
AND zeile EQ t_ekbe-buzei
AND bwart IN s_bwart
AND werks IN s_werks
AND lifnr IN s_lifnr
AND ebeln IN s_ebeln
AND bukrs IN s_bukrs
AND grund IN s_grund.
IF sy-subrc EQ 0.
SORT t_mseg BY mblnr mjahr.
ENDIF.
ENDFORM. " GET_MATDOC_ITEM_DATA
*---------------------------------------------------------------------*
* Form GET_REASON_DESC *
*---------------------------------------------------------------------*
* This subroutine retrieves descriptions for reason for movement *
* from table T157E *
*---------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine *
*---------------------------------------------------------------------*
FORM get_reason_desc .
* Read table T157E using the values from the IT_MSEG + selection screen
APPEND LINES OF t_mseg TO t_mseg_temp.
SORT t_mseg_temp BY bwart
grund.
DELETE ADJACENT DUPLICATES FROM t_mseg_temp
COMPARING bwart
grund.
IF t_mseg_temp IS NOT INITIAL.
SELECT bwart
grund
grtxt
FROM t157e
INTO TABLE t_t157e
FOR ALL ENTRIES IN t_mseg_temp
WHERE spras EQ sy-langu
AND bwart EQ t_mseg_temp-bwart
AND grund EQ t_mseg_temp-grund.
IF sy-subrc EQ 0.
SORT t_t157e.
FREE t_mseg_temp.
ENDIF.
ENDIF.
ENDFORM. " GET_REASON_DESC
*---------------------------------------------------------------------*
* Form POPULATE_FINAL_DATA *
*---------------------------------------------------------------------*
* This subroutine is used for populating final data *
*---------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine. *
*---------------------------------------------------------------------*
FORM populate_final_data.
LOOP AT t_ekpo INTO w_ekpo.
* Populate purchase order data
w_final-ebeln = w_ekpo-ebeln.
w_final-ebelp = w_ekpo-ebelp.
w_final-txz01 = w_ekpo-txz01.
w_final-werks = w_ekpo-werks.
w_final-bednr = w_ekpo-bednr.
w_final-matkl = w_ekpo-matkl.
w_final-poqty = w_ekpo-menge.
w_final-meins = w_ekpo-meins.
w_final-brtwr = w_ekpo-brtwr.
w_final-afnam = w_ekpo-afnam.
w_final-bsart = w_ekpo-bsart.
w_final-lifnr = w_ekpo-lifnr.
w_final-aedat = w_ekpo-aedat.
w_final-ernam = w_ekpo-ernam.
w_final-ekgrp = w_ekpo-ekgrp.
w_final-waers = w_ekpo-waers.
* Populate vendor name
READ TABLE t_lfa1 INTO w_lfa1
WITH KEY lifnr = w_ekpo-lifnr
BINARY SEARCH.
IF sy-subrc EQ 0.
w_final-name1 = w_lfa1-name1.
ENDIF.
* Populate item delivery date
READ TABLE t_eket INTO w_eket
WITH KEY ebeln = w_ekpo-ebeln
ebelp = w_ekpo-ebelp
BINARY SEARCH.
IF sy-subrc EQ 0.
w_final-eindt = w_eket-eindt.
ENDIF.
*----------------------------------------------
* Populate purchase order history category
READ TABLE t_ekbe INTO w_ekbe
WITH KEY ebeln = w_ekpo-ebeln
ebelp = w_ekpo-ebelp
BINARY SEARCH.
IF sy-subrc EQ 0.
LOOP AT t_ekbe INTO w_ekbe FROM sy-tabix.
IF w_ekbe-ebeln EQ w_ekpo-ebeln
AND w_ekbe-ebelp EQ w_ekpo-ebelp.
w_final-budat = w_ekbe-budat.
w_final-belnr = w_ekbe-belnr.
w_final-dmbtr = w_ekbe-dmbtr.
w_final-bwart = w_ekbe-bwart.
w_final-bewtp = w_ekbe-bewtp.
w_final-grqty = w_ekbe-menge.
w_final-shkzg = w_ekbe-shkzg.
* Populate material document data
READ TABLE t_mseg INTO w_mseg
WITH KEY mblnr = w_ekbe-belnr
mjahr = w_ekbe-gjahr
zeile = w_ekbe-buzei
BINARY SEARCH.
IF sy-subrc EQ 0.
w_final-grund = w_mseg-grund.
w_final-weunb = w_mseg-weunb.
* w_final-shkzg = w_mseg-shkzg.
* Populate Reason descriptions
CLEAR w_t157e.
READ TABLE t_t157e INTO w_t157e
WITH KEY bwart = w_mseg-bwart
grund = w_mseg-grund
BINARY SEARCH.
IF sy-subrc EQ 0.
w_final-grtxt = w_t157e-grtxt.
ENDIF.
ENDIF.
APPEND w_final TO t_final.
CLEAR:
w_final-grund,
w_final-weunb,
* w_final-shkzg,
w_final-grtxt,
w_t157e,
w_mseg,
w_ekbe.
ELSE.
EXIT.
ENDIF.
ENDLOOP.
ELSE.
APPEND w_final TO t_final.
ENDIF.
CLEAR :
w_ekbe,
w_eket,
w_lfa1,
w_ekpo,
w_final.
ENDLOOP.
FREE:
t_ekpo,
t_eket,
t_ekbe,
t_mseg,
t_lfa1,
t_t157e.
*------------------------------------------------------------
* LOOP AT t_ekpo INTO w_ekpo.
** Populate purchase order data
* w_final-ebeln = w_ekpo-ebeln.
* w_final-ebelp = w_ekpo-ebelp.
* w_final-txz01 = w_ekpo-txz01.
* w_final-werks = w_ekpo-werks.
* w_final-bednr = w_ekpo-bednr.
* w_final-matkl = w_ekpo-matkl.
* w_final-poqty = w_ekpo-menge.
* w_final-meins = w_ekpo-meins.
* w_final-brtwr = w_ekpo-brtwr.
* w_final-afnam = w_ekpo-afnam.
* w_final-bsart = w_ekpo-bsart.
* w_final-lifnr = w_ekpo-lifnr.
* w_final-aedat = w_ekpo-aedat.
* w_final-ernam = w_ekpo-ernam.
* w_final-ekgrp = w_ekpo-ekgrp.
* w_final-waers = w_ekpo-waers.
** Populate vendor name
* CLEAR w_lfa1.
* READ TABLE t_lfa1 INTO w_lfa1
* WITH KEY lifnr = w_ekpo-lifnr
* BINARY SEARCH.
* IF sy-subrc EQ 0.
* w_final-name1 = w_lfa1-name1.
* ENDIF.
** Populate item delivery date
* CLEAR w_eket.
* READ TABLE t_eket INTO w_eket
* WITH KEY ebeln = w_ekpo-ebeln
* ebelp = w_ekpo-ebelp
* BINARY SEARCH.
* IF sy-subrc EQ 0.
* w_final-eindt = w_eket-eindt.
* ENDIF.
** Populate purchase order history category
* clear w_ekbe.
* READ TABLE t_ekbe INTO w_ekbe
* WITH KEY ebeln = w_ekpo-ebeln
* ebelp = w_ekpo-ebelp
* BINARY SEARCH.
* IF sy-subrc EQ 0.
* LOOP AT t_ekbe INTO w_ekbe FROM sy-tabix.
*
* IF w_ekbe-ebeln EQ w_ekpo-ebeln
* AND w_ekbe-ebelp EQ w_ekpo-ebelp.
*
* w_final-budat = w_ekbe-budat.
* w_final-belnr = w_ekbe-belnr.
* w_final-dmbtr = w_ekbe-dmbtr.
* w_final-bwart = w_ekbe-bwart.
* w_final-bewtp = w_ekbe-bewtp.
* w_final-grqty = w_ekbe-menge.
*
** Populate material document data
* clear w_mseg.
* READ TABLE t_mseg INTO w_mseg
* WITH KEY mblnr = w_ekbe-belnr
* mjahr = w_ekbe-gjahr
* zeile = w_ekbe-buzei
* BINARY SEARCH.
* IF sy-subrc EQ 0.
* w_final-grund = w_mseg-grund.
* w_final-weunb = w_mseg-weunb.
* w_final-shkzg = w_mseg-shkzg.
** Populate Reason descriptions
* clear w_t157e.
* READ TABLE t_t157e INTO w_t157e
* WITH KEY bwart = w_mseg-bwart
* grund = w_mseg-grund
* BINARY SEARCH.
* IF sy-subrc EQ 0.
* w_final-grtxt = w_t157e-grtxt.
* ENDIF.
* ELSE.
* CLEAR:
* w_final-grund,
* w_final-weunb,
* w_final-shkzg,
* w_final-grtxt.
* ENDIF.
* APPEND w_final TO t_final.
* CLEAR:
* w_t157e,
* w_mseg,
* w_ekbe.
* ELSE.
* EXIT.
* ENDIF.
* ENDLOOP.
* ELSE.
* APPEND w_final TO t_final.
* CLEAR :
* w_ekbe,
* w_eket,
* w_lfa1,
* w_ekpo,
* w_final.
* ENDIF.
* ENDLOOP.
* FREE:
* t_ekpo,
* t_eket,
* t_ekbe,
* t_mseg,
* t_lfa1,
* t_t157e.
ENDFORM. " POPULATE FINAL_DATA
*---------------------------------------------------------------------*
* Form DISPLAY_ALV *
*---------------------------------------------------------------------*
* This subroutine is used for displaying ALV *
*---------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine. *
*---------------------------------------------------------------------*
FORM display_alv .
* Local Data Declaration
DATA:
lw_err_msg TYPE REF TO cx_salv_msg,
lw_key TYPE salv_s_layout_key.
TRY.
* 1. Instantiate the ALV Global Class
* -----------------------------------------
cl_salv_table=>factory(
IMPORTING
r_salv_table = obj_alv_table
CHANGING
t_table = t_final_dis ).
* 2. This Function is for the Tool Bar
* -----------------------------------------
* Get Object Reference to the Tool Bar Functions
CALL METHOD obj_alv_table->get_functions
RECEIVING
value = obj_functions.
* Activate all ALV Tool Bar Functions
CALL METHOD obj_functions->set_all
EXPORTING
value = if_salv_c_bool_sap=>true.
* Set the Key fields for the Report Display
* Get the Object Reference for Column
CALL METHOD obj_alv_table->get_columns
RECEIVING
value = obj_columns.
* 3. This is for the ALV Layout Functions
* -----------------------------------------
* Get the Object Reference for the ALV Layout
CALL METHOD obj_alv_table->get_layout
RECEIVING
value = obj_layout.
* Set the Key
lw_key-report = sy-repid.
obj_layout->set_key( lw_key ).
* Set the Save Layout Option
obj_layout->set_save_restriction(
if_salv_c_layout=>restrict_none ).
* Activate Option of Saving Default Setting
obj_layout->set_default( abap_true ).
* If there is a Selection Screen Entry for Layout then Set The Layout
IF NOT p_layout IS INITIAL.
obj_layout->set_initial_layout( p_layout ).
ENDIF.
* 4. Update Column Related Data
* -----------------------------------------
TRY.
* Purchasing Document Number - Set Column Text
obj_column ?= obj_columns->get_column( columnname = 'EBELN' ).
obj_column->set_long_text('Purchasing Document Number' ).
obj_column->set_medium_text('PO Number' ).
obj_column->set_short_text('PO Number' ).
obj_column->set_output_length( 25 ).
* Puchase Order Type - Set Column Text
obj_column ?= obj_columns->get_column( columnname = 'BSART' ).
obj_column->set_long_text('Purchasing Document Type' ).
obj_column->set_medium_text('PO Type' ).
obj_column->set_short_text('PO Type' ).
obj_column->set_output_length( 21 ).
* PO Created Date - Set Column Text
obj_column ?= obj_columns->get_column( columnname = 'AEDAT' ).
obj_column->set_long_text('Date on which the record was created' ).
obj_column->set_medium_text('PO Created Date' ).
obj_column->set_short_text('Created on' ).
obj_column->set_output_length( 30 ).
* PO Created By - Set Column Text
obj_column ?= obj_columns->get_column( columnname = 'ERNAM' ).
obj_column->set_long_text('Name of Person who Created the Object' ).
obj_column->set_medium_text('PO Created By' ).
obj_column->set_short_text('Created By' ).
obj_column->set_output_length( 32 ).
* Vendor's account number - Set Column Text
obj_column ?= obj_columns->get_column( columnname = 'LIFNR' ).
obj_column->set_long_text('Vendors account number' ).
obj_column->set_medium_text('Vendor No' ).
obj_column->set_short_text('Vendor No' ).
obj_column->set_output_length( 20 ).
* Vendor Name - Set Column Text
obj_column ?= obj_columns->get_column( columnname = 'NAME1' ).
obj_column->set_long_text('Name 1' ).
obj_column->set_medium_text('Name 1' ).
obj_column->set_short_text('Name 1' ).
obj_column->set_output_length( 10 ).
* Purchasing group - Set Column Text
obj_column ?= obj_columns->get_column( columnname = 'EKGRP' ).
obj_column->set_long_text('Purchasing Group' ).
obj_column->set_medium_text('Purchasing Group' ).
obj_column->set_short_text('Pur. Group' ).
obj_column->set_output_length( 15 ).
* PO Item Number - Set Column Text
obj_column ?= obj_columns->get_column( columnname = 'EBELP' ).
obj_column->set_long_text('Item Number of Purchasing Document' ).
obj_column->set_medium_text('PO Item No' ).
obj_column->set_short_text('PO Item' ).
obj_column->set_output_length( 35 ).
* Short text - Set Column Text
obj_column ?= obj_columns->get_column( columnname = 'TXZ01' ).
obj_column->set_long_text('Short Text' ).
obj_column->set_medium_text('Short Text' ).
obj_column->set_short_text('Short Text' ).
obj_column->set_output_length( 10 ).
* Material group - Set Column Text
obj_column ?= obj_columns->get_column( columnname = 'MATKL' ).
obj_column->set_long_text('Material Group' ).
obj_column->set_medium_text('Material Group' ).
obj_column->set_short_text('Mat. Group' ).
obj_column->set_output_length( 14 ).
* Req. Tracking Number - Set Column Text
obj_column ?= obj_columns->get_column( columnname = 'BEDNR' ).
obj_column->set_long_text('Requirement Tracking Number' ).
obj_column->set_medium_text('Req. Tracking Number' ).
obj_column->set_short_text('Req. Tr No' ).
obj_column->set_output_length( 25 ).
* Purchase order quantity - Set Column Text
obj_column ?= obj_columns->get_column( columnname = 'POQTY' ).
obj_column->set_long_text('Purchase order quantity' ).
obj_column->set_medium_text('PO Quantity' ).
obj_column->set_short_text('PO Qty' ).
obj_column->set_output_length( 19 ).
* Order unit - Set Column Text
obj_column ?= obj_columns->get_column( columnname = 'UNIT1' ).
obj_column->set_long_text('Order Unit' ).
obj_column->set_medium_text('Order Unit' ).
obj_column->set_short_text('Order Unit' ).
obj_column->set_output_length( 10 ).
* Gross order value in PO currency - Set Column Text
obj_column ?= obj_columns->get_column( columnname = 'BRTWR' ).
obj_column->set_long_text('Gross order value in PO currency' ).
obj_column->set_medium_text('Gross value' ).
obj_column->set_short_text('Gross val.' ).
obj_column->set_output_length( 35 ).
* Currency Key - Set Column Text
obj_column ?= obj_columns->get_column( columnname = 'CUKY1' ).
obj_column->set_long_text('Currency Key' ).
obj_column->set_medium_text('Currency Key' ).
obj_column->set_short_text('Curr. Key' ).
obj_column->set_output_length( 13 ).
* Order unit - Set Column Text
obj_column ?= obj_columns->get_column( columnname = 'UNIT2' ).
obj_column->set_long_text('Order Unit' ).
obj_column->set_medium_text('Order Unit' ).
obj_column->set_short_text('Order Unit' ).
obj_column->set_output_length( 10 ).
* Name of requisitioner - Set Column Text
obj_column ?= obj_columns->get_column( columnname = 'AFNAM' ).
obj_column->set_long_text('Name of Requisitioner' ).
obj_column->set_medium_text('Requisitioner' ).
obj_column->set_short_text('Req. Name' ).
obj_column->set_output_length( 20 ).
* PO history category - Set Column Text
obj_column ?= obj_columns->get_column( columnname = 'BEWTP' ).
obj_column->set_long_text('PO History Category' ).
obj_column->set_medium_text('PO history category' ).
obj_column->set_short_text('Hist. Cat.' ).
obj_column->set_output_length( 20 ).
* Item delivery date - Set Column Text
obj_column ?= obj_columns->get_column( columnname = 'EINDT' ).
obj_column->set_long_text('Item Delivery Date' ).
obj_column->set_medium_text('Delivery Date' ).
obj_column->set_short_text('Del. Date' ).
obj_column->set_output_length( 17 ).
* GRN Date - Set Column Text
obj_column ?= obj_columns->get_column( columnname = 'BUDAT' ).
obj_column->set_long_text('Posting Date in the Document' ).
obj_column->set_medium_text('GRN Date' ).
obj_column->set_short_text('GRN Date' ).
obj_column->set_output_length( 25 ).
* GR Quantity - Set Column Text
obj_column ?= obj_columns->get_column( columnname = 'GRQTY' ).
obj_column->set_long_text('Quantity' ).
obj_column->set_medium_text('Quantity' ).
obj_column->set_short_text('GR Qty' ).
obj_column->set_output_length( 10 ).
* Order unit - Set Column Text
obj_column ?= obj_columns->get_column( columnname = 'UNIT3').
obj_column->set_long_text('Order Unit' ).
obj_column->set_medium_text('Order Unit' ).
obj_column->set_short_text('Order Unit' ).
obj_column->set_output_length( 10 ).
* Goods Receipt, Non-Valuated - Set Column Text
obj_column ?= obj_columns->get_column( columnname = 'WEUNB' ).
obj_column->set_long_text('Goods Receipt, Non-Valuated' ).
obj_column->set_medium_text('GR, Non-Valuated' ).
obj_column->set_short_text('GR,Non-Val' ).
obj_column->set_output_length( 25 ).
** Debit/Credit Indicator - Set Column Text
* obj_column ?= obj_columns->get_column( columnname = 'SHKZG'
*).
* obj_column->set_long_text('Debit/Credit Ind.' ).
* obj_column->set_medium_text('Debit/Credit Ind.' ).
* obj_column->set_short_text('D/C Indic.' ).
* obj_column->set_output_length( 10 ).
* Amount in local currency - Set Column Text
obj_column ?= obj_columns->get_column( columnname = 'DMBTR' ).
obj_column->set_long_text('Amount in Local Currency' ).
obj_column->set_medium_text('Amt in Local Curr.' ).
obj_column->set_short_text('Amt in LC' ).
obj_column->set_output_length( 22 ).
* Currency Key - Set Column Text
obj_column ?= obj_columns->get_column( columnname = 'CUKY2' ).
obj_column->set_long_text('Currency Key' ).
obj_column->set_medium_text('Currency Key' ).
obj_column->set_short_text('Curr. Key' ).
obj_column->set_output_length( 13 ).
* Debit/Credit Indicator - Set Column Text
obj_column ?= obj_columns->get_column( columnname = 'SHKZG' ).
obj_column->set_long_text('Debit or Credit' ).
obj_column->set_medium_text('Debit or Credit' ).
obj_column->set_short_text('D/C Indic.' ).
obj_column->set_output_length( 17 ).
* Movement Type - Set Column Text
obj_column ?= obj_columns->get_column( columnname = 'BWART' ).
obj_column->set_long_text('Movement Type' ).
obj_column->set_medium_text('Movement Type' ).
obj_column->set_short_text('Mov. Type' ).
obj_column->set_output_length( 13 ).
* Reason for movement - Set Column Text
obj_column ?= obj_columns->get_column( columnname = 'GRUND' ).
obj_column->set_long_text('Reason code' ).
obj_column->set_medium_text('Reason code' ).
obj_column->set_short_text('Reason' ).
obj_column->set_output_length( 11 ).
* Reason for goods movement description - Set Column Text
obj_column ?= obj_columns->get_column( columnname = 'GRTXT' ).
obj_column->set_long_text('Reason Descriptions' ).
obj_column->set_medium_text('Reason Descriptions' ).
obj_column->set_short_text('RDesc' ).
obj_column->set_output_length( 19 ).
CATCH cx_salv_not_found. "#EC NO_HANDLER
* Do Nothing
ENDTRY.
* 5. Modify Display Settings
* -----------------------------------------
CALL METHOD obj_alv_table->get_display_settings
RECEIVING
value = obj_display.
obj_display->set_striped_pattern( abap_true ).
* 6. Display the ALV Data
* -----------------------------------------
IF obj_alv_table IS BOUND.
obj_alv_table->display( ).
ENDIF.
* Exceptions
* -----------------------------------------
CATCH cx_salv_msg INTO lw_err_msg.
ENDTRY.
ENDFORM. " DISPLAY_ALV
*---------------------------------------------------------------------*
* Form SUB_F4_LAYOUT *
*---------------------------------------------------------------------*
* This subroutine is for providing f4 help for layout *
*---------------------------------------------------------------------*
* -->P_IF_SALV_C_LAYOUT=>RESTRICT_NON text *
* <--P_P_LAYOUT text *
*---------------------------------------------------------------------*
FORM sub_f4_layout USING im_restrict TYPE salv_de_layout_restriction
CHANGING ch_layout TYPE disvariant-variant.
DATA: lw_layout TYPE salv_s_layout_info,
lw_key TYPE salv_s_layout_key.
lw_key-report = sy-repid.
lw_layout = cl_salv_layout_service=>f4_layouts(
s_key = lw_key
restrict = im_restrict ).
ch_layout = lw_layout-layout.
ENDFORM. " SUB_F4_LAYOUT
*---------------------------------------------------------------------*
* Form POPULATE_DISPLAY_DATA *
*---------------------------------------------------------------------*
* This subroutine populates T_FINAL_DIS based on T_FINAL *
*---------------------------------------------------------------------*
FORM populate_display_data .
LOOP AT t_final INTO w_final.
w_final_dis-ebeln = w_final-ebeln.
w_final_dis-bsart = w_final-bsart.
w_final_dis-aedat = w_final-aedat.
w_final_dis-ernam = w_final-ernam.
w_final_dis-lifnr = w_final-lifnr.
w_final_dis-name1 = w_final-name1.
w_final_dis-ekgrp = w_final-ekgrp.
w_final_dis-ebelp = w_final-ebelp.
w_final_dis-txz01 = w_final-txz01.
w_final_dis-matkl = w_final-matkl.
w_final_dis-bednr = w_final-bednr.
w_final_dis-poqty = w_final-poqty.
w_final_dis-unit1 = w_final-meins.
w_final_dis-brtwr = w_final-brtwr.
w_final_dis-cuky1 = w_final-waers.
w_final_dis-unit2 = w_final-meins.
w_final_dis-afnam = w_final-afnam.
w_final_dis-bewtp = w_final-bewtp.
w_final_dis-eindt = w_final-eindt.
w_final_dis-budat = w_final-budat.
w_final_dis-grqty = w_final-grqty.
w_final_dis-unit3 = w_final-meins.
w_final_dis-weunb = w_final-weunb.
w_final_dis-dmbtr = w_final-dmbtr.
w_final_dis-shkzg = w_final-shkzg.
w_final_dis-cuky2 = w_final-waers.
w_final_dis-bwart = w_final-bwart.
w_final_dis-grund = w_final-grund.
w_final_dis-grtxt = w_final-grtxt.
APPEND w_final_dis TO t_final_dis.
CLEAR w_final_dis.
ENDLOOP.
REFRESH t_final.
ENDFORM. " POPULATE_DISPLAY_DATA
No comments:
Post a Comment