SAP ABAP 7.4 INLINE DECLARATION

SAP ABAP 7.4 INLINE DECLARATION

In SAP ABAP 7.4 inline declarations are a new feature that allows you to declare and define data objects directly withing SELECT statements and loops, making your code more concise and readable. In this article we will look how inline declaration works.

Inline declaration makes your code more readable and reduce the need for extensive variable declaration at the beginning of your programs. They are especially helpful when working with smaller, temporary variables that are only needed within a specific scope.

SAP ABAP 7.4 INLINE DECLARATION

1. INLINE DECLARATION WITH JOIN AND CASE KEYWORD.

You can declare variable within the SELECT statement using the “@data” syntax. This is particularly useful when database to variables without the need for separate variable declarations.

One of the most welcomed features of ABAP 7.4 is the introduction of inline declarations within SELECT statements and loops. This syntax improvement allows developers to define data objects directly within these statements, reducing the need for separate declaration and making the code more compact and readable.

SELECT DISTINCT
p1~pernr,
p1~ename,
p1~persg,
p1~persk,
p1~orgeh,
p1~plans,
p1~werks,
p0~begda,
p0~endda,
p0~stat2,
p0~massn,
p22~ausbi,
p22~endda AS edate,
p2~zzcategory,
p2~gbdat,
t1~ausgr,
t2~gtext,
t3~orgtx,
t4~stext,
t5~atext,
a~zelb_year AS lV_YEAR,
CASE WHEN stat2 = ‘3’ THEN ‘Active’ END AS lv_status,
CASE WHEN persg = ‘A’ THEN ‘Executive’
WHEN persg = ‘C’ THEN ‘Non Executive’ END AS lv_empg
FROM pa0001 AS p1
INNER JOIN pa0000 AS p0 ON p0~pernr = p1~pernr AND p0~stat2 = ‘3’ “AND p0~massn = ‘Z1’ “AND p0~massn = ‘Z4’
AND p0~endda = ‘99991231’
LEFT OUTER JOIN pa0022 AS p22 ON p22~pernr = p1~pernr
LEFT OUTER JOIN pa0002 AS p2 ON p2~pernr = p1~pernr
LEFT OUTER JOIN t518e AS t1 ON t1~ausbi = p22~ausbi
LEFT OUTER JOIN t518c AS t2 ON t2~ausgr = t1~ausgr AND langu = ‘E’
LEFT OUTER JOIN t527x AS t3 ON t3~orgeh = p1~orgeh
LEFT OUTER JOIN t518b AS t5 ON t5~ausbi = p22~ausbi AND t5~langu = ‘E’
LEFT OUTER JOIN hrp1000 AS t4 ON t4~objid = p1~plans AND t4~endda = ‘99991231’
INNER JOIN zhrt_prom_elgb AS a ON a~old_persk = p1~persk AND a~slabs = p22~slabs “AND a~sltp1 = p22~sltp1 AND a~sltp2 = p22~sltp2
INTO TABLE @DATA(lt_data)
WHERE p1~pernr IN @s_pernr
AND p1~werks IN @s_werks
AND p1~endda = ‘99991231’
AND p0~massn IN (‘Z1′,’Z4’)
AND p1~persg IN @lr_persg.

2. INLINE DECLARATION WITH JOIN AND SELECT FOR ALL ENTRIES.

SELECT a~pernr,b~anred,b~vorna,b~nachn,b~gbdat,b~gesch,b~natio,b~famst,b~konfe,
         c~stras,
         d~bankn,d~iban,d~bankl,d~zlsch,d~emftx,d~waers,
         e~cttyp,e~prbzt,e~kdgfr,e~begda,
         f~homap
         FROM pa0000 AS a INNER JOIN pa0002 AS b
          ON ( a~pernr = b~pernr )
        INNER JOIN pa0006 AS c ON ( a~pernr = c~pernr )
        INNER JOIN pa0009 AS d ON ( a~pernr = d~pernr )
        INNER JOIN pa0016 AS e ON ( a~pernr = e~pernr )
        INNER JOIN pa3255 AS f ON ( a~pernr = f~pernr )
        INTO TABLE @DATA(lt_emp) FOR ALL ENTRIES IN @lt_pernr
        WHERE a~pernr = @lt_pernr-pernr
        AND a~endda = ‘99991231’
        AND b~endda = ‘99991231’
        AND c~endda = ‘99991231’
        AND d~endda = ‘99991231’
        AND e~endda = ‘99991231’
        AND f~endda = ‘99991231’.

SAP ABAP 7.4 INLINE DECLARATION
SAP ABAP 7.4 INLINE DECLARATION

3. VALUE KEYWORD WITH INLINE DECLARATION.

APPEND VALUE #( sign = ‘I’ option = ‘EQ’ low = p_persg  ) to data(lr_persg).

4. INLINE DECLARATION IN LOOPS.

You can also use inline declarations within LOOPS or FOR statements.

IF gt_final-custom_flow_ids IS NOT INITIAL.
    LOOP AT gt_final-custom_flow_ids INTO DATA(ls_final).
      gs_data-cf_id = ls_final.
      CLEAR ls_final.
      APPEND gs_data TO gt_data.
    ENDLOOP.
  ENDIF.

SAP ABAP 7.4 INLINE DECLARATION

5. INLINE DECLARATION IN FOR LOOP.

Declarations within a ‘FOR’ loop in SAP ABAP 7.4. This allows you to declare loop-specific variables directly within the loop statement. Here’s an example of how to use inline declarations in a ‘FOR’ loop.

 TYPES: BEGIN OF ty_psgroup,
           pernr TYPE persno,
           trfgr TYPE trfgr,
         END OF ty_psgroup,
         tt_psgrp TYPE TABLE OF ty_psgroup WITH EMPTY KEY.

DATA(lt_psgrp) = VALUE tt_psgrp( FOR gs_zemp IN gt_zemp
                                  ( pernr = |{ gs_zemp-employee_id ALPHA = IN }|
                                  trfgr = gs_zemp-ps_group ) ).

SAP ABAP 7.4 INLINE DECLARATION
SAP ABAP 7.4 INLINE DECLARATION

You May Also Like:

For the next blog please connect with us and follow us on twitter.com/einfonett

Leave a Comment

%d bloggers like this: