This Program helps to understand the Material Requirement Planning for Maintenance Plan between two dates. *Selection Screen *Report Output
REPORT zpmcipr0005
NO STANDARD PAGE HEADING LINE-SIZE 255.
TYPE-POOLS: truxs,slis.
************************************************************************
* Table Declaration *
************************************************************************
TABLES: mpla,mpos.
************************************************************************
* Struture Declaration *
************************************************************************
TYPES: BEGIN OF ty_vimpla,
warpl LIKE mpla-warpl, "Maintenance Plan
strat LIKE mpla-strat, "Maintenance strategy
equnr LIKE mpla-equnr, "Equipment Number
tplnr LIKE mpla-tplnr, "Functional Location
abnum LIKE mpla-abnum, "Maintenance Plan Call Number
objnr LIKE mpla-objnr, "Object number
mptyp LIKE mpla-mptyp, "Maintenance plan category
plan_sort LIKE mpla-plan_sort, "Sort field for maintenance plans
wapos LIKE mpos-wapos, "Maintenance item
plnty LIKE mpos-plnty, "Task List Type
plnnr LIKE mpos-plnnr, "Key for Task List Group
plnal LIKE mpos-plnal, "Group Counter
wpgrp LIKE mpos-wpgrp, "Planner Group
iwerk LIKE mpos-iwerk, "Maintenance Planning Plant
inact LIKE mpos-inact, "indicator that maintenance item
"is inactive
std_avo LIKE mpos-std_avo, "Number of the task list node
mityp LIKE mpos-mityp, "Maintenance item category
apfkt LIKE mpos-apfkt, "Execution Factor
END OF ty_vimpla.
TYPES: BEGIN OF ty_mhis,
warpl LIKE mhis-warpl,
abnum LIKE mhis-abnum,
zaehl LIKE mhis-zaehl,
nplda LIKE mhis-nplda,
tsenm LIKE mhis-tsenm,
tstat LIKE mhis-tstat,
END OF ty_mhis.
TYPES: BEGIN OF ty_mhis1,
warpl LIKE mpla-warpl, "Maintenance Plan
zaehl LIKE mhis-zaehl,
count TYPE i,
END OF ty_mhis1.
TYPES: BEGIN OF ty_plmz,
plnty LIKE plmz-plnty,
plnnr LIKE plmz-plnnr,
zuonr LIKE plmz-zuonr,
zaehl LIKE plmz-zaehl,
loekz LIKE plmz-loekz,
plnal LIKE plmz-plnal,
plnkn LIKE plmz-plnkn,
stlty LIKE plmz-stlty,
stlnr LIKE plmz-stlnr,
stlal LIKE plmz-stlal,
stlkn LIKE plmz-stlkn,
imeng LIKE plmz-imeng,
imein LIKE plmz-imein,
stpoz LIKE stpo-stpoz,
idnrk LIKE stpo-idnrk,
END OF ty_plmz.
TYPES: BEGIN OF ty_plwp,
plnty LIKE plwp-plnty,
plnnr LIKE plwp-plnnr,
plnal LIKE plwp-plnal,
plnfl LIKE plwp-plnfl,
plnkn LIKE plwp-plnkn,
paket LIKE plwp-paket,
zaehl LIKE plwp-zaehl,
strat LIKE plwp-strat,
vornr LIKE plpo-vornr,
arbid LIKE plpo-arbid,
aufkt LIKE plpo-aufkt,
END OF ty_plwp.
TYPES: BEGIN OF ty_t006a,
spras LIKE t006a-spras,
msehi LIKE t006a-msehi,
msehl LIKE t006a-msehl,
END OF ty_t006a.
TYPES: BEGIN OF ty_output,
warpl LIKE mpla-warpl, "Maintenance Plan
wapos LIKE mpos-wapos, "Maintenance item
plnty LIKE mpos-plnty, "Task List Type
plnnr LIKE mpos-plnnr, "Key for Task List Group
plnal LIKE mpos-plnal, "Group Counter
wpgrp LIKE mpos-wpgrp, "Planner Group
equnr LIKE mpla-equnr, "Equipment Number
tplnr LIKE mpla-tplnr, "Functional Location
matnr LIKE mara-matnr, "Material
maktx LIKE makt-maktx, "Material Description
mityp LIKE mpos-mityp, "Maintenance item category
imeng LIKE plmz-imeng, "Quantity
imein LIKE t006a-msehl, "UOM
nplda LIKE mhis-nplda, "Next due date
paket LIKE plwp-paket, "Package
END OF ty_output.
************************************************************************
* Intrnal Table Declaration *
************************************************************************
DATA: it_vimpla TYPE STANDARD TABLE OF ty_vimpla,
it_mhis TYPE STANDARD TABLE OF ty_mhis,
it_mhis1 TYPE STANDARD TABLE OF ty_mhis1,
it_mhis2 TYPE STANDARD TABLE OF ty_mhis,
it_plwp TYPE STANDARD TABLE OF ty_plwp,
it_plmz TYPE STANDARD TABLE OF ty_plmz,
it_makt TYPE STANDARD TABLE OF makt,
it_t006a TYPE STANDARD TABLE OF ty_t006a,
it_jest TYPE STANDARD TABLE OF jest,
it_output TYPE STANDARD TABLE OF ty_output,
it_fieldcatalog TYPE slis_t_fieldcat_alv WITH HEADER LINE.
************************************************************************
* Intrnal Table Declaration *
************************************************************************
DATA: wa_vimpla TYPE ty_vimpla,
wa_mhis TYPE ty_mhis,
wa_mhis1 TYPE ty_mhis1,
wa_mhis2 TYPE ty_mhis,
wa_plwp TYPE ty_plwp,
wa_plmz TYPE ty_plmz,
wa_makt TYPE makt,
wa_t006a TYPE ty_t006a,
wa_jest TYPE jest,
wa_output TYPE ty_output.
************************************************************************
* Data Declaration *
************************************************************************
DATA: ls_layout TYPE slis_layout_alv.
************************************************************************
* Constants Declaration *
************************************************************************
CONSTANTS: c_a TYPE c VALUE 'A'.
************************************************************************
* Selection Screen *
************************************************************************
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.
SELECT-OPTIONS: s_warpl FOR mpla-warpl,
s_strat FOR mpla-strat,
s_mptyp FOR mpla-mptyp,
s_psort FOR mpla-plan_sort,
s_wpgrp FOR mpos-wpgrp,
s_iwerk FOR mpos-iwerk OBLIGATORY,
s_period FOR sy-datum OBLIGATORY NO-EXTENSION.
SELECTION-SCREEN END OF BLOCK b1.
************************************************************************
* At Selection Screen *
************************************************************************
AT SELECTION-SCREEN ON BLOCK b1.
PERFORM screen_field_check.
************************************************************************
* Initialization *
************************************************************************
INITIALIZATION.
************************************************************************
* Start of Selection *
************************************************************************
START-OF-SELECTION.
PERFORM get_data.
PERFORM build_output.
PERFORM build_fieldcatalog.
************************************************************************
* End of Selection *
************************************************************************
END-OF-SELECTION.
IF it_output IS NOT INITIAL.
PERFORM display_output.
ELSE.
MESSAGE 'No data found' TYPE 'I'.
ENDIF.
*&---------------------------------------------------------------------*
*& Form SCREEN_FIELD_CHECK
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM screen_field_check .
DATA: l_warpl TYPE warpl,
l_wpgrp TYPE wpgrp,
l_psort TYPE plan_sort,
l_mptyp TYPE mptyp,
l_strat TYPE strat,
l_iwerk TYPE iwerk.
TYPES: BEGIN OF ty_iwerk,
iwerk TYPE iwerk,
END OF ty_iwerk.
DATA: it_iwerk TYPE STANDARD TABLE OF ty_iwerk,
wa_iwerk TYPE ty_iwerk.
LOOP AT s_warpl.
SELECT SINGLE warpl INTO l_warpl
FROM mpos
WHERE warpl = s_warpl-low
AND wpgrp IN s_wpgrp.
IF sy-subrc <> 0.
MESSAGE e004(zpm_clpi) WITH s_warpl-low.
ENDIF.
ENDLOOP.
IF s_warpl-high IS NOT INITIAL.
LOOP AT s_warpl.
SELECT SINGLE warpl INTO l_warpl
FROM mpos
WHERE warpl = s_warpl-high
AND wpgrp IN s_wpgrp.
IF sy-subrc <> 0.
MESSAGE e004(zpm_clpi) WITH s_warpl-high.
ENDIF.
ENDLOOP.
ENDIF.
*Validate Planner Group
LOOP AT s_wpgrp.
SELECT SINGLE ingrp INTO l_wpgrp
FROM t024i
WHERE ingrp = s_wpgrp-low
AND iwerk IN s_iwerk.
IF sy-subrc <> 0.
MESSAGE e005(zpm_clpi) WITH s_wpgrp-low.
ENDIF.
ENDLOOP.
IF s_wpgrp-high IS NOT INITIAL.
LOOP AT s_wpgrp.
SELECT SINGLE ingrp INTO l_wpgrp
FROM t024i
WHERE ingrp = s_wpgrp-high
AND iwerk IN s_iwerk.
IF sy-subrc <> 0.
MESSAGE e005(zpm_clpi) WITH s_wpgrp-high.
ENDIF.
ENDLOOP.
ENDIF.
*Validate Maintenance Plan Sort
TYPES: BEGIN OF ty_psort,
plan_sort LIKE t399g-plan_sort,
END OF ty_psort.
DATA: it_psort TYPE STANDARD TABLE OF ty_psort,
wa_psort TYPE ty_psort.
IF s_psort CA '*'.
SELECT plan_sort INTO TABLE it_psort
FROM t399g
WHERE plan_sort IN s_psort.
IF sy-subrc EQ 0.
REFRESH s_psort.
LOOP AT it_psort INTO wa_psort.
s_psort-sign = 'I'.
s_psort-option = 'CP'.
s_psort-low = wa_psort-plan_sort.
APPEND s_psort.
CLEAR wa_psort.
ENDLOOP.
ELSE .
MESSAGE e006(zpm_clpi) WITH s_psort-low.
ENDIF.
ELSE.
LOOP AT s_psort.
SELECT SINGLE plan_sort INTO l_psort
FROM t399g
WHERE plan_sort = s_psort-low.
IF sy-subrc <> 0.
MESSAGE e006(zpm_clpi) WITH s_psort-low.
ENDIF.
ENDLOOP.
IF s_psort-high IS NOT INITIAL.
LOOP AT s_psort.
SELECT SINGLE plan_sort INTO l_psort
FROM t399g
WHERE plan_sort = s_psort-high.
IF sy-subrc <> 0.
MESSAGE e006(zpm_clpi) WITH s_psort-high.
ENDIF.
ENDLOOP.
ENDIF.
ENDIF.
*Validate Maintenance Plan Category field
TYPES: BEGIN OF ty_mptyp,
mptyp LIKE t399w-mptyp,
END OF ty_mptyp.
DATA: it_mptyp TYPE STANDARD TABLE OF ty_mptyp,
wa_mptyp TYPE ty_mptyp.
IF s_mptyp CA '*'.
SELECT mptyp INTO TABLE it_mptyp
FROM t399w
WHERE mptyp IN s_mptyp.
IF sy-subrc EQ 0.
REFRESH s_mptyp.
LOOP AT it_mptyp INTO wa_mptyp.
s_mptyp-sign = 'I'.
s_mptyp-option = 'CP'.
s_mptyp-low = wa_mptyp-mptyp.
APPEND s_mptyp.
CLEAR wa_mptyp.
ENDLOOP.
ELSE.
MESSAGE e007(zpm_clpi) WITH s_mptyp-low.
ENDIF.
ENDIF.
LOOP AT s_mptyp.
SELECT SINGLE mptyp INTO l_mptyp
FROM t399w
WHERE mptyp = s_mptyp-low.
IF sy-subrc <> 0.
MESSAGE e007(zpm_clpi) WITH s_mptyp-low.
ENDIF.
ENDLOOP.
IF s_mptyp-high IS NOT INITIAL.
LOOP AT s_mptyp.
SELECT SINGLE mptyp INTO l_mptyp
FROM t399w
WHERE mptyp = s_mptyp-high.
IF sy-subrc <> 0.
MESSAGE e007(zpm_clpi) WITH s_mptyp-high.
ENDIF.
ENDLOOP.
ENDIF.
*Validate Maintenance Plan Strategy field
LOOP AT s_strat.
SELECT SINGLE strat INTO l_strat
FROM t351
WHERE strat = s_strat-low.
IF sy-subrc <> 0.
MESSAGE e008(zpm_clpi) WITH s_strat-low.
ENDIF.
ENDLOOP.
IF s_strat-high IS NOT INITIAL.
LOOP AT s_strat.
SELECT SINGLE strat INTO l_strat
FROM t351
WHERE strat = s_strat-high.
IF sy-subrc <> 0.
MESSAGE e008(zpm_clpi) WITH s_strat-high.
ENDIF.
ENDLOOP.
ENDIF.
* Validate Plant
IF s_iwerk-low IS NOT INITIAL AND
s_iwerk-high IS NOT INITIAL.
SELECT iwerk FROM t399i INTO TABLE it_iwerk
WHERE iwerk IN s_iwerk.
IF sy-subrc EQ 0.
LOOP AT it_iwerk INTO wa_iwerk.
AUTHORITY-CHECK OBJECT 'I_IWERK'
ID 'TCD' FIELD 'ZPMCI10'
ID 'IWERK' FIELD wa_iwerk-iwerk.
IF sy-subrc <> 0.
MESSAGE e011(zpm_clpi) WITH wa_iwerk-iwerk.
ENDIF.
ENDLOOP.
ENDIF.
ELSEIF s_iwerk-low IS NOT INITIAL.
LOOP AT s_iwerk.
SELECT SINGLE iwerk INTO l_iwerk
FROM t399i
WHERE iwerk = s_iwerk-low.
IF sy-subrc <> 0.
MESSAGE e009(zpm_clpi) WITH s_iwerk-low.
ELSE.
AUTHORITY-CHECK OBJECT 'I_IWERK'
ID 'TCD' FIELD 'ZPMCI10'
ID 'IWERK' FIELD s_iwerk-low.
IF sy-subrc <> 0.
MESSAGE e011(zpm_clpi) WITH s_iwerk-low.
ENDIF.
ENDIF.
CLEAR l_iwerk.
ENDLOOP.
IF s_iwerk-high IS NOT INITIAL.
LOOP AT s_iwerk.
SELECT SINGLE iwerk INTO l_iwerk
FROM t399i
WHERE iwerk = s_iwerk-high.
IF sy-subrc <> 0.
MESSAGE e009(zpm_clpi) WITH s_iwerk-high.
ELSE.
AUTHORITY-CHECK OBJECT 'I_IWERK'
ID 'TCD' FIELD 'ZPMCI10'
ID 'IWERK' FIELD s_iwerk-high.
IF sy-subrc <> 0.
MESSAGE e011(zpm_clpi) WITH s_iwerk-high.
ENDIF.
ENDIF.
CLEAR l_iwerk.
ENDLOOP.
ENDIF.
ENDIF.
*Check Period as it should be in future
IF s_period-low < sy-datum.
MESSAGE e010(zpm_clpi) WITH s_period-low.
ENDIF.
ENDFORM. " SCREEN_FIELD_CHECK
*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM get_data .
DATA: l_warpl TYPE warpl,
l_zaehl TYPE paketzaehl,
l_count_zaehl TYPE i.
*Get Maintenance plan data from View VIMPLA
SELECT warpl
strat
equnr
tplnr
abnum
objnr
mptyp
plan_sort
wapos
plnty
plnnr
plnal
wpgrp
iwerk
inact
std_avo
mityp
apfkt
INTO TABLE it_vimpla
FROM vimpla
WHERE warpl IN s_warpl
AND strat IN s_strat
AND mptyp IN s_mptyp
AND plan_sort IN s_psort
AND wpgrp IN s_wpgrp
AND iwerk IN s_iwerk
AND plnty EQ 'A'
AND inact EQ space.
IF sy-subrc EQ 0.
SORT it_vimpla BY warpl wapos .
SELECT * FROM jest INTO TABLE it_jest
FOR ALL ENTRIES IN it_vimpla
WHERE objnr = it_vimpla-objnr.
*For Checking packages SELECT data from MHIS table
SELECT warpl
abnum
zaehl
nplda
tsenm
tstat
FROM mhis AS h
INTO TABLE it_mhis
FOR ALL ENTRIES IN it_vimpla
WHERE warpl = it_vimpla-warpl
AND nplda IN s_period
* AND TSABR = 'X'
* AND tsenq = 'X'
* AND tsvbt = 'X'
AND tsenm = space
AND tstat <> 'X'.
SORT it_mhis BY warpl zaehl.
*Applying loop on MHIS data to count the package and repition of the package.
LOOP AT it_mhis INTO wa_mhis.
IF l_warpl IS INITIAL.
l_warpl = wa_mhis-warpl.
ENDIF.
IF wa_mhis-warpl = l_warpl.
IF l_zaehl IS INITIAL.
l_zaehl = wa_mhis-zaehl.
ENDIF.
IF wa_mhis-zaehl = l_zaehl.
l_count_zaehl = l_count_zaehl + 1.
wa_mhis1-warpl = wa_mhis-warpl.
wa_mhis1-zaehl = wa_mhis-zaehl.
ELSE.
wa_mhis1-count = l_count_zaehl.
APPEND wa_mhis1 TO it_mhis1.
CLEAR wa_mhis1.
l_zaehl = wa_mhis-zaehl.
l_count_zaehl = 1.
wa_mhis1-warpl = wa_mhis-warpl.
wa_mhis1-zaehl = wa_mhis-zaehl.
ENDIF.
ELSE.
wa_mhis1-count = l_count_zaehl.
APPEND wa_mhis1 TO it_mhis1.
CLEAR wa_mhis1.
CLEAR: l_warpl,l_zaehl.
l_warpl = wa_mhis-warpl.
l_zaehl = wa_mhis-zaehl.
l_count_zaehl = 1.
wa_mhis1-warpl = wa_mhis-warpl.
wa_mhis1-zaehl = wa_mhis-zaehl.
ENDIF.
ENDLOOP.
IF wa_mhis-warpl IS NOT INITIAL.
wa_mhis1-warpl = wa_mhis-warpl.
wa_mhis1-zaehl = wa_mhis-zaehl.
wa_mhis1-count = l_count_zaehl.
APPEND wa_mhis1 TO it_mhis1.
ENDIF.
CLEAR: l_warpl,l_zaehl,l_count_zaehl.
*Get the No of operations from table PLMZ
SELECT p~plnty
p~plnnr
p~zuonr
p~zaehl
p~loekz
p~plnal
p~plnkn
p~stlty
p~stlnr
p~stlal
p~stlkn
p~imeng
p~imein
s~stpoz
s~idnrk
INTO TABLE it_plmz
FROM plmz AS p
INNER JOIN stpo AS s ON p~stlty = s~stlty
AND p~stlnr = s~stlnr
AND p~stlkn = s~stlkn
FOR ALL ENTRIES IN it_vimpla
WHERE p~plnty = it_vimpla-plnty
AND p~plnnr = it_vimpla-plnnr
AND p~loekz = space
AND p~plnal = it_vimpla-plnal.
*Get the Package number & Operation number against Task list
SELECT p~plnty
p~plnnr
p~plnal
p~plnfl
p~plnkn
p~paket
p~zaehl
p~strat
o~vornr
o~arbid
o~aufkt
INTO TABLE it_plwp
FROM plwp AS p
INNER JOIN plpo AS o ON p~plnty = o~plnty
AND p~plnnr = o~plnnr
AND p~plnkn = o~plnkn
FOR ALL ENTRIES IN it_vimpla
WHERE p~plnty = it_vimpla-plnty
AND p~plnnr = it_vimpla-plnnr
AND p~plnal = it_vimpla-plnal
AND p~strat = it_vimpla-strat
AND p~loekz <> 'X'. "10-01-2011
*Get Material Description
SELECT * FROM makt
INTO TABLE it_makt
FOR ALL ENTRIES IN it_plmz
WHERE matnr = it_plmz-idnrk
AND spras = sy-langu.
SORT it_makt BY matnr.
*Get Quantity description
SELECT spras
msehi
msehl
INTO TABLE it_t006a
FROM t006a
FOR ALL ENTRIES IN it_plmz
WHERE spras = sy-langu
AND msehi = it_plmz-imein.
*Get Maintenance Plan History data for 'Next Due Date' and 'Package'
*irrespective of period on selection screen
SELECT warpl
abnum
zaehl
nplda
tsenm
tstat
FROM mhis AS h
INTO TABLE it_mhis2
FOR ALL ENTRIES IN it_vimpla
WHERE warpl = it_vimpla-warpl
AND tsenq = 'X'
AND tsvbt = 'X'.
*Sort this by planned date.
SORT it_mhis2 BY warpl nplda.
ENDIF.
ENDFORM. " GET_DATA
*&---------------------------------------------------------------------*
*& Form BUILD_OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM build_output .
IF it_vimpla IS NOT INITIAL.
LOOP AT it_vimpla INTO wa_vimpla.
*Check Inactive/Delete Flag
READ TABLE it_jest INTO wa_jest
WITH KEY objnr = wa_vimpla-objnr
stat = 'I0320'
inact = space.
IF sy-subrc EQ 0.
CONTINUE.
ENDIF.
READ TABLE it_jest INTO wa_jest
WITH KEY objnr = wa_vimpla-objnr
stat = 'I0076'
inact = space.
IF sy-subrc EQ 0.
CONTINUE.
ENDIF.
wa_output-warpl = wa_vimpla-warpl.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
input = wa_output-warpl
IMPORTING
output = wa_output-warpl.
*When Task List is not available
IF wa_vimpla-plnnr IS INITIAL.
CONTINUE.
ELSE.
wa_output-plnnr = wa_vimpla-plnnr.
ENDIF.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
input = wa_output-plnnr
IMPORTING
output = wa_output-plnnr.
wa_output-plnal = wa_vimpla-plnal.
wa_output-wapos = wa_vimpla-wapos.
wa_output-wpgrp = wa_vimpla-wpgrp.
wa_output-mityp = wa_vimpla-mityp.
wa_output-equnr = wa_vimpla-equnr.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
input = wa_output-equnr
IMPORTING
output = wa_output-equnr.
wa_output-tplnr = wa_vimpla-tplnr.
CALL FUNCTION 'CONVERSION_EXIT_TPLNR_OUTPUT'
EXPORTING
input = wa_output-tplnr
IMPORTING
output = wa_output-tplnr.
LOOP AT it_plwp INTO wa_plwp
WHERE plnty = wa_vimpla-plnty
AND plnnr = wa_vimpla-plnnr
AND plnal = wa_vimpla-plnal.
LOOP AT it_plmz INTO wa_plmz
WHERE plnty = wa_plwp-plnty
AND plnnr = wa_plwp-plnnr
AND plnal = wa_plwp-plnal
AND plnkn = wa_plwp-plnkn.
*Read frequecy(count) for the Package against the frequency
READ TABLE it_mhis1 INTO wa_mhis1
WITH KEY warpl = wa_vimpla-warpl
zaehl = wa_plwp-paket.
IF sy-subrc EQ 0.
wa_output-imeng = wa_output-imeng + ( wa_plmz-imeng * wa_mhis1-count ).
ELSE.
* wa_output-imeng = wa_output-imeng + wa_plmz-imeng.
CONTINUE.
ENDIF.
*Multiply Output Quantity with Operation Execution factor (PLPO-AUFKT)
IF wa_plwp-aufkt IS NOT INITIAL.
wa_output-imeng = wa_output-imeng * wa_plwp-aufkt.
ENDIF.
*Multiplt Output Quantity to Execution factor of whole Task List (MPOS-APFKT)
IF wa_vimpla-apfkt IS NOT INITIAL.
wa_output-imeng = wa_output-imeng * wa_vimpla-apfkt.
ENDIF.
*Material Number
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
input = wa_plmz-idnrk
IMPORTING
output = wa_output-matnr.
*Material Description
READ TABLE it_makt INTO wa_makt
WITH KEY matnr = wa_plmz-idnrk.
IF sy-subrc EQ 0.
wa_output-maktx = wa_makt-maktx.
ENDIF.
*Unit of measure
READ TABLE it_t006a INTO wa_t006a
WITH KEY spras = sy-langu
msehi = wa_plmz-imein.
IF sy-subrc EQ 0.
wa_output-imein = wa_t006a-msehl.
ELSE.
wa_output-imein = wa_plmz-imein.
ENDIF.
*Next Due Date
READ TABLE it_mhis2 INTO wa_mhis2
WITH KEY warpl = wa_vimpla-warpl.
wa_output-nplda = wa_mhis2-nplda.
*Package
wa_output-paket = wa_mhis2-zaehl.
*When No Material in Task List
IF wa_output-matnr IS INITIAL.
CLEAR: wa_output-matnr,wa_output-imeng,wa_plmz,wa_mhis1,
wa_mhis2.
CONTINUE.
ENDIF.
COLLECT wa_output INTO it_output.
CLEAR: wa_output-matnr,wa_output-imeng,wa_plmz,wa_mhis1,
wa_mhis2.
ENDLOOP.
CLEAR wa_plwp.
ENDLOOP.
IF sy-subrc <> 0.
*When No Task list/No Material in Task List
IF wa_output-matnr IS INITIAL.
CLEAR: wa_output,wa_plmz,wa_plwp,wa_mhis1,
wa_mhis2.
CONTINUE.
ENDIF.
COLLECT wa_output INTO it_output.
ENDIF.
CLEAR: wa_vimpla,wa_output.
ENDLOOP.
SORT it_output BY warpl wapos wpgrp plnnr plnal equnr matnr.
ENDIF.
ENDFORM. " BUILD_OUTPUT
*&---------------------------------------------------------------------*
*& Form BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM build_fieldcatalog .
it_fieldcatalog-fieldname = 'WARPL'.
it_fieldcatalog-seltext_l = 'Maintenance Plan'.
it_fieldcatalog-col_pos = 1.
APPEND it_fieldcatalog TO it_fieldcatalog.
CLEAR it_fieldcatalog.
it_fieldcatalog-fieldname = 'WAPOS'.
it_fieldcatalog-seltext_l = 'Maintenance item'.
it_fieldcatalog-col_pos = 2.
APPEND it_fieldcatalog TO it_fieldcatalog.
CLEAR it_fieldcatalog.
it_fieldcatalog-fieldname = 'WPGRP'.
it_fieldcatalog-seltext_l = 'Planner Group'.
it_fieldcatalog-col_pos = 3.
APPEND it_fieldcatalog TO it_fieldcatalog.
CLEAR it_fieldcatalog.
it_fieldcatalog-fieldname = 'PLNNR'.
it_fieldcatalog-seltext_l = 'Task List Group'.
it_fieldcatalog-col_pos = 4.
APPEND it_fieldcatalog TO it_fieldcatalog.
CLEAR it_fieldcatalog.
it_fieldcatalog-fieldname = 'PLNAL'.
it_fieldcatalog-seltext_l = 'Group Counter'.
it_fieldcatalog-col_pos = 5.
APPEND it_fieldcatalog TO it_fieldcatalog.
CLEAR it_fieldcatalog.
it_fieldcatalog-fieldname = 'EQUNR'.
it_fieldcatalog-seltext_l = 'Equipment'.
it_fieldcatalog-col_pos = 6.
APPEND it_fieldcatalog TO it_fieldcatalog.
CLEAR it_fieldcatalog.
it_fieldcatalog-fieldname = 'TPLNR'.
it_fieldcatalog-seltext_l = 'Functional Location'.
it_fieldcatalog-col_pos = 7.
APPEND it_fieldcatalog TO it_fieldcatalog.
CLEAR it_fieldcatalog.
it_fieldcatalog-fieldname = 'MATNR'.
it_fieldcatalog-seltext_l = 'Material No.'.
it_fieldcatalog-col_pos = 8.
APPEND it_fieldcatalog TO it_fieldcatalog.
CLEAR it_fieldcatalog.
it_fieldcatalog-fieldname = 'MAKTX'.
it_fieldcatalog-seltext_l = 'Material Description'.
it_fieldcatalog-col_pos = 9.
APPEND it_fieldcatalog TO it_fieldcatalog.
CLEAR it_fieldcatalog.
it_fieldcatalog-fieldname = 'MITYP'.
it_fieldcatalog-seltext_l = 'Maintenance item category'.
it_fieldcatalog-col_pos = 10.
APPEND it_fieldcatalog TO it_fieldcatalog.
CLEAR it_fieldcatalog.
it_fieldcatalog-fieldname = 'IMENG'.
it_fieldcatalog-seltext_l = 'Quantity'.
it_fieldcatalog-col_pos = 11.
APPEND it_fieldcatalog TO it_fieldcatalog.
CLEAR it_fieldcatalog.
it_fieldcatalog-fieldname = 'IMEIN'.
it_fieldcatalog-seltext_l = 'Unit of Measure'.
it_fieldcatalog-col_pos = 12.
APPEND it_fieldcatalog TO it_fieldcatalog.
CLEAR it_fieldcatalog.
it_fieldcatalog-fieldname = 'NPLDA'.
it_fieldcatalog-seltext_l = 'Next Due Date'.
it_fieldcatalog-col_pos = 13.
APPEND it_fieldcatalog TO it_fieldcatalog.
CLEAR it_fieldcatalog.
it_fieldcatalog-fieldname = 'PAKET'.
it_fieldcatalog-seltext_l = 'Package'.
it_fieldcatalog-col_pos = 14.
APPEND it_fieldcatalog TO it_fieldcatalog.
CLEAR it_fieldcatalog.
ENDFORM. " BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*& Form DISPLAY_OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM display_output .
ls_layout-colwidth_optimize = 'X'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
is_layout = ls_layout
i_callback_program = sy-repid
i_callback_top_of_page = 'TOP_OF_PAGE'
it_fieldcat = it_fieldcatalog[]
TABLES
t_outtab = it_output
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM. " DISPLAY_OUTPUT
*&---------------------------------------------------------------------*
*& Form TOP_OF_PAGE
*&---------------------------------------------------------------------*
FORM top_of_page.
*ALV Header declarations
DATA: t_header TYPE slis_t_listheader,
wa_header TYPE slis_listheader,
l_info TYPE slis_listheader-info,
l_from(10) TYPE c,
l_to(10) TYPE c.
wa_header-typ = 'H'.
wa_header-info = 'Material Requirement Planning for PM between Two Dates'.
APPEND wa_header TO t_header.
CLEAR wa_header.
CONCATENATE s_period-low+6(2) '-' s_period-low+4(2) '-' s_period-low+0(4)
INTO l_from.
CONCATENATE s_period-high+6(2) '-' s_period-high+4(2) '-' s_period-high+0(4)
INTO l_to.
CONCATENATE 'Period From:' l_from ' ' 'To:' l_to
INTO l_info SEPARATED BY space.
wa_header-typ = 'S'.
wa_header-info = l_info.
APPEND wa_header TO t_header.
CLEAR wa_header.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = t_header.
ENDFORM. "top_of_page
No comments:
Post a Comment