Documentos de Académico
Documentos de Profesional
Documentos de Cultura
0,
"Nome
"Rua e N
"Cep
"Cidade
"Telefone
************************************************************************
*
Include
*
************************************************************************
INCLUDE <icon>.
************************************************************************
*
Macros
*
************************************************************************
DEFINE coluna_alv.
* Monta tabela de campos a serem exibidos no ALV
clear ti_fieldcat.
ti_fieldcat-fieldname
= &1. " Ref. Campo Tabela Interna
ti_fieldcat-tabname
= &2. " Ref. Tabela Interna
ti_fieldcat-ref_tabname = &3. " Ref. Campo Tabela Standard
ti_fieldcat-ref_fieldname = &4. " Ref. Tabela Standard
ti_fieldcat-reptext_ddic
ti_fieldcat-outputlen
ti_fieldcat-hotspot
ti_fieldcat-do_sum
append ti_fieldcat.
END-OF-DEFINITION.
=
=
=
=
&5.
&6.
&7.
&8.
"
"
"
"
Ttulo da Coluna
Largura da Coluna
Coluna com HOTSPOT
Colunas com somatrio
************************************************************************
*
Tela de Parmetros
*
************************************************************************
SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE text-004.
PARAMETER:
p_land1 LIKE kna1-land1 DEFAULT 'BR',
"Pas
p_bukrs LIKE bkpf-bukrs DEFAULT '1000', "Empresa
p_gjahr LIKE bkpf-gjahr DEFAULT '2005'. "Ano
SELECTION-SCREEN: END OF BLOCK b1.
************************************************************************
*
At Selection Screen
*
************************************************************************
*at selection-screen.
************************************************************************
*
Start-of-selection
*
************************************************************************
START-OF-SELECTION.
*Montando o Header do ALV
PERFORM ysmonta_header_alv.
*Selecionando os dados
PERFORM ys_selecao_dados.
*DEFINIO DAS COLUNAS:
************************************************************************
* ASSIM:
* define dados das Colunas atravs da MACRO
* PERFORM ys_define_colunas_macro.
* OU ASSIM:
* Define dados das colunas do ALV
PERFORM ys_define_colunas_alv.
************************************************************************
* Exibe relatrio em formato ALV
PERFORM ys_exibe_alv.
*----------------------------------------------------------------------*
* Rotina executada para gerar a rea de cabealho do ALV
*
* Este form chamado de dentro da funo REUSE_ALV_GRID_DISPLAY
*
*----------------------------------------------------------------------*
FORM top_of_page_alv.
*LOGOTIPO (TRANSAO OAOR, Classe: Picture, Categoria de Classe: OT)
*Para importar uma figura, transao 0FPM002.
*Nome da Classe: PICTURES,
*Categoria de Classe: OT,
*Chave do objeto: NOME DO LOGO
*Descrio: QUALQUER DESCRIO
'S'.
'Empresa:'.
p_bukrs.
TO it_header.
CLEAR header.
header-typ =
header-key =
header-info =
APPEND header
'S'.
'Exerccio:'.
p_gjahr.
TO it_header.
CLEAR header.
header-typ =
header-key =
header-info =
APPEND header
'S'.
'Usurio:'.
sy-uname.
TO it_header.
ENDFORM.
" YSMONTA_HEADER_ALV
*----------------------------------------------------------------------*
*
Form YS_SELECAO_DADOS
*
*----------------------------------------------------------------------*
*
Seleco dos dados do ALV
*
*----------------------------------------------------------------------*
FORM ys_selecao_dados.
SELECT
name1 "Nome
stras "Regio
pstlz "Cep
ort01 "Cidade
telf1 "Telefone
FROM kna1
INTO TABLE ti_saida
WHERE land1 = p_land1.
ENDFORM.
" YS_SELECAO_DADOS
*----------------------------------------------------------------------*
*
Form ys_define_colunas_macro
*
*----------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* Define as colunas atravs da MACRO definida no incio do Programa.
*----------------------------------------------------------------------*
FORM ys_define_colunas_macro.
* Define atributos das colunas do ALV.
*
*
*
*
*
*
*
*
ti_fieldcat-fieldname
ti_fieldcat-tabname
ti_fieldcat-ref_tabname
ti_fieldcat-ref_fieldname
ti_fieldcat-reptext_ddic
ti_fieldcat-outputlen
ti_fieldcat-hotspot
ti_fieldcat-do_sum
*
coluna_alv
coluna_alv
coluna_alv
coluna_alv
coluna_alv
ENDFORM.
&1
'NAME1'
'STRAS'
'PSTLZ'
'ORT01'
'TELF1'
=
=
=
=
=
=
=
=
&1.
&2.
&3.
&4.
&5.
&6.
&7.
&8.
"
"
"
"
"
"
"
"
&2
&3
&4
&5
'TI_SAIDA' 'NAME1' 'KNA1' text-001
'TI_SAIDA' 'STRAS' 'KNA1' text-002
'TI_SAIDA' 'PSTLZ' 'KNA1' text-003
'TI_SAIDA' 'ORT01' 'KNA1' text-004
'TI_SAIDA' 'TELF1' 'KNA1' text-005
" ys_define_colunas_macro
&6
'44'
'35'
'10'
'35'
'16'
&7
'X'
''
''
''
''
&8
''.
''.
''.
''.
''.
*----------------------------------------------------------------------*
*
Form ys_define_colunas_alv
*
*----------------------------------------------------------------------*
* REPETE OS BLOCO TANTAS VEZES QUATAS FOREM OS N DE COLUNAS DO ALV *
*----------------------------------------------------------------------*
FORM ys_define_colunas_alv.
* 1 COLUNA:
CLEAR ti_fieldcat.
ti_fieldcat-fieldname
ti_fieldcat-tabname
ti_fieldcat-ref_tabname
ti_fieldcat-ref_fieldname
ti_fieldcat-reptext_ddic
ti_fieldcat-outputlen
ti_fieldcat-hotspot
ti_fieldcat-do_sum
APPEND ti_fieldcat.
=
=
=
=
=
=
=
=
'NAME1'.
'TI_SAIDA'.
'NAME1'.
'KNA1'.
text-001.
'35'.
'X'.
''.
"
"
"
"
"
"
"
"
* 2 COLUNA:
CLEAR ti_fieldcat.
ti_fieldcat-fieldname
ti_fieldcat-tabname
ti_fieldcat-ref_tabname
ti_fieldcat-ref_fieldname
ti_fieldcat-reptext_ddic
ti_fieldcat-outputlen
ti_fieldcat-hotspot
ti_fieldcat-do_sum
APPEND ti_fieldcat.
=
=
=
=
=
=
=
=
'STRAS'.
'TI_SAIDA'.
'NAME1'.
'STRAS'.
text-002.
'35'.
'X'.
''.
"
"
"
"
"
"
"
"
* 3 COLUNA:
CLEAR ti_fieldcat.
ti_fieldcat-fieldname
= 'PSTLZ'.
ti_fieldcat-tabname
ti_fieldcat-ref_tabname
ti_fieldcat-ref_fieldname
ti_fieldcat-reptext_ddic
ti_fieldcat-outputlen
ti_fieldcat-hotspot
ti_fieldcat-do_sum
APPEND ti_fieldcat.
=
=
=
=
=
=
=
'TI_SAIDA'.
'PSTLZ'.
'KNA1'.
text-003.
'10'.
''.
''.
"
"
"
"
Tabela Interna
Campo Tabela Standard
Tabela Standard
Tt. da Coluna
" Largrura da Coluna
" Define Hotspot
" Colunas com somatrio
* 4 COLUNA:
CLEAR ti_fieldcat.
ti_fieldcat-fieldname
ti_fieldcat-tabname
ti_fieldcat-ref_tabname
ti_fieldcat-ref_fieldname
ti_fieldcat-reptext_ddic
ti_fieldcat-outputlen
ti_fieldcat-hotspot
ti_fieldcat-do_sum
APPEND ti_fieldcat.
=
=
=
=
=
=
=
=
'ORT01'.
'TI_SAIDA'.
'ORT01'.
'KNA1'.
text-004.
'35'.
''.
''.
"
"
"
"
"
"
"
"
* 5 COLUNA:
CLEAR ti_fieldcat.
ti_fieldcat-fieldname
ti_fieldcat-tabname
ti_fieldcat-ref_tabname
ti_fieldcat-ref_fieldname
ti_fieldcat-reptext_ddic
ti_fieldcat-outputlen
ti_fieldcat-hotspot
ti_fieldcat-do_sum
APPEND ti_fieldcat.
ENDFORM.
=
=
=
=
=
=
=
=
'TELF1'.
'TI_SAIDA'.
'TELF1'.
'KNA1'.
text-005.
'16'.
''.
''.
"
"
"
"
"
"
"
"
" ys_define_colunas_alv
*----------------------------------------------------------------------*
*
Form ys_exibe_alv
*
*----------------------------------------------------------------------*
*
EXIBIO DO ALV
*
*----------------------------------------------------------------------*
FORM ys_exibe_alv.
* Evitar efeito colateral na chamada do ALV
DATA: lc_repid TYPE sy-repid.
* Define nome do programa chamados do ALV
lc_repid = sy-repid.
ti_layout_alv-get_selinfos
= 'X'.
t_outtab
= ti_saida " Tabela interna
EXCEPTIONS
program_error
= 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.
" ys_exibe_alv
*----------------------------------------------------------------------*
*
Form PF_STATUS_SET
*
Evento PF_STATUS_SET USADO NA FUNO ACIMA
*----------------------------------------------------------------------*
*Para copiar o PF_STATUS_SET standard, vou num pgm que o usa,
*clico no cone"Exibir Lista de Objetos"(Ctrl+Shift+F5),
*Boto direito no Statusgui e copio para o meu programa.
*EXCLUDING pf_tab abixo, exclui alguns cones.
*----------------------------------------------------------------------*
FORM pf_status_set USING pf_tab TYPE slis_t_extab.
SET PF-STATUS 'STANDARD_FULLSCREEN' ."EXCLUDING pf_tab.
ENDFORM.
" PF_STATUS_SET
*----------------------------------------------------------------------*
*
FORM AT_USER_COMMAND
*
*----------------------------------------------------------------------*
*
Trata o que ir ser feito quando o usurio clicar nas colunas *
*----------------------------------------------------------------------*
FORM user_command USING ucomm LIKE sy-ucomm
selfield TYPE kkblo_selfield.
selfield = selfield. "Selfield contem a coluna selecionada
CASE ucomm.
WHEN '&IC1'.
* L na tabela de sada
READ TABLE ti_saida INDEX selfield-tabindex.
IF sy-subrc EQ 0.
* Se foi clicado na coluna NAME1.
IF selfield-fieldname = 'NAME1'.
* Passa o valor clicado na coluna como parmetro para a transao que
*se quer chamar.
* Passa o id do campo Contrato na transao SE38.
*
Set parameter id 'XXX' field ti_saida-NAME1.
* Chamo a transao
CALL TRANSACTION 'SE38'." AND SKIP FIRST SCREEN.
ENDIF.
ENDIF.
WHEN OTHERS.
ENDCASE.
ENDFORM.
"user_command