Вы находитесь на странице: 1из 24

ALV report

*&---------------------------------------------------------------------*
*& Report ZEM02R0004
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zem02r0004 MESSAGE-ID zem0201.
***********************************************************************
* Program Name
: ZEM02R0004
Date
: 16.06.2011 *
* SAP Name
:
Version
:
*
* Programmer
: Smitha Srinivas
Last Update:
*
* Analyst/Specifier:
*
* Program Type
: Report program
*
* Impact request :
*
* Transaction Code : ZEM0204
*----------------------------------------------------------------------*
* Description
: This program is a costing exception report.
*
*
: - It reports on inconsistency in standard cost
*
*
: existing between plants
*
*
: - Standard cost is 0.00, indicating costing has *
*
: not been performed therefore, incomplete
*
*
: - Standard cost is 0.01, indicating costing is
*
*
: incomplete
*
*
: - Valuation class is not as expected
*
*----------------------------------------------------------------------*
*
*
* Authority
: Authorization chec is performed on company code *
*
*
*----------------------------------------------------------------------*
*
*report zmr00015 message-id zm.
*----------------------------------------------------------------------*
* Tables
*
*----------------------------------------------------------------------*
TABLES: t001,
mara,
mbew,
marc.
*----------------------------------------------------------------------*
* Types and Type Pools
*
*----------------------------------------------------------------------*
TYPE-POOLS: slis,
sscr.
*----------------------------------------------------------------------*
* ALV related variables
*
*----------------------------------------------------------------------*
DATA: gdf_repid
LIKE sy-repid.
DATA: gds_layout
TYPE slis_layout_alv.
DATA: gds_variant
TYPE disvariant.
DATA: gds_listheader TYPE slis_listheader.
DATA: gdt_fieldcat
TYPE slis_t_fieldcat_alv."it_fieldcat
DATA: gdt_listheader TYPE slis_t_listheader."it_listheader
*----------------------------------------------------------------------*
* Data Types
*
*----------------------------------------------------------------------*
TYPES: BEGIN OF gts_matpr,
matnr TYPE matnr,
" Material
lvorm TYPE lvoma,
" Flag for deletion
"MOD001

mtart TYPE mtart,


" Material type
"MOD001
meins TYPE meins,
" Unit of measure
spart TYPE spart,
" Division
prdha TYPE prodh_d,
" Product hierarchy
bw ey TYPE bw ey,
" Valuation area
stprs TYPE stprs,
" Stabdard price
peinh TYPE peinh,
" Price unit
b las TYPE b las,
" Valuation class
laepr TYPE laepr,
" Last price change
lb um TYPE lb um,
" Total valuated stoc
hr ft TYPE hr ft,
" Origin group
e alr TYPE c _e alrel,
" Costed with qty structure
h mat TYPE h mat,
" Material origin
END OF gts_matpr.
*----------------------------------------------------------------------*
* Internal Tables
*
*----------------------------------------------------------------------*
DATA: BEGIN OF gdt_org OCCURS 0,"it_org
bu rs TYPE bu rs,
bw ey TYPE bw ey,
END OF gdt_org.
DATA: gdt_mat_all
TYPE STANDARD TABLE OF gts_matpr WITH HEADER LINE.
"ldt_mat_all
DATA: gdt_primary
TYPE STANDARD TABLE OF gts_matpr WITH HEADER LINE.
"it_primary
DATA: BEGIN OF gdt_rept OCCURS 0,
bu rs TYPE bu rs,
" Company code
lvorm TYPE lvoma,
" Deletion indicator
"MOD001
bw ey TYPE bw ey,
" Valuation Area
mmsta TYPE mmsta,
" Plant Status
"MOD001
spart TYPE spart,
" Division
frnch TYPE spart,
" Franchise
matnr TYPE matnr,
" Material
ma tx TYPE ma tx,
" Description
b las TYPE b las,
" Valuation class
stprs TYPE string,"stprs, " Standard price----changed as type string,
702063061
peinh TYPE peinh,
" Price unit
meins TYPE meins,
" Base UoM
primp TYPE wer s_d,
" Primary plant
primc TYPE stprs,
" Primary plant std price
prmpu TYPE peinh,
" Primary plant price unit
prmbu TYPE meins,
" Primary plant base UoM
*
laepr TYPE laepr,
" Last price change
*
lb um TYPE lb um,
" Total valuated stoc
*
hr ft TYPE hr ft,
" Origin group
*
e alr TYPE c _e alrel,
" Costed with qty structure
*
h mat TYPE h mat,
" Material origin
extyp(14) TYPE c,
" Incomp/incons/val class excep type
END OF gdt_rept.
DATA: BEGIN OF gdt_divsn OCCURS 0,
spart TYPE spart,
END OF gdt_divsn.
DATA: BEGIN OF gdt_matdesc OCCURS 0,
matnr TYPE matnr,
ma tx TYPE ma tx,
END OF gdt_matdesc.
*----------------------------------------------------------------------*
* Wor ing Storage
*
*----------------------------------------------------------------------*

