Zfirp0001 F01

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 6

*&---------------------------------------------------------------------*

*& INCLUDE ZFIRP0001_F01


*&---------------------------------------------------------------------*

*&---------------------------------------------------------------------*
*& FORM F_SEL_FILE
*&---------------------------------------------------------------------*
*& TEXT
*&---------------------------------------------------------------------*
FORM f_sel_file .
DATA: gt_file TYPE filetable,
lt_file TYPE file_table,
lv_rc TYPE i.

CALL METHOD cl_gui_frontend_services=>file_open_dialog


CHANGING
file_table = gt_file
rc = lv_rc
EXCEPTIONS
file_open_dialog_failed = 1
cntl_error = 2
error_no_gui = 3
not_supported_by_gui = 4
OTHERS = 5.

IF sy-subrc EQ 0.
READ TABLE gt_file INTO lt_file INDEX 1.
IF sy-subrc EQ 0.
p_file = lt_file-filename.
ENDIF.
ENDIF.
ENDFORM.

*&---------------------------------------------------------------------*
*& FORM F_CARREGA_TXT
*&---------------------------------------------------------------------*
*& TEXT
*&---------------------------------------------------------------------*
FORM f_carrega_txt .

DATA: gt_bp1012 TYPE TABLE OF bp1012,


gt_bp1012_aux TYPE TABLE OF bp1012,
gt_bp1012_x TYPE TABLE OF bp1012_x,
lt_bp1012 TYPE bp1012,
lt_bp1012_x TYPE bp1012_x.

DATA: lt_raw TYPE truxs_t_text_data,


gt_file TYPE string.

gt_file = p_file.

CALL METHOD cl_gui_frontend_services=>gui_upload


EXPORTING
filename = gt_file
CHANGING
data_tab = lt_raw
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
not_supported_by_gui = 17
error_no_gui = 18
OTHERS = 19.
IF sy-subrc <> 0.
* IMPLEMENT SUITABLE ERROR HANDLING HERE
ENDIF.

LOOP AT lt_raw ASSIGNING FIELD-SYMBOL(<fs_raw>).


DATA: gt_layout TYPE TABLE OF ty_layout,
lt_layout TYPE ty_layout,
gt_dfkkbptaxnum TYPE TABLE OF dfkkbptaxnum,
lt_dfkkbptaxnum TYPE dfkkbptaxnum,
lv_s TYPE string,
lv_serasa_score(3) TYPE c,
lv_cnpj(10) TYPE c.

CASE <fs_raw>+9(1).

WHEN 1.
lt_layout-sequencia = <fs_raw>(9).
lt_layout-cod_reg = <fs_raw>+9(1).
lt_layout-cnpj_cliente = <fs_raw>+10(9).
lt_layout-cnpj_consultado = <fs_raw>+19(9).
lt_layout-score = <fs_raw>+328(4).

CONCATENATE '%' lt_layout-cnpj_consultado(8) '%' INTO lv_cnpj.

SELECT SINGLE * "PASSO 20


FROM dfkkbptaxnum
INTO lt_dfkkbptaxnum
WHERE taxtype = 'BR1'
AND taxnum LIKE lv_cnpj.

IF sy-subrc EQ 0. "1-REGRA
SELECT SINGLE *
FROM ukmbp_cms
INTO @DATA(lt_ukmbp_cms)
WHERE partner = @lt_dfkkbptaxnum-partner. "PASSO 30

IF sy-subrc EQ 0.
" PASSO 45
IF lt_layout-score > 450.
gv_aux_grade = 'A'.
gv_aux_tendency = '++'.
ELSEIF lt_layout-score > 250.
gv_aux_grade = 'B'.
gv_aux_tendency = '+'.

ELSEIF lt_layout-score > 100.


gv_aux_grade = 'C'.
gv_aux_tendency = 'O'.

ELSEIF lt_layout-score > 50.


gv_aux_grade = 'D'.
gv_aux_tendency = '-'.

ELSEIF lt_layout-score < 50.


gv_aux_grade = 'E'.
gv_aux_tendency = '--'.
ENDIF.

"PASSO 50 - SE LOCALIZAR O BP
CALL FUNCTION 'UKM_BUPA_BP1012_GET'
EXPORTING
i_partner = lt_dfkkbptaxnum-partner
TABLES
et_bp1012 = gt_bp1012.

IF sy-subrc EQ 0.
LOOP AT gt_bp1012 INTO lt_bp1012 WHERE partner =
lt_dfkkbptaxnum-partner
AND grade_method = 'SERASA'
AND date_to > sy-datum.

IF lt_bp1012-grade = gv_aux_grade.
IF lt_bp1012-text NE lt_layout-score.
* ATUALIZA SCORE
lt_bp1012-text = lt_layout-score.
APPEND lt_bp1012 TO gt_bp1012_aux.

CLEAR gt_bp1012_x.
lt_bp1012_x-text = 'X'.
APPEND lt_bp1012_x TO gt_bp1012_x.

CALL FUNCTION 'FS_API_BP1012_CHANGE'


EXPORTING
iv_partner = lt_bp1012-partner
* IV_PARTNER_GUID =
* IV_TESTRUN =
* IS_GENERAL =
TABLES
* ET_RETURN =
it_bp1012 = gt_bp1012_aux
it_bp1012_x = gt_bp1012_x.

