MUNDOSAP

Regresar   MUNDOSAP > CONSULTORIA > OTROS MODULOS
Nombre de Usuario
Contraseña
Home Descargas Registrar FAQ Miembros Calendario Buscar Temas de Hoy Marcar Foros Como Leídos




 
Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Viejo 20/07/06, 16:54:41
McKuak McKuak is offline
Junior Member
 
Fecha de Ingreso: jul 2006
Mensajes: 2
Post Carga de Registros.

Que tal gente Abapera....
Les escribo ya que tengo un problema de tiempo (se demora mucho) en las cargas de registro. Básicamente lo que hago es leer de un archivo *.txt (clientes, negocios, teléfonos) e insertarlos en tablas (clientes, negocios, teléfonos).
Según me dicen que el problema esta en el código y por mas que lo veo no encuentro nada malo....
Puede alguien darme una mano y decirme si lo codificado esta malo.....


Desde ya muchas gracias.

Mas abajo esta mi código........

REPORT ZRMCA_ST_CARGA_MASIVA MESSAGE-ID ZMSG_BLOQUEO.
Field-symbols <campo> type any.
Field-symbols <campo1> type any.
Field-symbols <tabla> type any table.
Field-symbols <ws> type any.

* Tablas Transparentes
tables: zrmcat_st_cli,
zrmcat_st_elem,
zrmcat_carmasiva,
zrmcat_st_cab,
zrmcat_st_nego,
dd07t.

data: wa like zrmcat_st_cli occurs 0 with header line.

* Tabla interna con los componentes de un método
DATA: BEGIN OF ti_reg OCCURS 0,
registro(60) type c,
END OF ti_reg.

DATA : BEGIN OF ti_flag OCCURS 0.
include structure ZRMCAT_ST_CAB.
DATA : END OF ti_flag.

DATA: BEGIN OF ti_reg_error OCCURS 0,
registro(999) type c,
END OF ti_reg_error.


* Definicion de variables
DATA : g_registro(600),
rut like but000-bpext,
digito(1),
filename LIKE rlgrap-filename,
g_partner like BUT000-PARTNER,
g_gpart like fkkvkp-gpart,
g_vkont like fkkvkp-vkont,
tabix LIKE sy-tabix,
nomfile(60) TYPE c,
l_reg TYPE I VALUE 0,
l_cont_file TYPE I VALUE 0,
l_reg_file TYPE I VALUE 0,
l_commit type i value 0,
total_reg type i value 0,
bueno like zrmcat_st_cab-ELEM_TOTAL,
erroneo like zrmcat_st_cab-ELEM_ERRONEOS,
archivo_error like zrmcat_st_cab-archivo_error,
elem_erroneos type i value 0,
origen(3),
ultima_fecha like sy-datum,
tipo_elemento(15),
g_msn(120),
fechacarga1 like ZRMCAT_ST_CAB-fecha_carga,
idcarga1 like ZRMCAT_ST_CAB-id_carga,
origen1 like ZRMCAT_ST_CAB-tipo_elemento,
elemento1 like ZRMCAT_ST_CAB-tipo_origen.

data: valor(10), indice(2), valor2(30), valor3(30), flag(1),
valor_tabla(30).

DATA: LOG LIKE BTCXPM OCCURS 2 WITH HEADER LINE.
DATA: BEGIN OF ARCH_LOTE OCCURS 30, "Nombre de los Archivos a leer
ARCHIVO(70) TYPE C,
END OF ARCH_LOTE.

DATA: REG TYPE I VALUE 0, " Contador de registros.
P_FILE(128) TYPE C,
REG_PAso(900) TYPE C.



