Status Update Equipment
Ekipman Durum değiştirme için ekipmanın mevcut durumları STATUS_READ fonksiyonu ile alınıp değiştirilecek olan duruma X veya space atılarak STATUS_CHANGE_INTERN fonksiyonu ile kaydedilir. Commit şart....
REPORT ZMEHO_TEST_002.
types: begin of ty_return ,
MSG_TYPE Type c , "İşlem Durumu ( S-Success E-Error)
MSG_TXT Type BAPI_MSG, " İleti metni
end of ty_return.
TYPES: begin of TY_equi,
equnr TYPE equnr,
OBJNR Type J_OBJNR,
STSYS_STAT Type J_STATUS,
STSYS_TEXT Type J_TXT04,
STSYS_DESC Type J_TXT30,
* STUSER_STAT type J_STATUS,
* STUSER_TEXT type J_TXT04,
* STUSER_DESC type J_TXT30,
end of TY_equi.
constants: c_STAT_I0076 TYPE J_STATUS VALUE `I0076`. "Silme İşareti
constants: c_STAT_I0099 TYPE J_STATUS VALUE `I0099`. "Kullanılabilir
constants: c_STAT_I0184 TYPE J_STATUS VALUE `I0184`. "Depoda
constants: c_STAT_I0188 TYPE J_STATUS VALUE `I0188`. "Müşteride
parameters: p_equnr type equnr,
p_newsts type J_STATUS. "New System Stat
* p_newstu type J_STATUS. "New User Stat
start-of-selection.
perform f_process.
end-of-selection.
form f_process.
data: ls_equi type equi.
data: ls_tyequi type TY_equi.
data: ls_return type ty_return.
clear ls_equi.
select single * into ls_equi
from equi where equnr = p_equnr.
check sy-subrc eq 0.
ls_tyequi-equnr = ls_equi-equnr.
ls_tyequi-objnr = ls_equi-objnr.
ls_tyequi-stsys_stat = p_newsts.
perform f_change_status using ls_tyequi changing ls_return .
if ls_return-msg_type = `S`.
call function `BAPI_TRANSACTION_COMMIT`
exporting
wait = `X`.
endif.
write: ls_return-msg_type , `-` ,ls_return-msg_txt.
endform.
form f_change_status using p_rm_edit type TY_equi
changing c_hn_sonuc type ty_return.
data: lt_stats type tt_jstat.
perform f_prepare_status using p_rm_edit
changing lt_stats .
call function `STATUS_CHANGE_INTERN`
exporting
* CHECK_ONLY = ` `
* CLIENT = SY-MANDT
objnr = p_rm_edit-objnr
* ZEILE = ` `
set_chgkz = `X`
* IMPORTING
* ERROR_OCCURRED =
* OBJECT_NOT_FOUND =
* STATUS_INCONSISTENT =
* STATUS_NOT_ALLOWED =
tables
status = lt_stats
exceptions
object_not_found = 1
status_inconsistent = 2
status_not_allowed = 3
others = 4.
case sy-subrc.
when 0.
c_hn_sonuc-msg_type = `S`.
c_hn_sonuc-msg_txt = `Success`.
when 1.
c_hn_sonuc-msg_type = `E`.
c_hn_sonuc-msg_txt = `object_not_found`.
when 2.
c_hn_sonuc-msg_type = `E`.
c_hn_sonuc-msg_txt = `status_inconsistent`.
when 3.
c_hn_sonuc-msg_type = `E`.
c_hn_sonuc-msg_txt = `status_not_allowed`.
when others.
c_hn_sonuc-msg_type = `E`.
c_hn_sonuc-msg_txt = `other`.
endcase.
endform.
form f_prepare_status using p_rm_edit type TY_equi
changing c_hn_stats type tt_jstat.
data: lv_xndx type int4.
data: ls_stats type jstat.
data: lt_fixed_stats type tt_jstat.
data: ls_fixed_stats type jstat.
perform f_fixed_status changing lt_fixed_stats . "buradan sıralı geliyor!
call function `STATUS_READ`
exporting
* CLIENT = SY-MANDT
objnr = p_rm_edit-objnr
* ONLY_ACTIVE = ` `
* IMPORTING
* OBTYP =
* STSMA =
* STONR =
tables
status = c_hn_stats
exceptions
object_not_found = 1
others = 2.
if sy-subrc eq 0."fonksiyon
sort c_hn_stats by stat.
read table c_hn_stats into ls_stats with key stat = p_rm_edit-stsys_stat binary search.
if sy-subrc ne 0. "Kayıt yok ise ekleyiver,
"Mümkün bir durum ise ekle
read table lt_fixed_stats into ls_fixed_stats with key stat = p_rm_edit-stsys_stat binary search.
if sy-subrc eq 0.
ls_stats-stat = p_rm_edit-stsys_stat.
ls_stats-inact = space.
append ls_stats to c_hn_stats.
endif.
endif.
loop at c_hn_stats into ls_stats.
lv_xndx = sy-tabix.
read table lt_fixed_stats into ls_fixed_stats with key stat = ls_stats-stat binary search.
if sy-subrc eq 0.
if p_rm_edit-stsys_stat = ls_stats-stat.
ls_stats-inact = space.
else.
ls_stats-inact = `X`.
endif.
modify c_hn_stats from ls_stats index lv_xndx.
endif.
endloop.
endif.
endform.
form f_fixed_status changing c_hn_stats type tt_jstat.
data: ls_jstat type jstat.
* constants: c_STAT_I0076 TYPE J_STATUS VALUE `I0076`. "Silme İşareti
* constants: c_STAT_I0099 TYPE J_STATUS VALUE `I0099`. "Kullanılabilir
* constants: c_STAT_I0184 TYPE J_STATUS VALUE `I0184`. "Depoda
* constants: c_STAT_I0188 TYPE J_STATUS VALUE `I0188`. "Müşteride
refresh c_hn_stats.
clear ls_jstat.
ls_jstat-stat = c_stat_i0076. append ls_jstat to c_hn_stats.
ls_jstat-stat = c_stat_i0099. append ls_jstat to c_hn_stats.
ls_jstat-stat = c_stat_i0184. append ls_jstat to c_hn_stats.
ls_jstat-stat = c_stat_i0188. append ls_jstat to c_hn_stats.
sort c_hn_stats by stat.
endform.