I have two transactions calling the same program/report. I would like to branch behavior of the program based on t-code used to run in it. How do I get the name of the original transaction in ABAP code? Or, do I need to use different approach?
Asked
Active
Viewed 2,923 times
1
-
Why differentiate the behavior of a report based on the calling transaction? That's equivalent to a function returning different values based on the caller - it's a break of encapsulation. If the two transactions need different behavior from the report, why not pass a parameter to it that controls it? More drastically, why call a *report* at all when you have classes and function modules at your disposal? – ACuriousMind Sep 05 '18 at 22:47
1 Answers
7
did you try this? sy-tcode always shows the foreground transaction code, not interested in your background program.
IF sy-tcode = 'A'.
... do your stuff
ELSEIF sy-tcode = 'B'.
... do your stuff
ENDIF.

dotchuZ
- 2,621
- 11
- 39
- 65
-
1Excellent! Exactly what I need. I couldn't find it by google. Wondering why it is not here: https://wiki.scn.sap.com/wiki/display/ABAP/ABAP+system+fields – jcjr Aug 22 '18 at 08:59
-
2
-
4@jcjr it's just a wiki maintained by the community, not by SAP - prefer looking at the [SY fields official documentation](https://help.sap.com/http.svc/rc/abapdocu_752_index_htm/7.52/en-US/index.htm?file=abensystem_fields.htm) - instead of SY-TCODE you may also use `CL_ABAP_SYST=>GET_TRANSACTION_CODE( )` (note that it has two tiny different behaviors, one for variant transactions, and one in case SY-TCODE has been programmatically changed) – Sandra Rossi Aug 22 '18 at 17:28