DATA: gdf_subrc
LIKE sy-subrc.
DATA: gdf_excep_icm(1) TYPE c.
DATA: gdf_excep_icn(1) TYPE c.
DATA: gdf_excep_vcl(1) TYPE c.
DATA: gdf_cocde_au(1) TYPE c.
DATA: gdf_cocde_nz(1) TYPE c.
*----------------------------------------------------------------------*
* Constants
*
*----------------------------------------------------------------------*
CONSTANTS: gcf_alv_top TYPE slis_formname VALUE 'DISPLAY_ALV_TOP'.
CONSTANTS: gcf_alv_pfs TYPE slis_formname VALUE 'SET_ALV_PFSTATUS'.
CONSTANTS: gcf_alv_cmd TYPE slis_formname VALUE
'ALV_USER_COMMAND_DISPLAY_MAT'.
CONSTANTS: gcf_space
TYPE c
VALUE ' '.
CONSTANTS: gcf_a
TYPE c
VALUE 'A'.
CONSTANTS: gcf_x
TYPE c
VALUE 'X'.
CONSTANTS: gcf_h
TYPE c
VALUE 'H'.
CONSTANTS: gcf_s
TYPE c
VALUE 'S'.
CONSTANTS: gcf_prmplnt40 TYPE wer s_d VALUE '0040'.
CONSTANTS: gcf_prmplnt70 TYPE wer s_d VALUE '0070'.
CONSTANTS: gcf_prmplnt85 TYPE wer s_d VALUE '0085'.
CONSTANTS: gcf_prmplnt71 TYPE wer s_d VALUE '0071'.
CONSTANTS: gcf_jjmau
TYPE bu rs VALUE '7515'.
CONSTANTS: gcf_jjmnz
TYPE bu rs VALUE '8360'.
CONSTANTS: gcf_incomplt(6) TYPE c
VALUE 'INCOMP' ." 'Incomp'.
CONSTANTS: gcf_inconsis(6) TYPE c
VALUE 'INCONS'. " Incons'.
CONSTANTS: gcf_valclass(6) TYPE c
VALUE 'VALCLS'. " Valcls'.
CONSTANTS: gcf_iau_mat(3) TYPE c
VALUE 'IAU'.
CONSTANTS: gcf_vcls3100
TYPE b las VALUE '3100'.
CONSTANTS: gcf_vcls3150
TYPE b las VALUE '3150'.
CONSTANTS: gcf_vcls3300
TYPE b las VALUE '3300'.
CONSTANTS: gcf_vcls7920
TYPE b las VALUE '7920'.
"MOD001
CONSTANTS: gcf_vcls7910
TYPE b las VALUE '7910'.
"MOD001
CONSTANTS: gcf_vcls7900
TYPE b las VALUE '7900'.
"MOD002
CONSTANTS: gcf_vcls3050
TYPE b las VALUE '3050'.
"MOD001
CONSTANTS: gcf_vcls3000
TYPE b las VALUE '3000'.
"MOD001
CONSTANTS: gcf_fert
TYPE mtart VALUE 'FERT'.
"MOD001
CONSTANTS: gcf_halb
TYPE mtart VALUE 'HALB'.
"MOD001
CONSTANTS: gcf_verp
TYPE mtart VALUE 'VERP'.
"MOD001
CONSTANTS: gcf_roh
TYPE mtart VALUE 'ROH'.
"MOD001
*----------------------------------------------------------------------*
* Field Symbols
*
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
* Ranges
*
*----------------------------------------------------------------------*
RANGES: gr_franchise
FOR mara-prdha.
RANGES: gr_mat_type
FOR mara-mtart.
RANGES: gr_plant_all
FOR mbew-bw ey.
RANGES: gr_prmry_plnt
FOR mbew-bw ey.
RANGES: gr_division
FOR mara-spart.
RANGES: gr_vcdiv_depuy FOR mara-spart.
RANGES: gr_vcdiv_nondpy FOR mara-spart.
RANGES: gr_vcplnt_depuy FOR mbew-bw ey.
RANGES: gr_vcplnt_nondpy FOR mbew-bw ey.
RANGES: gr_lvorm
FOR mara-lvorm.
*----------------------------------------------------------------------*
* Selection Screen
*
*----------------------------------------------------------------------*

* Selection Criteria
SELECTION-SCREEN BEGIN OF BLOCK bl 1 WITH FRAME TITLE text-001.
SELECT-OPTIONS: s_bu rs FOR t001-bu rs OBLIGATORY.
SELECT-OPTIONS: s_spart FOR mara-spart.
SELECT-OPTIONS: s_bw ey FOR mbew-bw ey.
SELECT-OPTIONS: s_matnr FOR mara-matnr.
SELECT-OPTIONS: s_b las FOR mbew-b las.
SELECT-OPTIONS: s_mmsta FOR marc-mmsta.
"MOD004
SELECTION-SCREEN END OF BLOCK bl 1.
* Report Options
SELECTION-SCREEN BEGIN OF BLOCK bl 2 WITH FRAME TITLE text-002.
PARAMETERS: p_incon AS CHECKBOX DEFAULT 'X'.
PARAMETERS: p_vlcls AS CHECKBOX DEFAULT 'X'.
SELECTION-SCREEN BEGIN OF BLOCK bl 3 WITH FRAME TITLE text-105 .
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS: p_incom AS CHECKBOX DEFAULT 'X'.
SELECTION-SCREEN COMMENT 3(20) text-004 FOR FIELD p_incom .
PARAMETERS: p_zerop AS CHECKBOX USER-COMMAND sel.
SELECTION-SCREEN COMMENT 26(28) text-005 FOR FIELD p_zerop.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK bl 3.
PARAMETERS: p_lvorm AS CHECKBOX.
SELECTION-SCREEN END OF BLOCK bl 2.
* ALV Variant
SELECTION-SCREEN BEGIN OF BLOCK bl 4 WITH FRAME TITLE text-003.
PARAMETERS: p_varian LIKE disvariant-variant.
SELECTION-SCREEN END OF BLOCK bl 4.
*----------------------------------------------------------------------*
* Initialization
*
*----------------------------------------------------------------------*
INITIALIZATION.
*----------------------------------------------------------------------* At Selection Screen
*----------------------------------------------------------------------AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_varian.
gds_variant-report = sy-repid.
CALL FUNCTION 'REUSE_ALV_VARIANT_F4'
EXPORTING
is_variant
= gds_variant
i_save
= gcf_x
i_display_via_grid = gcf_x
IMPORTING
es_variant
= gds_variant
EXCEPTIONS
not_found
= 1
program_error
= 2
OTHERS
= 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
p_varian = gds_variant-variant.
ENDIF.
AT SELECTION-SCREEN ON s_bu rs.
PERFORM authority_chec .
AT SELECTION-SCREEN OUTPUT.
IF p_zerop = gcf_x.
p_incom = gcf_x.
LOOP AT SCREEN.

IF screen-name = 'P_INCOM'.
screen-input = 0.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
ENDIF.
AT SELECTION-SCREEN.
IF p_incom IS INITIAL AND
p_incon IS INITIAL AND
p_vlcls IS INITIAL AND
p_zerop IS INITIAL.
SET CURSOR FIELD 'P_INCON'.
MESSAGE e000(zem0201) WITH text-006 text-002.
ENDIF.
*----------------------------------------------------------------------*
* Start of Selection
*
*----------------------------------------------------------------------*
START-OF-SELECTION.
PERFORM build_ranges.
PERFORM show_progress_indicator USING text-i01.
PERFORM start_data_selection.
IF gdt_mat_all[] IS INITIAL.
MESSAGE s000(zem0201) WITH text-i03.
EXIT.
ENDIF.
PERFORM show_progress_indicator USING text-i02.
PERFORM process_report_data.
IF gdt_rept[] IS INITIAL.
MESSAGE s000(zem0201) WITH text-i04.
EXIT.
ENDIF.
PERFORM display_alv_report.
END-OF-SELECTION.
*----------------------------------------------------------------------*
* End of Selection
*
*---------------------------------------------------------------------*&---------------------------------------------------------------------*
*&
Form show_progress_indicator
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
FORM show_progress_indicator USING ldf_text.
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
text = ldf_text.
ENDFORM.
" show_progress_indicator
*&---------------------------------------------------------------------*
*&
Form build_ranges
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
FORM build_ranges.
*-- r_lvorm
* build range to exclude deleted material
IF p_lvorm IS INITIAL.
* exclude deleted materials
CLEAR gr_lvorm.
gr_lvorm-sign = 'E'.
gr_lvorm-option = 'EQ'.
gr_lvorm-low
= gcf_x.

APPEND gr_lvorm.
ELSE.
REFRESH gr_lvorm.
ENDIF.
* select all divisions from table tspa.
SELECT spart INTO TABLE gdt_divsn
FROM tspa.
*-- r_division
* build range for divisions
IF s_spart[] IS INITIAL.
PERFORM build_division_range USING gcf_space.
ELSE.
APPEND LINES OF s_spart TO gr_division.
ENDIF.
*-- r_franchise
* Build range for franchises to include/exclude
* select prdha into r_franchise-low
*
from zmmm04.
*
r_franchise-sign = 'I'.
*
r_franchise-option = 'EQ'.
*
append r_franchise.
*
clear r_franchise.
* endselect.
CLEAR gr_franchise.
gr_franchise-sign = 'I'.
gr_franchise-option = 'EQ'.
gr_franchise-low
= 'DA'.
APPEND gr_franchise.
CLEAR gr_franchise.
gr_franchise-sign = 'I'.
gr_franchise-option = 'EQ'.
gr_franchise-low
= 'DC'.
APPEND gr_franchise.
CLEAR gr_franchise.
gr_franchise-sign = 'I'.
gr_franchise-option = 'EQ'.
gr_franchise-low
= 'DJ'.
APPEND gr_franchise.
CLEAR gr_franchise.
gr_franchise-sign = 'I'.
gr_franchise-option = 'EQ'.
gr_franchise-low
= 'DK'.
APPEND gr_franchise.
CLEAR gr_franchise.
gr_franchise-sign = 'I'.
gr_franchise-option = 'EQ'.
gr_franchise-low
= 'DS'.
APPEND gr_franchise.
CLEAR gr_franchise.
gr_franchise-sign = 'I'.
gr_franchise-option = 'EQ'.
gr_franchise-low
= 'DT'.
APPEND gr_franchise.
CLEAR gr_franchise.
gr_franchise-sign = 'I'.
gr_franchise-option = 'EQ'.
gr_franchise-low
= 'MH'.
APPEND gr_franchise.
CLEAR gr_franchise.
gr_franchise-sign = 'I'.

gr_franchise-option = 'EQ'.
gr_franchise-low
= 'MF'.
APPEND gr_franchise.
CLEAR gr_franchise.
gr_franchise-sign = 'I'.
gr_franchise-option = 'EQ'.
gr_franchise-low
= 'MG'.
APPEND gr_franchise.
CLEAR gr_franchise.
gr_franchise-sign = 'I'.
gr_franchise-option = 'EQ'.
gr_franchise-low
= 'ML'.
APPEND gr_franchise.
CLEAR gr_franchise.
gr_franchise-sign = 'I'.
gr_franchise-option = 'EQ'.
gr_franchise-low
= 'MD'.
APPEND gr_franchise.
CLEAR gr_franchise.
gr_franchise-sign = 'I'.
gr_franchise-option = 'EQ'.
gr_franchise-low
= 'MA'.
APPEND gr_franchise.
CLEAR gr_franchise.
gr_franchise-sign = 'I'.
gr_franchise-option = 'EQ'.
gr_franchise-low
= 'MB'.
APPEND gr_franchise.
CLEAR gr_franchise.
gr_franchise-sign = 'I'.
gr_franchise-option = 'EQ'.
gr_franchise-low
= 'MP'.
APPEND gr_franchise.
* Exclude OCD material i.e. Franchise = M1
CLEAR gr_franchise.
gr_franchise-sign = 'E'.
gr_franchise-option = 'EQ'.
gr_franchise-low
= 'M1'.
APPEND gr_franchise.
*-- r_mat_type
* Build range for material types to exclude
CLEAR gr_mat_type.
gr_mat_type-sign = 'E'.
gr_mat_type-option = 'EQ'.
gr_mat_type-low
= 'ZFRT'.
APPEND gr_mat_type.
CLEAR gr_mat_type.
gr_mat_type-sign = 'E'.
gr_mat_type-option = 'EQ'.
gr_mat_type-low
= 'ZCT'.
APPEND gr_mat_type.
CLEAR gr_mat_type.
gr_mat_type-sign = 'E'.
gr_mat_type-option = 'EQ'.
gr_mat_type-low
= 'DIEN'.
APPEND gr_mat_type.
CLEAR gr_mat_type.
gr_mat_type-sign = 'E'.
gr_mat_type-option = 'EQ'.
gr_mat_type-low
= 'UNBW'.

APPEND gr_mat_type.
*-- r_prmry_plnt
* build range for primary plants
* load JJM AU primary plants
PERFORM chec _company_code_entered.
IF gdf_cocde_au = gcf_x.
CLEAR gr_prmry_plnt.
gr_prmry_plnt-sign = 'I'.
gr_prmry_plnt-option = 'EQ'.
gr_prmry_plnt-low
= '0040'.
APPEND gr_prmry_plnt.
CLEAR gr_prmry_plnt.
gr_prmry_plnt-sign = 'I'.
gr_prmry_plnt-option = 'EQ'.
gr_prmry_plnt-low
= '0070'.
APPEND gr_prmry_plnt.
* AU OCD plant
CLEAR gr_prmry_plnt.
gr_prmry_plnt-sign = 'I'.
gr_prmry_plnt-option = 'EQ'.
gr_prmry_plnt-low
= '0050'.
APPEND gr_prmry_plnt.
ENDIF.
* load JJM NZ primary plants
IF gdf_cocde_nz = gcf_x.
CLEAR gr_prmry_plnt.
gr_prmry_plnt-sign = 'I'.
gr_prmry_plnt-option = 'EQ'.
gr_prmry_plnt-low
= '0071'.
APPEND gr_prmry_plnt.
CLEAR gr_prmry_plnt.
gr_prmry_plnt-sign = 'I'.
gr_prmry_plnt-option = 'EQ'.
gr_prmry_plnt-low
= '0085'.
APPEND gr_prmry_plnt.
* NZ OCD plant
CLEAR gr_prmry_plnt.
gr_prmry_plnt-sign = 'I'.
gr_prmry_plnt-option = 'EQ'.
gr_prmry_plnt-low
= '0056'.
APPEND gr_prmry_plnt.
ENDIF.
*-- r_plant_all
* build range for all plants to be reported
* load JJM AU Plants
IF gdf_cocde_au = gcf_x.
CLEAR gr_plant_all.
gr_plant_all-sign = 'I'.
gr_plant_all-option = 'EQ'.
gr_plant_all-low
= '0040'.
APPEND gr_plant_all.
CLEAR gr_plant_all.
gr_plant_all-sign = 'I'.
gr_plant_all-option = 'EQ'.
gr_plant_all-low
= '0060'.
APPEND gr_plant_all.
CLEAR gr_plant_all.
gr_plant_all-sign = 'I'.
gr_plant_all-option = 'EQ'.
gr_plant_all-low
= '0070'.

