Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Starting a new session programatically

Former Member
0 Likes
2,246

Hi,

What is the best way to start a new session programatically?

Basically I have my logic inside a method (I could also include the logic inside a function). I have a button in my dynpro, and when I click this button, I want that a new session is opened. I think that it is possible to start a new transaction into a new session, but in my case I see it very unnecessary to create a new transaction for something that doesn't really require a transaction

Regards,

Karri

Additional requirement: I was wondering that is it also possible to close the session programatically. So when the user has completed his task in the new opened session, the session would close automatically. I think that a bit similar thing happens in SU01 when you go to see the user's authorisations (new session is opened), and if you click "back" after you have checked the authorisations, the session will be closed automatically.

Edited by: Karri Kemppi on Feb 3, 2009 12:47 PM

5 REPLIES 5
Read only

Former Member
0 Likes
1,361

Hello,

To create a new session programmatically, call the function TH_CREATE_FOREIGN_MODE with tcode SESSION_MANAGER.

Regards,

Shailaja

Read only

Former Member
0 Likes
1,361

Here's an example of starting and ending a session.


START-OF-SELECTION.

  CALL FUNCTION 'ABAP4_CALL_TRANSACTION'
        STARTING NEW TASK 'NewTask'
        DESTINATION 'NONE'
  EXPORTING
    tcode = 'ZLEADS'
    "skip_screen = 'X'
    "mode_val = 'E'
    "update_val = 'A'
*  TABLES
*    using_tab = bdcdata_tab
  EXCEPTIONS
    call_transaction_denied = 1
  OTHERS = 2.


*  additional processing here *

** closes the current session.
  CALL FUNCTION 'TH_DELETE_MODE'
** EXPORTING
**   MODE          = -1
            .


  LEAVE PROGRAM.

Read only

GauthamV
Active Contributor
0 Likes
1,361

check this.

[new session using program|https://wiki.sdn.sap.com/wiki/pages/viewpage.action?pageId=23658609]

Read only

Former Member
0 Likes
1,361

Hi,

try this:


  CALL FUNCTION 'TH_CREATE_MODE'.

or this


  CALL FUNCTION 'TH_CREATE_MODE'
    EXPORTING
      TRANSAKTION = 'FB03'.

Regards, Dieter

Read only

Former Member
0 Likes
1,361

Well, everybody seemed to instruct to use function modules to launch a transaction (which was something I wanted to avoid). Anyhow, I finally included the needed logic into a function module, and used the "NEW TASK" addition when calling the function. This was a perfect solution. Thanks for all answers.