ZWIKI

De SAP ABAP
Saltar a: navegación, buscar

Para copiar el código fuente de este programa, pulsa en la pestaña de editar, y copia el texto comprendido entre <source lang="abap"> y </source>

Si falla con un progama que tenga líneas mayor de 72 carácteres, utiliza la versión ZWIKI_ECC


************************************************************************
* MÓDULO      : BC
* TIPO        : Utilidad
* TITULO      : Convierte el código fuente de un programa a formato WIKI
* DESCRIPCION :                                                        *
* Convierte el código fuerte en bruto de un programa en el sistena, o  *
* cargado a partir de un fichero de texto, en formato de MediaWiki,
*   - un espacio al principio para señalar bloque de código,
*   - comentarios en cursiva
*   - marca como hipervínculos las tablas, funciones e includes
* El resultado de la conversión se deja en el portapapeles para poder
* ser pegado fácilmente en el wiki http://sap4.com/wiki
* ...                                                                  *
* AUTOR: Andrés Picazo              Fecha: 30/10/2006                  *
*                                                                      *
************************************************************************
   REPORT zwiki.
 
   DATA: d_linea TYPE abaptxt255.
   DATA: source_ori TYPE abaptxt255_tab,
         source TYPE abaptxt255_tab,
         l_source TYPE abaptxt255.
 
   CLASS cl_abap_char_utilities DEFINITION LOAD.
 
   DATA: BEGIN OF l_new_line,
          espacio(1),
          new_line(2) type c VALUE cl_abap_char_utilities=>cr_lf,
         END OF l_new_line.
 
   PARAMETERS: program LIKE sy-repid DEFAULT sy-repid,
               fichero  LIKE  rlgrap-filename, "Fichero local
               clipboa AS CHECKBOX.
 
   SELECTION-SCREEN SKIP.
   PARAMETERS: anchofij AS CHECKBOX DEFAULT ' '.
 
   START-OF-SELECTION.
     DATA: l_aux1(80), l_aux2(80), l_grab, l_tabla(14),
           l_aux3(80), l_aux4(80),
           l_long TYPE i,
           l_function.
 
     IF clipboa = 'X'.
       CALL FUNCTION 'CLPB_IMPORT'
         TABLES
           data_tab   = source_ori
         EXCEPTIONS
           clpb_error = 1
           OTHERS     = 2.
     ELSE.
       IF NOT program IS INITIAL.