APPEND gr_plant_all.
CLEAR gr_plant_all.
gr_plant_all-sign = 'I'.
gr_plant_all-option = 'BT'.
gr_plant_all-low
= '0072'.
gr_plant_all-high = '0079'.
APPEND gr_plant_all.
* AU OCD plant
CLEAR gr_plant_all.
gr_plant_all-sign = 'I'.
gr_plant_all-option = 'EQ'.
gr_plant_all-low
= '0050'.
APPEND gr_plant_all.
ENDIF.
* load JJM NZ Plants
IF gdf_cocde_nz = gcf_x.
CLEAR gr_plant_all.
gr_plant_all-sign = 'I'.
gr_plant_all-option = 'EQ'.
gr_plant_all-low
= '0085'.
APPEND gr_plant_all.
CLEAR gr_plant_all.
gr_plant_all-sign = 'I'.
gr_plant_all-option = 'EQ'.
gr_plant_all-low
= '0071'.
APPEND gr_plant_all.
* NZ OCD plant
CLEAR gr_plant_all.
gr_plant_all-sign = 'I'.
gr_plant_all-option = 'EQ'.
gr_plant_all-low
= '0056'.
APPEND gr_plant_all.
ENDIF.
* build ranges for DePuy and non-DePuy Divisions
* for valuation class inconsistency chec .
*-- r_vcdiv_depuy, r_vcdiv_nondpy
PERFORM build_division_range USING gcf_x.
* build ranges for DePuy and non-DePuy plants
* for valuation class inconsistency chec .
*-- r_vcplnt_depuy
* load JJM AU DePuy plants
IF gdf_cocde_au = gcf_x.
CLEAR gr_vcplnt_depuy.
gr_vcplnt_depuy-sign = 'I'.
gr_vcplnt_depuy-option = 'EQ'.
gr_vcplnt_depuy-low
= '0070'.
APPEND gr_vcplnt_depuy.
CLEAR gr_vcplnt_depuy.
gr_vcplnt_depuy-sign = 'I'.
gr_vcplnt_depuy-option = 'BT'.
gr_vcplnt_depuy-low
= '0072'.
gr_vcplnt_depuy-high = '0079'.
APPEND gr_vcplnt_depuy.
ENDIF.
* load JJM NZ DePuy plant
IF gdf_cocde_nz = gcf_x.
CLEAR gr_vcplnt_depuy.
gr_vcplnt_depuy-sign = 'I'.
gr_vcplnt_depuy-option = 'EQ'.
gr_vcplnt_depuy-low
= '0071'.

APPEND gr_vcplnt_depuy.
ENDIF.
*-- r_vcplnt_nondpy
* load JJM AU Non-DePuy plants
IF gdf_cocde_au = gcf_x.
CLEAR gr_vcplnt_nondpy.
gr_vcplnt_nondpy-sign = 'I'.
gr_vcplnt_nondpy-option = 'EQ'.
gr_vcplnt_nondpy-low
= '0040'.
APPEND gr_vcplnt_nondpy.
CLEAR gr_vcplnt_nondpy.
gr_vcplnt_nondpy-sign = 'I'.
gr_vcplnt_nondpy-option = 'EQ'.
gr_vcplnt_nondpy-low
= '0060'.
APPEND gr_vcplnt_nondpy.
* AU OCD plant
CLEAR gr_vcplnt_nondpy.
gr_vcplnt_nondpy-sign = 'I'.
gr_vcplnt_nondpy-option = 'EQ'.
gr_vcplnt_nondpy-low
= '0050'.
APPEND gr_vcplnt_nondpy.
ENDIF.
* load JJM NZ Non-Depuy plants
IF gdf_cocde_nz = gcf_x.
CLEAR gr_vcplnt_nondpy.
gr_vcplnt_nondpy-sign = 'I'.
gr_vcplnt_nondpy-option = 'EQ'.
gr_vcplnt_nondpy-low
= '0085'.
APPEND gr_vcplnt_nondpy.
* NZ OCD plant
CLEAR gr_vcplnt_nondpy.
gr_vcplnt_nondpy-sign = 'I'.
gr_vcplnt_nondpy-option = 'EQ'.
gr_vcplnt_nondpy-low
= '0056'.
APPEND gr_vcplnt_nondpy.
ENDIF.
* pad s_mmsta with leading zeros.
LOOP AT s_mmsta.
CLEAR gdf_subrc.
IF NOT s_mmsta-low IS INITIAL.
UNPACK s_mmsta-low TO s_mmsta-low.
gdf_subrc = 1.
ENDIF.
IF NOT s_mmsta-high IS INITIAL.
UNPACK s_mmsta-high TO s_mmsta-high.
gdf_subrc = 1.
ENDIF.
IF gdf_subrc = 1.
MODIFY s_mmsta.
ENDIF.
ENDLOOP.
ENDFORM.
" build_ranges
*&---------------------------------------------------------------------*
*&
Form start_data_selection
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
FORM start_data_selection.
IF sy-batch = gcf_x.
MESSAGE i000 WITH text-007.

ENDIF.
PERFORM select_data.
IF sy-batch = gcf_x.
MESSAGE i000 WITH text-008.
ENDIF.
ENDFORM.
" start_data_selection
*&---------------------------------------------------------------------*
*&
Form select_data
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
FORM select_data.
* get company codes and valuation areas
SELECT bu rs bw ey FROM t001
INTO TABLE gdt_org
WHERE bu rs IN s_bu rs
AND bw ey IN s_bw ey.
* DELETE gdt_org WHERE NOT bw ey IN gr_plant_all. " commented parag
SORT gdt_org.
* get material and standard price
IF NOT gdt_org[] IS INITIAL.
SELECT mara~matnr
mara~lvorm
mara~mtart
mara~meins
mara~spart
mara~prdha
mbew~bw ey
mbew~stprs
mbew~peinh
mbew~b las
mbew~laepr
mbew~lb um
mbew~hr ft
mbew~e alr
mbew~h mat
INTO TABLE gdt_mat_all
FROM mara AS mara
INNER JOIN mbew AS mbew
ON mara~matnr = mbew~matnr
FOR ALL ENTRIES IN gdt_org
WHERE mara~matnr IN s_matnr
AND mara~lvorm IN gr_lvorm
*
AND mara~mtart IN gr_mat_type " commented parag
*
AND mara~spart IN gr_division " commented parag
AND mbew~bw ey = gdt_org-bw ey
AND mbew~b las IN s_b las.
ENDIF.
*delete materials with franchises not in the built range.
*DELETE gdt_mat_all WHERE NOT prdha+0(2) IN gr_franchise. " commented parag
*parag
SORT gdt_mat_all BY matnr bw ey.
PERFORM select_primary_plant_data.
ENDFORM.
" select_data
*&--------------------------------------------------------------------*
*&
Form build_field_catalog
*&--------------------------------------------------------------------*
*
text

