Nothing Special   »   [go: up one dir, main page]

Sap Abap 7.4

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 15
At a glance
Powered by AI
The key takeaways are that variable, table, and object declarations have been simplified and standardized in SAP ABAP 7.4 with the introduction of inline declarations using the DATA keyword.

In SAP ABAP 7.4, variables are declared inline using the DATA keyword followed by parentheses instead of separately declaring the type and name. Tables can also be declared and looped on inline.

Examples include declaring and looping on table work areas, result parameters, and nested FOR loops to populate tables from other tables all inline with 7.4.

SAP ABAP 7.

4 Inline Declarations

Comparing OLD SAP Code and New SAP Code Declarations

Gopal Karmakar
Declaration of a variable

 Before 7.40  With 7.40


 DATA text TYPE string.  DATA(text) = `…`.
text = `…`.

 For example :
For Example :
 Data l_index TYPE sy-tabix.
Data(l_index) = sy-tabix.
 l_index = sy-tabix.
Declaration of table work areas

Before 7.40 with 7.40


 DATA : l_st_t024w TYPE t024w.  LOOP AT l_it_t024w INTO DATA(l_st_t024)
  ….
LOOP AT l_it_t024w INTO l_st_t024w ...
… ENDLOOP.
 …
ENDLOOP.
Declaration of a result & actual parameters

Before 7.40 With 7.40


 DATA xml TYPE xstring.  ALL TRANSFORMATION … RESULT XML
DATA(xml).
CALL TRANSFORMATION … RESULT
XML xml.

 oref->meth( IMPORTING p1 = DATA(a1)


 DATA a1 TYPE …
 IMPORTING p2 = DATA(a2)
 DATA a2 TYPE …
 … ).
 oref->meth( IMPORTING p1 = a1
 IMPORTING p2 = a2
 … ).
Declaration of reference variables for
factory methods
Before 7.40 With 7.40
 DATA: ixml TYPE REF TO if_ixml.  DATA(ixml) = cl_ixml=>create( ).
DATA: stream_factory TYPE REF TO

if_ixml_stream_factory. DATA(stream_factory) = ixml->
DATA: document TYPE REF TO create_stream_factory( ).
if_ixml_document.

 DATA(document) = ixml->create_document( ).
 ixml = cl_ixml=>create( ).
stream_factory = ixml->create_stream_factory( ).
document = ixml->create_document( ).
Declaration of a READ TABLE Statement

Before 7.4 With 7.4

 DATA(flight_schedule) = flight_schedules
READ TABLE flight_schedules INTO [carrid = 'AA' connid = '0017' ].
DATA(flight_schedule) WITH KEY
carrid = 'AA' connid
= '0017'.

lo_mara = zcl_mara_factory( ls_mara-matnr ).


Declaration of “NEW” Constructor
Operator
Before 7.4 With 7.4
 DATA lo_human TYPE REF TO  lo_human = NEW class_human(
class_human. name = ‘TONY’ ).
 CREATE OBJECT lo_human
EXPORTING NAME = 'TONY'.

 DATA: lv_rows TYPE i.


 lv_rows = NEW i( 0 ).
 lv_rows = 0.
Declaration of “VALUE” Constructor
Operator
Before 7.4 With 7.4
 TYPES: t_itab TYPE STANDARD  TYPES: t_itab TYPE STANDARD
TABLE OF i WITH DEFAULT KEY. TABLE OF i WITH DEFAULT KEY.

 DATA itab_o TYPE t_itab.


 APPEND: 10 TO itab_o,
 20 TO itab_o,  DATA(itab) = VALUE t_itab( ( 10 ) ( 20 )
 30 TO itab_o. ( 30 ) ).
Declaration of FOR LOOP

Before 7.4 With 7.4


 DATA: gt_citys TYPE ty_citys,  DATA(gt_citys) = VALUE ty_citys( FOR
ls_ship IN gt_ships
 gs_ship TYPE ty_ship,
WHERE ( route = 'R0001' ) ( ls_ship-city ) ).
 gs_city TYPE ort01.

 LOOP AT gt_ships INTO gs_ship


WHERE route = 'R0001'.
 gs_city = gs_ship-city.
 APPEND gs_city TO gt_citys.
 ENDLOOP.
Declaration of Range table
Before 7.4 With 7.4
 BEGIN OF ty_ekorg, TYPES: tt_t024w_range TYPE RANGE OF char10.
sign TYPE char1,
optn TYPE char2,
low TYPE ekorg, "( sign = 'I' option = 'BT' low = ‘3500' high = ‘….' )
high TYPE ekorg,
END OF ty_ekorg,
DATA(t_t024w_range) = VALUE tt_t024w_range
DATA: l_rt_ekorg TYPE STANDARD
( FOR ls_t024w IN l_it_t024w
TABLE OF ty_ekorg. LET s = ‘I’
 LOOP AT l_it_t024w INTO l_st_t024w. o = ‘EQ’
l_st_ekorg-sign = ’I’.
l_st_ekorg-optn = ’EQ’. IN sing = s
l_st_ekorg-low = l_st_t024w-ekorg. option = o
APPEND l_st_ekorg TO l_rt_ekorg.
( low = ls_t024w-ekorg ) ).
CLEAR : l_st_ekorg.
ENDLOOP.
Declaration of SELECT STATEMENT
Before 7.4 With 7.4
 TYPES: BEGIN OF ty_mara,
 SELECT matnr
 matnr TYPE matnr,

 ersda TYPE ersda,


 ersda
 ernam TYPE ernam,  ernam
 laeda TYPE laeda,
 laeda
 aenam TYPE aenam,

 END OF ty_mara.  aenam


 DATA: lt_mara TYPE STANDARD TABLE OF ty_mara.  FROM mara
 SELECT matnr
 INTO TABLE @DATA(lt_mara) UP TO 10
 ersda
