Archivo

Posts Tagged ‘se38’

GUI_DOWNLOAD – Exportar archivo CSV

Caso: Se desea exportar una tabla interna con formato CSV.

Solución:

 DATA:  lt_export      TYPE TABLE OF mara, 
        lt_salida      TYPE truxs_t_text_data,
        lv_filename    TYPE string,
        lv_filepath    TYPE string,
        lv_fullpath    TYPE string.
 
      CALL METHOD cl_gui_frontend_services=>file_save_dialog
        EXPORTING
          file_filter          = '*.CSV'
          default_extension    = 'CSV'
        CHANGING
          filename             = lv_filename
          path                 = lv_filepath
          fullpath             = lv_fullpath
        EXCEPTIONS
          cntl_error           = 1
          error_no_gui         = 2
          not_supported_by_gui = 3
          OTHERS               = 4.
 
      CALL FUNCTION 'SAP_CONVERT_TO_CSV_FORMAT'
        EXPORTING
          i_field_seperator    = ';'
        TABLES
          i_tab_sap_data       = lt_export
        CHANGING
          i_tab_converted_data = lt_salida
        EXCEPTIONS
          conversion_failed    = 1
          OTHERS               = 2.
 
 
      CALL FUNCTION 'GUI_DOWNLOAD'
        EXPORTING
          filename = lv_fullpath
        TABLES
          data_tab = lt_salida.
Anuncios

Copiar variantes entre programas/reports

Escenario: buscando un reporte para poder copiar variantes entre reports SAP, encontré un par de post interesantes, armé un programa que une los post que permite copiar variantes y layouts de ALV.

Espero les sirva.

*&———————————————————————*
*& Report  Z_COPIAR_VARIANTES
*&
*&———————————————————————*
*& Programa para copiar variantes entre programas ABAP
*& Bajado de: http://www.mundosap.com/foro/showthread.php?t=422
*&            http://www.abap.es/foro/index.php?topic=138.0
*& Autor: Ing. Eduardo M. Puricelli
*& Fecha: 15.06.2011
*&———————————————————————*

REPORT  z_copiar_variantes.

TABLES: trdir,
raldb,
varid,
varis,
varit.

TABLES: ltdx, ltdxd, ltdxt.

SELECT-OPTIONS:
variant FOR raldb-variant.

PARAMETERS: p_rep1 LIKE raldb-report OBLIGATORY,
p_rep2 LIKE raldb-report OBLIGATORY.

DATA: tab_vari  LIKE  vari  OCCURS 0 WITH HEADER LINE,
tab_varid LIKE  varid OCCURS 0 WITH HEADER LINE,
tab_varis LIKE  varis OCCURS 0 WITH HEADER LINE,
tab_varit LIKE  varit OCCURS 0 WITH HEADER LINE,
tab_ltdx  LIKE  ltdx  OCCURS 0 WITH HEADER LINE,
tab_ltdxd LIKE  ltdxd OCCURS 0 WITH HEADER LINE,
tab_ltdxt LIKE  ltdxt OCCURS 0 WITH HEADER LINE.

INITIALIZATION.

variant-low    = ‘&*’.
variant-sign   = ‘E’.
variant-option = ‘CP’.
APPEND variant.

AT SELECTION-SCREEN.

trdir-name = p_rep1.
READ TABLE trdir.
IF sy-subrc NE 0.
MESSAGE e001(00) WITH ‘No existe el reporte origen. Verifique’.
ENDIF.

trdir-name = p_rep2.
READ TABLE trdir.
IF sy-subrc NE 0.
MESSAGE e001(00) WITH ‘No existe el reporte destino. Verifique’.
ENDIF.

START-OF-SELECTION.

SELECT * FROM vari
INTO TABLE tab_vari
WHERE report = p_rep1
AND  variant IN variant.

SELECT * FROM varis
INTO TABLE tab_varis
WHERE report = p_rep1
AND  variant IN variant.

SELECT * FROM varit
INTO TABLE tab_varit
WHERE report = p_rep1
AND  variant IN variant.

SELECT * FROM varid
INTO TABLE tab_varid
WHERE report = p_rep1
AND  variant IN variant.

LOOP AT tab_vari.
tab_vari-report = p_rep2.
INSERT INTO vari VALUES tab_vari.
ENDLOOP.

LOOP AT tab_varis.
tab_varis-report = p_rep2.
INSERT INTO varis VALUES tab_varis.
ENDLOOP.

LOOP AT tab_varid.
tab_varid-report = p_rep2.
INSERT INTO varid VALUES tab_varid.
ENDLOOP.

LOOP AT tab_varit.
tab_varit-report = p_rep2.
INSERT INTO varit VALUES tab_varit.
IF sy-subrc EQ 0.
WRITE:/ ‘OK’,tab_varit-variant.
ELSE.
WRITE:/ ‘Error:’,tab_varit-variant.
ENDIF.
ENDLOOP.

* Variantes de visualización (ALV)
SELECT * FROM ltdx
INTO TABLE tab_ltdx
WHERE report = p_rep1.

LOOP AT tab_ltdx.
tab_ltdx-report = p_rep2.
INSERT INTO ltdx VALUES tab_ltdx.
ENDLOOP.

SELECT * FROM ltdxd
INTO TABLE tab_ltdxd
WHERE report = p_rep1.

LOOP AT tab_ltdxd.
tab_ltdxd-report = p_rep2.
INSERT INTO ltdxd VALUES tab_ltdxd.
ENDLOOP.

SELECT * FROM ltdxt
INTO TABLE tab_ltdxt
WHERE report = p_rep1.

LOOP AT tab_ltdxt.
tab_ltdxt-report = p_rep2.
INSERT INTO ltdxt VALUES tab_ltdxt.
ENDLOOP.

COMMIT WORK.

Categorías:ABAP/4 Etiquetas: , ,