100 likes | 277 Views
Introduction ABAP Strings. Introduction (Strings). There are three character-based data types c stores character fields of a fixed length n stores numeric character fields of a fixed length Fields that contain only number but are not really numeric (telephone number)
E N D
Introduction (Strings) • There are three character-based data types • cstores character fields of a fixed length • n stores numeric character fields of a fixed length • Fields that contain only number but are not really numeric (telephone number) • Data is right aligned and leading zeros are inserted • string stores variable length strings
String Declaration (Example) • Declare a two character string • DATA state TYPE c LENGTH 2. • TYPE LIKE and VALUE keywords continue to apply • DATA state TYPE c LENGTH 2 VALUE ‘nv’.
String Conversion • When converting a character string ‘c’ to a ‘n’ string, only the digits are copied • The field is right justified • The field is padded with leading zeros
String Operations • Remember that this is a business language • Strings are “padded” into fixed-length string fields • We can move characters in a string (SHIFT) • Replace substrings (REPLACE) • Pack and concatenate strings • Split strings
String Operations (SHIFT) • SHIFT varname [BY n PLACES] [mode] • Where mode is LEFT, RIGHT, or CIRCULAR • If n is omitted, the default value is 1 • If mode is omitted, the default mode is LEFT • Optional clause • DELETING [LEADING | TRAILING] str
String Operations (REPLACE) • REPLACE string1 IN varname WITH string2 • Replaces string1 WITH string2
String Operations (CONDENSE) • Deletes redundant spaces from a string • Leading spaces are deleted • NO-GAPS removes all spaces • CONDENSE c [NO-GAPS]
String Operations (CONCATENATE) • CONCATENATE c1 … cn INTO c [SEPARATED BY] s • Concatenates the list of strings into an output string • s is inserted as the character seperator
String Operations (SPLIT) • SPLIT c AT del INTO c1 … cn • Splits string c using the delimiter del into a list of variables • Ok, this is hokey. We need to provide enough output fields for the record.