Tuesday, June 07, 2005

INCLUDE ZPP_UPLOAD_PROD_PLAN_INCLUDE

INCLUDE .
*----------------------------------------------------------------------*
***INCLUDE ZPP_UPLOAD_PROD_PLAN_INCLUDE .
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form UPLOAD_FILES
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM upload_files.
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
filename = fileplan
filetype = 'DAT'
TABLES
data_tab = pplan
EXCEPTIONS
conversion_error = 1
file_open_error = 2
file_read_error = 3
invalid_type = 4
no_batch = 5
unknown_error = 6
invalid_table_width = 7
gui_refuse_filetransfer = 8
customer_error = 9
OTHERS = 10.
IF sy-subrc NE 0.
WRITE:/ icon_message_error AS ICON,fileplan ,' açarken hata.'.
EXIT.
ENDIF.
ENDFORM. " UPLOAD_FILES

*&---------------------------------------------------------------------*
*& Form CHECK_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM check_data.

LOOP AT pplan.
CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
EXPORTING
input = pplan-matnr
IMPORTING
output = pplan-matnr
* EXCEPTIONS
* LENGTH_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.
MODIFY pplan.
ENDLOOP.


LOOP AT pplan.
CHECK sy-tabix > 1.
CLEAR : marc.
SELECT SINGLE * FROM marc WHERE matnr = pplan-matnr
AND werks = pplan-werks.
IF sy-subrc >< 0.
err = 'X'.
WRITE:/ pplan-matnr, pplan-werks, 'mevcut değil'.
ENDIF.
IF marc-pstat CA 'D'.
ELSE.
err = 'X'.
WRITE:/ pplan-matnr, pplan-werks, 'MİP Ekranı yok'.
ENDIF.

CLEAR: i_stb.
REFRESH: i_stb.

CALL FUNCTION 'CS_BOM_EXPL_MAT_V2'
EXPORTING
ftrel = ' '
altvo = ' '
aufsw = ' '
aumgb = ' '
aumng = 0
auskz = ' '
amind = ' '
bagrp = ' '
beikz = ' '
bessl = ' '
bgixo = ' '
brems = ' '
capid = 'PP01'
cospr = ' '
cuobj = 0
cuols = ' '
datuv = sy-datum
delnl = ' '
ehndl = ' '
emeng = 0
erskz = ' '
erssl = ' '
fbstp = ' '
knfba = ' '
ksbvo = ' '
mbwls = ' '
mktls = 'X'
mdmps = ' '
mehrs = 'X'
mkmat = ' '
mmaps = ' '
salww = ' '
splww = ' '
mmory = ' '
mtnrv = pplan-matnr
postp = ' '
rndkz = ' '
rvrel = ' '
sanfr = ' '
sanin = ' '
sanka = ' '
sanko = ' '
sanvs = ' '
schgt = ' '
stkkz = ' '
stlal = '01'
stlan = ' '
werks = pplan-werks
norvl = ' '
mdnot = ' '
panot = ' '
verid = ' '
* IMPORTING
* TOPMAT =
* DSTST =
TABLES
stb = i_stb
* MATCAT =
EXCEPTIONS
alt_not_found = 1
call_invalid = 2
material_not_found = 3
missing_authorization = 4
no_bom_found = 5
no_plant_data = 6
no_suitable_bom_found = 7
conversion_error = 8
OTHERS = 9.

IF sy-subrc EQ 0.

LOOP AT i_stb.
CLEAR : marc.
SELECT SINGLE * FROM marc WHERE matnr = i_stb-idnrk
AND werks = i_stb-werks.
IF marc-pstat CA 'D'.
ELSE.
err = 'X'.
WRITE:/ '_________________', pplan-matnr, pplan-werks,
i_stb-idnrk, 'MİP Ekranı yok'.
ENDIF.

ENDLOOP.
ENDIF.



ENDLOOP.



ENDFORM. " CHECK_DATA
*&---------------------------------------------------------------------*
*& Form CREATE_PPLAN
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM create_pplan.
PERFORM popup_to_inform.
********** production plan *************
LOOP AT pplan WHERE werks NE space.
IF sy-tabix = 1. "başlık bilgilerini oku
MOVE-CORRESPONDING pplan TO tplan.
ELSE.
PERFORM create_pplan_item_new.
ENDIF.
ENDLOOP.

