4 Useful Tips on ABAP and ABAP on HANA

In this short article, I would like to present only 3 tips which I found very interesting in SAP ABAP for HANA and one tip on normal ABAP which is very useful.

1. COALESCE function in Open SQL

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. If both argument 1 and 2 are null, then the next argument arg3 value is returned. A blank space must be placed after the opening parenthesis and before the closing parenthesis. A comma must be placed between the arguments.

Tip: Blank is not Null. If a row does not exist at all then it can be Null. But if a row exists, but some fields are blank, then those blank fields are not Null.

Example-

SELECT so_id,
so~gross_amount AS so_amount,
inv_head~gross_amount AS inv_amount,
" potential invoice amount
COALESCE( inv_head~gross_amount, so~gross_amount )
AS expected_amount
FROM snwd_so AS so
LEFT OUTER JOIN snwd_so_inv_head AS inv_head
ON inv_head~so_guid = so~node_key
INTO TABLE @DATA(li_result).

Output –

SELECT lfa1~lifnr,
lfa1~name1,
ekko~ebeln,
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.

Output

In this example, if the LIFNR has PO created, then the Vendor Number is printed, else, literal ‘No PO’ is printed on the Vendor Column. Hope you understand, blank/space is not NULL.

2. How to get a list of all the keyboard shortcuts in HANA Studio?

  • Go to -> Help -> Key Assists
  • Alternately, press CTRL+SHIFT+L to get the list of Keyboard Shortcuts.

3. Pinning Option for code element documentation in HANA Studio

You can pin down the code element documentation ( Key F2 ) by selecting the ‘@‘ button present in the popup as shown below.

The details will be shown in ABAP Element Info View for your reference.

4. How to retrieve the deleted program in SE38?

We have, most of the ABAPers know this tip by now. If not, then try the below steps to retrieve a deleted program.

  • Create a program with the same name as earlier (which is deleted)
  • Click on “Utilities” –> “Versions” –> “Version Management”
  • Select the version of your earlier program and click on display
  • Your earlier program is displayed here

Tip – The deleted program must have been saved in a transport previously. Try, if you can retrieve a deleted program which was created as a local object.