Showing posts with label ABAB Coding. Show all posts
Showing posts with label ABAB Coding. Show all posts

Monday, 12 October 2015

ABAP Program to Convert Value Stored In a Variable to UPPER/LOWER Case

In general, most of the time in SAP, we may need to convert the value of the String or Character field (say name, city, etc..) to UPPER case of to LOWER case.

We can achieve the functionality using the simple ABAP syntax provided by SAP.

Syntax:
Assuming the P_STR is a variable which is of type STRING or CHAR (C).

To Convert to UPPER case:
To convert value stored in the P_STR to UPPER case, we can use the below syntax.
TRANSLATE p_str TO UPPER CASE.

To Convert to LOWER case:
To convert value stored in the P_STR to LOWER case, we can use the below syntax.
TRANSLATE p_str TO UPPER CASE.

Program:
REPORT  ZVTEST_PGM_1.

*--Parameter for User Input
PARAMETERSp_str TYPE string.

*--Convert to Upper Case
TRANSLATE p_str TO UPPER CASE.
*--Print Value in Output
WRITE:'Upper Case Value : 'p_str.

*--Convert to Lower Case
TRANSLATE p_str TO LOWER CASE.
*--Print Value in Output
WRITE:'Lower Case Value : 'p_str.

================================
Save & Activate.

Enter the input string ("VENUgopal NanjaPPA") & execute (F8).


Below is the converted output.

Thanks & Regards,
Venugopal M Nanjappa

Sunday, 13 October 2013

ABAP Runtime Environment

SAP BASIS provides the runtime environment for the ABAP code. All ABAP programs reside inside the SAP database. 

In the database all ABAP code exists in two forms:
  • Source Code - which can be viewed and edited with the ABAP Workbench tools
  • Generated code - which is a binary code generated after activation of the source code


ABAP programs execute under the control of the runtime system, which is part of the SAP kernel

Features of the Runtime
  • It is part of the SAP kernel
  • Responsible for processing ABAP statements
  • Controlling the flow logic of screens
  • Responding/Handling to events to events
  • Convert the database-independent ABAP statements (Open SQL) to database specific (Native SQL) statements

SAP ABAP - Introduction

ABAP (Advanced Business Application Programming) is a high-level programming language created by the German software company SAP in 1980s. It is one of the many application-specific fourth-generation languages
It was originally the report language for SAP R/3, a platform that enabled large corporations to build business applications for easy of their business.

Features of ABAP
  • The language is case-insensitiveand each statement terminates with a period.
  • It programming language used to develop programs (Reports, Function modules) on the SAP R/3 client-server platform.
  • It is used by the SAP customers to develop their custom reports and interfaces with ABAP programming
  • The language is easy to learn for programmers, Knowledge of relational database (RDBMS) is necessary to create ABAP programs
  • Also Knowledge of object-oriented concepts is necessary to explore advanced concept, Since SAP released an object-oriented extension to ABAP along with release 4.6.
  • ABAP was one of the first languages to include the concept of Logical Databases (LDBs), which provides a high level of abstraction from the basic database level(s).
  • Most of the SAP R/3 basic application and functionalities are developed using ABAP

Advantages of SAP
  • SAP supports various database in back end
  • Platform Independent
  • Supports multiple languages
  • Faster between network

SAP ABAP - Best Coding practices

Following are the some of the best practices which ABAP developer should take care to achieve optimal performance.

1.       Avoid writing select query on a same table more than once
Since the retrieval of the data from the database take most of the processing time, it is better to fetch the required data from the table and store it in a internal table for further processing

2.       Refreshing the internal tables. Clearing variables & structures
In the custom program, before using the declared internal tables, work area& variables initialize them to default values. Use CLEAR statement for variables &work area. Use REFRESH statement for internal tables

3.       Clearwork area at the end of every LOOP pass
In order to avoid the problems such as carryover of the values of some field of work area corresponding to the last loop pass to the next loop pass, we need to clear the work area at the end of every LOOP pass.

4.       Avoid using the MOVE-CORRESPONDING
Compiler has to search & map the corresponding fields in case of MOVE-CORRESPONDING statement, hence it impact the performance. So, it is better to go for individual field assignment in case of copying the work area content to other inside the LOOP.

5.       Release the memory occupied by internal tables &work area
At the end of the program uses FREE statement to release the memory occupied by the internal tables, work area& internal tables.

6.       Avoid hard coding
Declare the CONSTANTS & use them in the program instead of hard coding the values.

7.       Check SY-SUBRC value after SELECT , READ statements
Putting the appropriate set of code based on the value of the sy-subrc after SELECT or READ statement enhances the performance & helps in avoiding execution of the unwanted code

8.       Check for internal table (it_tab) IS NOT INITIAL before using FOR ALL ENTRIES
Before using FOR ALL ENTRIES in the select statements, it is best practice to check does the table in the in the FOR ALL ENTRIES is having some values, else it result in fetching 0 records.

9.       Remove the unused constants, variables, work area& internal tables from the program
Unused constants, variables, work area & internal tables are the dead codes in the program. So, by removing the dead codes we can improve the performance of the code & make the code more readable.

10.       Avoid LOOP on the same internal table more than once
Try to include the required logic inside the same LOOP in order to enhance the performance.

11.       Avoid declaring the internal tables with header line
Declare separate work area to process the records of the internal table. By doing this one can avoid the chances of not clearing the header line in case of internal table with header line.

12.       SORT the internal table before using BINARY SEARCH in the READ statement.
READ statement fails to read the entry from the table if you are using BINARY SEARCH on unsorted internal table. So, SORT the internal table by the key fields which you are using in the READ statement.

13.       Place the most probable condition in the IF statement
This enhances the performance of the code when processing large amount of data.