Skip to Content

Introduction

Perhaps everyone of you knows this scenario very well: After logon we have to start multiple transactions to do our daily developer’s work. Sort of “same procedure as every day”. I optimized the logon process with software “KeePass” and the plugin “KeeSAPLogon” – so far so good. But I didn’t find a convincing solution to start multiple transactions subsequent. Not that starting transactions would be extremly time consuming but it’s a repeating task 🙂

A little search showed me: Other users had the same question and the answers were helpful but not the solution I was looking for. So I wrote a report to solve this problem for my purpose. Hope you enjoy it.

Please pay attention to the fact that this is just a tech demo – at no time to use in productive environments. Only on your personal system (playground) for your studies.

Solution description

I wrote a report to start multiple transactions from a favorite folder called “Autostart” (see “Managing Favorites“). Thereby it’s easy to control which transactions should be started at once after logon to a system/client combination. The associated transaction has to be your start transaction.

Important part of the implementation was calling the function module “Z_AUTOSTART” with the statements “STARTING IN NEW TASK” and “DESTINATION IN GROUP” (see “asynchronous/parallel RFC“). Pay attention to the limit of your SAP GUI sessions and that new sessions will be opened as type “RFC”.

To make it a little bit more user friendly, you will be asked if you want to autostart your transactions. Even a delayed start is possible. And if you autostart a transaction where a variant with your username exists, this variant will be run automatically. That’s interesting to have reporting like a slide show with a delay of 3 seconds.

Implementation

Create function module

Please create a function module called “Z_AUTOSTART”. You will find the source code at the end of the blog for lack of space. Set flag “Remote-Enabled Module” in attributes.

Create report and transaction

Please create a new report called “ZAUTOSTART”. You will find the source code at the end of the blog for lack of space. Create a transaction code called “Z_AUTOSTART”. Underline character is important to get the name of the folder of your favorites from transaction code.

That makes it a little bit more dynamic. To give an example you can create a transaction code called “Z_MISC” and it will start all transactions from folder “MISC” of your favorites. So you don’t have to use it as autostart transaction after logon but whenever you want. That’s handy 🙂

Enhance your favorites

Create a folder called “Autostart”. Place your required transaction in it. Pay attention to the limit of your SAP GUI sessions. The order you place them in the folder is the order they will be started. But that’s not necessary the order SAP GUI windows will appear.

Change your start transaction

Run transaction “Z_AUTOSTART”. If everything is ok, set this transaction as your start transaction. That’s all. Log off and on again.

Source code

Function module Z_AUTOSTART

FUNCTION z_autostart.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(IV_TCODE) TYPE  SYST_TCODE
*"     VALUE(IV_REPORT) TYPE  RALDB_REPO
*"     VALUE(IV_USE_VAR) TYPE  XFELD
*"  EXCEPTIONS
*"      SYSTEM_FAILURE
*"      COMMUNICATION_FAILURE
*"      RESOURCE_FAILURE
*"----------------------------------------------------------------------

  IF iv_use_var = abap_false AND iv_tcode IS NOT INITIAL.
    CALL TRANSACTION iv_tcode.
  ENDIF.

  IF iv_use_var = abap_true AND iv_report IS NOT INITIAL.
    SUBMIT (iv_report) USING SELECTION-SET sy-uname.
  ENDIF.

ENDFUNCTION.

Report ZAUTOSTART

*&---------------------------------------------------------------------*
*& Report ZAUTOSTART
*&---------------------------------------------------------------------*
*&
*& start transactions from a folder of your favorites
*&
*& written by Michael Keller
*&
*&---------------------------------------------------------------------*

REPORT zautostart.

CLASS lcl_autostart DEFINITION.

  PUBLIC SECTION.
    TYPES favorites TYPE TABLE OF smen_buffc.

    CLASS-METHODS run.

  PRIVATE SECTION.
    CLASS-METHODS do_prechecks
      IMPORTING
        iv_tcode      TYPE syst_tcode
      EXPORTING
        ev_report     TYPE raldb_repo
        ev_var_exists TYPE abap_bool
      EXCEPTIONS
        error.

    CLASS-METHODS get_favorites_from_folder
      IMPORTING
        iv_folder    TYPE char100sm
      EXPORTING
        et_favorites TYPE favorites.

ENDCLASS.

