You are on page 1of 4

ALV TREE

*----------------------------------------------------------------------* Tabelas internas


*----------------------------------------------------------------------TYPE-POOLS:
zopr. "pedidos de clientes
TABLES : afko,
afpo,
aufk,
mast,
plaf,
stko,
stpo,
mvke,
tvmst,
mapl.
DATA : t_data TYPE zopr_data OCCURS 1 WITH HEADER LINE.
DATA : t_ordprod TYPE zopr_prod_exp.
DATA : wa_ordpro TYPE LINE OF zopr_prod_exp.
DATA : t_ordplan TYPE zopr_plan_exp.
DATA : wa_ordpla TYPE LINE OF zopr_plan_exp.
* Primeira Tabela (Cabealho)
DATA : BEGIN OF wt_dgf OCCURS 0,
tipo TYPE c,
ano(4) TYPE n,
mes(2) TYPE n,
desc(20) TYPE c,
qdade TYPE afko-gamng,
unida TYPE afko-gmein,
END OF wt_dgf.
* Segunda Tabela (Itens)
DATA : BEGIN OF wt_ordens OCCURS 0,
tipo TYPE c,
ano(4) TYPE n,
mes(2) TYPE n,
matnr TYPE afko-plnbez,
maktx TYPE makt-maktx,
qdade TYPE afko-gamng,
unida TYPE afko-gmein,
END OF wt_ordens.
*----------------------------------------------------------------------* Tabelas internas ALV
*----------------------------------------------------------------------TYPE-POOLS: slis, "Tipos globais para ALV
vrm. "Necessrio para uso de ALV
DATA: wt_fieldcat TYPE slis_t_fieldcat_alv WITH HEADER LINE.
* Chave de ligao entre as tabelas
DATA: wf_keyinfo TYPE slis_keyinfo_alv.
DATA: wv_tabname_header TYPE slis_tabname,
wv_tabname_item TYPE slis_tabname.

DATA: wv_repid LIKE sy-repid.


*----------------------------------------------------------------------* Tela de seleo
*----------------------------------------------------------------------SELECTION-SCREEN BEGIN OF BLOCK b_janela01 WITH FRAME TITLE text-001.
SELECT-OPTIONS s_data FOR afko-gltrp. "data
PARAMETERS p_matnr LIKE afko-plnbez. "material
SELECTION-SCREEN END OF BLOCK b_janela01.
INITIALIZATION.
* Inicializar as tabelas e chave de ligao entre elas
PERFORM zform_inic_var.
START-OF-SELECTION.
* Aqui vai a seleo dos dados
*---------------------------------------------------------------------- PERFORM zform_busca_dados.
* Ordenar as tabelas pelo campo chave
SORT wt_dgf BY tipo.
SORT wt_ordens BY tipo maktx.
END-OF-SELECTION.
PERFORM zform_monta_alv.
PERFORM zform_lista_alv.
*&---------------------------------------------------------------------*
*& Form zform_monta_alv
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM zform_monta_alv .
* Primeiro montamos a tabela de cabealho e depois a de itens
*----------------------------------------------------------------------*

Cabecalho
CLEAR wt_fieldcat.
wt_fieldcat-fieldname =
wt_fieldcat-tabname =
wt_fieldcat-reptext_ddic =
wt_fieldcat-inttype =
wt_fieldcat-outputlen =
APPEND wt_fieldcat.

CLEAR wt_fieldcat.
wt_fieldcat-fieldname =
wt_fieldcat-tabname =
wt_fieldcat-reptext_ddic =
wt_fieldcat-inttype =
wt_fieldcat-outputlen =
APPEND wt_fieldcat.

'TIPO'.
'WT_DGF'.
'Tipo'.
'C'.
1.

'DESC'.
'WT_DGF'.
'Cdigo'.
'C'.
59.

CLEAR wt_fieldcat.
wt_fieldcat-fieldname = 'QDADE'.