SELECTION-SCREEN BEGIN OF BLOCK C WITH FRAME TITLE TEXT-004.
parameters : i_feccar like sy-datum default sy-datum modif id off.
selection-screen begin of line.
selection-screen comment 1(30) text-p02 for field idcarga.
selection-screen position 33.
parameters : idcarga(10) OBLIGATORY.
selection-screen end of line.
SELECTION-SCREEN SKIP.
*- Directorio Unix.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(28) TEXT-P03 FOR FIELD I_PATH .
PARAMETERS: I_PATH LIKE RLGRAP-FILENAME DEFAULT
'/home/interfaces/bloqueo/bun/'.
SELECTION-SCREEN END OF LINE.
*- Nombre Archivo.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(28) TEXT-P04 FOR FIELD I_NOMBRE.
PARAMETERS: I_NOMBRE LIKE RLGRAP-FILENAME.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN SKIP.
*- Origen del Elemento.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(28) TEXT-P05 FOR FIELD I_ORIGEN.
PARAMETERS: I_ORIGEN like zrmcat_st_cli-tipo_elemento modif id off.
SELECTION-SCREEN END OF LINE.
*- Tipo del Elemento.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(28) TEXT-P06 FOR FIELD I_TIPO.
PARAMETERS: I_TIPO like zrmcat_st_cli-tipo_origen OBLIGATORY.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK C.

SELECTION-SCREEN BEGIN OF BLOCK A WITH FRAME TITLE TEXT-001.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(28) TEXT-P07 FOR FIELD I_CARGA.
*PARAMETERS: I_CARGA like zrmcat_st_cab-flag_predeter.
PARAMETERS: I_CARGA AS CHECKBOX DEFAULT 'X'.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK A.

SELECTION-SCREEN BEGIN OF BLOCK J WITH FRAME TITLE TEXT-002.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(28) TEXT-P08 FOR FIELD I_REPRO.
PARAMETERS: I_REPRO AS CHECKBOX.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK J.

at selection-screen output.
loop at screen.
if screen-group1 = 'OFF'.
screen-input = '0'.
modify screen.
endif.
endloop.

start-of-selection.
*-----------------

TRANSLATE I_NOMBRE TO LOWER CASE.

PERFORM obtiene_archivo.
DESCRIBE TABLE ARCH_LOTE LINES REG.
if REG > 0.
PERFORM Proceso_Cliente.
CLEAR REG.
else.
write : /'No se encontro el archivo de carga.'.
endif.


*&---------------------------------------------------------------------*
*& Form obtiene_archivo
*&---------------------------------------------------------------------*

FORM obtiene_archivo.
CONCATENATE I_PATH I_NOMBRE INTO P_FILE.
DATA: COMMAND(90),
FECPRO LIKE SY-DATUM.
CONCATENATE 'ls' P_FILE INTO COMMAND SEPARATED BY SPACE.
SUBMIT ZBPOCS00
WITH PROCESO = 'ZCOMMAND'
WITH PARAME = COMMAND
WITH EXPOLOG = 'X'
AND RETURN.
IMPORT LOG FROM MEMORY ID 'tablalog'.
if SY-SUBRC = 0.
loop AT LOG.
MOVE LOG-MESSAGE TO ARCH_LOTE-ARCHIVO.
APPEND ARCH_LOTE.
endloop.
else.
write: /'No se encontro el archivo de carga.'.
endif.

ENDFORM. " obtiene_archivo
*&---------------------------------------------------------------------*
*& Form Proceso_Cliente
*&---------------------------------------------------------------------*

FORM Proceso_Cliente.
data: l_flag type i,
l_linea(255).

clear: l_commit, elem_erroneos, total_reg, l_flag, l_linea.
* lectura de archivos
OPEN DATASET P_FILE FOR INPUT IN TEXT MODE.
if sy-subrc = 0.

if i_repro = 'X'.
select single elem_total elem_erroneos
into (bueno, erroneo)
from zrmcat_st_cab
where fecha_carga = i_feccar
and id_carga = idcarga
and tipo_origen = I_TIPO
and tipo_elemento = I_ORIGEN.
if sy-subrc = 0.
total_reg = bueno + erroneo.
l_flag = 1.
l_cont_file = 1.
l_reg = total_reg.
else.
l_cont_file = 0.
endif.
endif.