*         READ REPORT program INTO source_ori.
 
         DATA:
           lv_object_name TYPE versobjnam,
           ls_object_name TYPE vrsd-objname,
           lt_trdir       TYPE STANDARD TABLE OF trdir,
           iv_versno      TYPE vrsd-versno.
 
         lv_object_name = program.
         CALL FUNCTION 'SVRS_GET_REPS_FROM_OBJECT'
           EXPORTING
             object_name                  = lv_object_name
             object_type                  = 'REPS'
             versno                       = iv_versno
             iv_no_release_transformation = 'X'
           TABLES
             repos_tab                    = source_ori
             trdir_tab                    = lt_trdir
           EXCEPTIONS
             no_version                   = 1
             OTHERS                       = 2.
 
       ELSEIF NOT fichero IS INITIAL.
         CALL FUNCTION 'WS_UPLOAD'
           EXPORTING
             filename        = fichero
             filetype        = 'ASC'
           TABLES
             data_tab        = source_ori
           EXCEPTIONS
             file_open_error = 1
             file_read_error = 2
             invalid_type    = 3
             unknown_error   = 4.
       ENDIF.
     ENDIF.
 
     IF anchofij = 'X'.
       PERFORM set_fixlen(saplgrap) USING '0' 76.
       PERFORM set_trail_blanks(saplgrap) USING 'X'.
     ENDIF.
 
     source[] = source_ori[].
 
     CALL FUNCTION 'PRETTY_PRINTER'
       EXPORTING
         inctoo             = space
       TABLES
         ntext              = source
         otext              = source
       EXCEPTIONS
         enqueue_table_full = 1
         include_enqueued   = 2
         include_readerror  = 3
         include_writeerror = 4
         OTHERS             = 5.
 
     DATA:  i_token LIKE stokex OCCURS 10 WITH HEADER LINE,
           i_statements LIKE sstmnt OCCURS 10 WITH HEADER LINE,
           l_linea TYPE i,
           l_token LIKE stokex.
 
     REFRESH: i_token, i_statements.
     SCAN ABAP-SOURCE source TOKENS INTO i_token
                               STATEMENTS INTO i_statements
                               WITH ANALYSIS.
 
     CLEAR l_grab.
     LOOP AT source INTO l_source.
       l_linea = sy-tabix.
       IF l_source IS INITIAL.
         CONTINUE.
       ENDIF.
 
       CLEAR i_token.
       READ TABLE i_token WITH KEY row = l_linea.
       d_linea = l_source.
       IF d_linea CS '[[' OR d_linea CS ']]' OR
          ( d_linea CS '<' AND d_linea CS '>' ) OR
          d_linea CS '''''' OR d_linea CS 'nowiki'.
 
         READ TABLE i_token WITH KEY row = l_linea
                                     type = 'S'
                                     str = ''''''
                            TRANSPORTING NO FIELDS.
         IF sy-subrc NE 0.
           READ TABLE i_token WITH KEY row = l_linea
                                       type = 'I'
                                       str = '<>'
                              TRANSPORTING NO FIELDS.
           IF sy-subrc NE 0.
             CONCATENATE '<nowiki>' d_linea '</nowiki>' INTO l_source.
             MODIFY source FROM l_source.
             CONTINUE.
           ENDIF.
         ENDIF.
       ENDIF.
       IF d_linea(1) = '*'.
         CONCATENATE '''''' l_source '''''' INTO l_source.
         MODIFY source FROM l_source.
         CONTINUE.
       ENDIF.
 
       IF d_linea CS '"'.
         SPLIT d_linea AT '"' INTO l_aux1 l_aux2.
         CONCATENATE l_aux1 '''''' '"' l_aux2 '''''' INTO l_source.
         MODIFY source FROM l_source.
         d_linea = l_source.
       ENDIF.
 
       IF i_token-type NE 'I'.
         CONTINUE.
       ENDIF.
 
       IF i_token-str = 'CALL'.
         CLEAR: l_tabla.
         SEARCH d_linea FOR 'CALL FUNCTION '''.
         IF sy-subrc = 0.
           TRANSLATE d_linea TO UPPER CASE.
           SPLIT d_linea AT 'CALL FUNCTION ''' INTO l_aux1 l_aux2.
           l_long = STRLEN( l_aux1 ).
           IF l_long = 0.
             l_long = STRLEN( l_aux2 ).
             IF l_long > 0.
               l_function = 'X'.
               SPLIT l_aux2 AT '''' INTO l_aux3 l_aux4.
               CONCATENATE l_aux1 'CALL FUNCTION ''[[' l_aux3 ']]'''
l_aux4
                                                                INTO
