Вы находитесь на странице: 1из 9

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

*& Report ZEXEMPLO_SAN


*&
*
*&---------------------------------------------------------------------*
*&
*
*&
*
*&---------------------------------------------------------------------*
report zexemplo_san

* Tabela BDC para armazenar mapeamento de telas


data: begin of t_bdc occurs 0.
include structure bdcdata.
data: end of t_bdc.
* Tabela interna para receber as mensagens do call transaction
data begin of t_msg occurs 0.
include structure bdcmsgcoll.
data end of t_msg.
data: begin of it_log occurs 0,
typ(3),
msg(200),
end of it_log.
* Tabela interna onde os dados do arquivo sero carregados inicialmente.
data: begin of it_dados occurs 0,
linha(200),
end of it_dados.
data: begin of it_quali occurs 0,
centro(4),
propos(4),
textob(33),
campop(22),
end of it_quali.
data: v_mode value 'N'.
* Tela de Seleo
selection-screen begin of block b1 with frame title text-001.
parameters: p_file like rlgrap-filename obligatory,
"Nome do arquivo
p_pasta like apqi-groupid obligatory.
"Nome da pasta de BI
selection-screen end of block b1.
selection-screen begin of block b2 with frame title text-002.
parameters:
p_ct type c radiobutton group g1, "Caso seja executada como Call transaction
p_bi type c radiobutton group g1. "Caso seja executada como Batch Input
selection-screen end of block b2.
selection-screen begin of block b3 with frame title text-003.
parameters:
p_ws type c radiobutton group g2, "Caso o arquivo esteja na workstation
p_rede type c radiobutton group g2. "Caso o arquivo esteja na rede/UNIX
selection-screen end of block b3.
at selection-screen on value-request for p_file.

call function 'WS_FILENAME_GET'


EXPORTING
DEF_FILENAME
=''
DEF_PATH
=''
MASK
=''
MODE
=''
TITLE
=''
importing
filename
= p_file
* RC
=
exceptions
inv_winsys
=1
no_batch
=2
selection_cancel
=3
selection_error
=4
others
=5
.
if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
*
*
*
*
*
*

start-of-selection.
perform zf_carrega_arquivo.
perform zf_prepara_dados.
end-of-selection.
if not p_ct is initial.
perform zf_call_transaction.
elseif not p_bi is initial.
perform zf_batch_input.
endif.
perform zf_imprime_log.
*&---------------------------------------------------------------------*
*&
Form zf_carrega_arquivo
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
form zf_carrega_arquivo .
data: v_file type string.
v_file = p_file.
if p_ws = 'X'.

*
*
*
*
*
*
*
*
*
*
*
*

call function 'GUI_UPLOAD'


exporting
filename
= v_file
FILETYPE
= 'ASC'
HAS_FIELD_SEPARATOR
=''
HEADER_LENGTH
=0
READ_BY_LINE
= 'X'
DAT_MODE
=''
CODEPAGE
=''
IGNORE_CERR
= ABAP_TRUE
REPLACEMENT
= '#'
CHECK_BOM
=''
IMPORTING
FILELENGTH
=
HEADER
=
tables
data_tab
= it_dados
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
others
= 17
.
else.
open dataset p_file for input in text mode encoding default.
do.
read dataset p_file into it_dados.
if sy-subrc is initial.
append it_dados.
else.
exit.
endif.
enddo.
close dataset p_file.

endif.
endform.
" zf_carrega_arquivo
*&---------------------------------------------------------------------*
*&
Form zf_prepara_dados
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text

* <-- p2
text
*----------------------------------------------------------------------*
form zf_prepara_dados .
loop at it_dados.
it_quali = it_dados.
append it_quali.
endloop.
endform.
" zf_prepara_dados
*&---------------------------------------------------------------------*
*&
Form zf_call_transaction
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
form zf_call_transaction .
loop at it_quali.
clear t_bdc.
refresh t_bdc.
perform zf_preenche_bdc using:
<aqui vai o SHDB da tela>

perform zf_preenche_bdc using:


<aqui vai o SHDB da tela>
perform zf_preenche_bdc using:
<aqui vai o SHDB da 1a. tela>
perform zf_preenche_bdc using:
<aqui vai o SHDB da 1a. tela>
perform zf_preenche_bdc using:
<aqui vai o SHDB da 1a. tela>

call transaction 'nome da transao'


using t_bdc
mode v_mode
update 'S'
messages into t_msg.
data: v_msg1(50),
v_msg2(50),

