REPORT Y_BC_BAJA_DATA_A_PC.
TABLES: dd02t, "R/3-DD: Textos de tablas SAP
dd03l. "Campos de tabla
* L¡nea
DATA: i_source LIKE line OCCURS 100 WITH HEADER LINE.
DATA l_resp.
DATA: program_name LIKE sy-cprog.
DATA: l_mandt.
DATA : c_tipoarch(10) TYPE c.
DATA : l_linea(72).
DATA : w_linea(72).
DATA : l_tabla(2000).
DEFINE ap.
append &1 to i_source.
END-OF-DEFINITION.
*------PARAMETER/SELECT-OPTIONS EN PANTALLA----------------------------*
SELECTION-SCREEN BEGIN OF BLOCK blk_par WITH FRAME.
PARAMETERS: tabla LIKE dd03l-tabname OBLIGATORY."Nombre de tabla
PARAMETERS: path LIKE rlgrap-filename "Directorio de salida
DEFAULT 'C:\TEMP\' OBLIGATORY,
ftype LIKE rlgrap-filetype DEFAULT 'ASC',
p_sepa(1) TYPE c.
*parameters: borrar as checkbox,
* sinmdt as checkbox.
SELECTION-SCREEN END OF BLOCK blk_par.
SELECTION-SCREEN BEGIN OF BLOCK blk_par3 WITH FRAME TITLE text-003."WHE
PARAMETERS: p_w1(80),
p_w2(80),
p_w3(80),
p_w4(80),
p_w5(80).
SELECTION-SCREEN END OF BLOCK blk_par3.
SELECTION-SCREEN BEGIN OF BLOCK blk_par2 WITH FRAME.
SELECTION-SCREEN END OF BLOCK blk_par2.
INITIALIZATION.
START-OF-SELECTION.
PERFORM generar_report.
PERFORM grabar_tabla.
*---------------------------------------------------------------------*
* FORM GENERAR_REPORT *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM generar_report.
DATA l_tabla(10).
CLEAR l_mandt.
SELECT * FROM dd03l
WHERE tabname = tabla
AND fieldname = 'MANDT'.
l_mandt = 'X'.
ENDSELECT.
CONCATENATE 'I_' tabla INTO l_tabla.
ap 'REPORT Z.'.
CONCATENATE 'TABLES' tabla '.' INTO l_linea SEPARATED BY space.
ap l_linea.
CONCATENATE 'DATA' l_tabla
'LIKE' tabla 'OCCURS 1000 WITH HEADER LINE.'
INTO l_linea SEPARATED BY space.
ap l_linea.
ap 'FORM GRABAR_TABLA.'.
CONCATENATE 'SELECT * FROM' tabla
'INTO TABLE ' l_tabla
INTO l_linea SEPARATED BY space.
ap l_linea.
IF NOT p_w1 IS INITIAL.
CONCATENATE 'WHERE' p_w1 INTO l_linea SEPARATED BY space.
ap l_linea.
ap p_w2.
ap p_w3.
ap p_w4.
ap p_w5.
ENDIF.
ap '.'.
c_tipoarch = ftype.
ap 'CALL FUNCTION ''GUI_DOWNLOAD'''.
ap 'EXPORTING'.
CONCATENATE 'FILENAME = ''' path tabla '.' c_tipoarch '''' INTO l_linea.
ap l_linea.
CONCATENATE 'FILETYPE = ''' c_tipoarch '''' INTO l_linea.
ap l_linea.
IF NOT ( p_sepa IS INITIAL ).
CONCATENATE 'WRITE_FIELD_SEPARATOR = ''' p_sepa '''' INTO l_linea.
ap l_linea.
ENDIF.
ap 'TABLES'.
CONCATENATE 'DATA_TAB = ' l_tabla '.' INTO l_linea
SEPARATED BY space.
ap l_linea.
ap 'ENDFORM. "GRABAR_TABLA'.
PERFORM generate_subroutine_pool TABLES i_source.
ENDFORM. "generar_report
*---------------------------------------------------------------------*
* FORM GRABAR_TABLA *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM grabar_tabla.
PERFORM grabar_tabla IN PROGRAM (program_name).
ENDFORM. "grabar_tabla
*---------------------------------------------------------------------*
* FORM CARGAR_TABLA *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM cargar_tabla.
* message i208(00) with '¨Est seguro de querer cargar los datos?'.
PERFORM cargar_tabla IN PROGRAM (program_name).
ENDFORM. "cargar_tabla
*---------------------------------------------------------------------*
* FORM BORRAR_TABLA *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM borrar_tabla.
SELECT * FROM dd02t
WHERE tabname = tabla
AND ddlanguage = sy-langu.
EXIT.
ENDSELECT.
CONCATENATE '¨Desea borra tabla' tabla INTO l_linea
SEPARATED BY space.
CONCATENATE l_linea '?' INTO l_linea.
CALL FUNCTION 'POPUP_CONTINUE_YES_NO'
EXPORTING
defaultoption = 'N'
textline1 = l_linea
textline2 = dd02t-ddtext
titel = 'Confirmaci¢n'
IMPORTING
answer = l_resp
EXCEPTIONS
OTHERS = 1.
IF l_resp = 'J'.
PERFORM borrar_tabla IN PROGRAM (program_name).
ENDIF.
ENDFORM. "borrar_tabla
*---------------------------------------------------------------------*
* FORM GENERATE_SUBROUTINE_POOL *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
* --> SOURCE_TAB *
*---------------------------------------------------------------------*
FORM generate_subroutine_pool TABLES source_tab.
DATA: line_no TYPE i,
syntax_check_message(128).
DESCRIBE TABLE source_tab.
CHECK sy-tfill GT 0.
GENERATE SUBROUTINE POOL source_tab
NAME program_name
MESSAGE syntax_check_message
LINE line_no.
IF sy-subrc NE 0.
WRITE: / 'Error de sintaxis, mensaje', syntax_check_message,
/ 'en linea', line_no.
STOP.
ENDIF.
ENDFORM.