Académique Documents
Professionnel Documents
Culture Documents
ABAPonSAPHANA.PartVI.NewAgeOpenSQLABAP740SAPYard
SAP YARD
TUTORIALS
CODE SNIPPETS
HELP FORUM
SAP QUIZ
246
Shares
Enteremail
Subscribe
SEARCH
SAP News
Follow@sapyard
http://www.sapyard.com/abaponsaphanapartvi/
1/24
10/30/2016
ABAPonSAPHANA.PartVI.NewAgeOpenSQLABAP740SAPYard
SAPYard
656likes
Liked
Youand2otherfriendslikethis
246
Shares
Abapinho
7MostPopular&FeaturedArticles
10/30/2016
246
Shares
ABAPonSAPHANA.PartVI.NewAgeOpenSQLABAP740SAPYard
The whole idea of the modern ABAP/SQL/HANA is to push down logic to the
database. We outsource these powerful innovations to put and execute the
logic in the database. But do remember, SAP also wants to be as Open as
possible. So given a choice between database speci c and database
independent solution, always chose the latter (database independent).
Enough of preaching, let us come to the topic of the day. New Age SQL for
ABAP.
ABAPer
Zero
We de ned the TYPES. We looped through the table and added the custom
logic (High Purchase or Low Purchase) as shown below.
IF <fs_ekpo>-netpr GT 299.
<fs_ekpo>-pur_type = 'High Purchase'.
http://www.sapyard.com/abaponsaphanapartvi/
Fiori App - An
Introduction from an
NetworkedBlogs
Blog:
SAPYard
Topics:
Abap,Sap,Hana
Followourblog
3/24
10/30/2016
246
Shares
ABAPonSAPHANA.PartVI.NewAgeOpenSQLABAP740SAPYard
ELSE.
<fs_ekpo>-pur_type = 'Low Purchase'.
ENDIF.
ENDLOOP.
NOVEMBER 5, 2014
NOVEMBER 3, 2014
Let us see how we can achieve the same thing in a new way. With ABAP 740
and above, we get rid of TYPES, Data Declaration and Loop. Isnt it cool?
http://www.sapyard.com/abaponsaphanapartvi/
4/24
10/30/2016
ABAPonSAPHANA.PartVI.NewAgeOpenSQLABAP740SAPYard
IF sy-subrc = 0.
cl_demo_output=>display_data(
EXPORTING
value = lt_sales_order_header
name = 'New AGE SQL : 1' ).
ENDIF.
http://www.sapyard.com/abaponsaphanapartvi/
5/24
10/30/2016
ABAPonSAPHANA.PartVI.NewAgeOpenSQLABAP740SAPYard
246
Shares
Outputs from both the above techniques are same. But the path does
matters. Isnt it?
If you have some confusion regarding HANA, check this popular post: SAP
HANA from Space Level.
Next, let us check the powerful inbuilt functions in SELECT.
Sample 2 ( Using JOIN and COUNT / DISTINCT functions in SELECT )
SELECT mara~matnr,
http://www.sapyard.com/abaponsaphanapartvi/
6/24
10/30/2016
ABAPonSAPHANA.PartVI.NewAgeOpenSQLABAP740SAPYard
mard~lgort,
COUNT( DISTINCT ( mard~matnr ) ) AS distinct_mat, " Unique Number of Material
COUNT( DISTINCT ( mard~werks ) ) AS distinct_plant, " Unique Number of Plant
SUM( mard~labst ) AS sum_unrest,
AVG( mard~insme ) AS avg_qlt_insp,
SUM( mard~vmspe ) AS sum_blocked
FROM mara AS mara INNER JOIN mard AS mard
ON mara~matnr EQ mard~matnr
INTO TABLE @DATA(lt_storage_loc_mat)
UP TO 1000 ROWS
WHERE mard~matnr = @p_matnr
246 AND mard~lgort = @p_lgort
Shares
GROUP BY mara~matnr,
mard~lgort.
IF sy-subrc = 0.
cl_demo_output=>display_data(
EXPORTING
value = lt_storage_loc_mat
name = 'New AGE SQL : 2' ).
ENDIF.
http://www.sapyard.com/abaponsaphanapartvi/
7/24
10/30/2016
ABAPonSAPHANA.PartVI.NewAgeOpenSQLABAP740SAPYard
246
Shares
SELECT ebeln,
10 AS rebate_per,
CEIL( netpr ) AS whole_ord_net,
( @lv_rebate * netpr ) AS rebate,
( netpr - ( @lv_rebate * netpr ) ) AS act_net
FROM ekpo
USING CLIENT '130'
UP TO 10 ROWS
INTO TABLE @DATA(lt_po_data).
http://www.sapyard.com/abaponsaphanapartvi/
8/24
10/30/2016
ABAPonSAPHANA.PartVI.NewAgeOpenSQLABAP740SAPYard
IF sy-subrc = 0.
cl_demo_output=>display_data(
EXPORTING
value = lt_po_data
name = 'New AGE SQL : 3' ).
ENDIF.
246
Shares
Not only Mathematics is fun with ABAP 740, but also logical programming.
Continue below to taste the new avour.
Sample 4 ( Using Complex Case statement on non-referenced elds i.e.
multiple in one Select )
SELECT ebeln,
http://www.sapyard.com/abaponsaphanapartvi/
9/24
10/30/2016
ABAPonSAPHANA.PartVI.NewAgeOpenSQLABAP740SAPYard
werks,
CEIL( netpr ) AS whole_ord_net,
( @lv_rebate * netpr ) AS rebate,
( netpr - ( @lv_rebate * netpr ) ) AS act_net,
FROM ekpo
USING CLIENT '130'
UP TO 25 ROWS
INTO TABLE @DATA(lt_po_data).
IF sy-subrc = 0.
cl_demo_output=>display_data(
EXPORTING
value = lt_po_data
name = 'New AGE SQL : 4' ).
ENDIF.
http://www.sapyard.com/abaponsaphanapartvi/
10/24
10/30/2016
ABAPonSAPHANA.PartVI.NewAgeOpenSQLABAP740SAPYard
246
Shares
COALESCEs literal meaning from the dictionary is come together and form
one mass or whole or combine (elements) in a mass or whole.
According to SAP documentation, the COALESCE function in Open SQL
returns the value of the argument arg1 (if this is not the null value); otherwise, it
returns the value of the argument arg2. A blank must be placed after the
opening parenthesis and before the closing parenthesis. A comma must be
placed between the arguments
Check the usage below. If data for ekko~lifnr is present (means PO is created
for the lessor) then the LIFNR (Vendor Number) from EKKO is printed else,
http://www.sapyard.com/abaponsaphanapartvi/
11/24
10/30/2016
ABAPonSAPHANA.PartVI.NewAgeOpenSQLABAP740SAPYard
SELECT lfa1~lifnr,
lfa1~name1,
246 ekko~ebeln,
Shares ekko~bukrs,
COALESCE( ekko~lifnr, 'No PO' ) AS vendor
FROM lfa1 AS lfa1 LEFT OUTER JOIN ekko AS ekko
ON lfa1~lifnr EQ ekko~lifnr
AND ekko~bukrs LT '0208'
INTO TABLE @DATA(lt_vend_po)
UP TO 100 ROWS.
IF sy-subrc = 0.
cl_demo_output=>display_data(
EXPORTING
value = lt_vend_po
name = 'New AGE SQL : 5' ).
ENDIF.
12/24
10/30/2016
ABAPonSAPHANA.PartVI.NewAgeOpenSQLABAP740SAPYard
How many times and in how many projects did you have the requirement to print
Plant and Plant description together like 0101 (Houston Site) or in forms you
had the requirement to write Payee (Payee Name)? We achieved it by looping
and concatenating. We did not have better option earlier, but now we can do
it while selecting the data. Thanks to the SAP Development Team.
Sample 6 (Concatenation while selecting data )
SELECT lifnr
Shares
&& '(' && name1 && ')' AS Vendor,
ORT01 as city
FROM lfa1
INTO TABLE @DATA(lt_bp_data)
UP TO 100 ROWS.
IF sy-subrc = 0.
cl_demo_output=>display_data(
EXPORTING
value = lt_bp_data
name = 'New AGE SQL : 6' ).
ENDIF.
246
http://www.sapyard.com/abaponsaphanapartvi/
13/24
10/30/2016
ABAPonSAPHANA.PartVI.NewAgeOpenSQLABAP740SAPYard
246
Shares
14/24
10/30/2016
ABAPonSAPHANA.PartVI.NewAgeOpenSQLABAP740SAPYard
SELECT lfa1~lifnr,
lfa1~name1,
ekko~ebeln,
ekko~bukrs
FROM lfa1 AS lfa1 INNER JOIN ekko AS ekko
ON lfa1~lifnr EQ ekko~lifnr
AND ekko~bukrs LT '0208'
INTO TABLE @DATA(lt_vend_po)
GROUP BY lfa1~lifnr, lfa1~name1, ekko~ebeln, ekko~bukrs
HAVING lfa1~lifnr > '0000220000'.
246
Shares
IF sy-subrc = 0.
cl_demo_output=>display_data(
EXPORTING
value = lt_vend_po
name = 'New AGE SQL : 8' ).
ENDIF.
http://www.sapyard.com/abaponsaphanapartvi/
15/24
10/30/2016
ABAPonSAPHANA.PartVI.NewAgeOpenSQLABAP740SAPYard
Remember, sometimes we need to select all elds of more than one table
and provide custom names in the output. Wasnt it tiresome to create TYPEs
and achieve our requirement?
Sample 9 ( Use of selection of all columns with renaming of elds. This
is handy in case you have to do all eld select )
I thought with ABAP 740, I could do the below.
246
Shares
SELECT jcds~*,
tj02t~*
FROM jcds INNER JOIN tj02t
ON jcds~stat = tj02t~istat
WHERE tj02t~spras = @sy-langu
INTO TABLE @DATA(lt_status)
UP TO 1000 ROWS.
IF sy-subrc = 0.
cl_demo_output=>display_data(
EXPORTING
value = lt_status
name = 'New AGE SQL : 9' ).
ENDIF.
16/24
10/30/2016
ABAPonSAPHANA.PartVI.NewAgeOpenSQLABAP740SAPYard
IF sy-subrc = 0.
cl_demo_output=>display_data(
EXPORTING
value = lt_status
name = 'New AGE SQL : 9' ).
ENDIF.
Check _CHANGE is added to the eld name. _TEXT is also added in the
column name from second table (not captured in the screen print below)
These were just the tip of the icebergs. We would stumble upon more
features and surprises as we work on projects in real system. Just to let you
know, all the above code snippets are from atraditional database (not HANA)
http://www.sapyard.com/abaponsaphanapartvi/
17/24
10/30/2016
ABAPonSAPHANA.PartVI.NewAgeOpenSQLABAP740SAPYard
which has EhP 7.4. So do not confuse that we need HANA database to take
advantage of modern SQL techniques. We just need near and above EhP 7.4.
Update 08/25/2016:
We askedIf CDS Views and SQL can achieve the same functionality. Which
one should we choose?
246
Shares
http://www.sapyard.com/abaponsaphanapartvi/
18/24
10/30/2016
ABAPonSAPHANA.PartVI.NewAgeOpenSQLABAP740SAPYard
105
246
Shares
http://www.sapyard.com/abaponsaphanapartvi/
19/24
10/30/2016
ABAPonSAPHANA.PartVI.NewAgeOpenSQLABAP740SAPYard
Previous post
9 COMMENTS
Next post
ON "ABAP ON SAP HANA. PART VI. NEW AGE OPEN SQL ABAP 740"
246
Shares
20/24
10/30/2016
ABAPonSAPHANA.PartVI.NewAgeOpenSQLABAP740SAPYard
hello Giri,
this should be work . Please drop the table and
reload it HANA studio, if it still does not work
please share the error log with us.(I hope you the restriction on
lines of code you could have in it).
You can also use Smart Data Integrator for it.
please be reminded Open SQL is preferred approach for Code
246
Shares
21/24
10/30/2016
ABAPonSAPHANA.PartVI.NewAgeOpenSQLABAP740SAPYard
Regards,
Team SAPYard.
Shares
SAP HANA and beyond. Hoping one day I could taste its power.
22/24
10/30/2016
ABAPonSAPHANA.PartVI.NewAgeOpenSQLABAP740SAPYard
I would like to add one more point, which i faced many times during
my work. some of the above explained statements wont work with
forall entries. So, use new open sql accordingly.
keep sharing
Thanks
Naveen
246
Shares
23/24
10/30/2016
ABAPonSAPHANA.PartVI.NewAgeOpenSQLABAP740SAPYard
Enteryourcommenthere...
246
Shares
http://www.sapyard.com/abaponsaphanapartvi/
24/24