*&---------------------------------------------------------------------*
*& Report ZEDI *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
REPORT ZEDI no standard page heading line-size 250.
tables: likp, lips.
type-pools: slis.
* data definition
types: begin of st_alv_output,
flag1(1),
vbeln like likp-vbeln, "发货单
serie(10), "发票号
erdat like likp-erdat, "创建日期
* vstel like likp-VSTEL, "装运点
lfdat like likp-LFDAT, "交货日期
kunnr like likp-kunnr, "送达方
POSNR like lips-POSNR, "行项目号
matnr like lips-matnr, "物料号码
KDMAT like lips-KDMAT, "客户物料
werks like lips-werks, "工厂
lgort like lips-lgort, "库存地点
LFIMG like lips-lFIMG, "交货数量
MEINS like lips-MEINS, "交货单位
brgew like lips-BRGEW, "毛重量
ntgew like lips-NTGEW, "净重量
gewei like lips-GEWEI, "重量单位
COLTAB type SLIS_T_SPECIALCOL_ALV,
number type i,
end of st_alv_output.
data: itab type st_alv_output occurs 1 with header line.
data: alv_output type st_alv_output occurs 1 with header line.
data: fieldcat type slis_t_fieldcat_alv with header line.
data: layout type slis_layout_alv.
data: colstr type slis_specialcol_alv.
data: flag type i,
FLAG_EXIT TYPE C,
vbeln_tmp like likp-vbeln.
DATA: ITAB_C LIKE ALV_OUTPUT OCCURS 1 WITH HEADER LINE.
DATA: STR_ITAB_C LIKE ITAB_C.
data: answer.
data: it_events type SLIS_T_EVENT with header line.
* serie no to xml file
data: begin of xmlno occurs 1,
serie(10),
end of xmlno.
* xml file content
data: begin of xmlcon occurs 1,
line(150),
end of xmlcon.
data: date_c(8),time_c(6).
DATA: BEGIN OF CONF_VBELN OCCURS 1,
vbeln like likp-vbeln,
END OF CONF_VBELN.
data: n1 type i,
n2 type i,
number type i.
DATA: LFIMG_C(10).
data: xml_file_name like RLGRAP-FILENAME.
data: brgew like lips-BRGEW, "毛重量
brgewc(10),
ntgew like lips-NTGEW, "净重量
ntgewc(10).
DATA: XMLFILE(200).
DATA: COMMANDLINE(200).
* selection screen
selection-screen begin of block b1 with frame title f1.
selection-screen begin of line.
selection-screen comment (20) text1 for field s_vbeln.
select-options: s_vbeln for lips-vbeln.
selection-screen end of line.
selection-screen begin of line.
selection-screen comment (20) text2 for field s_ernam.
select-options: s_ernam for likp-ernam.
selection-screen end of line.
selection-screen begin of line.
selection-screen comment (20) text3 for field s_erdat.
select-options: s_erdat for likp-erdat default sy-datum.
selection-screen end of line.
selection-screen begin of line.
selection-screen comment (20) text5 for field s_matnr.
select-options: s_matnr for lips-matnr NO INTERVALS.
selection-screen end of line.
selection-screen skip.
selection-screen begin of line.
selection-screen comment (20) text4 for field s_kunnr.
select-options: s_kunnr for likp-kunnr NO Intervals.
selection-screen end of line.
selection-screen end of block b1.
* Initialization.
initialization.
text1 = '交货单号码'.
text2 = '创建人'.
text3 = '创建日期'.
text4 = '福特 客户号码:'.
text5 = '料号'.
s_matnr-low = '100-AB'.
s_matnr-option = 'EQ'.
s_matnr-sign = 'I'.
append s_matnr.
s_matnr-low = '100-AA'.
s_matnr-option = 'EQ'.
s_matnr-sign = 'I'.
append s_matnr.
* at selection screen output.
at selection-screen output.
loop at screen.
if screen-name = 'S_KUNNR-LOW'.
screen-input = 0.
modify screen.
endif.
endloop.
* start-of-selection
start-of-selection.
select likp~vbeln "发货单号
likp~erdat "创建时间
likp~LFDAT "交货日期
likp~kunnr "送达方
lips~POSNR "行项目号
lips~matnr "物料号码
lips~KDMAT "客户物料
lips~werks "工厂
lips~lgort "库存地点
lips~LFIMG "交货数量
lips~MEINS "交货单位
lips~BRGEW "总重量
lips~NTGEW "净重量
lips~GEWEI "重量单位
from likp inner join lips on likp~vbeln = lips~vbeln
into (itab-vbeln, itab-erdat, itab-lfdat,
itab-kunnr, itab-posnr, itab-matnr,
itab-KDMAT, itab-werks, itab-lgort,
itab-lfimg, itab-meins, itab-bRgew,
itab-ntgew, itab-gewei)
where likp~vbeln in s_vbeln
and likp~ernam in s_ernam
and likp~erdat in s_erdat
and likp~kunnr in s_kunnr
and lips~kdmat in s_matnr.
append itab.
endselect.
loop at itab.
number = number + 1.
itab-number = number.
if itab-kdmat = '5T16-1007-AA'.
itab-kdmat = '5T16 1007 AA'.
endif.
modify itab.
endloop.
alv_output[] = itab[].
* merge fieldcat
perform add_fieldcat using:
'VBELN' '发货单号' '1' '10' '',
'SERIE' '发票号码' '2' '10' 'X',
'ERDAT' '创建日期' '3' '10' '',
'LFDAT' '交货日期' '4' '10' '',
'KUNNR' '送达方' '5' '10' '',
'POSNR' '行项目号' '6' '8' '',
'MATNR' '物料号码' '7' '18' '',
'KDMAT' '客户物料' '8' '18' '',
'WERKS' '工厂' '9' '4' '',
'LGORT' '库存地点' '10' '4' '',
'LFIMG' '交货数量' '11' '15' '',
'MEINS' '单位' '12' '4' '',
'BRGEW' '毛重量' '13' '15' '',
'NTGEW' '净重量' '14' '15' '',
'GEWEI' '单位' '15' '4' ''.
* layout set
layout-box_fieldname = 'FLAG1'.
layout-coltab_fieldname = 'COLTAB'.
* layout-zebra = 'X'.
loop at alv_output.
at new vbeln.
if flag = 0.
flag = 1.
else.
flag = 0.
endif.
endat.
if flag = 0.
colstr-color-col = 2.
elseif flag = 1.
colstr-color-col = 4.
endif.
append colstr to alv_output-coltab.
modify alv_output.
endloop.
loop at alv_output.
if alv_output-vbeln = vbeln_tmp.
clear: alv_output-vbeln,
alv_output-erdat,
alv_output-LFDAT,
alv_output-kunnr.
modify alv_output.
else.
vbeln_tmp = alv_output-vbeln.
endif.
endloop.
* events process
perform set_events.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER =
* I_BUFFER_ACTIVE = ' '
I_CALLBACK_PROGRAM = 'ZEDI'
I_CALLBACK_PF_STATUS_SET = 'SET_PF_STATUS'
I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
* I_STRUCTURE_NAME =
IS_LAYOUT = layout
IT_FIELDCAT = fieldcat[]
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
* I_SAVE = ' '
* IS_VARIANT =
IT_EVENTS = it_events[]
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
T_OUTTAB = alv_output
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2
.
*&---------------------------------------------------------------------*
*& Form add_fieldcat
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM add_fieldcat using A B C D E.
fieldcat-ref_tabname = 'ALV_OUTPUT'.
fieldcat-fieldname = A.
fieldcat-seltext_m = B.
* fieldcat-col_pos = C.
fieldcat-outputlen = D.
fieldcat-input = E.
fieldcat-no_zero = 'X'.
append fieldcat.
ENDFORM. " add_fieldcat
*&---------------------------------------------------------------------*
*& Form set_pf_status
*&---------------------------------------------------------------------*
FORM set_pf_status USING rt_extab TYPE slis_t_extab.
DATA: str_extab TYPE slis_extab.
SET PF-STATUS 'ZT' EXCLUDING rt_extab.
endform. "set_pf_status
*&---------------------------------------------------------------------*
*& Form user_command
*&---------------------------------------------------------------------*
FORM user_command USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
case r_ucomm.
when 'POST'.
* 对于每一张选中行项目,都需要输入对应的发票号码
clear: itab_c,N1,N2,CONF_VBELN,XMLNO.
refresh: itab_c,CONF_VBELN,XMLNO.
LOOP AT ALV_OUTPUT.
IF ALV_OUTPUT-FLAG1 = 'X'.
IF ALV_OUTPUT-SERIE IS INITIAL.
MESSAGE S001(ZZ) WITH '请输入发票号码'.
flag_exit = 'X'.
EXIT.
ELSE.
read table itab with key number = alv_output-number.
if sy-subrc = 0.
ITAB-SERIE = ALV_OUTPUT-SERIE.
APPEND itab TO ITAB_C.
endif.
ENDIF.
ENDIF.
ENDLOOP.
IF FLAG_EXIT = 'X'.
FLAG_EXIT = ''.
EXIT.
ENDIF.
* 对于某一张发货单的每一个行项目,是否需要全部发货?
LOOP AT ITAB_C.
CONF_VBELN-VBELN = ITAB_C-VBELN.
COLLECT CONF_VBELN.
ENDLOOP.
loop at conf_vbeln.
loop at ITAB transporting no fields
where vbeln = conf_vbeln-vbeln.
n1 = n1 + 1.
endloop.
loop at itab_c transporting no fields
where vbeln = conf_vbeln-vbeln.
n2 = n2 + 1.
endloop.
if n1 <> n2.
message s002(zz) with '对于每一张发货单,请全部发货'.
FLAG_EXIT = 'X'.
EXIT.
endif.
clear: n1,n2.
endloop.
IF FLAG_EXIT = 'X'.
FLAG_EXIT = ''.
EXIT.
ENDIF.
* DOWNLOAD XML FILE
perform down_xml.
CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
TEXT_QUESTION = '确定发送吗?'
IMPORTING
ANSWER = answer.
if answer = '1'.
perform send_asn.
elseif answer = '2'.
perform dele_xmlfile.
endif.
ENDCASE.
endform. "user_command
*&---------------------------------------------------------------------*
*& Form send_asn
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM send_asn.
* break-point.
LOOP AT XMLNO.
CONCATENATE 'C://' XMLNO-SERIE '.XML' INTO XMLFILE.
CONDENSE XMLFILE NO-GAPS.
CONCATENATE COMMANDLINE XMLFILE INTO COMMANDLINE SEPARATED BY SPACE.
ENDLOOP.
shift commandline.
CALL FUNCTION 'WS_EXECUTE'
EXPORTING
COMMANDLINE = COMMANDLINE
PROGRAM = 'C:/XMLSENDER.EXE'.
IF SY-SUBRC <> 0.
message i003(zz) with 'SAP 发送ASN时可能出错, 请检查!'.
ENDIF.
ENDFORM. " send_asn
*&---------------------------------------------------------------------*
*& Form set_events
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM set_events.
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
IMPORTING
ET_EVENTS = it_events[].
ENDFORM. " set_events
*&---------------------------------------------------------------------*
*& Form down_xml
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM down_xml.
loop at itab_c.
clear: itab_c-vbeln,itab_c-kunnr.
modify itab_c.
xmlno-serie = itab_c-serie.
collect xmlno.
endloop.
sort itab_c by serie.
loop at xmlno.
PERFORM GENERATE_XML_TEXT.
* download xml file
concatenate 'C:/' XMLNO-SERIE '.XML' INTO XML_FILE_NAME.
CONDENSE XML_FILE_NAME NO-GAPS.
CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
FILENAME = xml_file_name
FILETYPE = 'ASC'
TABLES
DATA_TAB = xmlcon.
REFRESH XMLCON.
endloop.
ENDFORM. " down_xml
*&---------------------------------------------------------------------*
*& Form dele_xmlfile
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM dele_xmlfile.
loop at xmlno.
concatenate 'C:/' XMLNO-SERIE '.XML' INTO XML_FILE_NAME.
CONDENSE XML_FILE_NAME NO-GAPS.
CALL FUNCTION 'WS_FILE_DELETE'
EXPORTING
FILE = XML_FILE_NAME.
endloop.
ENDFORM. " dele_xmlfile
*&---------------------------------------------------------------------*
*& Form GENERATE_XML_TEXT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GENERATE_XML_TEXT.
xmlcon-line = '<ASN>'.
append xmlcon.
xmlcon-line = '<HEADER>'.
append xmlcon.
*default
xmlcon-line =
'<TRANSACTION_CONTROL_NUMBER></TRANSACTION_CONTROL_NUMBER>'.
append xmlcon.
* VENDOR WANFENG
xmlcon-line = '<SENDER>ED1RA</SENDER>'.
append xmlcon.
* Ford
xmlcon-line = '<RECEIVER>D1D4F</RECEIVER>'.
append xmlcon.
xmlcon-line = '</HEADER>'.
append xmlcon.
*ASN NO
concatenate '<ASN_NUMBER>'
xmlno-serie
'</ASN_NUMBER>'
into xmlcon-line.
append xmlcon.
*
xmlcon-line = '<SHIPPED_FROM>ED1RA</SHIPPED_FROM>'.
append xmlcon.
*
xmlcon-line = '<SHIP_TO_PLANT>D1D4F</SHIP_TO_PLANT>'.
append xmlcon.
xmlcon-line = '<INTERMEDIATE_CONSIGNEE></INTERMEDIATE_CONSIGNEE>'.
append xmlcon.
* Create automaticly by Ford site: Delivery Note No
xmlcon-line = '<CONVEYANCE_NO></CONVEYANCE_NO>'.
append xmlcon.
xmlcon-line = '<ASN_PURPOSE>00</ASN_PURPOSE>'.
append xmlcon.
*Date may be set from Ford website Create Date
xmlcon-line = '<DATE_CREATED></DATE_CREATED>'.
append xmlcon.
xmlcon-line = '<TIME_CREATED></TIME_CREATED>'.
append xmlcon.
* Shipping date is the current date
date_c = sy-datum.
concatenate '<DATE_SHIPPED>'
date_c+2(6)
'</DATE_SHIPPED>' into xmlcon-line.
append xmlcon.
* shipping time is the current time
time_c = sy-uzeit.
concatenate '<TIME_SHIPPED>'
time_c+0(4)
'</TIME_SHIPPED>' into xmlcon-line.
append xmlcon.
*?
xmlcon-line = '<EXPECTED_ARRIVAL_DATE></EXPECTED_ARRIVAL_DATE>'.
append xmlcon.
*?
xmlcon-line = '<EXPECTED_ARRIVAL_TIME></EXPECTED_ARRIVAL_TIME>'.
append xmlcon.
loop at itab_c where serie = xmlno-serie.
brgew = itab_c-brgew + brgew.
ntgew = itab_c-ntgew + ntgew.
endloop.
brgewc = brgew.
ntgewc = ntgew.
concatenate '<NET_WEIGHT>'
ntgewc
'</NET_WEIGHT>' into xmlcon-line.
CONDENSE xmlcon-line NO-GAPS.
append xmlcon.
concatenate '<GROSS_WEIGHT>'
brgewc
'</GROSS_WEIGHT>' into xmlcon-line.
CONDENSE xmlcon-line NO-GAPS.
append xmlcon.
clear: ntgew,ntgewc,brgew,brgewc.
xmlcon-line = '<WEIGHT_UOM>KG</WEIGHT_UOM>'.
append xmlcon.
*default
xmlcon-line = '<CARRIER1></CARRIER1>'.
append xmlcon.
xmlcon-line = '<MODE_OF_TRANSPORT>M</MODE_OF_TRANSPORT>'.
append xmlcon.
xmlcon-line = '<FREIGHT_BILL_NO></FREIGHT_BILL_NO>'.
append xmlcon.
*Plate No
xmlcon-line = '<BILL_OF_LADING_NO>DIREKALIM</BILL_OF_LADING_NO>'.
append xmlcon.
xmlcon-line = '<LICENCE_PLATE_NO>DIREKALIM</LICENCE_PLATE_NO>'.
append xmlcon.
xmlcon-line = '<WAYBILL>'.
append xmlcon.
* Here is asn No
concatenate '<PACKING_SLIP_NO>'
xmlno-serie
'</PACKING_SLIP_NO>' into xmlcon-line.
append xmlcon.
concatenate '<PACKING_SLIP_DATE>'
date_c+2(6)
'</PACKING_SLIP_DATE>' into xmlcon-line.
append xmlcon.
xmlcon-line = '<PARTS>'.
append xmlcon.
loop at itab_c where serie = xmlno-serie.
xmlcon-line = '<PART>'.
append xmlcon.
concatenate '<NO_PART>'
itab_c-KDMAT
'</NO_PART>' into xmlcon-line.
append xmlcon.
*?
xmlcon-line = '<PART_NO_TYPE>PP</PART_NO_TYPE>'.
append xmlcon.
LFIMG_C = ITAB_C-LFIMG.
concatenate '<PART_QUANTITY>'
LFIMG_C
'</PART_QUANTITY>' into xmlcon-line.
CONDENSE xmlcon-line NO-GAPS.
append xmlcon.
*?
xmlcon-line = '<PART_UOM>EA</PART_UOM>'.
append xmlcon.
*default 0
xmlcon-line = '<PART_CUM_QTY>0</PART_CUM_QTY>'.
append xmlcon.
*default 0
xmlcon-line = '<PART_PRIOR_CUM_QTY>0</PART_PRIOR_CUM_QTY>'.
append xmlcon.
xmlcon-line = '<PART_PO_NO></PART_PO_NO>'.
append xmlcon.
xmlcon-line = '<CONTAINERS>'.
append xmlcon.
xmlcon-line = '<CONTAINER>'.
append xmlcon.
*default BOX90
xmlcon-line = '<CONTAINER_TYPE_CODE>BOX90</CONTAINER_TYPE_CODE>'.
append xmlcon.
*default 0
xmlcon-line = '<PARTS_PER_CONT>0</PARTS_PER_CONT>'.
append xmlcon.
*default 0
xmlcon-line = '<CONTS_PER_PART>0</CONTS_PER_PART>'.
append xmlcon.
xmlcon-line = '</CONTAINER>'.
append xmlcon.
xmlcon-line = '</CONTAINERS>'.
append xmlcon.
xmlcon-line = '</PART>'.
append xmlcon.
endloop.
xmlcon-line = '</PARTS>'.
append xmlcon.
xmlcon-line = '</WAYBILL>'.
append xmlcon.
xmlcon-line = '</ASN>'.
append xmlcon.
ENDFORM. " GENERATE_XML_TEXT