Skip to content

Latest commit

 

History

History
192 lines (151 loc) · 16.2 KB

19_ABAP_for_Cloud_Development.md

File metadata and controls

192 lines (151 loc) · 16.2 KB

ABAP for Cloud Development

This ABAP cheat sheet briefly outlines the terms ABAP Cloud and classic ABAP to get an idea about ABAP for Cloud Development. It provides references to more detailed information on the topic.

Terms

  • ABAP Cloud
    • Progamming paradigm for state-of-the-art, cloud-ready and upgrade-stable solutions
    • ABAP technology (the entire technology provided for and by an ABAP system for developing and executing ABAP-based applications) is used with the following restrictions:
    • The ABAP RESTful Application Programming Model (RAP) is the transactional programming model for ABAP Cloud.
    • Supported in all SAP products that are based on ABAP technology (in the products it can be fully or partly mandatory).
  • Classic ABAP
    • Progamming paradigm for legacy solutions
    • Based on the ABAP technology without restrictions regarding ABAP language versions (i.e. you can use Standard ABAP - the unrestricted ABAP language version - and also ABAP for Cloud Development there), usage of tools (ADT and/or SAP GUI) or access to repository objects (also objects provided by SAP).
    • Supported in SAP S/4HANA

💡 Note

⬆️ back to top