l_cont_file = l_cont_file + 1.
if l_cont_file = 1.
zrmcat_st_cab-fecha_carga = i_feccar.
zrmcat_st_cab-id_carga = idcarga.
zrmcat_st_cab-tipo_origen = I_TIPO.
zrmcat_st_cab-elem_erroneos = l_cont_file.
insert zrmcat_st_cab.
if sy-subrc <> 0.
write:/ 'No se Insertaron los registros de Control'.
write:/ 'Fecha Carga : ', i_feccar.
write:/ 'Identificador de Carga: ', idcarga.
write:/ 'Tipo de Origen : ', i_tipo.
exit.
endif.
endif.
do.
flag = 'N'.
READ DATASET P_FILE INTO g_registro.
if sy-subrc = 0.
l_linea = l_linea + 1.
******Logica para repocesar
if l_flag = 1 and l_linea <= total_reg.
continue.
endif.
perform recorre_registro.
else.
exit.
endif.
enddo.

* assign zrmcat_st_cab to <ws>.
* modify zrmcat_st_cab from <ws>.

unassign <campo>.
unassign <campo1>.
unassign <ws>.

* Graba los rut mal digitados, no se considera el "-" ni el
* dígito verificador.
if elem_erroneos >= 1.

* Se obtiene la descripción del Tipo Elemento
select ddtext into tipo_elemento
from dd07t
where DOMVALUE_L = I_ORIGEN
and DDLANGUAGE = 'S'
and DOMNAME = 'ZTIPO_ELEMENTO'.
endselect.

concatenate '/home/interfaces/bloqueo/bun/registros_erroneos_'
tipo_elemento '_' sy-datum
'.txt' into archivo_error.

OPEN DATASET archivo_error for output in text mode.
if sy-subrc = 0.
loop at ti_reg_error.
transfer ti_reg_error to archivo_error.
endloop.
endif.
move l_reg to zrmcat_st_cab-elem_total.
move archivo_error to zrmcat_st_cab-archivo_error.
move elem_erroneos to zrmcat_st_cab-elem_erroneos.
modify zrmcat_st_cab.
endif.
move elem_erroneos to zrmcat_st_cab-elem_erroneos.
move l_reg to zrmcat_st_cab-elem_total.
modify zrmcat_st_cab.
else.
write: 'El archivo no existe o no se puede abrir...!!!!!'.
exit.
endif.
CLOSE DATASET P_FILE.
close dataset archivo_error.
clear g_registro.

* Mensaje de Termino de Carga.
CONCATENATE 'El archivo "' I_NOMBRE '" fue Cargado'
'Exitosamente'
into g_msn
SEPARATED BY space.

message S004 with g_msn.


select single fecha_carga id_carga elem_total elem_erroneos
tipo_origen tipo_elemento
into (fechacarga1, idcarga1, bueno, erroneo, origen1, elemento1)
from zrmcat_st_cab
where fecha_carga = i_feccar
and id_carga = idcarga
and tipo_origen = I_TIPO
and tipo_elemento = I_ORIGEN.


write: /' La fecha de Carga es : ' , fechacarga1.
write: /' El Id de Carga es : ' , idcarga1.
write: /' El Tipo Origen es : ' , origen1.
write: /' El Tipo Elemento es : ' , elemento1.
write: /' Cant. Reg. OK : ' , bueno.
write: /' Cant. Reg Erroneos : ' , erroneo.
write: /' El archivo de carga es : ' , P_FILE.


ENDFORM. " Proceso_Cliente
*&---------------------------------------------------------------------*
*& Form recorre_archivo
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM recorre_registro.
SPLIT g_registro AT '|' INTO TABLE ti_reg.
loop at ti_reg.
l_reg_file = l_reg_file + 1.
indice = sy-tabix.
concatenate 'CAMPO_' indice into valor.
select single * from zrmcat_carmasiva
where tipo_elemento = i_origen and n_campo = valor.
if sy-subrc = 0.
if valor_tabla is initial.
valor_tabla = zrmcat_carmasiva-tabla_destino.
endif.
concatenate zrmcat_carmasiva-tabla_destino
'-'
zrmcat_carmasiva-campo_destino
into valor2.


*Tener presente que la nomenclatura de la calidad juridica es:
*J = Juridica (Empresa) y N = Persona Natural.
if zrmcat_carmasiva-campo_destino = 'RUT'.
if ti_reg-registro CN '0123456789 ' or
ti_reg-registro = ' ' .
if sy-subrc = 0.
append g_registro to ti_reg_error.
elem_erroneos = elem_erroneos + 1.
exit.
endif.
endif.
endif.

