You are on page 1of 6

Ejemplo 1

--------class ZCL00_SINGLETON definition


public
final
create private .
public section.
*"* public components of class ZCL00_SINGLETON
*"* do not include other source files here!!!
class-methods CLASS_CONSTRUCTOR .
class-methods GET_SINGLETON
returning
value(RET_SINGLE) type ref to ZCL00_SINGLETON .
protected section.
*"* protected components of class ZCL00_SINGLETON
*"* do not include other source files here!!!
private section.
*"* private components of class ZCL00_SINGLETON
*"* do not include other source files here!!!
class-data R_SINGLETON type ref to ZCL00_SINGLETON .
ENDCLASS.

CLASS ZCL00_SINGLETON IMPLEMENTATION.


* <SIGNATURE>--------------------------------------------------------------------------------------+
* | Static Public Method ZCL00_SINGLETON=>CLASS_CONSTRUCTOR
* +------------------------------------------------------------------------------------------------+
* +-------------------------------------------------------------------------------------</SIGNATURE>
method CLASS_CONSTRUCTOR.
create OBJECT r_singleton.
endmethod.
* <SIGNATURE>--------------------------------------------------------------------------------------+
* | Static Public Method ZCL00_SINGLETON=>GET_SINGLETON
* +------------------------------------------------------------------------------------------------+
* | [<-()] RET_SINGLE
TYPE REF TO ZCL00_SINGLETON
* +-------------------------------------------------------------------------------------</SIGNATURE>
method GET_SINGLETON.
"ret_sinlge = r_singleton.
endmethod.
ENDCLASS.

Ejemplo 2
---------

REPORT Z00_PERSISTENT_SCARR.
data r_carrier TYPE REF TO zcl_00carrier.
data r_agent TYPE REF TO zca_00carrier.
r_agent = zca_00carrier=>agent.
try.
r_carrier = r_agent->create_persistent(
i_carrid = 'PER'
).
CATCH cx_root.
message 'Fehler aufgetreten - i.d.F. existierte die FG schon ' type 'I'.
ENDTRY.
r_carrier->set_carrname( i_carrname = 'Persistente Flugges').
r_carrier->set_url( 'http://persisial.de').
commit WORK.
write 'Programmende'.

Ejemplo 3
--------REPORT Z00_PERSISTENT_SCARR.
data r_carrier TYPE REF TO zcl_00carrier.
data r_agent TYPE REF TO zca_00carrier.
data gv_url type scarr-url.
r_agent = zca_00carrier=>agent.
TRY.
r_carrier = r_agent->get_persistent(
i_carrid = 'PER'
).
gv_url = r_carrier->get_url( ).

write: / 'Url des Objektes', gv_url.


CATCH cx_root.
MESSAGE 'Datensatz existiert nicht in der Tabelle SCARR' type 'I'.
ENDTRY.

" Schreiben eines Objektes in die Datenbanktabelle


*try.
*
* r_carrier = r_agent->create_persistent(
*
i_carrid = 'PER'
* ).
*
* CATCH cx_root.
*
message 'Fehler aufgetreten - i.d.F. existierte die FG schon ' type 'I'.
*
*ENDTRY.
*
*r_carrier->set_carrname( i_carrname = 'Persistente Flugges').
*r_carrier->set_url( 'http://persisial.de').
*
*commit WORK.
write 'Programmende'.

Ejemplo 4
--------REPORT Z00_AUSNAHME_1.
PARAMETERS: pa_int1 type i DEFAULT 20,
pa_int2 type i DEFAULT 5.
data erg type DECFLOAT16.
try.
erg = pa_int1 / pa_int2.
WRITE: 'Ergebnis:', erg.
CATCH cx_sy_zerodivide.
ENDTRY.

Ejemplo 5
--------REPORT Z00_AUSNAHME_1.
PARAMETERS: pa_int1 type i DEFAULT 20,
pa_int2 type i DEFAULT 5.
data erg type DECFLOAT16.
try.
erg = pa_int1 / pa_int2.
WRITE: 'Ergebnis:', erg.
CATCH cx_sy_arithmetic_error.
MESSAGE 'Fehler in Berechnungen' type 'S'.
* CATCH cx_sy_zerodivide.
*
MESSAGE 'Division durch 0' TYPE 'S'.
* CATCH cx_sy_arithmetic_overflow.
*
MESSAGE 'berlauf ' TYPE 'S'.
ENDTRY.

Ejemplo 6
--------REPORT z00_ausnahme_1.
PARAMETERS: pa_int1 TYPE i DEFAULT 20,
pa_int2 TYPE i DEFAULT 5.
DATA erg TYPE decfloat16.
try.
PERFORM berechnung.
CATCH cx_sy_arithmetic_error.
MESSAGE 'Fehler in Berechnung' type 'S'.
ENDTRY.

*&---------------------------------------------------------------------*

*&
Form berechnung
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
FORM berechnung RAISING cx_sy_arithmetic_error.
erg = pa_int1 / pa_int2.
WRITE: 'Ergebnis:', erg.
erg = pa_int1 ** pa_int2.
WRITE: / 'Ergebnis:', erg.
ENDFORM.

"berechnung

Ejemplo 7
---------

REPORT z00_ausnahme_1.
PARAMETERS: pa_int1 TYPE i DEFAULT 20,
pa_int2 TYPE i DEFAULT 5.
data r_error TYPE REF TO cx_root.
data ausnahmetext type string.
DATA erg TYPE decfloat16.
try.
PERFORM berechnung.
CATCH cx_root into r_error.
ausnahmetext = r_error->get_text( ).
MESSAGE ausnahmetext type 'S'.
" MESSAGE 'Fehler in Berechnung' type 'S'.
ENDTRY.

*&---------------------------------------------------------------------*
*&
Form berechnung
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
FORM berechnung RAISING cx_sy_arithmetic_error.

erg = pa_int1 / pa_int2.


WRITE: 'Ergebnis:', erg.
erg = pa_int1 ** pa_int2.
WRITE: / 'Ergebnis:', erg.
ENDFORM.

"berechnung

You might also like