ERP Database - The Unofficial ERP Knowledge Base

Facebook Twitter del.icio.us Digg it
ERP Database contains a huge collection of articles related to ERP System and Software. Many of the articles are specifically related to SAP. All these ERP/SAP articles are freely available to everyone.

If you would like to submit an article or share any document related to ERP or any specific ERP software. Please mail it to support@erpdb.info. Please make sure that the documents are not copyrighted.
Social Bookmarks:

ABAP Programs: String Operations

Print This Post Email This Post Written by admin on Nov 12th, 2007 | Filed under: ABAP Programs

REPORT ZSOURCE0708.

* Concatenating strings without delimiter
DATA: FIRST_NAME(25), MIDDLE_NAME(2), LAST_NAME(25),
FULL_NAME(54).
FIRST_NAME = ‘John’.
MIDDLE_NAME = ‘F.’.
LAST_NAME = ‘Kennedy’.
CONCATENATE FIRST_NAME MIDDLE_NAME LAST_NAME INTO FULL_NAME.
WRITE / FULL_NAME.

* Concatenating strings with delimiter
DATA: DIRECTORY_1(2), DIRECTORY_2(10), FILE_NAME(10),
PATH(24).
DIRECTORY_1 = ‘a:’.
DIRECTORY_2 = ‘usr’.
FILE_NAME = ‘programs’.
CONCATENATE DIRECTORY_1 DIRECTORY_2 FILE_NAME
INTO PATH
SEPARATED BY ‘’.
WRITE / PATH.

* Splitting strings
DATA: LIST(40),
NAME_1(25), NAME_2(25), NAME_3(25).
LIST = ‘Edison,Smith,Young’.
SPLIT LIST AT ‘,’ INTO NAME_1 NAME_2 NAME_3.
WRITE: / NAME_1, NAME_2, NAME_3.

* Splitting strings with result in an internal table
DATA NAMES LIKE NAME_1 OCCURS 10 WITH HEADER LINE.
LIST = ‘Edison,Smith,Young,Edwards’.
SPLIT LIST AT ‘,’ INTO TABLE NAMES.
LOOP AT NAMES.
WRITE / NAMES.
ENDLOOP.

* Shifting strings by a fixed number of places
NAME_1 = ‘Edison’.
NAME_2 = ‘Smith’.
NAME_3 = ‘Young’.
SHIFT NAME_1.
SHIFT NAME_2 BY 3 PLACES.
SHIFT NAME_3 RIGHT.
WRITE: / NAME_1, NAME_2, NAME_3.

* Shifting strings up to a substring
NAMES = ‘Alexander Bill Charles’.
SHIFT NAMES UP TO ‘Bill’.
WRITE / NAMES.

* Shifting strings deleting blanks
NAMES = ‘Joanne___’.
SHIFT NAMES RIGHT DELETING TRAILING SPACE.
WRITE / NAMES.

* Replacing and translating characters in strings
DATA: STRING(80),
EXPRESSION(30).
STRING = ‘Variable: &. The variable & is substituted later.’.
REPLACE ‘&’ WITH ‘X’ INTO STRING.
WRITE / STRING.
TRANSLATE STRING USING ‘&X’.
WRITE / STRING.
EXPRESSION = ‘a ** 2 + b ** 2 = c ** 2′.
TRANSLATE EXPRESSION USING ‘axbycz’.
WRITE / EXPRESSION.

* Searching for strings in fields or internal tables
DATA TEXT(100) VALUE ‘Texas California New Mexico Louisiana Oregon’.
SEARCH TEXT FOR ‘California’.
IF SY-SUBRC NE 0. WRITE ‘Not found’. ENDIF.
SEARCH TEXT FOR ‘cAliforniA’.
IF SY-SUBRC NE 0. WRITE ‘Not found’. ENDIF.
SEARCH TEXT FOR ‘New M’.
IF SY-SUBRC NE 0. WRITE ‘Not found’. ENDIF.

* Working with parts of fields
DATA: S(8) VALUE ‘ABCDEFGH’,
T(8) VALUE ’12345678′,
OFF1 TYPE I, OFF2 TYPE I,
LEN1 TYPE I, LEN2 TYPE I.

OFF1 = 2.
LEN1 = 3.
OFF2 = 4.
LEN2 = 3.
MOVE S+OFF1(LEN1) TO T+OFF2(LEN2).
WRITE / T.

———————
ABAPer, mail: abap.community@gmail.com http://www.erpdb.info

Share

If you like this post, you may as well like these too:

  1. SM100 SAP Solution Manager for Operations of SAP Solutions SM100 SAP Solution Manager for Operations of SAP Solutions Download from Mediafire Table of Contents SAP Solution Manager Overview Customizing SAP Solution Manager - Solution Directory - Logical Components -...
  2. ABAP Source Code: Syntax of ABAP/4 Programs 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 * Declaration...
  3. ABAP Programs: Importing from the ABAP/4 Memory REPORT ZSOURCE1402. * Internal tables which will be imported DATA: ALL_CUSTOMERS LIKE CUSTOMERS OCCURS 100 WITH HEADER LINE, ALL_BOOKINGS LIKE BOOKINGS OCCURS 10 WITH HEADER LINE, NEW_BOOKINGS LIKE BOOKINGS OCCURS...
  4. ABAP Programs: Exporting to the ABAP/4 Memory REPORT ZSOURCE1401. * Work areas TABLES: CUSTOMERS, BOOKINGS. * Internal tables which will be exported DATA: ALL_CUSTOMERS LIKE CUSTOMERS OCCURS 100 WITH HEADER LINE, ALL_BOOKINGS LIKE BOOKINGS OCCURS 10 WITH...
  5. Ending ABAP Programs The execution of an ABAP program is always ended when the corresponding process in the runtime environment ends. From an ABAP programmer’s perspective, this is when the last of the...
  6. ABAP Programs for Beginners Here is the list of Programs available in the ABAP Master Code Book (PDF). How to define types and data objects A Few Simple Examples Working with database tables and...
  7. Some Cool Programs in ABAP and the link is :- http://www.kabai.com/abaps/q.htm...
  8. ABAP Programs: Using where clauses REPORT ZSOURCE1104.* Work areasTABLES: BOOKINGS, CUSTOMERS.* Internal tablesDATA CUSTOMER_ORDERS LIKE BOOKINGS OCCURS 100 WITH HEADER LINE.DATA ALL_CUSTOMERS LIKE CUSTOMERS OCCURS 100 WITH HEADER LINE.* Selecting data with a simple where...
  9. ABAP Programs: Using colors REPORT ZSOURCE0807. * Display the header using an appropriate color (grayish blue)WRITE ‘Header’ COLOR COL_HEADING. * Switch the standard colorFORMAT COLOR COL_TOTAL. * Make the color less brightWRITE / ‘total...
  10. Different types of ABAP Programs There are nine types of ABAP Programs in SAP: 1 Executable Programs (ABAP Reports) I INCLUDE Program M Module Pool/Dialogue programs S Sub-Routine Pool J Interface Pool K Class Pool...



Leave a Reply