*---------------------------------------------------------------------*
FORM build_field_catalog.
IF sy-batch = gcf_x.
MESSAGE i000 WITH text-027.
ENDIF.
PERFORM assign_fields USING:
'BUKRS'
'GDT_REPT' 'C' ' ' text-009,
'LVORM'
'GDT_REPT' 'C' ' ' text-010,
'BWKEY'
'GDT_REPT' 'C' ' ' text-011,
'MMSTA'
'GDT_REPT' 'C' ' ' text-012,
'SPART'
'GDT_REPT' 'C' ' ' text-013,
'FRNCH'
'GDT_REPT' 'C' ' ' text-014,
'MATNR'
'GDT_REPT' 'C' ' ' text-015,
'MAKTX'
'GDT_REPT' 'C' ' ' text-016,
'BKLAS'
'GDT_REPT' 'C' ' ' text-017,
'STPRS'
'GDT_REPT' 'C' ' ' text-018,
'PEINH'
'GDT_REPT' 'C' ' ' text-019,
'MEINS'
'GDT_REPT' 'C' ' ' text-020,
'PRIMP'
'GDT_REPT' 'C' ' ' text-021,
'PRIMC'
'GDT_REPT' 'C' ' ' text-022,
'PRMPU'
'GDT_REPT' 'C' ' ' text-023,
'PRMBU'
'GDT_REPT' 'C' ' ' text-024,
* 'LAEPR'
'IT_REPT' 'D' ' ' 'Last Price Change',
* 'LBKUM'
'IT_REPT' 'C' ' ' 'Total Valuated Stoc ',
* 'HRKFT'
'IT_REPT' 'C' ' ' 'Origin Group',
* 'EKALR'
'IT_REPT' 'C' ' ' 'Costed With Qty Structure',
* 'HKMAT'
'IT_REPT' 'C' ' ' 'Material Origin',
'EXTYP'
'GDT_REPT' 'C' ' ' text-025.
ENDFORM.
" build_field_catalog
*&--------------------------------------------------------------------*
*&
Form assign_fields
*&--------------------------------------------------------------------*
text
*---------------------------------------------------------------------*
FORM assign_fields USING
ldf_fieldname
ldt_tabname
ldf_inttype
ldf_ ey
ldf_seltext_s.
DATA: lds_fieldcat LIKE LINE OF gdt_fieldcat.
lds_fieldcat-fieldname
= ldf_fieldname.
lds_fieldcat-tabname
= ldt_tabname.
lds_fieldcat-inttype
= ldf_inttype.
lds_fieldcat- ey
= ldf_ ey.
lds_fieldcat-reptext_ddic = ldf_seltext_s.
IF lds_fieldcat-fieldname = 'LAEPR' OR
lds_fieldcat-fieldname = 'LBKUM' OR
lds_fieldcat-fieldname = 'HRKFT' OR
lds_fieldcat-fieldname = 'EKALR' OR
lds_fieldcat-fieldname = 'HKMAT'.
lds_fieldcat-no_out = gcf_x.
ENDIF.
IF lds_fieldcat-fieldname <> 'BWKEY' AND
lds_fieldcat-fieldname <> 'STPRS' AND
lds_fieldcat-fieldname <> 'MMSTA' AND
lds_fieldcat-fieldname <> 'PRIMP'.
lds_fieldcat-no_zero = gcf_x.

ENDIF.
APPEND lds_fieldcat TO gdt_fieldcat.
ENDFORM.
" assign_fields
*&--------------------------------------------------------------------*
*&
Form build_alv_header
*&--------------------------------------------------------------------*
*
text
*---------------------------------------------------------------------*
FORM build_alv_header.
DATA: ldf_header TYPE slis_entry.
DATA: ldf_perio(10) TYPE c.
DATA: ldf_cpudtl(10) TYPE c.
DATA: ldf_cpudth(10) TYPE c.
CLEAR gds_listheader.
REFRESH gdt_listheader.
* Main heading
CLEAR gds_listheader.
gds_listheader-typ = gcf_h.
gds_listheader-info = text-h01.
APPEND gds_listheader TO gdt_listheader.
* Sub heading - Company code
CLEAR gds_listheader.
gds_listheader-typ = gcf_s.
gds_listheader- ey = text-h02.
IF NOT s_bu rs[] IS INITIAL.
LOOP AT s_bu rs.
IF sy-tabix > 1.
CLEAR gds_listheader- ey.
ENDIF.
IF NOT s_bu rs-high IS INITIAL.
CONCATENATE s_bu rs-low s_bu rs-high INTO gds_listheader-info
SEPARATED BY ' - '.
ELSE.
gds_listheader-info = s_bu rs-low.
ENDIF.
APPEND gds_listheader TO gdt_listheader.
ENDLOOP.
ENDIF.
* Sub heading - Division
CLEAR gds_listheader.
gds_listheader-typ = gcf_s.
gds_listheader- ey = text-h03.
IF s_spart[] IS INITIAL.
gds_listheader-info = 'All'.
APPEND gds_listheader TO gdt_listheader.
ELSE.
LOOP AT s_spart.
IF sy-tabix > 1.
CLEAR gds_listheader- ey.
ENDIF.
IF NOT s_spart-high IS INITIAL.
CONCATENATE s_spart-low s_spart-high INTO gds_listheader-info
SEPARATED BY ' - '.
ELSE.
gds_listheader-info = s_spart-low.
ENDIF.
APPEND gds_listheader TO gdt_listheader.

ENDLOOP.
ENDIF.
* General ALV header info: date/time/username
* (this will appear on all ALV grids)
CLEAR gds_listheader.
gds_listheader-typ = gcf_s.
gds_listheader- ey = text-026.
WRITE sy-datum TO gds_listheader-info.
WRITE '/' TO gds_listheader-info+11(1).
WRITE sy-uzeit TO gds_listheader-info+13.
WRITE '/' TO gds_listheader-info+22(1).
WRITE sy-uname TO gds_listheader-info+24.
APPEND gds_listheader TO gdt_listheader.
ENDFORM.
" build_alv_header
*&--------------------------------------------------------------------*&
Form build_alv_layout
*&--------------------------------------------------------------------*
text
*---------------------------------------------------------------------*
FORM build_alv_layout.
gds_layout-cell_merge
= gcf_x.
gds_layout-colwidth_optimize = gcf_x.
ENDFORM.
" build_alv_layout
*&---------------------------------------------------------------------*
*&
Form set_alv_pfstatus
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
FORM set_alv_pfstatus USING ldt_extab TYPE slis_t_extab.
DATA: lds_extab TYPE slis_extab.
SET PF-STATUS '0100'.
ENDFORM.
" set_alv_pfstatus
*&--------------------------------------------------------------------*&
Form display_alv_report
*&--------------------------------------------------------------------*
text
*---------------------------------------------------------------------*
FORM display_alv_report.
PERFORM build_field_catalog.
* perform build_sort_sequence.
PERFORM build_alv_header.
PERFORM build_alv_layout.
SORT gdt_rept BY bw ey spart matnr.
gdf_repid = sy-repid.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callbac _program
= gdf_repid
i_callbac _pf_status_set = gcf_alv_pfs
i_callbac _top_of_page = gcf_alv_top
i_callbac _user_command = gcf_alv_cmd
is_layout
= gds_layout
it_fieldcat
= gdt_fieldcat
*
it_sort
= it_sort
i_save
= gcf_a
TABLES
t_outtab
= gdt_rept
EXCEPTIONS
program_error
= 1

