0% found this document useful (0 votes)
124 views

Programa Excel

This document describes a report program (ZFIR0120) that reads data from an Excel file, processes it, and posts entries to the SAP system. It defines internal tables and variables, includes selection screen parameters for the file name, reads the file using TEXT_CONVERT_XLS_TO_SAP, loops through the records to check for existing entries and post new ones using transaction FB02.

Uploaded by

Natasha Damasio
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
124 views

Programa Excel

This document describes a report program (ZFIR0120) that reads data from an Excel file, processes it, and posts entries to the SAP system. It defines internal tables and variables, includes selection screen parameters for the file name, reads the file using TEXT_CONVERT_XLS_TO_SAP, loops through the records to check for existing entries and post new ones using transaction FB02.

Uploaded by

Natasha Damasio
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

*-----------------------------------------------------------------------

*-----------------------------------------------------------------------
* Empresa..: SEIDOR
* ID.......:
* Programa.: ZFIR0120
* Tipo.....: Report
* Módulo...: FI
* Transação: ZFI056
* Descrição:
* Autor....: Bruno Barbosa
* Data.....: 23/04/2021
* [HISTÓRICO]
* ======== ========== ========== =======================================
* Data Autor Request Descrição
* ======== ========== ========== =======================================
* 23/04/2021 Bruno Criação dos programas e demais objetos
* ======== ========== ========== =======================================
REPORT zfir0120.

*----------------------------------------------------------------------*
* Tipos *
*----------------------------------------------------------------------*
TYPES: BEGIN OF ty_arq_d,
cod_titulo TYPE ztbfi0001-nr_titulo,
nosso_numero TYPE ztbfi0001-nr_titulo,
belnr TYPE bkpf-belnr,
bukrs TYPE bkpf-bukrs,
gjahr TYPE bkpf-gjahr,
END OF ty_arq_d.

*----------------------------------------------------------------------*
* Tabelas Internas *
*----------------------------------------------------------------------*
DATA: t_aqr_dados TYPE STANDARD TABLE OF ty_arq_d,
t_waw TYPE truxs_t_text_data.

DATA: t_bdc TYPE bdcdata OCCURS 0 WITH HEADER LINE.

DATA: BEGIN OF t_msg OCCURS 0.


INCLUDE STRUCTURE bdcmsgcoll.
DATA: END OF t_msg.

*----------------------------------------------------------------------*
* Variáveis Globais *
*----------------------------------------------------------------------*
DATA: vg_subrc TYPE sy-subrc,
vg_tabix TYPE sy-tabix.

*----------------------------------------------------------------------*
* Constantes
*----------------------------------------------------------------------*
CONSTANTS: c_e TYPE c VALUE 'E',
c_s TYPE c VALUE 'S'.

*----------------------------------------------------------------------*
* Parâmetros de Seleção *
*----------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE TEXT-004.
PARAMETERS: p_file TYPE string MODIF ID arq. "DEFAULT
SELECTION-SCREEN END OF BLOCK b2.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.


PERFORM f_f4_file_open USING 'XLS'
space
CHANGING p_file
vg_subrc.

*==================*
START-OF-SELECTION.
*==================*

IF p_file IS INITIAL.
MESSAGE s004(zfi) DISPLAY LIKE 'E'.
EXIT.
ENDIF.

PERFORM zf_le_arquivo_excel.
PERFORM f_process_data.

*----------------------------------------------------------------------*
* FORMS *
*----------------------------------------------------------------------*
FORM f_f4_file_open USING p_extension TYPE string
p_filename TYPE string
CHANGING v_local TYPE string
v_subrc TYPE sy-subrc.

DATA: ls_tab TYPE file_table,


lt_tab TYPE filetable,
lv_rc TYPE i.

CLEAR: v_local,
v_subrc,
lv_rc,
ls_tab,
lt_tab[].

CALL METHOD cl_gui_frontend_services=>file_open_dialog


