Friday 11 September 2020

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

SAP ABAP Development, SAP ABAP Tutorial and Material, SAP ABAP Certification, SAP ABAP Exam Prep

In Delivery Class, you must choose “L”

SAP ABAP Development, SAP ABAP Tutorial and Material, SAP ABAP Certification, SAP ABAP Exam Prep

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

SAP ABAP Development, SAP ABAP Tutorial and Material, SAP ABAP Certification, SAP ABAP Exam Prep

Check option Global temporary table and click OK

SAP ABAP Development, SAP ABAP Tutorial and Material, SAP ABAP Certification, SAP ABAP Exam Prep

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

SAP ABAP Development, SAP ABAP Tutorial and Material, SAP ABAP Certification, SAP ABAP Exam Prep

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.

SAP ABAP Development, SAP ABAP Tutorial and Material, SAP ABAP Certification, SAP ABAP Exam Prep

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

SAP ABAP Development, SAP ABAP Tutorial and Material, SAP ABAP Certification, SAP ABAP Exam Prep

Run program and you will see result

SAP ABAP Development, SAP ABAP Tutorial and Material, SAP ABAP Certification, SAP ABAP Exam Prep

No comments:

Post a Comment