CLASS lcl_autostart IMPLEMENTATION.

  METHOD do_prechecks.

    DATA: ls_tstc    TYPE tstc,
          lv_message TYPE text100,
          lv_report  TYPE raldb_repo,
          lv_variant TYPE raldb_vari,
          lv_subrc   TYPE sysubrc.

    " check if transaction code exists
    SELECT SINGLE *
           FROM tstc
           INTO ls_tstc
           WHERE tcode = iv_tcode.

    IF sy-subrc <> 0.
      lv_message = 'Transaction code &1 is invalid.'.
      REPLACE FIRST OCCURRENCE OF '&1' IN lv_message WITH iv_tcode.
      MESSAGE lv_message TYPE 'I'.
      RAISE error.
    ENDIF.

    CALL FUNCTION 'AUTHORITY_CHECK_TCODE'
      EXPORTING
        tcode  = iv_tcode
      EXCEPTIONS
        ok     = 1
        not_ok = 2
        OTHERS = 3.

    IF sy-subrc > 1. " a little bit special
      lv_message = 'No authorization for transaction code &1.'.
      REPLACE FIRST OCCURRENCE OF '&1' IN lv_message WITH iv_tcode.
      MESSAGE lv_message TYPE 'I'.
      RAISE error.
    ENDIF.

    lv_report = ls_tstc-pgmna.
    lv_variant = sy-uname.

    CALL FUNCTION 'RS_VARIANT_EXISTS'
      EXPORTING
        report              = lv_report
        variant             = lv_variant
      IMPORTING
        r_c                 = lv_subrc
      EXCEPTIONS
        not_authorized      = 1
        no_report           = 2
        report_not_existent = 3
        report_not_supplied = 4
        OTHERS              = 5.

    IF lv_subrc = 0.
      ev_report     = lv_report.
      ev_var_exists = abap_true.
    ENDIF.

  ENDMETHOD.


  METHOD get_favorites_from_folder.

    DATA: lt_favorites TYPE favorites,
          ls_favorites LIKE LINE OF lt_favorites,
          lv_object_id TYPE menu_num_5.

    CALL FUNCTION 'NAVIGATION_LOAD_FAVORITES'
      EXPORTING
        user_name     = sy-uname
      TABLES
        favorites_tab = lt_favorites.
*       FAVORITES_FOR_GUI       =
*       LINKS_LIST              =

    " look for the folder
    LOOP AT lt_favorites INTO ls_favorites
                         WHERE reporttype = space
                         AND   report     = space
                         AND   text IS NOT INITIAL.
      TRANSLATE ls_favorites-text TO UPPER CASE.
      IF ls_favorites-text = iv_folder.
        lv_object_id = ls_favorites-object_id.
        EXIT.
      ENDIF.
    ENDLOOP.

    IF sy-subrc <> 0 OR lv_object_id IS INITIAL.
      RETURN.
    ENDIF.

    " reduce to relevant transactions
    DELETE lt_favorites WHERE parent_id <> lv_object_id
                        OR    reporttype <> 'TR'
                        OR    report = sy-tcode.

    IF lt_favorites IS INITIAL.
      RETURN.
    ENDIF.

    " sort favorites, important for starting sequence
    SORT lt_favorites BY sort_order ASCENDING.
    READ TABLE lt_favorites INTO ls_favorites INDEX 1.
    IF sy-subrc <> 0.
      RETURN.
    ENDIF.
    APPEND ls_favorites TO lt_favorites.
    DELETE lt_favorites INDEX 1.
    IF sy-subrc <> 0.
      RETURN.
    ENDIF.

    et_favorites = lt_favorites.

  ENDMETHOD.


  METHOD run.

    DATA: lt_parts     TYPE TABLE OF syst_tcode,
          lv_lines     TYPE i,
          lv_folder    TYPE char100sm,
          lt_favorites TYPE favorites,
          ls_favorites TYPE smen_buffc,
          lv_tcode     TYPE syst_tcode,
          lv_task      TYPE text100,
          lv_report    TYPE raldb_repo,
          lv_use_var   TYPE abap_bool,
          lv_answer    TYPE char1,
          lv_question  TYPE itex132,
          lv_tabix     TYPE sytabix.

    FIELD-SYMBOLS <favorites> TYPE smen_buffc.

    " get name of favorites folder from transaction code
    SPLIT sy-tcode AT '_' INTO TABLE lt_parts.
    IF sy-subrc <> 0.
      RETURN.
    ENDIF.

    lv_lines = lines( lt_parts ).
    READ TABLE lt_parts INTO lv_folder INDEX lv_lines.
    IF sy-subrc <> 0 OR lv_folder IS INITIAL.
      RETURN.
    ENDIF.

    get_favorites_from_folder(
      EXPORTING
        iv_folder = lv_folder
      IMPORTING
        et_favorites = lt_favorites ).

    IF lt_favorites IS INITIAL.
      RETURN.
    ENDIF.

    lv_lines = lines( lt_favorites ).

    CONCATENATE 'Start transactions from folder "' lv_folder '"?' INTO lv_question.

    CALL FUNCTION 'POPUP_TO_CONFIRM'
      EXPORTING
        titlebar              = 'Autostart'
