String Commands in ABAP

Below are some of the common and handy commands for manipulating strings in ABAP.

CONCATENATE

To join multiple strings together into one string.

DATA u(10) TYPE C VALUE 'Rust'.
DATA v(10) TYPE C VALUE 'Iron'.
DATA w(10) TYPE C VALUE 'Brown'.
DATA str(30) TYPE  C.
CONCATENATE u v w INTO str.
CONCATENATE u v w INTO str SEPARATED BY '***'.
SPLIT

To separate a given string into multiple sub strings

DATA str(30) TYPE C VALUE 'Rust Iron Brown'.
DATA: u(10) TYPE C,
              v(10) TYPE C,
               w(10) TYPE C.
SPLIT str AT ',' INTO u v w.
WRITE: / u,
       / v,
       / w.
TRANSLATE

To convert a given string from one form to another form

TRANSLATE str TO LOWER CASE.
TRANSLATE str TO UPPER CASE.
TRANSLATE str USING 'AXBY'.

in the above example, all occurrences of A in str are replaced by X and B in str are replaced by Y.

SEARCH

to search for substring in a main string.

SEARCH str for 'AD'.  // it is not case sensitive.

In the above example if substring ‘AD’ is existed in main string str then SY-SUBRC will become 0 otherwise

SY-SUBRC will become 4.

Moreover

SY-FDPOS maintains the offset value of the substring to search for substring in a main string.

FIND

To search for substring in a main string.

FIND 'AD' IN str.

It is case sensitive.

SY-FDPOS doesn’t work.

OFFSET CONCEPT IN STRINGS
  • This concept is used to extract or modify substrings of a given main string
  • OFFSET indicates position of a character in a string
  • OFFSET of 1st character is 0.
  • OFFSET of 2nd character is 1 and so on.
DATA W(20) TYPE C VALUE 'INFINITY'.
WRITE W+2(3). //here the output is 'FIN'.

this is the example of extracting substring from the main string here 2 indicates OFFSET of the substring and 3 indicates number of characters.

remember here ‘+’ is not an addition operator. Observe no spaces in both the sides.

W+3(2) = '99'.
WRITE W.

Here the output is INF99ITY

This is an example for setting substring of main string.

Courtesy: ABAP  technical documentation

 

Goods Transportation Reports in BW/BI

Report Name Description Comments
Lane Deficiency Report Report points out actual transit times per lane and compares it against transit tables in source system such as R3 where transportation details are stored
Deployment Scorecard Measures lane cost, mode cost, line haul costs, load factor, mode mix, short lead %, – Weekly, monthly &  yearly view. Data from the Freight Cost Detail & Accrual Tables in the source
Freight Scorecard monthly/yearly network resupply orders.  Measures linehaul, fuel, accessories and volume against AOP and then illustrates the cost variance & impact Data from the Freight Cost Detail & Accrual Tables in the source
Delivery Scorecard monthly/yearly network sales orders.  Measures linehaul, fuel, accessories and volume against AOP and then illustrates the cost variance & impact Data from the Freight Cost Detail & Accrual Tables in the source
On Time Delivery Summary Report / Carrier Scorecard Measures on time delivery at a weekly, monthly and yearly level.
Carrier Revenue Report Fiscal Month/Fiscal Year view of spend by carrier.  Measures spend on line haul, fuel, accessories.
TRACK Cost Per Mile Report Report Measures TRACK Cost Per Mile

Courtesy: Project related generic documents

Declarative Statements in ABAP

These statements define data types or declare data objects which are used by the other statements in a program or routine.

Ex:

TYPES, DATA, TABLES, CONSTANTS, FIELD-SYMBOLS, PARAMETERS, SELECT-OPTIONS

Constants  This keyword is for declaring constant identifiers.

CONSTANTS PI TYPE P DECIMALS 3 VALUE ‘3.147’.

Constants cannot be modified in the further program.

Field-Symbols These are similar to pointers in C language. Used for referring to any type of data object in a program.

FIELD-SYMBOLS: <FS1>, <FS2>.