OTHERS
= 2.
IF sy-subrc NE 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 display_alv_top
*&--------------------------------------------------------------------*
*
text
*---------------------------------------------------------------------*
FORM display_alv_top.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = gdt_listheader.
ENDFORM.
" display_alv_top
*&---------------------------------------------------------------------*
*&
Form authority_chec
*&---------------------------------------------------------------------*
*
Chec Authorization for Company Code
*----------------------------------------------------------------------*
FORM authority_chec .
DATA: ldf_bu rs
LIKE t001-bu rs,
ldf_actvt03 TYPE activ_auth VALUE '03'.
SELECT bu rs INTO ldf_bu rs
FROM t001
WHERE bu rs IN s_bu rs.
AUTHORITY-CHECK OBJECT 'F_KNA1_BUK'
ID
'BUKRS' FIELD ldf_bu rs
ID
'ACTVT' FIELD ldf_actvt03.
IF sy-subrc <> 0.
SET CURSOR FIELD 'S_BUKRS-LOW'.
MESSAGE e460(f5) WITH ldf_bu rs.
ENDIF.
ENDSELECT.
IF sy-subrc NE 0.
SET CURSOR FIELD 'S_BUKRS-LOW'.
MESSAGE e165(f5) WITH s_bu rs-low.
ENDIF.
ENDFORM.
" authority_chec
*&---------------------------------------------------------------------*
*&
Form process_report_data
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM process_report_data.
CLEAR gdt_mat_all.
LOOP AT gdt_mat_all.
CLEAR: gdf_excep_icm,
gdf_excep_icn,
gdf_excep_vcl.
CLEAR gdt_rept.
gdt_rept-lvorm = gdt_mat_all-lvorm.

gdt_rept-meins = gdt_mat_all-meins.
gdt_rept-spart = gdt_mat_all-spart.
gdt_rept-matnr = gdt_mat_all-matnr.
gdt_rept-bw ey = gdt_mat_all-bw ey.
gdt_rept-stprs = gdt_mat_all-stprs.
gdt_rept-peinh = gdt_mat_all-peinh.
gdt_rept-b las = gdt_mat_all-b las.
APPEND gdt_rept.
*
MOVE-CORRESPONDING ldt_mat_all TO ldt_rept. "Commented By Parag.
* populate franchise
gdt_rept-frnch = gdt_mat_all-prdha+0(2).
* populate company code
CLEAR gdt_org.
READ TABLE gdt_org WITH KEY bw ey = gdt_rept-bw ey
BINARY SEARCH.
IF sy-subrc = 0.
gdt_rept-bu rs = gdt_org-bu rs.
MODIFY gdt_rept TRANSPORTING bu rs WHERE bw ey =
gdt_mat_all-bw ey. " commented by parag
ENDIF.
CASE gdt_rept-bu rs.
WHEN gcf_jjmau.
PERFORM load_jjmau_primary_plants.
WHEN gcf_jjmnz.
PERFORM load_jjmnz_primary_plants.
ENDCASE.
IF gdf_excep_icm IS INITIAL AND
gdf_excep_icn IS INITIAL AND
gdf_excep_vcl IS INITIAL.
CONTINUE.
ELSE.
PERFORM get_plant_status.
IF gdt_rept-mmsta IN s_mmsta.
"MOD004
PERFORM get_material_desc.
APPEND gdt_rept.
ENDIF.
"MOD004
ENDIF.
CLEAR gdt_mat_all.
ENDLOOP.
PERFORM refresh_internal_tables.
ENDFORM.
" process_report_data
*&---------------------------------------------------------------------*
*&
Form get_material_desc
*&---------------------------------------------------------------------*
FORM get_material_desc.
CLEAR gdt_rept-ma tx.
CLEAR gdt_matdesc.
READ TABLE gdt_matdesc WITH KEY
matnr = gdt_rept-matnr
BINARY SEARCH.
IF sy-subrc = 0.
gdt_rept-ma tx = gdt_matdesc-ma tx.
ELSE.
SELECT SINGLE matnr ma tx FROM ma t INTO gdt_matdesc
WHERE matnr = gdt_rept-matnr
AND spras = sy-langu.
IF sy-subrc = 0.
gdt_rept-ma tx = gdt_matdesc-ma tx.
APPEND gdt_matdesc.
SORT gdt_matdesc BY matnr.

ENDIF.
ENDIF.
ENDFORM.
" get_material_desc
*&---------------------------------------------------------------------*
*&
Form get_plant_status
*&---------------------------------------------------------------------*
FORM get_plant_status.
CLEAR gdt_rept-mmsta.
SELECT SINGLE mmsta INTO gdt_rept-mmsta FROM marc
WHERE matnr = gdt_rept-matnr
AND wer s = gdt_rept-bw ey.
ENDFORM.
" get_plant_status
*&---------------------------------------------------------------------*
*&
Form load_jjmau_primary_plants
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM load_jjmau_primary_plants.
DATA: ldf_divchar1(1) TYPE c.
gdf_subrc = 9.
CLEAR gdt_primary.
ldf_divchar1 = gdt_rept-spart+0(1).
CASE ldf_divchar1.
* Codman or Mite
WHEN '1' OR '2' OR '3'.
READ TABLE gdt_primary WITH KEY
matnr = gdt_rept-matnr
bw ey = gcf_prmplnt40
BINARY SEARCH.
gdf_subrc = sy-subrc.
* DePuy
WHEN 'A'.
IF gdt_rept-spart = 'AS'.
"Non-DePuy
READ TABLE gdt_primary WITH KEY
matnr = gdt_rept-matnr
bw ey = gcf_prmplnt40
BINARY SEARCH.
ELSE.
"DePuy (including IAU)
READ TABLE gdt_primary WITH KEY
matnr = gdt_rept-matnr
bw ey = gcf_prmplnt70
BINARY SEARCH.
ENDIF.
gdf_subrc = sy-subrc.
* Others
WHEN OTHERS.
CASE gdt_rept-spart.
* Mentor
WHEN 'BA' OR 'BC' OR 'FA' OR 'OA'.
READ TABLE gdt_primary WITH KEY
matnr = gdt_rept-matnr
bw ey = gcf_prmplnt70
BINARY SEARCH.
gdf_subrc = sy-subrc.
* All other divisions (BW, CF, CE, CL, ES, EN, EM, EO etc.)
WHEN OTHERS.
READ TABLE gdt_primary WITH KEY

