You are on page 1of 6

MILAN VICTOR – SAP ABAP CONSULTANT MILLU138@GMAIL.

COM

New ABAP Syntax for S4HANA


1. FOR ALL ENTRIES:

The FOR ALL ENTRIES statement in SAP ABAP is used for efficient database queries when selecting
data from a database table based on a list of specified keys. It allows you to avoid multiple database
accesses by selecting all relevant data in one go. Here's a basic overview of how to use FOR ALL
ENTRIES.

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.

2. MOVE CORRESPONDING:
It can transfer data between structures and work areas based on the corresponding field names.
data(wa_data1) = corresponding #( wa_data ).

3. CONVERSIONS ROUTINE:
This conversion routine is used to convert the data from SAP format to output format and output
format to SAP Format.
Conversion Input:
data(lv_matnr) = |{ wa_file_data-matnr alpha = in }|.

Conversion Outout:
data(lv_vbeln) = |{ wa_file_data-vbeln alpha = out }| .

4. CONCATENATION:
In SAP ABAP, the CONCATENATE statement is used to concatenate strings or fields into a single
string. The basic syntax of the CONCATENATE statement is as follows:
lv_descript = |{ text-001 } { gjahr } { space } { text-002 } { space } { monat }|.

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

In SAP ABAP, the READ TABLE statement can be used to check the existence of values in an internal
table without transferring any fields to the work area. When using TRANSPORTING NO FIELDS with
READ TABLE, it allows you to perform a simple existence check without copying any data to a target
structure.

if line_exists( Sales_order_inter_table [ ordertype = ’ZOR’ ] ).


*******add Logic here******
Endif.
MILAN VICTOR – SAP ABAP CONSULTANT MILLU138@GMAIL.COM

Note:
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:
This statement is to filter data in an internal table based on a specified condition.

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) ).
Note: Try ‘except’ to get the other non-matching set.

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


This allows you to assign values to nested fields in a single statement.
Wa_collect-matnr = it_vbap[ vbeln = wa_filedata-vbeln
posnr= wa_filedata-posnr ]-matnr.

8. APPENDING to internal table:


Its Used to Append the values to the internal table
append value #( werks = wa_vbap-werks
matnr = wa_vbap-matnr )
to it_internaltable3.

9. APPENDING with conditions:


It’s Used to Append the values to the Intern Table based on the condition
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.

10. Loop with append:


This Statement is used to Apprnd the values to the internal table based on FOR loop.
TYPES: lr_vehi1 TYPE STANDARD TABLE OF selopt WITH EMPTY KEY.

data : lr_vehi TYPE lr_vehi1.

SELECT equnr, eqart FROM equi CLIENT SPECIFIED


MILAN VICTOR – SAP ABAP CONSULTANT MILLU138@GMAIL.COM

INTO TABLE @DATA(gt_equi)


WHERE mandt = @sy-mandt
AND equnr IN @so_zvehn
AND ( eqart LIKE '%_PR’' OR eqart LIKE '%3%10%' ).

lr_vehi = VALUE lr_vehi1( FOR ls_equi IN gt_equi


( sign = 'I'
Option = 'EQ'
low = ls_equi-equnr ) ).

11. Data Type Declaration:


data declarations are used to define variables and data structures that are used in your program
DATA(lv_vehicle) = 'Mercedes'.
Before:
DATA: lv_rows TYPE i.
lv_rows = LINES( itab)
After:
DATA(lv_rows) = LINES( itab ).

12. Using The “NEW” Constructor Operator in ABAP:

In ABAP, the NEW constructor operator is used to dynamically create instances of objects. This is
commonly used with object-oriented programming in ABAP.

Before:
DATA lo_human TYPE REF TO class_human.
CREATE OBJECT lo_human EXPORTING NAME = 'TONY'.

After:
lo_human = NEW class_human( name = ‘TONY’ ).

13. Using The “VALUE” Constructor Operator:


In SAP ABAP, the VALUE constructor operator is used to create or initialize data objects directly
within the ABAP code. It is often used in combination with data declarations or inline declarations to
provide initial values to variables. The VALUE operator is versatile and supports different types of
data objects such as elementary data types, structures, and internal tables.

t_itab i TYPES TYPE STANDARD TABLE OF WITH DEFAULT KEY.


Before:
Data : itab type t_itab.
append : 10 to itab,
20 to itab,
MILAN VICTOR – SAP ABAP CONSULTANT MILLU138@GMAIL.COM

30 to itab.

After:
DATA(itab) = VALUE t_itab( ( 10 ) ( 20 ) ( 30 ) ).