DATA:  A TYPE I, str(20) TYPE C.

ASSIGN  A TO <FS1>.

WRITE <FS1>.    //Value of A will be displayed

ASSIGN STR TO <FS1>.

WRITE <FS1>.   //Value of STR will be displayed.

Types This keyword is used to define new user defined data types.

TYPES FLOATING TYPE P DECIMALS 6.

DATA A TYPE FLOATING.

DATA B TYPE FLOATING.

Tables This keyword is used to create a structure in RAM corresponding to a database table.

TABLES: mara, vbrk.

Type-Pools This keyword is used to attach a Data Dictionary (DDIC) type group to the current program. Type Group is a central repository object that maintains definitions of user defined data types.

TYPE-POOLS SLIS.              //Used in ALV Reporting

TYPE-POOLS SSCRFIELDS.     //Used for selection screen.

 

Courtesy: ABAP Technical Documentation

System Fields in ABAP

All the below system fields belong to the data dictionary (DDIC) Structure – SYST.

SY-INDEX for loop counting
SY-SUBRC condition of previous statement
SY-FDPOS position of substring in main string (works with SEARCH)
SY-ABCDE a string of 26 characters
SY-ULINE for horizontal lines of any length
SY-VLINE for only one vertical character
SY-DATUM for application server’s date
SY-UZEIT for application server’s current time
SY-DATLO for Presentation server’s date
SY-TIMLO for Presentation server’s current time
SY-DBSYS backend database name
SY-HOST name of application server
SY-SYSID name of the R/3 system
SY-OPSYS name of application server’s operating system
SY-MANDT Logon client number
SY-UNAME Logon User name
SY-LANGU Logon language
SY-MSGID message class name
SY-MSGNO message number
SY-MSGTY message type
SY-MSGV1 message variable 1
SY-MSGV2 message variable 2
SY-MSGV3 message variable 3
SY-MSGV4 message variable 4
SY-LSIND secondary list index
SY-PAGNO current page number
SY-LINSZ current width of a line
SY-LINCT current number of lines per page
SY-TABIX index of internal table’s record
SY-DBCNT no. of records processed by database statement
SY-DYNNR current screen number
SY-REPID current program name
SY-TITLE title of the program
SY-PFKEY name of the current GUI status
SY-UCOMM funtion code of the current pushbutton or menu option

Courtesy: ABAP Technical Documentation

BW Related ABAP – SELECT-OPTIONS and RANGES

Both Ranges and Select-Options are used for maintaining Ranges.

  • Select-Options are used for taking input from user on selection screen
  • In case of Select-Options system itself creates an internal table
  • In case of Ranges, the internal table should be defines explicitly
  • The internal table contains four fields- Sign, Option, Low and High.
  • Special operator IN is used in comparisons.
SIGN

The data type of SIGN is C with Lengh 1. Possible values are I and E.

  • I stands for “inclusive” (operators are not inverted)
  • E stands for “exclusive” (operators are inverted)
OPTION

The data type of OPTION is C with length 2. OPTION contains the selection operator.

The following operators are available:

  • if HIGH is empty, you can use EQ, NE, GT, LE, LT, CP and NP.
  • if HIGH is filled, you can use BT (Between) and NB (Not Between)
LOW

To maintain lower limit of range.

HIGH

To maintain higher limit of range.

Ex:

SELECT-OPTIONS range_ex FOR sy-index.

SELECT-OPTIONS matno FOR mara-matnr.

RANGES docu_num FOR likp-vbeln.

Example Program:

REPORT.
TABLES SCARR.
RANGES EX FOR SCARR-CARRID.
*--filling RANGES with a single value
EX-SIGN = 'I'.
EX-OPTION = 'EQ'.
EX-LOW = 'UA'.
APPEND EX.
SELECT * FROM SCARR WHERE CARRID IN EX.
WRITE:/ SCARR-CARRID, SCARR-CARRNAME.

 

 

SAP BI Business Content