matnr = gdt_rept-matnr
bw ey = gcf_prmplnt40
BINARY SEARCH.
gdf_subrc = sy-subrc.
ENDCASE.
ENDCASE.
* populate fields for primary plant i.e.
* primary plant, cost, price unit and base UoM
IF gdf_subrc = 0.
gdt_rept-primp = gdt_primary-bw ey.
gdt_rept-primc = gdt_primary-stprs.
gdt_rept-prmpu = gdt_primary-peinh.
gdt_rept-prmbu = gdt_primary-meins.
ENDIF.
PERFORM find_exception_data.
ENDFORM.
" load_jjmau_primary_plants
*&---------------------------------------------------------------------*
*&
Form load_jjmnz_primary_plants
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM load_jjmnz_primary_plants.
DATA: ldf_divchar1(1) TYPE c.
gdf_subrc = 9.
CLEAR gdt_primary.
ldf_divchar1 = gdt_rept-spart+0(1).
CASE ldf_divchar1.
* Codman or Mite
WHEN '1' OR '2' OR '3'.
READ TABLE gdt_primary WITH KEY
matnr = gdt_rept-matnr
bw ey = gcf_prmplnt85
BINARY SEARCH.
gdf_subrc = sy-subrc.
* DePuy
WHEN 'A'.
IF gdt_rept-spart = 'AS'.
"Non-DePuy
READ TABLE gdt_primary WITH KEY
matnr = gdt_rept-matnr
bw ey = gcf_prmplnt85
BINARY SEARCH.
ELSE.
"DePuy (including IAU)
READ TABLE gdt_primary WITH KEY
matnr = gdt_rept-matnr
bw ey = gcf_prmplnt71
BINARY SEARCH.
ENDIF.
gdf_subrc = sy-subrc.
* Others
WHEN OTHERS.
CASE gdt_rept-spart.
* Mentor
WHEN 'BA' OR 'BC' OR 'FA' OR 'OA'.
READ TABLE gdt_primary WITH KEY
matnr = gdt_rept-matnr
bw ey = gcf_prmplnt71
BINARY SEARCH.

gdf_subrc = sy-subrc.
* All other divisions (BW, CF, CE, CL, ES, EN, EM, EO etc.)
WHEN OTHERS.
READ TABLE gdt_primary WITH KEY
matnr = gdt_rept-matnr
bw ey = gcf_prmplnt85
BINARY SEARCH.
gdf_subrc = sy-subrc.
ENDCASE.
ENDCASE.
* populate fields for primary plant i.e.
* primary plant, cost, price unit and base UoM
IF gdf_subrc = 0.
gdt_rept-primp = gdt_primary-bw ey.
gdt_rept-primc = gdt_primary-stprs.
gdt_rept-prmpu = gdt_primary-peinh.
gdt_rept-prmbu = gdt_primary-meins.
ENDIF.
PERFORM find_exception_data.
ENDFORM.
" load_jjmnz_primary_plants
*&---------------------------------------------------------------------*
*&
Form build_division_range
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM build_division_range USING p_vclass.
DATA: ldf_divchar1(1) TYPE c.
RANGES: lr_division FOR mara-spart.
REFRESH lr_division.
lr_division-sign = 'I'.
lr_division-option = 'EQ'.
LOOP AT gdt_divsn.
CLEAR lr_division-low.
ldf_divchar1 = gdt_divsn-spart+0(1).
CASE ldf_divchar1.
WHEN '1' OR '2' OR '3' OR 'A' OR 'E'.
lr_division-low = gdt_divsn-spart.
APPEND lr_division.
WHEN OTHERS.
CASE gdt_divsn-spart.
WHEN 'BW' OR 'CF' OR 'CE' OR 'CL' OR
'BA' OR 'BC' OR 'FA' OR 'OA'.
lr_division-low = gdt_divsn-spart.
APPEND lr_division.
WHEN OTHERS.
ENDCASE.
ENDCASE.
ENDLOOP.
SORT lr_division.
IF p_vclass IS INITIAL.
REFRESH gr_division.
APPEND LINES OF lr_division TO gr_division.
ELSE.
* build ranges for DePuy and non-DePuy Divisions
* for valuation class inconsistency chec .
REFRESH gr_vcdiv_depuy.
APPEND LINES OF lr_division TO gr_vcdiv_depuy.

DELETE gr_vcdiv_depuy WHERE low+0(1) <> 'A'.


DELETE gr_vcdiv_depuy WHERE low = 'AS'.
REFRESH gr_vcdiv_nondpy.
APPEND LINES OF lr_division TO gr_vcdiv_nondpy.
DELETE gr_vcdiv_nondpy WHERE low IN gr_vcdiv_depuy.
ENDIF.
ENDFORM.
" build_division_range
*---------------------------------------------------------------------*
*
FORM ALV_USER_COMMAND_DISPLAY_MAT
*---------------------------------------------------------------------*
* --> P_UCOMM
*
* --> PS_SELFIELD
*
*---------------------------------------------------------------------*
FORM alv_user_command_display_mat USING
p_ucomm LIKE sy-ucomm
ps_selfield TYPE slis_selfield.
DATA: ldf_matnr TYPE matnr.
CASE p_ucomm.
WHEN '&IC1'.
"Double clic
READ TABLE gdt_rept INDEX ps_selfield-tabindex. "Cursor position
CHECK sy-subrc EQ 0.
ldf_matnr = gdt_rept-matnr.
CASE ps_selfield-fieldname.
WHEN 'MATNR'.
SET PARAMETER ID 'MAT' FIELD ldf_matnr.
CALL TRANSACTION 'MM03' AND SKIP FIRST SCREEN.
ENDCASE.
WHEN OTHERS.
"Do nothing
ENDCASE.
CLEAR p_ucomm.
ENDFORM.
"alv_user_command_display_mat
*&---------------------------------------------------------------------*
*&
Form chec _company_code_entered
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM chec _company_code_entered.
* set flag ws_cocde_au if jjmau company code has been entered in the
* selection criteria
CLEAR gdf_cocde_au.
LOOP AT s_bu rs.
CHECK s_bu rs-sign = 'I'.
IF s_bu rs-option = 'EQ'.
IF gcf_jjmau = s_bu rs-low.
gdf_cocde_au = gcf_x.
EXIT.
ENDIF.
ELSEIF s_bu rs-option = 'BT'.
IF gcf_jjmau IN s_bu rs.
gdf_cocde_au = gcf_x.
EXIT.
ENDIF.
ENDIF.
ENDLOOP.
* set flag ws_cocde_nz if jjmnz company code has been entered in the
* selection criteria
CLEAR gdf_cocde_nz.

LOOP AT s_bu rs.


