Escolar Documentos
Profissional Documentos
Cultura Documentos
INCLUDE z_alvbs01.
INCLUDE z_alvbf01.
START-OF-SELECTION.
PERFORM
PERFORM
PERFORM
PERFORM
fp_lectura_de_datos.
fp_validacion.
fp_campos.
display_logo.
***************TOP***********************
*&---------------------------------------------------------------------*
*& Include Z_ALVBTOP
Report Z_ALV
B
*&
*&---------------------------------------------------------------------*
REPORT
Z_ALVB.
*------------------------------------------------------------------***
**
DECLARACIN DE ESTRUCTURAS Y VARIABLES
**
***------------------------------------------------------------------*
TYPEPOOLS : slis. "Contiene todas las declaraciones de tipos necesarios para
la ALV...
DATA : it_flight
wa_flight
it_sflight
wa_sflight
it_fieldcat
wa_fieldcat
it_fieldcat1
wa_fieldcat1
wa_layout
wa_layout1
it_header
wa_header
it_header1
wa_header1
gv_resultado1
gv_resultado
gv_inicio
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
TABLE OF ty_flight,
ty_flight,
TABLE OF ty_flight,
ty_flight,
slis_t_fieldcat_alv,
slis_fieldcat_alv,
slis_t_fieldcat_alv,
slis_fieldcat_alv,
slis_layout_alv,
slis_layout_alv,
slis_t_listheader,
slis_listheader,
slis_t_listheader,
slis_listheader,
sflight-price,
sflight-price,
c.
**********************F01*************************
*&---------------------------------------------------------------------*
*& Include
Z_ALVBS01
*&---------------------------------------------------------------------*
*------------------------------------------------------------------***
**
DECLARACIN DE PARMETROS
**
***------------------------------------------------------------------*
If gv_inicio is not INITIAL.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text001. "definen un bloque en la actual pantalla de seleccin
PARAMETERS: pa_nom(10) TYPE c,
pa_edad(2) TYPE n,
pa_fecha
TYPE sy-datum.
SELECTION-SCREEN END OF BLOCK b1.
*********************F01********************
*&---------------------------------------------------------------------*
*& Include
Z_ALVBF01
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&
Form FP_LECTURA_DE_DATOS
*&---------------------------------------------------------------------*
*------------------------------------------------------------------***
**
LECTURA DE LA TABLA SFLIGHT
**
***------------------------------------------------------------------*
FORM fp_lectura_de_datos .
SELECT * FROM sflight
INTO CORRESPONDING FIELDS OF TABLE it_flight
WHERE carrid IN s_carrid AND connid IN s_connid.
ENDFORM.
" FP_LECTURA_DE_DATOS
*&---------------------------------------------------------------------*
*&
Form FP_VALIDACION
*&---------------------------------------------------------------------*
*------------------------------------------------------------------***
**
VALIDACIN SI > 60 < 60
**
***------------------------------------------------------------------*
FORM fp_validacion .
IF pa_nom IS NOT INITIAL " nombre
AND pa_edad IS NOT INITIAL. " edad
PERFORM fp_lectura_de_datos.
ELSE.
MESSAGE 'Ingrese sus datos' TYPE 'I'.
ENDIF.
IF it_flight[] IS NOT INITIAL.
a tabla interna.
*------------------------------------------------------------------***
**
ALIMENTACIN Y VISUALIZACIN DE CAMPOS
**
***------------------------------------------------------------------*
wa_fieldcat-row_pos = 1.
wa_fieldcat-col_pos = 1.
wa_fieldcat-fieldname = 'CARRID'.
wa_fieldcat-tabname = 'IT_FLIGHT'.
wa_fieldcat-ref_tabname = 'SFLIGHT'.
wa_fieldcat-key = 'X'.
"Posicin de la columna.
wa_fieldcat-row_pos = 1.
wa_fieldcat-col_pos = 2.
wa_fieldcat-fieldname = 'CONNID'.
wa_fieldcat-tabname = 'IT_FLIGHT'.
wa_fieldcat-ref_tabname = 'SFLIGHT'.
wa_fieldcat-key = 'X'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-row_pos = 1.
wa_fieldcat-col_pos = 3.
wa_fieldcat-fieldname = 'FLDATE'.
wa_fieldcat-tabname = 'IT_FLIGHT'.
wa_fieldcat-ref_tabname = 'SFLIGHT'.
wa_fieldcat-key = 'X'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-row_pos = 1.
wa_fieldcat-col_pos = 4.
wa_fieldcat-fieldname = 'PRICE'.
wa_fieldcat-tabname = 'IT_FLIGHT'.
wa_fieldcat-ref_tabname = 'SFLIGHT'.
wa_fieldcat-emphasize = 'C501'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-row_pos = 1.
wa_fieldcat-col_pos = 8.
wa_fieldcat-fieldname = 'AHORRO'.
wa_fieldcat-tabname = 'IT_FLIGHT'.
wa_fieldcat-ref_tabname = 'SFLIGHT'.
wa_fieldcat-reptext_ddic = 'Ahorro'.
"wa_fieldcat = gv_resultado1.
wa_fieldcat-emphasize = 'C201'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
*-------------------------------------------------------------------*
*
Llamada a la funcin; cabecera y logo
*
*-------------------------------------------------------------------*
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program
i_callback_top_of_page
i_background_id
i_grid_title
is_layout
it_fieldcat
TABLES
t_outtab
=
=
=
=
=
=
sy-cprog
'DISPLAY_LOGO'
'LOGO_ALV2'
'Informacin de vuelo'
wa_layout
it_fieldcat
= it_flight.
ENDFORM.
" FP_CAMPOS
*&---------------------------------------------------------------------*
*&
Form DISPLAY_LOGO
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
*-------------------------------------------------------------------*
*
CONTENIDO DE LA CABECERA
*
*-------------------------------------------------------------------*
FORM display_logo .
wa_header-typ = 'S'.
wa_header-key = 'Usuario:'.
wa_header-info = sy-uname.
APPEND wa_header TO it_header.
CLEAR wa_header.
wa_header-typ = 'S'.
wa_header-key = 'Fecha:'.
DATA: fecha_sistema(10).
WRITE sy-datum TO fecha_sistema USING EDIT MASK '__/__/____'.
wa_header-info = fecha_sistema.
APPEND wa_header TO it_header.
CLEAR wa_header.
wa_header-typ = 'S'.
wa_header-key = 'Hora: '.
DATA: hora_sistema(10).
WRITE sy-uzeit TO hora_sistema USING EDIT MASK '__:__:____'.
wa_header-info = hora_sistema.
APPEND wa_header TO it_header.
CLEAR wa_header.
wa_header-typ = 'S'.
wa_header-typ = 'S'.
wa_header-key = 'Edad:'.
wa_header-info = pa_edad.
APPEND wa_header TO it_header.
CLEAR wa_header.
*
*
*
*
*
wa_header-typ = 'S'.
wa_header-key = 'Ahorro:'.
wa_header-info = gv_resultado1.
APPEND wa_header TO it_header.
CLEAR wa_header.
" SUGERENCIAS
*****************************ALV_2B ************
INCLUDE: Z_ALV2B_TOP,
" global Data
Z_ALV2B_S01,
Z_ALV2B_F01." FORM-Routines
START-OF-SELECTION.
PERFORM LECTURA_DATOS.
PERFORM VALIDACIONES.
PERFORM ALV.
*************************TOP*************************
*&---------------------------------------------------------------------*
*& Include Z_ALV2B_TOP
Report Z_ALV
_2B
*&
*&---------------------------------------------------------------------*
REPORT
Z_ALV_2B.
TABLES: spfli, sflight.
DATA :
gv_resultado1
gv_resultado
TYPE sflight-price,
TYPE sflight-price.
"nombre
"edad
TYPE c,
TYPE n,
END OF tt_salida.
CONSTANTS:
pr TYPE s_price VALUE '0.20'.
DATA: BEGIN OF gt_sflight OCCURS 0,
carrid
LIKE sflight-carrid,
connid
LIKE sflight-connid,
fldate
LIKE sflight-fldate,
currency LIKE sflight-currency,
price
LIKE sflight-price,
END OF gt_sflight.
DATA: BEGIN OF gt_spfli OCCURS 0,
countryfr LIKE spfli-countryfr,
cityto
LIKE spfli-cityto ,
airpto
LIKE spfli-airpto,
deptime
LIKE spfli-deptime,
arrtime
LIKE spfli-arrtime,
END OF gt_spfli.
*************************S01************************
*&---------------------------------------------------------------------*
*& Include
Z_ALV2B_S01
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text001. "definen un bloque en la actual pantalla de seleccin
PARAMETERS: pa_nom(10) TYPE c,
pa_edad(2) TYPE n.
SELECTION-SCREEN END OF BLOCK b1.
SELECTION-SCREEN BEGIN OF
SELECT-OPTIONS : s_carrid
s_connid
s_fldate
*************************************F01****************************
*&---------------------------------------------------------------------*
*& Include
Z_ALV2B_F01
*&--------------------------------------------------------------------*
*&--------------------------------------------------------------------*
*&
Form LECTURA_DATOS
*&--------------------------------------------------------------------*
*
text
*---------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*---------------------------------------------------------------------*
FORM lectura_datos.
Clear: gt_sflight[],
gt_spfli[],
gt_salida[].
SELECT carrid
connid
fldate
price
currency
FROM
sflight
INTO CORRESPONDING FIELDS OF TABLE gt_sflight
WHERE carrid IN s_carrid AND connid IN s_connid
AND fldate IN s_fldate.
LOOP AT gt_sflight.
MOVE-CORRESPONDING gt_sflight TO wa_salida.
SELECT
countryfr
cityto
airpto
deptime
arrtime
INTO gt_spfli
FROM spfli.
MOVE-CORRESPONDING gt_spfli TO wa_salida.
APPEND wa_salida TO gt_salida.
ENDSELECT.
ENDLOOP.
ENDFORM.
" LECTURA_DATOS
*&--------------------------------------------------------------------*
*&
Form VALIDACIONES
*&--------------------------------------------------------------------*
*
text
*---------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*---------------------------------------------------------------------*
FORM validaciones .
IF gt_salida[] is not initial . "Si la tabla contiene dat
os, recorre la tabla interna.
LOOP AT gt_salida INTO wa_salida .
*
"Si la edad ingresada es mayor o igual de 60, tendr u
n 20% de descuento.
IF pa_edad >= 60.
*
gv_resultado1 = wa_sflight-price * '0.20'.
wa_salida-ahorro = wa_salida-price * pr.
wa_salida-price = wa_salida-price - wa_salida-ahorro.
"wa_salida-price = wa_salida-price - wa_salidaprice."- gv_resultado1.
MODIFY gt_salida FROM wa_salida.
ENDIF.
ENDLOOP.
*
"si la tabla no contiene informacin deseada, manda un m
ensaje informativo.
ELSEIF sy-subrc NE 0.
MESSAGE 'No hay vuelos disponibles en esa fecha seleccion
e otra' TYPE 'I'.
ENDIF.
ENDFORM.
" VALIDACIONES
*&--------------------------------------------------------------------*
*&
Form ALV
*&--------------------------------------------------------------------*
*
text
*---------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*---------------------------------------------------------------------*
FORM alv .
IF gt_salida[] IS NOT INITIAL.
"CL_SALV_TABLE. Con ella podemos contruirnos un informe con t
an solo llamar a un mtodo el factory y luego al displa
cl_salv_table=>factory(
IMPORTING
r_salv_table = lv_alv_object
CHANGING
t_table = gt_salida
).
g_functions = lv_alv_object->get_functions( ).
g_functions->set_all( abap_true ).
lv_columns = lv_alv_object->get_columns( ).
lv_columns->set_optimize( 'X' ).
gr_display = lv_alv_object->get_display_settings( ).
gr_display>set_striped_pattern( cl_salv_display_settings=>true ).
gr_display->set_list_header( 'Vuelos y precios' ).
** Visualizamos el ALV
lv_alv_object->display( ).
ELSE.
MESSAGE 'No tiene itinerario' TYPE 'I'.
ENDIF.
ENDFORM.
" ALV
INCLUDE: z_alv_oo_top,
z_alv_oo_s01,
z_alv_oo_f01,
z_alv_oo_i01,
z_alv_oo_o01.
START-OF-SELECTION.
PERFORM validaciones.
************************Top******************************
*&---------------------------------------------------------------------*
*& Include Z_ALV_OO_TOP
Report Z_ALV
_OO
*&
*&---------------------------------------------------------------------*
REPORT
Z_ALV_OO.
*------------------------------------------------------------------***
**
DECLARACIN DE ESTRUCTURAS Y VARIABLES
**
***------------------------------------------------------------------*
CONSTANTS:
pr TYPE sflight-price VALUE '0.20'.
data : it_flight
wa_flight
type
type
type
type
type
type
slis_layout_alv,
slis_layout_alv,
slis_t_listheader,
slis_listheader,
slis_t_listheader,
slis_listheader.
**************************************S01*****************************
*&---------------------------------------------------------------------*
*& Include
Z_ALV_OO_S01
*&---------------------------------------------------------------------*
*------------------------------------------------------------------***
**
DECLARACIN DE PARMETROS
**
***------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS: pa_nom(20)
TYPE c,
p_edad(2)
TYPE n.
SELECTION-SCREEN END OF BLOCK b1.
********************F01********************************
*&---------------------------------------------------------------------*
*& Include
Z_ALV_OO_F01
*&---------------------------------------------------------------------*
"Clase de receptor de eventos. Esta clase aade el nuevo botn a la barra
de
"herramientas y controla el evento cuando se pulsa el botn
CLASS lcl_event_receiver DEFINITION.
PUBLIC SECTION.
METHODS:
m_toolbar FOR EVENT toolbar OF cl_gui_alv_grid
IMPORTING e_object,
m_user_command FOR EVENT user_command OF cl_gui_alv_grid
IMPORTING e_ucomm.
ENDCLASS.
CLASS lcl_event_receiver IMPLEMENTATION.
METHOD m_toolbar.
" Mtodo de controlador de eventos para la barra de
herramientas de eventos.
PERFORM f_toolbar
USING e_object.
ENDMETHOD.
"m_toolbar
METHOD m_user_command.
PERFORM f_user_command_1000
USING e_ucomm.
ENDMETHOD.
"m_user_command
ENDCLASS.
"lcl_event_receiver IMPLEMENTATION
*&---------------------------------------------------------------------*
*&
Form RETRIEVE_DATA
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
FORM retrieve_data.
" RETRIEVE_DATA
*&---------------------------------------------------------------------*
*&
Form BUILD_FIELD_CATALOG
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
FORM build_field_catalog.
REFRESH: gt_fieldcat.
CLEAR: wa_fieldcat.
*
*
*
*
wa_fieldcat-fieldname
wa_fieldcat-scrtext_s
= 'CARRID'.
= 'ID'.
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
wa_fieldcat-scrtext_m
= 'Compaa area'.
wa_fieldcat-scrtext_l
= 'Compaa area'.
APPEND wa_fieldcat TO gt_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname
= 'CONNID'.
wa_fieldcat-scrtext_s
= 'Nm.'.
wa_fieldcat-scrtext_m
= 'Nm vuelo'.
wa_fieldcat-scrtext_l
= 'Nmero de vuelo'.
wa_fieldcat-emphasize
= 'C201'.
APPEND wa_fieldcat TO gt_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname
= 'FLDATE'.
wa_fieldcat-scrtext_s
= 'Fecha'.
wa_fieldcat-scrtext_m
= 'Fecha vuelo'.
wa_fieldcat-scrtext_l
= 'Fecha del vuelo'.
wa_fieldcat-emphasize
= 'C301'.
APPEND wa_fieldcat TO gt_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname
= 'PRICE'.
wa_fieldcat-scrtext_s
= 'Precio'.
wa_fieldcat-scrtext_m
= 'Precio vuelo'.
wa_fieldcat-scrtext_l
= 'Precio del vuelo'.
wa_fieldcat-emphasize
= 'C401'.
APPEND wa_fieldcat TO gt_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname
= 'CURRENCY'.
wa_fieldcat-scrtext_s
= 'Moneda'.
wa_fieldcat-scrtext_m
= 'Moneda'.
wa_fieldcat-scrtext_l
= 'Moneda'.
wa_fieldcat-emphasize
= 'C501'.
APPEND wa_fieldcat TO gt_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname
= 'SEATSMAX'.
wa_fieldcat-scrtext_s
= 'Ocupacin'.
wa_fieldcat-scrtext_m
= 'Ocupacin max.'.
wa_fieldcat-scrtext_l
= 'Ocupacin mxima'.
wa_fieldcat-emphasize
= 'C601'.
APPEND wa_fieldcat TO gt_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname
wa_fieldcat-scrtext_s
wa_fieldcat-scrtext_m
= 'SEATSOCC'.
= 'Asientos oc.'.
= 'Asientos oc.'.
* wa_fieldcat-scrtext_l
= 'Asientos ocupados'.
* wa_fieldcat-emphasize
= 'C701'.
* APPEND wa_fieldcat TO gt_fieldcat.
* CLEAR wa_fieldcat.
*
*
* wa_fieldcat-fieldname
= 'AHORRO'.
* wa_fieldcat-scrtext_s
= 'AHORRO.'.
* wa_fieldcat-scrtext_m
= 'AHORRO.'.
* wa_fieldcat-scrtext_l
= 'AHORRO'.
* wa_fieldcat-emphasize
= 'C701'.
* APPEND wa_fieldcat TO gt_fieldcat.
* CLEAR wa_fieldcat.
*
** wa_fieldcat-fieldname
= 'DESCUENTO'.
** wa_fieldcat-scrtext_s
= 'DESCUENTO.'.
** wa_fieldcat-scrtext_m
= 'DESCUENTO.'.
** wa_fieldcat-scrtext_l
= 'DESCUENTO'.
** wa_fieldcat-emphasize
= 'DESCUENTO'.
** APPEND wa_fieldcat TO gt_fieldcat.
** CLEAR wa_fieldcat.
*
wa_fieldcat-row_pos = 1.
wa_fieldcat-col_pos = 1.
"Posicin de la columna.
wa_fieldcat-fieldname = 'CARRID'.
wa_fieldcat-tabname = 'IT_FLIGHT'.
wa_fieldcat-ref_tabname = 'SFLIGHT'.
wa_fieldcat-key = 'X'.
wa_fieldcat-seltext_s = 'FLIGHT CODE'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-row_pos = 1.
wa_fieldcat-col_pos = 2.
wa_fieldcat-fieldname = 'CONNID'.
wa_fieldcat-tabname = 'IT_FLIGHT'.
wa_fieldcat-ref_tabname = 'SFLIGHT'.
wa_fieldcat-key = 'X'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-row_pos = 1.
wa_fieldcat-col_pos = 3.
wa_fieldcat-fieldname = 'FLDATE'.
wa_fieldcat-tabname = 'IT_FLIGHT'.
wa_fieldcat-ref_tabname = 'SFLIGHT'.
wa_fieldcat-key = 'X'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-row_pos = 1.
wa_fieldcat-col_pos = 4.
wa_fieldcat-fieldname = 'PRICE'.
wa_fieldcat-tabname = 'IT_FLIGHT'.
wa_fieldcat-ref_tabname = 'SFLIGHT'.
wa_fieldcat-emphasize = 'C501'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-row_pos = 1.
wa_fieldcat-col_pos = 8.
wa_fieldcat-fieldname = 'AHORRO'.
wa_fieldcat-tabname = 'IT_FLIGHT'.
wa_fieldcat-ref_tabname = 'SFLIGHT'.
wa_fieldcat-reptext_ddic = 'Ahorro'.
"wa_fieldcat = gv_resultado1.
wa_fieldcat-emphasize = 'C201'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
ENDFORM.
" BUILD_FIELD_CATALOG
*&---------------------------------------------------------------------*
*&
Form BUILD_LAYOUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
FORM build_layout.
gs_layout-cwidth_opt = 'X'.
gs_layout-col_opt
= 'X'.
gs_layout-zebra
= 'X'.
ENDFORM.
" BUILD_LAYOUT
*&---------------------------------------------------------------------*
*&
Form EXCLUDE_BUTTONS
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
"excluyendo funciones para la barra de herramientas editable alv
FORM exclude_buttons.
REFRESH:
gt_exclude.
**********************************************************************mc_
fc_check
CLEAR wa_exclude.
wa_exclude = cl_gui_alv_grid=>mc_fc_check.
APPEND wa_exclude TO gt_exclude.
**********************************************************************mc_
fc_refresh
CLEAR wa_exclude.
wa_exclude = cl_gui_alv_grid=>mc_fc_refresh.
APPEND wa_exclude TO gt_exclude.
**********************************************************************mc_
fc_loc_cut
CLEAR wa_exclude.
wa_exclude = cl_gui_alv_grid=>mc_fc_loc_cut.
APPEND wa_exclude TO gt_exclude.
**********************************************************************mc_
fc_loc_copy
CLEAR wa_exclude.
wa_exclude = cl_gui_alv_grid=>mc_fc_loc_copy.
APPEND wa_exclude TO gt_exclude.
**********************************************************************mc_
fc_loc_paste
CLEAR wa_exclude.
wa_exclude = cl_gui_alv_grid=>mc_fc_loc_paste.
APPEND wa_exclude TO gt_exclude.
**********************************************************************mc_
fc_loc_paste_new_row
CLEAR wa_exclude.
wa_exclude = cl_gui_alv_grid=>mc_fc_loc_paste_new_row.
APPEND wa_exclude TO gt_exclude.
**********************************************************************mc_
fc_loc_undo
CLEAR wa_exclude.
wa_exclude = cl_gui_alv_grid=>mc_fc_loc_undo.
APPEND wa_exclude TO gt_exclude.
**********************************************************************mc_
fc_loc_append_row
CLEAR wa_exclude.
wa_exclude = cl_gui_alv_grid=>mc_fc_loc_append_row.
APPEND wa_exclude TO gt_exclude.
**********************************************************************mc_
fc_loc_insert_row
CLEAR wa_exclude.
wa_exclude = cl_gui_alv_grid=>mc_fc_loc_insert_row.
APPEND wa_exclude TO gt_exclude.
**********************************************************************mc_
fc_loc_delete_row
CLEAR wa_exclude.
wa_exclude = cl_gui_alv_grid=>mc_fc_loc_delete_row.
APPEND wa_exclude TO gt_exclude.
**********************************************************************mc_
fc_loc_copy_row
CLEAR wa_exclude.
wa_exclude = cl_gui_alv_grid=>mc_fc_loc_copy_row.
APPEND wa_exclude TO gt_exclude.
**********************************************************************mc_
fc_sort_asc
**********************************************************************mc_
mb_sum
CLEAR wa_exclude.
wa_exclude = cl_gui_alv_grid=>mc_mb_sum.
APPEND wa_exclude TO gt_exclude.
**********************************************************************mc_
fc_subtot
CLEAR wa_exclude.
wa_exclude = cl_gui_alv_grid=>mc_fc_subtot.
APPEND wa_exclude TO gt_exclude.
**********************************************************************mc_
fc_print
CLEAR wa_exclude.
wa_exclude = cl_gui_alv_grid=>mc_fc_print.
APPEND wa_exclude TO gt_exclude.
**********************************************************************mc_
fc_views
CLEAR wa_exclude.
wa_exclude = cl_gui_alv_grid=>mc_fc_views.
APPEND wa_exclude TO gt_exclude.
**********************************************************************mc_
mb_export
**********************************************************************mc_
fc_current_variant
CLEAR wa_exclude.
wa_exclude = cl_gui_alv_grid=>mc_fc_current_variant.
APPEND wa_exclude TO gt_exclude.
**********************************************************************mc_
fc_graph
CLEAR wa_exclude.
wa_exclude = cl_gui_alv_grid=>mc_fc_graph.
APPEND wa_exclude TO gt_exclude.
**********************************************************************mc_
fc_info
CLEAR wa_exclude.
wa_exclude = cl_gui_alv_grid=>mc_fc_info.
APPEND wa_exclude TO gt_exclude.
ENDFORM.
" EXCLUDE_BUTTONS
*&---------------------------------------------------------------------*
*&
Form EXIT_PROGRAM
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
FORM exit_program.
CALL METHOD g_custom_container->free.
CALL METHOD cl_gui_cfw=>flush.
LEAVE PROGRAM. " Esta declaracin inmediatamente termina el programa p
rincipal actual y elimina su interior sesin
" incluyendo todos los programas cargados,
"instancias y sus datos.
ENDFORM.
" EXIT_PROGRAM
*&---------------------------------------------------------------------*
*&
Form F_TOOLBAR
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
*
-->P_TOOLBAR text
*----------------------------------------------------------------------*
FORM f_toolbar USING p_toolbar TYPE REF TO cl_alv_event_toolbar_set.
DATA:
lv_stb_button TYPE stb_button.
"aadir separador
lv_stb_button-butn_type = '3'.
APPEND lv_stb_button TO p_toolbar->mt_toolbar.
"aadir botn Salir
lv_stb_button-text = 'Salir'.
lv_stb_button-function = 'EXIT'.
lv_stb_button-icon = icon_cancel.
lv_stb_button-quickinfo = 'Salir'.
lv_stb_button-butn_type = ''.
APPEND lv_stb_button TO p_toolbar->mt_toolbar.
ENDFORM.
" F_TOOLBAR
*&---------------------------------------------------------------------*
*&
Form F_USER_COMMAND_1000
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
*
-->P_UCOMM
text
*----------------------------------------------------------------------*
FORM f_user_command_1000 USING p_ucomm TYPE sy-ucomm.
"UserCommand para el Toolbar del ALV
CASE p_ucomm.
WHEN 'NEW'.
WHEN 'EDIT'.
WHEN 'REFRESH'.
WHEN 'EXIT'.
PERFORM exit_program.
ENDCASE.
ENDFORM.
" F_USER_COMMAND_1000
*&---------------------------------------------------------------------*
*&
Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
SET PF-STATUS 'Z_ALV_OO_SG'.
PERFORM build_field_catalog.
PERFORM build_layout.
PERFORM retrieve_data.
CREATE OBJECT g_custom_container
EXPORTING
container_name = g_container.
CREATE OBJECT alv_grid
EXPORTING
i_parent = g_custom_container.
DATA: event_receiver TYPE REF TO lcl_event_receiver.
OUTPUT
*----------------------------------------------------------------------*
* MODULE USER_COMMAND_0100 INPUT
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
ok_code = sy-ucomm.
CASE ok_code.
WHEN 'EXIT'.
PERFORM exit_program.
ENDCASE.
ENDMODULE.
"USER_COMMAND_0100 INPUT
" VALIDACIONES
FORM build_alv_header .
"Cdigo de cabecera
wa_listheader-typ = 'S'.
wa_listheader-key = 'Date :' .
CONCATENATE sy-datum+6(2)
sy-datum+4(2)
sy-datum(4)
INTO wa_listheader-info
SEPARATED BY '/'.
APPEND wa_listheader TO it_listheader.
CLEAR wa_listheader.
wa_listheader-typ = 'H'.
wa_listheader-info ='Nombre'.
wa_listheader-info = pa_nom.
APPEND wa_listheader TO it_listheader.
CLEAR wa_listheader.
wa_listheader-typ = 'H'.
wa_listheader-info ='Edad'.
wa_listheader-info = p_edad.
APPEND wa_listheader TO it_listheader.
CLEAR wa_listheader.
wa_listheader-typ = 'A'.
wa_listheader-info ='SAP ALV O.O'.
APPEND wa_listheader TO it_listheader.
CLEAR wa_listheader.
ENDFORM.
" BUILD_ALV_HEADER
*&---------------------------------------------------------------------*
*&
Form top_of_page
*&---------------------------------------------------------------------*
FORM top_of_page.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = it_listheader
i_callback_program
= g_repid
i_callback_top_of_page = 'TOP_OF_PAGE'
i_structure_name
= 'SFLIGHT'.
ENDFORM.
********************EJERcicio 2**********************************+
*&---------------------------------------------------------------------*
*& Report Z_ALV_EJERCICIO
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
report
z_alv_ejercicio.
lv_columns->set_optimize( 'X' ).
** Cambiamos el nombre de la columna contador para que saque su descripci
n
lv_column = lv_columns->get_column('CONTADOR').
lv_column->set_long_text( text-001 ).
lv_column->set_medium_text( text-001 ).
lv_column->set_short_text( text-001 ).
** Visualizamos el ALV
lv_alv_object->display( ).
endif.
report z_alv_ejercicio2.
include <icon>.
when 'TO_SPFLI'.
leave to screen 100.
when 'TO_SFLIGHT'.
perform load_sflight_table tables lt_rows.
call screen 200.
endcase.
endmethod.
"handle_user_command
endclass.
*
* lcl_event_receiver (Implementation)
*===================================================================
*---------------------------------------------------------------------*
*
FORM EXIT_PROGRAM
*
*---------------------------------------------------------------------*
form exit_program.
" instancia no se liberar hasta que el programa
"sale de la pantalla principal.
call method custom_container1->free.
if not custom_container2 is initial.
call method custom_container2->free.
endif.
call method cl_gui_cfw=>flush.
if sy-subrc ne 0.
call function 'POPUP_TO_INFORM'
exporting
titel = g_repid
txt2 = sy-subrc
txt1 = 'Error in Flush'(500).
endif.
leave program.
endform.
*&---------------------------------------------------------------------*
*&
Module PBO_100 OUTPUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
module pbo_100 output.
"Crear el contenedor.
create object custom_container1
exporting
container_name = cont_on_100.
"create una instancia del alv.
create object grid1
exporting i_parent = custom_container1.
"Barra de ttulo para el control del grid.
gs_layout-grid_title = text-100.
call method grid1->set_table_for_first_display
exporting i_structure_name = 'SPFLI'
is_layout
= gs_layout
changing it_outtab
= gt_spfli.
********
*
" Crear objeto para recibir eventos y vincularlos a handler mtodos.
" Cuando el control ALV provoca el evento
"El mtodo correspondiente es llamado automticamente para todas las inst
ancias.
set handler lcl_event_receiver=>handle_user_command
lcl_event_receiver=>handle_menu_button
lcl_event_receiver=>handle_toolbar for all instances.
*
********
endcase.
clear ok_code.
endmodule.
" PAI_100 INPUT
*&---------------------------------------------------------------------*
*&
Module PBO_200 OUTPUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
module pbo_200 output.
set pf-status 'MAIN100'.
g_repid = sy-repid.
if custom_container2 is initial.
case ok_code.
when 'EXIT'.
perform exit_program.
endcase.
clear ok_code.
endmodule.
" PAI_200 INPUT
*&---------------------------------------------------------------------*
*&
Form SELECT_TABLE_SFLIGHT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
*
<--P_GT_SFLIGHT text
*----------------------------------------------------------------------*
form select_table_sflight using
p_ls_spfli like line of gt_spfli
changing p_gt_sflight like gt_sflight[].
select * from sflight into table p_gt_sflight up to g_max rows
where carrid = p_ls_spfli-carrid
and
connid = p_ls_spfli-connid.
endform.
" SELECT_TABLE_SFLIGHT
*&---------------------------------------------------------------------*
*&
Form SELECT_TABLE_SPFLI
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
*
<--P_it_spfli text
*----------------------------------------------------------------------*
form select_table_spfli changing p_gt_spfli like gt_spfli[].
select * from spfli into table p_gt_spfli.
endform.
" SELECT_TABLE_SPFLI
*&---------------------------------------------------------------------*
*&
Form load_sflight_table
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
*
-->P_LT_ROWS text
*----------------------------------------------------------------------*
form load_sflight_table tables p_et_index_rows structure lvc_s_row.
data: ls_selected_line like lvc_s_row,
lf_row_index type lvc_index,
ls_spfli like line of gt_spfli.
clear gt_sflight[].
read table p_et_index_rows index 1 into ls_selected_line.
if sy-subrc eq 0.
lf_row_index = ls_selected_line-index.
"Leer la informacin de la tabla interna it_sflight
read table gt_spfli index lf_row_index into ls_spfli.
"Seleccionar lneas correspondientes de la tabla spfli
perform select_table_sflight using ls_spfli
changing gt_sflight..
endif.
endform.
*&---------------------------------------------------------------------*
*& Report Z_ALV_4
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
report
z_alv_4.
field-symbols:
<f_tab1> type standard table.
parameters:
p_tname type tabname16 obligatory, " DEFAULT 'MARA' ,
p_rows(5) type c default '200'.
*----------------------------------------------------------------------*
*
CLASS lcl_dynamic DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
class lcl_dynamic definition .
public section.
methods:
check_selection
exceptions invalid_table,
main
exceptions no_data_found,
display.
private section.
type-pools: abap.
data: tab type ref to cl_abap_structdescr,
wa_tab type ref to cl_abap_structdescr,
comp_tab
type cl_abap_structdescr=>component_table,
i_tab type ref to cl_abap_tabledescr,
i_table type ref to data.
endclass.
"lcl_dynamic DEFINITION
*----------------------------------------------------------------------*
*
CLASS lcl_dynamic IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
class lcl_dynamic implementation.
method check_selection.
select count( * )
from dd02l
where tabname = p_tname
and
as4local = 'A'
and
tabclass = 'TRANSP'.
if sy-subrc <> 0.
raise invalid_table.
endif.
endmethod.
"check_selection
method main.
tab ?= cl_abap_typedescr=>describe_by_name( p_tname ).
comp_tab = tab->get_components( ).
wa_tab
= cl_abap_structdescr=>create( comp_tab ).
i_tab
= cl_abap_tabledescr=>create( wa_tab ).
*Get data
select * from (p_tname)
into table <f_tab1>
up to p_rows rows.
if sy-subrc <> 0.
raise no_data_found.
endif.
endmethod.
"main
method display.
set titlebar sy-title
of program sy-cprog
with 'Display table:' p_tname.
data:
l_gr_alv type ref to cl_salv_table,
l_gr_functions type ref to cl_salv_functions.
try.
call method cl_salv_table=>factory
importing
r_salv_table = l_gr_alv
changing
t_table
= <f_tab1>.
catch cx_salv_msg .
endtry.
l_gr_functions = l_gr_alv->get_functions( ).
l_gr_functions->set_all( abap_true ).
l_gr_alv->display( ).
endmethod.
endclass.
"display
"lcl_dynamic IMPLEMENTATION
at selection-screen.
"#EC NO_HANDLER
if sy-subrc <> 0.
message e001(00) with
p_tname ' No es un tabla transparente'.
endif.
start-of-selection.
data oref_main type ref to lcl_dynamic.
create object oref_main.
call method oref_main->main
exceptions
no_data_found = 1.
if sy-subrc <> 0.
message i001(00) with 'No se encontraron datos'.
leave list-processing.
endif.
end-of-selection.
call method oref_main->display.
*********************EXAMEN *******************
*&---------------------------------------------------------------------*
*& Report Z_EXAMEN_MGB1
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
report
include
include
include
include
include
z_examen_mgb1_top.
z_examen_mgb1_s01.
z_examen_mgb1_f01.
z_examen_mgb1_pai.
z_examen_mgb1_pbo.
start-of-selection.
perform f_initiar_alv.
perform f_build_fieldcatalog.
* PERFORM f_llena_la_tabla.
call function 'ZF_EXAMEN_MGB01'
exporting
i_carrid
= p_carrid
importing
e_zsflight
exceptions
not_datafound
others
= it_sflight
= 1
= 2.
perform f_cal_precioxtcambio.
perform f_display_alv.
end-of-selection.
call screen 0100.
*&---------------------------------------------------------------------*
*& Include
Z_EXAMEN_MGB1_TOP
*&---------------------------------------------------------------------*
tables sflight.
data: it_sflight
data: wa_sflight
data: w_pxtipoc
*&---------------------------------------------------------------------*
*& Include
Z_EXAMEN_MGB1_S01
*&---------------------------------------------------------------------*
selection-screen begin of block ss02 with frame title text-002.
parameters
: p_carrid type s_carr_id.
selection-screen end of block ss02.
*&---------------------------------------------------------------------*
*& Include
Z_EXAMEN_MGB1_F01
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&
Form F_INITIAR_ALV
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
form f_initiar_alv .
create object gv_container
exporting
container_name = 'GV_CONTAINER'.
create object gv_grid
exporting
i_parent = gv_container.
endform.
" F_INITIAR_ALV
*&---------------------------------------------------------------------*
*&
Form F_BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
form f_build_fieldcatalog .
call function 'LVC_FIELDCATALOG_MERGE'
exporting
i_structure_name
= 'SFLIGHT'
changing
ct_fieldcat
= lt_fieldcat
exceptions
inconsistent_interface = 1
program_error
= 2
others
= 3.
endform.
*&---------------------------------------------------------------------*
*&
Form F_LLENA_LA_TABLA
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
form f_llena_la_tabla .
select * from sflight into table it_sflight
where carrid = p_carrid.
endform.
*&---------------------------------------------------------------------*
*&
Form F_DISPLAY_ALV
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
form f_display_alv .
call method gv_grid->set_table_for_first_display
exporting
i_default
= 'X'
changing
it_fieldcatalog = lt_fieldcat
it_outtab
= it_sflight.
endform.
*&---------------------------------------------------------------------*
*&
Form F_CAL_PRECIOXTCAMBIO
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
form f_cal_precioxtcambio .
loop at it_sflight into wa_sflight.
call function 'ZF_EXAMEN_MGB02'
exporting
i_price
= wa_sflight-price
importing
e_pxtipoc
= wa_sflight-price
exceptions
not_datafound
= 1
others
= 2
.
if sy-subrc <> 0.
* Implement suitable error handling here
endif.
modify it_sflight from wa_sflight.
endloop.
endform.
" F_CAL_PRECIOXTCAMBIO
*&---------------------------------------------------------------------*
*& Include
Z_EXAMEN_MGB1_PAI
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&
Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
module status_0100 output.
set pf-status '0100'.
* SET TITLEBAR 'xxx'.
endmodule.
*&---------------------------------------------------------------------*
*& Include
Z_EXAMEN_MGB1_PBO
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&
Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
module user_command_0100 input.
case gv_okcode.
when 'ZBACK'.
set screen 0.
leave screen.
when 'ZFIN'.
call transaction 'SE80'.
when
'ZCANCEL'.
message i000 with 'Boton Cancel'.
endcase.
endmodule.
" USER_COMMAND_0100 INPUT
include: z_alv_objetos_top,
z_alv_objetos_o01,
z_alv_objetos_i01,
z_alv_objetos_f01.
start-of-selection.
perform obtener_datos.
end-of-selection.
*&---------------------------------------------------------------------*
*& Include
Z_ALV_OBJETOS_TOP
*&---------------------------------------------------------------------*
report z_alv_objetos.
*--------------------------------------------------------------------***
**
ESTRUCTURAS
**
***--------------------------------------------------------------------*
*--------------------------------------------------------------------***
** F I E L D S
S Y M B O L S
**
***--------------------------------------------------------------------*
data: ob_alvgrid
type ref to cl_gui_alv_grid,
ob_container type ref to cl_gui_custom_container.
*--------------------------------------------------------------------***
** V A R I A B L E S
**
***--------------------------------------------------------------------*
data: w_container_name type scrfname value 'C_ALV'.
*&---------------------------------------------------------------------*
*& Include
Z_ALV_OBJETOS_O01
*&--------------------------------------------------------------------*
module status_0100 output.
set pf-status 'PF_100'.
endmodule.
" STATUS_0100 OUTPUT
*&--------------------------------------------------------------------*
*&
Module ALV OUTPUT
*&--------------------------------------------------------------------*
*
text
*---------------------------------------------------------------------*
module alv output.
if not it_mara[] is initial.
perform crea_alv.
perform crea_fieldcat.
perform crea_layout.
perform muestra_alv.
endif.
endmodule.
" ALV
OUTPUT
*&---------------------------------------------------------------------*
*& Include
Z_ALV_OBJETOS_I01
*&---------------------------------------------------------------------*
module user_command_0100 input.
case sy-ucomm.
when 'BACK'.
leave program.
endcase.
endmodule.
*&---------------------------------------------------------------------*
*& Include
Z_ALV_OBJETOS_F01
*&---------------------------------------------------------------------*
form obtener_datos .
select *
from mara
up to 15 rows
into table it_mara.
if sy-subrc eq 0.
call screen 100.
endif.
endform.
" OBTENER_DATOS
*&---------------------------------------------------------------------*
*&
Form CREA_ALV
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
form crea_alv .
*
Crear container
if ob_container is initial .
create object ob_container
exporting
container_name
exceptions
cntl_error
cntl_system_error
create_error
lifetime_error
lifetime_dynpro_dynpro_link
others
if sy-subrc = 0.
= w_container_name
=
=
=
=
=
=
1
2
3
4
5
6.
= 'MARA'
= it_fieldcat
= 1
= 2
= 3.
endform.
" CREA_FIELDCAT
*&---------------------------------------------------------------------*
*&
Form CREA_LAYOUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
form crea_layout .
wa_layout-zebra = 'X' .
wa_layout-grid_title = 'ALV O.O' .
endform.
" CREA_LAYOUT
*&---------------------------------------------------------------------*
*&
Form MUESTRA_ALV
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
form muestra_alv .
call method ob_alvgrid->set_table_for_first_display
exporting
is_layout
= wa_layout
changing
it_outtab
it_fieldcatalog
exceptions
invalid_parameter_combination
program_error
too_many_lines
others
if sy-subrc ne 0.
= it_mara[]
= it_fieldcat
=
=
=
=
1
2
3
4.
" MUESTRA_ALV
***********************Tree
************************+
report z_alv_tree.
*######################*
* DECLARACION DE TYPES
*######################*
types: begin of ty_spfli,
carrid type spfli-carrid,
connid type spfli-connid,
countryfr type spfli-countryfr,
cityfrom type spfli-cityfrom,
airpfrom type spfli-airpfrom,
countryto type spfli-countryto,
cityto type spfli-cityto,
end of ty_spfli.
perform init_tree.
endif.
call screen 100.
*######################*
*
FORM init_tree
*######################*
form init_tree.
perform create_hierarchy.
endform.
*######################*
*
FORM FILL_CATALOG_TREE
*######################*
form fill_catalog_tree.
= 1.
= 'Flight'.
= 'Flight'.
= 'CONNID'.
'T_SPFLI'.
gt_fieldcat_tree.
clear gs_fieldcat.
gs_fieldcat-col_pos
gs_fieldcat-reptext
gs_fieldcat-scrtext_s
gs_fieldcat-fieldname
gs_fieldcat-tabname =
append gs_fieldcat to
= 2.
= 'Country'.
= 'Country'.
= 'COUNTRYFR'.
'T_SPFLI'.
gt_fieldcat_tree.
clear gs_fieldcat.
gs_fieldcat-col_pos
gs_fieldcat-reptext
gs_fieldcat-scrtext_s
gs_fieldcat-fieldname
gs_fieldcat-tabname =
gs_fieldcat-outputlen
append gs_fieldcat to
= 3.
= 'Dep.City'.
= 'Dep.City'.
= 'CITYFROM'.
'T_SPFLI'.
= '15'.
gt_fieldcat_tree.
clear gs_fieldcat.
gs_fieldcat-col_pos
gs_fieldcat-reptext
gs_fieldcat-scrtext_s
gs_fieldcat-fieldname
gs_fieldcat-tabname =
gs_fieldcat-outputlen
append gs_fieldcat to
= 4.
= 'Dep.Airp'.
= 'Dep.Airp'.
= 'AIRPFROM'.
'T_SPFLI'.
= '20'.
gt_fieldcat_tree.
clear gs_fieldcat.
gs_fieldcat-col_pos
gs_fieldcat-reptext
gs_fieldcat-scrtext_s
gs_fieldcat-fieldname
=
=
=
=
5.
'Country'.
'Country'.
'COUNTRYTO'.
gs_fieldcat-tabname = 'T_SPFLI'.
gs_fieldcat-outputlen = '15'.
append gs_fieldcat to gt_fieldcat_tree.
clear gs_fieldcat.
gs_fieldcat-col_pos
gs_fieldcat-reptext
gs_fieldcat-scrtext_s
gs_fieldcat-fieldname
gs_fieldcat-tabname =
gs_fieldcat-outputlen
append gs_fieldcat to
= 6.
= 'Arr.City'.
= 'Arr.City'.
= 'CITYTO'.
'T_SPFLI'.
= '20'.
gt_fieldcat_tree.
endform.
*#######################*
*
FORM build_hierarchy_header
*#######################*
form build_hierarchy_header changing
p_hierarchy_header type treev_hhdr.
clear p_hierarchy_header.
p_hierarchy_header-heading = 'Airline carrier'(300).
p_hierarchy_header-width = 18.
p_hierarchy_header-width_pix = ' '.
endform.
*#######################*
*
FORM create_hierarchy
*#######################*
form create_hierarchy.
data: l_root_key type lvc_nkey,
l_next_key type lvc_nkey,
l_last_key type lvc_nkey,
header type string,
w_menge_text(13) type c.
clear l_root_key.
loop at t_header assigning <header>.
clear l_root_key.
clear l_next_key.
perform add_node using <header>-carrid l_root_key
changing l_next_key.
loop at t_spfli assigning <spfli>
where carrid eq <header>-carrid.
move-corresponding
<spfli> to tab_tree.
*#######################*
form obtener_datos.
select carrid connid countryfr cityfrom
airpfrom countryto cityto
into table t_spfli
from spfli.
if sy-subrc eq 0.
loop at t_spfli assigning <spfli>.
move <spfli>-carrid to t_header-carrid.
append t_header.
endloop.
sort t_header.
delete adjacent duplicates from t_header.
endif.
endform.
Lorena
*&---------------------------------------------------------------------*
*& Report ZLSG_EJ1ALVOO
*&
*&---------------------------------------------------------------------*
*& Consultor: Lorena Silva (NOUSFERA).
*& Fecha:
2013.12.27
*& Objetivo: Mostrar en un listado ALV, una cosulta de vuelos.
*&
de tratarse de una persona de la tercera edad aplicarle
*&
el 20% descuento y mostrar el ahorro.
*&---------------------------------------------------------------------*
report
zlsg_ej1alvoo.
include zlsg_ej1alvoo_top.
include zlsg_ej1alvoo_s01.
include zlsg_ej1alvoo_f01.
start-of-selection.
perform fp_procesos.
*********Top************+
*&---------------------------------------------------------------------*
*& Include
ZLSG_EJ1ALVOO_TOP
*&---------------------------------------------------------------------*
" Tipos de datos
types:
begin of ty_sflight,
carrid
type sflight-carrid,
connid
type sflight-connid,
fldate
type sflight-fldate,
price
type sflight-price,
currency type sflight-currency,
end of ty_sflight,
tt_sflight type standard table of ty_sflight,
begin of ty_scarr,
carrid type scarr-carrid,
carrname type scarr-carrname,
end of ty_scarr,
tt_scarr type standard table of ty_scarr,
begin of ty_spfli,
carrid
type
connid
type
countryfr
type
cityfrom
type
airpfrom
type
countryto
type
cityto
type
airpto
type
fltime
type
spfli-carrid,
spfli-connid,
spfli-countryfr,
spfli-cityfrom,
spfli-airpfrom,
spfli-countryto,
spfli-cityto,
spfli-airpto,
spfli-fltime,
deptime
type spfli-deptime,
arrtime
type spfli-arrtime,
end of ty_spfli,
tt_spfli type standard table of ty_spfli,
begin of ty_salida,
carrid
type sflight-carrid,
connid
type sflight-connid,
carrname type scarr-carrname,
fldate
type sflight-fldate,
countryfr type spfli-countryfr,
cityfrom type spfli-cityfrom,
airpfrom type spfli-airpfrom,
countryto type spfli-countryto,
cityto
type spfli-cityto,
airpto
type spfli-airpto,
fltime
type spfli-fltime,
deptime
type spfli-deptime,
arrtime
type spfli-arrtime,
price
type sflight-price,
currency type sflight-currency,
ahorr
type p length 6 decimals 3,
end of ty_salida,
tt_salida type standard table of ty_salida.
" Declaracin de tablas internas y work areas
data:
it_flight type standard table of ty_sflight,
wa_flight type ty_sflight,
it_scarr type standard table of ty_scarr,
wa_scarr type ty_scarr,
it_spfli type standard table of ty_spfli,
wa_spfli type ty_spfli,
it_salida type standard table of ty_salida,
wa_salida type ty_salida.
" Declaracin de variables globales del report
data:
gv_ok type c,
gv_sug type c.
" Declaracin de constantes
constants:
c_x
type c value 'X',
c_a
type c value 'A',
c_0
type i value '0',
c_60(2) type c value '60',
c_80
type f value '0.80'.
" Variables necesarias para la creacin de ALV...
data: it_fieldcat
wa_fieldcat
wa_layout
it_sort_alv
ob_container
ob_alv_grid
type
type
type
type
type
type
lvc_t_fcat,
lvc_s_fcat,
lvc_s_layo,
lvc_t_sort,
ref to cl_gui_custom_container,
ref to cl_gui_alv_grid.
***************S01*******
selection-screen begin of block b1 with frame title text-001.
parameters: p_nmbr
type char50,
p_edad
type i.
selection-screen end of block b1.
selection-screen begin of block b2 with frame title text-002.
parameters: p_line
type sflight-carrid,
p_fecha
type sy-datum.
selection-screen end of block b2.
*****************F01************
*&---------------------------------------------------------------------*
*& Include
ZLSG_EJ1ALVOO_F01
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&
Form FP_PROCESOS
*&---------------------------------------------------------------------*
* ste subrutina encierra todos los procesos del programa
* ZLSG_EJ1ALVOO
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
form fp_procesos .
clear: gv_ok, gv_sug.
" Continuar solo si se tienen los datos del cliente...
if p_nmbr is not initial " nombre
and p_edad is not initial. " edad
" Lee los datos de tabla SFLIGHT
perform fp_lee_sflight changing it_flight
gv_ok
gv_sug.
if it_flight[] is not initial.
perform fp_lee_scarr
using it_flight
changing it_scarr.
*
*
else.
" implementar mensaje de error
endif.
endform.
" FP_PROCESOS
*&---------------------------------------------------------------------*
*&
Form FP_LEE_SLIGHT
*&---------------------------------------------------------------------*
*
Lee los vuelos correspondientes en tabla transparente
SFLIGHT.
*----------------------------------------------------------------------*
*
-->P_P_NMBR text
*
-->P_P_EDAD text
*
<--P_IT_FLIGHT text
*
<--P_GV_OK text
*----------------------------------------------------------------------*
form fp_lee_sflight changing pt_flight type tt_sflight
pv_ok type c
pv_sug type c.
" Limpio mi tabla a alimentar...
refresh pt_flight[].
" limpio mi bandera de "xito"
clear pv_ok.
* Traigo los datos referentes a la aerolnea electa por el cliente
select carrid
connid
fldate
price
currency
from sflight
into table pt_flight
where carrid eq p_line. " ID de Aerolnea
*
AND fldate EQ p_fecha. " Fecha del vuelo
" Si se tienen datos...
if pt_flight[] is not initial.
" filtrar por fecha
perform fp_fecha changing pt_flight[].
" Si se siguen teniendo datos, indico que tuve xito
" en mi lectura...
if pt_flight[] is not initial.
pv_ok = c_x. " Se prende bandera de xito...
else. " Sino, se traen sugerencias de otras aerolneas
" Limpio mi tabla interna de vuelos...
refresh pt_flight[].
" Hago mi lectura sin where condition, para traer la
" informacin de todas las aerolneas
select carrid
connid
fldate
price
currency
from sflight
into table pt_flight.
if pt_flight[] is not initial.
" Filtro por fecha..
perform fp_fecha changing pt_flight[].
" Si se tienen datos...
if pt_flight[] is not initial.
pv_sug = c_x. " Indico que devolver sugerencias...
pv_ok = c_x. " Se tiene xito ..
endif.
endif.
endif.
endif.
endform.
" FP_LEE_SLIGHT
*&---------------------------------------------------------------------*
*&
Form FP_FILTRO_CLIENTE
*&---------------------------------------------------------------------*
*
Dependiendo el cliente se lleva a cabo el calculo del descuento
*
y el ahorro.
*----------------------------------------------------------------------*
*
-->P_IT_FLIGHT text
*
<--P_GV_OK text
*----------------------------------------------------------------------*
form fp_filtro_cliente using
pt_flight type tt_sflight
*----------------------------------------------------------------------*
form fp_fecha changing pt_flight type tt_sflight.
data: lt_tmp type standard table of ty_sflight,
lw_tmp type ty_sflight.
clear wa_flight.
" Siempre antes de un DELETE ADJACENT DUPLICATES se debe ordenar
" la informacin
" En ste caso se ordena por ID de Aerolnea y Fecha de vuelo...
sort pt_flight by carrid fldate.
" Se elimina de la tabla la posible informacin duplicada
delete adjacent duplicates from pt_flight comparing carrid
fldate.
" Si nuestra tabla an tiene datos ...
if pt_flight[] is not initial.
" La asigno a una tabla interna local, para trabajar sobre sta...
lt_tmp[] = pt_flight[].
loop at pt_flight into wa_flight.
" Si la fecha no coincide con la fecha deseada ...
if wa_flight-fldate ne p_fecha.
"Elimino el registro...
delete lt_tmp where carrid = wa_flight-carrid
and connid = wa_flight-connid
and fldate = wa_flight-fldate.
endif.
endloop.
endif.
" Limpio mi tabla interna de vuelos, ya que contendr lo que se
" logr filtrar...
refresh pt_flight[].
" Si la tabla temporal tiene datos quiere decir que si hay
" aerolneas ofreciendo vuelos con la fecha deseada por el cliente...
if lt_tmp[] is not initial.
" Asigno los vuelos que si cumplen de nuevo en mi tabla interna
" de vuelos disponibles...
pt_flight[] = lt_tmp[].
endif.
endform.
" FP_FECHA
*&---------------------------------------------------------------------*
*&
Form FP_MOSTRAR
*&---------------------------------------------------------------------*
* Impresin en pantalla, de la informacin correspondiente, por medio
*
de sentencia WRITE.
*----------------------------------------------------------------------*
*
-->P_IT_SALIDA text
*----------------------------------------------------------------------*
form fp_mostrar using
pt_salida type tt_salida
pv_sug type c.
" Si no fue necesario traer informacin de sugerencias...
if pv_sug is initial.
" Muestro datos del cliente...
write:/ 'Cliente', ':', p_nmbr.
write:/'Edad', ':', p_edad.
" Hago un salto de lnea...
write: /.
" Escribo encabezados...
write:/ 'Aerolnea', '|', 'Vuelo','|',' Fecha
','|',
'
Precio
','
|','Moneda','|','
Ahorro
',
'|'.
" Escribo el contenido de mi tabla interna de salida...
loop at pt_salida into wa_salida.
write : / wa_salida-carrid,'
|',wa_salida-connid,' |',
wa_salida-fldate,'|', wa_salida-price,'| ',
wa_salida-currency,'|', wa_salida-ahorr, '|'.
" Limpio mi work area para no traer datos basura en la siguiente
" vuelta.
clear wa_salida.
endloop.
" Si se traen sugerencias, indicar que no se encontr lo que se busca
ba...
elseif pv_sug eq c_x.
write:/ 'Cliente', ':', p_nmbr.
write:/'Edad', ':', p_edad.
write: /.
write:'SIN DISPONIBILIDAD en aerolnea electa. Sugerencias de vuelo:'
.
write: /.
write:/ 'Aerolnea', '|', 'Vuelo','|',' Fecha
','|',
'
Precio
','
|','Moneda','|','
Ahorro
',
'|'.
loop at pt_salida into wa_salida.
write : / wa_salida-carrid,'
|',wa_salida-connid,' |',
wa_salida-fldate,'|', wa_salida-price,'| ',
wa_salida-currency,'|', wa_salida-ahorr, '|'.
" Limpio mi work area para no traer datos basura en la siguiente
" vuelta.
clear wa_salida.
endloop.
endif.
endform.
" FP_MOSTRAR
*&---------------------------------------------------------------------*
*&
Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
module status_0100 output.
set pf-status '0100'.
* SET TITLEBAR 'xxx'.
endmodule.
" STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*&
Module MOSTRAR_ALV OUTPUT
*&---------------------------------------------------------------------*
*
Se muestra en pantalla los vuelos disponibles segn las necesidades
*
del cliente, por medio de listado ALV.
*----------------------------------------------------------------------*
module mostrar_alv output.
if ob_container is not bound.
* Crea el custom container control para el control ALV
create object ob_container
exporting
container_name
= 'CC_ALV1'
exceptions
cntl_error
= 1
cntl_system_error
= 2
create_error
= 3
lifetime_error
= 4
lifetime_dynpro_dynpro_link = 5.
* Crea una instancia del control ALV
create object ob_alv_grid
exporting
i_parent = ob_container.
* Layout ALV
perform f_layout_alv.
* Carga el Catlogo de campos ALV
perform: f_fieldcat_alv.
endif.
* Ejecuto el ALV
call method ob_alv_grid->set_table_for_first_display
exporting
i_save
= c_a
is_layout
= wa_layout
*
is_variant
= wa_variant
changing
it_outtab
= it_salida
it_fieldcatalog = it_fieldcat.
*
it_sort
= gt_sort_alv.
* CALL METHOD cl_gui_control=>set_focus
*
EXPORTING
*
control = ob_alv_grid.
endmodule.
" MOSTRAR_ALV OUTPUT
*&---------------------------------------------------------------------*
*&
Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*
Indica las acciones a realizar con los comandos EXIT, CANCEL Y BACK
*
del Status GUI correspondiente a Dynpro 0100.
*----------------------------------------------------------------------*
module user_command_0100 input.
if
sy-ucomm eq 'EXIT'
or sy-ucomm eq 'CANCEL'
or sy-ucomm eq 'BACK'.
set screen 0.
leave screen.
endif.
endmodule.
" USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*&
Form F_LAYOUT_ALV
*&---------------------------------------------------------------------*
* Indica que "formato" que manejar mi ALV Grid.
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
form f_layout_alv .
wa_layout-zebra = c_x.
wa_layout-cwidth_opt = c_x.
wa_layout-frontend = c_x.
endform.
" F_LAYOUT_ALV
*&---------------------------------------------------------------------*
*&
Form F_FIELDCAT_ALV
*&---------------------------------------------------------------------*
* Se alimenta tabla interna de "catlogo de campos" para nuestro ALV.
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
form f_fieldcat_alv .
" se limpian las variables con las que se trabajarn
refresh it_fieldcat.
clear wa_fieldcat.
" Se comienza a alimentar nuestro "catlogo de campos" para el ALV...
wa_fieldcat-tabname
= 'IT_SALIDA'.
wa_fieldcat-fieldname = 'CARRID'.
wa_fieldcat-ref_table = 'SFLIGHT'.
wa_fieldcat-ref_field = 'CARRID'.
wa_fieldcat-col_opt
= c_x.
append wa_fieldcat to it_fieldcat.
clear wa_fieldcat.
wa_fieldcat-tabname
wa_fieldcat-fieldname
wa_fieldcat-ref_table
wa_fieldcat-ref_field
=
=
=
=
'IT_SALIDA'.
'CONNID'.
'SFLIGHT'.
'CONNID'.
wa_fieldcat-col_opt
= c_x.
append wa_fieldcat to it_fieldcat.
clear wa_fieldcat.
wa_fieldcat-tabname
= 'IT_SALIDA'.
wa_fieldcat-fieldname = 'CARRNAME'.
wa_fieldcat-ref_table = 'SCARR'.
wa_fieldcat-ref_field = 'CARRNAME'.
wa_fieldcat-col_opt
= c_x.
append wa_fieldcat to it_fieldcat.
clear wa_fieldcat.
wa_fieldcat-tabname
= 'IT_SALIDA'.
wa_fieldcat-fieldname = 'FLDATE'.
wa_fieldcat-ref_table = 'SFLIGHT'.
wa_fieldcat-ref_field = 'FLDATE'.
wa_fieldcat-col_opt
= c_x.
append wa_fieldcat to it_fieldcat.
clear wa_fieldcat.
wa_fieldcat-tabname
= 'IT_SALIDA'.
wa_fieldcat-fieldname = 'PRICE'.
wa_fieldcat-ref_table = 'SFLIGHT'.
wa_fieldcat-ref_field = 'PRICE'.
wa_fieldcat-col_opt
= c_x.
append wa_fieldcat to it_fieldcat.
clear wa_fieldcat.
wa_fieldcat-tabname
= 'IT_SALIDA'.
wa_fieldcat-fieldname = 'CURRENCY'.
wa_fieldcat-ref_table = 'SFLIGHT'.
wa_fieldcat-ref_field = 'CURRENCY'.
wa_fieldcat-col_opt
= c_x.
append wa_fieldcat to it_fieldcat.
clear wa_fieldcat.
wa_fieldcat-tabname
= 'IT_SALIDA'.
wa_fieldcat-fieldname = 'AHORR'.
* wa_fieldcat-ref_table = 'SFLIGHT'.
* wa_fieldcat-ref_field = 'CONNID'.
wa_fieldcat-scrtext_l = 'Ahorro'.
wa_fieldcat-scrtext_m = 'Ahorro'.
wa_fieldcat-scrtext_s = 'Ahorro'.
wa_fieldcat-col_opt
= c_x.
append wa_fieldcat to it_fieldcat.
clear wa_fieldcat.
endform.
" F_FIELDCAT_ALV
*&---------------------------------------------------------------------*
*&
Form FP_LEE_SCARR
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
*
<--P_IT_SCARR text
*
<--P_GV_OK text
*----------------------------------------------------------------------*
form fp_lee_scarr
using pt_flight type tt_sflight
changing pt_scarr type tt_scarr.
refresh pt_scarr[].
select carrid
carrname
from scarr
into table pt_scarr
for all entries in pt_flight
where carrid = pt_flight-carrid.
endform.
" FP_LEE_SCARR
*&---------------------------------------------------------------------*
*&
Form FP_LEE_SPFLI
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
*
-->P_IT_FLIGHT text
*
<--P_IT_SPFLI text
*----------------------------------------------------------------------*
form fp_lee_spfli using
pt_flight type tt_sflight
changing pt_spfli type tt_spfli.
refresh pt_spfli[].
select carrid
connid
countryfr
cityfrom
airpfrom
countryto
cityto
airpto
fltime
deptime
arrtime
from spfli
into table pt_spfli
for all entries in pt_flight
where carrid eq pt_flight-carrid
and connid eq pt_flight-connid.
endform.
" FP_LEE_SPFLI
---------------------------------------------------------------*
include znsfer_alv_top.
include znsfer_alv_s01.
include znsfer_alv_f01.
initialization.
start-of-selection.
perform fp_leer_tablas.
perform fp_armar_datos.
perform fp_obtener_carrname.
perform fp_validaciones.
"PERFORM FP_IMPRIME_DATOS."IMPRIME DATOS CON WRITE
perform fp_alv. "imprime datos con ALV DE FUNCIONES.
*&---------------------------------------------------------------------*
*& Include ZNSFER_ALV_TOP
Report ZNSFE
R_ALV
*&
*&---------------------------------------------------------------------*
report
znsfer_alv.
*Declaramos las tablas que vamos a leer.
tables:
sflight,
scarr.
" Declaramos los tipos de datos
types:
begin of ty_str_sflight,
carrid
type sflight-carrid,
connid type sflight-connid,
fldate
type sflight-fldate,
price
type sflight-price,
currency type sflight-currency,
seatsmax type sflight-seatsmax,
type
type
type
type
type
type
type
type
ty_st_sflight,
ty_st_sflight,
ty_st_sflight,
ty_str_sflight,
ty_st_scarr,
sflight-price,
sflight-price,
ty_str_scarr.
" Declaramos las Variables que necesitamos para la creacin de ALV DE FUN
CIONES.
data: it_fieldcat type slis_t_fieldcat_alv,
wa_fieldcat type slis_fieldcat_alv,
header_text(20) type c.
*&---------------------------------------------------------------------*
*& Include
ZNSFER_ALV_S01
*&---------------------------------------------------------------------*
" Parametros que vamos a utilizar
parameters:
pa_nom(10) type c,
pa_edad(2) type n,
pa_id
type sflight-carrid.
select-options
s_fldate for sflight-fldate.
*&---------------------------------------------------------------------*
*& Include
ZNSFER_ALV_F01
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&
Form FP_LEER_TABLAS
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
*En este perfor vamos a hacer la lectura de las tablas que utilizaremos
* a la B.D y las colocaremos en nuestras tablas internas para trabajar.
form fp_leer_tablas .
refresh: it_sflight[],
it_scarr[].
select carrid
connid
fldate
price
currency
seatsmax
seatsocc
from sflight
into table it_sflight
where carrid = pa_id and fldate in s_fldate.
if sy-subrc = 0.
select carrid
carrname
from scarr
into table it_scarr
for all entries in it_sflight
where carrid = it_sflight-carrid.
else.
perform fp_sugerencia.
message 'NO HAY VUELOS DISPONIBRES EN LA AEROLINEA SELECCIONADA,LE DA
MOS LAS SIGUIENTES SUJERENCIAS:' type 'I'.
endif.
endform.
" FP_LEER_TABLAS
*&---------------------------------------------------------------------*
*&
Form FP_ARMAR_DATOS
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
form fp_armar_datos .
if
endform.
" FP_ARMAR_DATOS
*&---------------------------------------------------------------------*
*&
Form FP_OBTENER_CARRNAME
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
form fp_obtener_carrname .
data:
lv_tabix type sy-tabix.
loop at it_sflight2 into wa_sflight.
lv_tabix = sy-tabix.
read table it_scarr into wa_scarr
with key carrid = wa_sflight-carrid
binary search.
if sy-subrc = 0.
wa_sflight-carrname = wa_scarr-carrname.
endform.
" FP_OBTENER_CARRNAME
*&---------------------------------------------------------------------*
*&
Form FP_VALIDACIONES
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
form fp_validaciones .
loop at it_sflight2 into wa_sflight.
if pa_edad >= 60.
wa_sflight-ahorro = wa_sflight-price * gv_oper."- gv_resultado1.
wa_sflight-price = wa_sflight-price - wa_sflight-ahorro.
modify it_sflight2 from wa_sflight.
endif.
endloop.
endform.
" FP_VALIDACIONES
*&---------------------------------------------------------------------*
*&
Form FP_IMPRIME_DATOS
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
form fp_imprime_datos .
write:/ 'NOMBRE', ':', pa_nom.
write:/ 'EDAD', ':', pa_edad.
write:/ 'AEROLINEA', ':', pa_id.
write:/ .
write:/ ' CARRID
', '|','CONNID ','
,'|',
'SEATSMAX',' |','SEATSOCC','
'PRICE','
|'.
loop at
|', 'FLDATE','
|',
write: /
wa_sflight-carrid,'
|', wa_sflight-
|','CURRENCY'
connid, '
|',wa_sflight-fldate, '|',
wa_sflight-currency, '
|', wa_sflight-seatsmax, '|', wa_sflightseatsocc, ' |',wa_sflight-price,'|'.
endloop.
write:/.
write:/'Precio con el 20% de Descuento', ':', gv_resultado.
write:/'Su ahorro fue de', ':', gv_resultado1.
endform.
" FP_IMPRIME_DATOS
*&---------------------------------------------------------------------*
*&
Form FP_ALV
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
form fp_alv .
=
=
=
=
'CARRNAME'.
'AEROLINEA.'.
'C600'.
'IT_SFLIGHT2'.
from scarr
into table it_scarr
for all entries in it_sflight
where carrid = it_sflight-carrid.
endif.
endform.
" FP_SUGERENCIA
Orientado a objetos
*&---------------------------------------------------------------------*
report
znsfer_alvo.
*Declaramos las tablas que vamos a leer.
tables:
sflight,
scarr,
spfli.
" Declaramos los tipos de datos
types:
begin of ty_str_sflight,
carrid
type sflight-carrid,
connid
type sflight-connid,
fldate
type sflight-fldate,
price
type sflight-price,
currency type sflight-currency,
it_sflight
it_sflight2
wa_sflight
it_scarr
gv_resultado
gv_resultado1
wa_scarr
it_spfli
wa_spfli
type
type
type
type
type
type
type
type
type
ty_st_sflight,
ty_st_sflight,
ty_str_sflight,
ty_st_scarr,
sflight-price,
sflight-price,
ty_str_scarr,
ty_st_spfli,
ty_str_spfli.
" Declaramos las Variables que necesitamos para la creacin de ALV OO.
data: it_fieldcat
wa_fieldcat
wa_layout
it_sort_alv
ob_container
ob_alv_grid
type
type
type
type
type
type
lvc_t_fcat,
lvc_s_fcat,
lvc_s_layo,
lvc_t_sort,
ref to cl_gui_custom_container,
ref to cl_gui_alv_grid.
*&---------------------------------------------------------------------*
*& Include
ZNSFER_ALVO_S01
*&---------------------------------------------------------------------*
" Parametros que vamos a utilizar
parameters:
pa_nom(10) type c,
pa_edad(2) type n,
pa_id
type sflight-carrid.
select-options
s_fldate for sflight-fldate.
form fp_leer_tablas .
clear gv_indi.
refresh: it_sflight[],
it_scarr[],
it_spfli[].
select carrid
connid
fldate
price
currency
from sflight
into table it_sflight
where carrid = pa_id and fldate in s_fldate.
if sy-subrc = 0.
select carrid
carrname
from scarr
into table it_scarr
for all entries in it_sflight
where carrid = it_sflight-carrid.
select carrid
connid
countryfr
cityto
airpto
fltime
deptime
arrtime
from spfli
into table it_spfli
for all entries in it_sflight
where carrid = it_sflight-carrid.
else.
perform fp_sugerencia.
gv_indi = 'X'.
message 'NO HAY VUELOS DISPONIBRES EN LA AEROLINEA SELECCIONADA,LE DA
MOS LAS SIGUIENTES SUJERENCIAS:' type 'I'.
endif.
endform.
" FP_LEER_TABLAS
*&---------------------------------------------------------------------*
*&
Form FP_ARMAR_DATOS
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
form fp_armar_datos .
if it_scarr[] is not initial.
loop at it_sflight into wa_sflight.
if wa_sflight-fldate in s_fldate.
append wa_sflight to it_sflight2.
endif.
endloop.
endif.
endform.
" FP_ARMAR_DATOS
*&---------------------------------------------------------------------*
*&
Form FP_OBTENER_CARRNAME
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
form fp_obtener_carrname .
data:
lv_tabix type sy-tabix.
loop at it_sflight into wa_sflight.
lv_tabix = sy-tabix.
move-corresponding wa_sflight to wa_salida.
read table it_scarr into wa_scarr
with key carrid = wa_sflight-carrid
binary search.
if sy-subrc = 0.
wa_salida-carrname = wa_scarr-carrname.
"MODIFY it_sflight2 FROM wa_sflight INDEX lv_tabix
"TRANSPORTING carrname.
endif.
read table it_spfli into wa_spfli
with key carrid = wa_sflight-carrid
binary search.
if sy-subrc = 0.
wa_salida-countryfr = wa_spfli-countryfr.
wa_salida-cityto = wa_spfli-cityto.
wa_salida-airpto = wa_spfli-airpto.
wa_salida-fltime = wa_spfli-fltime.
wa_salida-deptime = wa_spfli-deptime.
wa_salida-arrtime = wa_spfli-arrtime.
*
*
*
wa_sflight-carrname = wa_scarr-carrname.
MODIFY it_sflight2 FROM wa_sflight INDEX lv_tabix
TRANSPORTING carrname.
endif.
endloop.
endform.
" FP_VALIDACIONES
*&---------------------------------------------------------------------*
*&
Form FP_IMPRIME_DATOS
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
form fp_imprime_datos .
write:/ 'NOMBRE', ':', pa_nom.
write:/ 'EDAD', ':', pa_edad.
write:/ 'AEROLINEA', ':', pa_id.
write:/ .
write:/ ' CARRID
', '|','CONNID ','
|', 'FLDATE','
|','CURRENCY'
,'|',
'PRICE','
|'.
loop at
write: /
wa_sflight-carrid,'
|', wa_sflightconnid, '
|',wa_sflight-fldate, '|',
wa_sflight-currency, '
|', ' |',wa_sflight-price,'|'.
endloop.
write:/.
write:/'Precio con el 20% de Descuento', ':', gv_resultado.
write:/'Su ahorro fue de', ':', gv_resultado1.
endform.
" FP_IMPRIME_DATOS
*&---------------------------------------------------------------------*
*&
Module STATUS_0180 OUTPUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
module status_0180 output.
set pf-status '0180'. "No. de dympro que creamos
set titlebar 'VUELOS '.
endmodule.
" STATUS_0180 OUTPUT
*&---------------------------------------------------------------------*
*&
Module IMPRIMIR_ALVOO OUTPUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
module imprimir_alvoo output.
if ob_container is not bound.
"Crea el custom container control
create object ob_container
exporting
container_name
=
nuestro custom container
exceptions
cntl_error
=
cntl_system_error
=
create_error
=
lifetime_error
=
lifetime_dynpro_dynpro_link =
1
2
3
4
5.
"Ejecuto el ALV
call method ob_alv_grid->set_table_for_first_display
exporting
i_save
= 'x'
is_layout
= wa_layout
changing
it_outtab
= it_salida
it_fieldcatalog = it_fieldcat.
endmodule.
" IMPRIMIR_ALVOO OUTPUT
*&---------------------------------------------------------------------*
*&
Form F_LAYOUT_ALV
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
form f_layout_alv .
wa_layout-zebra = 'X'.
wa_layout-cwidth_opt = 'X'.
wa_layout-frontend = 'X'.
endform.
" F_LAYOUT_ALV
*&---------------------------------------------------------------------*
*&
Form F_FIELDCAT_ALV
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
form f_fieldcat_alv .
" se limpian las variables con las que se trabajarn
refresh it_fieldcat.
clear wa_fieldcat.
" Se comienza a alimentar nuestro "catlogo de campos" para el ALV...
wa_fieldcat-tabname
= 'IT_SALIDA'. "Nombre de nuestra tabla interna
wa_fieldcat-fieldname = 'CARRID'.
"nombre de nuestro campo
wa_fieldcat-ref_table = 'SFLIGHT'.
"Nombre de la Tabla referencia
wa_fieldcatref_field = 'CARRID'.
"Nombre del campo de referencia.
append wa_fieldcat to it_fieldcat.
clear wa_fieldcat.
wa_fieldcat-tabname
= 'IT_SALIDA'.
wa_fieldcat-fieldname = 'CONNID'.
wa_fieldcat-ref_table = 'SFLIGHT'.
wa_fieldcat-ref_field = 'CONNID'.
append wa_fieldcat to it_fieldcat.
clear wa_fieldcat.
wa_fieldcat-tabname
= 'IT_SALIDA'.
wa_fieldcat-fieldname = 'FLDATE'.
wa_fieldcat-ref_table = 'SFLIGHT'.
wa_fieldcat-ref_field = 'FLDATE'.
append wa_fieldcat to it_fieldcat.
clear wa_fieldcat.
wa_fieldcat-tabname
= 'IT_SALIDA'.
wa_fieldcat-fieldname = 'CURRENCY'.
wa_fieldcat-ref_table = 'SFLIGHT'.
wa_fieldcat-ref_field = 'CURRENCY'.
append wa_fieldcat to it_fieldcat.
clear wa_fieldcat.
wa_fieldcat-tabname
= 'IT_SALIDA'.
wa_fieldcat-fieldname = 'PRICE'.
wa_fieldcat-ref_table = 'SFLIGHT'.
wa_fieldcat-ref_field = 'PRICE'.
append wa_fieldcat to it_fieldcat.
clear wa_fieldcat.
wa_fieldcat-tabname
= 'IT_SALIDA'.
wa_fieldcat-fieldname = 'AHORRO'.
wa_fieldcat-scrtext_l = 'Ahorro'.
wa_fieldcat-scrtext_m = 'Ahorro'.
wa_fieldcat-scrtext_s = 'Ahorro'.
append wa_fieldcat to it_fieldcat.
clear wa_fieldcat.
endform.
" F_FIELDCAT_ALV
*&---------------------------------------------------------------------*
*&
Module USER_COMMAND_0180 INPUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
module user_command_0180 input.
if
sy-ucomm eq 'EXIT'
or sy-ucomm eq 'CANCEL'
or sy-ucomm eq 'BACK'.
set screen 0.
leave screen.
endif.
endmodule.
" USER_COMMAND_0180 INPUT
*&---------------------------------------------------------------------*
*&
Form FP_SUGERENCIA
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
form fp_sugerencia .
refresh: it_sflight[],
it_scarr[],
it_spfli[].
select carrid
connid
fldate
price
currency
from sflight
into table it_sflight
where fldate in s_fldate.
if sy-subrc = 0.
select carrid
carrname
from scarr
into table it_scarr
for all entries in it_sflight
where carrid = it_sflight-carrid.
select carrid
connid
countryfr
cityto
airpto
fltime
deptime
arrtime
from spfli
into table it_spfli
endform.
" FP_SUGERENCIA
include: z_alv2b_top,
" global Data
z_alv2b_s01,
z_alv2b_f01." FORM-Routines
start-of-selection.
perform lectura_datos.
perform validaciones.
perform alv.
*&---------------------------------------------------------------------*
*& Include Z_ALV2B_TOP
Report Z_ALV
_2B
*&
*&---------------------------------------------------------------------*
report
z_alv_2b.
tables: spfli, sflight.
data :
gv_resultado1
gv_resultado
type sflight-price,
type sflight-price.
gt_sflight occurs 0,
sflight-carrid,
sflight-connid,
sflight-fldate,
*&---------------------------------------------------------------------*
*& Include
Z_ALV2B_S01
*&---------------------------------------------------------------------*
selection-screen begin of block b1 with frame title text001. "definen un bloque en la actual pantalla de seleccin
parameters: pa_nom(10) type c,
pa_edad(2) type n.
selection-screen end of block b1.
selection-screen begin of
select-options : s_carrid
s_connid
s_fldate
*&---------------------------------------------------------------------*
*& Include
Z_ALV2B_F01
*&--------------------------------------------------------------------*
*&--------------------------------------------------------------------*
*&
Form LECTURA_DATOS
*&--------------------------------------------------------------------*
*
text
*---------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*---------------------------------------------------------------------*
form lectura_datos.
clear: gt_sflight[],
gt_spfli[],
gt_salida[].
select carrid
connid
fldate
price
currency
from
sflight
into corresponding fields of table gt_sflight
where carrid in s_carrid and connid in s_connid
and fldate in s_fldate.
loop at gt_sflight.
move-corresponding gt_sflight to wa_salida.
select
countryfr
cityto
airpto
deptime
arrtime
into gt_spfli
from spfli.
move-corresponding gt_spfli to wa_salida.
append wa_salida to gt_salida.
endselect.
endloop.
endform.
" LECTURA_DATOS
*&--------------------------------------------------------------------*
*&
Form VALIDACIONES
*&--------------------------------------------------------------------*
*
text
*---------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*---------------------------------------------------------------------*
form validaciones .
if gt_salida[] is not initial . "Si la tabla contiene datos, re
corre la tabla interna.
loop at gt_salida into wa_salida .
*
"Si la edad ingresada es mayor o igual de 60, tendr un 20%
de descuento.
if pa_edad >= 60.
*
gv_resultado1 = wa_sflight-price * '0.20'.
wa_salida-ahorro = wa_salida-price * pr.
wa_salida-price = wa_salida-price - wa_salida-ahorro.
"wa_salida-price = wa_salida-price - wa_salida-price."gv_resultado1.
modify gt_salida from wa_salida.
endif.
endloop.
*
"si la tabla no contiene informacin deseada, manda un mensaje
informativo.
elseif sy-subrc ne 0.
message 'No hay vuelos disponibles en esa fecha seleccione otra
' type 'I'.
endif.
endform.
" VALIDACIONES
*&--------------------------------------------------------------------*
*&
Form ALV
*&--------------------------------------------------------------------*
*
text
*------------------------------------------------------------------
----*
* --> p1
text
* <-- p2
text
*---------------------------------------------------------------------*
form alv .
if gt_salida[] is not initial.
"CL_SALV_TABLE. Con ella podemos contruirnos un informe con tan sol
o llamar a un mtodo el factory y luego al displa
cl_salv_table=>factory(
importing
r_salv_table = lv_alv_object
changing
t_table = gt_salida
).
g_functions = lv_alv_object->get_functions( ).
g_functions->set_all( abap_true ).
lv_columns = lv_alv_object->get_columns( ).
lv_columns->set_optimize( 'X' ).
gr_display = lv_alv_object->get_display_settings( ).
gr_display->set_striped_pattern( cl_salv_display_settings=>true ).
gr_display->set_list_header( 'Vuelos y precios' ).
** Visualizamos el ALV
lv_alv_object->display( ).
else.
message 'No tiene itinerario' type 'I'.
endif.
endform.
" ALV
rbol
REPORT demo_free_selections.
PARAMETERS dbtab TYPE tabname DEFAULT 'SPFLI'.
CLASS demo DEFINITION.
PUBLIC SECTION.
CLASS-METHODS main.
PRIVATE SECTION.
CLASS-METHODS check_existence_and_authority
RETURNING value(checked_dbtab) TYPE tabname.
ENDCLASS.
CLASS demo IMPLEMENTATION.
METHOD main.
DATA selid
TYPE rsdynsel-selid.
DATA field_tab TYPE TABLE OF rsdsfields.
DATA table_tab TYPE TABLE OF rsdstabs.
DATA table
LIKE LINE OF table_tab.
DATA cond_tab TYPE rsds_twhere.
DATA dref
TYPE REF TO data.
DATA alv
TYPE REF TO cl_salv_table.
FIELD-SYMBOLS <table> TYPE STANDARD TABLE.
FIELD-SYMBOLS <cond> LIKE LINE OF cond_tab.
DATA checked_dbtab TYPE tabname.
checked_dbtab = demo=>check_existence_and_authority( ).
table-prim_tab = dbtab.
APPEND table TO table_tab.
CALL FUNCTION 'FREE_SELECTIONS_INIT'
EXPORTING
kind
= 'T'
IMPORTING
selection_id = selid
TABLES
tables_tab = table_tab
EXCEPTIONS
OTHERS
= 4.
IF sy-subrc <> 0.
MESSAGE 'Error in initialization' TYPE 'I' DISPLAY LIKE 'E'.
LEAVE PROGRAM.
ENDIF.
CALL FUNCTION 'FREE_SELECTIONS_DIALOG'
EXPORTING
selection_id = selid
title
= 'Free Selection'
as_window = ' '
IMPORTING
where_clauses = cond_tab
TABLES
fields_tab = field_tab
EXCEPTIONS
OTHERS
= 4.
IF sy-subrc <> 0.
MESSAGE 'No free selection created' TYPE 'I'.
LEAVE PROGRAM.
ENDIF.
READ TABLE cond_tab WITH KEY tablename = dbtab ASSIGNING <cond>.
IF sy-subrc <> 0.
MESSAGE 'Error in condition' TYPE 'I' DISPLAY LIKE 'E'.
LEAVE PROGRAM.
ENDIF.
CREATE DATA dref TYPE TABLE OF (checked_dbtab).
ASSIGN dref->* TO <table>.
TRY.
SELECT *
FROM (checked_dbtab)
INTO TABLE <table>
WHERE (<cond>-where_tab).
CATCH cx_sy_dynamic_osql_error.
MESSAGE 'Error in dynamic Open SQL' TYPE 'I' DISPLAY LIKE 'E'.
LEAVE PROGRAM.
ENDTRY.
TRY.
cl_salv_table=>factory(