ABAP for SAP HANA – 26 – New way of ABAP Programming in HANA

0
8992
ABAP on HANA

Many must be wondering with new updates from SAP everyday on different areas, what’s there for ABAP coding? Well now an ABAP Consultant is expected to know CDS, AMDP, BRF+, Odata and above all new open SQL way of life.  The new way of ABAP Programming is not totally new but a bit of polished version with new syntaxes to make life what I can say a bit easier for the ABAP Consultants.

I will skip the basics like avoiding data declarations and using @data, data(workarea) or assigning field-symbol(<field-symbols>) syntax etc since it has already been covered in another useful article at SAPYard, but will move on to the more innovative ones. 🙂

New Training Announcement

SAP Adobe Forms for ABAP Developers (Enrolling Now) – Class Starts on 21st of Nov 2020

Training Days – 21, 22, 28, 29 Nov, 5, 6, 12, 13, 19 & 20 Dec 2020
Time – 7:30 AM to 9:30 AM IST GMD+5.5

Pay the Fee and Enroll

High Level Course Agenda

Note: Here it is not possible to add the full code context since the new syntaxes are applied as part of large and complex builds, but I will add snippets of dummy coding lines which may help to explain the new syntaxes, which of course one can apply and test its significance during their builds.

1. FOR ALL ENTRIES

Ever thought of doing away with our ‘for all entries’ statement and treating the internal table like a database one in our select and use join instead? Well that can be done now.

Select va~vbeln, va~posnr
from vbap as va
inner join it_internaltable1 as it
into table @data(it_table2)
where va~vbeln = it~vbeln.

So start using this for your builds and see if it makes your coding simpler.

2. MOVE CORRESPONDING:

No need of writing our typical ‘move corresponding …..’ instead can use the simple one as below when all fields are not same and not in correct sequence:

data(wa_data1) = corresponding  #(  wa_data ).

3. CONVERSIONS

Our conversions, using FMs, can be replaced as below:

data(lv_matnr) = |{ wa_file_data-matnr alpha = in }|.
data(lv_vbeln) =  |{ wa_file_data-vbeln alpha = out }| .

4. CONCATENATION:

Concatenation can be done like below:

lv_descript        = |{ text-001 } { gjahr } { space } { text-002 } { space } { monat }|.

5. READ table TRANSPORTING NO FIELDS for checking existence of values:

For validating a particular data in an internal table, we normally use ‘Read table….with key…..’ and then check sy-subrc value. Now can combine and check at one go like:

if line_exists( Sales_order_inter_table [  ordertype = ’ZOR’ ] ).
*******add your statement here******
Endif.

Isn’t this pretty simple and useful? Try to use the above for checking error or success for BAPI return messages, you will like it.

6. FILTERING data to an internal table:

Ever thought of doing something as below avoiding read and moving the workarea data with matching key-fields from one internal table to another?

it_mseg_item = value #( base it_mseg_item
                             for wa_stpo in it_stpo_temp
                            ( matnr  = wa_stpo-idnrk
                              werks    = wa_stpo-werks
                              lgort  = wa_stpo-lgort
                              menge = wa_stpo-menge
                             meins = wa_stpo-meins) ).

Try ‘except’ to get the other non-matching set.

7. NESTed field assignment at one go, how about it as below:

wa_collect-matnr  = it_vbap[  vbeln = wa_filedata-vbeln 
                                                       posnr= wa_filedata-posnr  ]-matnr.

8. APPENDING to internal table:

For appending data from workarea to an internal table we normally pass all the field data to the workarea-fieldname and then append workarea to internal table. Again we can combine and write at one go. Here we go!!!!

append value #(  werks = wa_vbap-werks 
                                 matnr = wa_vbap-matnr )
                            to  it_internaltable3.

9. APPENDING with conditions:

We can even hard-code values or add conditions within the same statement like something as below, interesting right?

Append value #(  werks = wa_vbap-werks 
                                 matnr = wa_vbap-matnr 
                                 flag = cond #( wa_sales_item-kwmeng gt 0
                                        then ‘Y’
                                          else ‘N’ )
                                ) to  it_internaltable3.

Above are some of the commonly used syntax in Modern ABAP. Try to use them in your projects. They are not HANA DB dependent. If you have the right service pack, you may start using it in ECC too.

Comments Please

You may look more ABAP 7.4 Syntax in this Complete YouTube Playlist at our YouTube Channel.

Please follow our LinkedIn Page,LinkedIn Group, Facebook Page, Facebook Group, Twitter , Instagramand Telegram SAP Technical Group.

Do not forget to SUBSCRIBE to our YouTube Channel for Free Courses and Unconventional Interesting Videos.

Also consider joining SAPYard’s Telegram Channel for SAP Blogs and Tutorials.

Save our number +1-251-727-9273 and send us a Whatsapp message ‘LEARN’ to be part of our Learning Community.

Check All ABAP Programming for SAP HANA Tutorials

Also Check Business Application Studio Tutorials

LEAVE A REPLY

Please enter your comment!
Please enter your name here