Plantilla sencilla que permite cargar un archivo .csv separado por ";" y que muestra los datos subidos en ALV, faltaría agregar el procesamiento de los registros mediante un evento.
**********************************************************************
REPORT zbn_migracion_cierre
NO STANDARD PAGE HEADING.
**********************************************************************
**********************************************************************
*DECLARACION DATOS
**********************************************************************
*TYPE-POOLS: slis.
*INCLUDE <icon>.
************************************************************************
* DATOS BI y ALV
************************************************************************
TYPES: BEGIN OF ty_data,
icnum(10), "rut sin dv
dv, "digito verificador
pernr(8), "nro_de_personal
butxt(25), "sociedad - sin uso
tipo_beneficio(30), "Tipo_informacion (carta, bono, etc) - sin uso
tipo_descuento(30), "concepto (salud / social)
vorna(25), "Nombres - sin uso
nachn(25), "Paterno - sin uso
name2(25), "Materno - sin uso
xblnr(16), "factura
fecha(10), "fecha_creacion - sin uso
amort(10), "fecha amortizacion
cuotas(2), "cuotas
monto(10), "importe
END OF ty_data.
TYPES: BEGIN OF ty_salida,
icnum TYPE p0185-icnum,
pernr TYPE p0185-pernr,
butxt TYPE t001-butxt,
tipo_beneficio TYPE zbn_doctos_cobro-tipo_beneficio,
tipo_descuento TYPE zbn_detalle_cier-tipo_descuento,
vorna TYPE p0002-vorna,
nachn TYPE p0002-nachn,
name2 TYPE p0002-name2,
xblnr TYPE zbn_doctos_cobro-xblnr,
fecha TYPE aedtm,
amort TYPE zbn_detalle_cier-fecha,
cuotas TYPE zbn_detalle_cier-cuotas,
monto TYPE zbn_detalle_cier-monto,
waers TYPE zbn_detalle_cier-waers,
icon(4),
message TYPE bapiret2-message,
END OF ty_salida.
DATA ti_data TYPE TABLE OF ty_data WITH HEADER LINE.
DATA ti_salida TYPE TABLE OF ty_salida.
DATA st_salida LIKE LINE OF ti_salida.
CONSTANTS: BEGIN OF icon,
success(4) VALUE '@08@',
error(4) VALUE '@0A@',
END OF icon.
**********************************************************************
*PANTALLA SELECCION y EVENTOS
**********************************************************************
*** Pantalla
* p_file: Archivo
PARAMETERS: p_file TYPE rlgrap-filename OBLIGATORY.
SELECTION-SCREEN BEGIN OF LINE.
* text-c01: ¿Archivo tiene linea de cabecera?
SELECTION-SCREEN COMMENT (34) text-c01 FOR FIELD p_header.
PARAMETERS p_header AS CHECKBOX.
SELECTION-SCREEN END OF LINE.
*** Eventos
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
field_name = 'P_FILE'
IMPORTING
file_name = p_file.
**********************************************************************
INITIALIZATION.
************************************************************************
**********************************************************************
START-OF-SELECTION.
************************************************************************
PERFORM upload_data TABLES ti_data
USING p_file.
PERFORM convertir_datos TABLES ti_data ti_salida.
PERFORM muestra_alv USING ti_salida.
*&---------------------------------------------------------------------*
*& define LLENA_CEROS
*&---------------------------------------------------------------------*
DEFINE llena_ceros.
call function 'CONVERSION_EXIT_ALPHA_INPUT'
exporting
input = &1
importing
output = &1.
END-OF-DEFINITION.
*&---------------------------------------------------------------------*
*& Form UPLOAD_DATA
*&---------------------------------------------------------------------*
FORM upload_data TABLES p_ti_data STRUCTURE ti_data
USING p_file TYPE rlgrap-filename.
DATA: ti_str TYPE truxs_t_text_data,
file TYPE string.
MOVE p_file TO file.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = file
TABLES
data_tab = ti_str
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.
IF sy-subrc <> 0.
WRITE / sy-subrc.
EXIT.
ENDIF.
IF p_header IS NOT INITIAL.
DELETE ti_str INDEX 1.
ENDIF.
CALL FUNCTION 'TEXT_CONVERT_CSV_TO_SAP'
EXPORTING
i_tab_raw_data = ti_str
TABLES
i_tab_converted_data = p_ti_data
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.
ENDFORM. " UPLOAD_DATA
*&---------------------------------------------------------------------*
*& Form CONVERTIR_DATOS
*&---------------------------------------------------------------------*
FORM convertir_datos TABLES p_ti_data STRUCTURE ti_data
p_ti_salida STRUCTURE st_salida.
LOOP AT p_ti_data.
CLEAR st_salida.
MOVE-CORRESPONDING p_ti_data TO st_salida.
APPEND st_salida TO ti_salida.
ENDLOOP.
ENDFORM. " CONVERTIR_DATOS
*&---------------------------------------------------------------------*
*& Form MUESTRA_ALV
*&---------------------------------------------------------------------*
FORM muestra_alv USING pt_alv TYPE table.
DATA: gr_table TYPE REF TO cl_salv_table.
cl_salv_table=>factory( IMPORTING r_salv_table = gr_table
CHANGING t_table = pt_alv
).
PERFORM alv_functions USING gr_table.
PERFORM alv_header IN PROGRAM (sy-repid) IF FOUND USING gr_table. "TODO: Implementar
PERFORM alv_display USING gr_table.
PERFORM alv_columns IN PROGRAM (sy-repid) IF FOUND USING gr_table. "TODO: Implementar
PERFORM alv_sort IN PROGRAM (sy-repid) IF FOUND USING gr_table. "TODO: Implementar
PERFORM alv_layout USING gr_table.
gr_table->display( ).
ENDFORM. " MUESTRA_ALV
*&---------------------------------------------------------------------*
*& Form ALV_FUNCTIONS
*&---------------------------------------------------------------------*
FORM alv_functions USING p_gr_table TYPE REF TO cl_salv_table.
DATA: gr_functions TYPE REF TO cl_salv_functions.
gr_functions = p_gr_table->get_functions( ).
gr_functions->set_all( abap_true ).
ENDFORM. " ALV_FUNCTIONS
*&---------------------------------------------------------------------*
*& Form ALV_DISPLAY
*&---------------------------------------------------------------------*
FORM alv_display USING p_gr_table TYPE REF TO cl_salv_table.
DATA: gr_display TYPE REF TO cl_salv_display_settings.
gr_display = p_gr_table->get_display_settings( ).
gr_display->set_striped_pattern( cl_salv_display_settings=>true ).
* gr_display->set_list_header( ).
ENDFORM. " ALV_DISPLAY
*&---------------------------------------------------------------------*
*& Form ALV_LAYOUT
*&---------------------------------------------------------------------*
FORM alv_layout USING p_gr_table TYPE REF TO cl_salv_table.
DATA: gr_layout TYPE REF TO cl_salv_layout.
DATA: key TYPE salv_s_layout_key.
gr_layout = p_gr_table->get_layout( ).
key-report = sy-repid.
gr_layout->set_key( key ).
gr_layout->set_save_restriction( cl_salv_layout=>restrict_none ).
ENDFORM. " ALV_LAYOUT
No hay comentarios:
Publicar un comentario