Реализация с/х запчастей

Информационно-поисковая система «Техсервис»

Выгрузка информации производится из SAP ежедневно без цены, наличие запчастей на Гомсельмаш и дилерских центрах

ABAP — программа для выгрузки информации из SAP:

*&---------------------------------------------------------------------*
*& Report ZHM_BELAGROPROMSERVIS
*&
*&---------------------------------------------------------------------*
*& на серверах 192.168.3.135, 192.168.3.137, 192.168.3.139 добавлен
*& маршрут с помощью команды
*& route -p add 213.184.244.152 mask 255.255.255.255 192.168.3.230 metric 2
*& на прокси-сервере isaserver правило №13 CLIENT BIRGA
*&---------------------------------------------------------------------*

report zhm_belagropromservis.
type-pools: abap.
tables: zlgort_clients.
types : begin of ty_out,
line(250),
end of ty_out.
types : begin of ty_item,
werks type werks_d,
lgort type lgort_d,
matnr_ext type matnr_ext,
maktx type maktx,
mseh3 type mseh3,
labst type labst,
price type salk3,
end of ty_item.
data: it_out type standard table of ty_out,
ls_out type ty_out,
p_file type rlgrap-filename,
it_t001l type table of t001l,
ls_t001l like line of it_t001l,
i type i,
ic(4) type c,
ls_kna1 type kna1,
it_mard type mard,
it_items type table of ty_item,
ls_items type ty_item,
labst_c(14) type c,
price_c(14) type c,
matnr_c type matnr,
char255 type char255.
select * into corresponding fields of table it_items
from mard
* inner join zbelagro on mard~werks = zbelagro~werks and mard~lgort = zbelagro~lgort
inner join mara on mard~matnr = mara~matnr
inner join materialid on mara~matnr = materialid~matnr_int
inner join makt on mara~matnr = makt~matnr
inner join t006b on mara~meins = t006b~msehi
where t006b~spras = 'R' and labst > 0 and spart = '25' and ( lgort = 'R215' or lgort like 'H%' ).
select t001l~werks t001l~lgort t001l~lgobe
from t001l "inner join zbelagro on t001l~werks = zbelagro~werks and t001l~lgort = zbelagro~lgort
into corresponding fields of table it_t001l
for all entries in it_items
where t001l~lgort = it_items-lgort.
i = 0.
loop at it_t001l into ls_t001l.
select single matnr into matnr_c from mard where lgort = ls_t001l-lgort and labst > 0.
if sy-subrc <> 0.
continue.
endif.
i = i + 1.
ls_out-line = '~~~~~'.
append ls_out to it_out.
clear ls_out.
ic = i.
ls_out-line = ic.
condense ls_out-line.
append ls_out to it_out.
clear ls_out.
select single * into corresponding fields of ls_kna1 from kna1 inner join zlgort_clients on kna1~kunnr = zlgort_clients~kunnr where zlgort_clients~lgort = ls_t001l-lgort.
ls_out-line = ls_kna1-name1.
if ls_t001l-lgort = 'R215'.
ls_out-line = 'ОАО "Гомсельмаш"'.
endif.
translate ls_out-line using ';:/\'.
condense ls_out-line.
append ls_out to it_out.
clear ls_out.
concatenate ls_kna1-land1 ls_kna1-ort01 ls_kna1-stras into ls_out-line separated by ','.
if ls_t001l-lgort = 'R215'.
ls_out-line = 'BY, Гомель, Шоссейная, 41'.
endif.
translate ls_out-line using ';:/\'.
condense ls_out-line.
append ls_out to it_out.
clear ls_out.
ls_out-line = ls_kna1-telf1.
if ls_t001l-lgort = 'R215'.
ls_out-line = '8-10-375(232) 59-22-31'.
endif.
concatenate 'Тел:' ls_out-line into ls_out-line separated by space.
translate ls_out-line using ';:/\'.
condense ls_out-line.
append ls_out to it_out.
clear ls_out.
ls_out-line = '~~~~~'.
condense ls_out-line.
append ls_out to it_out.
clear ls_out.
loop at it_items into ls_items where lgort = ls_t001l-lgort and werks = ls_t001l-werks.
translate ls_items-maktx using ';:/\'.
translate ls_items-matnr_ext using ';:/\'.
labst_c = ls_items-labst.
price_c = ls_items-price.
condense: labst_c, price_c.
concatenate ls_items-maktx ls_items-matnr_ext into char255 separated by space.
concatenate '0' '0' '0' ls_items-matnr_ext char255 ls_items-mseh3 labst_c price_c ls_items-matnr_ext '0' '0' into ls_out-line separated by ';'.
condense ls_out-line.
append ls_out to it_out.
clear ls_out.
endloop.
endloop.
clear ls_out.
ls_out-line = '~~~~~'.
condense ls_out-line.
append ls_out to it_out.
clear ls_out.
perform encoding tables it_out.
* perform create_file_to_ftp tables it_out.