EXPORTING
window_title = 'Selecionar arquivo'
default_extension = p_extension
default_filename = p_filename
multiselection = space
CHANGING
file_table = lt_tab
rc = lv_rc
EXCEPTIONS
file_open_dialog_failed = 1
cntl_error = 2
error_no_gui = 3
not_supported_by_gui = 4.

IF lv_rc EQ 1.
READ TABLE lt_tab INTO ls_tab INDEX 1.
IF sy-subrc EQ 0.
v_local = ls_tab-filename.
ENDIF.
ELSE.
v_subrc = 1.
ENDIF.

ENDFORM.

FORM zf_le_arquivo_excel.

DATA: lv_perc TYPE n LENGTH 3,


lv_size TYPE i,
lv_filename TYPE rlgrap-filename.

lv_filename = p_file.

CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'


EXPORTING
i_line_header = 'X'
i_tab_raw_data = t_waw
i_filename = lv_filename
TABLES
i_tab_converted_data = t_aqr_dados[]
EXCEPTIONS
conversion_failed = 1
OTHERS = 2.

IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

IF t_aqr_dados[] IS INITIAL.
MESSAGE 'Erro ao ler arquivo de entrada!' TYPE c_s DISPLAY LIKE c_e.
STOP.
ELSE.

ENDIF .

IF t_aqr_dados[] IS INITIAL.
MESSAGE 'Erro ao ler arquivo de entrada!' TYPE c_s DISPLAY LIKE c_e.
STOP.
ENDIF.

ENDFORM.

FORM f_process_data.

DATA: ls_opcoes TYPE ctu_params.

DATA: lv_belnr TYPE bkpf-belnr.

LOOP AT t_aqr_dados INTO DATA(ls_aqr_dados).

CLEAR: lv_belnr.
FREE: t_bdc.
FREE: t_msg.

lv_belnr = |{ ls_aqr_dados-belnr ALPHA = IN }|.

SELECT SINGLE xblnr INTO @DATA(lv_xblnr)


FROM bkpf
WHERE belnr = @lv_belnr
AND bukrs = @ls_aqr_dados-bukrs
AND gjahr = @ls_aqr_dados-gjahr.

IF lv_xblnr IS NOT INITIAL.


CONTINUE.
ENDIF.

PERFORM preenche_bdc USING:


'X' 'SAPMF05L' '0100',
' ' 'BDC_OKCODE' '=WEITE',
' ' 'RF05L-BELNR' ls_aqr_dados-belnr,
' ' 'RF05L-BUKRS' ls_aqr_dados-bukrs,
' ' 'RF05L-GJAHR' ls_aqr_dados-gjahr,
'X' 'SAPMF05L' '0750',
' ' 'BDC_OKCODE' '=VK',
'X' 'SAPMF05L' '1710',
' ' 'BDC_OKCODE' '=ENTR',
' ' 'BKPF-XBLNR' ls_aqr_dados-cod_titulo,
'X' 'SAPMF05L' '0750',
' ' 'BDC_OKCODE' '=AE'.

CLEAR ls_opcoes.
ls_opcoes-dismode = 'N'.
ls_opcoes-updmode = 'A'.
ls_opcoes-cattmode = ' '.
ls_opcoes-racommit = ' '.
ls_opcoes-nobinpt = 'X'.
ls_opcoes-nobiend = 'X'.

CALL TRANSACTION 'FB02'


USING t_bdc
OPTIONS FROM ls_opcoes
MESSAGES INTO t_msg.

ENDLOOP.

MESSAGE s368(00) WITH 'Dados Processados!'.

ENDFORM.

FORM preenche_bdc USING dynbegin name value.

IF dynbegin = 'X'.
MOVE: name TO t_bdc-program,
value TO t_bdc-dynpro,
'X' TO t_bdc-dynbegin.
ELSE.
MOVE: name TO t_bdc-fnam,
value TO t_bdc-fval.
ENDIF.
APPEND t_bdc.
CLEAR t_bdc.

ENDFORM. " PREENCHE_BDC

17.279

You might also like