ROWS.
 ernam

 laeda

 aenam

 FROM mara

 INTO TABLE lt_mara UP TO 10 ROWS.


Append value of 1 field into another table using FOR
 TYPES:  * FOR to get the column CITY
 BEGIN OF ty_customer,
 customer TYPE char10,  DATA(t_city) =
 name TYPE char30,  VALUE tt_citys(
 city TYPE char30,  FOR ls_cust IN t_customres
 route TYPE char10,  ( ls_cust-city )
 END OF ty_customer.  ).

 TYPES: tt_customers TYPE SORTED TABLE OF ty_customer


 WITH UNIQUE KEY customer.

 TYPES: tt_citys TYPE STANDARD TABLE OF char30 WITH EMPTY


KEY.
 DATA(t_customres) =
 VALUE tt_customers(
 ( customer = 'C0001' name = 'Test Customer 1' city = 'NY'
route = 'R0001' )
 ( customer = 'C0002' name = 'Customer 2' city = 'LA'
route = 'R0003' )
 ( customer = 'C0003' name = 'Good Customer 3' city =
'DFW' route = 'R0001' )
 ( customer = 'C0004' name = 'Best Customer 4' city = 'CH'
route = 'R0003' )
 ).
Nested FOR with 2 tables
 TYPES:  DATA(t_rc) =

 BEGIN OF ty_route_config,  VALUE tt_route_config(

 route TYPE char10,  ( route = 'R0001' c_type = 'RTYPE' c_value = 'DSD' )

 c_type TYPE char10,  ( route = 'R0001' c_type = 'MAX' c_value = '10' )

 c_value TYPE char40,  ( route = 'R0002' c_type = 'RTYPE' c_value = 'WH' )

 END OF ty_route_config.  ( route = 'R0002' c_type = 'MAX' c_value = '100' )

 TYPES: tt_route_config TYPE SORTED TABLE OF ty_route_config  ( route = 'R0003' c_type = 'RTYPE' c_value = 'WH' )

 WITH UNIQUE KEY route c_type.  ( route = 'R0004' c_type = 'RTYPE' c_value = 'DSD' )

 TYPES:  ).

 BEGIN OF ty_routes,

 route TYPE char10, * Nested FOR - 2 levels

 name TYPE char40, TYPES: tt_names TYPE STANDARD TABLE OF char40 WITH DEFAULT KEY.

 END OF ty_routes. DATA(t_route_names) =

 TYPES: tt_routes TYPE SORTED TABLE OF ty_routes VALUE tt_names(

 WITH UNIQUE KEY route. FOR ls_cust_1 IN t_customres

DATA(t_routes) = FOR ls_route IN t_routes WHERE ( route = ls_cust_1-route )

VALUE tt_routes( ( ls_route-name )

( route = 'R0001' name = 'Route 1' ) ).

( route = 'R0002' name = 'Route 2' )

( route = 'R0003' name = 'Route 3' )

).
Nested LOOP with multiple tables
* Nested FOR - 3 levels DATA(t_routes_max) =
TYPES: VALUE tt_routes_max(
BEGIN OF ty_routes_max, FOR ls_cust_2 IN t_customres
route TYPE char10, FOR ls_route_2 IN t_routes WHERE ( route =
ls_cust_2-route )
name TYPE char40,
FOR ls_rc_2 IN t_rc WHERE ( route =
c_value TYPE char40,
ls_route_2-route AND c_type = 'MAX' )
END OF ty_routes_max.
( route = ls_route_2-route
name = ls_route_2-name
TYPES: tt_routes_max TYPE STANDARD TABLE OF
c_value = ls_rc_2-c_value )
ty_routes_max WITH DEFAULT KEY.
).
LET with specific (and default) value with FOR
Here you can see the FOR is used with LET. The LV_NAME is read using the tabular expression or [ ]
from the table. The LV_ROUE is also read using the tabular expression but for only first row [1].

TYPES: DATA(t_routes_cust) =
BEGIN OF ty_routes_cust, VALUE tt_routes_cust(
route TYPE char10, FOR ls_cust_l IN t_customres
name TYPE char40,
INDEX INTO cust_index
customer TYPE char10,
"where ( customer = 'C0001' )
END OF ty_routes_cust.
LET lv_name = t_routes[ route = t_customres
TYPES: tt_routes_cust TYPE STANDARD TABLE OF [ cust_index ]-route ]-name
ty_routes_cust WITH DEFAULT KEY.
lv_route = t_routes[ 1 ]-route

*data(t_routes_cust) = IN name = lv_name


* value tt_routes_cust( route = lv_route
* for ls_cust_l in t_customres ( customer = ls_cust_l-customer )
* "where ( customer = 'C0001' ) ).
* let LV_NAME = 'teSTING name'
* LV_ROUTE = 'TESTING ROUTE'
* IN NAME = LV_NAME
* ROUTE = LV_ROUTE
* ( CUSTOMER = ls_cust_L-CUSTOMER )
* ).

You might also like