Abap Objects

The current incarnation of AbapLanguage, the language that most of the SAP R/3 system is written in (not the very core though), and which is used to write programs for SAP R/3.


Below is an example. Disclaimer: I never wrote production ABAP code, the example below is assembled from example code I was given when I had to learn ABAP at the university. The following code was never compiled, because I don't have access to an SAP R/3 system. Plus, in newer releases, they did something to the call syntax so that you can now optionally use a less cumbersome variant. That being said, the following should be good enough to demonstrate the flavor of ABAP...

 REPORT yexample.
 * Class that wraps a "boolean" value, assigning it in
 * the constructor and providing a getter. Plus, a "main"
 * program that uses the class.
 * In other words, a pointless syntax example ;)

TYPES: ty_boolean(1) TYPE c. CONSTANTS: co_true VALUE 'X', co_false VALUE SPACE.

CLASS bool_wrapper DEFINITION. PUBLIC SECTION. TYPES: ty_boolean(1) TYPE c. METHODS: constructor IMPORTING VALUE(im_bool) TYPE ty_boolean, get_bool RETURNING VALUE(re_bool) TYPE ty_boolean. PRIVATE SECTION. DATA: bool TYPE ty_boolean. ENDCLASS.

CLASS bool_wrapper IMPLEMENTATION. METHOD constructor. bool = im_bool. ENDMETHOD. METHOD get_bool. re_bool = bool. ENDMETHOD. ENDCLASS.

* "Main" program: DATA: a_wrapper TYPE REF TO bool_wrapper, bool TYPE ty_boolean. START-OF-SELECTION. CREATE OBJECT a_wrapper EXPORTING im_value = co_true. CALL METHOD a_wrapper->get_bool RECEIVING re_value = value. * "assigns" the value of "re_value" to "value" - from left to right IF ( value = co_true ). WRITE: / 'Got value true'. ELSE. WRITE: / 'Got value false'. ENDIF.

This, to my best knowledge, the equivalent to the following Java program:

 public class BooleanWrapper {
   private boolean value;
   public BooleanWrapper( boolean value ) {
     this.value = value;
   }
   public boolean getValue() {
     return value;
   }
   public static void main( String[] args ) {
     BooleanWrapper aWrapper = new BooleanWrapper( true );
     System.out.println( "Got value " + aWrapper.getValue() );
   }
 }
And some people think Java is too wordy...


...had to learn ABAP at the university...

You poor, poor soul; you HadToUseCobol.


CategoryProgrammingLanguage


EditText of this page (last edited February 10, 2009) or FindPage with title or text search