sap_connect 0.1.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 33

sap_connect - the package is designed to establish a connection and then execute queries to the SAP system #

Visually represents a screen for setting up a connection and logging to SAP system GIF showing / hiding connection settings and switching input language

Connection settings are saved on the device
Provides connection and work in the language chosen by the user (internationalization)
After the connection is established, it allows you to perform queries to the SAP server

To make this package work, you must install to the SAP server package YDK_WEBS.

The package comes with a simple but fully working example, see the folder example\sap_flights_simplest_demo

To simplify the creation of the application and all the necessary settings, you can use the class SapApplication
The main settings of the application are stored in the class SapStartParams
Application debugging can be performed without the SAP server, but with simulating server interaction, see global variable [kFakeHandler] in sap_connect.dart
Use the methods to execute server requests: SapConnect().fetchPostWS(...) or SapConnect().fetchPost(...).
Difference between SapConnect().fetchPostWS(...) and SapConnect().fetchPost(...) methods:

  • SapConnect().fetchPostWS(...) Making a request to the server with a blocking screen output, the WaitScreen obscures the program screen during the execution and processing of the request. During execution of the processing of query results, additional requests to the server can be executed using fetchPost.
  • SapConnect().fetchPost(...) Just executes a request to the server, returns Future on the result of execution

general development approach:

on the SAP server, create the class inherited from class YDK_CL_WEBS_ACTION and make a class-method in it class:

CLASS <name of class> DEFINITION inheriting from YDK_CL_WEBS_ACTION....   
  CLASS-METHODS <name of method>
      !action_data TYPE string   " incaming query, usually a string JSON 
      !return_status TYPE string " return status of processing result
      !return_data TYPE string.  " returned data, most often a string JSON

  METHOD <name of method>.
* In order to make it easier to work with request data, load the request into the variable with a structure corresponding to the request structure (query)
    from_json( EXPORTING json = action_data CHANGING data = query ).

* Process the request, fill in the structure for returning data (ret_data)

* Return the processing result (ret_data)
    get_json( EXPORTING data = ret_data IMPORTING return_status = return_status return_data = return_data ).	

