ABAP
Transcription
ABAP
ABAP Finding Appropriate Abstractions for Business Application Programming ABA P Horst Keller NetWeaver Foundation ABAP ABAP Finding Appropriate Abstractions for Business Application Programming ABA P Business Application Programming ABAP Runtime Environment ABAP Essential Concepts at one Glance ABAP Development ABAP Strong Points Conclusion © SAP 2008 / ABAP Introduction and Overview / Horst Keller / NW F ABAP / Page 2 ABAP Finding Appropriate Abstractions for Business Application Programming ABA P Business Application Programming ABAP Runtime Environment ABAP Essential Concepts at one Glance ABAP Development ABAP Strong Points Conclusion © SAP 2008 / ABAP Introduction and Overview / Horst Keller / NW F ABAP / Page 3 Business Application Programming – General Figure Presentation Layer Application Layer UI Application Programs System Persistence Layer © SAP 2008 / ABAP Introduction and Overview / Horst Keller / NW F ABAP / Page 4 System Tabular Data in Tables of a Central Relational Database Business Application Programming – The ABAP Way Presentation Layer Application Layer UI ABAP Programs ABAP Runtime Environment ABAP System Persistence Layer © SAP 2008 / ABAP Introduction and Overview / Horst Keller / NW F ABAP / Page 5 remote System Tabular Data in Tables of a Central relational Database ABAP Finding Appropriate Abstractions for Business Application Programming ABA P Business Application Programming ABAP Runtime Environment ABAP Essential Concepts at one Glance ABAP Development ABAP Strong Points Conclusion © SAP 2008 / ABAP Introduction and Overview / Horst Keller / NW F ABAP / Page 6 Business Application Programming – The ABAP Runtime Environment SAP GUI, HTTP ABAP Runtime Envrionment Hardware-, operating-system-, and database-independent platform (virtual machine) that provides Interfaces PROGRAM ... Server Management (Memory, Process, Task Handling) CLASS ... METHOD main. ... ENDMETHOD. ENDCLASS. Text Environment Locking and LUW Services … for ABAP programs. ABAP Program RFC, HTTP Native Database Commands © SAP 2008 / ABAP Introduction and Overview / Horst Keller / NW F ABAP / Page 7 ABAP Runtime Environment – Past to Present Classical ABAP - Reporting Classical Lists (Screen/Spool) _________________ _________________ _________________ _________________ _________________ _________________ _________________ _________________ _________________ _________________ _________________ _________________ _________________ _________________ _________________ _________________ _________________ _________________ _________________ _________________ _________________ _________________ _________________ _________________ _________________ _________________ _________________ _________________ _________________ _________________ _________________ _________________ _________________ _________________ _________________ _________________ _________________ _________________ _________________ _________________ _________________ _________________ _________________ _________________ _________________ _________________ _________________ _________________ _________________ _________________ _________________ _________________ _________________ _________________ _________________ _________________ Report Program SAP Basis REPORT abap_intro_classic_report. TABLES spfli. START-OF-SELECTION. WRITE text-lst. ULINE. GET spfli. WRITE: spfli-carrid, spfli-connid, spfli-cityfrom, spfli-cityto. END-OF-SELECTION. ULINE. R/3-System DEMO ABAP – Allgemeiner Berichts Aufbereitungs Prozessor © SAP 2008 / ABAP Introduction and Overview / Horst Keller / NW F ABAP / Page 8 ABAP Runtime Environment – Past to Present Classical ABAP - Transactions PROGRAM abap_intro_classic_transaction. Classical Dynpros Dialog Program SAP Basis R/3-System MODULE user_command_0100 INPUT. CASE sy-ucomm. WHEN 'EXECUTE'. SELECT * FROM sflight INTO CORRESPONDING FIELDS OF TABLE conn_tab WHERE carrid = demo_conn-carrid AND connid = demo_conn-connid. … ENDMODULE. MODULE user_command_0200 INPUT. CASE sy-ucomm. WHEN 'SAVE'. CALL FUNCTION 'UPDATE_SFLIGHT' EXPORTING flight_tab = conn_tab. COMMIT WORK. … ENDMODULE. DEMO ABAP – Advanced Business Application Programming © SAP 2008 / ABAP Introduction and Overview / Horst Keller / NW F ABAP / Page 9 ABAP Runtime Environment – Past to Present Modern ABAP – ABAP Objects Services Application Services Services NW AS ABAP Non-ABAP SOA – Service Oriented Architecture © SAP 2008 / ABAP Introduction and Overview / Horst Keller / NW F ABAP / Page 10 ABAP Runtime Environment – Past to Present Modern ABAP – NetWeaver Application Server ABAP Web Dynpro BSP ICF Taskhandler Dynpro Gateway CFW Dispatcher Enqueue ICM ABAP/ABAP Objects Open SQL XSLT/ST Native SQL SAP OS Data Base Interface NW AS ABAP Database © SAP 2008 / ABAP Introduction and Overview / Horst Keller / NW F ABAP / Page 11 OS RFC Interface ABAP Finding Appropriate Abstractions for Business Application Programming ABA P Business Application Programming ABAP Runtime Environment ABAP Essential Concepts at one Glance ABAP Development ABAP Strong Points Conclusion © SAP 2008 / ABAP Introduction and Overview / Horst Keller / NW F ABAP / Page 12 ABAP Language ABAP Essential Concepts at one Glance, Part 1 Exception Class PROGRAM abap_intro_essentials. CLASS cx_no_flights DEFINITION INHERITING FROM cx_static_check. ENDCLASS. Class Definition CLASS get_and_display_flights DEFINITION. PUBLIC SECTION. CLASS-METHODS main. PRIVATE SECTION. TYPES flight_tab TYPE HASHED TABLE OF sflight WITH UNIQUE KEY carrid connid fldate. CLASS-DATA self TYPE REF TO get_and_display_flights. METHODS: get_flights IMPORTING carrier TYPE sflight-carrid RETURNING value(flights) TYPE flight_tab RAISING cx_no_flights, display_flights IMPORTING flights TYPE flight_tab. ENDCLASS. DEMO © SAP 2008 / ABAP Introduction and Overview / Horst Keller / NW F ABAP / Page 13 Static Methods Type declaration Static Attributes Instance Methods ABAP Language ABAP Essential Concepts at one Glance, Part 2 Class Implementation CLASS get_and_display_flights IMPLEMENTATION. METHOD main. DATA: carrier TYPE sflight-carrid, my_flights TYPE flight_tab. CREATE OBJECT self. CALL FUNCTION 'REQUEST_CARRIER' IMPORTING carrier = carrier. TRY. my_flights = self->get_flights( carrier ). CATCH cx_no_flights. MESSAGE text-nof TYPE 'I' DISPLAY LIKE 'E'. RETURN. ENDTRY. self->display_flights( my_flights ). ENDMETHOD. Method Implementation Local Data Object Instantiation Function Call Method Call Exception Handling DEMO © SAP 2008 / ABAP Introduction and Overview / Horst Keller / NW F ABAP / Page 14 ABAP Language ABAP Essential Concepts at one Glance, Part 3 METHOD get_flights. SELECT * FROM sflight INTO TABLE flights WHERE carrid = carrier. IF sy-subrc <> 0. RAISE EXCEPTION TYPE cx_no_flights. ENDIF. ENDMETHOD. Open SQL Internal Table Exception Raising METHOD display_flights. DATA: display_tab TYPE STANDARD TABLE OF sflight, alv TYPE REF TO cl_salv_table, exc TYPE REF TO cx_salv_msg. TRY. display_tab = flights. cl_salv_table=>factory( IMPORTING r_salv_table = alv CHANGING t_table = display_tab ). alv->display( ). CATCH cx_salv_msg INTO exc. MESSAGE exc TYPE 'I' DISPLAY LIKE 'E'. RETURN. ENDTRY. ENDMETHOD. ENDCLASS. DEMO © SAP 2008 / ABAP Introduction and Overview / Horst Keller / NW F ABAP / Page 15 Global Classes External Method Call ABAP Finding Appropriate Abstractions for Business Application Programming ABA P Business Application Programming ABAP Runtime Environment ABAP Essential Concepts at one Glance ABAP Development ABAP Strong Points Conclusion © SAP 2008 / ABAP Introduction and Overview / Horst Keller / NW F ABAP / Page 16 ABAP Development ABAP Workbench ABAP Workbench © SAP 2008 / ABAP Introduction and Overview / Horst Keller / NW F ABAP / Page 17 Integrated Tool Environment for all Development Objects Server Side Development Change and Transport System Test Tools … ABAP Development ABAP Debugger © SAP 2008 / ABAP Introduction and Overview / Horst Keller / NW F ABAP / Page 18 Two Process Debugging ABAP Development ABAP Language - Keywords ABAP – Not really a Language for Esthets © SAP 2008 / ABAP Introduction and Overview / Horst Keller / NW F ABAP / Page 19 ABAP Development ABAP Language - Documentation F1 Comprehensive help for more than 700 ABAP keywords © SAP 2008 / ABAP Introduction and Overview / Horst Keller / NW F ABAP / Page 20 ABAP Finding Appropriate Abstractions for Business Application Programming ABA P Business Application Programming ABAP Runtime Environment ABAP Essential Concepts at one Glance ABAP Development ABAP Strong Points Conclusion © SAP 2008 / ABAP Introduction and Overview / Horst Keller / NW F ABAP / Page 21 ABAP Language ABAP Strong Points – Built-in Database Access Open SQL Native SQL EXEC SQL. SELECT ... FROM ... INTO ... WHERE ... GROUP BY ... HAVING ... ORDER BY ... SELECT ... CREATE TABLE ... EXECUTE PROCEDURE ... DML and DDL – Platform Dependent ENDEXEC. INSERT UPDATE MODIFY DELETE ... ... ... ... ADBC DATA: sql TYPE REF TO cl_sql_statement, stmt TYPE string. stmt = `SELECT ... `. DML – Platform Independent sql->execute_query( stmt ). DCL: Locking etc. is managed by other concepts © SAP 2008 / ABAP Introduction and Overview / Horst Keller / NW F ABAP / Page 22 ABAP Language ABAP Strong Points – Type Declarations and Typing (Web) Dynpro ____ TYPES local_type TYPE HASHED TABLE OF dbtab WITH UNIQUE KEY ... … FIELD DATA screen_field TYPE field. … ... DATA dbtab_wa TYPE dbtab. … DBTAB DATA dbtab_tab TYPE local_type. ABAP Dictionary METHODS meth IMPORTING para1 TYPE field EXPORTING para2 TYPE local_type. Database Tables © SAP 2008 / ABAP Introduction and Overview / Horst Keller / NW F ABAP / Page 23 ABAP Language ABAP Strong Points – The ABAP Type Zoo, Part 1 Types Objects Generic Types Data Types Data Objects data, any Elementary Daty Types Elementary Data Objects simple Fixed Length Static Data Objects c Text Fields d Date Fields n Numeric Text Fields t Time Fields csequence clike decfloat16/34 Decimal FltPt. f Binary Floating Point Numbers i Integers p Packed Numbers x Byte Fields Variable Length string © SAP 2008 / ABAP Introduction and Overview / Horst Keller / NW F ABAP / Page 24 numeric Dynamic Data Objects xstring decfloat Byte Strings Character Strings xsequence ABAP Language ABAP Strong Points – The ABAP Type Zoo, Part 2 Types Objects Data Types Data Objects data, any Complex Data Types Complex Data Objects Structured Types Structures Table Types Internal Tables any table Index Tables index table Standard Tables Sorted Tables Standard Tables Sorted Tables Hashed Tables Hashed Tables [standard] table sorted table hashed table Reference Types Reference Variables Data References Data Reference Variables Object References Object Reference Variables Class References Class Reference Variables Interface References Interface Reference Variables Object Types Classes object Objects Interfaces © SAP 2008 / ABAP Introduction and Overview / Horst Keller / NW F ABAP / Page 25 ABAP Language ABAP Strong Points – Handling Tables ____ Tables on Screens DATA itab TYPE ... TABLE OF … WITH ... KEY ... READ TABLE itab WITH TABLE KEY ... LOOP AT itab ... Tables in ABAP: ENDLOOP. Internal Tables INSERT ... INTO TABLE ... SELECT ... INTO TABLE ... ... Database Tables © SAP 2008 / ABAP Introduction and Overview / Horst Keller / NW F ABAP / Page 26 ABAP Language ABAP Strong Points – Internal Tables from Past to Present Three kinds of internal tables: Standard tables Sorted tables Hashed tables Tables of References Tables of any Type REPORT abap_intro_reference_table. DATA vehicle_tab TYPE TABLE OF REF TO cl_abap_intro_vehicle. DEMO Tables of Structures © SAP 2008 / ABAP Introduction and Overview / Horst Keller / NW F ABAP / Page 27 DO n TIMES. CREATE OBJECT vehicle. APPEND vehicle TO vehicle_tab. ENDDO. LOOP AT vehicle_tab INTO vehicle. vehicle->show_speed( ). ENDLOOP. ABAP Language ABAP Strong Points – Internal Tables with Secondary Keys L s! w Ne .1) t 7 s ate s e lea e (R REPORT demo_secondary_keys. DATA: itab TYPE HASHED TABLE OF example_data=>struc WITH UNIQUE KEY idx WITH NON-UNIQUE SORTED KEY k1 COMPONENTS name postal_code. READ TABLE jtab INTO wa WITH KEY k1 COMPONENTS name = ... postal_code = ... . Primary unique hashed key Secondary non-unique sorted key DEMO Access via secondary key © SAP 2008 / ABAP Introduction and Overview / Horst Keller / NW F ABAP / Page 28 ABAP Language ABAP Strong Points – String Processing REPORT abap_intro_regex. IF matches( val = email regex = `\w+(\.\w+)*@(\w+\.)+(\w{2,4})` case = abap_false ). ... ELSE. ... ENDIF. Example 1 Built-in Support for Regular Expressions DEMO REPORT abap_intro_string_expressions. Example 2 String Expressions with String Templates output( text-sym && |: { get_amount( ) + get_tax( ) STYLE = MONETARY CURRENCY = cur }| && | { cur ALIGN = LEFT }| ). ews! N t s e t La .1) se 7 (Relea © SAP 2008 / ABAP Introduction and Overview / Horst Keller / NW F ABAP / Page 29 DEMO ABAP Language ABAP Strong Points – Language Environment The language environment of an ABAP-Program comprises Text pool with language dependend text elements Text environment with language dependent Locale and System Code Page Format settings with country specific number, date, and time formats → Language Independent Development output = text-sym. Text Symbol, as an Example for Text Elements © SAP 2008 / ABAP Introduction and Overview / Horst Keller / NW F ABAP / Page 30 ABAP Language ABAP Strong Points – Built-in XML-Support REPORT abap_intro_xml_conversion. DATA: BEGIN OF carrier_wa, carrid TYPE scarr-carrid, carrname TYPE scarr-carrname, url TYPE scarr-url, END OF carrier_wa, carrier_tab LIKE TABLE OF carrier_wa, xml_xstring TYPE xstring. SELECT * FROM scarr INTO CORRESPONDING FIELDS OF TABLE carrier_tab. CALL TRANSFORMATION abap_intro_simple_trans SOURCE carriers = carrier_tab RESULT XML xml_xstring OPTIONS xml_header = 'NO'. cl_abap_browser=>show_xml( xml_xstring = xml_xstring ). cl_abap_browser=>show_html( html_xstring = xml_xstring buttons = 'X' check_html = ' ' ). DEMO © SAP 2008 / ABAP Introduction and Overview / Horst Keller / NW F ABAP / Page 31 <?sap.transform simple?> <tt:transform xmlns:tt="http://www.sap.com/transformation-templates"> <tt:root name="CARRIERS"/> <tt:template> <html> <body> <h2>Carriers:</h2> <table border="2"> <tr> <td><b>Id</b></td> <td><b>Name</b></td> <td><b>Homepage</b></td> </tr> <tt:loop ref=".CARRIERS"> <tr><td> <tt:value ref="$ref.carrid"/> </td> <td> <tt:value ref="$ref.carrname"/> </td> <td> <a><tt:attribute name="href" value-ref="$ref.url" /> <tt:value ref="$ref.url"/></a> </td> </tr> </tt:loop> </table> </body> </html> </tt:template> </tt:transform> Simple Transformation, Standard XSLT is also possible ABAP Language ABAP Strong Points – Dynamic Programming REPORT abap_intro_dynamic . DATA: type_descr struct_descr table_descr components table_ref TYPE REF TO cl_abap_typedescr, TYPE REF TO cl_abap_structdescr, TYPE REF TO cl_abap_tabledescr, TYPE cl_abap_structdescr=>component_table, TYPE REF TO data. FIELD-SYMBOLS <table> TYPE ANY TABLE. cl_abap_typedescr=>describe_by_name( EXPORTING p_name = dbtab RECEIVING p_descr_ref = type_descr ). RTTS Classes Data Reference Field Symbol components = ... struct_descr = cl_abap_structdescr=>create( components ). table_descr = cl_abap_tabledescr=>create( struct_descr ). CREATE DATA table_ref TYPE HANDLE table_descr. ASSIGN table_ref->* TO <table>. RTTC TRY. SELECT (cols) FROM (dbtab) INTO CORRESPONDING FIELDS OF TABLE <table> WHERE (where). CATCH cx_sy_sql_error INTO error. ... ENDTRY. DEMO © SAP 2008 / ABAP Introduction and Overview / Horst Keller / NW F ABAP / Page 32 RTTI Data Object Instantiation Dynamic Tokens ABAP Language ABAP Strong Points – Exception Handling CX_ROOT CX_STATIC_CHECK CX_DYNAMIC_CHECK CX_NO_CHECK CLASS cx_... DEFINITION INHERITING FROM cx_..._check. ... ENDCLASS. DATA oref TYPE cx_... METHODS method RAISING cx_... TRY. method( ... ). CATCH cx_... cx_... INTO oref. ... CLEANUP. ... ENDTRY. © SAP 2008 / ABAP Introduction and Overview / Horst Keller / NW F ABAP / Page 33 METHOD method. RAISE cx_... ENDMETHOD. e 7.1: Releas ceptions able Ex Resum ABAP Finding Appropriate Abstractions for Business Application Programming ABA P Business Application Programming ABAP Runtime Environment ABAP Essential Concepts at one Glance ABAP Development ABAP Strong Points Conclusion © SAP 2008 / ABAP Introduction and Overview / Horst Keller / NW F ABAP / Page 34 Conclusion ABAP meets the Demands of an Ever-Changing World … by an Ongoing Evolution! R/2 ABAP ABAP/4 ABAP Objects © SAP 2008 / ABAP Introduction and Overview / Horst Keller / NW F ABAP / Page 35 Unicode enabled Modern ABAP ABAP Finding Appropriate Abstractions for Business Application Programming ABA P THANK YOU FOR YOUR ATTENTION ! QUESTIONS – SUGGESTIONS © SAP 2008 / ABAP Introduction and Overview / Horst Keller / NW F ABAP / Page 36 – DISCUSSION