CHECK s_bu rs-sign = 'I'.
IF s_bu rs-option = 'EQ'.
IF gcf_jjmnz = s_bu rs-low.
gdf_cocde_nz = gcf_x.
EXIT.
ENDIF.
ELSEIF s_bu rs-option = 'BT'.
IF gcf_jjmnz IN s_bu rs.
gdf_cocde_nz = gcf_x.
EXIT.
ENDIF.
ENDIF.
ENDLOOP.
ENDFORM.
" chec _company_code_entered
*&---------------------------------------------------------------------*
*&
Form find_exception_data
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM find_exception_data.
* find exceptions and populate flag for the type of exception:
* <<<< valuation class exception >>>>
IF gdt_mat_all-mtart = gcf_fert AND gdt_rept-b las = gcf_vcls7920.
* material type FERT (finished product) has valuation class 7920 so,
* this is not an exception - clear the flag
CLEAR gdf_excep_vcl.
ELSEIF gdt_mat_all-mtart = gcf_halb AND
( gdt_rept-b las = gcf_vcls7910 OR gdt_rept-b las = gcf_vcls7900 ).
* material type HALB (semifinished product) has valuation class 7910 so,
* this is not an exception - clear the flag
CLEAR gdf_excep_vcl.
ELSEIF gdt_mat_all-mtart = gcf_verp AND gdt_rept-b las = gcf_vcls3050.
* material type VERP (pac aging) has valuation class 3050 so,
* this is not an exception - clear the flag
CLEAR gdf_excep_vcl.
ELSEIF gdt_mat_all-mtart = gcf_roh AND gdt_rept-b las = gcf_vcls3000.
* material type ROH (raw material) has valuation class 3000 so,
* this is not an exception - clear the flag
CLEAR gdf_excep_vcl.
ELSEIF gdt_rept-matnr+0(3) = gcf_iau_mat AND
gdt_rept-b las = gcf_vcls3300.
* IAU materials have valuation class 3300 so, this is not an
* exception - clear the flag
CLEAR gdf_excep_vcl.
ELSE.
IF NOT p_vlcls IS INITIAL.
* DePuy (non IAU)
IF gdt_rept-spart IN gr_vcdiv_depuy.
* DePuy materials in DePuy plants should have valuation class 3100,
* otherswise report as an exception - set the flag
IF gdt_rept-bw ey IN gr_vcplnt_depuy AND
"MOD002
gdt_rept-b las <> gcf_vcls3100.
gdf_excep_vcl = gcf_x.
* DePuy materials in non DePuy plants should not have valuation class
* 3100, otherswise report as an exception - set the flag
ELSEIF gdt_rept-bw ey IN gr_vcplnt_nondpy AND
"MOD002

*
*
*

*
*

*
*
*
*

*
*

gdt_rept-b las = gcf_vcls3100.


"MOD002
gdf_excep_vcl = gcf_x.
ENDIF.
Non-Depuy
ELSEIF gdt_rept-spart IN gr_vcdiv_nondpy.
Non-DePuy materials in non DePuy plants should have valuation class
3100, otherwise report as an exception - set the flag
IF gdt_rept-bw ey IN gr_vcplnt_nondpy AND
"MOD002
gdt_rept-b las <> gcf_vcls3100.
gdf_excep_vcl = gcf_x.
Non-DePuy materials in DePuy plants should have valuation class
3150, otherwise report as an exception - set the flag
ELSEIF gdt_rept-bw ey IN gr_vcplnt_depuy AND
"MOD002
gdt_rept-b las <> gcf_vcls3150.
gdf_excep_vcl = gcf_x.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
populate valuation class exception type
IF gdf_excep_vcl = gcf_x.
gdt_rept-extyp = gcf_valclass.
ENDIF.
<<<< incomplete exception >>>>
- incomplete when price is equal to 0.01
- also incomplete when accounting view has not been created
and the price is equal to 0.00
IF gdt_rept-stprs = '0.00'.
IF NOT p_zerop IS INITIAL AND
NOT p_incom IS INITIAL.
gdf_excep_icm = gcf_x.
ENDIF.
ELSEIF gdt_rept-stprs = '0.01'.
IF NOT p_incom IS INITIAL.
gdf_excep_icm = gcf_x.
ENDIF.
ENDIF.
populate incomplete exception type
IF gdf_excep_icm = gcf_x.
IF gdf_excep_vcl IS INITIAL.
gdt_rept-extyp = gcf_incomplt.
ELSE.
CONCATENATE gcf_incomplt gdt_rept-extyp INTO gdt_rept-extyp
SEPARATED BY '/'.
ENDIF.
ENDIF.
<<<< inconsistent exception >>>>
- inconsistent when price is not equal to primary plant price
IF gdf_subrc = 0 AND
"primary plant found
gdt_rept-stprs > '0.01'.
"price is not incomplete
IF NOT p_incon IS INITIAL AND NOT gdt_rept-primp IS INITIAL.
IF gdt_rept-stprs <> gdt_rept-primc.
gdf_excep_icn = gcf_x.
ENDIF.
ENDIF.
ENDIF.
populate inconsistent exception type
IF gdf_excep_icn = gcf_x.
IF gdf_excep_vcl IS INITIAL.
gdt_rept-extyp = gcf_inconsis.

ELSE.
CONCATENATE gcf_inconsis gdt_rept-extyp INTO gdt_rept-extyp
SEPARATED BY '/'.
ENDIF.
ENDIF.
* if primary plant and valuation area are same, clear primary plant info
IF gdt_rept-bw ey = gdt_rept-primp.
CLEAR: gdt_rept-primp,
gdt_rept-primc,
gdt_rept-prmpu,
gdt_rept-prmbu.
ENDIF.
ENDFORM.
" find_exception_data
*&---------------------------------------------------------------------*
*&
Form refresh_internal_tables
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM refresh_internal_tables.
* refresh internal tables
REFRESH: gdt_org,
gdt_mat_all,
gdt_primary,
gdt_matdesc,
gdt_divsn.
* refresh ranges tables
REFRESH: gr_franchise,
gr_mat_type,
gr_plant_all,
gr_prmry_plnt,
gr_division,
gr_vcdiv_depuy,
gr_vcdiv_nondpy,
gr_vcplnt_depuy,
gr_vcplnt_nondpy,
gr_lvorm.
ENDFORM.
" refresh_internal_tables
*&---------------------------------------------------------------------*
*&
Form select_primary_plant_data
"MOD003
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM select_primary_plant_data.
"MOD003
IF s_bw ey[] IS INITIAL.
* build an internal table for primary plants from already selected data.
APPEND LINES OF gdt_mat_all TO gdt_primary.
*
DELETE gdt_primary WHERE NOT bw ey IN gr_prmry_plnt. "commented by parag
ELSE.
* select primary plant data from database.
SELECT mara~matnr
mara~lvorm
mara~mtart
mara~meins
mara~spart

mara~prdha
mbew~bw ey
mbew~stprs
mbew~peinh
mbew~b las
mbew~laepr
mbew~lb um
mbew~hr ft
mbew~e alr
mbew~h mat
INTO TABLE gdt_primary
FROM mara AS mara
INNER JOIN mbew AS mbew
ON mara~matnr = mbew~matnr
WHERE mara~matnr IN s_matnr
AND mara~lvorm IN gr_lvorm
"commented by parag
*
AND mara~mtart IN gr_mat_type "commented by parag
*
AND mara~spart IN gr_division "commented by parag
*
AND mbew~bw ey IN gr_prmry_plnt
AND mbew~b las IN s_b las.
ENDIF.
SORT gdt_primary BY matnr bw ey.
ENDFORM.
" select_primary_plant_data

"MOD003

Вам также может понравиться