l_source.
               IF l_aux1 IS INITIAL.
                 SEARCH d_linea FOR 'CALL FUNCTION '''.
                 IF sy-fdpos > 0.
                   l_long = sy-fdpos.
                   l_source+l_long = l_source.
                   CLEAR l_source(l_long).
                 ENDIF.
               ENDIF.
               MODIFY source FROM l_source.
               d_linea = l_source.
               CONTINUE.
             ENDIF.
           ENDIF.
         ENDIF.
       ENDIF.
 
       IF l_function IS INITIAL.
         CLEAR l_tabla.
         IF i_token-str =  'TABLES '.
           TRANSLATE d_linea TO UPPER CASE.
           SPLIT d_linea AT 'TABLES' INTO l_aux1 l_aux2.
           SPLIT l_aux2 AT ':' INTO l_aux1 l_aux2.
           IF l_aux2 CA '.'.
             IF l_aux2 CA ','.
               SPLIT l_aux2 AT ',' INTO l_aux1 l_aux2.
               CONDENSE l_aux1.
               l_tabla = l_aux1.
             ELSE.
               SPLIT l_aux2 AT '.' INTO l_aux1 l_aux2.
               CONDENSE l_aux1.
               l_tabla = l_aux1.
             ENDIF.
           ELSE.
             l_grab = 'X'.
             SPLIT l_aux2 AT ',' INTO l_aux1 l_aux2.
             CONDENSE l_aux1.
             l_tabla = l_aux1.
           ENDIF.
         ELSE.
           TRANSLATE d_linea TO UPPER CASE.
           IF l_tabla IS INITIAL AND l_grab = 'X'.
             IF d_linea CA '.'.
               SPLIT d_linea AT '.' INTO l_aux1 l_aux2.
               CONDENSE l_aux1.
               l_tabla = l_aux1.
               CLEAR l_grab.
             ELSE.
               SPLIT d_linea AT ',' INTO l_aux1 l_aux2.
               CONDENSE l_aux1.
               l_tabla = l_aux1.
             ENDIF.
           ENDIF.
         ENDIF.
         IF NOT l_tabla IS INITIAL.
           l_long = STRLEN( l_tabla ).
           SPLIT d_linea AT l_tabla(l_long) INTO l_aux1 l_aux2.
           IF l_aux1 IS INITIAL.
             CONCATENATE l_aux1 '[[' l_tabla ']]' INTO l_aux3.
           ELSE.
             CONCATENATE '[[' l_tabla ']]' INTO l_aux3.
             CONCATENATE l_aux1 l_aux3 INTO l_aux3 SEPARATED BY space.
           ENDIF.
           IF l_aux1 IS INITIAL.
             SEARCH d_linea FOR l_tabla.
             IF sy-fdpos > 0.
               l_long = sy-fdpos.
               l_aux3+l_long = l_aux3.
               CLEAR l_aux3(l_long).
             ENDIF.
           ENDIF.
           CONCATENATE l_aux3 l_aux2 INTO d_linea
           SEPARATED BY space.
           l_source = d_linea.
           MODIFY source FROM l_source.
           CONTINUE.
         ENDIF.
       ENDIF.
 
       IF i_token-str =  'INCLUDE '.
         SPLIT d_linea AT 'INCLUDE ' INTO l_aux1 l_aux2.
         SEARCH l_aux2 FOR 'STRUCTURE'.
         IF sy-subrc NE 0.
           IF l_aux2 CA '.'.
             SPLIT l_aux2 AT '.' INTO l_aux1 l_aux2.
           ELSE.
             SPLIT l_aux2 AT ',' INTO l_aux1 l_aux2.
           ENDIF.
           l_tabla = l_aux1.
           CONDENSE l_tabla.
           l_long = STRLEN( l_tabla ).
           IF l_long > 0.
             SPLIT d_linea AT l_tabla(l_long) INTO l_aux1 l_aux2.
             IF l_aux1 IS INITIAL.
               CONCATENATE l_aux1 '[[' l_tabla ']]' l_aux2 INTO d_linea.
             ELSE.
               CONCATENATE '[[' l_tabla ']]' l_aux2 INTO l_aux3.
               CONCATENATE l_aux1 l_aux3 INTO d_linea
               SEPARATED BY space.
             ENDIF.
             l_source = d_linea.
             MODIFY source FROM l_source.
             CONTINUE.
           ENDIF.
         ENDIF.
       ENDIF.
 
       IF i_token-str =  'FORM ' OR i_token-str =  'ENDFORM' OR
       i_token-str =  'DEFINE ' OR i_token-str = 'END-OF-DEFINITION' OR
    i_token-str ='START-OF-SELECTION' OR i_token-str = 'INITIALIZATION'
       OR i_token-str ='END-OF-SELECTION' OR i_token-str = 'REPORT' OR
       i_token-str = 'AT SELECCION-SCREEN' OR
       i_token-str = 'SELECTION-SCREEN' OR
        i_token-str = 'FUNCTION' OR i_token-str = 'ENDFUNCTION'.
         CONCATENATE '''''''' l_source '''''''' INTO l_source.
         MODIFY source FROM l_source.
         CONTINUE.
       ENDIF.
 
       IF d_linea(7) =  'DEFINE '.
         CONCATENATE '''''''' l_source '''''''' INTO l_source.
         MODIFY source FROM l_source.
         CONTINUE.
       ENDIF.
     ENDLOOP.
 
     LOOP AT source INTO l_source.
       IF NOT l_source IS INITIAL.
         l_source+1 = l_source.
         l_source(1) = ' '.
         l_long = STRLEN( l_source ).
         MODIFY source FROM l_source.
       ELSE.
         l_source(1) = ' '.
         IF anchofij IS INITIAL.
           l_source+1 = l_new_line.
         ENDIF.
         MODIFY source FROM l_source.
       ENDIF.
       WRITE / l_source.
     ENDLOOP.
 
     CLEAR l_source.
     APPEND l_source TO source.
     l_source = '[[Categoría:Código]]'.
     APPEND l_source TO source.
 
 
     DATA rc TYPE i.
     CALL METHOD cl_gui_frontend_services=>clipboard_export
       IMPORTING
         data = source
       CHANGING
         rc   = rc.
 
     MESSAGE s398(00)
      WITH 'Tiene el código formateado en el portapapeles'.
Herramientas personales
Espacios de nombres

Variantes
Acciones
Navegación
Herramientas
Google AdSense