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

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

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

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
*&---------------------------------------------------------------------*
*& 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 = 'PLC "GMSM"'.
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.

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