0% found this document useful (0 votes)
28 views

Advanced ABAP Programming Compressed

The document discusses advanced ABAP programming techniques including efficient handling of string and text data using strings, regular expressions, and internal tables. It covers string value storage, sharing, and processing methods as well as recommendations for choosing string or character field data types.

Uploaded by

balapedada878
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

Advanced ABAP Programming Compressed

The document discusses advanced ABAP programming techniques including efficient handling of string and text data using strings, regular expressions, and internal tables. It covers string value storage, sharing, and processing methods as well as recommendations for choosing string or character field data types.

Uploaded by

balapedada878
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Visit WWW.SOFTBASIC.

NET - SAP Portal

CD3 5 1
Adva nc e d
ABAP Progra m m ing
Visit WWW.SOFTBASIC.NET - SAP Portal
Cont ribut ing Spe a k e rs

Ralph Benzinger
Developer, SAP

Thomas Jung
Product Manager, SAP

Björn Mielenhausen
Development Manager, SAP

© SAP AG 2006, SAP TechEd ’06 / CD 351 / 2


Visit WWW.SOFTBASIC.NET - SAP Portal
Le a rning Obje c t ive s

As a re sult of t his w ork shop, you w ill be a ble t o:

„ Deploy strings for efficient handling of text-based information


„ Harness regular expressions to process strings effectively
„ Utilize data references for type-agnostic programming
„ Work proficiently with internal tables
„ Employ dynamic statements in your reports

„ Benefit from new ABAP features of NetWeaver 2004s!

© SAP AG 2006, SAP TechEd ’06 / CD 351 / 3


Visit WWW.SOFTBASIC.NET - SAP Portal

Strings and Regular Expressions

Data References

Internal Tables

Dynamic Statements
Visit WWW.SOFTBASIC.NET - SAP Portal
Se que nt ia l Da t a T ype s in ABAP

Busine ss inform a t ion = se que nc e s of byt e s or c ha ra c t e rs


„ Customer names, addresses
„ Product numbers, dates, currencies
„ XML data
„ Natural language

Overview of sequential data types in ABAP

Character Special Byte

Fixed Size C D, T, N X

Variable Size STRING XSTRING


CSEQUENCE CLIKE

© SAP AG 2006, SAP TechEd ’06 / CD 351 / 5


Visit WWW.SOFTBASIC.NET - SAP Portal
Com pa rison of St rings a nd Fix e d-Size d Fie lds

Strings Fields

Length adjusted dynamically at Length fixed and preallocated


runtime

Max length of 2,000,000,000 Max length of 65,000

Trailing blanks are significant Trailing blanks are ignored

Backquote literals `stringlit` Straight quote literals 'fieldlit'

Substring idiom +offset(length) Subfield idiom +offset(length)


for read access only for read and write access

Some benefits that ABAP strings provide


„ Efficient management of string storage space
„ Automatic garbage collection
„ Automatic value sharing with copy-on-write

© SAP AG 2006, SAP TechEd ’06 / CD 351 / 6


Visit WWW.SOFTBASIC.NET - SAP Portal
St rings V a lue s

St ring va lue s a re st ore d se pa ra t e ly from va ria ble s in


m e m ory
DATA: BEGIN OF struc1, DATA: BEGIN OF struc2,
a(3) TYPE n, a(3) TYPE n,
b(10) TYPE c, b TYPE string,
c(3) TYPE n, c(3) TYPE n,
END OF struc1. END OF struc2.

struc1 is flat struc2 is deep

1 2 3 A B C D E F G H I J 4 5 6 1 2 3 string reference 4 5 6
Å a ÆÅ b ÆÅ c Æ Å a ÆÅ b ÆÅ c Æ

string value
A B C D E F G H I J
Decoupling of value and reference allows for
„ Efficient resizing of strings
„ Sharing of string values

© SAP AG 2006, SAP TechEd ’06 / CD 351 / 7


Visit WWW.SOFTBASIC.NET - SAP Portal
St ring St ora ge Alloc a t ion

M e m ory a lloc a t ion during a t ypic a l progra m run

DATA str TYPE string. string reference (8 bytes)

string header (16-32 bytes)

str = 'first'. f i r s t string value (variable)

str = 'second value'. d


s
a n
e v
o
c a
ot n
hl u
d
e er v at rl u
y e

SHIFT str BY 5 PLACES.


str = 'another try'.

str = 'a final value!'. a f i n a l v a l u e !

main memory

© SAP AG 2006, SAP TechEd ’06 / CD 351 / 8


Visit WWW.SOFTBASIC.NET - SAP Portal
St ring Sha ring

V a lue s m a y be sha re d by m ult iple st ring re fe re nc e s

DATA: str1 TYPE string, str1 references + headers


str2 TYPE string, str2
str3 TYPE string. str3

str1 = 'common'. o n

str2 = str1.
str3 = str2.
c o m m o n

SHIFT str2 BY 2 PLACES.

Unsharing Æ copy-on-write / lazy copy


„ Delays costly copying as long as possible

© SAP AG 2006, SAP TechEd ’06 / CD 351 / 9


Visit WWW.SOFTBASIC.NET - SAP Portal
Re st ric t ions on Subst rings

+offset(length)cannot be used to modify strings

DATA str TYPE string VALUE `strvalue`.

WRITE / str+3(4). " OK


str+3(4) = `x`. " would modify value

„ Use REPLACE instead

REPLACE SECTION OFFSET 3 LENGTH 4 OF str WITH `x`.

Field symbols cannot be used for substring access


„ Value changes would necessitate updating all assigned field symbols

FIELD-SYMBOLS <fs> TYPE any.

ASSIGN str+3(4) TO <fs>.


SHIFT str RIGHT BY 2 PLACES. " shifts char positions

© SAP AG 2006, SAP TechEd ’06 / CD 351 / 10


Visit WWW.SOFTBASIC.NET - SAP Portal
Whic h Da t a T ype t o Choose

Advantages of character fields


„ Easy to access (+off(len), flat structures)
„ No internal overhead for accessing value

Advantages of strings
„ Storage allocated dynamically

DATA custname TYPE c LENGTH ??.


READ DATASET dset INTO line.

„ Common values are shared

DATA customers TYPE TABLE OF cust_record.


" cust_record = ( name, street, city )

„ Trailing blanks are significant (may increase performance)


Checks 75 trailing
DATA c80 TYPE c LENGTH 80 VALUE 'hello'.
blanks for finding
CONCATENATE c80 'world' INTO c80. end of text

© SAP AG 2006, SAP TechEd ’06 / CD 351 / 11


Visit WWW.SOFTBASIC.NET - SAP Portal
St ring Dia gnost ic s

Display list of
largest strings

Goto ->

Display condition ->

Memory use

...de le t e d pa ge s from 1 3 t o 7 9
© SAP AG 2006, SAP TechEd ’06 / CD 351 / 12
Visit WWW.SOFTBASIC.NET - SAP Portal

- This is preview version -

Re a d m ore a bout t he c om ple t e SAP T e c hED 2 0 0 6 Book s a t

WWW.SOFTBASIC.NET

You might also like