DATA: e_message LIKE msglog-txt .
e_message = 'ÜY alanı boş' .
LOOP AT pplan WHERE werks EQ space.
PERFORM add_log USING pplan-matnr e_message.
ENDLOOP.
ENDFORM. " CREATE_PPLAN
*&---------------------------------------------------------------------*
*& Form CREATE_PPLAN_ITEM
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM create_pplan_item.
DATA: amount LIKE x60et-plnmg.
DATA: beg_day LIKE x60et-edatu.
DATA: pweek LIKE scal-week.
REFRESH x60bl.
REFRESH x60et.
PERFORM create_item_header.
g_pos = 1.
DO VARYING amount FROM pplan-f1 NEXT pplan-f2.
MOVE amount TO x60et-plnmg.
IF amount(1) EQ space. "miktarsızları es geç
CONTINUE.
ENDIF.
* pweek = beg_week + g_pos - 1. "locate week

IF sy-index LE pnweek.
PERFORM hafta_hesapla USING beg_week sy-index CHANGING pweek.
* move 'W' to x60et-entlu.
MOVE 'T' TO x60et-entlu. "daily requirement
CALL FUNCTION 'WEEK_GET_FIRST_DAY'
EXPORTING
week = pweek
IMPORTING
date = x60et-edatu
EXCEPTIONS
week_invalid = 1
OTHERS = 2.

IF sy-subrc EQ 0.
* OD 15/04 haftanın 2.günü olacak PZTESI --> ÇARŞAMBA
ADD 2 TO x60et-edatu.
APPEND x60et.
ELSE.
WRITE:/ icon_message_error AS ICON, ' date convertion'.
ENDIF.
ELSE.
IF sy-index LE 27.
PERFORM ay_hesapla USING sy-index CHANGING x60et-edatu.
MOVE 'M' TO x60et-entlu. "KALAN AYLAR İÇİN GİRİŞLER
APPEND x60et.
ELSE.
EXIT.
ENDIF.
ENDIF.
g_pos = g_pos + 1.
ENDDO.

CALL FUNCTION 'REQUIREMENTS_CREATE'
EXPORTING
e60bl = x60bl
" EPRASTA = ' '
" EDELET = 'X'
" ELANGU = 'D'
" MSG_LOG = ' '
TABLES
e60et = x60et
proto = proto
EXCEPTIONS
requirement_not_found = 01
calendar_id_missing = 02
calendar_not_found = 03
date_after_range = 04
date_before_range = 05
date_invalid = 06
date_option_invalid = 07
t009b_not_found = 08
no_data = 09
period_invalid = 10.
IF sy-subrc NE 0.
CASE sy-subrc.
WHEN 1.
PERFORM add_log USING pplan-matnr ', requirement_not_found'.
WHEN 2.
PERFORM add_log USING pplan-matnr ', calendar_id_missing'.
WHEN 3.
PERFORM add_log USING pplan-matnr ', calendar_not_found'.
WHEN 4.
PERFORM add_log USING pplan-matnr ', date_after_range'.
WHEN 5.
PERFORM add_log USING pplan-matnr ', date_before_range'.
WHEN 6.
PERFORM add_log USING pplan-matnr ', date_invalid'.
WHEN 7.
PERFORM add_log USING pplan-matnr ', date_option_invalid'.
WHEN 8.
PERFORM add_log USING pplan-matnr ', t009b_not_found'.
WHEN 9.
PERFORM add_log USING pplan-matnr ', no_data'.
WHEN 10.
PERFORM add_log USING pplan-matnr ' period_invalid'.
ENDCASE.
ENDIF.
ENDFORM. " CREATE_PPLAN_ITEM
*&---------------------------------------------------------------------*
*& Form REPORT_ERRORS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM report_errors.

if err is initial and msglog[] is initial.
write:/ ICON_ACTION_SUCCESS AS ICON, 'Program başarıyla çalıştı'.
else.
write:/ icon_message_error AS ICON, 'Hatalar Oluştu'.
endif.

LOOP AT msglog.
WRITE:/ msglog-matnr, msglog-txt.
ENDLOOP.

ENDFORM. " REPORT_ERRORS

