REPORT Z01BC_PRG_UPLOAD_PAPELES. "v1.5
* Dado un filez de entrada con la siguiente estructura:
*
*;1250;Papel;Objeto;Descripcin
*;1251;Campo;Valor-Low;Valor-Low;Valor-Low;etc...
*;1252;campo;valor-low;valor-high
*
* ( El separador puede ser cualquier character y debe colocarse como
* ejemplo en la primera posicin de cada lnea.
* Recordad no poner el separado dentro del contenido. )
*
* 1250, sirve para indentificar el papel
* 1251, sirve para identificar un campo con valor low
* 1252, sivve para identificar un campo con valor low y high
*
* Se genera un fichero resultante para poder subirlo a las
* diferentes machines por la transaccin PFCG
*
* No se inserta directamente en tablas para evitar problemas de
* transportes
tables: agr_1250, agr_1251, agr_define, agr_time, AGR_TEXTS.
selection-screen begin of block b01 with frame.
parameter: filez_in like rlgrap-filename,
f_pc radiobutton group bol,
f_ho radiobutton group bol.
selection-screen end of block b01.
parameter: mandtdes like sy-mandt default sy-mandt.
selection-screen begin of block b02 with frame.
parameter: filez_ou like rlgrap-filename,
f_pco radiobutton group boo,
f_hoo radiobutton group boo.
selection-screen end of block b02.
data: intab(65534) occurs 0 with header line,
outab(65534) occurs 0 with header line,
car(1),
regs(1024) occurs 0 with header line,
i_1250 like agr_1250 occurs 0 with header line,
i_1251 like agr_1251 occurs 0 with header line,
i_define like agr_define occurs 0 with header line,
i_texts like agr_texts occurs 0 with header line,
begin of cs occurs 0,
agr_name like agr_1251-agr_name,
counter like agr_1251-counter,
end of cs,
begin of agrs_list occurs 0,
agr_name like agr_define-agr_name,
end of agrs_list.
at selection-screen on value-request for filez_ou.
data: fichero_in like rlgrap-filename.
call function 'WS_FILENAME_GET'
exporting
def_filename = filez_ou
mask = ',all files,*.*,data files,*.dat,text files,*.txt.'
mode = 'o'
title = 'Selecciona un fichero...'
importing
filename = filez_ou
exceptions
inv_winsys = 04
no_batch = 04
selection_cancel = 04
selection_error = 04.
at selection-screen on value-request for filez_in.
data: fichero_in like rlgrap-filename.
call function 'WS_FILENAME_GET'
exporting
def_filename = filez_in
mask = ',all files,*.*,data files,*.dat,text files,*.txt.'
mode = 'o'
title = 'Selecciona un fichero...'
importing
filename = filez_in
exceptions
inv_winsys = 04
no_batch = 04
selection_cancel = 04
selection_error = 04.
end-of-selection.
perform data_ini.
perform load_filez.
perform work_filez.
perform down_filez.
form down_filez.
*descargamos el fichero
* Creamos Fecha
outab = 'DATE'. outab+50 = sy-datum. append outab.
* Creamos Release
outab = 'RELEASE'. outab+50 = '46C'. append outab.
* Papeles creados...
loop at agrs_list.
outab = 'LOADED_AGRS'. outab+50 = agrs_list. append outab.
endloop.
* Creamos Defines
loop at i_define.
outab = 'AGR_DEFINE'. i_define-mandt = mandtdes.
outab+50 = i_define. append outab.
endloop.
* Creamos AGR_1250
loop at i_1250.
outab = 'AGR_1250'. i_1250-mandt = mandtdes.
outab+50 = i_1250. append outab.
endloop.
* Creamos AGR_1250
loop at i_1251.
outab = 'AGR_1251'. i_1251-mandt = mandtdes.
outab+50 = i_1251. append outab.
endloop.
* Creamos AGR_1250
loop at i_texts.
outab = 'AGR_TEXTS'. i_texts-mandt = mandtdes.
outab+50 = i_texts. append outab.
endloop.
perform save_filez_n.
message s398(00) with 'Operacin finalizada!'.
endform.
form data_ini.
* Refrescamos variables
clear: i_1250, i_1251, cs, intab, outab, car, i_define,
i_texts.
refresh: i_1250, i_1251, cs, intab, outab, i_define,
i_texts.
endform.
form work_filez.
* Procesamos los registros del fichero
loop at intab.
car = intab+0(1). "First char
shift intab left.
split intab at car into table regs.
loop at regs.
case regs.
when '1250'. Perform work_cab.
exit.
when '1251'. perform work_det using 'L'.
exit.
when '1252'. perform work_det using 'H'.
exit.
when others. continue.
endcase.
endloop.
endloop.
endform.
form work_det using modor.
* Procesamos los campos
data: sytabix like sy-tabix,
bkp like regs.
sytabix = sy-tabix.
add 1 to i_1251-node.
do.
add 1 to sytabix.
read table regs index sytabix.
if sy-subrc ne 0.
read table cs with key agr_name = i_1250-agr_name.
cs-counter = i_1251-counter - 1.
modify table cs.
exit.
endif.
case sy-tabix.
when 2. subtract 1 from i_1251-node.
i_1251-field = regs.
add 1 to i_1251-node.
when others.
if modor = 'H'.
case sy-tabix.
when 3. i_1251-low = regs.
when 4. i_1251-high = regs.
endcase.
else.
i_1251-low = regs.
endif.
append i_1251.
add 1 to: i_1251-counter, cs-counter.
endcase.
enddo.
endform.
form work_cab.
* Procesamos la cabecera
data: sytabix like sy-tabix.
sytabix = sy-tabix.
add 1 to sytabix.
read table regs index sytabix.
clear i_1250.
* Leemos el papel
read table cs with key agr_name = regs.
if sy-subrc ne 0.
clear cs.
select max( counter ) into cs-counter from agr_1250
where agr_name = regs.
if cs-counter = 0.
cs-counter = 1.
else.
add 1 to cs-counter.
endif.
cs-agr_name = regs.
append cs.
else.
add 1 to cs-counter.
modify table cs.
endif.
i_1250-agr_name = regs.
* Leemos el objeto
add 1 to sytabix.
read table regs index sytabix.
i_1250-counter = cs-counter.
i_1250-object = regs.
i_1250-node = 4. "Parece que siempre comienza por el 4
i_1250-modified = 'U'.
* Leemos la descripcin
add 1 to sytabix.
read table regs index sytabix.
* Creamos definicin
read table i_define with key agr_name = regs.
if sy-subrc ne 0.
clear i_define.
I_define-agr_name =
agrs_list-agr_name = i_texts-agr_name = i_1250-agr_name.
i_define-create_usr = 'ZLOADER'.
i_define-create_dat = sy-datum.
i_define-create_tim = sy-uzeit.
i_texts-text = regs.
i_texts-spras = sy-langu.
i_texts-line = 0.
append: i_define, i_texts, agrs_list.
endif.
i_1250-atext = regs.
append i_1250.
clear i_1251.
move-corresponding i_1250 to i_1251.
endform.
* Rutinas de fichero...
form load_filez.
case 'X'.
when f_pc. perform load_from_pc tables intab
using filez_in.
when f_ho. perform load_from_host tables intab
using filez_in.
endcase.
endform.
form save_filez_n.
case 'X'.
when f_pco. perform save_to_pc tables outab
using filez_ou.
when f_hoo. perform save_to_host tables outab
using filez_ou.
endcase.
endform.
*{ Host Module
form save_to_host tables my_tab
using p_filez.
open dataset p_filez for output in text mode.
loop at my_tab.
transfer my_tab to p_filez.
endloop.
close dataset p_filez.
endform.
form load_from_host tables my_tab
using p_filez.
open dataset p_filez for input in text mode.
check sy-subrc eq 0.
do.
read dataset p_filez into my_tab.
if sy-subrc ne 0. exit. endif.
append my_tab.
enddo.
close dataset p_filez.
endform.
*{ PC Module
form save_to_pc tables my_tab
using p_filez.
if p_filez is initial.
call function 'DOWNLOAD'
exporting
filename = p_filez
filetype = 'ASC'
tables
data_tab = my_tab
exceptions
invalid_filesize = 4
invalid_table_width = 4
invalid_type = 4
no_batch = 4
unknown_error = 4
gui_refuse_filetransfer = 4
customer_error = 4
others = 4.
else.
call function 'WS_DOWNLOAD'
EXPORTING
FILENAME = p_filez
FILETYPE = 'ASC'
tables
data_tab = my_tab
EXCEPTIONS
FILE_OPEN_ERROR = 4
FILE_WRITE_ERROR = 4
INVALID_FILESIZE = 4
INVALID_TYPE = 4
NO_BATCH = 4
UNKNOWN_ERROR = 4
INVALID_TABLE_WIDTH = 4
GUI_REFUSE_FILETRANSFER = 4
CUSTOMER_ERROR = 4
OTHERS = 4.
endif.
check sy-subrc ne 0.
message e398(00) with 'Error al descargar fichero.'.
endform.
form load_from_pc tables my_tab
using p_filez.
if p_filez is initial.
call function 'UPLOAD'
exporting
filename = p_filez
filetype = 'ASC'
tables
data_tab = my_tab
exceptions
conversion_error = 4
invalid_table_width = 4
invalid_type = 4
no_batch = 4
unknown_error = 4
gui_refuse_filetransfer = 4
others = 4.
else.
call function 'WS_UPLOAD'
EXPORTING
FILENAME = p_filez
FILETYPE = 'ASC'
tables
data_tab = my_tab
EXCEPTIONS
CONVERSION_ERROR = 4
FILE_OPEN_ERROR = 4
FILE_READ_ERROR = 4
INVALID_TYPE = 4
NO_BATCH = 4
UNKNOWN_ERROR = 4
INVALID_TABLE_WIDTH = 4
GUI_REFUSE_FILETRANSFER = 4
CUSTOMER_ERROR = 4
OTHERS = 4.
endif.
check sy-subrc ne 0.
message e398(00) with 'Error al cargar fichero.'.
endform.