Call the created method from the mobile application:

      handlerType  : HandlerType.Method,
      handlerID    : <name of class>,
      action       : <name of method>,
      actionData   : query, // usually a string JSON 
      context      : context,
      postCallback : (Post post) {
        if (post.returnStatus != PostStatus.OK) return;
        setState(() {
// processing query results saved in post.returnData

the status returned by the SAP server (return_status) is a string, two values are reserved

  • "OK" - in dart constant PostStatus.OK; in abap constant YDK_CL_WEBS_ACTION=>STATUS_OK - request processing was successful
  • "ERR" - in dart constant PostStatus.Error; in abap constant YDK_CL_WEBS_ACTION=>STATUS_ERR - the processing was NOT successful, in this case the description of the error is in post.returnData, simple string not JSON

any other values can be used by the programmer as he pleases

[0.0.1] - 02.08.2019 #

[0.0.2] - 22.09.2019 #

[0.0.3] - 23.09.2019 several minor fixes #

[0.1.0] - 06.10.2019 Everything is ready for the first release. #


sap_connect examples #

at the moment there is only one example

"sap_flights_simplest_demo" #

Displays the connection screen to SAP server
After connecting to the SAP server, displays data from the sflights DB GIF showing / hiding connection settings and switching input language

By default, example works with a simulated SAP server.

To configure working with a real SAP server, you must:

  • In main.dart, uncomment the line starting with "// kFakeSapServer = false;..."
  • Install the YDK_WEBS package on the SAP server
  • In the YDK_WEBS_ACT table using transaction SM30, add entry:
    • processor name = YDK_CL_WEBS_FLIGHTS
    • action name = GET_FLIGHTS
  • Configure user to login through a mobile application using a transaction YDK_WEBS_USR
  • If sflights DB is empty in your SAP server, it can by filled by the run programms SAPBC_DATA_GENERATOR and SFLIGHT_DATA_GEN

main parts:

  METHOD get_flights.
*    importing
*    exporting
*      !RETURN_DATA type STRING .

* The sflight DB can be filled with test data by running the programs SAPBC_DATA_GENERATOR and SFLIGHT_DATA_GEN

    TYPES: BEGIN OF ty_query,
             carrid TYPE RANGE OF sflight-carrid,
             connid TYPE RANGE OF sflight-connid,
             fldate TYPE RANGE OF sflight-fldate,
           END   OF ty_query.

    DATA: query TYPE ty_query.

* to simplify the work with the request data, they are loaded into the corresponding structure
    from_json( EXPORTING json = action_data CHANGING data = query ). 

    DATA: lt_sflight TYPE STANDARD TABLE OF sflight.

    SELECT * INTO TABLE lt_sflight
      FROM sflight
     WHERE carrid IN query-carrid
       AND connid IN query-connid
       AND fldate IN query-fldate.
    IF lt_sflight IS INITIAL.
* return error message	
      return_data = 'No flights found by query criteria'.
      return_status = status_err.
* return query results, return_status is set to STATUS_OK
    get_json( EXPORTING data = lt_sflight IMPORTING return_status = return_status return_data = return_data ).

Dart (reduced)

void main() {
  Route _getRoute(RouteSettings settings) {
    switch ({
      case '/flights' :
        return MaterialPageRoute( builder: (context) => FlightsPage() );
      default :
        return null;

  final sapApplicationParams = SapApplicationParams(
    title: 'Flights',
    onGenerateRoute: _getRoute,

  final sapStartParams = SapStartParams(
    nextRouteName: "/flights", // the route that will be launched after a successful connection to the server
    useSecondaryLogin: true,

  runApp( SapApplication(sapApplicationParams, sapStartParams) );

class FlightsPageState extends State<FlightsPage> {
  final _flightList = List<Flight>();

  void _queryFlights(){
    final query = json.encode({
      'carrid'  : [SapRange( low : 'AA')],

      handlerID    : 'YDK_CL_WEBS_FLIGHTS',
      action       : 'GET_FLIGHTS',
      actionData   : query,
      context      : context,
      postCallback : (Post post) {
        if (post.returnStatus != PostStatus.OK) return;
        setState(() {
          _flightList.addAll((json.decode(post.returnData) as List).map((subJson) => Flight.fromJson(subJson)).toList());

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  sap_connect: ^0.1.0

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:sap_connect/sap_connect.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Mar 27, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Analysis issues and suggestions

Fix dependencies in pubspec.yaml.

Running flutter pub upgrade failed with the following output:

ERR: Because sap_connect depends on flutter_localizations any from sdk which depends on intl 0.16.0, intl 0.16.0 is required.
 So, because sap_connect depends on intl ^0.15.7, version solving failed.

Health suggestions

Format lib/sap_application.dart.

Run flutter format to format lib/sap_application.dart.

Format lib/sap_authorization.dart.

Run flutter format to format lib/sap_authorization.dart.

Format lib/sap_authorization_utils.dart.

Run flutter format to format lib/sap_authorization_utils.dart.

Fix additional 7 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/sap_connect.dart (Run flutter format to format lib/sap_connect.dart.)
  • lib/sap_const.dart (Run flutter format to format lib/sap_const.dart.)
  • lib/sap_file.dart (Run flutter format to format lib/sap_file.dart.)
  • lib/sap_internationalization.dart (Run flutter format to format lib/sap_internationalization.dart.)
  • lib/sap_internationalization_languages.dart (Run flutter format to format lib/sap_internationalization_languages.dart.)
  • lib/sap_utils.dart (Run flutter format to format lib/sap_utils.dart.)
  • lib/wait_screen.dart (Run flutter format to format lib/wait_screen.dart.)

Maintenance issues and suggestions

No valid SDK. (-20 points)

The analysis could not detect a valid SDK that can use this package.

Make sure dartdoc successfully runs on your package's source files. (-10 points)

Dependencies were not resolved.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0