Skip to Content
Technical Articles

How to get quickly OpenSQL queries for your ABAP programs

As impossible as it may seem, we sometimes forget the way in which a query should be constructed in openSQL. Have you ever wondered if there is an easy way to build queries to use in your programs? 

Well, the answer is YES, in this post I will show you how to get simple queries (nothing too complex) for your programs.

After reading this post you easily will build your SELECT statements and you could also modify it for UPDATE or INSERT statements.

Let’s get into that.

Step 1: Go to transaction SE16N

Transaction%20SE16N

Transaction SE16N

 

Step 2: Choose your table

Choosing%20table

Choosing table

 

For this example let’s use SFLIGHT

 

Step 3: Choose your fields for filtering (in this case I’m using the field date)

Choosing%20Fields

Choosing Fields

 

Press F8

 

Step 4: Visualize your data

Visualize%20data

Visualize data

Step 5: Visualize your script

Now just click the Display selection Criteria button or SHIFT + F1

Click%20the%20button

Click the button

 

And visualize your script

Visualize%20script

Visualize script

Now just copy the script and use it where you need it.

 

With this few steps yo can now get simple queries for your programs in no time.

IMPORTANT: the key is to know the fields of the table that you want to use in your program (for correct filtering).

I hope this information can be useful for your projects as it has been for me.

Share this post with whoever needs it

See you next time.

6 Comments
You must be Logged on to comment or reply to a post.
  • Thanks!

    By the way, SE16N is only for S/4HANA (as far as I know). In other ABAP-based applications (CRM, etc.), there is now the transaction code S416N (documented in SAP notes). There is also the same feature as you mention.

  • Besides the well known SE16 and SE16N, there is also SE16H as well as S416N (another alias is S4H16N) and S416H (with its alias S4H16H).

    These ‘new’ transactions are not necessarily limited to HANA, but are part of ‘newer’ SAP application releases: SE16 -> SE16N -> SE16H -> S416N/S416H. In general, these programs work on any SAP application, if available, however, there might be included functions that are strictly supported only for a HANA database (however, I am currently not aware of functions striclty limited to a HANA applications in SE16H or S416N and S416H, other then possible performance issues).

    • SE16H and S416H – lets you define joins for table selects as well as aggregate functions
      SE16H is actually based on the same FM ‘SE16N_START’ as SE16N is, just the new flag parameter I_HANA is checked
      same with S416H which is based on FM ‘GTB_START’ as S416N is, and again, just the flag parameter I_HANA is checked
    • The parameter I_HANA is a little misleading, since the inner / outer join functions as well as the aggregate functions are also available and work on Oracle and MaxDB databases.
    • The transactions S4* (S416N, S416H, S4H16N, S4H16H) are also a little misleading, as these transactions are also present on a recent CRM system, whereas SE16N and SE16H where not present.