assign (valor2) to <campo>.
move ti_reg-registro to <campo>.
flag = 'S'.

endif.
endloop.
if flag = 'S'.
*Se inserta la fecha de carga
concatenate valor_tabla '-fecha_carga' into valor2.
concatenate 'zrmcat_st_cab' '-fecha_carga' into valor3.
assign (valor2) to <campo>.
move i_feccar to <campo>.
assign (valor3) to <campo1>.
move i_feccar to <campo1>.
*Se inserta identificador de carga.
concatenate valor_tabla '-id_carga' into valor2.
concatenate 'zrmcat_st_cab' '-id_carga' into valor3.
assign (valor2) to <campo>.
move idcarga to <campo>.
assign (valor3) to <campo1>.
move idcarga to <campo1>.
*Se inserta el tipo elemento de la carga.
concatenate valor_tabla '-tipo_elemento' into valor2.
concatenate 'zrmcat_st_cab' '-tipo_elemento' into valor3.
assign (valor2) to <campo>.
move I_ORIGEN to <campo>.
assign (valor3) to <campo1>.
move I_ORIGEN to <campo1>.
*Se inserta el tipo de origen de la carga.
concatenate valor_tabla '-tipo_origen' into valor2.
concatenate 'zrmcat_st_cab' '-tipo_origen' into valor3.
assign (valor2) to <campo>.
move I_TIPO to <campo>.
assign (valor3) to <campo1>.
move I_TIPO to <campo1>.
*Se inserta el flag predeterminado
if i_carga = 'X'.
* and sy-index = 1.
update zrmcat_st_cab set flag_predeter = ' '
where tipo_origen = i_tipo
and tipo_elemento = i_origen
and flag_predeter = 'X'.
endif.
concatenate 'zrmcat_st_cab' '-flag_predeter' into valor3.
assign (valor3) to <campo1>.
move I_CARGA to <campo1>.
*Se inserta la dirección del archivo
concatenate 'zrmcat_st_cab' '-archivo_carga' into valor3.
assign (valor3) to <campo1>.
move P_FILE to <campo1>.
*Se inserta el usuario de la carga.
concatenate valor_tabla '-usuario' into valor2.
assign (valor2) to <campo>.
move sy-uname to <campo>.
*Se inserta la fecha de la carga.
concatenate valor_tabla '-fecha' into valor2.
assign (valor2) to <campo>.
move sy-datum to <campo>.
*Se inserta la hora de la carga.
concatenate valor_tabla '-hora' into valor2.
assign (valor2) to <campo>.
move sy-timlo to <campo>.

assign (valor_tabla) to <ws>.
insert (valor_tabla) from <ws>.
* modify (valor_tabla) from <ws>.
if sy-subrc <> 0.
append g_registro to ti_reg_error.
elem_erroneos = elem_erroneos + 1.
else.
* contador de registros ingresados a la tabla
add 1 to l_reg.
endif.

*por cada 10000 registros leidos, se graban en la tabla
l_commit = l_commit + 1.
if l_commit >= 10000.
*En caso de error al procesar los registros se guardon los
*últimos datos.
move l_reg to zrmcat_st_cab-elem_total.
move archivo_error to zrmcat_st_cab-archivo_error.
move elem_erroneos to zrmcat_st_cab-elem_erroneos.
assign zrmcat_st_cab to <ws>.
modify zrmcat_st_cab from <ws>.
commit work and wait.
l_commit = 0.
endif.
endif.

ENDFORM. " recorre_archivo


Responder Con Cita
Respuesta


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

Reglas de Mensajes
no puedes crear nuevos temas
no puedes responder temas
no puedes adjuntar archivos
no puedes editar tus mensajes

El código vB está On
Las caritas están On
Código [IMG] está On
Código HTML está Off
Saltar a Foro


Husos Horarios son GMT. La hora en este momento es 13:30:58.


www.mundosap.com 2006 - Spain
software crm, crm on demand, software call center, crm act, crm solutions, crm gratis, crm web