sap_connect 0.1.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 51

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:
ABAP

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

CLASS <name of class> IMPLEMENTATION.
  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 ).	
  ENDMETHOD.
ENDCLASS.  

Call the created method from the mobile application:
Dart

    SapConnect().fetchPostWS(
      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.

example/README.md

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:
ABAP

CLASS YDK_CL_WEBS_FLIGHTS IMPLEMENTATION.
  METHOD get_flights.
*    importing
*      !ACTION_DATA type STRING
*    exporting
*      !RETURN_STATUS type STRING
*      !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.
    ENDIF.
	
* 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 ).
  ENDMETHOD.
ENDCLASS.

Dart (reduced)

void main() {
  Route _getRoute(RouteSettings settings) {
    switch (settings.name){
      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')],
    });

    SapConnect().fetchPostWS(
      handlerID    : 'YDK_CL_WEBS_FLIGHTS',
      action       : 'GET_FLIGHTS',
      actionData   : query,
      context      : context,
      postCallback : (Post post) {
        if (post.returnStatus != PostStatus.OK) return;
        setState(() {
          _flightList.clear();
          _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:


dependencies:
  sap_connect: ^0.1.0

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support 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';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
26
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
40
Overall:
Weighted score of the above. [more]
51
Learn more about scoring.

We analyzed this package on Oct 18, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.4

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

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

Support latest dependencies. (-60 points)

The version constraint in pubspec.yaml does not support the latest published versions for 6 dependencies (device_id, fluttertoast, intl, open_file, path_provider, shared_preferences).

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0
async ^2.3.0 2.4.0
cookie_jar ^1.0.0 1.0.1
crypto ^2.0.6 2.1.3
device_id ^0.1.3 0.1.3 0.2.0
flutter 0.0.0
flutter_localizations 0.0.0
fluttertoast ^2.1.2 2.2.11 3.1.3
intl ^0.15.7 0.15.8 0.16.0
open_file ^1.2.3+1 1.3.0 2.0.3
package_info ^0.4.0+1 0.4.0+8
path_provider ^0.5.0+1 0.5.0+1 1.3.1
shared_preferences ^0.4.2 0.4.3 0.5.3+5
Transitive dependencies
charcode 1.1.2
collection 1.14.11 1.14.12
convert 2.1.1
meta 1.1.7
path 1.6.4
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test
mockito ^4.0.0