*&---------------------------------------------------------------------*
*& Report ZRMM178 REL : 7.1c Author : Peak Huang *
* Created : 2011.06.21 APP : All Type : Report *
* Title : CMFE Auto upload goods movement from RFID to CEN
*----------------------------------------------------------------------*
*------Update list-----------------------------------------------------*
*Sequence Date Author Description *
*M1 2011.08.02 Peak Enhance
*M2 2011.08.18 Peak Cancel Vendor batch Check Document Header text
*M3 2012.02.09 Peak Enahce server path get file method
*M4 2012.03.22 Daniel CMH RFID Integration-Goods movt txt file
*M5 2012.03.29 Daniel enhance for 311/312
*M6 2012.04.20 Peak add header text filter for 101 102 122 123 922 923 511/512/309/310/311/312/551/552/991/992/333/334/261/262
*M7 2012.05.28 Peak for 992 add GR date
*M8 2012.06.04 Peak add 601 602
*M9 2012.06.19 Daniel Enh Goods movt to do Subcon PO GR
* the last update time: 2012.08.08 16:30
*----------------------------------------------------------------------*
REPORT ZRMM178 .
*----------------------------------------------------------------------*
* Database Table *
*----------------------------------------------------------------------*
tables: mbew,zrfid_goodsmvt,zrfid_email, zpp_iss_doc_log, ekko, j_3abdsi, resb, t100
,T158 ,T156N,T158B, mseg .
types: tfield(40) type c.
data:begin of itab occurs 0.
include structure zrfid_goodsmvt.
*M4 add
data: bwart like mseg-bwart,
bldat like mkpf-bldat,
budat like mkpf-budat,
werks like mseg-werks,
lgort like mseg-lgort,
j_4ksca like mseg-j_4ksca,
matnr like mseg-matnr,
erfmg like mseg-erfmg,
j_3asiz like mseg-j_3asiz,
licha like mcha-licha,
charg like mseg-charg,
umlgo like mseg-umlgo,
j_4kumsc like mseg-j_4kumsc,
ummat like mseg-ummat,
j_3aumsi like mseg-j_3aumsi,
umbar like mseg-umbar,
*M4 end
mblnr like mseg-mblnr, "M9 add
end of itab.
data:itab_err like itab occurs 0 with header line .
data:itab_succ like itab occurs 0 with header line .
data:itab_succ_tmp like itab occurs 0 with header line .
data:itab_modify like itab occurs 0 with header line .
data:itab_public like itab occurs 0 with header line .
data:itab_last like itab occurs 0 with header line .
data:begin of itab_log occurs 0.
include structure zpp_iss_doc_log.
data: end of itab_log.
data:begin of it_record occurs 0,
field01 type tfield,
field02 type tfield,
field03 type tfield,
field04 type tfield,
field05 type tfield,
field06 type tfield,
field07 type tfield,
field08 type tfield,
field09 type tfield,
field10 type tfield,
field11 type tfield,
field12 type tfield,
field13 type tfield,
field14 type tfield,
field15 type tfield,
field16 type tfield,
field17 type tfield,
field18 type tfield,
field19 type tfield,
field20 type tfield,
field21 type tfield,
field22 type tfield,
field23 type tfield,
field24 type tfield,
field25 type tfield,
field26 type tfield,
field27 type tfield,
field28 type tfield, "M9 add
* field29 type tfield,
end of it_record.
data:begin of it_output occurs 0.
include structure it_record.
data: "field28 type tfield,"M9 remark
field29(255) type c,
*M4 add
field30 type tfield,
field31 type tfield,
field32 type tfield,
field33 type tfield,
field34 type tfield,
field35 type tfield,
field36 type tfield,
field37 type tfield,
field38 type tfield,
field39 type tfield,
field40 type tfield,
field41 type tfield,
field42 type tfield,
field43 type tfield,
field44 type tfield,
field45 type tfield,
*M4 end
end of it_output.
data: begin of i_file occurs 0,
line(1500) type c, "M4 modify the length (change 700 to 1500)
end of i_file.
data:it_file like i_file occurs 0 with header line .
data:begin of file_name occurs 100,
name(75) type c,
end of file_name.
data:it_filter like file_name occurs 0 with header line . "M3
TYPES: KCDE_DIRECTORY LIKE RLGRAP-FILENAME OCCURS 0.
DATA: l_directory TYPE KCDE_DIRECTORY WITH HEADER LINE.
data: in_file(255) TYPE C,
out_file(255) TYPE C.
data: i type i.
data: gv_file like rlgrap-filename.
data: mc_filename(50) type c.
data: a_dir_name like rlgrap-filename.
data :lv_mail_file like rlgrap-filename.
data: lv_tabix like sy-tabix,
lv_tabix_last like sy-tabix,
lv_seq_no type i,
lv_bukrs type ekko-bukrs.
data: lv_file_upld type string.
*M9 add
data: sc_stock like mslb occurs 0 with header line.
data old_J3ABDSI like J_3ABDSI occurs 0 with header line.
data old_resb like resb occurs 0 with header line.
data: begin of it_mchb occurs 0,
lgort like mchb-lgort,
matnr like mchb-matnr,
j_3asize like mchb-j_3asize,
clabs like mchb-clabs,
end of it_mchb.
DATA: BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE.
DATA: MESSTAB LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.
DATA: L_SUBRC LIKE SY-SUBRC.
data g_flag_adj type c.
data :begin of it_eket occurs 0,
ebeln like ekko-ebeln,
ebelp like ekpo-ebelp,
etenr like eket-etenr,
j_3asize like eket-j_3asize,
end of it_eket.
data: begin of it_req occurs 0,
ebeln like ekko-ebeln,
ebelp like ekpo-ebelp,
etenr like eket-etenr,
baugr like resb-baugr,
matnr like resb-matnr,
j_3asize like resb-j_3asize,
j_3astmeng like resb-j_3astmeng,
j_3astmein like resb-j_3astmein,
bmeng like stko-bmeng,
meins like ekpo-meins,
end of it_req.
data g_flag_req type c.
data g_flag_zme2o type c.
data zme2o_err type string.
data it_lack like itab_succ occurs 0 with header line.
DATA: BEGIN OF TA_ISSUE OCCURS 0,
row(3) type c,
spline(3) type c,
MATNR LIKE MSEG-MATNR,
ENTRY LIKE ZMMCOMSKU-GENTRY,
VALUE LIKE J_3ABDBS-J_3ASIZE,
OQTY LIKE J_3ABDBS-MENGE,
QTY LIKE J_3ABDBS-MENGE,
CHARG LIKE MSEG-CHARG,
MEINS LIKE MSEG-MEINS,
WERKS LIKE MSEG-WERKS,
J_4KSCAT LIKE MSEG-J_4KSCA,
* sort(2) type n,
END OF TA_ISSUE.
data ta_issue1 like ta_issue occurs 0 with header line.
data g_flag_subcon type c.
DATA: BEGIN OF TA_GRID OCCURS 0,
* 26/03/07 : SO breakdown
sel type c,
fr type c,
j_4kscat like eket-j_4kscat,
MBLNR LIKE MSEG-MBLNR,
MJAHR LIKE MSEG-MJAHR,
VALUE LIKE J_3ABDBS-J_3ASIZE,
OQTY LIKE J_3ABDBS-MENGE,
QTY LIKE J_3ABDBS-MENGE,
BATCH LIKE MSEG-CHARG,
ZEILE LIKE MSEG-ZEILE,
SGTXT LIKE MSEG-SGTXT,
ENTRY LIKE ZMMCOMSKU-GENTRY,
LENTRY LIKE ZMMCOMSKU-LENTRY,
GENTRY LIKE ZMMCOMSKU-GENTRY,
MATNR LIKE MSEG-MATNR,
EBELP LIKE EKPO-EBELP,
SL LIKE EKET-ETENR,
SORTSEQ type ZSORTSEQ,
INSEAM(40) TYPE C,
licha like mcha-licha,
split type c,
row(3) type c,
bwart like ekbe-bwart,
LINE_ID like mseg-LINE_ID,
PARENT_ID like mseg-PARENT_ID,
canc type c,
meins like ekpo-meins,
buom like ekpo-meins,
stlnr like mast-stlnr,
END OF TA_GRID.
*M9 end
*----------------------------------------------------------------------*
* Parameter & Select-Options *
*----------------------------------------------------------------------*
selection-screen begin of block BLK1 with frame title text-001.
parameter: p_dir like rlgrap-filename default '\\10.2.1.35\tmp\testRFID'.
parameter: local as checkbox default space.
selection-screen end of block BLK1.
*----------------------------------------------------------------------*
* Initialize *
*----------------------------------------------------------------------*
initialization.
*M4 add
data l_time like sy-UZEIT .
l_time = sy-UZEIT.
*M4 end
*----------------------------------------------------------------------*
* AT SELECTION-SCREEN *
*----------------------------------------------------------------------*
at selection-screen on value-request for p_dir.
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
def_path = ''
mask = ',*.*,*.*.'
mode = 'O'
IMPORTING
filename = p_dir
EXCEPTIONS
INV_WINSYS = 1
NO_BATCH = 2
SELECTION_CANCEL = 3
SELECTION_ERROR = 4.
at selection-screen.
if local ne 'X'.
if p_dir is initial.
message e058(zpp01) with 'Server Path is missing to entry'.
endif.
else.
if p_dir is initial.
message e058(zpp01) with 'Local File is missing to entry'.
endif.
endif.
a_dir_name = p_dir.
*----------------------------------------------------------------------*
* Start of Processing *
*----------------------------------------------------------------------*
start-of-selection.
if local ne 'X'.
perform read_file. "M3 Modify
else.
clear file_name[].
move p_dir to file_name-name.
append file_name.
endif.
clear:itab_last.
loop at file_name.
refresh: it_record,itab,itab_err,itab_succ,itab_succ_tmp,itab_modify.
clear: it_record,itab,itab_err,itab_succ,itab_succ_tmp,itab_modify.
perform upload_file.
perform get_data.
read table itab index 1.
if sy-subrc eq 0.
perform check_itab.
perform fiter_err_record.
read table itab_succ index 1.
if sy-subrc eq 0 .
loop at itab_succ.
clear g_flag_subcon. "m9 add
case itab_succ-move_type.
when '101' or '102'.
*M9 add
if itab_succ-move_type = '101'.
perform check_subcon_po.
perform process_subcon_po.
elseif itab_succ-move_type = '102'.
perform check_subcon_po.
endif.
*M9 end
perform create_movetype using 'Z_BAPI_GOODSMVT_CREATE_101_102'.
when '511' or '512'.
perform create_movetype using 'Z_BAPI_GOODSMVT_CREATE_511_512'.
when '122' or '123'.
perform create_movetype using 'Z_BAPI_GOODSMVT_CREATE_122_123'.
when '922' or '923'.
perform create_movetype using 'Z_BAPI_GOODSMVT_CREATE_922_923'.
when '309' or '310'.
perform create_movetype using 'Z_BAPI_GOODSMVT_CREATE_309_310'.
when '311' or '312'.
perform create_movetype using 'Z_BAPI_GOODSMVT_CREATE_311_312'.
when '551' or '552'.
perform create_movetype using 'Z_BAPI_GOODSMVT_CREATE_551_552'.
when '991' or '992'.
perform create_movetype using 'Z_BAPI_GOODSMVT_CREATE_991_992'.
when '333' or '334'.
perform create_movetype using 'Z_BAPI_GOODSMVT_CREATE_333_334'.
when '261' or '262'.
perform create_movetype using 'Z_BAPI_GOODSMVT_CREATE_261_262'.
when '701' or '702'.
perform create_movetype using 'Z_BAPI_GOODSMVT_CREATE_701_702'.
when '601' or '602'. "M8 add
perform create_movetype using 'Z_BAPI_GOODSMVT_CREATE_601_602'.
endcase.
endloop.
endif.
endif.
perform get_last_data.
if local ne 'X'.
perform move_file.
endif.
endloop.
read table itab_last index 1.
if sy-subrc eq 0.
clear:lv_bukrs.
perform delete_zrfid_goodsmvt_table.
perform update_zpp_iss_doc_log.
perform excel_header.
loop at itab_last.
perform insert_zrfid_goodsmvt_table.
perform generate_excel.
if lv_bukrs is initial or lv_bukrs = space.
concatenate itab_last-plant+0(3) '0' into lv_bukrs .
endif.
endloop.
perform generate_excel_file.
endif.
*&---------------------------------------------------------------------*
*& Form UPLOAD_FILE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM UPLOAD_FILE .
clear:i_file,i_file[],itab,itab[],lv_file_upld.
if local ne 'X'.
concatenate p_dir '\' file_name-name into lv_file_upld .
perform batch_upld.
else.
lv_file_upld = file_name-name.
perform upload_file_data.
endif.
ENDFORM. " UPLOAD_FILE
*&---------------------------------------------------------------------*
*& Form FORMAT_DATE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_LV_DOC_DATE text
* <--P_ITAB_DOC_DATE text
*----------------------------------------------------------------------*
FORM FORMAT_DATE USING p_lv_date type tfield
CHANGING p_itab_date like sy-datum.
data:lv_len type i.
data :wa_date type tfield.
wa_date = p_lv_date.
shift wa_date right deleting trailing space.
shift wa_date left deleting leading space.
if not wa_date is initial.
lv_len = strlen( wa_date ).
if lv_len = 10.
concatenate wa_date+6(4) wa_date+3(2) wa_date+0(2) into p_itab_date.
endif.
endif.
ENDFORM. " FORMAT_DATE
*&---------------------------------------------------------------------*
*& Form BATCH_UPLD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM BATCH_UPLD .
concatenate p_dir '\' file_name-name into gv_file.
open dataset gv_file for input in text mode encoding UTF-8.
* open dataset gv_file for input in text mode encoding default.
if sy-subrc = 0.
*//upload data to file
do.
read dataset gv_file into i_file.
if sy-subrc ne 0.
exit.
endif.
append i_file.
enddo.
close dataset gv_file.
else.
* raise FILE_OPEN_ERROR.
endif.
ENDFORM. " BATCH_UPLD
*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GET_DATA .
data :lv_str type i.
loop at i_file.
split i_file-line at '|' into it_record-field01 it_record-field02 it_record-field03 it_record-field04
it_record-field05 it_record-field06 it_record-field07 it_record-field08 it_record-field09 it_record-field10
it_record-field11 it_record-field12 it_record-field13 it_record-field14 it_record-field15 it_record-field16
it_record-field17 it_record-field18 it_record-field19 it_record-field20 it_record-field21 it_record-field22
it_record-field23 it_record-field24 it_record-field25 it_record-field26 it_record-field27 it_record-field28. "m9 add 28
append it_record.
endloop.
i = 1.
loop at it_record.
condense it_record-field01 no-gaps.
lv_str = strlen( it_record-field01 ).
itab-move_type = it_record-field01.
if lv_str > 3 .
itab-move_type = it_record-field01+1(lv_str).
endif.
perform format_date using it_record-field02
changing itab-doc_date.
perform format_date using it_record-field03
changing itab-pstng_date.
itab-header_txt = it_record-field04.
itab-plant = it_record-field05.
itab-stge_loc = it_record-field06.
itab-stock_cat = it_record-field07.
translate itab-stock_cat to upper case.
itab-mat_code = it_record-field08.
itab-entry_qnt = it_record-field09.
itab-grid_value = it_record-field10.
itab-vendr_batch = it_record-field11.
itab-rfid_batch = it_record-field12.
itab-move_rfid_batch = it_record-field13.
itab-move_reas = it_record-field14.
itab-move_stloc = it_record-field15.
itab-move_stock_cat = it_record-field16.
translate itab-move_stock_cat to upper case.
itab-move_mat = it_record-field17.
itab-move_grid_value = it_record-field18.
translate it_record-field19 to upper case.
itab-move_val_type = it_record-field19.
itab-ref_doc = it_record-field20.
itab-po_number = it_record-field21.
itab-po_item = it_record-field22.
itab-sched_line_sku = it_record-field23.
translate it_record-field24 to upper case.
itab-val_type = it_record-field24.
itab-mat_slip = it_record-field25.
perform get_gl_account.
perform get_cost_center.
perform get_internal_order.
perform format_date using it_record-field26
changing itab-count_date.
itab-user_id = it_record-field27.
itab-file_name = file_name-name.
itab-seq_no = i.
itab-upload_userid = sy-uname.
itab-upload_date = sy-datum.
itab-mblnr = it_record-field28. "M9 add
append itab.
clear:itab.
i = i + 1.
endloop.
* endif.
ENDFORM. " GET_DATA
*&---------------------------------------------------------------------*
*& Form CHECK_ITAB
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM CHECK_ITAB .
loop at itab.
clear:itab-err_flag,itab-err_message.
lv_tabix = sy-tabix.
*Movement type
perform check_field using ' Movement type'
itab-move_type.
*Document date
perform check_field using ' Document date'
itab-doc_date.
*Posting date
perform check_field using ' Posting date'
itab-doc_date.
*M2 Remark
"Document header text
* perform check_field using ' Document header text'
* itab-header_txt.
*M2 End
if itab-move_type ne '601' and itab-move_type ne '602' . "*M8 add
"Plant
perform check_field using ' Plant'
itab-plant.
"Storage Location
perform check_field using ' Storage Location'
itab-stge_loc.
"Stock Category
perform check_field using ' Stock Category'
itab-stock_cat.
"Material Code
perform check_field using ' Material Code'
itab-mat_code.
"Quantity
perform check_field using ' Quantity'
itab-entry_qnt.
"Grid Value
perform check_field using ' Grid Value'
itab-grid_value.
* M2 Remark
"Vendor Batch
* perform check_field using ' Vendor Batch'
* itab-vendr_batch .
* M2 End
"RFID Batch
perform check_field using ' RFID Batch'
itab-rfid_batch .
endif.
"Receive RFID Batch
if itab-move_type = '309' or itab-move_type = '310' .
perform check_field using ' Receive RFID Batch'
itab-move_rfid_batch.
endif.
"Reason for Movement
if itab-move_type = '122' or itab-move_type = '123' or
itab-move_type = '309' or itab-move_type = '310' or
itab-move_type = '922' or itab-move_type = '923' .
perform check_field using ' Reason for Movement'
itab-move_reas .
endif.
"Receive Location
if itab-move_type = '311' or itab-move_type = '312' or
itab-move_type = '309' or itab-move_type = '310' .
perform check_field using ' Receive Location'
itab-move_stloc .
endif.
"Receive Stock Category Receive Material Code Receive Grid Receive Valuation Type
if itab-move_type = '309' or itab-move_type = '310' .
perform check_field using ' Receive Stock Category'
itab-move_stock_cat .
perform check_field using ' Receive Material Code'
itab-move_mat .
perform check_field using ' Receive Grid'
itab-move_grid_value .
perform check_field using ' Receive Valuation Type'
itab-move_val_type .
endif.
"Delivery note
if itab-move_type = '101' or itab-move_type = '102' or
itab-move_type = '122' or itab-move_type = '123' or
itab-move_type = '511' or itab-move_type = '512' or
itab-move_type = '922' or itab-move_type = '923' or
itab-move_type = '601' or itab-move_type = '602'. "M8 add
perform check_field using ' Delivery note'
itab-ref_doc.
endif.
"Purchase order PO Line Item No PO Schedule Line No
if itab-move_type = '101' or itab-move_type = '102' or
itab-move_type = '122' or itab-move_type = '123' or
itab-move_type = '922' or itab-move_type = '923' .
perform check_field using ' Purchase order'
itab-po_number.
perform check_field using ' PO Line Item No'
itab-po_item.
perform check_field using ' PO Schedule Line No'
itab-sched_line_sku.
endif.
"Valuation type
* if itab-move_type = '101' or itab-move_type = '102' or
* itab-move_type = '511' or itab-move_type = '512' .
perform check_field using ' Valuation type'
itab-val_type.
* endif.
"Material Slip
if itab-move_type = '991' or itab-move_type = '992' .
perform check_field using ' Material Slip'
itab-mat_slip .
endif.
"G/L Account
if itab-move_type = '261' or itab-move_type = '262' or
itab-move_type = '333' or itab-move_type = '334' or
itab-move_type = '551' or itab-move_type = '552' or
itab-move_type = '701' or itab-move_type = '702'.
perform check_field using ' G/L Account'
itab-gl_account.
endif.
"Internal Order
if itab-move_type = '261' or itab-move_type = '262' .
perform check_field using ' Internal Order'
itab-order_id.
endif.
"Cost Center
if itab-move_type = '333' or itab-move_type = '334' or
itab-move_type = '551' or itab-move_type = '552' or
itab-move_type = '701' or itab-move_type = '702'.
perform check_field using ' Cost Center'
itab-cost_center.
endif.
"Count date
if itab-move_type = '701' or itab-move_type = '702' or itab-move_type = '992'. "M7
perform check_field using ' Count date'
itab-count_date.
endif.
"User ID
if itab-move_type ne '601' and itab-move_type ne '602' . "M8 add
perform check_field using ' User ID'
itab-user_id.
endif .
endloop.
ENDFORM. " CHECK_ITAB
*&---------------------------------------------------------------------*
*& Form CHECK_FIELD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_1034 text
* -->P_ITAB_MOVE_TYPE text
* <--P_ITAB_ERR_FLAG text
* <--P_ITAB_ERR_MESSAGE text
*----------------------------------------------------------------------*
FORM CHECK_FIELD USING VALUE(p_value)
p_field.
if p_field is initial or p_field = space.
itab-err_flag = 'X'.
concatenate itab-err_message p_value ' is Empty.'
into itab-err_message.
modify itab index lv_tabix.
endif.
ENDFORM. " CHECK_FIELD
*&---------------------------------------------------------------------*
*& Form FITER_ERR_RECORD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FITER_ERR_RECORD .
i = 1.
loop at itab.
if itab-err_flag = 'X'.
move-corresponding itab to itab_err.
append itab_err.
else.
move-corresponding itab to itab_succ.
itab-seq_no = i.
append itab_succ.
i = i + 1 .
endif.
endloop.
itab_succ_tmp[] = itab_succ[].
itab_modify[] = itab_succ[].
ENDFORM. " FITER_ERR_RECORD
*&---------------------------------------------------------------------*
*& Form MOVE_FILE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM MOVE_FILE .
DATA: CMND LIKE SXPGCOLIST-NAME,
PARM LIKE SXPGCOLIST-PARAMETERS .
DATA: BEGIN OF OUT_DATA OCCURS 50.
INCLUDE STRUCTURE BTCXPM.
DATA: END OF OUT_DATA .
DATA: RTN_CH.
*< 1 >* Call LHA Command
* create system command
CMND = 'ZMOVE'. "<-- system command name. Refer "SM69"
********************************************************
* Configuration *
* operating system command : "cmd" *
* parameters for operating system command : "/c move" *
********************************************************
* MOVE need parameter "<source file> _ <target file>"
* move file_name-name to out_file.
concatenate a_dir_name '\' file_name-name into out_file.
concatenate a_dir_name '\COMPLETED\' into in_file.
concatenate out_file in_file into parm separated by space.
*call system command
CLEAR RTN_CH.
CALL FUNCTION 'SXPG_CALL_SYSTEM'
EXPORTING
COMMANDNAME = CMND
ADDITIONAL_PARAMETERS = PARM
* IMPORTING
* STATUS = RTN_CH
TABLES
EXEC_PROTOCOL = OUT_DATA
EXCEPTIONS
NO_PERMISSION = 01
COMMAND_NOT_FOUND = 02
PARAMETERS_TOO_LONG = 03
SECURITY_RISK = 04
WRONG_CHECK_CALL_INTERFACE = 05
PROGRAM_START_ERROR = 06
PROGRAM_TERMINATION_ERROR = 07
X_ERROR = 08
PARAMETER_EXPECTED = 09
TOO_MANY_PARAMETERS = 10
ILLEGAL_COMMAND = 11.
ENDFORM. " MOVE_FILE
*&---------------------------------------------------------------------*
*& Form CREATE_MOVETYPE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_0540 text
*----------------------------------------------------------------------*
FORM CREATE_MOVETYPE USING VALUE(p_function_Name).
data l_tabix type sy-tabix. "M9 add
clear : lv_seq_no.
lv_seq_no = itab_succ-seq_no.
move-corresponding itab_succ to itab_public.
append itab_public.
lv_seq_no = lv_seq_no + 1 .
sort itab_succ_tmp by seq_no. "M1
case itab_succ-move_type.
when '101' or '102' or '122' or '123'or '922' or '923'.
read table itab_succ_tmp with key seq_no = lv_seq_no
move_type = itab_succ-move_type
po_number = itab_succ-po_number
header_txt = itab_succ-header_txt binary search. "M6 Modify
when '511' or '512' or '309' or '310' or '311' or '312'
or '551' or '552'or '991' or '992' or '333' or '334'or '261' or '262'.
read table itab_succ_tmp with key seq_no = lv_seq_no
move_type = itab_succ-move_type
mat_code = itab_succ-mat_code
stock_cat = itab_succ-stock_cat
header_txt = itab_succ-header_txt binary search. "M6 Modify
when '701' or '702'.
read table itab_succ_tmp with key seq_no = lv_seq_no
doc_date = itab_succ-doc_date
count_date = itab_succ-count_date
plant = itab_succ-plant
stge_loc = itab_succ-stge_loc
move_type = '701' binary search.
if sy-subrc ne 0.
read table itab_succ_tmp with key seq_no = lv_seq_no
doc_date = itab_succ-doc_date
count_date = itab_succ-count_date
plant = itab_succ-plant
stge_loc = itab_succ-stge_loc
move_type = '702' binary search..
endif.
when '601' or '602'. "M8 add
read table itab_succ_tmp with key seq_no = lv_seq_no
move_type = itab_succ-move_type
ref_doc = itab_succ-ref_doc binary search.
*m5 add
* when '311' or '312'.
* read table itab_succ_tmp with key seq_no = lv_seq_no
* move_type = itab_succ-move_type
* mat_code = itab_succ-mat_code
* stock_cat = itab_succ-stock_cat
* header_txt = itab_succ-header_txt .
*M5 end
endcase.
if sy-subrc ne 0.
*M9 add
if itab_succ-move_type = '101' and g_flag_subcon = 'X'.
perform get_poGR_requirements.
perform update_ttable.
perform bdc_zme2o.
endif.
if itab_succ-move_type = '101' and g_flag_zme2o eq 'X' .
loop at itab_public.
loop at itab_modify where seq_no = itab_public-seq_no.
l_tabix = sy-tabix.
itab_modify-err_flag = 'X' .
itab_modify-err_message = zme2o_err .
itab_modify-mat_doc = itab_public-mat_doc .
itab_modify-com_date = itab_public-com_date .
modify itab_modify index l_tabix. "M9 modify
endloop.
endloop.
else.
if g_flag_subcon = 'X' and itab_succ-move_type = '101' .
perform bdc_migo.
refresh: ta_issue, ta_grid, ta_issue1.
clear: g_flag_subcon.
elseif g_flag_subcon = 'X' and itab_succ-move_type = '102'.
perform cancel_subcon_GR.
else.
*M9 end
call function p_function_Name
tables
goodsmvt_data = itab_public.
endif.
loop at itab_public.
loop at itab_modify where seq_no = itab_public-seq_no.
l_tabix = sy-tabix. "M9 add
itab_modify-err_flag = itab_public-err_flag .
itab_modify-err_message = itab_public-err_message .
* M9 add
if itab_modify-move_type = '101' and itab_modify-err_flag ne 'X'.
read table it_lack with key seq_no = itab_public-seq_no.
if sy-subrc = 0.
itab_modify-err_message = it_lack-err_message.
endif.
endif.
* M9 end
itab_modify-mat_doc = itab_public-mat_doc .
itab_modify-com_date = itab_public-com_date .
modify itab_modify index l_tabix. "M9 modify
endloop.
endloop.
endif. "M9 add endif.
*M9 add
if itab_succ-move_type = '101'.
read table itab_public index 1.
if itab_public-err_flag = 'X'.
perform reverse_scstock.
refresh: old_j3abdsi[], old_resb[].
else.
refresh: old_j3abdsi[], old_resb[].
endif.
clear g_flag_req .
elseif itab_succ-move_type = '102'.
read table itab_public index 1.
if itab_public-err_flag = 'X'.
endif.
clear g_flag_req .
endif.
*M9 end
clear g_flag_subcon. "M9 add
refresh itab_public.
clear:itab_public.
endif.
ENDFORM. " CREATE_MOVETYPE
*&---------------------------------------------------------------------*
*& Form GET_GL_ACCOUNT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GET_GL_ACCOUNT .
if itab-move_type = '261' or itab-move_type = '262' or
itab-move_type = '333' or itab-move_type = '334' or
itab-move_type = '551' or itab-move_type = '552' or
itab-move_type = '701' or itab-move_type = '702'.
select single * from mbew "bklas
where matnr = itab-mat_code
and bwkey = itab-plant.
* and bwtar = 'NORMAL'.
select single sakto into itab-gl_account from zrfid_gl_acct
where werks = itab-plant
and bwart = itab-move_type
and ( bklas = mbew-bklas or bklas = space ) .
endif.
ENDFORM. " GET_GL_ACCOUNT
*&---------------------------------------------------------------------*
*& Form GET_COST_CENTER
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GET_COST_CENTER .
data:lv_mat(3) type c.
clear:lv_mat.
if itab-move_type = '333' or itab-move_type = '334' or
itab-move_type = '551' or itab-move_type = '552' or
itab-move_type = '701' or itab-move_type = '702'.
lv_mat = itab-mat_code+0(3).
select single kostl into itab-cost_center from zrfid_cost_ctr
where werks = itab-plant
and bwart = itab-move_type
and ( zcust_code = lv_mat or zcust_code = space ).
endif.
ENDFORM. " GET_COST_CENTER
*&---------------------------------------------------------------------*
*& Form GET_INTERNAL_ORDER
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GET_INTERNAL_ORDER .
data:lv_ordt like zpp_fty_cctr.
if itab-move_type = '261' or itab-move_type = '262' .
select single ordt into lv_ordt from zpp_fty_cctr
where fty = itab-plant .
if sy-subrc eq 0.
concatenate itab-stock_cat '/' lv_ordt into itab-order_id.
endif.
endif.
ENDFORM. " GET_INTERNAL_ORDER
*&---------------------------------------------------------------------*
*& Form INSERT_ZRFID_GOODSMVT_TABLE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM INSERT_ZRFID_GOODSMVT_TABLE .
move-corresponding itab_last to zrfid_goodsmvt.
insert zrfid_goodsmvt.
ENDFORM. " INSERT_ZRFID_GOODSMVT_TABLE
*&---------------------------------------------------------------------*
*& Form GENERATE_EXCEL_FILE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GENERATE_EXCEL_FILE .
*M4 add
data l_time(6) type c.
l_time = sy-UZEIT.
*M4 end
data: l_date(8) type c.
concatenate sy-datum+0(4) sy-datum+4(2) sy-datum+6(2) into l_date.
concatenate 'CENGoodsMvt_' l_date '_' l_time into lv_mail_file . "m4 modify add time
condense lv_mail_file.
if local ne 'X' .
concatenate a_dir_name '\LOG\' lv_mail_file '.xls' into gv_file.
loop at it_output.
concatenate it_output-field01
it_output-field02
it_output-field03
it_output-field04
it_output-field05
it_output-field06
it_output-field07
it_output-field08
it_output-field09
it_output-field10
it_output-field11
it_output-field12
it_output-field13
it_output-field14
it_output-field15
it_output-field16
it_output-field17
it_output-field18
it_output-field19
it_output-field20
it_output-field21
it_output-field22
it_output-field23
it_output-field24
it_output-field25
it_output-field26
it_output-field27
it_output-field28
it_output-field29
*M4 add
it_output-field30
it_output-field31
it_output-field32
it_output-field33
it_output-field34
it_output-field35
it_output-field36
it_output-field37
it_output-field38
it_output-field39
it_output-field40
it_output-field41
it_output-field42
it_output-field43
it_output-field44
it_output-field45
*M4 end
into it_file separated by CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
condense it_file.
append it_file .
endloop.
open dataset gv_file for output in text mode encoding default.
loop at it_file.
transfer it_file-line to gv_file.
endloop.
close dataset gv_file.
perform Auto_send_email.
else.
data : lv_string type string.
concatenate 'D:\' lv_mail_file '.xls' into in_file.
lv_string = in_file.
* CALL FUNCTION 'WS_EXCEL'
* EXPORTING
* FILENAME = in_file
* TABLES
* DATA = it_output.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = lv_string
filetype = 'DAT'
codepage = '4103'
replacement = '#'
write_field_separator = 'X'
write_bom = 'X'
TABLES
data_tab = it_output.
if sy-subrc eq 0.
* --- show document in the XLS Reader ---
cl_gui_frontend_services=>execute( EXPORTING document = lv_string
EXCEPTIONS cntl_error = 1
error_no_gui = 2
bad_parameter = 3
file_not_found = 4
path_not_found = 5
file_extension_unknown = 6
error_execute_failed = 7
synchronous_failed = 8
not_supported_by_gui = 9
OTHERS = 10 ).
endif.
endif.
ENDFORM. " GENERATE_EXCEL_FILE
*&---------------------------------------------------------------------*
*& Form GENERATE_EXCEL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GENERATE_EXCEL .
it_output-field01 = itab_last-move_type .
perform out_date_format using itab_last-doc_date
changing it_output-field02.
perform out_date_format using itab_last-pstng_date
changing it_output-field03.
it_output-field04 = itab_last-header_txt .
it_output-field05 = itab_last-plant .
it_output-field06 = itab_last-stge_loc .
it_output-field07 = itab_last-stock_cat .
it_output-field08 = itab_last-mat_code .
it_output-field09 = itab_last-entry_qnt .
it_output-field10 = itab_last-grid_value .
it_output-field11 = itab_last-vendr_batch .
it_output-field12 = itab_last-rfid_batch .
it_output-field13 = itab_last-move_rfid_batch .
it_output-field14 = itab_last-move_reas .
it_output-field15 = itab_last-move_stloc .
it_output-field16 = itab_last-move_stock_cat .
it_output-field17 = itab_last-move_mat .
it_output-field18 = itab_last-move_grid_value .
it_output-field19 = itab_last-move_val_type .
it_output-field20 = itab_last-ref_doc .
it_output-field21 = itab_last-po_number .
it_output-field22 = itab_last-po_item .
it_output-field23 = itab_last-sched_line_sku .
it_output-field24 = itab_last-val_type .
it_output-field25 = itab_last-mat_slip.
perform out_date_format using itab_last-count_date
changing it_output-field26.
it_output-field27 = itab_last-user_id .
it_output-field28 = itab_last-mat_doc .
it_output-field29 = itab_last-err_message .
*M4 add
if itab_last-mat_doc is not initial.
perform get_from_mseg using itab_last-mat_doc
itab_last-mat_code
itab_last-grid_value
itab_last-rfid_batch .
endif.
*M4 end
append it_output.
clear:it_output.
ENDFORM. " GENERATE_EXCEL
*&---------------------------------------------------------------------*
*& Form GET_LAST_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GET_LAST_DATA .
i = 1 .
loop at itab_modify .
move-corresponding itab_modify to itab_last.
append itab_last.
i = i + 1 .
endloop.
loop at itab_err.
move-corresponding itab_err to itab_last.
itab_last-seq_no = i.
append itab_last.
i = i + 1 .
endloop.
ENDFORM. " GET_LAST_DATA
*&---------------------------------------------------------------------*
*& Form EXCEL_HEADER
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM EXCEL_HEADER .
it_output-field01 = 'Movement type'.
it_output-field02 = 'Document date' .
it_output-field03 = 'Posting date' .
it_output-field04 = 'Document header text' .
it_output-field05 = 'Plant' .
it_output-field06 = 'Storage Location' .
it_output-field07 = 'Stock Category' .
it_output-field08 = 'Material Code' .
it_output-field09 = 'Quantity' .
it_output-field10 = 'Grid Value'.
it_output-field11 = 'Vendor Batch' .
it_output-field12 = 'RFID Batch'.
it_output-field13 = 'Receive RFID Batch' .
it_output-field14 = 'Reason for Movement' .
it_output-field15 = 'Receive Location'.
it_output-field16 = 'Receive Stock Category'.
it_output-field17 = 'Receive Material Code' .
it_output-field18 = 'Receive Grid' .
it_output-field19 = 'Receive Valuation Type' .
it_output-field20 = 'Delivery note' .
it_output-field21 = 'Purchase order' .
it_output-field22 = 'PO Line Item No'.
it_output-field23 = 'PO Schedule Line No' .
it_output-field24 = 'Valuation type' .
it_output-field25 = 'Material Slip'.
it_output-field26 = 'Count date' .
it_output-field27 = 'User ID' .
it_output-field28 = 'Material Document Number' .
it_output-field29 = 'Message' .
*M4 add
it_output-field30 = 'Movement Type'.
it_output-field31 = 'Document Date'.
it_output-field32 = 'Posting Date'.
it_output-field33 = 'Plant'.
it_output-field34 = 'Storage Location'.
it_output-field35 = 'Stock Category'.
it_output-field36 = 'Material code'.
it_output-field37 = 'QTY'.
it_output-field38 = 'Grid Value'.
it_output-field39 = 'Vendor batch'.
it_output-field40 = 'System batch'.
it_output-field41 = 'Receive Location'.
it_output-field42 = 'Receive Stock Category'.
it_output-field43 = 'Receive Material code'.
it_output-field44 = 'Receive Grid'.
it_output-field45 = 'Receive Valuation Type'.
*M4 end
append it_output.
clear:it_output.
ENDFORM. " EXCEL_HEADER
*&---------------------------------------------------------------------*
*& Form OUT_DATE_FORMAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_ITAB_LAST_DOC_DATE text
* <--P_IT_OUTPUT_FIELD02 text
*----------------------------------------------------------------------*
FORM OUT_DATE_FORMAT USING p_date
CHANGING t_output.
if not p_date is initial and p_date ne space.
concatenate p_date+6(2) p_date+4(2) p_date+0(4)
into t_output separated by '/'.
condense t_output.
endif.
ENDFORM. " OUT_DATE_FORMAT
*&---------------------------------------------------------------------*
*& Form UPLOAD_FILE_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM UPLOAD_FILE_DATA .
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = lv_file_upld
FILETYPE = 'DAT'
HAS_FIELD_SEPARATOR = 'X'
* codepage = '4103'
TABLES
DATA_TAB = i_file
EXCEPTIONS
FILE_OPEN_ERROR = 1
FILE_READ_ERROR = 2
NO_BATCH = 3
GUI_REFUSE_FILETRANSFER = 4
INVALID_TYPE = 5
NO_AUTHORITY = 6
UNKNOWN_ERROR = 7
BAD_DATA_FORMAT = 8
HEADER_NOT_ALLOWED = 9
SEPARATOR_NOT_ALLOWED = 10
HEADER_TOO_LONG = 11
UNKNOWN_DP_ERROR = 12
ACCESS_DENIED = 13
DP_OUT_OF_MEMORY = 14
DISK_FULL = 15
DP_TIMEOUT = 16
OTHERS = 17.
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. " UPLOAD_FILE_DATA
*&---------------------------------------------------------------------*
*& Form AUTO_SEND_EMAIL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM AUTO_SEND_EMAIL .
data: binary_content type solix_tab.
data: conlength type i,
conlengths type so_obj_len,
result_content type string,
wa_string type string, "This holds all of your data
wa_str_temp type string.
data: send_request type ref to cl_bcs.
data: text type bcsy_text.
data: document type ref to cl_document_bcs.
data: sender type ref to if_sender_bcs.
data: recipient type ref to if_recipient_bcs.
data: bcs_exception type ref to cx_bcs.
data: sent_to_all type os_boolean.
data: wa_rec type ad_smtpadr .
data: bcs_message type string .
data: subject type so_obj_des.
data: sender_id type ad_smtpadr.
data: zto like zemail_to occurs 0 with header line,
zcc like zemail_cc occurs 0 with header line.
data:lv_err_flag type c .
refresh binary_content .
clear: wa_string,zto[], zcc[],lv_err_flag,mc_filename.
loop at it_output.
clear wa_str_temp.
concatenate it_output-field01
it_output-field02
it_output-field03
it_output-field04
it_output-field05
it_output-field06
it_output-field07
it_output-field08
it_output-field09
it_output-field10
it_output-field11
it_output-field12
it_output-field13
it_output-field14
it_output-field15
it_output-field16
it_output-field17
it_output-field18
it_output-field19
it_output-field20
it_output-field21
it_output-field22
it_output-field23
it_output-field24
it_output-field25
it_output-field26
it_output-field27
it_output-field28
it_output-field29
*M4 add
it_output-field30
it_output-field31
it_output-field32
it_output-field33
it_output-field34
it_output-field35
it_output-field36
it_output-field37
it_output-field38
it_output-field39
it_output-field40
it_output-field41
it_output-field42
it_output-field43
it_output-field44
it_output-field45
*M4 end
into wa_str_temp separated by CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
concatenate wa_str_temp
cl_abap_char_utilities=>horizontal_tab
cl_abap_char_utilities=>cr_lf into wa_str_temp.
if wa_string is initial.
wa_string = wa_str_temp.
else.
concatenate wa_string wa_str_temp into wa_string.
endif.
endloop.
data: lp_size type so_obj_len.
try.
cl_bcs_convert=>string_to_solix(
exporting
iv_string = wa_string
iv_codepage = '4103'
iv_add_bom = 'X'
importing
et_solix = binary_content
ev_size = lp_size ).
* delete binary_content index 1.
* if sy-subrc = 0.
* lp_size = lp_size - 255.
* endif.
catch cx_bcs.
message e445(so).
endtry.
****-----
read table itab_last with key err_flag = 'X'.
if sy-subrc eq 0 .
lv_err_flag = 'X'.
endif.
clear result_content .
if lv_err_flag = 'X'.
subject = 'CMH RFID interface file upload status ¨C Failure'.
concatenate
result_content
'<p><font color="#000080">Pls be noted that the RFID interface file uploaded failure, pls take immediately follow-up action.</font></p>'
into result_content .
else.
subject = 'CMH RFID interface file upload status ¨C Successful'.
concatenate
result_content
'<p><font color="#000080">Pls be noted that the RFID interface file uploaded successfully.</font></p>'
into result_content .
endif.
conlength = strlen( result_content ) .
conlengths = conlength .
sender_id = 'WF-BATCH@CRYSTALGROUP.COM'.
call function 'SCMS_STRING_TO_FTEXT'
exporting
text = result_content
tables
ftext_tab = text.
concatenate lv_mail_file '.xls' into mc_filename.
try.
clear send_request .
send_request = cl_bcs=>create_persistent( ).
clear document .
document = cl_document_bcs=>create_document(
i_type = 'HTM'
i_text = text
i_length = conlengths
i_subject = subject ).
call method document->add_attachment
exporting
i_attachment_type = 'EXT'
i_attachment_subject = mc_filename "Attachment name
i_attachment_size = lp_size
I_ATTACHMENT_LANGUAGE = '1'
i_att_content_hex = binary_content.
* add document to send request
call method send_request->set_document( document ).
clear sender .
sender = cl_cam_address_bcs=>create_internet_address( sender_id ).
call method send_request->set_sender
exporting
i_sender = sender.
clear wa_rec .
select * from zrfid_email where bukrs = lv_bukrs
and ZEMAIL_TYPE = 'TO'.
zto-to = zrfid_email-zemail.
collect zto.
endselect.
select * from zrfid_email where bukrs = lv_bukrs
and ZEMAIL_TYPE = 'CC'.
zcc-cc = zrfid_email-zemail.
collect zcc.
endselect.
loop at zto.
clear recipient .
wa_rec = zto-to.
recipient = CL_CAM_ADDRESS_BCS=>create_internet_address(
wa_rec ).
call method send_request->add_recipient
exporting
i_recipient = recipient.
* i_express = 'X'.
endloop.
loop at zcc.
clear recipient .
wa_rec = zcc-cc.
recipient = CL_CAM_ADDRESS_BCS=>create_internet_address(
wa_rec ).
call method send_request->add_recipient
exporting
i_recipient = recipient
i_copy = 'X'.
* i_express = 'X'.
endloop.
call method send_request->set_status_attributes
exporting
i_requested_status = 'E'
i_status_mail = 'E'.
call method send_request->set_send_immediately( 'X' ).
* ---------- send document ---------------------------------------
call method send_request->send(
exporting
i_with_error_screen = 'X'
RECEIVING
result = sent_to_all ).
if sent_to_all = 'X'.
* APPEND 'Mail sent successfully ' TO return .
endif.
commit work.
catch cx_bcs into bcs_exception.
bcs_message = bcs_exception->get_text( ).
* APPEND bcs_message TO return .
exit.
endtry.
ENDFORM. " AUTO_SEND_EMAIL
*&---------------------------------------------------------------------*
*& Form DELETE_ZRFID_GOODSMVT_TABLE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM DELETE_ZRFID_GOODSMVT_TABLE .
data:lv_upload_date like zrfid_goodsmvt-upload_date.
lv_upload_date = sy-datum - 30.
delete from zrfid_goodsmvt where upload_date < lv_upload_date .
ENDFORM. " DELETE_ZRFID_GOODSMVT_TABLE
*&---------------------------------------------------------------------*
*& Form READ_FILE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM READ_FILE .
clear:it_filter[].
it_filter-name = 'rfid'.
append it_filter.
TRANSLATE A_DIR_NAME TO LOWER CASE.
call function 'Z_UPLOAD_FILE_BY_FOLDER'
exporting
DIR_NAME = A_DIR_NAME
FILENAME_EXTENSION = '.txt'
tables
ZFILE_NAME = file_name
filename_filter = it_filter.
ENDFORM. " READ_FILE
*&---------------------------------------------------------------------*
*& Form UPDATE_ZPP_ISS_DOC_LOG
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM UPDATE_ZPP_ISS_DOC_LOG .
data: wa_log_temp type zpp_iss_doc_log.
data: seqno1 type i,
seqno2 type i.
loop at itab_last.
" add 'or itab_last-mat_slip is initial. ' on 2012.03.23 request by vincent
if itab_last-move_type <> '311' or itab_last-mat_doc is initial or itab_last-mat_slip is initial.
skip.
else.
itab_log-zrefno = itab_last-mat_slip.
itab_log-werks = itab_last-plant.
itab_log-mblnr = itab_last-mat_doc.
append itab_log.
endif.
endloop.
sort itab_log.
delete adjacent duplicates from itab_log.
loop at itab_log.
clear: wa_log_temp, lv_tabix.
seqno1 = 0.
select * into wa_log_temp from zpp_iss_doc_log
where zrefno = itab_log-zrefno
and werks = itab_log-werks.
seqno2 = wa_log_temp-seqno.
if seqno2 > seqno1.
seqno1 = seqno2.
endif.
endselect.
seqno1 = seqno1 + 1.
itab_log-seqno = seqno1.
itab_log-cpudt = sy-datum.
itab_log-cputm = sy-uzeit.
itab_log-ernam = sy-uname.
lv_tabix = sy-tabix.
modify itab_log index lv_tabix.
insert zpp_iss_doc_log from itab_log.
if sy-subrc ne 0.
loop at itab_last
where mat_slip = itab_log-zrefno
and plant = itab_log-werks
and mat_doc = itab_log-mblnr.
clear: lv_tabix_last.
lv_tabix_last = sy-tabix.
itab_last-err_flag = 'X'.
concatenate itab_last-err_message ' However, it is failed to update the log table.' into itab_last-err_message.
modify itab_last index lv_tabix_last.
endloop.
endif.
sy-tabix = lv_tabix.
endloop.
ENDFORM. " UPDATE_ZPP_ISS_DOC_LOG
*&---------------------------------------------------------------------*
*& Form GET_FROM_MSEG
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_ITAB_LAST_MAT_DOC text
*----------------------------------------------------------------------*
*M4 add
FORM GET_FROM_MSEG USING P_mblnr
p_matnr
p_size
p_charg.
select single a~bwart b~bldat b~budat a~werks a~lgort a~j_4ksca a~matnr
a~erfmg a~j_3asiz a~charg a~umlgo a~j_4kumsc a~ummat a~j_3aumsi a~umbar
into (itab_last-bwart , itab_last-bldat, itab_last-budat, itab_last-werks, itab_last-lgort, itab_last-j_4ksca,
itab_last-matnr, itab_last-erfmg, itab_last-j_3asiz, itab_last-charg, itab_last-umlgo,
itab_last-j_4kumsc, itab_last-ummat, itab_last-j_3aumsi, itab_last-umbar)
from mseg as a
inner join mkpf as b on a~mblnr = b~mblnr
where a~mblnr = p_mblnr
and a~matnr = p_matnr
and a~charg = p_charg
and a~j_3asiz = p_size.
select single licha into itab_last-licha from mcha
where matnr = p_matnr
and werks = itab_last-werks
and charg = itab_last-charg.
it_output-field30 = itab_last-bwart.
*it_output-field31 = itab_last-bldat.
*it_output-field32 = itab_last-budat.
perform out_date_format using itab_last-bldat
changing it_output-field31.
perform out_date_format using itab_last-budat
changing it_output-field32.
it_output-field33 = itab_last-werks.
it_output-field34 = itab_last-lgort.
it_output-field35 = itab_last-j_4ksca.
it_output-field36 = itab_last-matnr.
it_output-field37 = itab_last-erfmg.
it_output-field38 = itab_last-j_3asiz.
it_output-field39 = itab_last-licha.
it_output-field40 = itab_last-charg.
it_output-field41 = itab_last-umlgo.
it_output-field42 = itab_last-j_4kumsc.
it_output-field43 = itab_last-ummat.
it_output-field44 = itab_last-j_3aumsi.
it_output-field45 = itab_last-umbar.
*M4 end
ENDFORM. " GET_FROM_MSEG
*&---------------------------------------------------------------------*
*& Form PROCESS_SUBCON_PO
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
*M9 add
FORM PROCESS_SUBCON_PO .
check g_flag_subcon = 'X'.
perform get_poRequire.
ENDFORM. " PROCESS_SUBCON_PO
*M9 end
*&---------------------------------------------------------------------*
*& Form GET_POREQUIRE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GET_POREQUIRE .
refresh: old_j3abdsi[], old_resb[].
clear: old_j3abdsi, old_resb.
data l_index type i.
refresh it_Req. clear it_req.
*if g_flag_req ne 'X'.
select * into table old_j3abdsi
from j_3abdsi
where aufnr eq itab_succ-po_number
and werks eq itab_succ-plant.
* and J_4KRCAT eq itab_succ-STOCK_CAT.
select * into table old_resb
from resb
where ebeln eq itab_succ-po_number
and werks eq itab_succ-plant.
* and j_4kscat eq itab_succ-STOCK_CAT.
loop at old_resb.
l_index = sy-tabix.
it_req-ebeln = old_resb-ebeln.
it_req-ebelp = old_resb-ebelp.
it_req-etenr = old_resb-ebele.
it_req-baugr = old_resb-baugr.
it_req-matnr = old_resb-matnr.
it_req-j_3asize = old_resb-j_3asize.
it_req-j_3astmeng = old_resb-j_3astmeng.
it_req-j_3astmein = old_resb-j_3astmein.
select single bmeng from stko into it_req-bmeng
where stlnr = old_resb-stlnr.
select single meins into it_req-meins from ekpo
where ebeln = old_resb-ebeln and ebelp = old_resb-ebelp.
append it_req.
endloop.
* g_flag_req = 'X'.
*
*endif.
ENDFORM. " GET_POREQUIRE
*&---------------------------------------------------------------------*
*& Form UPDATE_POREQUIRE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_IT_MCHB_CLABS text
*----------------------------------------------------------------------*
FORM UPDATE_POREQUIRE USING P_value.
clear: j_3abdsi , resb.
select single * from j_3abdsi
where matnr = old_j3abdsi-matnr
and aufnr = itab_succ-po_number
and posnr = itab_succ-po_item
and j_3asize = old_j3abdsi-j_3asize
and rsnum = old_j3abdsi-rsnum.
if sy-subrc = 0.
j_3abdsi-erfmg = p_value.
j_3abdsi-nomng = p_value.
j_3abdsi-menge = p_value.
j_3abdsi-aedat = sy-datum.
j_3abdsi-utime = sy-uzeit.
j_3abdsi-uname = sy-uname.
update j_3abdsi.
select single * from resb where rsnum = old_j3abdsi-rsnum
and matnr = old_j3abdsi-matnr
and j_3asize = old_j3abdsi-j_3asize.
if sy-subrc = 0.
resb-erfmg = p_value.
resb-nomng = p_value.
resb-bdmng = p_value.
update resb.
endif.
endif.
ENDFORM. " UPDATE_POREQUIRE
*----------------------------------------------------------------------*
* Start new screen *
*----------------------------------------------------------------------*
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
CLEAR BDCDATA.
BDCDATA-PROGRAM = PROGRAM.
BDCDATA-DYNPRO = DYNPRO.
BDCDATA-DYNBEGIN = 'X'.
APPEND BDCDATA.
ENDFORM.
*----------------------------------------------------------------------*
* Insert field *
*----------------------------------------------------------------------*
FORM BDC_FIELD USING FNAM FVAL.
* IF FVAL <> NODATA.
CLEAR BDCDATA.
BDCDATA-FNAM = FNAM.
BDCDATA-FVAL = FVAL.
APPEND BDCDATA.
* ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form BDC_ZME2O
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM BDC_ZME2O .
clear: g_flag_zme2o, zme2o_err.
data:lv_count type i,
lv_item(5) type c value '08/03'.
clear: messtab. refresh messtab.
data wa_budat(8) type c.
concatenate sy-datum+6(2) sy-datum+4(2) sy-datum(4) into wa_budat.
*concatenate itab_succ-PSTNG_DATE+6(2) itab_succ-PSTNG_DATE+4(2) itab_succ-PSTNG_DATE(4) into wa_budat.
*concatenate itab_succ-PSTNG_DATE+6(2) '.' itab_succ-PSTNG_DATE+4(2) '.'itab_succ-PSTNG_DATE(4) into wa_budat.
perform bdc_dynpro using 'ZRM06ELLB4' '1000'.
perform bdc_field using 'BDC_CURSOR'
'S_FR'.
perform bdc_field using 'BDC_OKCODE'
'=ONLI'.
perform bdc_field using 'S_LIFNR-LOW'
' '.
* wa_pogr-lifnr.
perform bdc_field using 'P_CONV'
'SY'.
perform bdc_field using 'P_SCREQ'
'X'.
perform bdc_field using 'P_TPSCR'
'X'.
perform bdc_field using 'P_TPSCP'
'X'.
*** U1
perform bdc_field using 'P_BATGRP'
'X'.
*** end of U1
perform bdc_field using 'S_EBELN'
itab_succ-po_number.
perform bdc_field using 'S_LGORT'
itab_succ-mat_slip.
* perform bdc_field using 'S_FR'
* wa_pogr-fr.
perform bdc_field using 'S_FR'
' '.
perform bdc_field using 'S_BUDAT'
wa_BUDAT.
perform bdc_dynpro using 'SAPMSSY0' '0120'.
perform bdc_field using 'BDC_OKCODE'
'=EXPA'.
perform bdc_dynpro using 'SAPMSSY0' '0120'.
perform bdc_field using 'BDC_CURSOR'
'11/05'.
perform bdc_field using 'BDC_OKCODE'
'=MALL'.
perform bdc_dynpro using 'SAPMSSY0' '0120'.
perform bdc_field using 'BDC_CURSOR'
'11/05'.
perform bdc_field using 'BDC_OKCODE'
'=WABU'.
perform bdc_transaction using 'ZME2OA'.
describe table messtab.
read table messtab index sy-tfill.
* it_po-ebeln = messtab-msgv2. "M3 remove
if l_subrc eq 0 .
clear g_flag_zme2o .
else.
g_flag_zme2o = 'X' .
move 'ZME2OA Error' to zme2o_err.
endif.
ENDFORM. " BDC_ZME2O
*&---------------------------------------------------------------------*
*& Form BDC_TRANSACTION
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_4171 text
*----------------------------------------------------------------------*
FORM BDC_TRANSACTION USING tcode.
DATA: L_MSTRING(480).
DATA: WA_PARAMS TYPE CTU_PARAMS.
REFRESH MESSTAB.
WA_PARAMS-DISMODE = 'N'.
WA_PARAMS-UPDMODE = 'L'. ".'S'. "L --> local
WA_PARAMS-DEFSIZE = 'X'.
CALL TRANSACTION TCODE USING BDCDATA OPTIONS FROM WA_PARAMS
MESSAGES INTO MESSTAB.
L_SUBRC = SY-SUBRC.
read table MESSTAB with key MSGTYP = 'E'.
if sy-subrc eq 0.
SELECT SINGLE * FROM T100 WHERE SPRSL = MESSTAB-MSGSPRA
AND ARBGB = MESSTAB-MSGID
AND MSGNR = MESSTAB-MSGNR.
IF SY-SUBRC = 0.
L_MSTRING = T100-TEXT.
IF L_MSTRING CS '&1'.
REPLACE '&1' WITH MESSTAB-MSGV1 INTO L_MSTRING.
REPLACE '&2' WITH MESSTAB-MSGV2 INTO L_MSTRING.
REPLACE '&3' WITH MESSTAB-MSGV3 INTO L_MSTRING.
REPLACE '&4' WITH MESSTAB-MSGV4 INTO L_MSTRING.
ELSE.
REPLACE '&' WITH MESSTAB-MSGV1 INTO L_MSTRING.
REPLACE '&' WITH MESSTAB-MSGV2 INTO L_MSTRING.
REPLACE '&' WITH MESSTAB-MSGV3 INTO L_MSTRING.
REPLACE '&' WITH MESSTAB-MSGV4 INTO L_MSTRING.
ENDIF.
CONDENSE L_MSTRING.
.
* message e058(zpp01) with l_mstring(250).
ENDIF.
endif.
REFRESH BDCDATA.
ENDFORM. " BDC_TRANSACTION
*&---------------------------------------------------------------------*
*& Form REVERSE_SCSTOCK
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM REVERSE_SCSTOCK .
data wa_mblnr like mseg-mblnr.
data wa_mjahr like mseg-mjahr.
data wa_budat like mkpf-budat.
data: ret like BAPIRET2 occurs 0 with header line.
select mblnr mjahr into (wa_mblnr,
wa_mjahr) from mseg
where ebeln = itab_succ-po_number
and bwart = '541'
order by mblnr descending.
exit.
endselect.
check sy-subrc = 0.
select single budat into wa_budat from mkpf
where mblnr = wa_mblnr
and mjahr = wa_mjahr.
CALL FUNCTION 'BAPI_GOODSMVT_CANCEL'
EXPORTING
MATERIALDOCUMENT = wa_mblnr
MATDOCUMENTYEAR = wa_mjahr
GOODSMVT_PSTNG_DATE = wa_budat
TABLES
RETURN = ret.
read table ret with key type = 'E'.
if sy-subrc eq 0.
* message w999(zmrr) with ret-message.
else.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
* destination cn_rfc
EXPORTING
WAIT = 'X'.
endif.
wait up to 1 seconds.
ENDFORM. " REVERSE_SCSTOCK
*&---------------------------------------------------------------------*
*& Form REVERSE_POREQUIRE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM REVERSE_POREQUIRE .
check g_flag_adj eq 'X'.
check old_j3abdsi[] is not initial.
modify j_3abdsi from table old_j3abdsi.
modify resb from table old_resb.
clear: old_j3abdsi[], old_resb[].
clear g_flag_adj.
ENDFORM. " REVERSE_POREQUIRE
*&---------------------------------------------------------------------*
*& Form UPDATE_TTABLE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM UPDATE_TTABLE .
SELECT * FROM T158 WHERE TCODE = 'ME2O'.
T158-TCODE = 'ZME2OA'.
MODIFY T158.
ENDSELECT.
SELECT * FROM T156N WHERE FCODE = 'ME2O'.
T156N-FCODE = 'ZME2OA'.
MODIFY T156N.
ENDSELECT.
SELECT * FROM T158B WHERE TCODE = 'ME2O'.
T158B-TCODE = 'ZME2OA'.
MODIFY T158B.
ENDSELECT.
ENDFORM. " UPDATE_TTABLE
*&---------------------------------------------------------------------*
*& Form GET_POGR_REQUIREMENTS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GET_POGR_REQUIREMENTS .
data l_index type sy-tabix.
data l_grqty like resb-erfmg.
data l_reqty like ekpo-menge.
data l_lack like ekpo-menge.
data lc_lack type string.
refresh it_lack.
refresh: ta_issue, it_mchb.
data l_mes type string.
data l_msg type string.
loop at itab_public.
clear l_msg.
l_grqty = itab_public-ENTRY_QNT.
refresh it_mchb.
select distinct b~lgort a~matnr a~j_3asize b~clabs into it_mchb from mchb as b
inner join j_3abdsi as a on a~matnr = b~matnr and a~j_3asize = b~j_3asize"lv_clabs
where b~j_4kscat = itab_public-stock_cat
and a~aufnr = itab_public-po_number
and b~lgort = itab_public-mat_slip
and b~j_3asize = itab_public-grid_value
and b~clabs > 0.
collect it_mchb.
endselect.
" get the GR qty with base unit
loop at it_req where baugr = itab_public-MAT_CODE
and ebeln = itab_public-po_number
and ebelp = itab_public-po_item
and etenr = itab_public-sched_line_sku.
clear: lc_lack, l_lack.
l_index = sy-tabix.
if it_req-meins ne it_req-j_3astmein and it_req-meins ne space.
CALL FUNCTION 'MD_CONVERT_MATERIAL_UNIT'
EXPORTING
i_matnr = it_req-baugr
i_in_me = it_req-meins
i_out_me = it_req-j_3astmein
i_menge = itab_public-ENTRY_QNT
IMPORTING
e_menge = l_grqty
EXCEPTIONS
error_in_application = 1
error = 2
OTHERS = 3.
endif.
if it_req-bmeng ne 0.
l_reqty = l_grqty * it_req-j_3astmeng / it_req-bmeng.
endif.
read table it_mchb with key matnr = it_req-matnr
j_3asize = it_req-j_3asize.
if sy-subrc = 0.
l_lack = l_reqty - it_mchb-clabs.
else.
l_lack = l_reqty .
endif.
if l_lack > 0.
lc_lack = l_lack.
concatenate it_req-matnr it_req-j_3asize 'lack of quantity: ' lc_lack into l_mes separated by space.
if l_index > 1.
concatenate l_msg ';' l_mes into l_msg.
else.
l_msg = l_mes.
endif.
endif.
endloop.
condense l_msg.
if l_msg ne space.
move-corresponding itab_public to it_lack .
it_lack-err_message = l_msg.
append it_lack.
endif.
endloop.
"---------------------------------------------
perform get_grid.
loop at itab_public.
clear ta_issue.
ta_issue-matnr = itab_public-mat_code.
ta_issue-value = itab_public-grid_value.
* read table it_req with key baugr = ta_issue-matnr.
* if sy-subrc = 0.
* ta_issue-meins = j_3astmein..
* endif.
ta_issue-j_4kscat = itab_public-stock_cat.
* ta_issue-werks = itab_public-plant.
select single charg into ta_issue-charg
from eket
where ebeln = itab_public-po_number
and ebelp = itab_public-PO_ITEM
and etenr = itab_public-SCHED_LINE_SKU.
* ta_issue-sort = '01'.
append ta_issue.
endloop.
loop at ta_grid.
l_index = sy-tabix.
read table itab_public with key po_item = ta_grid-ebelp
SCHED_LINE_SKU = ta_grid-sl
mat_code = ta_grid-matnr
grid_value = ta_grid-value.
if sy-subrc = 0.
ta_grid-qty = itab_public-ENTRY_QNT.
ta_grid-sel = 'X'.
modify ta_Grid index l_index.
endif.
endloop.
loop at itab_public.
l_grqty = itab_public-ENTRY_QNT.
" get the GR qty with base unit
read table it_req with key ebeln = itab_public-po_number
ebelp = itab_public-PO_ITEM
baugr = itab_public-MAT_CODE.
if sy-subrc = 0.
if it_req-meins ne it_req-j_3astmein and it_req-meins ne space.
CALL FUNCTION 'MD_CONVERT_MATERIAL_UNIT'
EXPORTING
i_matnr = it_req-baugr
i_in_me = it_req-meins
i_out_me = it_req-j_3astmein
i_menge = itab_public-ENTRY_QNT
IMPORTING
e_menge = l_grqty
EXCEPTIONS
error_in_application = 1
error = 2
OTHERS = 3.
endif.
endif.
loop at old_j3abdsi where posnr = itab_public-po_item
and j_4krcat = itab_public-stock_cat
and j_3asize = itab_public-grid_value
and j_3aetenr = itab_public-sched_line_sku .
clear ta_issue.
read table ta_grid with key ebelp = itab_public-po_item
sl = itab_public-sched_line_sku
value = itab_public-grid_value.
if sy-subrc = 0.
ta_issue-row = ta_grid-row.
endif.
* ta_issue-sort = '02'.
ta_issue-matnr = old_j3abdsi-matnr.
ta_issue-value = old_j3abdsi-j_3asize.
ta_issue-j_4kscat = itab_public-stock_cat.
ta_issue-werks = itab_public-plant.
select single charg into ta_issue-charg
from eket
where ebeln = itab_public-po_number
and ebelp = itab_public-PO_ITEM
and etenr = itab_public-SCHED_LINE_SKU.
clear it_mchb.
clear l_reqty.
*---------------------------
read table it_req with key ebeln = itab_succ-po_number
ebelp = itab_succ-PO_ITEM
baugr = itab_succ-MAT_CODE
matnr = old_j3abdsi-matnr
j_3asize = old_j3abdsi-j_3asize.
ta_issue-meins = it_req-j_3astmein.
refresh it_mchb.
select distinct b~lgort a~matnr a~j_3asize b~clabs into it_mchb from mchb as b
inner join j_3abdsi as a on a~matnr = b~matnr and a~j_3asize = b~j_3asize"lv_clabs
where b~j_4kscat = itab_public-stock_cat
and a~aufnr = itab_public-po_number
and b~lgort = itab_public-mat_slip
and b~j_3asize = itab_public-grid_value
and b~clabs > 0.
collect it_mchb.
endselect.
read table it_mchb with key matnr = old_j3abdsi-matnr
j_3asize = old_j3abdsi-j_3asize.
l_index = sy-tabix.
if sy-subrc = 0.
if it_mchb-clabs > 0.
if sy-subrc = 0.
l_reqty = l_grqty * it_req-j_3astmeng / it_req-bmeng.
endif.
if l_reqty > it_mchb-clabs.
ta_issue-qty = it_mchb-clabs.
g_flag_adj = 'X'.
it_mchb-clabs = 0.
modify it_mchb index l_index.
else.
ta_issue-qty = l_reqty .
it_mchb-clabs = it_mchb-clabs - l_reqty.
modify it_mchb index l_index.
endif.
else. "it_mchb-clabs <= 0.
ta_issue-qty = 0 .
g_flag_adj = 'X'.
endif.
else."stock not exists the material
ta_issue-qty = 0 .
g_flag_adj = 'X'.
endif.
append ta_issue.
endloop.
endloop.
data wa_qty(8) type p.
loop at ta_issue.
wa_qty = ta_issue-qty.
ta_issue-qty = wa_qty.
modify ta_issue index sy-tabix.
endloop.
sort ta_issue by j_4kscat matnr value.
export ta_issue to memory id 'TA_ISSUE'.
ENDFORM. " GET_POGR_REQUIREMENTS
*&---------------------------------------------------------------------*
*& Form BDC_MIGO
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM BDC_MIGO .
data l_tabix type i.
data: wa_bldat(8) type c,
wa_budat(8) type c.
data: wa_count type i.
data: lv_tabix type sy-tabix.
data: tt_grid like ta_grid occurs 0 with header line.
data: wa_qty(15) type c.
data: wa_count2(2) type n,
wa_sstr(17) type c value 'GOSPLIT-ERFMG(??)'.
data: wa_cursor(2) type n.
data: wa_expand(17) type c value 'GOITEM-EXPAND(??)'.
concatenate itab_public-doc_date+6(2) itab_public-doc_date+4(2)
itab_public-doc_date(4) into wa_bldat.
concatenate itab_public-pstng_date+6(2) itab_public-pstng_date+4(2)
itab_public-pstng_date(4) into wa_budat.
*data: tmp_issue like ta_issue1 occurs 0 with header line.
*// reset screen for migo
tt_grid[] = ta_grid[].
* delete tt_grid where qty = 0
* and split = space.
describe table tt_grid.
wa_count = sy-tfill - 1.
ta_issue1[] = ta_issue[].
sort ta_issue1 by row spline matnr value.
*set default value
perform bdc_dynpro using 'SAPLMIGO' '0001'.
perform bdc_field using 'BDC_OKCODE'
'=OK_DEFVALS'.
perform bdc_dynpro using 'SAPLMIGO' '1100'.
perform bdc_field using 'BDC_OKCODE'
'=OK_DEF_GO'.
perform bdc_field using 'BDC_CURSOR'
'GODEFAULT-PROPOSE_ALL_ITEMS'.
perform bdc_field using 'GODEFAULT-PROPOSE_ALL_ITEMS'
'X'.
perform bdc_dynpro using 'SAPLMIGO' '0001'.
perform bdc_field using 'BDC_OKCODE'
'/EOK_END'.
perform bdc_transaction using 'MIGO'.
*// set date
perform bdc_dynpro using 'SAPLMIGO' '0001'.
perform bdc_field using 'BDC_OKCODE'
'=MIGO_OK_HEADER_OPEN'.
perform bdc_dynpro using 'SAPLMIGO' '0001'.
perform bdc_field using 'BDC_OKCODE'
'=MIGO_OK_DETAIL_OPEN'.
perform bdc_dynpro using 'SAPLMIGO' '0001'.
perform bdc_field using 'BDC_OKCODE'
'=MIGO_OK_ACTION'.
perform bdc_field using 'GODYNPRO-ACTION'
'A01'.
perform bdc_dynpro using 'SAPLMIGO' '0001'.
perform bdc_field using 'BDC_OKCODE'
'=MIGO_OK_REFDOC'.
perform bdc_field using 'GODYNPRO-REFDOC'
'R01'.
perform bdc_dynpro using 'SAPLMIGO' '0001'.
perform bdc_field using 'BDC_OKCODE'
'=OK_GO'.
perform bdc_field using 'BDC_CURSOR'
'GODYNPRO-PO_NUMBER'.
perform bdc_field using 'GODEFAULT_TV-BWART'
'101'.
perform bdc_dynpro using 'SAPLMIGO' '1300'.
perform bdc_field using 'BDC_OKCODE'
'=OK_TIP_GO'.
perform bdc_field using 'BDC_CURSOR'
'G_TIP_DONT_SHOW_AGAIN'.
perform bdc_transaction using 'MIGO'.
read table itab_public index 1.
*// cancel tips on split qty
perform bdc_dynpro using 'SAPLMIGO' '0001'.
perform bdc_field using 'BDC_OKCODE'
'=OK_GO'.
perform bdc_field using 'BDC_CURSOR'
'GODYNPRO-PO_NUMBER'.
perform bdc_field using 'GODYNPRO-PO_NUMBER'
itab_public-po_number.
perform bdc_dynpro using 'SAPLMIGO' '0001'.
perform bdc_field using 'BDC_OKCODE'
'=MIGO_OK_SPLIT_QUAN'.
perform bdc_dynpro using 'SAPLMIGO' '1300'.
perform bdc_field using 'BDC_OKCODE'
'=OK_TIP_GO'.
perform bdc_field using 'BDC_CURSOR'
'G_TIP_DONT_SHOW_AGAIN'.
perform bdc_field using 'G_TIP_DONT_SHOW_AGAIN'
'X'.
perform bdc_dynpro using 'SAPLMIGO' '1000'.
perform bdc_field using 'BDC_OKCODE'
'=OK_GOON'.
perform bdc_transaction using 'MIGO'.
*// GR
perform bdc_dynpro using 'SAPLMIGO' '0001'.
perform bdc_field using 'BDC_OKCODE'
'=OK_GO'.
perform bdc_field using 'BDC_CURSOR'
'GODYNPRO-PO_NUMBER'.
perform bdc_field using 'GODYNPRO-PO_NUMBER'
itab_public-po_number.
perform bdc_field using 'GOHEAD-BLDAT'
WA_BLDAT.
perform bdc_field using 'GOHEAD-BUDAT'
WA_BUDAT.
if itab_public-ref_doc is initial.
perform bdc_field using 'GOHEAD-LFSNR'
'N/A'.
else.
perform bdc_field using 'GOHEAD-LFSNR'
itab_public-ref_doc.
endif.
perform bdc_field using 'GOHEAD-BKTXT'
itab_public-HEADER_TXT.
wa_cursor = 0.
loop at tt_grid.
if tt_grid-split is initial.
wa_cursor = wa_cursor + 1.
*** U1
* if wa_cursor > '02'.
* wa_cursor = '02'.
* endif.
if wa_cursor > '03'.
wa_cursor = '03'.
endif.
*** end of U1
wa_expand+14(2) = wa_cursor.
if tt_grid-qty > 0.
perform bdc_dynpro using 'SAPLMIGO' '0001'.
perform bdc_field using 'BDC_OKCODE'
'=MIGO_OK_EXPAND'.
perform bdc_field using 'BDC_CURSOR'
wa_expand.
* perform bdc_dynpro using 'SAPLMIGO' '0001'.
* perform bdc_field using 'BDC_OKCODE'
* '=MIGO_OK_EXPAND_BOM'.
wa_qty = tt_grid-qty.
perform bdc_field using 'GOITEM-ERFMG'
wa_qty.
perform bdc_field using 'GOITEM-LICHA'
tt_grid-licha.
* 26/03/07 : add so breakdown
perform bdc_field using 'GOITEM-J_4KSCAT'
tt_grid-j_4kscat.
perform bdc_field using 'GOITEM-LGOBE'
itab_public-lgort.
endif.
perform bdc_dynpro using 'SAPLMIGO' '0001'.
perform bdc_field using 'BDC_OKCODE'
'=MIGO_OK_NEXT_IT'.
perform bdc_field using 'BDC_CURSOR'
'GODYNPRO-DETAIL_TAKE'.
if tt_grid-qty > 0.
perform bdc_field using 'GODYNPRO-DETAIL_TAKE'
'X'.
* wa_qty = tt_grid-qty.
* perform bdc_field using 'GOITEM-ERFMG'
* wa_qty.
* perform bdc_field using 'GOITEM-LICHA'
* tt_grid-licha.
* perform bdc_field using 'GOITEM-LGOBE'
* wa_pogr-lgort.
loop at ta_issue1 where row = tt_grid-row
* and j_4kscat ne space.
and not werks is initial.
wa_cursor = wa_cursor + 1.
perform bdc_dynpro using 'SAPLMIGO' '0001'.
perform bdc_field using 'BDC_OKCODE'
'=MIGO_OK_NEXT_IT'.
*** perform bdc_field using 'BDC_CURSOR'
*** 'GODYNPRO-DETAIL_TAKE'.
*** perform bdc_field using 'GODYNPRO-DETAIL_TAKE'
*** 'X'.
wa_qty = ta_issue1-qty.
perform bdc_field using 'GOITEM-ERFMG'
wa_qty.
* 21/04/06 : uom conversion for 'ST' to 'PC'
perform uom_st_pc.
perform bdc_field using 'GOITEM-ERFME'
ta_issue1-meins.
perform bdc_field using 'GOITEM-J_3ASIZED'
ta_issue1-value.
* perform bdc_field using 'GOITEM-CHARG'
* ta_issue1-charg.
endloop.
endif.
else.
* perform bdc_dynpro using 'SAPLMIGO' '0001'.
* perform bdc_field using 'BDC_OKCODE'
* '=MIGO_OK_SPLIT_QUAN'.
*
* perform bdc_dynpro using 'SAPLMIGO' '1000'.
* perform bdc_field using 'BDC_OKCODE'
* '=OK_GOON'.
* wa_count2 = 0.
* loop at ta_split where row = tt_grid-row.
* wa_count2 = wa_count2 + 1.
* wa_sstr+14(2) = wa_count2.
* wa_qty = ta_split-qty.
* perform bdc_field using wa_sstr
* wa_qty.
* endloop.
* loop at ta_split where row = tt_grid-row.
* wa_cursor = wa_cursor + 1.
**** U1
** if wa_cursor > '02'.
** wa_cursor = '02'.
** endif.
* if wa_cursor > '03'.
* wa_cursor = '03'.
* endif.
**** end of U1
* wa_expand+14(2) = wa_cursor.
*
* perform bdc_dynpro using 'SAPLMIGO' '0001'.
* perform bdc_field using 'BDC_OKCODE'
* '=MIGO_OK_EXPAND'.
* perform bdc_field using 'BDC_CURSOR'
* wa_expand.
** perform bdc_dynpro using 'SAPLMIGO' '0001'.
** perform bdc_field using 'BDC_OKCODE'
** '=MIGO_OK_EXPAND_BOM'.
* perform bdc_field using 'GOITEM-LGOBE'
* wa_pogr-lgort.
** 26/03/07 : add so breakdown
**** perform bdc_field using 'GOITEM-J_4KSCAT'
**** ta_split-j_4kscat.
*
* perform bdc_field using 'GOITEM-LICHA'
* ta_split-licha.
*
* perform bdc_dynpro using 'SAPLMIGO' '0001'.
* perform bdc_field using 'BDC_OKCODE'
* '=MIGO_OK_NEXT_IT'.
* perform bdc_field using 'BDC_CURSOR'
* 'GODYNPRO-DETAIL_TAKE'.
* perform bdc_field using 'GODYNPRO-DETAIL_TAKE'
* 'X'.
** perform bdc_field using 'GOITEM-LGOBE'
** wa_pogr-lgort.
** perform bdc_field using 'GOITEM-LICHA'
** ta_split-licha.
*
*
* loop at ta_issue1 where row = ta_split-row
* and spline = ta_split-spline
** and j_4kscat ne space.
* and not werks is initial.
*
* wa_cursor = wa_cursor + 1.
* perform bdc_dynpro using 'SAPLMIGO' '0001'.
* perform bdc_field using 'BDC_OKCODE'
* '=MIGO_OK_NEXT_IT'.
* perform bdc_field using 'BDC_CURSOR'
* 'GODYNPRO-DETAIL_TAKE'.
* perform bdc_field using 'GODYNPRO-DETAIL_TAKE'
* 'X'.
* wa_qty = ta_issue1-qty.
* perform bdc_field using 'GOITEM-ERFMG'
* wa_qty.
** 21/04/06 : uom conversion for 'ST' to 'PC'
* perform uom_st_pc.
* perform bdc_field using 'GOITEM-ERFME'
* ta_issue1-meins.
* perform bdc_field using 'GOITEM-J_3ASIZED'
* ta_issue1-value.
*
** perform bdc_field using 'GOITEM-CHARG'
** ta_issue1-charg.
* endloop.
* endloop.
endif.
endloop.
perform bdc_dynpro using 'SAPLMIGO' '0001'.
perform bdc_field using 'BDC_OKCODE'
'=OK_POST'.
perform bdc_field using 'BDC_CURSOR'
'GODYNPRO-DETAIL_TAKE'.
* break-point.
perform bdc_transaction using 'MIGO'.
read table messtab with key msgtyp = 'S'
msgid = 'MIGO'
msgnr = '012'.
if sy-subrc eq 0.
loop at itab_public.
l_tabix = sy-tabix.
concatenate messtab-msgv1 'is created' into itab_public-err_message
separated by space.
itab_public-err_flag = ''.
itab_public-mat_doc = messtab-msgv1.
itab_public-com_date = sy-datum .
modify itab_public index l_tabix. "M9 modify
endloop.
else.
loop at itab_public .
l_tabix = sy-tabix.
concatenate 'E:' messtab-msgv1 into itab_public-err_message.
itab_public-err_flag = 'X' .
modify itab_public index l_tabix.
endloop.
endif.
ENDFORM. " BDC_MIGO
*&---------------------------------------------------------------------*
*& Form UOM_ST_PC
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM UOM_ST_PC .
CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT'
EXPORTING
INPUT = ta_issue1-meins
LANGUAGE = SY-LANGU
IMPORTING
OUTPUT = ta_issue1-meins
EXCEPTIONS
UNIT_NOT_FOUND = 1
OTHERS = 2
.
ENDFORM. " UOM_ST_PC
*&---------------------------------------------------------------------*
*& Form GET_GRID
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GET_GRID .
data: begin of wa_grid,
matnr like ekpo-matnr,
menge like eket-menge,
WEMNG like eket-WEMNG,
j_3asize like j_3abdbs-j_3asize,
charg like eket-charg,
pstyp like ekpo-pstyp,
j_4kscat like eket-j_4kscat,
meins like ekpo-meins,
ETENR like eket-ETENR,
EBELP like ekpo-ebelp,
end of wa_grid.
data: wa_qty like wa_grid-menge.
data: wa_stlnr like mast-stlnr.
data: wa_rcount(3) type n.
read table itab_public index 1.
wa_rcount = 0.
refresh ta_grid. clear ta_Grid.
l_subrc = 0.
clear wa_grid.
select b~matnr c~menge WEMNG j_3asize charg pstyp c~j_4kscat
b~meins etenr b~ebelp into wa_grid
from ekko as a
inner join ekpo as b
on a~ebeln = b~ebeln
inner join eket as c
on b~ebeln = c~ebeln
and b~ebelp = c~ebelp
where b~ebeln = itab_public-po_number
and b~LOEKZ = space.
wa_rcount = wa_rcount + 1.
ta_grid-row = wa_rcount.
* wa_pogr-matnr = wa_grid-matnr.
ta_grid-matnr = wa_grid-matnr.
ta_grid-value = wa_grid-j_3asize.
if wa_grid-wemng > wa_grid-menge.
ta_grid-oqty = 0.
else.
ta_grid-oqty = wa_grid-menge - wa_grid-wemng.
endif.
ta_grid-batch = wa_grid-charg.
ta_grid-meins = wa_grid-meins.
ta_grid-sl = wa_grid-ETENR.
ta_grid-ebelp = wa_grid-ebelp.
* 26/03/07 : SO breakdwon
ta_grid-j_4kscat = wa_grid-j_4kscat.
CALL FUNCTION 'Z_CONVERSION_VALUE'
EXPORTING
MATNR = wa_grid-matnr
J_3ASIZE = ta_grid-value
IMPORTING
CONV_LENTRY = ta_grid-lentry
CONV_GENTRY = ta_grid-gentry
SORTSEQ = ta_grid-sortseq
L_INSEAM = ta_grid-inseam.
select single meins into ta_grid-buom from mara
where matnr = ta_grid-matnr.
append ta_grid.
clear ta_grid. clear wa_grid.
endselect.
* delete ta_grid where oqty = cn_zeros.
read table ta_grid index 1.
if sy-subrc ne 0.
* message e001(zpp01).
endif.
sort ta_grid by sortseq ebelp.
ENDFORM. " GET_GRID
*&---------------------------------------------------------------------*
*& Form CHECK_SUBCON_PO
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM CHECK_SUBCON_PO .
select single * from ekko
where ebeln = itab_succ-po_number
and bsart in ('ZMC' , 'ZCC')
and loekz eq space.
check sy-subrc = 0.
"if is subcon po then do next
g_flag_subcon = 'X'.
ENDFORM. " CHECK_SUBCON_PO
*&---------------------------------------------------------------------*
*& Form CANCEL_SUBCON_GR
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM CANCEL_SUBCON_GR .
data l_flag type c.
data l_tabix type i.
data: ret like BAPIRET2 occurs 0 with header line.
data wa_mblnr like mseg-mblnr.
data wa_mjahr like mseg-mjahr.
data wa_budat like mkpf-budat.
data wa_lfbnr like mseg-lfbnr.
data l_mblnr like mseg-mblnr.
*loop at itab_public.
* clear: wa_mblnr, wa_mjahr, wa_lfbnr.
* select mblnr mjahr lfbnr into (wa_mblnr, wa_mjahr, wa_lfbnr) from mseg
* where ebeln = itab_public-po_number
* and ebelp = itab_public-po_item
* and bwart = '101'
* and j_4ksca = itab_public-stock_cat
* and matnr = itab_public-mat_code
* and j_3asiz = itab_public-grid_value
* and erfmg = itab_public-entry_qnt
* order by mblnr descending.
* exit .
* endselect.
* if sy-subrc = 0.
* if wa_mblnr <> wa_lfbnr.
* l_flag = 'X'.
* exit.
* endif.
* if l_mblnr <> wa_mblnr.
* l_flag = 'X'.
* exit.
* endif.
* l_mblnr = wa_mblnr.
* else.
* l_flag = 'X'.
* exit.
* endif.
*endloop.
*if l_flag = 'X'.
* loop at itab_public .
* l_tabix = sy-tabix.
* concatenate 'E:' 'The previous corresponding 101 subCon GR can not find' into itab_public-err_message.
* itab_public-err_flag = 'X' .
* modify itab_public index l_tabix.
* endloop.
*endif.
data: begin of lt_mblnr occurs 0,
mblnr like mseg-mblnr,
end of lt_mblnr.
loop at itab_public.
lt_mblnr-mblnr = itab_public-mblnr.
collect lt_mblnr.
endloop.
sort lt_mblnr.
delete adjacent duplicates from lt_mblnr.
loop at lt_mblnr.
clear wa_mblnr.
wa_mblnr = lt_mblnr-mblnr.
select single budat mjahr into (wa_budat, wa_mjahr) from mkpf
where mblnr = wa_mblnr.
* and mjahr = wa_mjahr.
CALL FUNCTION 'BAPI_GOODSMVT_CANCEL'
EXPORTING
MATERIALDOCUMENT = wa_mblnr
MATDOCUMENTYEAR = wa_mjahr
GOODSMVT_PSTNG_DATE = wa_budat
TABLES
RETURN = ret.
read table ret with key type = 'E'.
if sy-subrc eq 0.
loop at itab_public where mblnr = wa_mblnr .
l_tabix = sy-tabix.
concatenate 'E:' ret-message into itab_public-err_message.
itab_public-err_flag = 'X' .
modify itab_public index l_tabix.
endloop.
else.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
loop at itab_public where mblnr = wa_mblnr.
l_tabix = sy-tabix.
concatenate wa_mblnr 'is reversed' into itab_public-err_message
separated by space.
itab_public-err_flag = ''.
itab_public-mat_doc = ret-message.
itab_public-com_date = sy-datum .
modify itab_public index l_tabix.
endloop.
endif.
wait up to 1 seconds.
endloop.
ENDFORM. " CANCEL_SUBCON_GR