REQUIREMENTS İhtiyaç Planlama Bapi
İhtiyaç Planlama
BAPI_REQUIREMENTS_GETDETAIL
BAPI_REQUIREMENTS_CHANGE
BAPI_REQUIREMENTS_CREATE
constants : gc_plant_default type werks_d value `3434`.
form f_save_to_system using prm_master type ztr_s_sattah_master
changing chn_error type c.
data: ls_detay like line of gt_detay_full.
data: ls_slave like line of gt_slave_full.
data: lt_requi type standard table of bapisitmeo.
data: ls_requi type bapisitmeo.
data: lt_return type standard table of bapireturn1.
data: lv_edatu type edatu.
data: ls_item type bapisshdin.
data: lt_change_items type standard table of bapisshdin.
data: lt_create_items type standard table of bapisshdin.
loop at gt_slave_full into ls_slave where tahmin_id = prm_master-tahmin_id.
REFRESH lt_change_items.
REFRESH lt_create_items.
call function `BAPI_REQUIREMENTS_GETDETAIL`
exporting
material = ls_slave-matnr
plant = gc_plant_default
requirementstype = ``
version = ls_slave-surum
reqmtsplannumber = ``
tables
requirements_out = lt_requi
return = lt_return.
sort lt_requi by date_type req_date. "VERS_ACTIV ????
loop at gt_detay_full into ls_detay where tahmin_id = prm_master-tahmin_id
and matnr = ls_slave-matnr
and yil = ls_slave-yil
and surum = ls_slave-surum.
concatenate ls_detay-yil ls_detay-ay `01` into lv_edatu.
" VERSION_ACTIV = `X` kullanmak gerekebilir
ls_item-date_type = `3`.
ls_item-req_date = lv_edatu.
ls_item-req_qty = ls_detay-req_qty.
ls_item-unit = ls_detay-mara_meins.
* read table lt_requi into ls_requi with key date_type = gc_prgrs_aylik
* req_date = lv_edatu
* binary search .
if lt_requi[] is not initial ."change
append ls_item to lt_change_items.
else."create
append ls_item to lt_create_items.
endif.
endloop.
if lt_change_items[] is not initial.
perform f_change_requirement tables lt_change_items
using ls_slave
changing chn_error .
endif.
if lt_create_items[] is not initial and chn_error is initial .
perform f_create_requirement tables lt_create_items
using ls_slave
changing chn_error .
endif.
if chn_error is initial.
perform f_save_log tables lt_change_items lt_create_items using ls_slave prm_master.
call function `BAPI_TRANSACTION_COMMIT`.
else.
Return."Diğerlerini yapma
endif.
endloop.
commit work and wait.
endform. "f_save_to_system
form f_change_requirement tables prt_items structure bapisshdin
using prm_slave type ztr_s_sattah_slave
changing chn_error type c.
data: lt_return type standard table of bapireturn1.
check prt_items[] is not initial.
call function `BAPI_REQUIREMENTS_CHANGE`
exporting
material = prm_slave-matnr
plant = gc_plant_default
requirementstype = ``
version = prm_slave-surum
reqmtsplannumber = ``
vers_activ = space
* REQUIREMENT_PARAM =
* MRP_AREA =
* DO_COMMIT = `X`
update_mode = `X`
* DELETE_OLD = `X`
* NO_WITHDR = ` `
* MATERIAL_EVG =
* IMPORTING
* REQUIREMENT_ITEM_OUT =
tables
requirements_schedule_in = prt_items[]
* REQUIREMENTS_CHAR_IN =
return = lt_return[]
.
perform f_check_erros tables lt_return changing chn_error .
if chn_error = `X` .
call function `BAPI_TRANSACTION_ROLLBACK` .
endif.
endform. "f_change_REQUIREMENT
*&---------------------------------------------------------------------*
*& Form f_create_REQUIREMENT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->PRT_ITEMS text
* -->PRT_RETURN text
* -->PRM_SLAVE text
*----------------------------------------------------------------------*
form f_create_requirement tables prt_items structure bapisshdin
using prm_slave type ztr_s_sattah_slave
changing chn_error type c.
data: ls_header type bapisitemr.
data: lt_return type standard table of bapireturn1.
check prt_items[] is not initial.
ls_header-material = prm_slave-matnr.
ls_header-plant = gc_plant_default.
ls_header-requ_type = ``.
ls_header-version = prm_slave-surum.
ls_header-vers_activ = space.
call function `BAPI_REQUIREMENTS_CREATE`
exporting
requirements_item = ls_header
* REQUIREMENT_PARAM =
* DO_COMMIT = `X`
update_mode = `X`
* REFER_TYPE = ` `
* PROFILID = ` `
* IMPORTING
* MATERIAL =
* PLANT =
* REQUIREMENTSTYPE =
* VERSION =
* REQMTSPLANNUMBER =
* MRP_AREA =
* MATERIAL_EVG =
tables
requirements_schedule_in = prt_items[]
* REQUIREMENTS_CHAR_IN =
return = lt_return[]
.
perform f_check_erros tables lt_return changing chn_error .
if chn_error = `X` .
call function `BAPI_TRANSACTION_ROLLBACK` .
endif.
endform. "f_create_REQUIREMENT