Skip to Content
Personal Insights
Author's profile photo Chau Nguyen Phuc

GTT – another ways to replace FAE

With the ECC system in the past, when handling logic to filter the table together, we usually used For all entries – FAE. But, when we use it, we could not be able to utilize power in open SQL (ex Built-in function, order by). Known this disadvantage in the system, SAP has developed alternative solutions (CTE, View, …), one of the solutions which are a Global Temporary Tables, also known as GTT. So what it is, let’s stay tuned!!!

Prerequisites

  • SAP NW AS ABAP 7.52 or higher

Agenda

  1. What is GTT
  2. Handling with GTT
  3. Summary

What is GTT

Global Temporary Tables, called GTT, is a temporary table to store data in the program. In essence, GTT is also a transparent table. But it is slightly different than a transparent table, which means it only stores temporary and will be deleted at the end of the program.

GTT is always empty at the beginning of LUW and will be cleared at the end of LUW, which means data has only existed in the process of running the program.

At the end of the program, you must use statement DELETE <YOUR_GTT_NAME> FROM @dbtab to prevent the run-time error COMMIT_GTT_ERROR.

By using GTT, you will able to be more flexible in the query in Open SQL (easy to use order by, aggregate function, built-in function…) without the same restriction as FAE

Please note that we don’t need to create more key fields in GTT, because at this time, the number of key fields is only 15.

Handling with GTT

Create GTT in SE11

Firstly, go to tcode SE11 to create a database table

In Delivery Class, you must choose “L”

At menu ->Extras, select Change Display table Category to change transparent table to GTT

Check option Global temporary table and click OK

After choosing GTT option, you will see text Transparent Table will be changed to Global Temporary T

At tab Fields, create some fields (key or non-key fields) which you want to filter/store data in your program. In this sample, I will create 3 key fields which are Company Code (BUKRS), Fiscal Year(GJAHR), and document number (BELNR).
Please note that Max key fields = 15.

Implement GTT in program

In se38, create a program and write some code the same as the image below. I will use GTT same as table to inner join with another table in the system. In this way, I can use built-in function or some feature in open SQL without any restrictions.

At the end of program, you must delete this GTT, if you don’t delete it, your system will be crashed with exception COMMIT_GTT_ERROR

Run program and you will see result

Summary

Through this blog, I hope you will have alternative ways to handle data instead of the traditional ways previously.

Hope this helps!!!

Assigned Tags

      5 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo David Henn
      David Henn

      Nice!

      where does this GTT live? On the database or on the AS ABAP?

      Do I have to worry about concurrency (e.g. add a session key to the key fields)?

       

      Regards David

      Author's profile photo Chau Nguyen Phuc
      Chau Nguyen Phuc
      Blog Post Author

      GTT is a special transparent table, so i think it will live on the database, but it will not store any data. You can only insert data in your ABAP code and data will be deleted at the end of LUW (after using, you must use delete GTT)
      Don't worry about concurrency because it can be accessed only by one consumer

      Author's profile photo Sandra Rossi
      Sandra Rossi

      It would be nice to mention the ABAP documentation - Global Temporary Tables.

      Author's profile photo Suhas Saha
      Suhas Saha

      Actually with ABAP release 7.52 you can use internal tables as data sources for SELECT statements. In your code snippet you could directly join BSEG with the internal table GT_BKPF; no need to use a GTT. 

      Tbh, i have never had the need/opportunity to use this feature until now. I am not quite sure about the restrictions/limitations of it. 

      Cf. ABAP documentation

      Author's profile photo Chau Nguyen Phuc
      Chau Nguyen Phuc
      Blog Post Author

      Restriction of internal table that is you can only use one internal table in select statement.
      But with GTTs, you can use more. I tried to select from @itab on SAP 1709