v_msg3(50),
v_msg4(50).
loop at t_msg.
v_msg1 = t_msg-msgv1.
v_msg2 = t_msg-msgv2.
v_msg3 = t_msg-msgv3.
v_msg4 = t_msg-msgv4.
call function 'MESSAGE_PREPARE'
exporting
language
= sy-langu
msg_id
= t_msg-msgid
msg_no
= t_msg-msgnr
msg_var1
= v_msg1
msg_var2
= v_msg2
msg_var3
= v_msg3
msg_var4
= v_msg4
importing
msg_text
= it_log-msg
exceptions
function_not_completed = 1
message_not_found
=2
others
= 3.
it_log-typ = t_msg-msgtyp.
if sy-subrc is initial.
append it_log.
endif.
endloop.
refresh t_msg.
clear t_msg.
endloop.
endform.
" zf_call_transaction
*&---------------------------------------------------------------------*
*&
Form zf_batch_input
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
form zf_batch_input .
perform f_abre_pasta using p_pasta.
perform f_preenche_pasta.
perform f_fecha_pasta.
endform.

" zf_batch_input

*&---------------------------------------------------------------------*
*&
Form zf_preenche_bdc
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
*
-->TELA_INIT text

*
-->NAME
text
*
-->VALUE
text
*----------------------------------------------------------------------*
form zf_preenche_bdc using tela_init
name
value.
*Limpa o cabealho da tabela bdc
clear t_bdc.
if tela_init = 'X'.
t_bdc-program = name.
t_bdc-dynpro = value.
t_bdc-dynbegin = 'X'.
else.
t_bdc-fnam = name.
t_bdc-fval = value.
endif.
append t_bdc.
endform.
" zf_preenche_bdc
*&---------------------------------------------------------------------*
*&
Form f_abre_pasta
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
*
-->P_P_PASTA text
*----------------------------------------------------------------------*
form f_abre_pasta using p_p_pasta.
call function 'BDC_OPEN_GROUP'
exporting
client
= sy-mandt
* DEST
= FILLER8
group
= p_p_pasta
* HOLDDATE
= FILLER8
* KEEP
= FILLER1
user
= sy-uname
* RECORD
= FILLER1
* PROG
= SY-CPROG
* IMPORTING
* QID
=
exceptions
client_invalid
=1
destination_invalid
=2
group_invalid
=3
group_is_locked
=4
holddate_invalid
=5
internal_error
=6
queue_error
=7
running
=8
system_lock_error
=9
user_invalid
= 10
others
= 11
.
if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.

endform.
" f_abre_pasta
*&---------------------------------------------------------------------*
*&
Form f_preenche_pasta
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
form f_preenche_pasta .
loop at it_quali.
clear t_bdc.
refresh t_bdc.
perform zf_preenche_bdc using:
<aqui vai o SHDB da 1a. tela>
perform zf_preenche_bdc using:
<aqui vai o SHDB da 1a. tela>
perform zf_preenche_bdc using:
<aqui vai o SHDB da 1a. tela>
perform zf_preenche_bdc using:
<aqui vai o SHDB da 1a. tela>
perform zf_preenche_bdc using:
<aqui vai o SHDB da 1a. tela>
* Insere na pasta o registro do loop.
perform f_bdc_transaction tables t_bdc using 'nome da transao'.
endloop.
endform.
" f_preenche_pasta
*&---------------------------------------------------------------------*
*&
Form f_fecha_pasta
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
form f_fecha_pasta .
call function 'BDC_CLOSE_GROUP'
exceptions
not_open = 1
queue_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.
endform.
" f_fecha_pasta
*&---------------------------------------------------------------------*
*&
Form f_bdc_transaction
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
*
-->P_T_BDC text
*
-->P_0878 text
*----------------------------------------------------------------------*
form f_bdc_transaction tables p_t_bdc structure bdcdata
using value.
call function 'BDC_INSERT'
exporting
tcode
= value
*
POST_LOCAL
= NOVBLOCAL
*
PRINTING
= NOPRINT
*
SIMUBATCH
=''
*
CTUPARAMS
=''
tables
dynprotab
= p_t_bdc
exceptions
internal_error
=1
not_open
=2
queue_error
=3
tcode_invalid
=4
printing_invalid
=5
posting_invalid
=6
others
=7
.
if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
endform.
" f_bdc_transaction
*&---------------------------------------------------------------------*
*&
Form zf_imprime_log
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
form zf_imprime_log .
write: / 'Log de processamento:'.
if not p_ct is initial.
loop at it_log.
write: / it_log-typ,
' ',
it_log-msg.
endloop.

elseif not p_bi is initial.


write: / 'Pasta de BI criada com sucesso!',
/ 'Para execut-la v na transao SM35.'.
endif.
endform.

" zf_imprime_log

Вам также может понравиться