form create_file_to_ftp tables lt_out type standard table.
data: l_user(30) type c value 'Gomel', "user name of ftp server
l_pwd(30) type c value 'docTar', "password of ftp server
l_host(64) type c value 'BELAGROSERVICE.BY', "ip address of FTP server
l_dest like rfcdes-rfcdest value 'SAPFTPA',"Background RFC destination
w_hdl type i value 1,
c_key type i value 26101957,
l_slen type i,
p_file type rlgrap-filename,
file type string value 'gomselmash.txt',
it_out type table of ty_out.
it_out[] = lt_out[].
p_file = file.
*HTTP_SCRAMBLE: used to scramble the password provided in a format recognized by SAP.
set extended check off.
l_slen = strlen( l_pwd ).
call function 'HTTP_SCRAMBLE'
exporting
source = l_pwd
sourcelen = l_slen
key = c_key
importing
destination = l_pwd.
call function 'SAPGUI_PROGRESS_INDICATOR'
exporting
text = 'Connect to FTP Server'.
*To Connect to the Server using FTP
call function 'FTP_CONNECT'
exporting
user = l_user
password = l_pwd
host = l_host
rfc_destination = l_dest
importing
handle = w_hdl
exceptions
others = 1.
if sy-subrc ne 0.
format color col_negative.
write:/ 'Error in Connection'.
else.
write:/ 'FTP Connection is opened '.
endif.
*Create file on FTP server
call function 'SAPGUI_PROGRESS_INDICATOR'
exporting
text = 'Create file on FTP Server'.
*FTP_R3_TO_SERVER:used to transfer the internal table data as a file to other system in the character mode.
call function 'FTP_R3_TO_SERVER'
exporting
handle = w_hdl
fname = p_file "file path of destination system
character_mode = 'X'
tables
text = it_out
exceptions
tcpip_error = 1
command_error = 2
data_error = 3
others = 4.

if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
raising invalid_output_file.
endif.

call function 'SAPGUI_PROGRESS_INDICATOR'
exporting
text = 'Writing Contents to the file'.
*FTP_DISCONNECT: This is used to disconnect the connection between SAP and other system.
*To disconnect the FTP
call function 'FTP_DISCONNECT'
exporting
handle = w_hdl.
*RFC_CONNECTION_CLOSE:This is used to disconnect the RFC connection between SAP and other system.
call function 'RFC_CONNECTION_CLOSE'
exporting
destination = l_dest
exceptions
others = 1.
endform.
form encoding tables lt_out type standard table.
data: it_out type table of ty_out,
it_out_f type table of ty_out,
ls_out type ty_out,
hx(2) type x value '0D0A', "Перевод строки для WIN1251
l_str type string,
g_buffer type xstring, "Байтовый буфер в кодировке WIN1251
encoding type string, "Строка кодировки
codepage_n type cpcodepage, "Кодовая страница к кодировке число
codepage_c type abap_encoding, "Кодовая страница как строка
cvto_win type ref to cl_abap_conv_out_ce,
g_file_cost(60) type c value 'D:/BELAGROSERVIS/gomselmash.txt',
lv_xstring type xstring,

current_filename(100),
wa(1024).

data: begin of gt_xml_cskt occurs 0,
line type string,
end of gt_xml_cskt.
data: l_oref type ref to cx_root,
text type string.
it_out[] = lt_out[].
loop at it_out into ls_out.
gt_xml_cskt-line = ls_out-line.
append gt_xml_cskt.
endloop.
clear ls_out.
encoding = 'WINDOWS-1251'.
call function 'SCP_CODEPAGE_BY_EXTERNAL_NAME'
exporting
external_name = encoding
importing
sap_codepage = codepage_n
exceptions
not_found = 1
others = 2.
codepage_c = codepage_n.
call method cl_abap_conv_out_ce=>create
exporting
encoding = codepage_c
receiving
conv = cvto_win.
cvto_win->reset( ).
loop at gt_xml_cskt.
try.
call method cvto_win->write
exporting
data = gt_xml_cskt-line.
catch cx_sy_conversion_codepage into l_oref.
text = l_oref->get_text( ).
endtry.
call method cvto_win->write
exporting
data = hx.
endloop.
open dataset g_file_cost for output in binary mode.
call method cvto_win->get_buffer
receiving
buffer = lv_xstring.
transfer lv_xstring to g_file_cost.
close dataset g_file_cost.
open dataset g_file_cost for input in text mode encoding non-unicode.
do.
if sy-subrc = 0.
read dataset g_file_cost into ls_out-line.
append ls_out-line to it_out_f.
else.
exit.
endif.
enddo.
lt_out[] = it_out_f[].
if it_out_f[] is not initial.
write:/ 'Файл выгружен'.
endif.
concatenate 'D:\BELAGROSERVIS\400051757_' sy-datum+6(2) '-' sy-datum+4(2) '-' sy-datum(4) '.txt' into g_file_cost.
open dataset g_file_cost for output in binary mode.
call method cvto_win->get_buffer
receiving
buffer = lv_xstring.
transfer lv_xstring to g_file_cost.
close dataset g_file_cost.
open dataset g_file_cost for input in text mode encoding non-unicode.
do.
if sy-subrc = 0.
read dataset g_file_cost into ls_out-line.
append ls_out-line to it_out_f.
else.
exit.
endif.
enddo.
lt_out[] = it_out_f[].
if it_out_f[] is not initial.
write:/ 'Файл выгружен'.
endif.

current_filename = 'd:\BELAGROSERVIS\current_filename.txt'.

open dataset current_filename for output in text mode encoding default.

if sy-subrc ne 0.
exit.
endif.

write g_file_cost to wa.

transfer wa to current_filename.
clear wa.

close dataset current_filename.
endform.

Добавить комментарий