*&---------------------------------------------------------------------*
*& 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 check 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
bwkey TYPE bwkey, " Valuation area
stprs TYPE stprs, " Stabdard price
peinh TYPE peinh, " Price unit
bklas TYPE bklas, " Valuation class
laepr TYPE laepr, " Last price change
lbkum TYPE lbkum, " Total valuated stock
hrkft TYPE hrkft, " Origin group
ekalr TYPE ck_ekalrel, " Costed with qty structure
hkmat TYPE hkmat, " Material origin
END OF gts_matpr.
*----------------------------------------------------------------------*
* Internal Tables *
*----------------------------------------------------------------------*
DATA: BEGIN OF gdt_org OCCURS 0,"it_org
bukrs TYPE bukrs,
bwkey TYPE bwkey,
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,
bukrs TYPE bukrs, " Company code
lvorm TYPE lvoma, " Deletion indicator "MOD001
bwkey TYPE bwkey, " Valuation Area
mmsta TYPE mmsta, " Plant Status "MOD001
spart TYPE spart, " Division
frnch TYPE spart, " Franchise
matnr TYPE matnr, " Material
maktx TYPE maktx, " Description
bklas TYPE bklas, " 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 werks_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
* lbkum TYPE lbkum, " Total valuated stock
* hrkft TYPE hrkft, " Origin group
* ekalr TYPE ck_ekalrel, " Costed with qty structure
* hkmat TYPE hkmat, " 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,
maktx TYPE maktx,
END OF gdt_matdesc.
*----------------------------------------------------------------------*
* Working 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 werks_d VALUE '0040'.
CONSTANTS: gcf_prmplnt70 TYPE werks_d VALUE '0070'.
CONSTANTS: gcf_prmplnt85 TYPE werks_d VALUE '0085'.
CONSTANTS: gcf_prmplnt71 TYPE werks_d VALUE '0071'.
CONSTANTS: gcf_jjmau TYPE bukrs VALUE '7515'.
CONSTANTS: gcf_jjmnz TYPE bukrs 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 bklas VALUE '3100'.
CONSTANTS: gcf_vcls3150 TYPE bklas VALUE '3150'.
CONSTANTS: gcf_vcls3300 TYPE bklas VALUE '3300'.
CONSTANTS: gcf_vcls7920 TYPE bklas VALUE '7920'. "MOD001
CONSTANTS: gcf_vcls7910 TYPE bklas VALUE '7910'. "MOD001
CONSTANTS: gcf_vcls7900 TYPE bklas VALUE '7900'. "MOD002
CONSTANTS: gcf_vcls3050 TYPE bklas VALUE '3050'. "MOD001
CONSTANTS: gcf_vcls3000 TYPE bklas 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-bwkey.
RANGES: gr_prmry_plnt FOR mbew-bwkey.
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-bwkey.
RANGES: gr_vcplnt_nondpy FOR mbew-bwkey.
RANGES: gr_lvorm FOR mara-lvorm.
*----------------------------------------------------------------------*
* Selection Screen *
*----------------------------------------------------------------------*
* Selection Criteria
SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME TITLE text-001.
SELECT-OPTIONS: s_bukrs FOR t001-bukrs OBLIGATORY.
SELECT-OPTIONS: s_spart FOR mara-spart.
SELECT-OPTIONS: s_bwkey FOR mbew-bwkey.
SELECT-OPTIONS: s_matnr FOR mara-matnr.
SELECT-OPTIONS: s_bklas FOR mbew-bklas.
SELECT-OPTIONS: s_mmsta FOR marc-mmsta. "MOD004
SELECTION-SCREEN END OF BLOCK blk1.
* Report Options
SELECTION-SCREEN BEGIN OF BLOCK blk2 WITH FRAME TITLE text-002.
PARAMETERS: p_incon AS CHECKBOX DEFAULT 'X'.
PARAMETERS: p_vlcls AS CHECKBOX DEFAULT 'X'.
SELECTION-SCREEN BEGIN OF BLOCK blk3 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 blk3.
PARAMETERS: p_lvorm AS CHECKBOX.
SELECTION-SCREEN END OF BLOCK blk2.
* ALV Variant
SELECTION-SCREEN BEGIN OF BLOCK blk4 WITH FRAME TITLE text-003.
PARAMETERS: p_varian LIKE disvariant-variant.
SELECTION-SCREEN END OF BLOCK blk4.
*----------------------------------------------------------------------*
* 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_bukrs.
PERFORM authority_check.
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 check_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 check.
*-- 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 check.
*-- 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 bukrs bwkey FROM t001k
INTO TABLE gdt_org
WHERE bukrs IN s_bukrs
AND bwkey IN s_bwkey.
* DELETE gdt_org WHERE NOT bwkey 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~bwkey
mbew~stprs
mbew~peinh
mbew~bklas
mbew~laepr
mbew~lbkum
mbew~hrkft
mbew~ekalr
mbew~hkmat
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~bwkey = gdt_org-bwkey
AND mbew~bklas IN s_bklas.
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 bwkey.
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 Stock',
* '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_key
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-key = ldf_key.
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-key = text-h02.
IF NOT s_bukrs[] IS INITIAL.
LOOP AT s_bukrs.
IF sy-tabix > 1.
CLEAR gds_listheader-key.
ENDIF.
IF NOT s_bukrs-high IS INITIAL.
CONCATENATE s_bukrs-low s_bukrs-high INTO gds_listheader-info
SEPARATED BY ' - '.
ELSE.
gds_listheader-info = s_bukrs-low.
ENDIF.
APPEND gds_listheader TO gdt_listheader.
ENDLOOP.
ENDIF.
* Sub heading - Division
CLEAR gds_listheader.
gds_listheader-typ = gcf_s.
gds_listheader-key = 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-key.
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-key = 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 bwkey spart matnr.
gdf_repid = sy-repid.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = gdf_repid
i_callback_pf_status_set = gcf_alv_pfs
i_callback_top_of_page = gcf_alv_top
i_callback_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_check
*&---------------------------------------------------------------------*
* Check Authorization for Company Code
*----------------------------------------------------------------------*
FORM authority_check.
DATA: ldf_bukrs LIKE t001-bukrs,
ldf_actvt03 TYPE activ_auth VALUE '03'.
SELECT bukrs INTO ldf_bukrs
FROM t001
WHERE bukrs IN s_bukrs.
AUTHORITY-CHECK OBJECT 'F_KNA1_BUK'
ID 'BUKRS' FIELD ldf_bukrs
ID 'ACTVT' FIELD ldf_actvt03.
IF sy-subrc <> 0.
SET CURSOR FIELD 'S_BUKRS-LOW'.
MESSAGE e460(f5) WITH ldf_bukrs.
ENDIF.
ENDSELECT.
IF sy-subrc NE 0.
SET CURSOR FIELD 'S_BUKRS-LOW'.
MESSAGE e165(f5) WITH s_bukrs-low.
ENDIF.
ENDFORM. " authority_check
*&---------------------------------------------------------------------*
*& 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-bwkey = gdt_mat_all-bwkey.
gdt_rept-stprs = gdt_mat_all-stprs.
gdt_rept-peinh = gdt_mat_all-peinh.
gdt_rept-bklas = gdt_mat_all-bklas.
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 bwkey = gdt_rept-bwkey
BINARY SEARCH.
IF sy-subrc = 0.
gdt_rept-bukrs = gdt_org-bukrs.
MODIFY gdt_rept TRANSPORTING bukrs WHERE bwkey =
gdt_mat_all-bwkey. " commented by parag
ENDIF.
CASE gdt_rept-bukrs.
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-maktx.
CLEAR gdt_matdesc.
READ TABLE gdt_matdesc WITH KEY
matnr = gdt_rept-matnr
BINARY SEARCH.
IF sy-subrc = 0.
gdt_rept-maktx = gdt_matdesc-maktx.
ELSE.
SELECT SINGLE matnr maktx FROM makt INTO gdt_matdesc
WHERE matnr = gdt_rept-matnr
AND spras = sy-langu.
IF sy-subrc = 0.
gdt_rept-maktx = gdt_matdesc-maktx.
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 werks = gdt_rept-bwkey.
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 Mitek
WHEN '1' OR '2' OR '3'.
READ TABLE gdt_primary WITH KEY
matnr = gdt_rept-matnr
bwkey = 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
bwkey = gcf_prmplnt40
BINARY SEARCH.
ELSE. "DePuy (including IAU)
READ TABLE gdt_primary WITH KEY
matnr = gdt_rept-matnr
bwkey = 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
bwkey = 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
bwkey = 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-bwkey.
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 Mitek
WHEN '1' OR '2' OR '3'.
READ TABLE gdt_primary WITH KEY
matnr = gdt_rept-matnr
bwkey = 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
bwkey = gcf_prmplnt85
BINARY SEARCH.
ELSE. "DePuy (including IAU)
READ TABLE gdt_primary WITH KEY
matnr = gdt_rept-matnr
bwkey = 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
bwkey = 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
bwkey = 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-bwkey.
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 check.
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 click
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 check_company_code_entered
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM check_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_bukrs.
CHECK s_bukrs-sign = 'I'.
IF s_bukrs-option = 'EQ'.
IF gcf_jjmau = s_bukrs-low.
gdf_cocde_au = gcf_x.
EXIT.
ENDIF.
ELSEIF s_bukrs-option = 'BT'.
IF gcf_jjmau IN s_bukrs.
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_bukrs.
CHECK s_bukrs-sign = 'I'.
IF s_bukrs-option = 'EQ'.
IF gcf_jjmnz = s_bukrs-low.
gdf_cocde_nz = gcf_x.
EXIT.
ENDIF.
ELSEIF s_bukrs-option = 'BT'.
IF gcf_jjmnz IN s_bukrs.
gdf_cocde_nz = gcf_x.
EXIT.
ENDIF.
ENDIF.
ENDLOOP.
ENDFORM. " check_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-bklas = 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-bklas = gcf_vcls7910 OR gdt_rept-bklas = 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-bklas = gcf_vcls3050.
* material type VERP (packaging) 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-bklas = 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-bklas = 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-bwkey IN gr_vcplnt_depuy AND "MOD002
gdt_rept-bklas <> 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-bwkey IN gr_vcplnt_nondpy AND "MOD002
gdt_rept-bklas = 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-bwkey IN gr_vcplnt_nondpy AND "MOD002
gdt_rept-bklas <> 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-bwkey IN gr_vcplnt_depuy AND "MOD002
gdt_rept-bklas <> 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-bwkey = 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_bwkey[] 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 bwkey 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~bwkey
mbew~stprs
mbew~peinh
mbew~bklas
mbew~laepr
mbew~lbkum
mbew~hrkft
mbew~ekalr
mbew~hkmat
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~bwkey IN gr_prmry_plnt
AND mbew~bklas IN s_bklas.
ENDIF.
SORT gdt_primary BY matnr bwkey.
ENDFORM. " select_primary_plant_data "MOD003
*& 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 check 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
bwkey TYPE bwkey, " Valuation area
stprs TYPE stprs, " Stabdard price
peinh TYPE peinh, " Price unit
bklas TYPE bklas, " Valuation class
laepr TYPE laepr, " Last price change
lbkum TYPE lbkum, " Total valuated stock
hrkft TYPE hrkft, " Origin group
ekalr TYPE ck_ekalrel, " Costed with qty structure
hkmat TYPE hkmat, " Material origin
END OF gts_matpr.
*----------------------------------------------------------------------*
* Internal Tables *
*----------------------------------------------------------------------*
DATA: BEGIN OF gdt_org OCCURS 0,"it_org
bukrs TYPE bukrs,
bwkey TYPE bwkey,
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,
bukrs TYPE bukrs, " Company code
lvorm TYPE lvoma, " Deletion indicator "MOD001
bwkey TYPE bwkey, " Valuation Area
mmsta TYPE mmsta, " Plant Status "MOD001
spart TYPE spart, " Division
frnch TYPE spart, " Franchise
matnr TYPE matnr, " Material
maktx TYPE maktx, " Description
bklas TYPE bklas, " 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 werks_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
* lbkum TYPE lbkum, " Total valuated stock
* hrkft TYPE hrkft, " Origin group
* ekalr TYPE ck_ekalrel, " Costed with qty structure
* hkmat TYPE hkmat, " 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,
maktx TYPE maktx,
END OF gdt_matdesc.
*----------------------------------------------------------------------*
* Working 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 werks_d VALUE '0040'.
CONSTANTS: gcf_prmplnt70 TYPE werks_d VALUE '0070'.
CONSTANTS: gcf_prmplnt85 TYPE werks_d VALUE '0085'.
CONSTANTS: gcf_prmplnt71 TYPE werks_d VALUE '0071'.
CONSTANTS: gcf_jjmau TYPE bukrs VALUE '7515'.
CONSTANTS: gcf_jjmnz TYPE bukrs 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 bklas VALUE '3100'.
CONSTANTS: gcf_vcls3150 TYPE bklas VALUE '3150'.
CONSTANTS: gcf_vcls3300 TYPE bklas VALUE '3300'.
CONSTANTS: gcf_vcls7920 TYPE bklas VALUE '7920'. "MOD001
CONSTANTS: gcf_vcls7910 TYPE bklas VALUE '7910'. "MOD001
CONSTANTS: gcf_vcls7900 TYPE bklas VALUE '7900'. "MOD002
CONSTANTS: gcf_vcls3050 TYPE bklas VALUE '3050'. "MOD001
CONSTANTS: gcf_vcls3000 TYPE bklas 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-bwkey.
RANGES: gr_prmry_plnt FOR mbew-bwkey.
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-bwkey.
RANGES: gr_vcplnt_nondpy FOR mbew-bwkey.
RANGES: gr_lvorm FOR mara-lvorm.
*----------------------------------------------------------------------*
* Selection Screen *
*----------------------------------------------------------------------*
* Selection Criteria
SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME TITLE text-001.
SELECT-OPTIONS: s_bukrs FOR t001-bukrs OBLIGATORY.
SELECT-OPTIONS: s_spart FOR mara-spart.
SELECT-OPTIONS: s_bwkey FOR mbew-bwkey.
SELECT-OPTIONS: s_matnr FOR mara-matnr.
SELECT-OPTIONS: s_bklas FOR mbew-bklas.
SELECT-OPTIONS: s_mmsta FOR marc-mmsta. "MOD004
SELECTION-SCREEN END OF BLOCK blk1.
* Report Options
SELECTION-SCREEN BEGIN OF BLOCK blk2 WITH FRAME TITLE text-002.
PARAMETERS: p_incon AS CHECKBOX DEFAULT 'X'.
PARAMETERS: p_vlcls AS CHECKBOX DEFAULT 'X'.
SELECTION-SCREEN BEGIN OF BLOCK blk3 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 blk3.
PARAMETERS: p_lvorm AS CHECKBOX.
SELECTION-SCREEN END OF BLOCK blk2.
* ALV Variant
SELECTION-SCREEN BEGIN OF BLOCK blk4 WITH FRAME TITLE text-003.
PARAMETERS: p_varian LIKE disvariant-variant.
SELECTION-SCREEN END OF BLOCK blk4.
*----------------------------------------------------------------------*
* 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_bukrs.
PERFORM authority_check.
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 check_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 check.
*-- 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 check.
*-- 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 bukrs bwkey FROM t001k
INTO TABLE gdt_org
WHERE bukrs IN s_bukrs
AND bwkey IN s_bwkey.
* DELETE gdt_org WHERE NOT bwkey 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~bwkey
mbew~stprs
mbew~peinh
mbew~bklas
mbew~laepr
mbew~lbkum
mbew~hrkft
mbew~ekalr
mbew~hkmat
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~bwkey = gdt_org-bwkey
AND mbew~bklas IN s_bklas.
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 bwkey.
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 Stock',
* '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_key
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-key = ldf_key.
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-key = text-h02.
IF NOT s_bukrs[] IS INITIAL.
LOOP AT s_bukrs.
IF sy-tabix > 1.
CLEAR gds_listheader-key.
ENDIF.
IF NOT s_bukrs-high IS INITIAL.
CONCATENATE s_bukrs-low s_bukrs-high INTO gds_listheader-info
SEPARATED BY ' - '.
ELSE.
gds_listheader-info = s_bukrs-low.
ENDIF.
APPEND gds_listheader TO gdt_listheader.
ENDLOOP.
ENDIF.
* Sub heading - Division
CLEAR gds_listheader.
gds_listheader-typ = gcf_s.
gds_listheader-key = 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-key.
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-key = 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 bwkey spart matnr.
gdf_repid = sy-repid.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = gdf_repid
i_callback_pf_status_set = gcf_alv_pfs
i_callback_top_of_page = gcf_alv_top
i_callback_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_check
*&---------------------------------------------------------------------*
* Check Authorization for Company Code
*----------------------------------------------------------------------*
FORM authority_check.
DATA: ldf_bukrs LIKE t001-bukrs,
ldf_actvt03 TYPE activ_auth VALUE '03'.
SELECT bukrs INTO ldf_bukrs
FROM t001
WHERE bukrs IN s_bukrs.
AUTHORITY-CHECK OBJECT 'F_KNA1_BUK'
ID 'BUKRS' FIELD ldf_bukrs
ID 'ACTVT' FIELD ldf_actvt03.
IF sy-subrc <> 0.
SET CURSOR FIELD 'S_BUKRS-LOW'.
MESSAGE e460(f5) WITH ldf_bukrs.
ENDIF.
ENDSELECT.
IF sy-subrc NE 0.
SET CURSOR FIELD 'S_BUKRS-LOW'.
MESSAGE e165(f5) WITH s_bukrs-low.
ENDIF.
ENDFORM. " authority_check
*&---------------------------------------------------------------------*
*& 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-bwkey = gdt_mat_all-bwkey.
gdt_rept-stprs = gdt_mat_all-stprs.
gdt_rept-peinh = gdt_mat_all-peinh.
gdt_rept-bklas = gdt_mat_all-bklas.
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 bwkey = gdt_rept-bwkey
BINARY SEARCH.
IF sy-subrc = 0.
gdt_rept-bukrs = gdt_org-bukrs.
MODIFY gdt_rept TRANSPORTING bukrs WHERE bwkey =
gdt_mat_all-bwkey. " commented by parag
ENDIF.
CASE gdt_rept-bukrs.
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-maktx.
CLEAR gdt_matdesc.
READ TABLE gdt_matdesc WITH KEY
matnr = gdt_rept-matnr
BINARY SEARCH.
IF sy-subrc = 0.
gdt_rept-maktx = gdt_matdesc-maktx.
ELSE.
SELECT SINGLE matnr maktx FROM makt INTO gdt_matdesc
WHERE matnr = gdt_rept-matnr
AND spras = sy-langu.
IF sy-subrc = 0.
gdt_rept-maktx = gdt_matdesc-maktx.
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 werks = gdt_rept-bwkey.
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 Mitek
WHEN '1' OR '2' OR '3'.
READ TABLE gdt_primary WITH KEY
matnr = gdt_rept-matnr
bwkey = 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
bwkey = gcf_prmplnt40
BINARY SEARCH.
ELSE. "DePuy (including IAU)
READ TABLE gdt_primary WITH KEY
matnr = gdt_rept-matnr
bwkey = 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
bwkey = 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
bwkey = 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-bwkey.
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 Mitek
WHEN '1' OR '2' OR '3'.
READ TABLE gdt_primary WITH KEY
matnr = gdt_rept-matnr
bwkey = 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
bwkey = gcf_prmplnt85
BINARY SEARCH.
ELSE. "DePuy (including IAU)
READ TABLE gdt_primary WITH KEY
matnr = gdt_rept-matnr
bwkey = 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
bwkey = 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
bwkey = 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-bwkey.
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 check.
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 click
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 check_company_code_entered
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM check_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_bukrs.
CHECK s_bukrs-sign = 'I'.
IF s_bukrs-option = 'EQ'.
IF gcf_jjmau = s_bukrs-low.
gdf_cocde_au = gcf_x.
EXIT.
ENDIF.
ELSEIF s_bukrs-option = 'BT'.
IF gcf_jjmau IN s_bukrs.
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_bukrs.
CHECK s_bukrs-sign = 'I'.
IF s_bukrs-option = 'EQ'.
IF gcf_jjmnz = s_bukrs-low.
gdf_cocde_nz = gcf_x.
EXIT.
ENDIF.
ELSEIF s_bukrs-option = 'BT'.
IF gcf_jjmnz IN s_bukrs.
gdf_cocde_nz = gcf_x.
EXIT.
ENDIF.
ENDIF.
ENDLOOP.
ENDFORM. " check_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-bklas = 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-bklas = gcf_vcls7910 OR gdt_rept-bklas = 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-bklas = gcf_vcls3050.
* material type VERP (packaging) 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-bklas = 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-bklas = 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-bwkey IN gr_vcplnt_depuy AND "MOD002
gdt_rept-bklas <> 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-bwkey IN gr_vcplnt_nondpy AND "MOD002
gdt_rept-bklas = 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-bwkey IN gr_vcplnt_nondpy AND "MOD002
gdt_rept-bklas <> 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-bwkey IN gr_vcplnt_depuy AND "MOD002
gdt_rept-bklas <> 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-bwkey = 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_bwkey[] 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 bwkey 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~bwkey
mbew~stprs
mbew~peinh
mbew~bklas
mbew~laepr
mbew~lbkum
mbew~hrkft
mbew~ekalr
mbew~hkmat
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~bwkey IN gr_prmry_plnt
AND mbew~bklas IN s_bklas.
ENDIF.
SORT gdt_primary BY matnr bwkey.
ENDFORM. " select_primary_plant_data "MOD003
No comments:
Post a Comment