*&---------------------------------------------------------------------*
*& Report ZBACK_AND_REST
*& Este programa permite realizar Back Up y Restauración de
*& Module Pool, Grupo de Funciones y Reportes
*&
*& El Back Up y la Restauracion incluyen:
*& Dynpros, PF Status, Modulos de Funciones, etc
*&
*& Modo de Uso :
*& - Seleccione la operacion a realizar ( Back Up o Restauracion)
*& - Seleccione el tipo de aplicacion (Reporte, Module Pool o Grupo de Funciones)
*& - Ingrese el nombre de la aplicacion.
*& (En caso de seleccionar un grupo de funciones, indicar el nombre del grupo
*& y no de alguno de sus modulos de funciones)
*& - Seleccione la ruta donde se guardaran los archivos generados (en caso de Back Up)
*& o la ruta donde se encuentran los archivos generados (en caso de restauracion)
*&
*& Recomendaciones:
*& - No cambie el nombre de ninguno de los archivos y carpetas generados
*& - En caso de restauracion, el nombre a ingresar debera ser el mismo que el
*& de la carpeta generada.
*&
*& Contacto:
*& - Por reporte de errores, dumps, bugs, modificaciones, etc
*& enviar mail a: pablopessoa@gmail.com
*&---------------------------------------------------------------------*
*& Desarrollado por : Pablo Guillermo Pessoa
*& Fecha : 27-07-2010
*& La Plata - Bs As - Argentina
*&---------------------------------------------------------------------*
REPORT zback_and_rest_ppe.
TABLES : trdir,trkey.
***********************************************************************
* DATA (Para descargar el programa)
***********************************************************************
"Programa Principal
DATA: prog_texts LIKE textpool OCCURS 0 WITH HEADER LINE.
DATA: BEGIN OF prog_source OCCURS 0,
line(255) TYPE c,
END OF prog_source.
"Include
DATA: inc_texts LIKE textpool OCCURS 0 WITH HEADER LINE.
DATA: BEGIN OF inc_source OCCURS 0,
line(255) TYPE c,
END OF inc_source.
DATA: gt_trdir TYPE STANDARD TABLE OF trdir WITH HEADER LINE. "trdir Tabla de sistema TRDIR
DATA: gt_d010inc TYPE STANDARD TABLE OF d010inc WITH HEADER LINE. " Tabla de Includes
DATA: gs_trdir TYPE trdir. "Tabla de sistema TRDIR
DATA: gs_d010inc TYPE d010inc. "Tabla de utilización para Includes ABAP
***********************************************************************
* DATA (Para grupos de funciones)
***********************************************************************
DATA : gt_tfdir TYPE STANDARD TABLE OF tfdir,
gt_enlfdir TYPE STANDARD TABLE OF enlfdir,
gs_enlfdir TYPE enlfdir,
gs_tfdir TYPE tfdir.
DATA: gt_functab TYPE TABLE OF rs38l_incl,
gs_functab TYPE rs38l_incl,
gt_dokumentation TYPE TABLE OF funct,
gt_exception_list TYPE TABLE OF rsexc,
gt_export_parameter TYPE TABLE OF rsexp,
gt_import_parameter TYPE TABLE OF rsimp,
gt_tables_parameter TYPE TABLE OF rstbl,
includes TYPE rs38l-name,
nombre_funcion TYPE tlibg-area,
funcion_tlibg TYPE tlibg-area,
funcion_rs38l TYPE rs38l-name.
***********************************************************************
* DATA (Para Module Pool)
***********************************************************************
DATA: gt_d020t TYPE TABLE OF d020t. "Descripción breve del dynpro
DATA: gt_d020s TYPE TABLE OF d020s. "Tabla de sistema D020S (sources de dynpro)
DATA: gt_d021s TYPE TABLE OF d021s. "fld Campos de dynpro
DATA: gt_d022s TYPE TABLE OF d022s. "src Lógica de proceso en dynpro
DATA: gt_d023s TYPE TABLE OF d023s. "matchcodes dynpro
DATA: gt_d021t TYPE TABLE OF d021t. "d021t Textos de palabras clave en dynpro
"workAreas
DATA: gs_d020s TYPE d020s. "hdr dynpros
DATA: gs_d020t TYPE d020t. "Descripción breve del dynpro
DATA: gs_d021s TYPE d021s. "Campos de dynpro
DATA: gs_d022s TYPE d022s. "Lógica de proceso en dynpro
DATA: gs_d023s TYPE d023s. "Parámetros dynpro
DATA: BEGIN OF dynp_id,
prog TYPE d020t-prog,
dynr TYPE d020t-dynr,
END OF dynp_id.
DATA: mess(50) TYPE c,
line(50) TYPE c,
word(50) TYPE c.
***********************************************************************
************* DATA Para menu painter (gui status)
*** Codigo extraido y adaptado del programa ZREPTRAN_620
***********************************************************************
DATA: stx4 TYPE STANDARD TABLE OF rsmptexts WITH HEADER LINE.
DATA: fun4 TYPE STANDARD TABLE OF rsmpe_funt WITH HEADER LINE.
DATA: ctx4 TYPE STANDARD TABLE OF rsmpe_ctx WITH HEADER LINE.
DATA: mtx4 TYPE STANDARD TABLE OF rsmpe_mnlt WITH HEADER LINE.
DATA: men4 TYPE STANDARD TABLE OF rsmpe_men WITH HEADER LINE.
DATA: act4 TYPE STANDARD TABLE OF rsmpe_act WITH HEADER LINE.
DATA: doc4 TYPE STANDARD TABLE OF rsmpe_atrt WITH HEADER LINE.
DATA: sta4 TYPE STANDARD TABLE OF rsmpe_stat WITH HEADER LINE.
DATA: set4 TYPE STANDARD TABLE OF rsmpe_staf WITH HEADER LINE.
DATA: pfk4 TYPE STANDARD TABLE OF rsmpe_pfk WITH HEADER LINE.
DATA: but4 TYPE STANDARD TABLE OF rsmpe_but WITH HEADER LINE.
DATA: tit4 TYPE STANDARD TABLE OF rsmpe_titt WITH HEADER LINE.
DATA: biv46c TYPE STANDARD TABLE OF rsmpe_buts WITH HEADER LINE.
DATA: tadm4 TYPE STANDARD TABLE OF rsmpe_adm WITH HEADER LINE.
DATA: adm4 TYPE rsmpe_adm.
DATA: gs_tadir TYPE tadir.
DATA: gt_tadir TYPE STANDARD TABLE OF tadir.
DATA: gs_tdevc TYPE tdevc.
DATA: tr_key TYPE trkey.
***********************************************************************
* DATA (Generales)
***********************************************************************
DATA: ruta_destino TYPE string.
DATA: resp TYPE c.
DATA: pro_name TYPE reposrc-progname. "se insertara el nombre a guardar en las tablas
DATA: nombregrupo TYPE string.
DATA: reporte TYPE reposrc-progname.
***********************************************************************
********************** Selection - Screen
***********************************************************************
SELECTION-SCREEN BEGIN OF BLOCK programa WITH FRAME TITLE tprogram.
SELECTION-SCREEN SKIP 1 .
SELECTION-SCREEN BEGIN OF BLOCK operac WITH FRAME TITLE toperac.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(13) tbackup.
PARAMETERS: rb_back RADIOBUTTON GROUP oper.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(13) trestore.
PARAMETERS: rb_rest RADIOBUTTON GROUP oper.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK operac.
SELECTION-SCREEN SKIP 1 .
SELECTION-SCREEN BEGIN OF BLOCK aplic WITH FRAME TITLE ttipo.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(19) trepor.
PARAMETERS: rb_repor RADIOBUTTON GROUP appl.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(19) tmodul.
PARAMETERS: rb_modul RADIOBUTTON GROUP appl.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(19) tgrupo.
PARAMETERS: rb_grupo RADIOBUTTON GROUP appl.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK aplic.
SELECTION-SCREEN SKIP 1 .
SELECTION-SCREEN BEGIN OF BLOCK info WITH FRAME TITLE tinfo.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(23) tname.
PARAMETERS: p_name TYPE reposrc-progname DEFAULT ' '.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(23) tdest.
PARAMETERS: p_dest TYPE string DEFAULT 'C:\' LOWER CASE.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK info.
SELECTION-SCREEN SKIP 1 .
SELECTION-SCREEN END OF BLOCK programa.
***********************************************************************
* AT SELECTION-SCREEN
***********************************************************************
"ayuda de busqueda de ruta donde guardar los archivos
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_dest.
PERFORM f_ayuda USING p_dest.
***********************************************************************
* Inicializacion de textos de Selección
***********************************************************************
INITIALIZATION.
tprogram = 'Back up y Restauración de Aplicaciones'.
toperac = 'Seleccione Operación'.
tbackup = 'Back Up'.
trestore = 'Restauración'.
ttipo = 'Seleccione Tipo de Aplicación'.
trepor = 'Reporte'.
tmodul = 'Module Pool'.
tgrupo = 'Grupo de Funciones'.
tinfo = 'Complete la Información'.
tname = 'Nombre :'.
tdest = 'Ruta Destino / Origen :'.
***********************************************************************
* START-OF-SELECTION
***********************************************************************
START-OF-SELECTION.
IF rb_back = 'X'. " La Operacion es de Back Up
IF rb_repor = 'X'.
PERFORM backup_reporte.
ENDIF.
IF rb_modul = 'X'.
PERFORM backup_module.
ENDIF.
IF rb_grupo = 'X'.
PERFORM backup_grupofunc.
ENDIF.
ELSE. "La Operacion es de Restauracion
IF rb_repor = 'X'.
PERFORM restore_reporte.
ENDIF.
IF rb_modul = 'X'.
PERFORM restore_module.
ENDIF.
IF rb_grupo = 'X'.
PERFORM restore_grupofunc.
ENDIF.
ENDIF.
***********************************************************************
* SUB-RUTINAS
***********************************************************************
*&---------------------------------------------------------------------*
*& Form F_AYUDA
*& Obtiene la ruta donde se colocaran los archivos
*&---------------------------------------------------------------------*
FORM f_ayuda USING p_aux.
" abre un browser para seleccionar el directorio de destino
CALL METHOD cl_gui_frontend_services=>directory_browse
EXPORTING
window_title = 'Seleccione un Directorio'
initial_folder = 'C:\'
CHANGING
selected_folder = p_aux.
ENDFORM. "F_AYUDA
*&---------------------------------------------------------------------*
*& Form BACKUP_REPORTE
*&---------------------------------------------------------------------*
FORM backup_reporte .
PERFORM backup_module.
ENDFORM. " BACKUP_REPORTE
*&---------------------------------------------------------------------*
*& Form BACKUP_MODULE
*& Realiza el backup del Module Pool
*&---------------------------------------------------------------------*
FORM backup_module .
REFRESH gt_trdir.
"valido en trdir qeu exista el programa Principal
SELECT SINGLE *
INTO CORRESPONDING FIELDS OF gs_trdir
FROM trdir WHERE name EQ p_name.
IF sy-subrc EQ 0.
"voy generando la entrada en TRDIR tanto para includes como para el module pool
APPEND gs_trdir TO gt_trdir.
"Descargo los elementos de texto del Programa Pincipal
READ TEXTPOOL p_name INTO prog_texts.
CLEAR ruta_destino.
CONCATENATE p_dest '\' p_name '\TEXTELEMENT\' p_name INTO ruta_destino.
PERFORM download TABLES prog_texts USING ruta_destino.
"Descargo el Codigo Fuente del Programa Pincipal
READ REPORT p_name INTO prog_source.
CLEAR ruta_destino.
CONCATENATE p_dest '\' p_name '\SOURCES\' p_name INTO ruta_destino.
PERFORM download TABLES prog_source USING ruta_destino.
" Ahora traigo toda la lista de includes de ese module pool
PERFORM buscar_includes TABLES gt_d010inc USING p_name.
"loopeo la tabla de includes y por cada uno guardo el source, la entrada en trdir y los elem de texto
LOOP AT gt_d010inc INTO gs_d010inc.
CLEAR gs_trdir.
SELECT SINGLE *
INTO CORRESPONDING FIELDS OF gs_trdir
FROM trdir WHERE name EQ gs_d010inc-include.
APPEND gs_trdir TO gt_trdir.
"Descargo los elementos de texto del include gs_d010inc-include
CLEAR prog_texts.
READ TEXTPOOL gs_d010inc-include INTO prog_texts.
CLEAR ruta_destino.
CONCATENATE p_dest '\' p_name '\TEXTELEMENT\' gs_d010inc-include INTO ruta_destino.
PERFORM download TABLES prog_texts USING ruta_destino.
"Descargo el Codigo Fuente include gs_d010inc-include
CLEAR prog_source.
READ REPORT gs_d010inc-include INTO prog_source.
CLEAR ruta_destino.
CONCATENATE p_dest '\' p_name '\SOURCES\' gs_d010inc-include INTO ruta_destino.
PERFORM download TABLES prog_source USING ruta_destino.
ENDLOOP.
" Descargo todas las entradas en TRDIR
CLEAR ruta_destino.
CONCATENATE p_dest '\' p_name '\TRDIR' INTO ruta_destino.
PERFORM download TABLES gt_trdir USING ruta_destino.
"Busco los status Gui.
PERFORM savestatus USING p_dest p_name.
"Descargo las dynpros
PERFORM savedynpros USING p_dest p_name.
ELSE.
MESSAGE 'El Module Pool Ingresado no Existe' TYPE 'S'.
ENDIF.
ENDFORM. " BACKUP_MODULE
*&---------------------------------------------------------------------*
*& Form BACKUP_GRUPOFUNC
*&---------------------------------------------------------------------*
FORM backup_grupofunc .
"el grupo de funciones es un reporte, por lo tanto tengo que guardar su codigo fuente
"asi como de todos sus includes para poder despues ingresarlos al sistema
CONCATENATE 'SAPL' p_name INTO nombregrupo.
reporte = nombregrupo.
READ REPORT reporte INTO prog_source.
"guardo el codigo fuente del grupo de funciones
CLEAR ruta_destino.
CONCATENATE p_dest '\' p_name '\FUNCTIONGROUP\' p_name INTO ruta_destino.
PERFORM download TABLES prog_source USING ruta_destino.
"ahora busco y descargo los codigos fuentes de todos los includes del grupo de funciones
" hay que destacar que no es son lo mismo los source del grupo que del modulo de funcion
PERFORM buscar_includes TABLES gt_d010inc USING nombregrupo.
CLEAR ruta_destino.
CONCATENATE p_dest '\' p_name '\FUNCTIONGROUP\INCLUDES' INTO ruta_destino.
PERFORM download TABLES gt_d010inc USING ruta_destino.
"Loopeo la tabla de d010inc y saco los trdir de cada uno
LOOP AT gt_d010inc INTO gs_d010inc.
"Saco y guardo el codigo fuente de cada include
reporte = gs_d010inc-include.
READ REPORT reporte INTO prog_source.
CLEAR ruta_destino.
CONCATENATE p_dest '\' p_name '\FUNCTIONGROUP\' gs_d010inc-include INTO ruta_destino.
PERFORM download TABLES prog_source USING ruta_destino.
" esto crea una tabla "INCLUDES SOURCE" donde estaran los codigos fuentes de todos los includes
ENDLOOP.
"Busco los status Gui.
PERFORM savestatus USING p_dest p_name.
"Descargo las dynpros
PERFORM savedynpros USING p_dest nombregrupo.
"Ya guarde toda la informacion del grupo de funciones y sus includes
" ahora busco los modulos de funciones y guardo su informacion
funcion_tlibg = p_name.
CALL FUNCTION 'RS_FUNCTION_POOL_CONTENTS'
EXPORTING
function_pool = funcion_tlibg
TABLES
functab = gt_functab
EXCEPTIONS
function_pool_not_found = 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.
ELSE.
"Encontro la tabla de modulos de funciones para el grupo p_name
" la loopeo y traigo la informacion de cada module
LOOP AT gt_functab INTO gs_functab.
"descargo la tabla que tiene todos los modulos de funciones
CLEAR ruta_destino.
CONCATENATE p_dest '\' p_name '\FUNCTIONMODULES\MODULES' INTO ruta_destino.
PERFORM download TABLES gt_functab USING ruta_destino.
includes = gs_functab-funcname.
CALL FUNCTION 'FUNCTION_IMPORT_DOKU'
EXPORTING
funcname = includes
TABLES
dokumentation = gt_dokumentation
exception_list = gt_exception_list
export_parameter = gt_export_parameter
import_parameter = gt_import_parameter
tables_parameter = gt_tables_parameter
EXCEPTIONS
error_message = 1
function_not_found = 2
invalid_name = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
" No tuvo problemas en importar la funcion, traigo el codigo fuente de su include
CLEAR prog_source.
reporte = gs_functab-include.
READ REPORT reporte INTO prog_source.
"y guardo toda la informacion
CONCATENATE p_dest '\' p_name '\FUNCTIONMODULES\dokumentation_' gs_functab-include INTO ruta_destino.
PERFORM download TABLES gt_dokumentation USING ruta_destino.
CONCATENATE p_dest '\' p_name '\FUNCTIONMODULES\exception_list_' gs_functab-include INTO ruta_destino.
PERFORM download TABLES gt_exception_list USING ruta_destino.
CONCATENATE p_dest '\' p_name '\FUNCTIONMODULES\export_parameter_' gs_functab-include INTO ruta_destino.
PERFORM download TABLES gt_export_parameter USING ruta_destino.
CONCATENATE p_dest '\' p_name '\FUNCTIONMODULES\import_parameter_' gs_functab-include INTO ruta_destino.
PERFORM download TABLES gt_import_parameter USING ruta_destino.
CONCATENATE p_dest '\' p_name '\FUNCTIONMODULES\tables_parameter_' gs_functab-include INTO ruta_destino.
PERFORM download TABLES gt_tables_parameter USING ruta_destino.
CONCATENATE p_dest '\' p_name '\FUNCTIONMODULES\' gs_functab-include INTO ruta_destino.
PERFORM download TABLES prog_source USING ruta_destino.
ENDIF.
ENDLOOP.
ENDIF.
ENDFORM. " BACKUP_GRUPOFUNC
*&---------------------------------------------------------------------*
*& Form RESTORE_REPORTE
*&---------------------------------------------------------------------*
FORM restore_reporte .
PERFORM restore_module.
ENDFORM. " RESTORE_REPORTE
*&---------------------------------------------------------------------*
*& Form RESTORE_MODULE
*&---------------------------------------------------------------------*
FORM restore_module .
DATA : programa TYPE string.
" Levanto las tablas TRDIR
REFRESH gt_trdir.
CLEAR ruta_destino.
CONCATENATE p_dest '\TRDIR' INTO ruta_destino.
PERFORM upload TABLES gt_trdir USING ruta_destino. "gt_trdir-name
" loopeo la tabla gt_trdir y cargo todo el contenido ( module pool e includes)
LOOP AT gt_trdir INTO gs_trdir.
programa = gs_trdir-name.
"Verificar que no existe el programa para no reescribirlo
resp = 1.
SELECT SINGLE * FROM trdir WHERE name = programa.
IF sy-subrc = 0.
PERFORM popuptoconfirm USING resp programa.
ENDIF.
IF resp = 1. " se puede insertar el programa/include
"inserto el codigo fuente
CLEAR ruta_destino.
CONCATENATE p_dest '\SOURCES\' programa INTO ruta_destino.
PERFORM upload TABLES prog_source USING ruta_destino.
pro_name = programa.
INSERT REPORT pro_name FROM prog_source DIRECTORY ENTRY gs_trdir.
"inserto los elementos de texto
CLEAR ruta_destino.
CONCATENATE p_dest '\TEXTELEMENT\' programa INTO ruta_destino.
PERFORM upload TABLES prog_texts USING ruta_destino.
INSERT textpool pro_name FROM prog_texts LANGUAGE sy-langu.
ENDIF.
ENDLOOP.
"Busco los status Gui.
PERFORM uploadstatus USING p_dest p_name.
"Restaurados el Programa y los Includes, Restauro las Dynpros
PERFORM uploaddynpros USING p_dest.
ENDFORM. " RESTORE_MODULE
*&---------------------------------------------------------------------*
*& Form RESTORE_GRUPOFUNC
*&---------------------------------------------------------------------*
FORM restore_grupofunc .
nombre_funcion = p_name.
"Compruebo que no exista el grupo en el sistema
resp = 1.
CALL FUNCTION 'RS_FUNCTION_POOL_EXISTS'
EXPORTING
function_pool = nombre_funcion
EXCEPTIONS
pool_not_exists = 1
OTHERS = 2.
IF sy-subrc = 0. " el grupo existe, se debe pedir confirmacion
PERFORM popuptoconfirm USING resp nombre_funcion.
ENDIF.
IF resp = 1 . " Esta habilitado a insertar el grupo de funciones
"Comienzo por crear el grupo de funciones con sus includes
CALL FUNCTION 'FUNCTION_POOL_CREATE'
EXPORTING
pool_name = nombre_funcion
short_text = nombre_funcion
EXCEPTIONS
name_already_exists = 1
name_not_correct = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
"Ya cree el grupo.. ahora inserto el codigo fuente del grupo y cargo todos sus includes
CONCATENATE p_dest '\FUNCTIONGROUP\' p_name INTO ruta_destino.
PERFORM upload TABLES prog_source USING ruta_destino.
funcion_rs38l = p_name.
INSERT REPORT funcion_rs38l FROM prog_source.
"INCLUDES
REFRESH gt_d010inc.
CONCATENATE p_dest '\FUNCTIONGROUP\INCLUDES' INTO ruta_destino.
PERFORM upload TABLES gt_d010inc USING ruta_destino. "MASTER INCLUDE
LOOP AT gt_d010inc INTO gs_d010inc.
REFRESH prog_source.
CONCATENATE p_dest '\FUNCTIONGROUP\' gs_d010inc-include INTO ruta_destino.
PERFORM upload TABLES prog_source USING ruta_destino.
funcion_rs38l = gs_d010inc-include.
INSERT REPORT funcion_rs38l FROM prog_source.
ENDLOOP.
"Restaurados el Programa y los Includes, Restauro las Dynpros
PERFORM uploaddynpros USING p_dest.
"ya termine con el grupo de funciones, ahora cargo todos sus modulos de funciones
CONCATENATE p_dest '\FUNCTIONMODULES\MODULES' INTO ruta_destino.
PERFORM upload TABLES gt_functab USING ruta_destino. "FUNCNAME INCLUDE
LOOP AT gt_functab INTO gs_functab.
"levanto los archivos necesarios para crear la funcion
CONCATENATE p_dest '\FUNCTIONMODULES\import_parameter_' gs_functab-include INTO ruta_destino.
PERFORM upload TABLES gt_import_parameter USING ruta_destino.
CONCATENATE p_dest '\FUNCTIONMODULES\dokumentation_' gs_functab-include INTO ruta_destino.
PERFORM upload TABLES gt_dokumentation USING ruta_destino.
CONCATENATE p_dest '\FUNCTIONMODULES\exception_list_' gs_functab-include INTO ruta_destino.
PERFORM upload TABLES gt_exception_list USING ruta_destino.
CONCATENATE p_dest '\FUNCTIONMODULES\export_parameter_' gs_functab-include INTO ruta_destino.
PERFORM upload TABLES gt_export_parameter USING ruta_destino.
CONCATENATE p_dest '\FUNCTIONMODULES\tables_parameter_' gs_functab-include INTO ruta_destino.
PERFORM upload TABLES gt_tables_parameter USING ruta_destino.
CONCATENATE p_dest '\FUNCTIONMODULES\' gs_functab-include INTO ruta_destino.
PERFORM upload TABLES prog_source USING ruta_destino.
"creo la funcion
funcion_tlibg = p_name.
CALL FUNCTION 'FUNCTION_CREATE'
EXPORTING
funcname = gs_functab-funcname
function_pool = funcion_tlibg
short_text = funcion_tlibg
TABLES
exception_list = gt_exception_list
export_parameter = gt_export_parameter
import_parameter = gt_import_parameter
parameter_docu = gt_dokumentation
tables_parameter = gt_tables_parameter
EXCEPTIONS
double_task = 1
error_message = 2
function_already_exists = 3
invalid_function_pool = 4
invalid_name = 5
too_many_functions = 6
OTHERS = 7.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
"le inserto el codigo fuente
funcion_rs38l = gs_functab-funcname.
INSERT REPORT funcion_rs38l FROM prog_source.
ENDLOOP.
ENDIF.
ENDFORM. " RESTORE_GRUPOFUNC
*&---------------------------------------------------------------------*
*& Form BUSCAR_INCLUDES
*&---------------------------------------------------------------------*
FORM buscar_includes TABLES gt_d010inc_aux USING programa.
DATA : gs_d010inc_aux TYPE d010inc.
DATA : str(2) TYPE c.
SELECT *
INTO CORRESPONDING FIELDS OF TABLE gt_d010inc_aux
FROM d010inc WHERE master EQ p_name AND
include NOT LIKE '<%' AND
include NOT LIKE '>%' AND
include NOT LIKE '%======%'.
LOOP AT gt_d010inc_aux INTO gs_d010inc_aux.
str = gs_d010inc_aux-include+0(2).
IF str = '%_' OR str = 'CL' OR str = 'CX' OR str = 'IF' .
DELETE gt_d010inc_aux INDEX sy-tabix.
ENDIF.
ENDLOOP.
ENDFORM. " BUSCAR_INCLUDES
*&---------------------------------------------------------------------*
*& Form SAVESTATUS
*&---------------------------------------------------------------------*
FORM savestatus USING destino programa.
DATA: pro TYPE program.
DATA: prog TYPE trdir-name.
DATA: ruta_destino TYPE string.
pro = programa. " esto se hace asi por que sino sale error con el tipo de parametro qeu se pasa
prog = programa.
"saco los valores de la tabla TADIR
CALL FUNCTION 'AKB_GET_TADIR'
EXPORTING
obj_type = 'PROG'
obj_name = prog
IMPORTING
tadir = gs_tadir
tdevc = gs_tdevc
EXCEPTIONS
object_not_found = 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.
REFRESH gt_tadir.
APPEND gs_tadir TO gt_tadir.
CLEAR ruta_destino.
CONCATENATE destino '\' programa '\STATUSGUI\TADIR' INTO ruta_destino.
PERFORM download TABLES gt_tadir USING ruta_destino.
SELECT * FROM rsmptexts INTO TABLE stx4
WHERE progname = pro.
CALL FUNCTION 'RS_CUA_INTERNAL_FETCH'
EXPORTING
program = prog
IMPORTING
adm = adm4
TABLES
sta = sta4
fun = fun4
men = men4
mtx = mtx4
act = act4
but = but4
pfk = pfk4
set = set4
doc = doc4
tit = tit4
biv = biv46c
EXCEPTIONS
not_found = 1
unknown_version = 2
OTHERS = 3.
IF sy-subrc = 0.
"Descargo todas las tablas en la carpeta STATUSGUI
CLEAR ruta_destino.
CONCATENATE destino '\' programa '\STATUSGUI\sta4' INTO ruta_destino.
PERFORM download TABLES sta4 USING ruta_destino.
CLEAR ruta_destino.
CONCATENATE destino '\' programa '\STATUSGUI\stx4' INTO ruta_destino.
PERFORM download TABLES stx4 USING ruta_destino.
REFRESH tadm4.
APPEND adm4 TO tadm4.
CLEAR ruta_destino.
CONCATENATE destino '\' programa '\STATUSGUI\adm4' INTO ruta_destino.
PERFORM download TABLES tadm4 USING ruta_destino.
CLEAR ruta_destino.
CONCATENATE destino '\' programa '\STATUSGUI\fun4' INTO ruta_destino.
PERFORM download TABLES fun4 USING ruta_destino.
CLEAR ruta_destino.
CONCATENATE destino '\' programa '\STATUSGUI\men4' INTO ruta_destino.
PERFORM download TABLES men4 USING ruta_destino.
CLEAR ruta_destino.
CONCATENATE destino '\' programa '\STATUSGUI\mtx4' INTO ruta_destino.
PERFORM download TABLES mtx4 USING ruta_destino.
CLEAR ruta_destino.
CONCATENATE destino '\' programa '\STATUSGUI\act4' INTO ruta_destino.
PERFORM download TABLES act4 USING ruta_destino.
CLEAR ruta_destino.
CONCATENATE destino '\' programa '\STATUSGUI\but4' INTO ruta_destino.
PERFORM download TABLES but4 USING ruta_destino.
CLEAR ruta_destino.
CONCATENATE destino '\' programa '\STATUSGUI\pfk4' INTO ruta_destino.
PERFORM download TABLES pfk4 USING ruta_destino.
CLEAR ruta_destino.
CONCATENATE destino '\' programa '\STATUSGUI\set4' INTO ruta_destino.
PERFORM download TABLES set4 USING ruta_destino.
CLEAR ruta_destino.
CONCATENATE destino '\' programa '\STATUSGUI\doc4' INTO ruta_destino.
PERFORM download TABLES doc4 USING ruta_destino.
CLEAR ruta_destino.
CONCATENATE destino '\' programa '\STATUSGUI\tit4' INTO ruta_destino.
PERFORM download TABLES tit4 USING ruta_destino.
CLEAR ruta_destino.
CONCATENATE destino '\' programa '\STATUSGUI\biv46c' INTO ruta_destino.
PERFORM download TABLES biv46c USING ruta_destino.
ENDIF.
ENDFORM. " SAVESTATUS
*&---------------------------------------------------------------------*
*& Form UPLOADSTATUS
*&---------------------------------------------------------------------*
FORM uploadstatus USING destino programa.
DATA: pro TYPE program.
DATA: prog TYPE trdir-name.
DATA: ruta_destino TYPE string.
"LÑevanto todas las tablas en la carpeta STATUSGUI
CLEAR ruta_destino.
CONCATENATE destino '\STATUSGUI\TADIR' INTO ruta_destino.
PERFORM upload TABLES gt_tadir USING ruta_destino.
CLEAR gs_tadir.
READ TABLE gt_tadir INTO gs_tadir INDEX 1.
CLEAR ruta_destino.
CONCATENATE destino '\STATUSGUI\sta4' INTO ruta_destino.
PERFORM upload TABLES sta4 USING ruta_destino.
CLEAR ruta_destino.
CONCATENATE destino '\STATUSGUI\stx4' INTO ruta_destino.
PERFORM upload TABLES stx4 USING ruta_destino.
CLEAR ruta_destino.
CONCATENATE destino '\STATUSGUI\adm4' INTO ruta_destino.
PERFORM upload TABLES tadm4 USING ruta_destino.
CLEAR adm4.
READ TABLE tadm4 INTO adm4 INDEX 1.
CLEAR ruta_destino.
CONCATENATE destino '\STATUSGUI\fun4' INTO ruta_destino.
PERFORM upload TABLES fun4 USING ruta_destino.
CLEAR ruta_destino.
CONCATENATE destino '\STATUSGUI\men4' INTO ruta_destino.
PERFORM upload TABLES men4 USING ruta_destino.
CLEAR ruta_destino.
CONCATENATE destino '\STATUSGUI\mtx4' INTO ruta_destino.
PERFORM upload TABLES mtx4 USING ruta_destino.
CLEAR ruta_destino.
CONCATENATE destino '\STATUSGUI\act4' INTO ruta_destino.
PERFORM upload TABLES act4 USING ruta_destino.
CLEAR ruta_destino.
CONCATENATE destino '\STATUSGUI\but4' INTO ruta_destino.
PERFORM upload TABLES but4 USING ruta_destino.
CLEAR ruta_destino.
CONCATENATE destino '\STATUSGUI\pfk4' INTO ruta_destino.
PERFORM upload TABLES pfk4 USING ruta_destino.
CLEAR ruta_destino.
CONCATENATE destino '\STATUSGUI\set4' INTO ruta_destino.
PERFORM upload TABLES set4 USING ruta_destino.
CLEAR ruta_destino.
CONCATENATE destino '\STATUSGUI\doc4' INTO ruta_destino.
PERFORM upload TABLES doc4 USING ruta_destino.
CLEAR ruta_destino.
CONCATENATE destino '\STATUSGUI\tit4' INTO ruta_destino.
PERFORM upload TABLES tit4 USING ruta_destino.
CLEAR ruta_destino.
CONCATENATE destino '\STATUSGUI\biv46c' INTO ruta_destino.
PERFORM upload TABLES biv46c USING ruta_destino.
prog = programa.
CALL FUNCTION 'RS_CUA_INTERNAL_WRITE'
EXPORTING
program = prog
language = sy-langu
tr_key = tr_key
adm = adm4
TABLES
sta = sta4
fun = fun4
men = men4
mtx = mtx4
act = act4
but = but4
pfk = pfk4
set = set4
doc = doc4
tit = tit4
biv = biv46c
EXCEPTIONS
not_found = 1
OTHERS = 2.
IF sy-subrc = 0.
MODIFY rsmptexts FROM TABLE stx4.
ENDIF.
ENDFORM. " UPLOADSTATUS
*&---------------------------------------------------------------------*
*& Form SAVEDYNPROS
*&---------------------------------------------------------------------*
FORM savedynpros USING destino programa .
"Primero traigo las dynpros asociadas al programa de la tabla D020S
SELECT *
INTO CORRESPONDING FIELDS OF TABLE gt_d020t
FROM d020t
WHERE prog = programa. "AND dtxt NOT LIKE 'SEL_SCREEN%'.
"Loopeo los resultados obtenidos para traer el detalle de cada dynpro
LOOP AT gt_d020t INTO gs_d020t.
dynp_id-prog = gs_d020t-prog.
dynp_id-dynr = gs_d020t-dynr.
IMPORT DYNPRO gs_d020s gt_d021s gt_d022s gt_d023s ID dynp_id.
CLEAR ruta_destino.
CONCATENATE destino '\' programa '\DYNPROS\DYN_SOU_' dynp_id-dynr INTO ruta_destino.
REFRESH gt_d020s.
APPEND gs_d020s TO gt_d020s.
PERFORM download TABLES gt_d020s USING ruta_destino.
CLEAR ruta_destino.
CONCATENATE destino '\' programa '\DYNPROS\DYN_CAM_' dynp_id-dynr INTO ruta_destino.
PERFORM download TABLES gt_d021s USING ruta_destino.
CLEAR ruta_destino.
CONCATENATE destino '\' programa '\DYNPROS\DYN_LOG_' dynp_id-dynr INTO ruta_destino.
PERFORM download TABLES gt_d022s USING ruta_destino.
CLEAR ruta_destino.
CONCATENATE destino '\' programa '\DYNPROS\DYN_PAR_' dynp_id-dynr INTO ruta_destino.
PERFORM download TABLES gt_d023s USING ruta_destino.
"Traigo la informacion de la tabla d021t
SELECT * INTO CORRESPONDING FIELDS OF TABLE gt_d021t
FROM d021t WHERE prog EQ dynp_id-prog AND dynr EQ dynp_id-dynr.
CLEAR ruta_destino.
CONCATENATE destino '\' programa '\DYNPROS\DYN_21T_' dynp_id-dynr INTO ruta_destino.
PERFORM download TABLES gt_d021t USING ruta_destino.
ENDLOOP.
" descargo la tabla que tiene los nombres de las dynpros
CLEAR ruta_destino.
CONCATENATE destino '\' programa '\DYNPROS\DYN_20T' INTO ruta_destino.
PERFORM download TABLES gt_d020t USING ruta_destino.
ENDFORM. " SAVEDYNPROS
*&---------------------------------------------------------------------*
*& Form UPLOADDYNPROS
*&---------------------------------------------------------------------*
FORM uploaddynpros USING origen.
CLEAR ruta_destino.
CONCATENATE origen '\DYNPROS\DYN_20T' INTO ruta_destino.
PERFORM upload TABLES gt_d020t USING ruta_destino.
"Loopeo la tabla de Dynpros y genero cada una
LOOP AT gt_d020t INTO gs_d020t.
" cada ds_d020t es un numero de dynpro asociado al programa PROG Y DYNR
"Levanto los archivos correspondientes a la Dynpro DYNR
"'SOU'.
CLEAR ruta_destino.
CONCATENATE origen '\DYNPROS\DYN_SOU_' gs_d020t-dynr INTO ruta_destino.
PERFORM upload TABLES gt_d020s USING ruta_destino.
"'CAM'.
CLEAR ruta_destino.
CONCATENATE origen '\DYNPROS\DYN_CAM_' gs_d020t-dynr INTO ruta_destino.
PERFORM upload TABLES gt_d021s USING ruta_destino.
"'LOG'.
CLEAR ruta_destino.
CONCATENATE origen '\DYNPROS\DYN_LOG_' gs_d020t-dynr INTO ruta_destino.
PERFORM upload TABLES gt_d022s USING ruta_destino.
"'PAR'.
CLEAR ruta_destino.
CONCATENATE origen '\DYNPROS\DYN_PAR_' gs_d020t-dynr INTO ruta_destino.
PERFORM upload TABLES gt_d023s USING ruta_destino.
"21t
CLEAR ruta_destino.
CONCATENATE origen '\DYNPROS\DYN_21T_' gs_d020t-dynr INTO ruta_destino.
PERFORM upload TABLES gt_d021t USING ruta_destino.
CLEAR dynp_id.
dynp_id-prog = gs_d020t-prog.
dynp_id-dynr = gs_d020t-dynr.
READ TABLE gt_d020s INTO gs_d020s INDEX 1.
GENERATE DYNPRO gs_d020s gt_d021s gt_d022s gt_d023s ID dynp_id
MESSAGE mess LINE line WORD word.
IF sy-subrc = 0.
EXPORT DYNPRO gs_d020s gt_d021s gt_d022s gt_d023s ID dynp_id.
ENDIF.
ENDLOOP.
ENDFORM. " UPLOADDYNPROS
*&---------------------------------------------------------------------*
*& Form DOWNLOAD
*&---------------------------------------------------------------------*
FORM download TABLES tabla USING value(ruta_destino).
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = ruta_destino
filetype = 'DAT'
TABLES
data_tab = tabla
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6
header_not_allowed = 7
separator_not_allowed = 8
filesize_not_allowed = 9
header_too_long = 10
dp_error_create = 11
dp_error_send = 12
dp_error_write = 13
unknown_dp_error = 14
access_denied = 15
dp_out_of_memory = 16
disk_full = 17
dp_timeout = 18
file_not_found = 19
dataprovider_exception = 20
control_flush_error = 21
OTHERS = 22.
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. " DOWNLOAD
*&---------------------------------------------------------------------*
*& Form UPLOAD
*&---------------------------------------------------------------------*
FORM upload TABLES tabla USING value(ruta_destino).
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = ruta_destino
filetype = 'DAT'
TABLES
data_tab = tabla
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.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM. " UPLOAD
*&---------------------------------------------------------------------*
*& Form POPUPTOCONFIRM
*&---------------------------------------------------------------------*
FORM popuptoconfirm USING p_resp p_programa.
DATA: pregunta TYPE string,
title TYPE string.
CLEAR pregunta.
CLEAR title.
CONCATENATE 'El programa/include ' p_programa ' ya existe en el Sistema' INTO title.
CONCATENATE 'Si decide continuar se reemplazara bajo su responsabilidad' cl_abap_char_utilities=>newline INTO pregunta.
CONCATENATE pregunta 'Continuar de todos modos ?' INTO pregunta.
CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
titlebar = title
text_question = pregunta
default_button = '2'
display_cancel_button = space
text_button_1 = 'Continuar'(002)
text_button_2 = 'Cancelar'(003)
IMPORTING
answer = resp
EXCEPTIONS
text_not_found = 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. " POPUPTOCONFIRM
Sunday, March 31, 2013
Download and Uploda MOdule Pool Program
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment