sy-uname написал(а):
Марик написал:
Могу выложить или выслать на почту готовую программу берущую курс с центробанковского сайта..
Вы хотите чтобы Вас умоляли опубликовать Ваше творение?
Берите пример с коллег:
Разработки участников форумаДа не в том дело.
Этот код я брал с какого-то форума (даже возможно с этого), поэтому не могу выложить его, присвоив авторство.
Какой смысл выкладывать код, если существует возможность того, что автор ветки уже нашёл этот код, как и я в своё время?
Да и в принципе вот и он:
Code:
*&---------------------------------------------------------------------*
*& Report ZDOWNLOAD_CUR
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZDOWNLOAD_CUR.
INCLUDE ZDOWNLOAD_CUR_TOP.
INCLUDE ZDOWNLOAD_CUR_SSCR.
INCLUDE ZDOWNLOAD_CUR_EVENTS.
*&---------------------------------------------------------------------*
*& Include ZDOWNLOAD_CUR_TOP
*&---------------------------------------------------------------------*
tables: tcurr.
types: begin of l_cur,
numcode type string,
charcode type string,
nominal type string,
name type string,
value type string,
end of l_cur.
data: wa_tcur TYPE TABLE OF l_cur WITH HEADER LINE.
*&---------------------------------------------------------------------*
*& Include ZDOWNLOAD_CUR_SSCR
*&---------------------------------------------------------------------*
PARAMETERS: p_date type d DEFAULT sy-datum,
p_coment as CHECKBOX USER-COMMAND flag.
*&---------------------------------------------------------------------*
*& Include ZDOWNLOAD_CUR_EVENTS
*&---------------------------------------------------------------------*
start-of-selection.
*------------------------------------------------------
*download data from www.cbr.ru
types: begin of text,
line(120),
end of text.
data: l_url(264) type c,
cur_date(10) type c,
status(3) type c,
statustext(128) type c,
dest like rfcdes-rfcdest,
rlength type i,
* response type standard table of text,
response type standard table of text with header line,
response_headers type table of text with header line,
btocrlf type c.
btocrlf = 'Y'.
write p_date to cur_date dd/mm/yyyy.
replace all occurrences of '.' in cur_date with '/'.
*l_url = 'http://www.cbr.ru/scripts/XML_daily.asp?date_req=10/10/2008'.
*l_url = 'http://www.cbr.ru/scripts/XML_dynamic.asp?date_req1=10/10/2008&date_req2=12/10/2008&VAL_NM_RQ=R01235'.
l_url = 'http://www.cbr.ru/scripts/XML_daily.asp?date_req='.
concatenate l_url cur_date into l_url.
call function 'HTTP_GET'
exporting
absolute_uri = l_url
rfc_destination = dest
* user = user
* password = pwd
blankstocrlf = btocrlf
importing
status_code = status
status_text = statustext
response_entity_body_length = rlength
tables
response_entity_body = response
response_headers = response_headers
exceptions
CONNECT_FAILED = 1
TIMEOUT = 2
INTERNAL_ERROR = 3
TCPIP_ERROR = 4
DATA_ERROR = 5
SYSTEM_FAILURE = 6
COMMUNICATION_FAILURE = 7
OTHERS = 8
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
call function 'RFC_CONNECTION_CLOSE'
EXPORTING
destination = dest
EXCEPTIONS
others = 0.
**************************************************************
*convert download data from site to table format
**************************************************************
data: xml type ref to cl_xml_document,
xml2 type ref to cl_xml_document,
w_subrc like sy-subrc,
l_node type ref to if_ixml_node,
gt_xmltree type swxmltree,
gs_xmltree like wa_tcur,
val_node type string,
l_node_root type ref to if_ixml_node,
children type ref to if_ixml_node_list.
data: iter type ref to if_ixml_node_iterator.
create object xml.
call method xml->create_with_table
EXPORTING
table = response[]
size = rlength
RECEIVING
retcode = w_subrc.
if w_subrc ne 0.
write / 'error: unable to create xml'.
endif.
call method xml->find_node
EXPORTING
name = 'ValCurs'
RECEIVING
node = l_node.
data: date type string,
name type string.
field-symbols <i> like line of wa_tcur.
data: attr type ref to if_ixml_named_node_map.
data: date_node type ref to if_ixml_node.
data: l_name type string.
call method l_node->get_attributes
RECEIVING
rval = attr.
call method attr->get_named_item
EXPORTING
name = 'Date'
RECEIVING
rval = date_node.
l_name = date_node->get_value( ).
children = l_node->get_children( ).
iter = children->create_iterator( ).
iter->reset( ).
do.
l_node_root = iter->get_next( ).
if not l_node_root is bound.
exit.
endif.
l_node = xml->find_node( name = 'NumCode' root = l_node_root ).
check l_node is bound.
append initial line to wa_tcur assigning <i>.
<i>-numcode = l_node->get_value( ).
l_node = xml->find_node( name = 'CharCode' root = l_node_root ).
check l_node is bound.
<i>-charcode = l_node->get_value( ).
l_node = xml->find_node( name = 'Nominal' root = l_node_root ).
check l_node is bound.
<i>-nominal = l_node->get_value( ).
l_node = xml->find_node( name = 'Name' root = l_node_root ).
check l_node is bound.
<i>-name = l_node->get_value( ).
l_node = xml->find_node( name = 'Value' root = l_node_root ).
check l_node is bound.
<i>-value = l_node->get_value( ).
enddo.
**************************************************************
*Place data form table to TCURR
**************************************************************
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(EXC_IN) TYPE STRING
*" VALUE(DCURR_IN) TYPE STRING
*" VALUE(SCURR_IN) TYPE STRING
*" TABLES
*" EXCH_RATE_LIST STRUCTURE BAPI1093_0 OPTIONAL
*"----------------------------------------------------------------------
*
data: exch_rate like bapi1093_0 occurs 1 with header line,
rettab like bapiret2 occurs 1 with header line,
ret2 like bapiret2 occurs 1 with header line,
ret3 like bapiret2 occurs 1 with header line,
exch_rate_list like bapi1093_0 occurs 1 with header line.
data:
i_from_curr_range type table of bapi1093_3 with header line,
i_to_currncy_range type table of bapi1093_3 with header line.
write: 'currency value on date: '. write: p_date.
loop at wa_tcur.
replace ',' with '.' into wa_tcur-value.
if wa_tcur-charcode = 'USD'.
exch_rate-rate_type = 'M'.
exch_rate-from_curr = wa_tcur-charcode.
exch_rate-to_currncy = 'RUB'.
exch_rate-valid_from = p_date.
exch_rate-exch_rate = wa_tcur-value.
exch_rate-from_factor = wa_tcur-nominal.
exch_rate-to_factor = wa_tcur-nominal.
append exch_rate.
call function 'BAPI_EXCHANGERATE_CREATE'
EXPORTING
exch_rate = exch_rate
IMPORTING
return = rettab.
write: / 'USD = '. write wa_tcur-value.
PERFORM print_protocol.
clear exch_rate[].
exch_rate-rate_type = 'M'.
exch_rate-from_curr = 'UUSD'.
exch_rate-to_currncy = 'RUB'.
exch_rate-valid_from = p_date.
exch_rate-exch_rate = wa_tcur-value.
exch_rate-from_factor = wa_tcur-nominal.
exch_rate-to_factor = wa_tcur-nominal.
append exch_rate.
call function 'BAPI_EXCHANGERATE_CREATE'
EXPORTING
exch_rate = exch_rate
IMPORTING
return = rettab.
write: / 'UUSD = '. write wa_tcur-value.
PERFORM print_protocol.
clear exch_rate[].
elseif wa_tcur-charcode = 'EUR'.
exch_rate-rate_type = 'M'.
exch_rate-from_curr = wa_tcur-charcode.
exch_rate-to_currncy = 'RUB'.
exch_rate-valid_from = p_date.
exch_rate-exch_rate = wa_tcur-value.
exch_rate-from_factor = wa_tcur-nominal.
exch_rate-to_factor = wa_tcur-nominal.
append exch_rate.
call function 'BAPI_EXCHANGERATE_CREATE'
EXPORTING
exch_rate = exch_rate
IMPORTING
return = rettab.
write: / 'EUR = '. write wa_tcur-value.
PERFORM print_protocol.
clear exch_rate[].
exch_rate-rate_type = 'M'.
exch_rate-from_curr = 'UEUR'.
exch_rate-to_currncy = 'RUB'.
exch_rate-valid_from = p_date.
exch_rate-exch_rate = wa_tcur-value.
exch_rate-from_factor = wa_tcur-nominal.
exch_rate-to_factor = wa_tcur-nominal.
append exch_rate.
call function 'BAPI_EXCHANGERATE_CREATE'
EXPORTING
exch_rate = exch_rate
IMPORTING
return = rettab.
write: / 'UEUR = '. write wa_tcur-value.
PERFORM print_protocol.
clear exch_rate[].
endif.
endloop.
call function 'BAPI_TRANSACTION_COMMIT'
IMPORTING
return = ret2.
if ret2 is not initial.
write / 'error: unable to commit work'.
endif.
*&---------------------------------------------------------------------*
*& Form print_protocol
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM print_protocol.
if rettab is not initial and p_coment is not initial.
write: / 'protocol:'.
if rettab-MESSAGE = 'Aey iaiiaeaiey ia i?aaoniio?aia ie iaia oaaee?iay caienu.'.
rettab-MESSAGE = 'Aaiiua oniaoii iaiiaeaiu'.
endif.
write: / rettab-ID.
write: / rettab-MESSAGE.
write: / rettab-MESSAGE_V1.
write: / rettab-MESSAGE_V2.
write: / rettab-MESSAGE_V3.
write: / rettab-MESSAGE_V4.
write: / '---------------------------------------'.
endif.
endform. "print_protocol