Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
amol_samte
Contributor
Hello Folks,

Over a time period we are seeing new changes in ABAP and hope will come more and more to get work easy and interesting.

As a developer we always try to write code in optimized way, but whenever coming across a situation to enhance standard functionality like user exits, enhancements , adding extra functionality to copied Adobe Form etc.. some times we have to carry forward logic using existing data source or internal table with the help of  For All Entries. For All Entries is nothing but a join to an internal table.

For All Entries Sap Help :-

https://help.sap.com/doc/abapdocu_752_index_htm/7.52/en-US/abenwhere_logexp_itab.htm

But it has some limitations and restriction to use SQL expressions and Order by clause with field names etc..

But we have some alternatives -

  1. Pushing Internal table to DB by using AMDP - After release 7.40

  2. Usage GTT (Global Temporary table) -  Before release 7.52

  3. Direct select from internal table - From release 7.52


Lets have an example -

1.Pushing Internal table to DB by using AMDP

Please go thought below link to understand how to push internal table to AMDP method and usage.

Note : Please read comments of below shared link blog for fair usage.

https://blogs.sap.com/2015/04/29/handle-internal-table-inside-amdp/

2. Using GTT

Create a GTT to hold Airline code and Flight Connection Number



After Creation of GTT table and insertion of records into GTT we can write direct query, Please see below example.

The GTT concept specifies that a GTT is always empty at the start of a database LUW and hence always has to be cleared at the end of each database LUW.
"Insert records into Global Temporary Table
INSERT zgtt_flight FROM @( VALUE #( carrid = 'LH' connid = 2402 ) ).

SELECT a~carrid,
a~connid,
SUM( b~price ) AS price,
b~currency

FROM zgtt_flight AS a LEFT OUTER JOIN sflight AS b
ON a~carrid = b~carrid
AND a~connid = b~connid

GROUP BY a~carrid, a~connid, b~currency

ORDER BY a~carrid

INTO TABLE @DATA(lt_itab).

IF sy-subrc = 0.
"The GTT concept specifies that a GTT is always empty at the start of a database LUW
"hence always has to be cleared at the end of each database LUW otherwise will give dump
"Runtime Errors COMMIT_GTT_ERROR
DELETE FROM zgtt_flight.
ENDIF.

 

Output :



For more about GTT

https://help.sap.com/doc/abapdocu_751_index_htm/7.51/en-US/abenddic_database_tables_gtt.htm

 

3. Using Internal table as Data Source From Release 7.52

The SELECT statement handles the internal table of the application server like a database table on the database and internal table must be prefixed with @ symbol as a data source of a query.

Below is the example :-
TYPES : BEGIN OF lty_flt,
carrid TYPE s_carr_id,
connid TYPE s_conn_id,
END OF lty_flt.
DATA : lt_flt TYPE STANDARD TABLE OF lty_flt.
"Insert records into local internal table
lt_flt = VALUE #( ( carrid = 'LH' ) ( connid = 2402 ) ) .

SELECT a~carrid,
a~connid,
SUM( b~price ) AS price,
b~currency

FROM @lt_flt AS a LEFT OUTER JOIN sflight AS b
ON a~carrid = b~carrid
AND a~connid = b~connid

GROUP BY a~carrid, a~connid, b~currency

ORDER BY a~carrid

INTO TABLE @DATA(lt_itab)
##db_feature_mode[itabs_in_from_clause].

Output : -



For more about Internal Table as Data Source

https://help.sap.com/doc/abapdocu_752_index_htm/7.52/en-US/abapselect_itab.htm

 

Well, hope this idea will be useful and always refer the sap help documentation for best practice.

 

Cheers,

Amol
12 Comments