Hoy me aprobado examen de certificación C_HANATEC_15
Ahora ademas de programas en ABAP on HANA también se administrar una sistema SAP HANA.
"La vida es como montar en bicicleta. Para mantener el equilibro hay que seguir pedaleando". Albert Einstein.![]() |
| Búsqueda secuencial en una tabla interna |
![]() |
| Tiempos de acceso a una tabla interna con 100.000 registros |
![]() |
| Búsqueda binaria del registro con valor 20 |
![]() |
| Búsqueda binaria ordenando antes la tabla interna |
![]() |
| Búsqueda binaria SIN ordenar antes la tabla interna |
![]() |
| Patrón Modelo Vista Controlador MVC |
REPORT zreport_clasico_abap.
* Definiciones de datos y estructuras globales
* Parametros de la pantalla de selección
STAR-OF-SELECTION.
PERFORM leer_pedidos_ventas.
PERFORM eliminar_bloqueados.
PERFORM display_alv.
END-OF-SELECTION.
FORM leer_pedidos_ventas.
* Código para leer datos de las tablas VBAK/VBAP
* Almacenar los datos en una tabla interna
ENDFORM.
FORM eliminar_bloqueados.
* Código para eliminar pedidos con clientes bloqueados
* Leer datos de alguna tabla KN**
* Eliminar registros de la tabla interna
ENDFORM.
FORM display_alv.
* Mostar la tabla interna por pantalla en un ALV (REUSE_ALV_GRID_DISPLAY)
ENDFORM.
FORM user_command USING pi_ucomm rs_selfield.
IF ( pi_ucomm EQ c_ucomm_save ).
PERFORM crear_entregas.
ENDIF.
ENDFORM.
FORM crear_entregas.
* Código para crear entregas de los pedidos seleccionados
ENDFORM
* Más y más subrutinas....
![]() |
| diagrama UML de la aplicación |
class ZCL_MODELO_DATOS definition public final create public .
public section.
types: BEGIN OF T_PARAM,
s_vbeln TYPE RANGE OF vbak-vbeln,
s_vbtyp TYPE RANGE OF vbak-vbtyp,
s_kunnr TYPE RANGE OF vbak-kunnr,
END OF t_param .
types: BEGIN OF T_PEDIDOS,
VBELN type vbak-vbeln,
posnr type vbap-posnr,
kunnr type vbak-kunnr,
name1 type kna1-name1,
matnr type vbap-matnr,
maktx type makt-maktx,
END OF t_pedidos .
types:
tt_pedidos type STANDARD TABLE OF t_pedidos with non-unique key TABLE_LINE.
methods LEER_PEDIDOS_VENTAS
importing
!IS_PARAM type T_PARAM.
methods ELIMINAR_BLOQUEADOS.
methods GET_LISTA_PEDIDOS.
returning
value(RT_LISTA) type TT_PEDIDOS .
methods CREAR_PEDIDOS.
protected section.
private section.
data ZTT_PEDIDOS type TT_PEDIDOS .
ENDCLASS.
CLASS ZCL_MODELO_DATOS IMPLEMENTATION.
method LEER_PEDIDOS_VENTAS.
"Código para leer la VBAK/VBAP segun parametros y rellenar la tabla ZTT_PEDIDOS
endmethod.
method ELIMINAR_BLOQUEADOS.
"Código para recorrer la tabla interna ZTT_PEDIDOS
"Eliminar clientes bloqueados consultando tablas KN**
endmethod.
method GET_LISTA_PEDIDOS.
rt_lista[] = ztt_pedidos
endmethod.
method CREAR_PEDIDOS.
"Algo de código para un LOOP a la tabla ZTT_PEDIDOS y crear las entregas
endmethod.
ENDCLASS.
REPORT ZREPORT_SE38.
DATA go_modelo_datos TYPE REF TO zcl_modelo_datos.
DATA ti_pedidos TYPE ztt_pedidos.
* Algunas definiciones de datos
* Parametros de la pantalla de seleccion
START-OF-SELECTION.
go_modelo_datos = NEW #( ).
go_modelo_datos->leer_pedidos_ventas( ).
go_modelo_datos->eliminar_bloqueados( ).
ti_pedido = go_modelo_datos-get_lista_pedidos( ).
perform display_alv.
END-OF-SELECTION.
FORM display_alv.
* Código para llamar a REUSE_ALV_GRID_DISPLAY
ENDFORM.
FORM user_command USING pi_ucomm rs_selfield.
IF ( pi_ucomm EQ c_ucomm_save ).
go_modelo_datos->crear_entregas( ).
ENDIF.
ENDFORM.
![]() |
| Diagrama entidad/relación de varias tablas de SAP |
| Modelo de datos y sus posibles implementaciones |
![]() |
| especificación Core Data Services |
![]() |
| Modelo de datos, implementación y consumo con CDS |
![]() |
| Data to core vs Code to data |
![]() |
| Operaciones aritméticas directamente en la sentencia SQL que se ejecutan a nivel de base de dato |
![]() |
| ABAP CDS, una única orden de transporte |
![]() |
| Algunas diferencias entre ABAP CDS y vistas de la transacción SE11 |
![]() |
| Nivel módulo SAP_BASIS |
![]() |
| vista ABAP CDS |
![]() |
| Vista ABAP CDS desde la transacción SE11 |
![]() |
| Consumición de la vista ABAP CDS |
![]() |
| Entradas de la tabla TADIR correspondientes a vistas CDS |
![]() |
| Nombre de la vista ABAP CDS en HANA y en el diccionario ABAP |
![]() |
try.
cl_salv_table=>factory(
importing
r_salv_table = gr_table
changing
t_table = ti_mara ).
gr_table->get_functions( )->set_all( if_salv_c_bool_sap=>true ). "TODOS los pulsadores estandard
* gr_table->get_functions( )->set_default( if_salv_c_bool_sap=>true ). "Solamente algunos puls estandard
gr_table->display( ).
catch cx_salv_msg into cx_salv.
* Gestionamos las excepciones que puedan suceder
gr_msg = cx_salv->get_text( ).
message gr_msg type 'E'.
catch cx_salv_not_found into cx_not_found.
gr_msg = cx_not_found->get_text( ).
message gr_msg type 'E'
endtry.
![]() |
| Toolbar estándar creada con el metodo set_all( if_salv_c_bool_sap=>true ) |
![]() |
| Toolbar estándar creada con el metodo set_default( if_salv_c_bool_sap=>true ) |
try.
cl_salv_table=>factory(
importing
r_salv_table = gr_table
changing
t_table = ti_mara ).
gr_table->set_screen_status( pfstatus = 'ZZSTATUS_001' "Nuestro STATUS GUI
report = sy-repid
set_functions = gr_table->c_functions_all ).
gr_table->display( ).
catch cx_salv_msg into cx_salv.
* Gestionamos las excepciones que puedan suceder
gr_msg = cx_salv->get_text( ).
message gr_msg type 'E'.
catch cx_salv_not_found into cx_not_found.
gr_msg = cx_not_found->get_text( ).
message gr_msg type 'E'
endtry.
*---------------------------------------------------------------------*
* CLASS class_handle_events DEFINITION
*---------------------------------------------------------------------*
* define a local class for handling events of cl_salv_table
*---------------------------------------------------------------------*
class class_handle_events definition.
public section.
methods:
on_user_command
for event added_function of cl_salv_events
importing e_salv_function. "e_salv_function es como el OK_CODE de las dynpros
endclass. "lcl_handle_events DEFINITION
*---------------------------------------------------------------------*
* CLASS lcl_handle_events IMPLEMENTATION
*---------------------------------------------------------------------*
* implement the events for handling the events of cl_salv_table
*---------------------------------------------------------------------*
class class_handle_events implementation.
method on_user_command.
case e_salv_function. "Contiene el cod. de funcion del pulsador seleccionado
WHEN 'GO_VBELN'. "mensaje por pantalla
MESSAGE "Esto es una prueba, funcion GO_VBELN" display like 'I'.
ENDCASE.
endmethod.
endclass. "lcl_handle_events IMPLEMENTATION
DATA r_handler_salv_table type REF TO class_handle_events.
try.
cl_salv_table=>factory(
importing
r_salv_table = gr_table
changing
t_table = ti_mara ).
gr_table->set_screen_status( pfstatus = 'ZZSTATUS_001' "Nuestro STATUS GUI
report = sy-repid
set_functions = gr_table->c_functions_all ).
* Creamos la instancia de la clase de eventos y registramos el evento on_user_command
CREATE OBJECT r_handler_salv_table.
set handler r_handler_salv_table->on_user_command for gr_table->get_event( ).
gr_table->display( ).
catch cx_salv_msg into cx_salv.
* Gestionamos las excepciones que puedan suceder
gr_msg = cx_salv->get_text( ).
message gr_msg type 'E'.
catch cx_salv_not_found into cx_not_found.
gr_msg = cx_not_found->get_text( ).
message gr_msg type 'E'
endtry.
![]() |
| STATUS GUI de nuestro ALV |
![]() |
| CL_SALV_TABLE con pulsadores a medida |
*&---------------------------------------------------------------------*
*& Report: ZZCL_SALV_TABLE_FULL_SCREEN
*& Autor : David Rueda Barrón
*&---------------------------------------------------------------------*
*& Creacion de ALV a pantalla completa con la clase CL_SALV_TABLE
*& Se añaden 3 pulsadores a medida con un STATUS GUI
*& La clase de eventos CLASS_HANDLE_EVENTS recoje los eventos
*&---------------------------------------------------------------------*
report zzcl_salv_table_full_screen.
*---------------------------------------------------------------------*
* CLASS class_handle_events DEFINITION
*---------------------------------------------------------------------*
* define a local class for handling events of cl_salv_table
*---------------------------------------------------------------------*
class class_handle_events definition.
public section.
methods:
on_user_command
for event added_function of cl_salv_events
importing e_salv_function. "e_salv_function es como el OK_CODE de las dynpros
endclass. "lcl_handle_events DEFINITION
*---------------------------------------------------------------------*
* CLASS lcl_handle_events IMPLEMENTATION
*---------------------------------------------------------------------*
* implement the events for handling the events of cl_salv_table
*---------------------------------------------------------------------*
class class_handle_events implementation.
method on_user_command.
case e_salv_function. "Contiene el cod. de funcion del pulsador seleccionado
WHEN 'GO_VBELN'. "mensaje por pantalla
MESSAGE 'Esto es una prueba, funcion GO_VBELN' TYPE 'I'.
WHEN 'GO_VF03'.
MESSAGE 'Esto es una prueba, funcion GO_VF03' TYPE 'I'.
WHEN 'GO_MM02'.
MESSAGE 'Esto es una prueba, funcion MM02' TYPE 'I'.
ENDCASE.
endmethod.
endclass. "lcl_handle_events IMPLEMENTATION
*---------------------------------------------------------------------*
* TIPOS, ESTRUCTURAS y VARIABLES GLOBALES
*---------------------------------------------------------------------*
types: begin of type_matnr,
matnr type mara-matnr,
maktx type makt-maktx,
mtart type mara-mtart,
matkl type mara-matkl,
meins type mara-meins,
end of type_matnr.
* Tabla interna con los datos del ALV
data ti_mara type standard table of type_matnr.
data gr_table type ref to cl_salv_table.
data r_handler_salv_table type REF TO class_handle_events.
*Variables globales para gestionar las excepciones
data gr_msg type string.
data cx_salv type ref to cx_salv_msg.
data cx_not_found TYPE ref to cx_salv_not_found.
*&---------------------------------------------------------------------*
*& START-OF-SELECTION
*&---------------------------------------------------------------------*
start-of-selection.
select m~matnr t~maktx m~mtart m~matkl m~meins
into corresponding fields of table ti_mara
from mara as m
inner join makt as t
on m~matnr eq t~matnr
and t~spras eq sy-langu.
try.
cl_salv_table=>factory(
importing
r_salv_table = gr_table
changing
t_table = ti_mara ).
catch cx_salv_msg into cx_salv.
* Gestionamos las excepciones que puedan suceder
gr_msg = cx_salv->get_text( ).
message gr_msg type 'E'.
endtry.
try.
* Registramos el status gui para el ALV
gr_table->set_screen_status( pfstatus = 'ZZSTATUS_001' "Nuestro STATUS GUI
report = sy-repid
set_functions = gr_table->C_FUNCTIONS_ALL ).
* Creamos la instancia de la clase de eventos y registramos el evento on_user_command
CREATE OBJECT r_handler_salv_table.
SET HANDLER r_handler_salv_table->on_user_command for gr_table->get_event( ).
catch cx_salv_msg into cx_salv.
gr_msg = cx_salv->get_text( ).
message gr_msg type 'E'.
catch cx_salv_not_found into cx_not_found.
gr_msg = cx_not_found->get_text( ).
message gr_msg type 'E'.
endtry.
gr_table->display( ).
![]() |
| Transacción SE24 -> Clase CL_SALV_COLUMN_TABLE |
*&---------------------------------------------------------------------*
*& Report: ZZCL_SALV_TABLE_FULL_SCREEN
*& Fecha : 29.07.2015
*& Autor : David Rueda Barrón
*&---------------------------------------------------------------------*
*& Creacion de ALV a pantalla completa con la clase CL_SALV_TABLE
*& Modificacion de los atributos de la columnas con las clases:
*& - CL_SALV_COLUMNS_TABLE
*& - CL_SALV_COLUMN_TABLE
*&---------------------------------------------------------------------*
report zzcl_salv_table_full_screen.
types: begin of type_matnr,
matnr type mara-matnr,
maktx type makt-maktx,
mtart type mara-mtart,
matkl type mara-matkl,
meins type mara-meins,
box type c,
end of type_matnr.
data: ti_mara type standard table of type_matnr.
data gr_table type ref to cl_salv_table. "Instancia de la clase
data gr_columns type ref to cl_salv_columns_table. "Para gestionar las columnas
data gr_column type ref to cl_salv_column_table. "Para gestionar atrb. de una columna
data cx_salv type ref to cx_salv_msg.
data cx_not_found TYPE ref to cx_salv_not_found.
data gr_msg type string.
*&---------------------------------------------------------------------*
*& START-OF-SELECTION
*&---------------------------------------------------------------------*
start-of-selection.
select m~matnr t~maktx m~mtart m~matkl m~meins
into corresponding fields of table ti_mara
from mara as m
inner join makt as t
on m~matnr eq t~matnr
and t~spras eq sy-langu.
try.
cl_salv_table=>factory(
importing
r_salv_table = gr_table
changing
t_table = ti_mara ).
catch cx_salv_msg into cx_salv.
* Gestionamos las excepciones que puedan suceder
gr_msg = cx_salv->get_text( ).
message gr_msg type 'E'.
endtry.
try.
gr_columns ?= gr_table->get_columns( ).
* gr_columns->set_optimize( 'X' ). "Optimizar automa. abcho de TODAS las columnas
* Cambiamos la descripción de la columna MATNR - MATERIAL
gr_column ?= gr_columns->get_column( 'MATNR' ).
gr_column->set_short_text( 'Cod.Mat.' ).
gr_column->set_medium_text( 'Cod. Material' ).
gr_column->set_long_text( 'Código Material SAP' ).
* Ocultamos la columna MTART - Tipo de material
gr_column ?= gr_columns->get_column( 'MTART' ).
gr_column->set_visible( value = if_salv_c_bool_sap=>false ).
* Cambiamos la longitud de la columnas:
* MAKTX descripción del material
* MATKL Grupo de articulos
gr_column ?= gr_columns->get_column( 'MAKTX' ).
gr_column->set_output_length( 30 ).
gr_column ?= gr_columns->get_column( 'MATKL' ).
gr_column->set_output_length( 20 ).
* Cambiamos la descripcion y formato de la columna box
gr_column ?= gr_columns->get_column( 'BOX' ).
gr_column->set_short_text( 'box' ).
gr_column->set_medium_text( 'Checkbox' ).
gr_column->set_long_text( 'Checkbox' ).
gr_column->set_cell_type( if_salv_c_cell_type=>checkbox ).
catch cx_salv_msg into cx_salv.
gr_msg = cx_salv->get_text( ).
message gr_msg type 'E'.
catch cx_salv_not_found into cx_not_found.
gr_msg = cx_not_found->get_text( ).
message gr_msg type 'E'.
endtry.
gr_table->display( ).
![]() |
| CL_SALV_TABLE con los atributos de las comunas modificados |
*&---------------------------------------------------------------------*
*& Report: ZZCL_SALV_TABLE_FULL_SCREEN
*& Fecha : 29.07.2015
*& Autor : David Rueda Barrón
*&---------------------------------------------------------------------*
*& Creacion de ALV a pantalla completa con la clase CL_SALV_TABLE
*&---------------------------------------------------------------------*
REPORT ZZCL_SALV_TABLE_FULL_SCREEN.
TYPES: BEGIN OF type_matnr,
matnr type mara-matnr,
maktx type makt-maktx,
MTART type mara-MTART,
MATKL type mara-matkl,
MEINS type mara-MEINS,
END OF type_matnr.
DATA: ti_mara type STANDARD TABLE OF type_matnr.
DATA gr_table type ref to cl_salv_table. "instancia de la clase
DATA cx_salv TYPE REF TO cx_salv_msg.
DATA gr_msg TYPE string.
*&---------------------------------------------------------------------*
*& START-OF-SELECTION
*&---------------------------------------------------------------------*
START-OF-SELECTION.
SELECT m~matnr t~maktx m~mtart m~matkl m~meins
INTO CORRESPONDING FIELDS OF TABLE ti_mara
FROM mara as m
INNER JOIN makt as t
ON m~matnr EQ t~matnr
AND t~spras EQ sy-langu.
try.
cl_salv_table=>factory(
importing
r_salv_table = gr_table
changing
t_table = ti_mara ).
catch cx_salv_msg INTO cx_salv.
* gestionamos las excepciones que puedan suceder
gr_msg = cx_salv->get_text( ).
MESSAGE gr_msg TYPE 'E'.
endtry.
gr_table->display( ).
![]() |
| CL_SALV_TABLE a pantalla completa |
*&---------------------------------------------------------------------* *& Report: ZZCL_SALV_TABLE_DYNPRO *& Fecha : 29.07.2015 *& Autor : David Rueda Barrón *&---------------------------------------------------------------------* *& Creación de ALV dentro de Dynpro con la clase CL_SALV_TABLEDATA ti_mara type STANDARD TABLE OF type_matnr.*&---------------------------------------------------------------------* REPORT ZZCL_SALV_TABLE_DYNPRO. TYPES: BEGIN OF type_matnr, matnr type mara-matnr, maktx type makt-maktx, MTART type mara-MTART, MATKL type mara-matkl, MEINS type mara-MEINS, END OF type_matnr.
DATA ok_code type sy-ucomm.
DATA gr_table TYPE REF TO cl_salv_table. "instancia de la clase
DATA gr_container TYPE REF TO cl_gui_custom_container. DATA cx_salv TYPE REF TO cx_salv_msg. DATA gr_msg TYPE string. *&---------------------------------------------------------------------* *& START-OF-SELECTION *&---------------------------------------------------------------------* START-OF-SELECTION. SELECT m~matnr t~maktx m~mtart m~matkl m~meins INTO CORRESPONDING FIELDS OF TABLE ti_mara FROM mara as m INNER JOIN makt as t ON m~matnr EQ t~matnr AND t~spras EQ sy-langu. CALL SCREEN 4001.
![]() |
| Doble click sobre el número de dynpro para crearla |
![]() |
| descripción de la dynpro |
![]() |
| OK_CODE para recoger el código de función de cada evento de la dynpro |
![]() |
| Códigos de funciones para el status de la dynpro 4001 |
![]() |
| Crear el modulo USER_COMMAND_4001 |
DATA wl_command TYPE sy-ucomm.
wl_command = ok_code.
clear ok_code.
CASE wl_command.
WHEN 'BACK' OR 'EXIT' OR 'CANCEL'.
SET SCREEN 0.
LEAVE SCREEN.
ENDCASE.
![]() |
| Añadimos un contenedor a la dynpro 4001 |
![]() |
| nuevo modulo PBO - SET_ALV |
if ( gr_container is not bound ).
* Si es la primera vez, instancia las clases y muestra los datos de la tabla
create object gr_container
exporting
container_name = 'ZCONTENEDOR_ALV'
exceptions
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5
others = 6.
if ( sy-subrc <> 0 ).
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
cl_salv_table=>factory(
exporting
r_container = gr_container
list_display = ' '
importing
r_salv_table = gr_table
changing
t_table = ti_mara ).
gr_table->display( ).
else.
* Si ya estan instanciadas las clases, pues refrescamso los datos de la pantalla
gr_table->refresh( ).
endif.
![]() |
| ALV con CL_SALV_TABLE dentro de una dynpro |