SAP ABAP CLASES
From SapWiki
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 ).
REDEFINITION
</nowiki>*----------------------------------------------------------------------*
- CLASS smart DEFINITION
- ----------------------------------------------------------------------*
- ----------------------------------------------------------------------*
CLASS cl_smart DEFINITION ABSTRACT.
PUBLIC SECTION.
METHODS set_parameters IMPORTING i_form TYPE tdsfname
i_control_parameters TYPE ssfctrlop
i_output_options TYPE ssfcompop.
METHODS get_otf EXPORTING e_otf TYPE tt_itcoo. METHODS get_errortab EXPORTING e_errortab TYPE tsferror.
- smartforms related
DATA: func_module_name TYPE rs38l_fnam,
control_parameters TYPE ssfctrlop,
output_options TYPE ssfcompop,
job_output_info TYPE ssfcrescl,
otf TYPE tt_itcoo,
errortab TYPE tsferror.
- data: pa_form type tdsfname .
- private section.
ENDCLASS. "smart DEFINITION
CLASS cl_smart_usuarios DEFINITION INHERITING FROM cl_smart.
PUBLIC SECTION. METHODS print EXPORTING e_subrc TYPE sy-subrc. METHODs get_errortab REDEFINITION.
ENDCLASS. "smart DEFINITION
- ----------------------------------------------------------------------*
- CLASS smart IMPLEMENTATION
- ----------------------------------------------------------------------*
- ----------------------------------------------------------------------*
CLASS cl_smart IMPLEMENTATION.
METHOD set_parameters.
- pa_form = i_form.
- determine the name of the generated function module for the SMartform
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = i_form
IMPORTING
fm_name = func_module_name
EXCEPTIONS
no_form = 1
no_function_module = 2
OTHERS = 3.
control_parameters = i_control_parameters.
output_options = i_output_options.
ENDMETHOD. "set_parameters
METHOD get_otf. e_otf[] = otf[]. ENDMETHOD.
METHOD get_errortab. e_errortab[] = errortab[]. ENDMETHOD.
ENDCLASS. "smart IMPLEMENTATION CLASS cl_smart_usuarios IMPLEMENTATION.
METHOD print.
- call the generated function module of the form
CALL FUNCTION func_module_name
EXPORTING
control_parameters = control_parameters
output_options = output_options
- user_settings = space
IMPORTING
job_output_info = job_output_info
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
my_exception = 5
OTHERS = 6.
e_subrc = sy-subrc.
IF sy-subrc <> 0.
- Implement suitable error handling here
- Transfer SF errors to internal table
CALL FUNCTION 'SSF_READ_ERRORS'
IMPORTING
errortab = errortab.
ENDIF.
otf[] = job_output_info-otfdata[].
ENDMETHOD. "print
METHOD get_errortab. e_errortab[] = errortab[]. ENDMETHOD.
ENDCLASS. "smart_usuarios IMPLEMENTATION</nowiki>
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.