*&---------------------------------------------------------------------*
*& Form ADD_LOG
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_PPLAN_MATNR text *
* -->P_0241 text *
*----------------------------------------------------------------------*
FORM add_log USING p_pplan_matnr
value(p_0241).
msglog-matnr = p_pplan_matnr.
msglog-txt = p_0241.
APPEND msglog.
ENDFORM. " ADD_LOG
*&---------------------------------------------------------------------*
*& Form HAFTA_HESAPLA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_BEG_WEEK text *
* -->P_G_POS text *
* <--P_PWEEK text *
*----------------------------------------------------------------------*
FORM hafta_hesapla USING p_beg_week
p_g_pos
CHANGING p_pweek.
DATA: yr(4),wk(2),tmp(7),mt(2).

PERFORM getdate USING p_g_pos CHANGING tmp.
yr = tmp+3(4). mt = tmp(2).
CONCATENATE yr mt INTO p_pweek.
ENDFORM. " HAFTA_HESAPLA
*&---------------------------------------------------------------------*
*& Form CREATE_ITEM_HEADER
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM create_item_header.
DATA: l TYPE i,pos TYPE i,wa LIKE x60bl-matnr.


IF pplan-matnr CO '0123456789 ' .
l = STRLEN( pplan-matnr ). pos = 18 - l.
wa = '000000000000000000'.
wa+pos(l) = pplan-matnr.
ELSE.
wa = pplan-matnr.
ENDIF.
* overlay wa with pplan-matnr only '0'.
* create header material, version and planname
MOVE wa TO x60bl-matnr.
MOVE pplan-werks TO x60bl-werks.
MOVE 'VSF' TO x60bl-bedae. "lsf --> Bsf --> Vsf
MOVE 'X' TO x60bl-vervs.
MOVE versb TO x60bl-versb.
MOVE planname TO x60bl-pbdnr.
APPEND x60bl.

ENDFORM. " CREATE_ITEM_HEADER

*&---------------------------------------------------------------------*
*& Form GETDATE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_TMP text *
*----------------------------------------------------------------------*
FORM getdate USING p_g_pos CHANGING tmp.
CASE p_g_pos.
WHEN 1.
tmp = tplan-f1.
WHEN 2.
tmp = tplan-f2.
WHEN 3.
tmp = tplan-f3.
WHEN 4.
tmp = tplan-f4.
WHEN 5.
tmp = tplan-f5.
WHEN 6.
tmp = tplan-f6.
WHEN 7.
tmp = tplan-f7.
WHEN 8.
tmp = tplan-f8.
WHEN 9.
tmp = tplan-f9.
WHEN 10.
tmp = tplan-f10.
WHEN 11.
tmp = tplan-f11.
WHEN 12.
tmp = tplan-f12.
WHEN 13.
tmp = tplan-f13.
WHEN 14.
tmp = tplan-f14.
WHEN 15.
tmp = tplan-f15.
WHEN 16.
tmp = tplan-f16.
WHEN 17.
tmp = tplan-f17.
WHEN 18.
tmp = tplan-f18.
WHEN 19.
tmp = tplan-f19.
WHEN 20.
tmp = tplan-f20.
WHEN 21.
tmp = tplan-f21.
WHEN 22.
tmp = tplan-f22.
WHEN 23.
tmp = tplan-f23.
WHEN 24.
tmp = tplan-f24.
WHEN 25.
tmp = tplan-f25.
WHEN 26.
tmp = tplan-f26.
WHEN 27.
tmp = tplan-f27.
WHEN OTHERS.
tmp = '*ERROR*'.
WRITE:/ 'oops.'.
EXIT.
ENDCASE.

ENDFORM. " GETDATE
*&---------------------------------------------------------------------*
*& Form AY_HESAPLA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_SY_INDEX text *
* <--P_X60ET_EDATU text *
*----------------------------------------------------------------------*
FORM ay_hesapla USING p_sy_index
CHANGING p_x60et_edatu.
DATA: yr(4),wk(2),tmp(7),mt(2).

