Posted: Fri Dec 04, 2009 6:01 pm Post subject: HTTP
ФМ HTTP2_GET
У этого ФМа есть один нюанс - в таблице response_entity_body возвращается не текст, как положено, а некое двоичное представление этого текста, которое еще нужно привести в удобоваримый вид.
Нижеследующий исходник, любезно предоставленный John Doe, демонстрирует как это сделать:
Code:
TYPE-POOLS: truxs, slis.
CONSTANTS: cs_url TYPE mmpur_url
VALUE 'http://www.cbr.ru/scripts/XML_daily.asp?date_req=DD/MM/YYYY&d='.
DATA: url TYPE mmpur_url,
length TYPE i,
http_load_data TYPE truxs_xml_table,
http_load_headers TYPE TABLE OF char256,
xml_in TYPE xstring,
xml_out TYPE TABLE OF smum_xmltb,
xml_line TYPE smum_xmltb,
return TYPE TABLE OF bapiret2,
fieldname TYPE fieldname,
fcat TYPE slis_t_fieldcat_alv,
title TYPE text70.
DATA: BEGIN OF itab OCCURS 0,
id LIKE vwrpltaf-feldname,
numcode LIKE t242q-numbr,
charcode LIKE tcurr-tcurr,
nominal LIKE tcurr-tfact,
name LIKE tcurt-ltext,
value LIKE tcurr-ukurs,
END OF itab.
FIELD-SYMBOLS: <field>.
PARAMETERS: datum TYPE sy-datum DEFAULT sy-datum,
daily RADIOBUTTON GROUP type DEFAULT 'X',
montly RADIOBUTTON GROUP type.
START-OF-SELECTION.
url = cs_url.
REPLACE ALL OCCURRENCES OF:
'DD' IN url WITH datum+6(2),
'MM' IN url WITH datum+4(2),
'YYYY' IN url WITH datum(4).
IF daily IS NOT INITIAL.
CONCATENATE url '0' INTO url.
ELSE.
CONCATENATE url '1' INTO url.
ENDIF.
READ TABLE return TRANSPORTING NO FIELDS
WITH KEY type = 'E'.
IF sy-subrc IS INITIAL.
CALL FUNCTION 'C14ALD_BAPIRET2_SHOW'
TABLES
i_bapiret2_tab = return.
EXIT.
ENDIF.
LOOP AT xml_out INTO xml_line.
TRANSLATE xml_line-cname TO UPPER CASE.
ASSIGN COMPONENT xml_line-cname OF STRUCTURE itab TO <field>.
CHECK sy-subrc IS INITIAL.
IF xml_line-cname EQ 'VALUE'.
REPLACE FIRST OCCURRENCE OF ',' IN xml_line-cvalue WITH '.'.
MOVE xml_line-cvalue TO <field>.
APPEND itab.
ELSEIF xml_line-cname EQ 'VALUTE'.
CLEAR itab.
CONTINUE.
ELSE.
MOVE xml_line-cvalue TO <field>.
ENDIF.
ENDLOOP.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = sy-repid
i_internal_tabname = 'ITAB'
i_inclname = sy-repid
CHANGING
ct_fieldcat = fcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
WRITE datum TO title.
CONCATENATE 'Currency rates from CBRF on' title INTO
title SEPARATED BY space.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
it_fieldcat = fcat
i_grid_title = title
TABLES
t_outtab = itab.
Добавил John Doe: это пример по считыванию курсов валют с сайта ЦБ РФ. Выложил полностью для увеличения информативности. В данной программе присутствует также привязка к типам таблицы данных.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.