SQL Server administration and T-SQL development, Web Programming with ASP.NET, HTML5 and Javascript, Windows Phone 8 app development, SAP Smartforms and ABAP Programming, Windows 7, Visual Studio and MS Office software
Development resources, articles, tutorials, code samples, tools and downloads for SAP HANA and ABAP, HANA Database, SQLScript, SAP UI5, Screen Personas, Web Dynpro, Workflow


ABAP Tutorial - SAP Split and ABAP Split String Function


If you are an ABAP developer developing code in SAP ABAP string functions are frequently used like ABAP split string operations.
SAP split string or splitting string using ABAP split operator can be managed using two methods.
The two SAP split variants are using variables and using ABAP internal table for storing splitted string values.

ABAP programmers can see how split string functions are used in below sample ABAP program.
First method uses SPLIT ... AT ... INTO ABAP command and stores outcome or splitted string fragments directly into string variables. This method is suitable, if the ABAP developer is only interested in first n splitted string data.
The second method uses the same ABAP SPLIT command with one difference. In the second usage of SAP function, the output result is stored in an internal table. So the programmers can loop through the ABAP internal table and read every splitted string fragment.

REPORT Z_TEST_SPLIT .

TYPES :
  BEGIN OF gty_Modules,
    Module(25) TYPE C,
  END OF gty_Modules.

DATA :
  gs_Modules TYPE gty_Modules,
  gt_Modules TYPE TABLE OF gty_Modules.

DATA :
  Seperator(1) TYPE C VALUE ',', " Delimeter or Seperator
  ListOfSAPModules(2000) TYPE C,
  FirstModule(200) TYPE C,
  SecondModule(200) TYPE C,
  ThirdModule(200) TYPE C,
  FourthModule(200) TYPE C,
  FifthModule(200) TYPE C.

START-OF-SELECTION.

" SPLIT Syntax : Split using variables
" SPLIT InputString AT SeperatorInCType INTO SplittedString1..n.

ListOfSAPModules = 'Sales and Distribution,Warehouse Management,Controlling,Payroll,Customer Service'.
SPLIT ListOfSAPModules AT Seperator INTO FirstModule SecondModule ThirdModule FourthModule FifthModule.

WRITE 'ABAP Split String using Variables'.
WRITE FirstModule.
WRITE SecondModule.
WRITE ThirdModule.
WRITE FourthModule.
WRITE FifthModule .
WRITE :/.

" SPLIT Syntax - Split using internal table
" SPLIT f AT g INTO TABLE itab.

WRITE 'ABAP Split String using Internal Table'.
SPLIT ListOfSAPModules AT Seperator INTO TABLE gt_Modules.
LOOP AT gt_Modules INTO gs_Modules.
  WRITE :/ gs_Modules-Module.
ENDLOOP.

END-OF-SELECTION.
Code

Here is the output of the above ABAP split string sample code. I hope the split code in this ABAP tutorial is useful for programmers.

ABAP split string code



SAP HANA and ABAP

Install SAP Free
CRM Companies List
Web Based CRM Software


Copyright © 2004 - 2021 Eralper YILMAZ. All rights reserved.