PERFORM getdate USING p_sy_index CHANGING tmp.
yr = tmp+3(4). mt = tmp(2).
CONCATENATE yr mt '01' INTO p_x60et_edatu.
ENDFORM. " AY_HESAPLA
*&---------------------------------------------------------------------*
*& Form DEACTIVATE_PLAN
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM deactivate_plan.
DATA: xpbim LIKE TABLE OF pbim WITH HEADER LINE.
DATA: ret LIKE TABLE OF bapireturn1 WITH HEADER LINE.
DATA: req_schedule LIKE TABLE OF bapisshdin WITH HEADER LINE.
DATA: req_out LIKE TABLE OF bapisitmeo WITH HEADER LINE.


SELECT * FROM pbim
APPENDING CORRESPONDING FIELDS OF TABLE xpbim
WHERE pbdnr EQ oldplan .
* AND WERKS EQ WERKS.

IF sy-subrc NE 0.
WRITE:/ icon_message_error AS ICON,oldplan ,'mevcut değil.'.
ENDIF.

LOOP AT xpbim.
* read PLAN
CALL FUNCTION 'BAPI_REQUIREMENTS_GETDETAIL'
EXPORTING
material = xpbim-matnr
plant = xpbim-werks
requirementstype = xpbim-bedae
version = xpbim-versb
reqmtsplannumber = oldplan
TABLES
requirements_out = req_out
return = ret
EXCEPTIONS
OTHERS = 1.

IF sy-subrc NE 0.
WRITE:/ icon_message_error AS ICON,' İhtiyaçları okuyamıyorum'.
LOOP AT ret.
WRITE:/ ret.
ENDLOOP.
ENDIF.

* copy plan values
LOOP AT req_out.
MOVE-CORRESPONDING req_out TO req_schedule.
APPEND req_schedule.
ENDLOOP.

* change PLAN
CALL FUNCTION 'BAPI_REQUIREMENTS_CHANGE'
EXPORTING
material = xpbim-matnr
plant = xpbim-werks
requirementstype = xpbim-bedae
version = xpbim-versb
reqmtsplannumber = oldplan
vers_activ = ' ' "deactivate
* REQUIREMENT_PARAM =
* IMPORTING
* REQUIREMENT_ITEM_OUT =
TABLES
requirements_schedule_in = req_schedule
* REQUIREMENTS_CHAR_IN =
return = ret
EXCEPTIONS
OTHERS = 1.

IF sy-subrc NE 0.
WRITE:/ icon_message_error AS ICON,' İhtiyaçları değiştiremiyorum'.
LOOP AT ret.
WRITE:/ ret.
ENDLOOP.
ENDIF.

ENDLOOP.

ENDFORM. " DEACTIVATE_PLAN

