report ZYPB840.
types:
begin of TYP_PIR_KEY,
MATNR type MATNR,
PBDNR type PBIM-PBDNR,
end of TYP_PIR_KEY,
begin of TYP_FILE,
ROW type STRING,
end of TYP_FILE,
I_TYP_FILE type standard table of TYP_FILE.
data:
G_KUNNR type ZXP24-KUNNR,
G_KBN type ZXP24-ZZKUBUN,
G_KDMAT type ZXP24-KDMAT,
G_NOUKI type ZXP24-ZZNOUKI,
GI_SYS type I_TYP_FILE,
GI_TRN type I_TYP_FILE,
GI_END type I_TYP_FILE.
select-options:
S_KUNNR for G_KUNNR,
S_KBN for G_KBN,
S_KDMAT for G_KDMAT,
S_NOUKI for G_NOUKI obligatory.
selection-screen:skip 2.
parameters:
P_FOLD1 type FILEPATH-PATHINTERN obligatory,
P_FOLD2 type FILEPATH-PATHINTERN obligatory,
P_FOLD3 type FILEPATH-PATHINTERN obligatory.
selection-screen:skip 1.
parameters:
P_WAIT1 type I,
P_WAIT2 type I.
initialization.
S_NOUKI-SIGN = 'I'.
S_NOUKI-OPTION = 'EQ'.
S_NOUKI-LOW = SY-DATUM - 30.
append S_NOUKI.
P_WAIT1 = 60.
P_WAIT2 = 300.
at selection-screen.
start-of-selection.
perform F_MAIN.
end-of-selection.
if GI_SYS is not initial.
perform F_WRITE_LOG using '1' GI_SYS.
endif.
perform F_WRITE_LOG using '2' GI_TRN.
perform F_WRITE_LOG using '3' GI_END.
if GI_SYS is initial and LINES( GI_TRN ) <= 1 .
message '正常終了' type 'S'.
else.
message 'エラー発生、ログ参照' type 'S' display like 'E'.
endif.
*&---------------------------------------------------------------------*
*& Form f_main 主処理
*&---------------------------------------------------------------------*
form F_MAIN.
data:
LI_ZXP24 type standard table of ZXP24,
LW_ZXP24 type ZXP24,
LW_PIR_KEY type TYP_PIR_KEY,
LI_PIR_KEY type standard table of TYP_PIR_KEY,
LI_PBIM type standard table of PBIM,
LV_JOBNAME type TBTCO-JOBNAME,
LW_PBIM type PBIM,
LW_TRN type TYP_FILE,
LW_SYS type TYP_FILE,
LV_FLG type CHAR01,
LV_INDEX type I.
* mrp実行確認
clear: LV_FLG,
GI_SYS,
GI_TRN.
do 3 times.
LV_INDEX = SY-INDEX.
select single JOBNAME into LV_JOBNAME
from TBTCO where JOBNAME like '%MRP%'.
if SY-SUBRC <> 0.
LV_FLG = ABAP_ON.
exit.
else.
if LV_INDEX < 3.
wait up to P_WAIT1 seconds.
endif.
endif.
enddo.
if LV_FLG is initial.
LW_SYS-ROW = 'MRP実行中。。。。。。'.
append LW_SYS to GI_SYS.
return.
endif.
* テーブルロック処理
do 3 times.
LV_INDEX = SY-INDEX.
call function 'ENQUEUE_E_TABLE'
exporting
MODE_RSTABLE = 'E'
TABNAME = 'ZXP24'
exceptions
FOREIGN_LOCK = 1
SYSTEM_FAILURE = 2
others = 3.
if SY-SUBRC = 0.
LV_FLG = ABAP_ON.
exit.
else.
if LV_INDEX < 3.
wait up to P_WAIT2 seconds.
endif.
endif.
enddo.
if LV_FLG is initial.
LW_SYS-ROW = 'ロックエラー。。。。。'.
append LW_SYS to GI_SYS.
return.
endif.
* データ抽出処理
select * from ZXP24
into table LI_ZXP24
where KUNNR in S_KUNNR and
ZZKUBUN in S_KBN and
KDMAT in S_KDMAT and
ZZNOUKI in S_NOUKI and
ZZUPDDATE_FLG = 'X' and
ZZDELETE_FLG = SPACE.
check LI_ZXP24 is not initial.
loop at LI_ZXP24 into LW_ZXP24.
LW_PIR_KEY-MATNR = LW_ZXP24-MATNR.
LW_PIR_KEY-PBDNR = LW_ZXP24-KUNNR+5(5) && LW_ZXP24-ZZKUBUN.
append LW_PIR_KEY to LI_PIR_KEY.
endloop.
sort LI_PIR_KEY by MATNR ascending
PBDNR ascending.
delete adjacent duplicates from LI_PIR_KEY.
*(2)独立所要量データ
* 内示データに該当独立所要量データを取得する
select * from PBIM into table LI_PBIM
for all entries in LI_PIR_KEY
where MATNR = LI_PIR_KEY-MATNR and
PBDNR = LI_PIR_KEY-PBDNR.
concatenate TEXT-H01
TEXT-H02
TEXT-H03
TEXT-H04
TEXT-H05
into LW_TRN-ROW separated by CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
append LW_TRN to GI_TRN.
*(4) 独立所要量登録更新処理
loop at LI_ZXP24 into LW_ZXP24.
read table LI_PBIM into LW_PBIM
with key MATNR = LW_ZXP24-MATNR
VERSB = LW_ZXP24-KUNNR+5(5) && LW_ZXP24-ZZKUBUN.
if SY-SUBRC <> 0.
perform F_CREATE using LW_ZXP24.
else.
perform F_CHANGE using LW_ZXP24.
endif.
endloop.
* テーブルアンロック処理
call function 'DEQUEUE_E_TABLE'
exporting
MODE_RSTABLE = 'E'
TABNAME = 'ZXP24'.
endform.
*&---------------------------------------------------------------------*
*& Form CREATE 登録処理
*&---------------------------------------------------------------------*
form F_CREATE using UV_ZXP24 type ZXP24.
data:
LW_BAPISITEMR type BAPISITEMR,
LI_SCHEDULE type standard table of BAPISSHDIN,
LW_SCHEDULE type BAPISSHDIN,
LI_RETURN type standard table of BAPIRETURN1,
LW_RETURN type BAPIRETURN1,
LW_ZXP24 type ZXP24,
LV_ERRFLG type CHAR01,
LW_TRN type TYP_FILE.
"品目
LW_BAPISITEMR-MATERIAL = UV_ZXP24-MATNR.
"プラント
LW_BAPISITEMR-PLANT = '1000'.
"所要量タイプ
LW_BAPISITEMR-REQU_TYPE = 'LSF'.
"所要量のバージョン番号
LW_BAPISITEMR-VERSION = '01'.
"バージョン有効フラグ
LW_BAPISITEMR-VERS_ACTIV = 'X'.
LW_BAPISITEMR-REQ_NUMBER = UV_ZXP24-KUNNR+5(5) && UV_ZXP24-ZZKUBUN.
clear LI_SCHEDULE.
LW_SCHEDULE-DATE_TYPE = '1'. "day
LW_SCHEDULE-REQ_DATE = UV_ZXP24-ZZNOUKI.
LW_SCHEDULE-REQ_QTY = UV_ZXP24-ZZSUU.
* LW_SCHEDULE-unit = c_unit.
append LW_SCHEDULE to LI_SCHEDULE.
call function 'BAPI_REQUIREMENTS_CREATE' " Bapi to Create Planned Independent Reqmts
exporting
REQUIREMENTS_ITEM = LW_BAPISITEMR
DO_COMMIT = 'X'
UPDATE_MODE = 'X'
tables
REQUIREMENTS_SCHEDULE_IN = LI_SCHEDULE
RETURN = LI_RETURN.
loop at LI_RETURN into LW_RETURN
where TYPE = 'A' or
TYPE = 'E'.
LV_ERRFLG = 'X'.
endloop.
if LV_ERRFLG is initial.
LW_ZXP24 = UV_ZXP24.
clear LW_ZXP24-ZZUPDDATE_FLG.
LW_ZXP24-AEDAT = SY-DATUM.
LW_ZXP24-AENAM = SY-UNAME.
LW_ZXP24-UDLTIME = SY-UZEIT.
modify ZXP24 from LW_ZXP24.
commit work.
else.
concatenate UV_ZXP24-KUNNR
UV_ZXP24-ZZKUBUN
UV_ZXP24-KDMAT
UV_ZXP24-ZZNOUKI
LW_RETURN-MESSAGE
into LW_TRN-ROW separated by CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
append LW_TRN to GI_TRN.
endif.
endform.
*&---------------------------------------------------------------------*
*& Form change 更新処理
*&---------------------------------------------------------------------*
form F_CHANGE using UV_ZXP24 type ZXP24.
data:
LW_BAPISITEMR type BAPISITEMR,
LI_SCHEDULE type standard table of BAPISSHDIN,
LW_SCHEDULE type BAPISSHDIN,
LI_RETURN type standard table of BAPIRETURN1,
LW_RETURN type BAPIRETURN1,
LV_ERRFLG type CHAR01,
LW_ZXP24 type ZXP24,
LW_TRN type TYP_FILE.
clear LI_SCHEDULE.
LW_SCHEDULE-DATE_TYPE = '1'. "day
LW_SCHEDULE-REQ_DATE = UV_ZXP24-ZZNOUKI.
LW_SCHEDULE-REQ_QTY = UV_ZXP24-ZZSUU.
* LW_SCHEDULE-unit = c_unit.
append LW_SCHEDULE to LI_SCHEDULE.
call function 'BAPI_REQUIREMENTS_CHANGE'
exporting
MATERIAL = UV_ZXP24-MATNR
PLANT = '1000'
REQUIREMENTSTYPE = 'LSF'
VERSION = UV_ZXP24-KUNNR+5(5) && UV_ZXP24-ZZKUBUN
REQMTSPLANNUMBER = ''
VERS_ACTIV = 'X'
DO_COMMIT = 'X'
UPDATE_MODE = 'X'
tables
REQUIREMENTS_SCHEDULE_IN = LI_SCHEDULE
RETURN = LI_RETURN.
loop at LI_RETURN into LW_RETURN
where TYPE = 'A' or
TYPE = 'E'.
LV_ERRFLG = 'X'.
endloop.
if LV_ERRFLG is initial.
LW_ZXP24 = UV_ZXP24.
clear LW_ZXP24-ZZUPDDATE_FLG.
LW_ZXP24-AEDAT = SY-DATUM.
LW_ZXP24-AENAM = SY-UNAME.
LW_ZXP24-UDLTIME = SY-UZEIT.
modify ZXP24 from LW_ZXP24.
commit work.
else.
concatenate UV_ZXP24-KUNNR
UV_ZXP24-ZZKUBUN
UV_ZXP24-KDMAT
UV_ZXP24-ZZNOUKI
LW_RETURN-MESSAGE
into LW_TRN-ROW separated by CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
append LW_TRN to GI_TRN.
endif.
endform.
*&---------------------------------------------------------------------*
*& Form F_WRITE_LOG サーバ7ファイル作成処理
*&---------------------------------------------------------------------*
form F_WRITE_LOG using UV_TYPE type CHAR01
UI_CONTENTS type I_TYP_FILE.
data:LV_PATH type FILEPATH-PATHINTERN,
LV_FILE type STRING,
LV_FILENM type STRING,
LV_ROW type TYP_FILE.
if UV_TYPE = 1.
LV_PATH = P_FOLD1.
LV_FILE = TEXT-T01 && SY-DATUM && SY-UZEIT && '.txt'.
elseif UV_TYPE = 2.
LV_PATH = P_FOLD2.
LV_FILE = TEXT-T02 && SY-DATUM && SY-UZEIT && '.txt'.
else.
LV_PATH = P_FOLD3.
LV_FILE = TEXT-T03 && SY-DATUM && SY-UZEIT && '.txt'.
endif.
call function 'FILE_GET_NAME_USING_PATH'
exporting
LOGICAL_PATH = LV_PATH
FILE_NAME = LV_FILE
importing
FILE_NAME_WITH_PATH = LV_FILENM
exceptions
PATH_NOT_FOUND = 1
MISSING_PARAMETER = 2
OPERATING_SYSTEM_NOT_FOUND = 3
FILE_SYSTEM_NOT_FOUND = 4
others = 5.
if SY-SUBRC <> 0.
* Implement suitable error handling here
endif.
open dataset LV_FILENM for output
in legacy text mode code page '8000'
with windows linefeed .
loop at UI_CONTENTS into LV_ROW.
transfer LV_ROW-ROW to LV_FILENM.
endloop.
close dataset LV_FILENM.
endform.
2019年12月19日星期四
订阅:
博文评论 (Atom)
Customer Characteristic
Characteristic Descriptions are stored in the table - CABNT - Language - SPRAS - Characteristic description - ATBEZ Characteristic Values ...
-
REPORT ZBPADD2 . DATA : L_PARTN_CAT TYPE BAPIBUS1006_HEAD - PARTN_CAT , LS_CENTRAL TYPE BAPIBUS1006_CENTRAL , ...
-
HEADER: ADD Customer Fields to structure of IMKPF and BAPI_TE_XMKPF. Items: ADD Customer Fields to structure of IMSEG and BAPI_TE_XMSEG....
-
FUNCTION:SD_SALESDOCUMENT_CREATE Append fiels to Structure below. BAPE_VBAP BAPE_VBAPX VBAPKOZ VBAPKOZX No need to append fields to Struc...
没有评论:
发表评论