This post describes generic standards and guidelines that apply to the use of standard BI objects delivered by SAP as part of the BI business content. Again, these may change as per your client’s BW system standards.

Activating Business Content

Anyone with access to the sandbox may activate business content there. If you activate content in sandbox, make sure that you do not activate the content in the background (batch mode.) Instead, activate the content in the foreground and always keep any existing customization for the objects you activate.

No one except the people allowed may activate business content in SAP BW development system.

 

If you need business content activated, contact one of those people and explain what you need activated. Continue reading “SAP BI Business Content”

SAP BW Back-End Usage Standards and Guidelines

Write ­Optimized DataStore Objects

Consider the following important facts in mind before you choose to use a Write Optimized DataStore Object:

  1. The primary unique key to a WODS Object consists of Request ID, Data Packet ID, and Record Number. The system does not use the semantic key as the primary, unique key to the data. This means that each time you load a particular semantic key into a WODS Object, you get a new, unique record.
  2. Write ­Optimized DataStore Objects do not aggregate data. If you extract and load two records with the same logical key (or extract and load the same record twice,) both records appear in the WODS Object.
  3. No delta detection or extraction function exists for WODS Objects. When forwarding data to subsequent data targets, the system will forward the requests (loads) that have not yet moved to those targets. Note, however, that this can result in duplicate rows going to the subsequent target.

Continue reading “SAP BW Back-End Usage Standards and Guidelines”

BW Data Retention / Archival and Space Management Guidelines

This post provides guidelines for managing space in the SAP BW Production environment in general. It describes these guidelines in the context of generic business intelligence goals, principles, and architecture.

 

Principles of Data Warehousing Data Retention:

Data warehouses exist to serve as the “information memory” of an enterprise. Data warehouses record all the critical business transactions conducted by an enterprise, so decision makers and business strategists can leverage the information to meet their goals and objectives.

 

The Value of Historical Information:

The business intelligence team must ensure that information captured in the data warehouse supports both the current, known requirements for analyses, but also supports the future, unknown requirements.

Low ­level, historical transaction data captures information about past behavior of the enterprise that no other source of information provides. When we delete this data, we eliminate forever the ability of the enterprise to leverage the knowledge contained in the raw data. If we summarize data and delete the original details, we eliminate forever the ability to produce alternate summaries of that data. Continue reading “BW Data Retention / Archival and Space Management Guidelines”

Designing and Building Secondary Indexes on DataStore Objects

This post describes best practices for building appropriate secondary indexes on DataStore Objects.

General guidelines for placing secondary indexes on DataStore Objects:

  1. The presence of secondary indexes on an DataStore Object can greatly improve query performance, but it may slow down load performance.
  2. If your application does not have routine, frequent reads or reports on a DataS­tore Object, do not build secondary indexes on it.

 

Designing Secondary Indexes:

Apply these general guidelines when determining the number and structure of secondary indexes on DataStore Objects: Continue reading “Designing and Building Secondary Indexes on DataStore Objects”

BW Development Standards Part 10: Flat File Management Guidelines

The standards and guidelines in this post apply to situations where you must move flat files into the BW environment and load them through the BW flat file interface. You may only load from flat files when you absolutely cannot use the BW Service API, the DB Connect interface, or the Universal Data Connect interface to extract data into BW.

File Locations on the BW System:

As part of your solution implementation, you need to ask the Basis team to create at least one file system directory for your application’s flat files. You should request a folder under the following path;

/usr/sap/interfaces/…..

NOTE: Refer your client’s SAP BW Naming Convention document for the details to follow naming convention.

 

Managing Flat Files in BW Process Chains

The BI Technology group has developed four custom process types to help you manage flat files in BW. You can find these process types under “General Services” in the Process Chain Maintenance tool. Their icons and descriptions appear below:

12

Each of these process types can perform its process on either the local BW system or on a remote system accessible from the BW server via ftp. In addition, each process type allows branching to one of two subsequent processes based on success or failure.

Standards Continue reading “BW Development Standards Part 10: Flat File Management Guidelines”