*{ INSERT DUPK902810 1
*&---------------------------------------------------------------------*
*& Form CREATE_PPLAN_ITEm_new
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM create_pplan_item_new .
DATA : requirements_item LIKE bapisitemr,
requirement_param LIKE cm60r,
requirements_schedule_in LIKE bapisshdin OCCURS 10 WITH HEADER LINE,
requirements_char_in LIKE bapischarr OCCURS 10 WITH HEADER LINE,
return LIKE bapireturn1 OCCURS 10 WITH HEADER LINE.


DATA: amount LIKE x60et-plnmg.
DATA: beg_day LIKE x60et-edatu.
DATA: pweek LIKE scal-week.
REFRESH x60bl.
REFRESH x60et.
PERFORM create_item_header.
g_pos = 1.
DO VARYING amount FROM pplan-f1 NEXT pplan-f2.
MOVE amount TO x60et-plnmg.
IF amount(1) EQ space. "miktarsızları es geç
CONTINUE.
ENDIF.
* pweek = beg_week + g_pos - 1. "locate week

IF sy-index LE pnweek.
PERFORM hafta_hesapla USING beg_week sy-index CHANGING pweek.
* move 'W' to x60et-entlu.
* MOVE 'T' TO X60ET-ENTLU. "daily requirement
MOVE '1' TO x60et-entlu. "daily requirement
CALL FUNCTION 'WEEK_GET_FIRST_DAY'
EXPORTING
week = pweek
IMPORTING
date = x60et-edatu
EXCEPTIONS
week_invalid = 1
OTHERS = 2.

IF sy-subrc EQ 0.
* OD 15/04 haftanın 2.günü olacak PZTESI --> ÇARŞAMBA
* ADD 2 TO X60ET-EDATU.
APPEND x60et.
ELSE.
WRITE:/ icon_message_error AS ICON, ' date convertion'.
ENDIF.
ELSE.
IF sy-index LE 27.
PERFORM ay_hesapla USING sy-index CHANGING x60et-edatu.
* MOVE 'M' TO X60ET-ENTLU. "KALAN AYLAR İÇİN GİRİŞLER
MOVE '2' TO x60et-entlu.
APPEND x60et.
ELSE.
EXIT.
ENDIF.
ENDIF.
g_pos = g_pos + 1.
ENDDO.

requirements_item-material = x60bl-matnr.
requirements_item-plant = x60bl-werks.
requirements_item-requ_type = x60bl-bedae.
requirements_item-version = x60bl-versb.
requirements_item-vers_activ = x60bl-vervs.
requirements_item-req_number = x60bl-pbdnr.

LOOP AT x60et.
requirements_schedule_in-date_type = x60et-entlu.
requirements_schedule_in-req_date = x60et-edatu.
requirements_schedule_in-req_qty = x60et-plnmg.


*----------------------------------------------------------------------*
*-- miktar çevrimi
DATA: input TYPE f,
meins LIKE mara-meins,
meinh LIKE marm-meinh,
output TYPE f ,
lv_qty TYPE i .

CLEAR meins .
SELECT SINGLE meins INTO meins
FROM mara
WHERE matnr EQ requirements_item-material .

meinh = 'KG' .
input = requirements_schedule_in-req_qty * 1000 .

CALL FUNCTION 'MATERIAL_UNIT_CONVERSION'
EXPORTING
input = input
kzmeinh = 'X'
matnr = requirements_item-material
meinh = meinh
meins = meins
* EXTENDED_CONV = ' '
* TYPE_UMR = ' '
* NO_OUTPUT = ' '
* CHARGE =
* CHARG_CUOBJ =
* WERKS =
IMPORTING
* ADDKO =
* MEINS =
output = output .

CLEAR lv_qty .
lv_qty = output .
requirements_schedule_in-req_qty = lv_qty .

*----------------------------------------------------------------------*

APPEND requirements_schedule_in.
ENDLOOP.




* IF p_sim = 'X'.
*
* CALL FUNCTION 'BAPI_REQUIREMENTS_SIMULATE'
* EXPORTING
* material = requirements_item-material
* plant = requirements_item-plant
* requirementstype = requirements_item-requ_type
* version = requirements_item-version
* reqmtsplannumber = requirements_item-req_number
* vers_activ = requirements_item-vers_activ
* mrp_area = requirements_item-mrp_area
** IMPORTING
** REQUIREMENT_ITEM_OUT =
* TABLES
* requirements_schedule_in = requirements_schedule_in
** REQUIREMENTS_SCHEDULE_OUT =
** REQUIREMENTS_CHAR_IN =
* return = return .
*
* LOOP AT return WHERE type = 'E' OR type = 'A'.
*
* PERFORM add_log USING pplan-matnr return-message.
*
* ENDLOOP.
*
*
*
* ELSE.

CALL FUNCTION 'BAPI_REQUIREMENTS_CREATE'
EXPORTING
requirements_item = requirements_item
* REQUIREMENT_PARAM =
* IMPORTING
* MATERIAL =
* PLANT =
* REQUIREMENTSTYPE =
* VERSION =
* REQMTSPLANNUMBER =
* MRP_AREA =
TABLES
requirements_schedule_in = requirements_schedule_in
* REQUIREMENTS_CHAR_IN =
return = return
.

LOOP AT return WHERE type = 'E' OR type = 'A'.

PERFORM add_log USING pplan-matnr return-message.

ENDLOOP.
* ENDIF.

ENDFORM. " CREATE_PPLAN_ITEm_new

*} INSERT
*&---------------------------------------------------------------------*
*& Form popup_to_inform
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM popup_to_inform .

* IF p_sim = 'X'.
*
* CALL FUNCTION 'POPUP_TO_INFORM'
* EXPORTING
* titel = 'Dikkat'
* txt1 = 'Program Simülasyon modunda çalışıyor.'
* txt2 = 'kayıtlar yaratılmayacak'
** TXT3 = ' '
** TXT4 = ' '
* .
* ENDIF.
ENDFORM. " popup_to_inform

0 Comments:

Post a Comment

<< Home