Difference between revisions of "SAP ABAP CLASES"
From SapWiki
Line 60: | Line 60: | ||
i_data_tab = gt_t001 ).</nowiki> | i_data_tab = gt_t001 ).</nowiki> | ||
− | ==CONSTRUCTOR== | + | ==CONSTRUCTOR & EXCEPTIONS== |
− | <nowiki>REPORT ytest_solicitudes. | + | *&---------------------------------------------------------------------* |
+ | <nowiki>*& Report YTEST_SOLICITUDES | ||
+ | *& | ||
+ | *&---------------------------------------------------------------------* | ||
+ | *& | ||
+ | *& | ||
+ | *&---------------------------------------------------------------------* | ||
+ | |||
+ | REPORT ytest_solicitudes. | ||
CLASS cl_sol DEFINITION. | CLASS cl_sol DEFINITION. | ||
PUBLIC SECTION. | PUBLIC SECTION. | ||
− | METHODS: constructor IMPORTING i_iddocumento TYPE zidocumento, | + | METHODS: constructor IMPORTING i_iddocumento TYPE zidocumento |
− | + | EXCEPTIONS sol_no_existe, | |
− | + | aprobar EXPORTING e_subrc TYPE sy-subrc | |
+ | e_mensaje TYPE string. | ||
DATA gt_sol TYPE STANDARD TABLE OF zhr_solicitudes. | DATA gt_sol TYPE STANDARD TABLE OF zhr_solicitudes. | ||
Line 76: | Line 85: | ||
METHOD constructor. | METHOD constructor. | ||
SELECT * INTO TABLE gt_sol FROM zhr_solicitudes WHERE iddocumento = i_iddocumento. | SELECT * INTO TABLE gt_sol FROM zhr_solicitudes WHERE iddocumento = i_iddocumento. | ||
+ | IF sy-subrc <> 0. | ||
+ | RAISE sol_no_existe. | ||
+ | ENDIF. | ||
ENDMETHOD. | ENDMETHOD. | ||
Line 107: | Line 119: | ||
PARAMETERS p_id TYPE zidocumento. | PARAMETERS p_id TYPE zidocumento. | ||
+ | |||
START-OF-SELECTION. | START-OF-SELECTION. | ||
− | CREATE OBJECT g_sol EXPORTING i_iddocumento = p_id. | + | CREATE OBJECT g_sol |
+ | EXPORTING | ||
+ | i_iddocumento = p_id | ||
+ | EXCEPTIONS | ||
+ | sol_no_existe = 1. | ||
+ | IF sy-subrc <> 0. | ||
+ | WRITE:/ |Sol { p_id } no existe|. | ||
+ | RETURN. | ||
+ | ENDIF. | ||
g_sol->aprobar( IMPORTING e_subrc = DATA(l_subrc) | g_sol->aprobar( IMPORTING e_subrc = DATA(l_subrc) | ||
− | + | e_mensaje = DATA(l_mensaje) | |
). | ). | ||
WRITE:/ l_mensaje.</nowiki> | WRITE:/ l_mensaje.</nowiki> |
Revision as of 18:36, 7 April 2020
CLASS-METHODS
The CLASS-METHODS statement declares a static method meth. For the name meth, the naming conventions apply.
With the class component selector (=>), static methods can be used independently of objects. In static methods, the static components of the class or its superclasses can be accessed only if the component selector is not used.
REPORT ytest_clases. CLASS cl_gui DEFINITION. PUBLIC SECTION. CLASS-METHODS gui_download IMPORTING i_filename TYPE string i_data_tab TYPE STANDARD TABLE. ENDCLASS. CLASS cl_gui IMPLEMENTATION. METHOD gui_download. CALL FUNCTION 'GUI_DOWNLOAD' EXPORTING filename = i_filename TABLES data_tab = i_data_tab * FIELDNAMES = EXCEPTIONS file_write_error = 1 no_batch = 2 gui_refuse_filetransfer = 3 invalid_type = 4 no_authority = 5 unknown_error = 6 header_not_allowed = 7 separator_not_allowed = 8 filesize_not_allowed = 9 header_too_long = 10 dp_error_create = 11 dp_error_send = 12 dp_error_write = 13 unknown_dp_error = 14 access_denied = 15 dp_out_of_memory = 16 disk_full = 17 dp_timeout = 18 file_not_found = 19 dataprovider_exception = 20 control_flush_error = 21 OTHERS = 22. IF sy-subrc <> 0. * Implement suitable error handling here ENDIF. ENDMETHOD. ENDCLASS. DATA gt_t001 TYPE STANDARD TABLE OF t001. START-OF-SELECTION. SELECT * INTO TABLE gt_t001 FROM t001 UP TO 10 ROWS. cl_gui=>gui_download( EXPORTING i_filename = 'c:\temp\ytest_t001.txt' i_data_tab = gt_t001 ).
CONSTRUCTOR & EXCEPTIONS
- &---------------------------------------------------------------------*
*& Report YTEST_SOLICITUDES *& *&---------------------------------------------------------------------* *& *& *&---------------------------------------------------------------------* REPORT ytest_solicitudes. CLASS cl_sol DEFINITION. PUBLIC SECTION. METHODS: constructor IMPORTING i_iddocumento TYPE zidocumento EXCEPTIONS sol_no_existe, aprobar EXPORTING e_subrc TYPE sy-subrc e_mensaje TYPE string. DATA gt_sol TYPE STANDARD TABLE OF zhr_solicitudes. ENDCLASS. CLASS cl_sol IMPLEMENTATION. METHOD constructor. SELECT * INTO TABLE gt_sol FROM zhr_solicitudes WHERE iddocumento = i_iddocumento. IF sy-subrc <> 0. RAISE sol_no_existe. ENDIF. ENDMETHOD. METHOD aprobar. LOOP AT gt_sol INTO DATA(ls_sol) WHERE subty <> '0904'. ENDLOOP. IF sy-subrc <> 0. e_subrc = 4. e_mensaje = 'Solicitud de vacaciones que desea aprobar no existe.'. RETURN. ENDIF. *---- update Registro ls_sol-status_solicitud = '02'. UPDATE zhr_solicitudes FROM ls_sol. COMMIT WORK. e_subrc = sy-subrc. IF sy-subrc = 0. e_mensaje = 'Solicitud Aprobada con éxito'. ELSE. e_mensaje = 'Error al Aprobar solicitud'. ENDIF. ENDMETHOD. ENDCLASS. DATA g_sol TYPE REF TO cl_sol. PARAMETERS p_id TYPE zidocumento. START-OF-SELECTION. CREATE OBJECT g_sol EXPORTING i_iddocumento = p_id EXCEPTIONS sol_no_existe = 1. IF sy-subrc <> 0. WRITE:/ |Sol { p_id } no existe|. RETURN. ENDIF. g_sol->aprobar( IMPORTING e_subrc = DATA(l_subrc) e_mensaje = DATA(l_mensaje) ). WRITE:/ l_mensaje.