Untitled
Untitled
Untitled
REPORT z9r_fi029 .
*----------------------------------------------------------------------*
* T A B E L A S
*----------------------------------------------------------------------*
TABLES : z9t_fi020, z9t_fi026, mltx.
*----------------------------------------------------------------------*
* C L A S S E S
*----------------------------------------------------------------------*
CLASS cl_gui_column_tree DEFINITION LOAD.
CLASS cl_gui_cfw DEFINITION LOAD.
*----------------------------------------------------------------------*
* T A B E L A S I N T E R N A S
*----------------------------------------------------------------------*
DATA : tg_020 LIKE z9t_fi020 OCCURS 0 WITH HEADER LINE,
tg_026 LIKE z9t_fi026 OCCURS 0 WITH HEADER LINE,
tg_029 LIKE z9t_fi029 OCCURS 0 WITH HEADER LINE,
tg_029_aux LIKE z9t_fi029 OCCURS 0.
*----------------------------------------------------------------------*
* I N C L U D E S
*----------------------------------------------------------------------*
INCLUDE <icon>.
INCLUDE bcalv_toolbar_event_receiver.
INCLUDE bcalv_tree_event_receiver.
*----------------------------------------------------------------------*
* E S T R U T U R A S
*----------------------------------------------------------------------*
DATA: toolbar_event_receiver TYPE REF TO lcl_toolbar_event_receiver.
*----------------------------------------------------------------------*
* C O N S T A N T E S
*----------------------------------------------------------------------*
CONSTANTS : c_1 TYPE c VALUE '1',
c_2 TYPE c VALUE '2',
c_3 TYPE c VALUE '3',
c_4 TYPE c VALUE '4',
c_01(2) TYPE c VALUE '01',
c_02(2) TYPE c VALUE '02',
c_21(2) TYPE c VALUE '21',
c_a(1) TYPE c VALUE 'A',
c_m(1) TYPE c VALUE 'M',
c_d(1) TYPE c VALUE 'D',
c_x(1) TYPE c VALUE 'X',
c_real(4) TYPE c VALUE 'Real',
c_prev(9) TYPE c VALUE 'Previsto',
c_recreal(10) TYPE c VALUE 'Rec. Real'.
*----------------------------------------------------------------------*
* T E L A D E S E L A � � O
*----------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK bl1 WITH FRAME TITLE text-001.
SELECT-OPTIONS : s_pspid FOR z9t_fi020-pspid,
s_posid FOR z9t_fi020-posid,
s_zvrsnr FOR z9t_fi026-zvrsnr.
SELECTION-SCREEN END OF BLOCK bl1.
*----------------------------------------------------------------------*
* I N I C I O D O P R O C E S S A M E N T O
*----------------------------------------------------------------------*
START-OF-SELECTION.
*----------------------------------------------------------------------*
* T E R M I N O D O P R O C E S S A M E N T O
*----------------------------------------------------------------------*
END-OF-SELECTION.
*&---------------------------------------------------------------------*
*& Module PBO OUTPUT
*&---------------------------------------------------------------------*
* process before output
*----------------------------------------------------------------------*
MODULE pbo OUTPUT.
CASE ok_code.
WHEN 'EXIT' OR 'BACK' OR 'CANC'.
PERFORM exit_program.
WHEN OTHERS.
CALL METHOD cl_gui_cfw=>dispatch.
ENDCASE.
CLEAR ok_code.
CALL METHOD cl_gui_cfw=>flush.
ENDMODULE. " PAI INPUT
*&---------------------------------------------------------------------*
*& Form build_fieldcatalog
*&---------------------------------------------------------------------*
* build fieldcatalog for structure sflight
*----------------------------------------------------------------------*
FORM build_fieldcatalog.
* get fieldcatalog
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = 'Z9T_FI029'
CHANGING
ct_fieldcat = gt_fieldcatalog.
* change fieldcatalog
DATA: ls_fieldcatalog TYPE lvc_s_fcat.
LOOP AT gt_fieldcatalog INTO ls_fieldcatalog.
CASE ls_fieldcatalog-fieldname.
WHEN 'VBELN' OR 'POSNR'.
ls_fieldcatalog-no_out = 'X'.
ls_fieldcatalog-key = ''.
WHEN 'VALLAB' OR 'VALLABL' OR 'VALLAR' OR 'VALLARL'.
ls_fieldcatalog-do_sum = 'X'.
ENDCASE.
MODIFY gt_fieldcatalog FROM ls_fieldcatalog.
ENDLOOP.
ENDFORM. " build_fieldcatalog
*&---------------------------------------------------------------------*
*& Form build_hierarchy_header
*&---------------------------------------------------------------------*
* build hierarchy-header-information
*----------------------------------------------------------------------*
* -->P_L_HIERARCHY_HEADER strucxture for hierarchy-header
*----------------------------------------------------------------------*
FORM build_hierarchy_header CHANGING
p_hierarchy_header TYPE treev_hhdr.
p_logo = 'ENJOYSAP_LOGO'.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form create_hierarchy
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM create_hierarchy.
**.Seleciona o projeto
* SELECT *
* INTO TABLE tg_020
* FROM z9t_fi020
* WHERE pspid IN s_pspid.
*
* IF NOT sy-subrc IS INITIAL.
* MESSAGE i000(z9fi) WITH 'Nenhum registro foi encontrado!!'.
* STOP.
* ENDIF.
*
* SELECT *
* INTO TABLE tg_026
* FROM z9t_fi026
* WHERE pspid IN s_pspid AND
* zvrsnr IN s_zvrsnr.
*
* SORT tg_026 BY pspid zvrsnr.
PERFORM f_limpa_tabelas.
PERFORM f_selecion_projeto.
PERFORM f_seleciona_vlr_basico.
PERFORM f_seleciona_vlr_reajust.
PERFORM f_seleciona_vlr_reajust2.
PERFORM f_seleciona_vlr_basico_real.
PERFORM f_seleciona_vlr_reajt_real.
PERFORM f_verifica_registros.
ENDON.
ON CHANGE OF st_029-posid.
PERFORM add_posid_line USING st_029
l_pspid_key
CHANGING l_posid_key.
ENDON.
ON CHANGE OF st_029-vbeln.
PERFORM add_carrid_line USING st_029
l_posid_key
CHANGING l_vbeln_key.
v_ok = c_x.
ENDON.
ON CHANGE OF st_029-posnr.
IF v_ok IS INITIAL.
PERFORM add_connid_line USING st_029
l_vbeln_key
CHANGING l_posnr_key.
ELSE.
CLEAR v_ok.
ENDIF.
ENDON.
PERFORM add_complete_line USING st_029
l_posnr_key
CHANGING l_last_key.
ENDLOOP.
* calculate totals
CALL METHOD tree1->update_calculations.
*&---------------------------------------------------------------------*
*& Form add_carrid_line
*&---------------------------------------------------------------------*
* add hierarchy-level 1 to tree
*----------------------------------------------------------------------*
* -->P_LS_SFLIGHT sflight
* -->P_RELEATKEY relatkey
* <-->p_node_key new node-key
*----------------------------------------------------------------------*
FORM add_carrid_line USING ps_fi029 TYPE z9t_fi029
p_relat_key TYPE lvc_nkey
CHANGING p_node_key TYPE lvc_nkey.
* set item-layout
DATA: lt_item_layout TYPE lvc_t_layi,
ls_item_layout TYPE lvc_s_layi.
ls_item_layout-t_image = '@3Y@'.
ls_item_layout-fieldname = tree1->c_hierarchy_column_name.
ls_item_layout-style =
cl_gui_column_tree=>style_intensifd_critical.
APPEND ls_item_layout TO lt_item_layout.
* add node
l_node_text = ps_fi029-vbeln.
CALL METHOD tree1->add_node
EXPORTING
i_relat_node_key = p_relat_key
i_relationship = cl_gui_column_tree=>relat_last_child
i_node_text = l_node_text
is_outtab_line = ls_fi029
it_item_layout = lt_item_layout
IMPORTING
e_new_node_key = p_node_key.
* set item-layout
DATA: lt_item_layout TYPE lvc_t_layi,
ls_item_layout TYPE lvc_s_layi.
ls_item_layout-t_image = '@3Y@'.
ls_item_layout-style =
cl_gui_column_tree=>style_intensified.
ls_item_layout-fieldname = tree1->c_hierarchy_column_name.
APPEND ls_item_layout TO lt_item_layout.
* add node
l_node_text = ps_fi029-posnr.
CALL METHOD tree1->add_node
EXPORTING
i_relat_node_key = p_relat_key
i_relationship = cl_gui_column_tree=>relat_last_child
i_node_text = l_node_text
is_outtab_line = ls_fi029
it_item_layout = lt_item_layout
IMPORTING
e_new_node_key = p_node_key.
l_node_text = mltx-ktext.
CALL METHOD tree1->add_node
EXPORTING
i_relat_node_key = p_relat_key
i_relationship = cl_gui_column_tree=>relat_last_child
is_outtab_line = ps_fi029
i_node_text = l_node_text
it_item_layout = lt_item_layout
IMPORTING
e_new_node_key = p_node_key.
* set Handler
DATA: l_event_receiver TYPE REF TO lcl_tree_event_receiver.
CREATE OBJECT l_event_receiver.
SET HANDLER l_event_receiver->handle_node_ctmenu_request
FOR tree1.
SET HANDLER l_event_receiver->handle_node_ctmenu_selected
FOR tree1.
SET HANDLER l_event_receiver->handle_item_ctmenu_request
FOR tree1.
SET HANDLER l_event_receiver->handle_item_ctmenu_selected
FOR tree1.
ENDFORM. " register_events
*&---------------------------------------------------------------------*
*& Form change_toolbar
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM change_toolbar.
IF sy-batch IS INITIAL.
CREATE OBJECT l_custom_container
EXPORTING
container_name = l_tree_container_name
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5.
IF sy-subrc <> 0.
MESSAGE x208(00) WITH 'ERROR'. "#EC NOTEXT
ENDIF.
ENDIF.
* create Hierarchy-header
DATA l_hierarchy_header TYPE treev_hhdr.
PERFORM build_hierarchy_header CHANGING l_hierarchy_header.
* create hierarchy
PERFORM create_hierarchy.
* register events
PERFORM register_events.
* adjust column_width
CALL METHOD tree1->column_optimize.
*.Seleciona o projeto
SELECT *
INTO TABLE tg_020
FROM z9t_fi020
WHERE pspid IN s_pspid AND
posid IN s_posid.
*&---------------------------------------------------------------------*
*& Form f_seleciona_vlr_basico
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM f_seleciona_vlr_basico.
SELECT *
INTO TABLE tg_026
FROM z9t_fi026
FOR ALL ENTRIES IN tg_020
WHERE pspid EQ tg_020-pspid AND
posid EQ tg_020-posid AND
vbeln EQ tg_020-vbeln AND
posnr EQ tg_020-posnr AND
zvrsnr EQ space AND
tplanc EQ c_02 AND
ztpsd EQ c_1.
IF sy-subrc IS INITIAL.
LOOP AT tg_026.
IF tg_026-tplanc EQ c_01.
MOVE : c_real TO tg_029-tipo1.
ELSEIF tg_026-tplanc EQ c_02.
MOVE : c_prev TO tg_029-tipo1.
ENDIF.
APPEND tg_029.
CLEAR tg_029.
ENDLOOP.
ENDIF.
*&---------------------------------------------------------------------*
*& Form f-seleciona_vlr_reajust
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM f_seleciona_vlr_reajust.
CLEAR : tg_026.
REFRESH : tg_026.
SELECT *
INTO TABLE tg_026
FROM z9t_fi026
FOR ALL ENTRIES IN tg_020
WHERE pspid EQ tg_020-pspid AND
posid EQ tg_020-posid AND
vbeln EQ tg_020-vbeln AND
posnr EQ tg_020-posnr AND
zvrsnr IN s_zvrsnr AND
tplanc EQ c_02 AND
ztpsd EQ c_1.
IF sy-subrc IS INITIAL.
LOOP AT tg_026.
vg_tabix = sy-tabix.
IF sy-subrc IS INITIAL.
IF tg_026-tplanc EQ c_01.
MOVE : c_real TO tg_029-tipo2.
ELSEIF tg_026-tplanc EQ c_02.
MOVE : c_prev TO tg_029-tipo2.
ENDIF.
ELSE.
IF tg_026-tplanc EQ c_01.
MOVE : c_real TO tg_029-tipo2.
ELSEIF tg_026-tplanc EQ c_02.
MOVE : c_prev TO tg_029-tipo2.
ENDIF.
APPEND tg_029.
CLEAR tg_029.
ENDIF.
ENDLOOP.
ENDIF.
*&---------------------------------------------------------------------*
*& Form f_seleciona_vlr_reajust2
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM f_seleciona_vlr_reajust2.
CLEAR : tg_026.
REFRESH : tg_026.
SELECT *
INTO TABLE tg_026
FROM z9t_fi026
FOR ALL ENTRIES IN tg_020
WHERE pspid EQ tg_020-pspid AND
posid EQ tg_020-posid AND
* vbeln EQ tg_020-vbeln AND
* posnr EQ tg_020-posnr AND
* zvrsnr EQ s_zvrsnr AND
tplanc EQ c_01 AND
ztpsd EQ c_2.
IF sy-subrc IS INITIAL.
LOOP AT tg_026.
vg_tabix = sy-tabix.
IF sy-subrc IS INITIAL.
IF tg_026-tplanc EQ c_01.
MOVE : c_real TO tg_029-tipo2.
ELSEIF tg_026-tplanc EQ c_02.
MOVE : c_prev TO tg_029-tipo2.
ENDIF.
ELSE.
IF tg_026-tplanc EQ c_01.
MOVE : c_real TO tg_029-tipo2.
ELSEIF tg_026-tplanc EQ c_02.
MOVE : c_prev TO tg_029-tipo2.
ENDIF.
APPEND tg_029.
CLEAR tg_029.
ENDIF.
ENDLOOP.
ENDIF.
*&---------------------------------------------------------------------*
*& Form f_limpa_tabelas
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM f_limpa_tabelas.
* set item-layout
DATA: lt_item_layout TYPE lvc_t_layi,
ls_item_layout TYPE lvc_s_layi.
ls_item_layout-t_image = '@3P@'.
ls_item_layout-style =
cl_gui_column_tree=>style_intensified.
ls_item_layout-fieldname = tree1->c_hierarchy_column_name.
APPEND ls_item_layout TO lt_item_layout.
* add node
l_node_text = ps_fi029-pspid.
CALL METHOD tree1->add_node
EXPORTING
i_relat_node_key = p_relat_key
i_relationship = cl_gui_column_tree=>relat_last_child
i_node_text = l_node_text
is_outtab_line = ls_fi029
it_item_layout = lt_item_layout
IMPORTING
e_new_node_key = p_node_key.
* set item-layout
DATA: lt_item_layout TYPE lvc_t_layi,
ls_item_layout TYPE lvc_s_layi.
ls_item_layout-t_image = '@3P@'.
ls_item_layout-style =
cl_gui_column_tree=>style_intensified.
ls_item_layout-fieldname = tree1->c_hierarchy_column_name.
APPEND ls_item_layout TO lt_item_layout.
* add node
l_node_text = ps_fi029-posid.
CALL METHOD tree1->add_node
EXPORTING
i_relat_node_key = p_relat_key
i_relationship = cl_gui_column_tree=>relat_last_child
i_node_text = l_node_text
is_outtab_line = ls_fi029
it_item_layout = lt_item_layout
IMPORTING
e_new_node_key = p_node_key.
*----------------------------------------------------------------------*
* Variaveis Locais
*----------------------------------------------------------------------*
DATA : vl_data LIKE p0001-begda,
vl_dia LIKE t5a4a-dlydy,
vl_mes LIKE t5a4a-dlymo,
vl_ano LIKE t5a4a-dlyyr,
vl_data2 LIKE p0001-begda.
IF sy-subrc IS INITIAL.
CLEAR : vl_dia, vl_mes, vl_ano, vl_data, vl_data2.
MOVE : tg_020-kdatu TO vl_data.
IF tg_020-tpreaj EQ c_a.
MOVE : tg_020-perrea TO vl_ano.
ELSEIF tg_020-tpreaj EQ c_m.
MOVE : tg_020-perrea TO vl_mes.
ELSEIF tg_020-tpreaj EQ c_d.
MOVE : tg_020-perrea TO vl_dia.
ENDIF.
ENDIF.
ENDLOOP.
*&---------------------------------------------------------------------*
*& Form f_seleciona_vlr_basico_real
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM f_seleciona_vlr_basico_real.
CLEAR : tg_026.
REFRESH : tg_026.
SELECT *
INTO TABLE tg_026
FROM z9t_fi026
FOR ALL ENTRIES IN tg_020
WHERE pspid EQ tg_020-pspid AND
posid EQ tg_020-posid AND
tplanc EQ c_21 AND
ztpsd EQ c_3.
IF sy-subrc IS INITIAL.
LOOP AT tg_026.
IF tg_026-tplanc EQ c_21.
MOVE : c_recreal TO tg_029-tipo1.
ENDIF.
APPEND tg_029.
CLEAR tg_029.
ENDLOOP.
ENDIF.
*&---------------------------------------------------------------------*
*& Form f_seleciona_vlr_reajt_real
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM f_seleciona_vlr_reajt_real.
CLEAR : tg_026.
REFRESH : tg_026.
SELECT *
INTO TABLE tg_026
FROM z9t_fi026
FOR ALL ENTRIES IN tg_020
WHERE pspid EQ tg_020-pspid AND
posid EQ tg_020-posid AND
tplanc EQ c_21 AND
ztpsd EQ c_4.
IF sy-subrc IS INITIAL.
LOOP AT tg_026.
READ TABLE tg_020 WITH KEY pspid = tg_026-pspid
posid = tg_026-posid
ztpsd = c_3
BINARY SEARCH.
IF sy-subrc IS INITIAL.
MOVE : tg_026-valla TO tg_029-vallar.
IF tg_026-tplanc EQ c_21.
MOVE : c_recreal TO tg_029-tipo2.
ENDIF.
ELSE.
CLEAR tg_029.
MOVE : tg_026-pspid TO tg_029-pspid,
tg_026-posid TO tg_029-posid,
tg_020-vbeln TO tg_029-vbeln,
tg_026-posnr TO tg_029-posnr,
tg_026-mlst_zaehl TO tg_029-mlst_zaehl,
tg_026-dtcob TO tg_029-dtcob,
tg_026-valla TO tg_029-vallar.
IF tg_026-tplanc EQ c_21.
MOVE : c_recreal TO tg_029-tipo2.
ENDIF.
APPEND tg_029.
CLEAR tg_029.
ENDIF.
ENDLOOP.
ENDIF.