IF sy-subrc EQ 0.
COMMIT WORK.
ELSE.
ROLLBACK WORK.
ENDIF.
ENDIF.
ELSE.
lt_bp1012-date_to = sy-datum - 1.
APPEND lt_bp1012 TO gt_bp1012_aux.

CLEAR gt_bp1012_x.
lt_bp1012_x-date_to = 'X'.
APPEND lt_bp1012_x TO gt_bp1012_x.

CALL FUNCTION 'FS_API_BP1012_CHANGE'


EXPORTING
iv_partner = lt_bp1012-partner
* IV_PARTNER_GUID =
* IV_TESTRUN =
* IS_GENERAL =
TABLES
* ET_RETURN =
it_bp1012 = gt_bp1012_aux
it_bp1012_x = gt_bp1012_x.

IF sy-subrc EQ 0.
COMMIT WORK.
ELSE.
ROLLBACK WORK.
ENDIF.

lt_bp1012-grade = gv_aux_grade.
lt_bp1012-tendency = gv_aux_tendency.
lt_bp1012-date_when = sy-datum.
lt_bp1012-text = lt_layout-score.
CLEAR gt_bp1012_aux.
APPEND lt_bp1012 TO gt_bp1012_aux.

CALL FUNCTION 'FS_API_BP1012_ADD'


EXPORTING
iv_partner = lt_bp1012-partner
* iv_partner_guid =
* is_general =
* iv_testrun =
TABLES
* ET_RETURN =
it_bp1012 = gt_bp1012_aux.

IF sy-subrc EQ 0.
COMMIT WORK.
lt_log-cnpj = lt_layout-cnpj_consultado. "PASSO 40
lt_log-bp = lt_dfkkbptaxnum-partner.
lt_log-historico = TEXT-002 && ` ` && lt_dfkkbptaxnum-partner
&& ` ` && TEXT-003 && ` ` && gv_aux_grade .
APPEND lt_log TO gt_log.
ELSE.
ROLLBACK WORK.
ENDIF.
ENDIF.
ENDLOOP.

ELSE. " sen�o achar Incluir Avalia��o Atualizada no BP


lt_bp1012-grade = gv_aux_grade.
lt_bp1012-tendency = gv_aux_tendency.
lt_bp1012-date_when = sy-datum.
lt_bp1012-text = lt_layout-score.
CLEAR gt_bp1012_aux.
APPEND lt_bp1012 TO gt_bp1012_aux.

CALL FUNCTION 'FS_API_BP1012_ADD'


EXPORTING
iv_partner = lt_bp1012-partner
* iv_partner_guid =
* is_general =
* iv_testrun =
TABLES
* ET_RETURN =
it_bp1012 = gt_bp1012_aux.

IF sy-subrc EQ 0.
COMMIT WORK.
lt_log-cnpj = lt_layout-cnpj_consultado. "PASSO 40
lt_log-bp = lt_dfkkbptaxnum-partner.
lt_log-historico = TEXT-002 && ` ` && lt_dfkkbptaxnum-partner && `
` && TEXT-003 && ` ` && gv_aux_grade.
APPEND lt_log TO gt_log.
ELSE.
ROLLBACK WORK.
ENDIF.
ENDIF.
ELSE.
lt_log-cnpj = lt_layout-cnpj_consultado. "PASSO 40
lt_log-bp = lt_dfkkbptaxnum-partner.
lt_log-historico = TEXT-002 && ` ` && lt_dfkkbptaxnum-partner && ` `
&& TEXT-004.
APPEND lt_log TO gt_log.
ENDIF.
ENDIF.
ENDCASE.
ENDLOOP.
ENDFORM.

*&---------------------------------------------------------------------*
*& FORM F_EXIBE_DADOS
*&---------------------------------------------------------------------*
*& TEXT
*&---------------------------------------------------------------------*

FORM f_exibe_dados .

DATA: lr_log TYPE REF TO cl_salv_table,


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_layout TYPE REF TO cl_salv_layout.

TRY.
cl_salv_table=>factory(
IMPORTING
r_salv_table = lr_log
CHANGING
t_table = gt_log[]
).

lr_columns = lr_log->get_columns( ).
TRY.
lr_column ?= lr_columns->get_column( 'CNPJ' ).
lr_column->set_short_text( 'CNPJ' ).
lr_column->set_medium_text( 'CNPJ ' ).
lr_column->set_long_text( 'CNPJ' ).
lr_column->set_visible( abap_true ).
CATCH cx_root.
ENDTRY.

TRY.
lr_column ?= lr_columns->get_column( 'BP' ).
lr_column->set_short_text( 'BP' ).
lr_column->set_medium_text( 'BP' ).
lr_column->set_long_text( 'BP' ).
lr_column->set_visible( abap_true ).
CATCH cx_root.
ENDTRY.

TRY.
lr_column ?= lr_columns->get_column( 'HISTORICO' ).
lr_column->set_short_text( 'HISTOR' ).
lr_column->set_medium_text( 'HIST�RICO' ).
lr_column->set_long_text( 'HIST�RICO' ).
lr_column->set_visible( abap_true ).
CATCH cx_root.
ENDTRY.

* FUNCTION
lr_functions = lr_log->get_functions( ).
lr_functions->set_all( abap_true ).

lr_log->display( ).

ENDTRY.
ENDFORM.

You might also like