Programa para Download de Fontes ABAP e seus Textos

Código fornecido por Walmir Basevic

Programa para Download de Fontes ABAP e seus Textos

REPORT YDOWN.

************************************************************************

************************************************************************

* Descrição : Efetua o download de programas e de seus textos *

* (não trata os includes, telas, modules ou scripts *

* dos programas, apenas o texto fonte básico) *

************************************************************************

************************************************************************

*

*** Especificação das tabelas transparentes utilizadas

TABLES: TRDIR, "ABAP: informações p/fontes de programa-ABAP

T002. "Chave de idioma

*

*** Definição das tabelas internas

TYPES: BEGIN OF TY_TRDIR,

NAME LIKE TRDIR-NAME,

END OF TY_TRDIR,

*

BEGIN OF TY_T002,

LANGU LIKE T002-SPRAS,

END OF TY_T002,

*

BEGIN OF TY_TEXTPOOL,

ID LIKE TEXTPOOL-ID,

KEY LIKE TEXTPOOL-KEY,

ENTRY LIKE TEXTPOOL-ENTRY,

LENGTH LIKE TEXTPOOL-LENGTH,

END OF TY_TEXTPOOL,

*

BEGIN OF TY_TEXTPOOL_L,

LANGU LIKE SY-LANGU,

ID LIKE TEXTPOOL-ID,

KEY LIKE TEXTPOOL-KEY,

ENTRY LIKE TEXTPOOL-ENTRY,

LENGTH(004) TYPE N,

END OF TY_TEXTPOOL_L,

*

BEGIN OF TY_PGM,

LINE LIKE SWOTPROG-LINE,

END OF TY_PGM.

*

*** Definição das variáveis

DATA: C_FILE LIKE RLGRAP-FILENAME,

T_TRDIR TYPE TY_TRDIR OCCURS 0 WITH HEADER LINE,

T_T002 TYPE TY_T002 OCCURS 0 WITH HEADER LINE,

T_TEXTPOOL TYPE TY_TEXTPOOL OCCURS 0 WITH HEADER LINE,

T_TEXTPOOL_L TYPE TY_TEXTPOOL_L OCCURS 0 WITH HEADER LINE,

T_PGM TYPE TY_PGM OCCURS 0 WITH HEADER LINE.

*

*** Definição dos parâmetros

PARAMETERS: P_PATH LIKE RFCPUT-PATH

OBLIGATORY

DEFAULT 'C:TEMP'.

SELECT-OPTIONS: S_NAME FOR TRDIR-NAME,

S_LANGU FOR T002-SPRAS.

*

*** Inicialização dos parâmetros

INITIALIZATION.

CLEAR: S_NAME,

S_LANGU.

MOVE: 'I' TO S_NAME-SIGN,

'CP' TO S_NAME-OPTION,

'Z*' TO S_NAME-LOW,

'I' TO S_LANGU-SIGN,

'EQ' TO S_LANGU-OPTION,

'P' TO S_LANGU-LOW.

APPEND: S_NAME,

S_LANGU.

MOVE 'E' TO S_LANGU-LOW.

APPEND S_LANGU.

MOVE 'D' TO S_LANGU-LOW.

APPEND S_LANGU.

*

************************************************************************

* Tratamento dos parâmetros de seleção *

************************************************************************

*** Garante que o caminho de gravação dos arquivos termine com ""

AT SELECTION-SCREEN ON P_PATH.

DATA: W_SIZE TYPE I,

C_STR(001) TYPE C.

W_SIZE = STRLEN( P_PATH ).

CHECK NOT W_SIZE IS INITIAL.

SUBTRACT 1 FROM W_SIZE.

MOVE P_PATH+W_SIZE TO C_STR.

IF C_STR NE ''.

ADD 1 TO W_SIZE.

MOVE '' TO P_PATH+W_SIZE.

ENDIF.

*

*** Testa se alguma seleção de nome de programa foi realizada

AT SELECTION-SCREEN ON S_NAME.

CHECK: S_NAME-LOW IS INITIAL,

S_NAME-HIGH IS INITIAL.

*** Indicar alguma seleção para o Nome dos Pgms

MESSAGE ID '00'

TYPE 'E'

NUMBER 398

WITH TEXT-002 SPACE SPACE SPACE.

*

************************************************************************

* Start of selection *

************************************************************************

START-OF-SELECTION.

*** Testa a existência de programas em acordo c/ os parâmetros indicados

SELECT NAME

FROM TRDIR