*       DIAGNOSE_OBJECT       = ' '
        text_question         = lv_question
        text_button_1         = 'Yes'
        icon_button_1         = 'ICON_EXECUTE_OBJECT'
        text_button_2         = 'Yes, delayed'
        icon_button_2         = 'ICON_TIME'
        default_button        = '2'
        display_cancel_button = 'X'
*       USERDEFINED_F1_HELP   = ' '
*       START_COLUMN          = 25
*       START_ROW             = 6
*       POPUP_TYPE            =
*       IV_QUICKINFO_BUTTON_1 = ' '
*       IV_QUICKINFO_BUTTON_2 = ' '
      IMPORTING
        answer                = lv_answer
*     TABLES
*       PARAMETER             =
      EXCEPTIONS
        text_not_found        = 1
        OTHERS                = 2.

    IF sy-subrc <> 0 OR lv_answer = 'A'.
      RETURN.
    ENDIF.

    " find all transaction codes in folder and start them
    LOOP AT lt_favorites ASSIGNING <favorites>.
      CLEAR: lv_report,
             lv_use_var.

      lv_tabix = sy-tabix.
      lv_tcode = <favorites>-report.
      lv_task  = lv_tcode.

      do_prechecks(
        EXPORTING
          iv_tcode = lv_tcode
        IMPORTING
          ev_report     = lv_report
          ev_var_exists = lv_use_var
        EXCEPTIONS
          error  = 1
          OTHERS = 2 ).

      IF sy-subrc <> 0.
        CONTINUE.
      ENDIF.

      IF lv_tabix <> lv_lines.
        CALL FUNCTION 'Z_AUTOSTART'
          STARTING NEW TASK lv_task
          DESTINATION IN GROUP DEFAULT
          EXPORTING
            iv_tcode              = lv_tcode
            iv_report             = lv_report
            iv_use_var            = lv_use_var
          EXCEPTIONS
            system_failure        = 1
            communication_failure = 2
            resource_failure      = 3
            OTHERS                = 4.

        IF sy-subrc <> 0.
          CONTINUE.
        ENDIF.

        IF lv_lines > 2 AND lv_answer = '2'.
          WAIT UP TO 3 SECONDS.
        ELSE.
          " do not start too fast
          WAIT UP TO 1 SECONDS.
        ENDIF.
      ELSE.
        CALL FUNCTION 'Z_AUTOSTART'
          EXPORTING
            iv_tcode   = lv_tcode
            iv_report  = lv_report
            iv_use_var = lv_use_var.
      ENDIF.
    ENDLOOP.

  ENDMETHOD.

ENDCLASS.

START-OF-SELECTION.
  lcl_autostart=>run( ).

 

To report this post you need to login first.

5 Comments

You must be Logged on to comment or reply to a post.

  1. Michelle Crapo

    Cool!   I’m going to give this a try.    Prior to this – I just created a transaction and it would open multiple sessions – but not user favorites.  A transaction with variable Logon and a simple transaction that opened multiple screens.   So I’ll try to combine the two.    Just a normal GUI logon.

    I’ll let you know how it goes.

     

     

    (0) 
        1. Michelle Crapo

          Hi Michael,

          I’m giving a session at SAP Teched in Las Vegas.   I was going to show variable logon as an example of quickly getting users to the screen(s) they use the most. (My demo)

          Do you mind – and I’ll give you credit – if that demo includes opening multiple sessions from a folder.  Like you have here?   I’ll even direct them to your blog.

          I couldn’t find a great way to contact you – so I’m writing on your blog!!

          Thank you!

          Michelle

          (0) 
          1. Michael Keller Post author

            Hi Michelle,

            gladly 🙂 Please share this demo or parts of it with your audience on SAP TechEd. Credit is welcome. And I’m really interested in your demo. If there are any news about it, let me know.

            Best regards

            Michael

            (0) 

Leave a Reply