wt_fieldcat-tabname =
wt_fieldcat-reptext_ddic =
wt_fieldcat-inttype =
wt_fieldcat-outputlen =
APPEND wt_fieldcat.

'WT_DGF'.
'Qdade (KG)'.
'P'.
16.

CLEAR wt_fieldcat.
wt_fieldcat-fieldname =
wt_fieldcat-tabname =
wt_fieldcat-reptext_ddic =
wt_fieldcat-inttype =
wt_fieldcat-outputlen =
APPEND wt_fieldcat.

Itens
CLEAR wt_fieldcat.
wt_fieldcat-fieldname =
wt_fieldcat-tabname =
wt_fieldcat-reptext_ddic =
wt_fieldcat-inttype =
wt_fieldcat-outputlen =
APPEND wt_fieldcat.

CLEAR wt_fieldcat.
wt_fieldcat-fieldname =
wt_fieldcat-tabname =
wt_fieldcat-reptext_ddic =
wt_fieldcat-inttype =
wt_fieldcat-outputlen =
APPEND wt_fieldcat.

'MATNR'.
'WT_ORDENS'.
'Cdigo'.
'C'.
18.

CLEAR wt_fieldcat.
wt_fieldcat-fieldname =
wt_fieldcat-tabname =
wt_fieldcat-reptext_ddic =
wt_fieldcat-inttype =
wt_fieldcat-outputlen =
APPEND wt_fieldcat.

'MAKTX'.
'WT_ORDENS'.
'Descrio'.
'C'.
40.

CLEAR wt_fieldcat.
wt_fieldcat-fieldname =
wt_fieldcat-tabname =
wt_fieldcat-reptext_ddic =
wt_fieldcat-inttype =
wt_fieldcat-outputlen =
APPEND wt_fieldcat.

'QDADE'.
'WT_ORDENS'.
'Qdade (KG)'.
'P'.
16.

CLEAR wt_fieldcat.
wt_fieldcat-fieldname =
wt_fieldcat-tabname =
wt_fieldcat-reptext_ddic =
wt_fieldcat-inttype =
wt_fieldcat-outputlen =
APPEND wt_fieldcat.

'UNIDA'.
'WT_ORDENS'.
'UND'.
'C'.
3.

'UNIDA'.
'WT_DGF'.
'UND'.
'C'.
3.

'TIPO'.
'WT_ORDENS'.
'Tipo'.
'C'.
1.

ENDFORM. " zform_monta_alv


*&---------------------------------------------------------------------*
*& Form ZFORM_INIC_VAR
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text

* <-- p2 text
*----------------------------------------------------------------------*
FORM zform_inic_var .
wv_repid = sy-repid.
wv_tabname_header = 'WT_DGF'.
wv_tabname_item = 'WT_ORDENS'.
CLEAR wf_keyinfo.
wf_keyinfo-header01 = 'TIPO'. "campo de ligao entre as tabelas
wf_keyinfo-item01 = 'TIPO'.
ENDFORM. " ZFORM_INIC_VAR
*&---------------------------------------------------------------------*
*& Form zform_lista_alv
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM zform_lista_alv .
* ---------------------------------------------------------------------*
* Funo para chamar a ALV. Os parametros abaixo funcionam da mesma *
* forma que na funo REUSE_ALV_GRID_DISPLAY *
* I_CALLBACK_PF_STATUS_SET *
* I_CALLBACK_USER_COMMAND *
* ---------------------------------------------------------------------*
CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
EXPORTING
i_callback_program = wv_repid
it_fieldcat = wt_fieldcat[]
i_save = 'A'
i_tabname_header = wv_tabname_header
i_tabname_item = wv_tabname_item
is_keyinfo = wf_keyinfo
TABLES
t_outtab_header = wt_dgf
t_outtab_item = wt_ordens
EXCEPTIONS
program_error = 1
OTHERS = 2.
ENDFORM. " zform_lista_alv