14. Using the “FOR” Iteration Expression:


In SAP ABAP, the FOR-iteration expression is used for loop constructions. It allows you to iterate
over a range of values or a table and perform operations within the loop. The syntax and usage of
the FOR expression can vary depending on the context.

Before:
APPEND LINES OF lt_itab1 TO lt_itab2.
lt_itab2[] = lt_itab1[].

After:
FOR wa| IN itab [INDEX INTO idx] [cond]

Before :
TYPES: BEGIN OF ty_ship,
tknum TYPE tknum,
name TYPE ernam,
city TYPE ort01,
route TYPE route,
END OF ty_ship.

TYPES: ty_ships TYPE SORTED TABLE OF ty_ship WITH UNIQUE KEY tknum.
TYPES: ty_citys TYPE STANDARD TABLE OF ort01 WITH EMPTY KEY.

DATA: gt_citys TYPE ty_citys,


gs_ship TYPE ty_ship,
gs_city TYPE ort01.

LOOP AT gt_ships INTO gs_ship.


gs_city = gs_ship-city.
APPEND gs_city TO gt_citys.
ENDLOOP.

After:
DATA(gt_citys) = VALUE ty_citys( FOR ls_ship IN gt_ships ( ls_ship-city ) ).

Before with conditions:


DATA: gt_citys TYPE ty_citys,
gs_ship TYPE ty_ship,
gs_city TYPE ort01.
MILAN VICTOR – SAP ABAP CONSULTANT MILLU138@GMAIL.COM

LOOP AT gt_ships INTO gs_ship WHERE route = 'R0001'.


gs_city = gs_ship-city.
APPEND gs_city TO gt_citys.
ENDLOOP.

After with conditions:


DATA(gt_citys) = VALUE ty_citys( FOR ls_ship IN gt_ships
WHERE ( route = 'R0001' ) ( ls_ship-city ) ).

15. Using COND as a Replacement for IF/ELSE:


the COND expression is a more concise and modern way to express conditional logic, replacing
traditional IF/ELSE statements. It provides a more functional programming-style approach to
handling conditions.
Before:
DATA: lv_text(30).
IF lv_vehicle = '01' AND lv_type = 'C'.
lv_text = 'Toyota'.
ELSE.
Endif.

IF lv_vehicle ='02' AND lv_type = 'C'.


lv_text = 'Chevy'
ELSE.
Endif.

IF lv_vehicle ='03' AND lv_type = 'C'.


lv_text = 'Range Rover'.
ENDIF.

After:
DATA(lv_text) = COND text30(
WHEN lv_vehicle ='01' AND lv_type = 'C' THEN 'Toyota'
WHEN lv_vehicle ='02' AND lv_type = 'C' THEN 'Chevy'
WHEN lv_vehicle ='03' AND lv_type = 'C' THEN 'Range Rover').

16. Using SWITCH, a Replacement for CASE:


Before:
data: l_indicator like scal-indicator,
l_day(10) type c.

call function 'DATE_COMPUTE_DAY'


exporting
MILAN VICTOR – SAP ABAP CONSULTANT MILLU138@GMAIL.COM

date = p_date
importing
day = l_indicator.

case l_indicator.
when 1.
l_day = 'Monday'.
when 2.
l_day = 'Tuesday'.
when 3.
l_day = 'Wednesday'.
when 4.
l_day = 'Thursday'.
when 5.
l_day = 'Friday'.
when 6.
l_day = 'Saturday'.
when 7.
l_day = 'Sunday'.
else.
Raise exception type zcx_day_problem.
endcase.

After:
DATA(L_DAY) = SWITCH char10( l_indicator
when 1 THEN 'Monday'
when 2 THEN 'Tuesday'
when 3 THEN 'Wednesday'
when 4 THEN 'Thursday'
when 5 THEN 'Friday'
when 6 THEN 'Saturday'
when 7 THEN 'Sunday'
ELSE THROW zcx_day_problem( ) ).

17. Declaring Table Work Areas:


table work areas are used to hold data records when processing internal tables. Work areas are
declared to hold the data of individual records during table processing. Work areas are usually
defined with the same structure as the internal table they are associated with
READ TABLE lt_mara WITH KEY matnr = lv_matnr INTO DATA(ls_mara).
LOOP AT lt_mara INTO DATA(ls_mara).
FIELD-SYMBOLS
READ TABLE lt_mara WITH KEY matnr = lv_matnr ASSIGNING FIELD-SYMBOL().
LOOP AT lt_mara ASSIGNING FIELD-SYMBOL().

You might also like