INTO TABLE T_TRDIR

WHERE NAME IN S_NAME.

*

DESCRIBE TABLE T_TRDIR LINES SY-TFILL.

*

IF SY-TFILL IS INITIAL.

*** Nenhum programa se adequa aos parâmetros !

MESSAGE ID '00'

TYPE 'I'

NUMBER 398

WITH TEXT-001 SPACE SPACE SPACE.

ENDIF.

*

*** Carrega todas as línguas de acordo com os parâmetros

SELECT SPRAS

FROM T002

INTO TABLE T_T002

WHERE SPRAS IN S_LANGU.

*

END-OF-SELECTION.

*

************************************************************************

* End of selection *

************************************************************************

************************************************************************

* Processamento para cada programa que satisfaça os parâmetros *

************************************************************************

LOOP AT T_TRDIR.

REFRESH T_PGM.

*** Carrega os textos do programa na língua desejada

PERFORM Z_LOAD_TEXTPOOL_LANGUAGE.

*** Monta o nome do arquivo destino de textos do programa

CONCATENATE P_PATH

T_TRDIR-NAME

TEXT-004

INTO C_FILE.

*** Grava o arquivo destino de textos do programa

CALL FUNCTION 'WS_DOWNLOAD'

EXPORTING

FILENAME = C_FILE

TABLES

DATA_TAB = T_TEXTPOOL_L

EXCEPTIONS

FILE_OPEN_ERROR = 1

FILE_WRITE_ERROR = 2

INVALID_FILESIZE = 3

INVALID_TABLE_WIDTH = 4

INVALID_TYPE = 5

NO_BATCH = 6

UNKNOWN_ERROR = 7

OTHERS = 8.

*

IF NOT SY-SUBRC IS INITIAL.

*** Erro na gravação do arquivo de textos, código xxx

MESSAGE ID '00'

TYPE 'I'

NUMBER 398

WITH TEXT-003 SY-SUBRC SPACE SPACE.

EXIT.

ENDIF.

*

READ REPORT T_TRDIR-NAME INTO T_PGM.

*** Monta o nome do arquivo destino do fonte do programa

CONCATENATE P_PATH

T_TRDIR-NAME

TEXT-005

INTO C_FILE.

*** Grava o arquivo destino do fonte do programa

CALL FUNCTION 'WS_DOWNLOAD'

EXPORTING

FILENAME = C_FILE

TABLES

DATA_TAB = T_PGM

EXCEPTIONS

FILE_OPEN_ERROR = 1

FILE_WRITE_ERROR = 2

INVALID_FILESIZE = 3

INVALID_TABLE_WIDTH = 4

INVALID_TYPE = 5

NO_BATCH = 6

UNKNOWN_ERROR = 7

OTHERS = 8.

*

IF NOT SY-SUBRC IS INITIAL.

*** Erro na gravação do arquivo de fonte, código xxx

MESSAGE ID '00'

TYPE 'I'

NUMBER 398

WITH TEXT-006 SY-SUBRC SPACE SPACE.

EXIT.

ENDIF.

ENDLOOP.

*---------------------------------------------------------------------*

* FORM Z_LOAD_TEXTPOOL_LANGUAGE *

*---------------------------------------------------------------------*

* Carrega os textos do programa na língua desejada *

*---------------------------------------------------------------------*

FORM Z_LOAD_TEXTPOOL_LANGUAGE.

REFRESH: T_TEXTPOOL,

T_TEXTPOOL_L.

LOOP AT T_T002.

READ TEXTPOOL T_TRDIR-NAME INTO T_TEXTPOOL LANGUAGE T_T002-LANGU.

DESCRIBE TABLE T_TEXTPOOL LINES SY-TFILL.

CHECK NOT SY-TFILL IS INITIAL.

LOOP AT T_TEXTPOOL.

MOVE: T_T002-LANGU TO T_TEXTPOOL_L-LANGU,

T_TEXTPOOL-ID TO T_TEXTPOOL_L-ID,

T_TEXTPOOL-KEY TO T_TEXTPOOL_L-KEY,

T_TEXTPOOL-ENTRY TO T_TEXTPOOL_L-ENTRY,

T_TEXTPOOL-LENGTH TO T_TEXTPOOL_L-LENGTH.

APPEND T_TEXTPOOL_L.

ENDLOOP.

ENDLOOP.

ENDFORM. " Z_LOAD_TEXTPOOL_LANGUAGE

Qual é a sua opinião ou dúvida?