понедельник, 17 февраля 2014 г.

Загрузка банков с сайта ЦБ РФ

Частые запросы пользователей добавить в систему банк клиента, который отсутствует в системе вынудили написать программу, позволяющая массового актуализировать справочник кредитных организаций в SAP.
В качестве источника информации по кредитным организациям взят справочник с сайта ЦБ РФ.
Алгоритм работы программы следующий:
- Скачать с сайта ЦБ РФ каталог архивов с дампами БД (файлы .DBF) по кредитным организациям;
- Выбрать последний актуальный архив;
- Распаковать архив в память;
- Распарсить дампы БД во внутренние таблицы;
- Обновить данные в справочнике SAP.

Под катом много кода, если кому интересно - велком =)
PS: КПЗ "Справочник"

 

Много кода, я свое слово сдержал:

ZBANK_INFO_UPDATE
*&---------------------------------------------------------------------* *& Report ZBANK_INFO_UPDATE *& *&---------------------------------------------------------------------* *& *& *&---------------------------------------------------------------------* report zbank_info_update. *----------------------------------------------------------------------* * Includes * *----------------------------------------------------------------------* type-pools: icon. *---------------------------------------------------------------------* * CLASS lcl_handle_events DEFINITION *---------------------------------------------------------------------* * §5.1 define a local class for handling events of cl_salv_table *---------------------------------------------------------------------* class lcl_handle_events definition. public section. methods: on_double_click for event double_click of cl_salv_events_table importing row column. endclass. "lcl_handle_events DEFINITION *---------------------------------------------------------------------* * CLASS lcl_handle_events IMPLEMENTATION *---------------------------------------------------------------------* * §5.2 implement the events for handling the events of cl_salv_table *---------------------------------------------------------------------* class lcl_handle_events implementation. method on_double_click. perform on_double_click using row column. endmethod. "on_double_click endclass. "lcl_handle_events IMPLEMENTATION *----------------------------------------------------------------------* * Types definition * *----------------------------------------------------------------------* * Types for ZIP-file types: begin of ty_data, row(1024) type x, end of ty_data, begin of ty_bnkdel, vkey(8) type c, vkeydel(8) type c, pzn(2) type c, uer(1) type c, rgn(2) type c, ind(6) type c," Почтовый индекс tnp(1) type c," Тип населенного пункта nnp(25) type c," НАИМЕНОВАНИЕ НАСЕЛЕННОГО ПУНКТА adr(30) type c," АДРЕС В НАСЕЛЕННОМ ПУНКТЕ rkc(9) type c, namep(45) type c," ПЛАТЕЖНОЕ НАИМЕНОВАНИЕ УЧАСТНИКА РАСЧЕТОВ namen(30) type c, newnum(9) type c," БИК newks(9) type c, permfo(6) type c, srok(2) type c, at1(7) type c, at2(7) type c, telef(25) type c, regn(9) type c, okpo(8) type c, datedel type datum, dt_izm type datum, cks(6) type c, ksnp(20) type c," КОРСЧЕТ r_close(2) type c," Причина закрытия корреспондентского счета (субсчета) date_in type datum, end of ty_bnkdel, tt_bnkdel type table of ty_bnkdel, begin of ty_bnkseek, vkey(8) type c, real(4) type c, pzn(2) type c, uer(1) type c, rgn(2) type c," Регион ind(6) type c," Почтовый индекс tnp(1) type c," Тип населенного пункта nnp(25) type c," НАИМЕНОВАНИЕ НАСЕЛЕННОГО ПУНКТА adr(30) type c," АДРЕС В НАСЕЛЕННОМ ПУНКТЕ rkc(9) type c, namep(45) type c," ПЛАТЕЖНОЕ НАИМЕНОВАНИЕ УЧАСТНИКА РАСЧЕТОВ namen(30) type c, newnum(9) type c," БИК newks(9) type c, permfo(6) type c, srok(2) type c, at1(7) type c, at2(7) type c, telef(25) type c, regn(9) type c, okpo(8) type c, dt_izm type datum, cks(6) type c, ksnp(20) type c," КОРСЧЕТ date_in type datum, date_ch type datum, vkeydel(8) type c, dt_izmr type datum, end of ty_bnkseek, tt_bnkseek type table of ty_bnkseek, begin of ty_co, bic_cf type string, bic_uf type string, dt_st type datum, dt_fin type datum, end of ty_co, tt_co type table of ty_co, begin of ty_fc, vkey(2) type c, basech(12) type c, end of ty_fc, tt_fc type table of ty_fc, begin of ty_keybaseb, vkey(8) type c, bvkey(8) type c, newnum(9) type c, namemaxb(140) type c, end of ty_keybaseb, tt_keybaseb type table of ty_keybaseb, begin of ty_keybasef, vkey(8) type c, fvkey(8) type c, namemaxf(75) type c, newnum(9) type c, end of ty_keybasef, tt_keybasef type table of ty_keybasef, begin of ty_kgur, vkey(2) type c, kgur(2) type c, newnum(9) type c, date_end type datum, end of ty_kgur, tt_kgur type table of ty_kgur, begin of ty_korrek, kor(4) type c, ver(2) type c, dt_izm type datum, chs(14) type c, end of ty_korrek, tt_korrek type table of ty_korrek, begin of ty_prim, vkey(8) type c, prim1(30) type c, prim2(34) type c, prim3(30) type c, end of ty_prim, tt_prim type table of ty_prim, begin of ty_pzn, vkey(2) type c, pzn(2) type c," Код imy(4) type c," Краткое наименование name(40) type c," Полное наименование cb_date type datum, ce_date type datum, end of ty_pzn, tt_pzn type table of ty_pzn, begin of ty_rayon, vkey(8) type c, name(75) type c, end of ty_rayon, tt_rayon type table of ty_rayon, begin of ty_rclose, vkey(2) type c, r_close(2) type c, nameclose(45) type c, end of ty_rclose, tt_rclose type table of ty_rclose, begin of ty_real, vkey(4) type c, real(4) type c," Код контроля name_ogr(60) type c," Полное наименование end of ty_real, tt_real type table of ty_real, begin of ty_reg, vkey(2) type c, rgn(2) type c, name(40) type c, center(30) type c, namet(40) type c, end of ty_reg, tt_reg type table of ty_reg, begin of ty_tnp, vkey(2) type c, tnp(2) type c, fullname(25) type c," Полное наименование shortname(5) type c," Тип населенного пункта end of ty_tnp, tt_tnp type table of ty_tnp, begin of ty_uer, vkey(2) type c, uer(1) type c, uername(70) type c, end of ty_uer, tt_uer type table of ty_uer, begin of ty_uerko, vkey(2) type c, uerko(1) type c, uername(70) type c, end of ty_uerko, tt_uerko type table of ty_uerko. * Данные для вывода на экран types: begin of ty_alv, icon type icon_d," Статус лицензии Отозвана/Не отозвана sap type c," Индикатор наличия в справочнике SAP is_dif type c," Индикатор наличия расхождений bic(9) type c," БИК namep(45) type c," Наименование message_type type icon_d," Статус сообщения message type text255, corr_schet(20) type c," Корр.счет name_ogr(60) type c," Полное наименование ограничения в расчетах imy(4) type c," Тип участн.расч. rgn(2) type c," Регион post_ind(6) type c," Почтовый индекс nnp(25) type c," НАИМЕНОВАНИЕ НАСЕЛЕННОГО ПУНКТА adr(30) type c," АДРЕС В НАСЕЛЕННОМ ПУНКТЕ end of ty_alv, tt_alv type table of ty_alv. *----------------------------------------------------------------------* * Constants * *----------------------------------------------------------------------* constants: c_bic_cat_url type string value 'http://www.cbr.ru/mcirabis/PluginInterface/GetBicCatalog.aspx'. *----------------------------------------------------------------------* * Global Data Declaration * *----------------------------------------------------------------------* data: gt_alv type tt_alv, gs_alv type ty_alv, gr_response type ref to if_http_response, g_xml_resp type string, gv_bin_data type xstring, " Tables for DBF data gt_bnkdel type tt_bnkdel," база данных удаленных "кредитных организаций и их правопреемников gt_bnkseek type tt_bnkseek," Справочник БИК РФ "участников расчетов gt_co type tt_co, gt_fc type tt_fc, " Список файлов в архиве gt_keybaseb type tt_keybaseb, gt_keybasef type tt_keybasef," файл базы данных "юридических наименований филиалов кредитных организаций; gt_kgur type tt_kgur, gt_korrek type tt_korrek," Лог изменений (ХЗ чего) gt_prim type tt_prim, gt_pzn type tt_pzn, " Типы участников расчётов. gt_rayon type tt_rayon, " Перечень районов gt_rclose type tt_rclose," Причина закрытия "корреспондентского счета (субсчета) gt_real type tt_real, " Признак ограничения "участия в расчётах gt_reg type tt_reg, " Кодовый указатель "территорий России gt_tnp type tt_tnp, " код типа населенного "пункта gt_uer type tt_uer, " коды участников электронных "расчетов (Признаки участия в электронных расчетах) gt_uerko type tt_uerko, " Наименование типа "пользователя системы электронных " расчетов и участника обмена электронными документами gs_bnkdel type tt_bnkdel, gs_bnkseek type tt_bnkseek, gs_reg type tt_reg, gs_pzn type tt_pzn, gs_real type tt_real. * Data for transformation data: begin of gs_correct, file type string, hash type string, end of gs_correct. data: begin of gs_bik_list, file type string, date type string, hash type string, it_correct like table of gs_correct, end of gs_bik_list. data: gv_base type string, gv_version type string, gv_date_generation type string, gv_doc_name type string, gt_bik_list like table of gs_bik_list, gv_catalog_hash type string, gv_file_url type string. data: lr_table type ref to cl_salv_table. data: gv_date type char10. *----------------------------------------------------------------------* * Selection Screen * *----------------------------------------------------------------------* selection-screen begin of block b01 with frame title aaa. selection-screen begin of line. selection-screen comment 1(50) cm1. parameters: p_upd as checkbox default abap_false. selection-screen end of line. selection-screen begin of line. selection-screen comment 1(50) cm2. parameters: p_dsp as checkbox default abap_true. selection-screen end of line. selection-screen end of block b01. selection-screen begin of block b02 with frame title bbb. selection-screen begin of line. selection-screen comment 1(50) cm3. parameters: p_upddel as checkbox default abap_false. selection-screen end of line. selection-screen begin of line. selection-screen comment 1(50) cm4. parameters: p_ddif as checkbox default abap_false. selection-screen end of line. selection-screen end of block b02. *----------------------------------------------------------------------* * At selection screen events * *----------------------------------------------------------------------* *----------------------------------------------------------------------* * Initialization * *----------------------------------------------------------------------* initialization. aaa = 'Режим работы программы '. bbb = 'Правила обновления данных'. cm1 = 'Обновить данные в справочнике'. cm2 = 'Выводить результат'. cm3 = 'Создавать банки с отозванной лицензией'. cm4 = 'Устранять расхождения в справочниках'. *----------------------------------------------------------------------* * Start of selection * *----------------------------------------------------------------------* start-of-selection. " Загрузим XML со списком архивов perform get_response using c_bic_cat_url changing gr_response. g_xml_resp = gr_response->get_cdata( ). check sy-subrc eq 0. free gr_response. perform transform_xml using g_xml_resp changing gv_base gv_version gv_date_generation gv_doc_name gt_bik_list gv_catalog_hash. perform get_newest_file_url using gt_bik_list gv_base changing gv_file_url gv_date. " Загрузим последний актуальный архив perform get_response using gv_file_url changing gr_response. gv_bin_data = gr_response->get_data( ). free gr_response. perform read_data_file using gv_bin_data changing gt_bnkdel gt_bnkseek gt_co gt_fc gt_keybaseb gt_keybasef gt_kgur gt_korrek gt_prim gt_pzn gt_rayon gt_rclose gt_real gt_reg gt_tnp gt_uer gt_uerko . * Формирование итоговой таблицы perform prepare_data_for_input using gt_bnkseek gt_real gt_pzn changing gt_alv. if p_upd eq abap_true. perform update_bank_info changing gt_alv. endif. if p_dsp eq abap_true. perform alv_display using gt_alv p_upd gv_date. endif. *----------------------------------------------------------------------* * Forms * *----------------------------------------------------------------------* *&---------------------------------------------------------------------* *& Form get_response *&---------------------------------------------------------------------* form get_response using i_url type string changing cr_response type ref to if_http_response. data: lr_client type ref to if_http_client. if not cr_response is initial. free cr_response. endif. cl_http_client=>create_by_url( exporting url = i_url importing client = lr_client exceptions internal_error = 1 argument_not_found = 2 plugin_not_active = 3 others = 4 ). if sy-subrc ne 0. message 'Create client error' type 'I'. leave to screen 0. endif. lr_client->send( exceptions http_communication_failure = 1 http_invalid_state = 2 http_processing_failed = 3 others = 4 ). if sy-subrc ne 0. message 'Request send error' type 'I'. leave to screen 0. endif. lr_client->receive( exceptions http_communication_failure = 1 http_invalid_state = 2 http_processing_failed = 3 others = 4 ). if sy-subrc ne 0. message 'Recieve response error' type 'I'. leave to screen 0. endif. cr_response = lr_client->response. free lr_client. endform. "get_response *&---------------------------------------------------------------------* *& Form transform_xml *&---------------------------------------------------------------------* form transform_xml using i_xml type string changing cv_base type string cv_version type string cv_date_generation type string cv_doc_name type string ct_bik_list like gt_bik_list cv_catalog_hash type string. data: oref type ref to cx_root, xslt_message type string. clear: cv_base,cv_version,cv_date_generation,cv_doc_name, ct_bik_list[],cv_catalog_hash. try . call transformation ('ZCBR_BICLIST') source xml i_xml result v_base = cv_base v_version = cv_version v_date_generation = cv_date_generation v_doc_name = cv_doc_name t_bik_list = ct_bik_list v_catalog_hash = cv_catalog_hash . catch cx_xslt_exception into oref. xslt_message = oref->get_text( ). message xslt_message type 'I'. leave to screen 0. catch cx_st_match_element into oref. xslt_message = oref->get_text( ). message xslt_message type 'I'. leave to screen 0. catch cx_root into oref. xslt_message = oref->get_text( ). message xslt_message type 'I'. leave to screen 0. endtry. endform. "transform_xml *&---------------------------------------------------------------------* *& Form get_newest_file_url *&---------------------------------------------------------------------* form get_newest_file_url using it_bik_list like gt_bik_list iv_base type string changing c_url type string c_date type char10. data: lv_date(10) type c, lv_datum type sy-datum, ls_bik_list like line of it_bik_list. clear: lv_date,lv_datum,ls_bik_list. lv_datum = sy-datum + 1. write lv_datum to lv_date dd/mm/yyyy. read table it_bik_list into ls_bik_list with key date = lv_date. if not sy-subrc eq 0. clear: lv_date,lv_datum. lv_datum = sy-datum. write lv_datum to lv_date dd/mm/yyyy. read table it_bik_list into ls_bik_list with key date = lv_date. if not sy-subrc eq 0. clear: lv_date,lv_datum. lv_datum = sy-datum - 1. write lv_datum to lv_date dd/mm/yyyy. read table it_bik_list into ls_bik_list with key date = lv_date. endif. endif. check sy-subrc eq 0. concatenate 'http://www.cbr.ru' iv_base ls_bik_list-file into c_url. c_date = lv_date. endform. "get_newest_file_url *&---------------------------------------------------------------------* *& Form read_data_file *&---------------------------------------------------------------------* form read_data_file using i_bin_data type xstring changing ct_bnkdel type tt_bnkdel ct_bnkseek type tt_bnkseek ct_co type tt_co ct_fc type tt_fc ct_keybaseb type tt_keybaseb ct_keybasef type tt_keybasef ct_kgur type tt_kgur ct_korrek type tt_korrek ct_prim type tt_prim ct_pzn type tt_pzn ct_rayon type tt_rayon ct_rclose type tt_rclose ct_real type tt_real ct_reg type tt_reg ct_tnp type tt_tnp ct_uer type tt_uer ct_uerko type tt_uerko . data: lr_zip type ref to cl_abap_zip, lt_files type cl_abap_zip=>t_splice_entries, ls_file like line of lt_files, lv_content type xstring, lt_binary type table of ty_data, lv_length type i, lv_outlength type i. create object lr_zip. lr_zip->load( i_bin_data ). lt_files = lr_zip->splice( i_bin_data ). loop at lt_files into ls_file. clear: lv_content,lt_binary[],lv_length. lr_zip->get( exporting name = ls_file-name importing content = lv_content ). case ls_file-name. when 'BNKDEL.DBF'. clear ct_bnkdel[]. perform read_dbf_2 tables ct_bnkdel changing lv_content. when 'BNKSEEK.DBF'. clear ct_bnkseek[]. perform read_dbf_2 tables ct_bnkseek changing lv_content. when 'CO.DBF'. clear ct_co[]. perform read_dbf_2 tables ct_co changing lv_content. when 'FC.DBF'. clear ct_fc[]. perform read_dbf_2 tables ct_fc changing lv_content. when 'KEYBASEB.DBF'. clear ct_keybaseb[]. perform read_dbf_2 tables ct_keybaseb changing lv_content. when 'KEYBASEF.DBF'." файл базы данных юридических наименований филиалов кредитных организаций; clear ct_keybasef[]. perform read_dbf_2 tables ct_keybasef changing lv_content. when 'KGUR.DBF'. clear ct_kgur[]. perform read_dbf_2 tables ct_kgur changing lv_content. when 'KORREK.DBF'. clear ct_korrek[]. perform read_dbf_2 tables ct_korrek changing lv_content. when 'PRIM.DBF'. clear ct_prim[]. perform read_dbf_2 tables ct_prim changing lv_content. when 'PZN.DBF'." Типы участников расчётов. clear ct_pzn[]. perform read_dbf_2 tables ct_pzn changing lv_content. when 'RAYON.DBF'. clear ct_rayon[]. perform read_dbf_2 tables ct_rayon changing lv_content. when 'RCLOSE.DBF'. clear ct_rclose[]. perform read_dbf_2 tables ct_rclose changing lv_content. when 'REAL.DBF'." Признак ограничения участия в расчётах clear ct_real[]. perform read_dbf_2 tables ct_real changing lv_content. when 'REG.DBF'." Кодовый указатель территорий России clear ct_reg[]. perform read_dbf_2 tables ct_reg changing lv_content. when 'TNP.DBF'." Типы населенных пунктов clear ct_tnp[]. perform read_dbf_2 tables ct_tnp changing lv_content. when 'UER.DBF'." Признаки участия в электронных расчетах clear ct_uer[]. perform read_dbf_2 tables ct_uer changing lv_content. when 'UERKO.DBF'." Наименование типа пользователя системы электронных " расчетов и участника обмена электронными документами clear ct_uerko[]. perform read_dbf_2 tables ct_uerko changing lv_content. when others. continue. endcase. endloop. free lr_zip. endform. "read_data_file *&---------------------------------------------------------------------* *& Form read_dbf_2 *&---------------------------------------------------------------------* form read_dbf_2 tables pt_dbf changing xdbf. * Dbf Header data: begin of ls_dbf_head , date like sy-datum , rows type int4 , start_offset type int2 , row_len type int2 , codepage type int1 , zdate(6) type c , end of ls_dbf_head. * Fields Catalog data: begin of lt_dbf_fields occurs 0 , name type char10 , type type c , pos type int4 , len type int1 , digits type int1 , end of lt_dbf_fields. data l_xdbf type xstring. data l_xstring type xstring. data l_xfield type xstring. data l_xrow type xstring. data l_len type i. data l_fields_len type i. data l_offset type i. data l_field_offset type i. field-symbols type any. field-symbols type any. field-symbols type any. * All Table into X string clear l_xdbf. * * loop at pt_xdata assigning . * assign component 1 of structure to . * check sy-subrc eq 0. * * l_xstring = . * concatenate l_xdbf l_xstring into l_xdbf in byte mode. * endloop. concatenate l_xdbf xdbf into l_xdbf in byte mode. * Fill Dbf Header clear ls_dbf_head. * Count of Rows l_xstring = l_xdbf+4(4). perform convert_from_x using l_xstring changing ls_dbf_head-rows. * Start Offset l_xstring = l_xdbf+8(2). perform convert_from_x using l_xstring changing ls_dbf_head-start_offset. * Row Len l_xstring = l_xdbf+10(2). perform convert_from_x using l_xstring changing ls_dbf_head-row_len. * ---------- * Code Page l_xstring = l_xdbf+29(1). perform convert_from_x using l_xstring changing ls_dbf_head-codepage. * Date l_xstring = l_xdbf+1(3). perform convert_from_x using l_xstring changing ls_dbf_head-zdate. * ---------- * Fill Dbf Fields refresh lt_dbf_fields[]. l_offset = 32. l_fields_len = ls_dbf_head-start_offset - 1. while l_offset lt l_fields_len. l_xfield = l_xdbf+l_offset(32). clear lt_dbf_fields. * Field Name l_xstring = l_xfield(10). perform convert_from_x using l_xstring changing lt_dbf_fields-name. * Field Type l_xstring = l_xfield+11(1). perform convert_from_x using l_xstring changing lt_dbf_fields-type. * Field Position l_xstring = l_xfield+12(4). perform convert_from_x using l_xstring changing lt_dbf_fields-pos. * Field Length l_xstring = l_xfield+16(1). perform convert_from_x using l_xstring changing lt_dbf_fields-len. * Digits l_xstring = l_xfield+17(1). perform convert_from_x using l_xstring changing lt_dbf_fields-digits. append lt_dbf_fields. add 32 to l_offset. endwhile. * Fill Data refresh pt_dbf[]. l_offset = ls_dbf_head-start_offset. do ls_dbf_head-rows times. l_xrow = l_xdbf+l_offset(ls_dbf_head-row_len). clear pt_dbf. * Not Deleted check l_xrow(1) eq '20'. l_field_offset = 1. * For All Fields loop at lt_dbf_fields. assign component lt_dbf_fields-name of structure pt_dbf to . check sy-subrc eq 0. l_len = lt_dbf_fields-len. l_xstring = l_xrow+l_field_offset(l_len). * Read Value perform convert_from_x using l_xstring changing . add l_len to l_field_offset. endloop. add l_field_offset to l_offset. append pt_dbf. enddo. endform. "read_dbf_2 *&---------------------------------------------------------------------* *& Form convert_from_x *&---------------------------------------------------------------------* form convert_from_x using p_xstring type xstring changing p_value. data l_encoding type abap_encoding value '1508'. data l_type type c. data l_x00 type x value '00'. data l_x20 type x value '20'. * Convert From XString data lc_conv type ref to cl_abap_conv_in_ce. data l_len type i. data l_xstring type xstring. l_xstring = p_xstring. describe field p_value type l_type. if l_type ca 'Cg'. replace all occurrences of l_x00 in l_xstring with l_x20 in byte mode. endif. cl_abap_conv_in_ce=>create( exporting input = l_xstring encoding = l_encoding replacement = space ignore_cerr = abap_true receiving conv = lc_conv ). try. lc_conv->read( importing data = p_value len = l_len ). * Should ignore errors in code conversions catch cx_sy_conversion_codepage. catch cx_sy_codepage_converter_init. catch cx_parameter_invalid_type. catch cx_parameter_invalid_range. endtry. endform. "convert_from_x *&---------------------------------------------------------------------* *& Form prepare_data_for_input *&---------------------------------------------------------------------* form prepare_data_for_input using it_bnkseek type tt_bnkseek it_real type tt_real it_pzn type tt_pzn changing ct_alv type tt_alv. data: ls_bnkseek type ty_bnkseek, ls_real type ty_real, ls_pzn type ty_pzn, ls_alv type ty_alv. clear ct_alv[]. loop at it_bnkseek into ls_bnkseek. clear ls_alv. ls_alv-icon = icon_led_green. ls_alv-bic = ls_bnkseek-newnum. ls_alv-namep = ls_bnkseek-namep. ls_alv-corr_schet = ls_bnkseek-ksnp. ls_alv-rgn = ls_bnkseek-rgn. ls_alv-post_ind = ls_bnkseek-ind. " Почтовый индекс ls_alv-nnp = ls_bnkseek-nnp." НАИМЕНОВАНИЕ НАСЕЛЕННОГО ПУНКТА ls_alv-adr = ls_bnkseek-adr." АДРЕС В НАСЕЛЕННОМ ПУНКТЕ read table it_real into ls_real with key real = ls_bnkseek-real. if sy-subrc eq 0. ls_alv-name_ogr = ls_real-name_ogr. endif. if ls_bnkseek-real eq 'ОТЗВ'." Лицензия отозвана ls_alv-icon = icon_led_red. endif. read table it_pzn into ls_pzn with key pzn = ls_bnkseek-pzn. if sy-subrc eq 0. ls_alv-imy = ls_pzn-imy. endif. perform check_bank_in_sap changing ls_alv. append ls_alv to ct_alv. endloop. endform. "prepare_data_for_input *&---------------------------------------------------------------------* *& Form check_bank_in_sap *&---------------------------------------------------------------------* form check_bank_in_sap changing cs_alv type ty_alv. data: ls_address type bapi1011_address, ls_detail type bapi1011_detail, ls_return type bapiret2. cs_alv-is_dif = abap_false. perform bapi_bank_getdetail using cs_alv-bic changing ls_address ls_detail ls_return. if ls_return-type eq 'E' and ls_return-id eq 'BF00' and ls_return-number eq '211'." Банк & & отсутствует. cs_alv-sap = abap_false. return. else. cs_alv-sap = abap_true. endif. check not cs_alv-namep eq ls_address-bank_name. cs_alv-is_dif = abap_true. * check not cs_alv-rgn eq ls_address-region. * cs_alv-is_dif = abap_true. check not cs_alv-nnp eq ls_address-city. cs_alv-is_dif = abap_true. check not cs_alv-adr eq ls_address-street. cs_alv-is_dif = abap_true. check not cs_alv-corr_schet eq ls_address-bank_branch. cs_alv-is_dif = abap_true. endform. "check_bank_in_sap *&---------------------------------------------------------------------* *& Form BAPI_BANK_GETDETAIL *&---------------------------------------------------------------------* form bapi_bank_getdetail using value(i_bankkey) changing c_address type bapi1011_address c_detail type bapi1011_detail c_return type bapiret2. data: l_bank_key type bapi1011_key-bank_key, l_bank_ctry type bapi1011_key-bank_ctry. l_bank_ctry = 'RU'. l_bank_key = i_bankkey. call function 'BAPI_BANK_GETDETAIL' EXPORTING bankcountry = l_bank_ctry bankkey = l_bank_key IMPORTING bank_address = c_address bank_detail = c_detail return = c_return. endform. "BAPI_BANK_GETDETAIL *&---------------------------------------------------------------------* *& Form update_bank_info *&---------------------------------------------------------------------* form update_bank_info changing ct_alv type tt_alv. field-symbols: type ty_alv. loop at ct_alv assigning . if -sap eq abap_true. if -is_dif eq abap_true and p_ddif eq abap_true. perform bapi_bank_change changing . else. -message_type = icon_led_green. -message = 'Информация по банку не менялась.'. endif. else. if -icon eq icon_led_red and p_upddel eq abap_true. -message_type = icon_led_red. -message = 'Отозвана лицензия.Банк не создан.'. continue. endif. perform bapi_bank_create changing . endif. endloop. endform. "update_bank_info *&---------------------------------------------------------------------* *& Form BAPI_BANK_CREATE *&---------------------------------------------------------------------* form bapi_bank_create changing cs_alv type ty_alv. data: l_bank_ctry type bapi1011_key-bank_ctry value 'RU', l_bank_key type bapi1011_key-bank_key, l_bank_address type bapi1011_address, l_return type bapiret2. l_bank_key = cs_alv-bic. l_bank_address-bank_name = cs_alv-namep . * l_bank_address-region = cs_alv-rgn . l_bank_address-city = cs_alv-nnp . l_bank_address-street = cs_alv-adr . l_bank_address-bank_branch = cs_alv-corr_schet. call function 'BAPI_BANK_CREATE' EXPORTING bank_ctry = l_bank_ctry bank_key = l_bank_key bank_address = l_bank_address IMPORTING return = l_return. if l_return-type ca 'EAX'. cs_alv-message_type = icon_led_red. cs_alv-message = l_return-message. cs_alv-sap = abap_false. perform bapi_rollback. else. cs_alv-message_type = icon_led_green. cs_alv-message = 'Банк создан в справочнике.'. cs_alv-sap = abap_true. perform bapi_commit. endif. endform. "BAPI_BANK_CREATE *&---------------------------------------------------------------------* *& Form bapi_bank_change *&---------------------------------------------------------------------* form bapi_bank_change changing cs_alv type ty_alv. data: l_bank_ctry type bapi1011_key-bank_ctry value 'RU', l_bank_key type bapi1011_key-bank_key, l_bank_address type bapi1011_address, l_bank_addressx type bapi1011_addressx, l_return type bapiret2. l_bank_key = cs_alv-bic. l_bank_address-bank_name = cs_alv-namep . * l_bank_address-region = cs_alv-rgn . l_bank_address-city = cs_alv-nnp . l_bank_address-street = cs_alv-adr . l_bank_address-bank_branch = cs_alv-corr_schet. l_bank_addressx-bank_name = abap_true. * l_bank_addressx-region = abap_true. l_bank_addressx-city = abap_true. l_bank_addressx-street = abap_true. l_bank_addressx-bank_branch = abap_true. call function 'BAPI_BANK_CHANGE' EXPORTING bankcountry = l_bank_ctry bankkey = l_bank_key bank_address = l_bank_address bank_addressx = l_bank_addressx IMPORTING return = l_return. if l_return-type ca 'EAX'. cs_alv-message_type = icon_led_red. cs_alv-message = l_return-message. cs_alv-is_dif = abap_true. perform bapi_rollback. else. cs_alv-message_type = icon_led_green. cs_alv-message = 'Информация по банку актуализирована'. cs_alv-is_dif = abap_false. perform bapi_commit. endif. endform. "bapi_bank_change *&---------------------------------------------------------------------* *& Form bapi_commit *&---------------------------------------------------------------------* form bapi_commit. data: ls_ret type bapiret2. call function 'BAPI_TRANSACTION_COMMIT' EXPORTING wait = 'X' IMPORTING return = ls_ret. endform. "bapi_commit *&---------------------------------------------------------------------* *& Form bapi_ROLLBACK *&---------------------------------------------------------------------* form bapi_rollback. data: ls_ret type bapiret2. call function 'BAPI_TRANSACTION_ROLLBACK' IMPORTING return = ls_ret. endform. "bapi_ROLLBACK *&---------------------------------------------------------------------* *& Form alv_display *&---------------------------------------------------------------------* form alv_display using it_out type tt_alv as_journal type c iv_date type char10. data: lr_functions type ref to cl_salv_functions, lr_columns type ref to cl_salv_columns_table, lr_column type ref to cl_salv_column_table, lr_header type ref to cl_salv_display_settings. data: l_title type lvc_title, l_lines type i, l_str type string. data: lr_events type ref to cl_salv_events_table, lr_events_handler type ref to lcl_handle_events. describe table it_out lines l_lines. l_str = l_lines. "Инициируем alv cl_salv_table=>factory( importing r_salv_table = lr_table changing t_table = it_out ). if as_journal eq abap_true. l_title = 'Банки.Журнал обновления'. else. concatenate 'Банки.Справочник от ' ` ` iv_date ` ` '( ' ` ` l_str ` ` 'записи )' into l_title. endif. "Создаем заголовок lr_header = lr_table->get_display_settings( ). lr_header->set_striped_pattern( 'X' ). lr_header->set_list_header( l_title ). "Создаем кнопки lr_functions = lr_table->get_functions( ). lr_functions->set_all( abap_true ). lr_columns = lr_table->get_columns( ). * lr_column ?= lr_columns->get_column( 'ICON' ). lr_column->set_long_text( 'Статус лицензии' ). lr_column->set_medium_text( 'Стат.лиц.' ). lr_column->set_short_text('Стат.лиц' ). lr_column->set_output_length( 7 ). lr_column->set_alignment( 3 ). * lr_column ?= lr_columns->get_column( 'BIC' ). lr_column->set_long_text( 'БИК' ). lr_column->set_medium_text( 'БИК' ). lr_column->set_short_text('БИК' ). * lr_column ?= lr_columns->get_column( 'NAMEP' ). lr_column->set_long_text( 'Наименование' ). lr_column->set_medium_text( 'Наименование' ). lr_column->set_short_text('Наимен' ). * lr_column ?= lr_columns->get_column( 'CORR_SCHET' ). lr_column->set_long_text( 'Корр.счет' ). lr_column->set_medium_text( 'Корр.счет' ). lr_column->set_short_text('Корр.сч' ). * lr_column ?= lr_columns->get_column( 'POST_IND' ). lr_column->set_long_text( 'Почтовый индекс' ). lr_column->set_medium_text( 'Почт.инд' ). lr_column->set_short_text('Почт.инд.' ). * lr_column ?= lr_columns->get_column( 'NNP' ). lr_column->set_long_text( 'Населенный пункт' ). lr_column->set_medium_text( 'Насел.пункт' ). lr_column->set_short_text('Нас.пун' ). * lr_column ?= lr_columns->get_column( 'ADR' ). lr_column->set_long_text( 'Адрес' ). lr_column->set_medium_text( 'Адрес' ). lr_column->set_short_text('Адрес' ). * lr_column ?= lr_columns->get_column( 'NAME_OGR' ). lr_column->set_long_text( 'Огранич.в расч.' ). lr_column->set_medium_text( 'Огранич.' ). lr_column->set_short_text('Огранич.' ). lr_column->set_output_length( 23 ). * lr_column ?= lr_columns->get_column( 'IMY' ). lr_column->set_long_text( 'Типы участн.расч.' ). lr_column->set_medium_text( 'Тип.уч.' ). lr_column->set_short_text('Тип.уч.рсч' ). * lr_column ?= lr_columns->get_column( 'RGN' ). lr_column->set_long_text( 'Регион' ). lr_column->set_medium_text( 'Регион' ). lr_column->set_short_text('Регион' ). * lr_column ?= lr_columns->get_column( 'SAP' ). lr_column->set_long_text( 'Заведен в SAP' ). lr_column->set_medium_text( 'Заведен SAP' ). lr_column->set_short_text('SAP' ). lr_column->set_output_length( 4 ). lr_column->set_alignment( 3 ). * lr_column ?= lr_columns->get_column( 'IS_DIF' ). lr_column->set_long_text( 'Имеются расхождения' ). lr_column->set_medium_text( 'Расхождения' ). lr_column->set_short_text('Расхожд' ). lr_column->set_output_length( 4 ). lr_column->set_alignment( 3 ). * lr_column ?= lr_columns->get_column( 'MESSAGE_TYPE' ). lr_column->set_long_text( 'Тип сообщения' ). lr_column->set_medium_text( 'Тип сообщ' ). lr_column->set_short_text('Тип сообщ.' ). lr_column->set_output_length( 7 ). lr_column->set_alignment( 3 ). if as_journal eq abap_false. lr_column->set_technical( abap_true ). endif. * lr_column ?= lr_columns->get_column( 'MESSAGE' ). lr_column->set_long_text( 'Сообщение' ). lr_column->set_medium_text( 'Сообщение' ). lr_column->set_short_text( 'Сообщение' ). lr_column->set_output_length( 50 ). if as_journal eq abap_false. lr_column->set_technical( abap_true ). endif. * *... §6 register to the events of cl_salv_table lr_events = lr_table->get_event( ). create object lr_events_handler. *... §6.4 register to the event DOUBLE_CLICK set handler lr_events_handler->on_double_click for lr_events. "Выводим на экран lr_table->display( ). endform. "alv_display *&---------------------------------------------------------------------* *& Form on_double_click *&---------------------------------------------------------------------* form on_double_click using row type salv_de_row column type salv_de_column. data: l_answer type c. field-symbols: type ty_alv. read table gt_alv assigning index row. check sy-subrc eq 0. case column. when 'BIC'. if -sap eq abap_true. set parameter id 'BKL' field 'RU'. set parameter id 'BNK' field -bic. call transaction 'FI03' and skip first screen. else. message 'Банк еще не заведен в справочнике.' type 'S'. endif. when 'SAP'. if -sap eq abap_false. perform popup_to_confirm using 'Загрузить банк в справочник SAP ?' changing l_answer. if l_answer eq '1'. perform bapi_bank_create changing . lr_table->refresh( ). message -message type 'S'. else. message 'Операция отменена пользователем' type 'S'. endif. else. message 'Банк уже существует в справочнике.' type 'S'. endif. when 'IS_DIF'. if -is_dif eq abap_true. perform popup_to_confirm using 'Обновить информацию по банку в справочник SAP ?' changing l_answer. if l_answer eq '1'. perform bapi_bank_change changing . lr_table->refresh( ). message -message type 'S'. else. message 'Операция отменена пользователем' type 'S'. endif. else. message 'Расхождений в справочниках нет.' type 'S'. endif. endcase. endform. "on_double_click *&---------------------------------------------------------------------* *& Form POPUP_TO_CONFIRM *&---------------------------------------------------------------------* form popup_to_confirm using value(text) changing value(answer). clear answer. call function 'POPUP_TO_CONFIRM' exporting text_question = text display_cancel_button = ' ' importing answer = answer. endform. "POPUP_TO_CONFIRM

2 комментария:

  1. Добрый день!
    Все FIELD-SYMBOLS из за треугольных кавычек пропали из кода. Видимо потому что очень похожи на теги )

    ОтветитьУдалить
    Ответы
    1. Запоздалый ответ)
      Вы все верно сказали, пока не нашел как можно было бы красиво код сюда добавлять)

      Удалить