Excursions

  1. If available to you, you have accessed an SAP BTP ABAP environment using ADT.

    Access to SAP-provided repository objects is restricted to objects that have been released for ABAP for Cloud Development (released APIs). You can find the released repository objects in the Project Explorer view in ADT under Released Objects:

    Released APIs

    As an example of a released API, consider the CL_ABAP_RANDOM_INT class (computes random integers). In ADT, once you have opened the class, check the Properties tab. Click API State on the left to display information about the release contracts. In this case, it is C1. As mentioned above, see here for more information on C1, and so on. This is also true for ABAP repository objects in classic ABAP.

    Release contract

    For deprecated and invalid syntax in ABAP for Cloud Development, refer to the following example code. You can create a demo class and insert the code below (adjust the class name if necessary). Several syntax errors and warnings will be displayed:

    • ABAP SQL statements
      • The first two ABAP SQL statements select from demo database tables. The first one is a demo table provided by SAP, but it cannot be accessed directly in ABAP Cloud like in classic ABAP. Therefore, it cannot be used as a data source for selection.
      • The second one is a database table from the ABAP cheat sheet GitHub repository. If you have imported the repository into the system, you can use it as a data source.
      • The CDS view is released and can be accessed in the restricted ABAP language scope.
      • Although the source code provides an invalid data source, the dynamic ABAP SQL statement does not produce a syntax error during compilation. However, it would result in a runtime error because you cannot select from that data source. You can check the validity of dynamic specifications using the cl_abap_dyn_prg class, which supports dynamic programming.
      • The addition USING CLIENT for client handling is not allowed in the restricted ABAP language scope.
    • When using APIs and types like string_table, ensure that they are released. The IF_OO_ADT_CLASSRUN interface is released, and you can implement it to run an ABAP class. In ADT, you can do this by choosing F9. However, the example class will not run because the class cannot be activated due to the syntax errors. To output the content of data objects, you can use out->write( ... ) in the main method.
    • The example includes a selection of deprecated and invalid syntax in ABAP for Cloud Development. It includes the invalid statement MOVE ... TO and others that are included for demonstration purposes (some alternatives are provided). Certain system fields should not be accessed. The pointless WRITE statement within the method implementation represents invalid classic ABAP UI-related statements. Executable programs (reports) are not allowed in the restricted ABAP language scope. To set breakpoints in ADT, double-click the area to the left of the code line number.
    CLASS zcl_some_class DEFINITION
          PUBLIC
          FINAL
          CREATE PUBLIC .
    
      PUBLIC SECTION.
        INTERFACES if_oo_adt_classrun.
    ENDCLASS.
    
    CLASS zcl_some_class IMPLEMENTATION.
      METHOD if_oo_adt_classrun~main.
        "ABAP SQL statements
        "Using database tables and CDS views as data sources
        SELECT carrid, connid FROM spfli WHERE carrid = 'LH' INTO TABLE @DATA(it1).
        SELECT carrid, connid FROM zdemo_abap_fli WHERE carrid = 'LH' INTO TABLE @DATA(it2).
        SELECT SINGLE * FROM i_timezone WHERE TimeZoneID = 'EST' INTO @DATA(tz_info).
        "Dynamic ABAP SQL statements
        SELECT SINGLE carrid, connid FROM ('SPFLI') WHERE carrid = 'LH' INTO NEW @DATA(ref_a).
        SELECT SINGLE carrid, connid FROM ('ZDEMO_ABAP_FLI') WHERE carrid = 'LH' INTO NEW @DATA(ref_b).
        "ABAP SQL Statement involving client handling
        DATA(clnt) = sy-mandt.
        SELECT carrid, connid FROM zdemo_abap_fli USING CLIENT @clnt WHERE carrid = 'LH' INTO TABLE @DATA(it3).
    
        "(Not) released APIs
        "Getting a random integer
        DATA(random_num) = cl_abap_random_int=>create( seed = cl_abap_random=>seed( )
                                                      min  = 1
                                                      max  = 100 )->get_next( ).
    
        "Possible alternatives to the system fields used below
        DATA(sys_date) = cl_abap_context_info=>get_system_date( ).
        DATA(sys_time) = cl_abap_context_info=>get_system_time( ).
    
        "Querying whether the current database supports AMDP methods
        DATA(amdp_allowed) = xsdbool( cl_abap_dbfeatures=>use_features(
          EXPORTING requested_features = VALUE #( ( cl_abap_dbfeatures=>call_amdp_method ) ) ) ).
    
        "Examples for deprecated and invalid syntax in ABAP for Cloud Development
        DATA(num1) = 1.
        DATA(num2) = 1.
        DATA(num3) = 2.
        MOVE num3 TO num1.
        num2 = num3.
    
        DATA(it4) = VALUE string_table( ( `a` ) ( `b` ) ( `c` ) ).
        DESCRIBE TABLE it4 LINES DATA(num_lines1).
        DATA(num_lines2) = lines( it4 ).
    
        DATA: ref1 TYPE REF TO i,
              ref2 TYPE REF TO i.
    
        GET REFERENCE OF num1 INTO ref1.
        ref2 = REF #( num1 ).
    
        DATA(current_time) = sy-uzeit.
        DATA(current_date) = sy-datum.        
    
        DATA str_itab TYPE string_table.
        READ REPORT 'ZCL_DEMO_ABAP_UNIT_TEST=======CCAU' INTO str_itab.
        WRITE 'hi'.
        BREAK-POINT.
      ENDMETHOD.
    ENDCLASS.
  2. If available to you, you have accessed an on-premise ABAP system using ADT. It is assumed that the latest ABAP release is available.

    a) Checking API status information

    • Choose CTRL + SHIFT + A to open the search in ADT. Search the class CL_ABAP_RANDOM_INT. Once you have opened the class, check the Properties tab and find the API status information.

    b) Creating an example class

    • Create a global class and insert the code from above. Depending on the name of the class you created, replace the class name in the snippet. For the example class created, check the information in the Properties tab. Choose General. The ABAP Language Version is maintained as Standard ABAP: Standard ABAP
    • If you have not imported the ABAP cheat sheet GitHub repository, remove the lines of code using artifacts from that repository, i.e. remove the statements using objects starting with Z.... You should not see any syntax errors. Activate the class.
    • Run the class with F9. The code should have been processed up to the BREAK-POINT statement and the debugger should have started. You may want to check the content of the variables in the debugger. Choose Terminate to exit the debugger.
    • So, unlike in the case of ABAP Cloud above, you should be able to activate and run the code (which does not represent a meaningful code example).

    c) Verifying cloud-readiness of your code in classic ABAP

    • You have walked through b), created a class, inserted the code from above, and activated the class. The ABAP Language Version is maintained as Standard ABAP in the Properties tab.
    • Verifying if your code is cloud-ready
      • You can use ATC check variant ABAP_CLOUD_READINESS for this purpose.
      • For example, in your class, right-click and choose Run As4 ABAP Test Cockpit With.... Enter ABAP_CLOUD_READINESS in the pop-up window and choose Ok. The ATC check run is started.
      • As a result of the ATC check run (note that it may take a while to complete), the ATC Problems tab in ADT should display results. In this case, these are the errors and warnings mentioned above, indicating that the code is not cloud-ready in various places. Double-click on the findings for more detailed information.

    d) Cloud-ready development in classic ABAP

    • You have walked through b), created a class, inserted the code from above, and activated the class. The ABAP Language Version is maintained as Standard ABAP in the Properties tab under General.
    • Suppose you want to do cloud-ready development and use ABAP for Cloud Development, i.e. the restricted ABAP language version, in classic ABAP (e.g. an on-premise ABAP system that allows the unrestricted ABAP language version).
    • Open the Properties tab and choose General for this purpose.
    • Choose the Edit... button to the right of the ABAP Language Version property.
    • Select ABAP for Cloud Development in the pop-up window and choose Ok.
    • You will then be able to work with a repository object with the restrictions mentioned above. As a result, the example class with the code snippets will have syntax errors and cannot be activated. In more meaningful, productive development contexts, appropriate refactoring is required.

⬆️ back to top

More Information

⬆️ back to top

Executable Example

zcl_demo_abap_cloud_excursion

💡 Note

  • The executable example ...
    • does not focus - unlike other ABAP cheat sheet examples - on ABAP syntax as such (the other non-Standard-ABAP cheat sheet examples focus on ABAP syntax available in ABAP for Cloud Development), but rather emphasizes released APIs and libraries that provide predefined functionality and can be used in ABAP for Cloud Development. In particular, the Extension Components Library (XCO) is used.
    • covers an arbitrary selection for you to explore. For more detailed information and code snippets, see the SAP Help Portal documentation here and here about XCO. In most cases, the example covers a selection of classes and methods for retrieving information about repository objects. It is more of a "playground" for exploring the APIs with a few snippets of code, and should be seen as an invitation to more in-depth exploration.
  • The steps to import and run the code are outlined here.
  • Disclaimer