Subscribe

RSS Feed (xml)



Powered By

Skin Design:
Free Blogger Skins

Powered by Blogger

Tuesday, October 12, 2010

faqs on ABAP Interview Tips and Questions

SAP TERMINOLOGY

Master data is a collection of information about a person or an object, e.g. a cost object, vendor, or G/L account. For example, a vendor master record contains not only general information such as the vendor's name and address, but also specific information, such as payment terms and delivery instructions. Generally for end users, master data is reference data that you will look up and use, but not create or change.

Transactional data is data related to a single business event such as a purchase requisition or a request for payment. When you create a requisition, for example, SAP creates an electronic document for that particular transaction. SAP gives the transaction a document number and adds the document to the transaction data that is already in the system. Whenever you complete a transaction in SAP, that is, when you create, change, or print a document in SAP, this document number appears at the bottom of the screen.

Workflow A routing tool in SAP that forwards documents for review or approval. For example, a requisition that needs to be approved is sent to the appropriate approver's inbox.Workflow is also used to route journal vouchers, credit card charges, and other documents in SAP.

Cost Object: A Cost Object collects expenses and revenues for a particular purpose, such as a research project. In SAP there are three types of cost objects: Cost Center, Internal Order, and WBS (Work Breakdown Structure) Element (see below for definition).

Cost Center: General or operating Cost Objects are known in SAP as Cost Centers. Cost Centers are budgeted on the fiscal year.

Internal Order: A non-sponsored Cost Object (for example, funding from the MIT Provost) used to track costs over periods other than fiscal years. Internal Orders are often created to track gifts or endowments at MIT.

WBS Element: WBS Elements are funded by outside sponsors and are used to track costs of a particular research project over the entire span of its activity. They may also be created to track other sponsored activities, such as gifts.

G/L Account: G/L accounts are also called Cost Elements in SAP. They are a classification by expense or revenue type. In the CO (Controlling) module of SAP, the term Cost Element is used. In the FI (Financial) module, the term G/L Account is used. These terms are used interchangeably for reporting, requisitions, and journal vouchers.

Database tables and open SQL Add a single record to a database table insert into values Inserting all lines from an internal table into a database table: insert from table Delete all records Select * from zmellemtab. delete zmellemtab. endselect. Deleting records using records from an internal table delete employees from table itab.


Q & A BASIS LAYER


What are the central interfaces of the R/3 system ?
- Presentation interface
Database interface
Operating system interface

Which interface controls what is shown on the p.c. ?
- Presentation interface

Which interface converts SQL requirements in the SAP development system to those of the database ?- Database interface

What is SAP dispatcher ?
- SAP dispatcher is the control agent which manages the resources for the R/3 applications.

What are the functions of dispatcher ?
- Equal distribution of transaction load to the work processes
Management of buffer areas in main memory Integration of the presentation levels
Organization of communication activies

What is a work process ?
- A work process is where individual dialog steps are actually processed and the work is done. Each work process handles one type of request.

Name various work processes of R/3 system ?
1) Dialog or Online ( processes only one request at a time )
2) Background ( started at a specified time ) 3) Update ( primary or secondary ) 4) Enque( lock mechanism ) 5) Spool ( generated online or during back ground processing For printing )

What are the types of Update requests ?
- An update request can be divided into one primary (V1) and several Secondary update components (V2). Time-critical operations are placed in V1 component and those whose timing are less critical are placed in V2 components. If a V1 update fails, V2 components will not be processed.

What are the roll and page areas ?
- Roll and page areas are SAP R/3 buffers used to store user contexts ( process requests ) . The SAP dispatcher assigns process requests to work processes as they are received. If the work process is unavailable the process requests are queued in the roll and page areas. Paging area holds data from the application programs. Roll area holds data from previous dialog steps and data that characterizes user.

What is a Spool request ?
- Spool requests are generated during dialog or background processing and placed in the spool database with information about the printer and print format. The actual data is placed in the Tem Se (Temporary Sequential objects).

What are the different database integrities ?
- Semantic integrity
- Relational integrity
- Primary key integrity
- Value set integrity
- Foreign key integrity and
- Operational integrity.


DATA DICTIONARY :


Type of a table or structure
The table type determines how the logical table description defined in the ABAP/4 Dictionary is reproduced on the database. There are the following table types:
transparent table
structure
append structure

For internal purposes, such as storing control data or update texts, there are in addition the following table types:

pooled table
cluster table
generated view structure

Transparent table There is a physical table on the database for each transparent table. The names of the physical tables and the logical table definition in the ABAP/4 Dictionary correspond. All business data and application data are stored in transparent tables.

Structure No data records exist in the database for a structure. Structures are used for the interface definition between programs or between screens and programs.

Append structure An append structure defines a set of fields which belong to another table or structure but which are treated in the correction administration as its own object. Append structures are used to support modifications.

Pooled table Pooled tables can be used to store control data (e.g. screen sequences, program parameters or temporary data). Several pooled tables can be combined to form a table pool. The table pool corresponds to a physical table on the database in which all the records of the allocated pooled tables are stored.

Cluster table Cluster tables contain continuous text, for example, documentation. Several cluster tables can be combined to form a table cluster. Several logical lines of different tables are combined to form a physical record in this table type. This permits object-by-object storage or object-by-object access. In order to combine tables in clusters, at least parts of the keys must agree. Several cluster tables are stored in one corresponding table on the database.

Generated view structure In activation a structure is generated for a view. This structure serves as interface for the runtime environment. It does not generally appear in the ABAP/4 Dictionary.

What is a Data Class?

The Data class determines in which tablespace the table is stored when it is created in the database. What is a Size Category? The Size category describes the probable space requirement of the table in the database. How Many types of size categories and data classes are there? There are five size categories (0-4) and 11 data classes, only three of which are appropriate for application tables:
- APPL0 - Master data (data frequently accessed but rarely updated)
- APPL1 - Transaction data (data that is changed frequnetly)
- APPL2 - Organisational data (customizing data that is entered when system is
configured and then rarely changed)

What are control tables?

The values specified for the size category and data class are mapped to database-specific values via control tables.

What is the function of the transport system and workbench organiser?

The function of the transport system and the Workbench Organizer is to manage any changes made to objects of the ABAP/4 Development Workbench and to transport these changes between different SAP systems.

What is a table pool?
A table pool (or pool) is used to combine several logical tables in the ABAP/4 Dictionary. The definition of a pool consists of at least two key fields and a long argument field (VARDATA).

What are pooled tables?
These are logical tables which must be assigned to a table pool when they are defined. Pooled tables can be used to store control data (such as screen sequences or program parameters).

What is a table cluster?
A table cluster combines several logical tables in the ABAP/4 Dictionary. Several logical rows from different cluster tables are brought together in a single physical record. The records from the cluster tables assigned to a cluster are thus stored in a single common table in the database.

Which objects are independent transport objects?
Domains, Data elements, Tables, Technical settings for tables, Secondary indexes for transparent tables,
Structures, Views,
Matchcode objects, Matchcode IDs, Lock objects.

What are the Data types of the external layer?
ACCP, CHAR, CLNT, CUKY,CURR, DATS, DEC, FLTP, INT1,INT2, INT4, LANG, LCHR,LRAW, NUMC, PREC, QUAN,RAW ,TIMS, UNIT, VARC.

What are the Data types of the ABAP/4 layer?

Possible ABAP/4 data types: C: Character. D: Date, format YYYYMMDD. F: Floating-point number in DOUBLE PRECISION (8 bytes). I: Integer. N: Numerical character string of arbitrary length. P: Amount or counter field (packed; implementation depends on hardware platform). S: Time stamp YYYYMMDDHHMMSS. T: Time of day HHMMSS. V: Character string of variable length, length is given in the first two bytes. X: Hexadecimal (binary) storage.

How can we set the tablespaces and extent sizes ?
You can specify the extent sizes and the tablespace (physical storage
area in the database) in which a transparent table is to be stored by setting the size category and data class.

What is a data dictionary ?
Data dictionary is a central source of data in a data management system. Its main function is to support the .It has details about

- What data is contained ?
- What are the attributes of the data ?
- What is the relationship existing between the various data elements ?

What functions does a data dictionary perform ?
In a data management system, the principal functions performed by the data dictionary are
- Management of data definitions
- Provision of information for evaluation
- Support for software development
- Support form documentation
- Ensuring that the data definitions are flexible and up-to-date.

A field containing currency amounts (data type CURR) must be assigned to a reference table and a reference field. Explain.

As a reference table, a system table containing all the valid currencies is assigned or any other table which contains a field with the currency key format. This field is called as reference field. The assignment of the field containing currency amounts to the reference field is made at runtime. The value in the reference field determines the currency of the amount.

What is the significance of Technical settings (specified while creating a table in the data dictionary) ?

By specifying technical settings we can control how database tables are created in the database. The technical settings allows us to - optimize storage space requiremnets
- table access behaviour
- buffering required
- changes to entries logged

What is the significance of Delivery Class ?
- The delivery class controls the degree to which the SAP or the customer is responsible for table maintenance
- whether SAP provides the table with or without contents.
- determines the table type. - determines how the table behaves when it is first installed, at upgrade, when it is transported, and when a client copy is performed.

What is the maximum number of structures that can be included in a table or structure
- Nine.

What are the two methods of modifying Sap standard tables ?
- Append Structures and
- Customizing Includes.


What is the difference between a Substructure and an Append Structure ?
- In case of a substructure, the reference originates in the table itself, in the forma of a statement .include... . - In case of an append structure, the table itself remains unchanged and the refrence originates in the append structure.
What are the two ways for restricting the value range for a domain ? - By specifying fixed values.
- By stipulating a value table.

What is a Match Code ?

Match Code is a tool to help us to search for data records in the system. Match codes are an efficient and user-friendly search aid where key of a record is unknown. What are the two levels in defining a Match Code ?
- Match Code object
- Match Code Id.

What is the maximum number of match code Id's that can be defined for one Match code object ?
- 36. A match code Id is a one character ID which can be a letter or a number.

Can we define our own Match Code ID's for SAP Matchcodes ?
Yes, the numbers 0 to 9 are reserved for us to create our own Match Code IDs for a SAP defined Matchcode object.

What is an Update type with reference to a Match code ID?
If the data in one of the base tables of a matchcode ID changes, the matchcode data has to be updated. The update type stipulates when the matchcode is to be updated and how it is to be done. The update type also specifies which method is to be used for Building matchcodes . You must specify the update type when you define a matchcode ID.

What are conversion routines ?
- Non standard conversions from display format to sap internal format and vice-versa are implemented with so called conversion routines.
Aggregated Objects Views, matchcodes, and lock objects are also called aggregate objects because they are formed from several related tables.

What is a View ?
- A view is a logical view on one or more tables. A view on one or more tables i.e, the data from a view is not actually physically stored instead being derived from one or more tables. A view can be used to summarize data which is distributed among several tables

How many types of Views are there ? - Database View (SE11)
Database views are implement an inner join, that is, only records of the primary table (selected via the join operation) for which the corresponding records of the secondary tables also exist are fetched. Inconsistencies between primary and secondary table could, therefore, lead to a reduced selection set. In database views, the join conditions can be formulated using equality relationships between any base fields. In the other types of view, they must be taken from existing foreign keys. That is, tables can only be collected in a maintenance or help view if they are linked to one another via foreign keys.

- Help View ( SE54)
Help views are used to output additional information when the online help system is called. When the F4 button is pressed for a screen field, a check is first made on whether a matchcode is defined for this field. If this is not the case, the help view is displayed in which the check table of the field is the primary table. Thus, for each table no more than one help view can be created, that is, a table can only be primary table in at most one help view.

- Projection View

Projection views are used to suppress or mask certain fields in a table (projection), thus minimizing the number of interfaces. This means that only the data that is actually required is exchanged when the database is accessed. A projection view can draw upon only one table. Selection conditions cannot be specified for projection views.

- Maintenance View ( SE54 )

Maintenance views enable a business-oriented approach to looking at data, while at the same time, making it possible to maintain the data involved. Data from several tables can be summarized in a maintenance view and maintained collectively via this view. That is, the data is entered via the view and then distributed to the underlying tables by the system.


What is Locking ?
- When two users simultaneously attempt to access the same data record, this is synchronised by a lock mechanism.
When dialog transactions are programmed, locks are set and released by calling certain function modules. These function modules are generated automatically from the definition of so-called lock objects in the ABAP/4 Dictionary. To synchronize the access to a table by setting and removing locks, a Lock object has to be defined in the ABAP/4 Dictionary. Activating the lock object automatically creates #function modules for setting and removing locks. These function modules must be included when programming interactive transactions.

Lock Mechanism : To set locks, a lock object must be defined in the ABAP/4 Dictionary. In this lock object, those tables in which data records are to be locked by calling a lock are determined. All tables included in a lock object must be connected to each other via foreign keys. The key fields of the tables in a lock object form the Lock arguments for the tables. The lock arguments are the basis for formulating the logical condition for identifying the records to be locked. When activating this lock object, two function modulesB with the names ENQUEUE_ and DEQUEUE_ are generated.

Example :
Problem :
You wish to prevent a user from being able to change the name of a course or the name of the professor with responsibility for the course at a time when another user is editing the course description (which contains this information).

Solution : The problem described above can be solved by defining a lock object E_UKURS. This is done by defining primary and secondary tables in the lock object. Table UKURS is check table of table UKRSB, so UKURS should be selected as primary table and UKRSB as secondary table of the lock object. The Lock argument in this case is the field combination FABNR, KRSNR, and SPRAS (i.e Primary Key Combination). The Lock mode Shared is to be selected here. This allows several users to access the data simultaneously in display mode. The lock mode in the generated function modules for setting (ENQUEUE_E_UKURS) and releasing (DEQUEUE_E_UKURS) locks is therefore set to shared as default, but can be overridden by calling the function modules. If the function module ENQUEUE_E_UKURS is called with FABNR = '1' and KRSNR = '3', the record for course 3 in faculty 1 is locked in table UKURS. Furthermore, all the course descriptions for this course are locked in table UKRSB since field SPRAS was not specified when the function module was called. In such cases, the lock is made generically for a field which is not defined. If the function module DEQUEUE_E_UKURS is now called with FABNR = '1', KRSNR = '3' and SPRAS = 'D', the German course description is unlocked. All other course descriptions remain locked.

What is database utility ?
-
Database utility is the interface between the ABAP/4 Dictionary and the underlying the SAP system.
The database utility is the interface between the ABAP/4 Dictionary and the relational database underlying the SAP system. You can call the database utility from the initial screen of the ABAP/4 Dictionary with Utilities ® Database utility. The database utility allows you to create, delete and convert objects from the ABAP/4 Dictionary in the database. MODULARIZATION What is Modularization and its benefits? If the program contains the same or similar blocks of statements or it is required to process the same function several times, we can avoid redundancy by using modularization techniques. By modularizing the ABAP/4 programs we make them easy to read and improve their structure. Modularized programs are also easier to maintain and to update.

How can we create callable modules of program code within one ABAP/4 Program?
A. By defining macros. B. By creating include programs in the library.

What are subroutines?
Subroutines are program modules which can be called from other ABAP/4 programs or within the same program.

What are the types of Subroutines?
A. Internal Subroutines: The source code of the internal subroutines will be in the
same ABAP/4 program as the calling procedure (internal call).
B. External Subroutines: The source code of the external subroutines will be in an
ABAP/4 program other than the calling procedure.

What are the different types of parameters?
Formal parameters: Parameters which are defined during the definition of subroutine with the FORM statement. Actual parameters: Parameters which are specified during the call of a subroutine with the PERFORM statement.

How can one distinguish between different kinds of parameters?
A. Input parameters are used to pass data to subroutines. B. Output parameters are used to pass data from subroutines.

What are the different methods of passing data?
A. Calling by reference: During a subroutine call, only the address of the actual
parameter is transferred to the formal parameters. The formal parameter has no memory of its own, and we work with the field of the calling program within the subroutine. If we change the formal parameter, the field contents in the calling program also change.
B. Calling by value: During a subroutine call, the formal parameters are created as
copies of the actual parameters. The formal parameters have memory of their own. Changes to the formal parameters have no effect on the actual parameters.
C. Calling by value and result: During a subroutine call, the formal parameters are
created as copies of the actual parameters. The formal parameters have their own memory space. Changes to the formal parameters are copied to the actual parameters at the end of the subroutine.
The method by which internal tables are passed is By Reference.

What is the difference between the function module and a normal ABAP/4 subroutine?

In contrast to normal subroutines function modules have uniquely defined interface. Sub routines do not return values.
Sub routines do not return exceptions. Sub routines cannot be tested independently. Declaring data as common parts is not possible for function modules. Function modules are stored in a central library. What is a function group? A function group is a collection of logically related modules that share global data with each other. All the modules in the group are included in the same main program. When an ABAP/4 program contains a CALL FUNCTION statement, the system loads the entire function group in with the program code at runtime. Every function module belongs to a function group.

What is the difference between internal tables and extract datasets?

A. The lines of an internal table always have the same structure. By using extract
datasets, you can handle groups of data with different structure and get statistical figures from the grouped data.
B. You have to define the structure of the internal table at the begining. You need
not define the structure of the extract dataset.
C. In contrast to internal tables, the system partly compresses extract datasets
when storing them. This reduces the storage space required.
D. Internal tables require special work area for interface whereas extract datasets
do not need a special work area for interface.


LOGICAL DATABASE

What are logical databases?
What are the advantages/disadvantages of logical databases? Ans :- A Logical Database is a hierarchical structure of tables. Use the GET statement to process Logical Databases. - LDB consists of logically related tables grouped together ­ used for reading and processing data.
- Advantages = 1. No need of programming for retrieval , meaning for data selection
- 2. Easy to use standard user interface, have check completeness of user input.
Disadvantages = 1. Fast in case of lesser no. of tables But if the table is in the lowest level of hierarchy, all upper level tables should be read so performance is slower.

Preparation of the data records by the L.D.B and reading of the data records in the actual report are accomplished with the command pair.
- Put and Get.

The three main elements of LDB are - Structure, Selections, Database Program.

What sort of tables one can use in designing the hierarchy of a LDB ?
- Tables which are having Foreign key relations.

The structure of Logical Databases relfects the ________________ dependencies of hierarchical tables in the SAP System.
- Foreign key

If you want to improve the response time ( time to access data ) Logical DataBases permits you to achieve this using ______________
- VIEWS.

What are the advantages of Logical DataBases ?
- It offers an easy-to-use selection screen.
You can modify the pre-generated selection screen to your needs. It offers check functions to check whether user input is complete, correct, and plausible.
It offers reasonable data selections.
It contains central authorization checks for database accesses.
Enhancements such as improved performance immediately apply to all report programs that use the logical database.
Report FORMATTING In order to suppress the leading zeros of a number field the keywords used are : NO-ZERO. The Command that allows for vertical alignment of fields one below the other. UNDER. In order to concatenate strings only for output purposes the command _________ can be used in conjunction with the 'Write' statement. NO-GAP. Data can be moved from one field to another using a 'Write:' Statement and stored in the desired format. TRUE. Write : Date_1 to Date_2 format DD/MM/YY. In order to have boldfaced text as output the command used is Write : INTENSIFIED. Background and foreground colors can be interchanged using the command Format inverse. Which datatype cannot be used to define parameters. Type F. For each new event, the system resets all formatting options to their default values. TRUE.

The processing block following END-OF-PAGE is processed only if you reserve lines for the footer in the LINE-COUNT option of the REPORT statement.
To execute a page break under the condition that less than a certain number of lines is left on a page is acheived by ________________________. RESERVE n lines. What is the limit for the length of a page if the page length is not specified in the report statement. 60,000 Lines. How can Symbols or R/3 icons be output on the screen? WRITE AS SYMBOL. WRITE AS ICON.

REPORTING - GENERAL What are reports? and how do you set up reports? A report program reads and analyzes data from one or more database tables without modifying the database. Usually, the result of such a report program is in the form of a list which is output to the screen or sent to a printer. What are the different types of programs?
I Include Program
M Module Pool
F Function Modules
S External Subroutines
1 Online program

Events in Reporting ? Explain ?
The following events occur at runtime of a typical report program which uses logical databases: Event keyword
Event

-- INITIALIZATION
Point before the selection screen
is displayed
When you start a program in which a selection screen is defined (either in the program itself or in the linked logical database program), the system normally processes this selection screen first. If you want to execute a processing block before the selection screen is processed, you can assign it to the event keyword INITIALIZATION.

AT SELECTION-SCREEN
Point after processing user input on the selection screen while the selection screen is still active
The event keyword AT SELECTION-SCREEN provides you with several possibilities to carry out processing blocks while the system is processing the selection screen.

START-OF-SELECTION
Point after processing the selection screen
The event START-OF-SELECTION gives you the possibility of creating a processing block after processing the selection screen and before accessing database tables using a logical database. You can use this processing block, for example, to set the values of internal fields or to write informational statements onto the output screen. At the START-OF-SELECTION event, also all statements are processed that are not attached to an event keyword except those that are written behind a FORM-ENDFORM block .

GET

Point at which the logical database offers a line of the database table
The most important event for report programs with an attached logical database is the moment at which the logical database program has read a line from a database table (see Accessing Data Using Logical Databases ). To start a processing block at this event, use the GET statement as follows:

Syntax

GET


[FIELDS ].


[FIELDS ]. After this statement, you can work with the current line of the database table

. The data is provided in the table work area


GET LATE

Point after processing all tables which are hierarchically subordinate to the database table


in the structure of the logical database.
To start a processing block at the moment after the system has processed all database tables of a logical database that are hierarchically inferior to a specific database table, use the event keyword GET as follows:

Syntax :

GET


LATE [FIELDS ]


In analogy to report programs that use only SELECT statements (see table in Comparison of Access Methods ), the processing block of a GET LATE

statement would appear directly before the ENDSELECT statement in the SELECT loop for the database table

.
END-OF-SELECTION

Point after processing all lines offered by the logical database.
To define a processing block after the system has read and processed all database tables of a logical database, use the keyword END-OF-SELECTION. The following events occur during the processing of the output list of a report program: Event keyword

Event

-----------------------------------------------------------------------------------------------

TOP-OF-PAGE
Point during list processing when a new page is started
END-OF-PAGE

Point during list processing when a page is ended
The following events occur during the display of the output list of a report program: Event keyword

Event


--AT LINE-SELECTION
Point at which the user selects a line


AT USER-COMMAND
Point at which the user presses a function key or enters a command in the
command field.


AT PF
Point at which the user presses the function key with the function code
PF


With the selection screen, ABAP/4 offers an interactive element also for report programs. You can define a selection screen without having to bother about all the details required in dialog programming. The selection screen is always processed directly after a report program is started. The user can enter field values and selection criteria on this screen. The main purpose of the selection screen is to enable the user to control the database selections of the report program. If a report program is started from another ABAP/4 program with the SUBMIT statement (see Calling Reports), the selection screen objects also serve as a data interface, With a selection screen defined in the report program, you can enable the user to ·
assign values to variables with the PARAMETERS statement
·
determine selection criteria with the SELECT-OPTIONS statement


How do you read selected lines of database table into an internal table in packages of predefined size?.


SELECT * FROM INTO TABLE PACKAGE SIZE .
where 'n' is variable.
Name the WILDCARD characters which are used for comparisions with character strings & numeric strings.
'%' and '_'.


How to specify a client for database table processing.

TABLES SPFLI.
SELECT * FROM SPFLI CLIENT SPECIFIED
WHERE MANDT BETWEEN '001' AND '003'.
...
ENDSELECT.


Activation ­ During activation, the runtime object of aggregate object or tables is created. The runtime object is buffered so that the application program can access it quickly. Runtime object has information about the following objects of table - domain ­ data elements ­ field definition ­ table definition

Lock Mechanism ­ prevents a new database operation being started an existing one has been correctly completed. When conversion is done, lock is created automatically and released only when conversion is successful. Clearing of locks ­ restart adjustment ­ attempt is made to continue conversion at the point of
termination
Cancel adjustment ­ lock entry is simply deleted from table

Version Management functions ­

- Canceling changes ­ reset revised version to active version
- Storing changes ­ active version will be temporarily stored in version
Switching changes ­ switch between active and revised versions

Version catalog ­ list of all existing versions of an object

- Revised version ­ produced when we edit an existing object
- Active version ­ produced when we activate an object
- Temporary version ­ produced when we copy the active version temporarily to the database with store version functions
- Historical versions ­ created when 1. Correction is created 2 correction is
released

Table Buffering : Possible buffering types

- full buffering ­ either, whole table or none of the table is located in the buffer (Tables up to 30 kb done in client dependent fully buffered tables)
- Generic buffering ­ generic areas of the table are fully buffered.
- Generic key ­ left justified section of primary key of a table.
Single record buffering ­ records actually being accessed are loaded to buffers, large records where few records are accessed.


Internal Tables ? Types ?

STANDARD table Key access to a standard table uses a linear search. This means that the time required for a search is in linear relation to the number of table entries. You should use index operations to access standard tables.

SORTED table Defines the table as one that is always saved correctly sorted. Key access to a sorted table uses a binary key. If the key is not unique, the system takes the entry with the lowest index. The runtime required for key access is logarithmically related to the number of table entries.

HASHED table Defines the table as one that is managed with an internal hash procedure You can only access a hashed table using the generic key operations or other generic operations ( SORT, LOOP, and so on). Explicit or implicit index operations (such as LOOP ... FROM oe INSERT itab within a LOOP) are not allowed.

INDEX table A table that can be accessed using an index. Index table is only used to specify the type of generic parameters in a FORM or FUNCTION. That means that you can't create a table of type INDEX. Standard tables and sorted tables are index tables.

Syntax : DATA itab TYPE table type of line type [WITH UNIQUE/NON-UNIQUE KEY ] [Iinitial size n] [WITH HEADER LINE]

What are DATA CLUSTERS ?

You can group any complex internal data objects of an ABAP/4 program together in data clusters and store them temporarily in ABAP/4 memory or for longer periods in databases. You can store data clusters in special databases of the ABAP/4 Dictionary. These databases are known as ABAP/4 cluster databases and have a predefined structure.Storing a data cluster is specific to ABAP/4. Although you can also access
cluster databases using SQL statements, only ABAP/4 statements are able to decode the structure of the stored data cluster.


Describe the functions of the debugger screen.

- Single step(F5) - Use this option to step through the program statement by statement. This allows you to branch into subroutines and function modules, and to execute these routines step by step as well. Once a subroutine or function module has been processed, control returns to the statement following the CALL FUNCTION or PERFORM statement.


- Execute(F6)- Use this option to process a program line by line. All of the statements on the current line are processed in a single step. If you are positioned on a line that calls a subroutine and you choose Execute, the Debugger processes the whole subroutine and then moves on to the line following the subroutine call. This allows you to jump through the statements within the subroutine.


- Return(F7) - The Debugger returns from a routine to the point at which control returns to the main program. Use this option to return from a subroutine, function module, or called program to the calling program.


- Continue(F8)- Use this option to process the program up to the next dynamic or static breakpoint or up to the cursor position. If there are no more breakpoints in the program and no cursor has been set, the system exits debugging mode and executes the rest of the program normally.


- Tables - Display the contents of internal tables.

Problem:How to run a program in background?

Solution :Execute the Report In the selection screen :After filling the screen fields press F9. A screen appears requesting U to print the Background Parameters *Enter the output device(Eg HPLJ /SAP2 etc) *In the spool options Uncheck Print immedietly,Uncheck delete after output,and new spool request. Press enter. Another screen appears with heading start time .U can press start immly ,then save Now the Background job is scheduled for the given program .
To View the status of background Job,The transaction code is SM37. Execute from the resulting screen . Job overview -->From the Job list select U'r program and select Spool from the application toolbar Output Controller :List of Spool Requests Select U'r Spool request and click Display icon from the overview screen . U will be displayed with the List. Caution :See to that the list with does not exceed 255 columns ,If it exceeds the extra columns will be truncated in Background



What are presentation and application servers in SAP?

A presentation server is actually a program named Sapgui.exe. It is usually installed on a user's workstation. Application server is a set of executables that collectively interpret the ABAP/4 programs and manage the input & output for them.

In an ABAP/4 program how do you access data that exists on a presentation server v/s on an application server?

For presentation server use UPLOAD or WS_UPLOAD function modules. For application server use OPEN DATASET, READ DATASET and CLOSE DATASET commands.


Describe the syntax and function of the AUTHORITY CHECK command?

Ans :- AUTHORITY ­ CHECK OBJECT

ID FIELD ID FIELD ... IF SY-SUBRC NE 0. The AUTHORITY-CHECK checks whether a user has the appropriate authorization to execute a particular activity.


Dialog Programming FAQ

1) Why do I need to do dialog programming?
Ans: to have your own customized screens and processing

2) What does dialog programming consist of ?
Ans: Screens with their corresponding processing code, Menu , module pool program

3) Difference between the normal report / program and Module pool program?
Ans: Normal report can be run straight away by executing it and useually has a selection criteria – Attributes : 1 online program
Module pool program cannot be run straight away. It first needs to display a screen – attributes : M module pool program

4) What is PBO and PAI?
Ans: Process before output. Code that is executed prior to the display of a screen.
Process after input. Code that is executed after a button on the screen has been pressed.

5) How can I identify which button is pressed?
Ans: “ fcode” attributes of the button. Define the okcode value of the screen (type sy-ucomm)

6) What is the GUI interface to the program?
Ans: The menu bar where you define the ok-codes of the buttons and function keys for the screen. You typically code SAVE, BACK, CANC, EXIT and then more specific codes. CANC (leave to screen 0) allows you to get out of the current screen.

7) What does PAI and Pbo contain by default?
Ans: PBO - MODULE STATUS_0100 - Key / button definitions
PAI - * MODULE USER_COMMAND_0100 - How do you handle thecode behind the button that was pressed

8) If we do not have / give menu bar than what will menu bar have by default?
Ans: Not much -> system , help

9) How many PBO and PAI modules are allowed for a screen?
Ans: one PBO and one PAI

10) In the menu bar can you associate a function key to a button?
Ans: yes

This Document Provides Answers to Frequently Asked Questions About:


Starting the debugger in a modal screen

Usually in ABAP, when you want to start the debugger from a certain point, you just have to write "/H" in the

command window. But if you are in a modal screen or in a message display, you cannot write the traditional

"/H", here is how to do it :

  1. Open notepad and paste these lines in a document : [FUNCTION] Command=/H Title=Debugger Type=SystemCommand

  2. Save this document anywhere on your local pc. ex: c:\breakpoint.txt

  3. Drag&drop this file from the explorer to your ABAP modal screen.... et voila !!

Retrieving field names dynamically

Sometimes you may have only a table name and want to retrieve the name of each field of the corresponding table. For example, when you want to use ASSIGN COMPONENT fieldname OF TABLE table.

An ABAPer's first reaction is to read the standard ABAP basis tables DD02L, DD03L, etc

This way of reading fields is very slow. Use methods from the class CL_ABAP_TYPEDESCR instead.

Example:

data: descr_struc_ref TYPE REF TO cl_abap_structdescr.

descr_struc_ref ?= cl_abap_typedescr=>describe_by_name('SFLIGHT' ).

Here is the result of descr_struct_ref after the execution of this piece of code

ABSOLUTE_NAME C 200 \TYPE=SFLIGHT

TYPE_KIND C 1 u

LENGTH I 4 80

DECIMALS I 4 0

KIND C 1 S

STRUCT_KIND C 1 F

COMPONENTS h 8 Table[14x40]

HAS_INCLUDE C 1

The table COMPONENTS is filled with :

LENGTH DECIMALS TYPE_KIND NAME

3 | 0 |C |MANDT

3 | 0 |C |CARRID

4 | 0 |N |CONNID

8 | 0 |D |FLDATE

etc.

You have the fields name and a lot more information about the table. This class can also handle structure, table type, etc.

Note that this method is very fast because it uses the database layer directly thanks to SYSTEM CALLs.

To have a look at the class, use transaction SE24.


Restricting the selection screen

When you create a select-option for an input to your program, for each field, the default selection screen looks like this:

And the default possible selections are:

but sometime you don't want to give the user the possibility to select a range, select values "greater than", etc.
     
Here is a small example on how to do it:
     
REPORT ZDANY_RESTRICT_SELECTION.
     
* Include type pool SSCR
    TYPE-POOLS sscr.
    TABLES : sflight.
     
* defining the selection-screen
    select-options :
        s_carrid for sflight-carrid,
        s_connid for sflight-connid.
     
* Define the object to be passed to the RESTRICTION parameter
    DATA restrict TYPE sscr_restrict.
     
* Auxiliary objects for filling RESTRICT
    DATA :     optlist TYPE sscr_opt_list,
                    ass type sscr_ass.
     
    INITIALIZATION.
* Restricting the carrid selection to only EQ and 'BT'.
    optlist-name = 'OBJECTKEY1'.
    optlist-options-eq = 'X'.
    optlist-options-bt = 'X'.
    APPEND optlist TO restrict-opt_list_tab.
     
    ass-kind = 'S'.
    ass-name = 'S_carrid'.
    ass-sg_main = 'I'.
    ass-sg_addy = space.
    ass-op_main = 'OBJECTKEY1'.
    APPEND ass TO restrict-ass_tab.
     
* Restricting the connid selection to CP, GE, LT, NE.
    optlist-name = 'OBJECTKEY2'.
    optlist-options-cp = 'X'.
    optlist-options-ge = 'X'.
    optlist-options-lt = 'X'.
    optlist-options-ne = 'X'.
    APPEND optlist TO restrict-opt_list_tab.
     
    ass-kind = 'S'.
    ass-name = 'S_connid'.
    ass-sg_main = 'I'.
    ass-sg_addy = space.
    ass-op_main = 'OBJECTKEY2'.
    APPEND ass TO restrict-ass_tab.
     
    CALL FUNCTION 'SELECT_OPTIONS_RESTRICT'
        EXPORTING
            restriction = restrict
        EXCEPTIONS
            TOO_LATE = 1
            REPEATED = 2
            SELOPT_WITHOUT_OPTIONS = 3
            SELOPT_WITHOUT_SIGNS = 4
            INVALID_SIGN = 5
            EMPTY_OPTION_LIST = 6
            INVALID_KIND = 7
            REPEATED_KIND_A = 8
            OTHERS = 9.
     
    IF sy-subrc <> 0.
        MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
        WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
     
when you execute this piece of code, you will notice that for carrid, the selection screen is now restricted :

Calling an external program

You want to call a program on your PC from an ABAP program ? try this function :
     
*This example calls the dos prompt DATA:
     
     
i_returncode TYPE i.
     
     
CALL FUNCTION 'GUI_EXEC'
     
     
     
    EXPORTING
     
     
        command = 'CMD' <<==-- CMD calls the DOS prompt but you can put any program here
     
     
        * PARAMETER = 'test'
     
     
    IMPORTING
     
     
        returncode = i_returncode.
     
     
there is a lot of other functions to communicate with the PC like:
     
     
GUI_CREATE_DIRECTORY GUI_DELETE_FILE GUI_DOWNLOAD
     
GUI_EXEC
     
GUI_FILE_SAVE_DIALOG
     
GUI_GET_DESKTOP_INFO
     
GUI_GET_FILE_INFO
     
etc...

Using a variable from a calling program without passing it in parameter

Did you ever try to use a variable from another program without passing this variable as a parameter. This is very useful when you CANNOT add the field as a standard parameter. For example, when you want to use a variable in a BADI which is not already passed as a parameter. Another good example is when you create a correction in a function and you want to keep the installation of the OSS note automatic (if you add parameters in a note, the user will have to install the note manually).

Here is a short example on how to do this :

REPORT zdany_test_var_from_fm.

TABLES: spfli.

DATA dbcnt TYPE sy-dbcnt.

DATA: itab TYPE spfli_tab.

SELECT * FROM spfli INTO TABLE itab UP TO 2 ROWS.

dbcnt = sy-dbcnt.

CALL FUNCTION 'ZFUNCTION'.

FUNCTION zfunction.

* We want to use the DBCNT from the program ZDANY_TEST_VAR_FROM_FM

DATA: field(50).

FIELD-SYMBOLS: .

field = '(ZDANY_TEST_VAR_FROM_FM)dbcnt'.

ASSIGN (field) TO .

WRITE .

* We want to use the internal table from the program ZDANY_TEST_VAR_FROM_FM

DATA: itab TYPE spfli.

FIELD-SYMBOLS: TYPE spfli_tab.

field = '(ZDANY_TEST_VAR_FROM_FM)ITAB[]'.

ASSIGN (field) TO .

LOOP AT INTO itab.

WRITE: / itab-carrid, itab-connid.

ENDLOOP.

ENDFUNCTION

List of internal tables while debugging

There can be times when you need a list of active internal tables while you are debugging ABAP code.

The first method, lets you see which table required a lot of memory

  1. While on debug mode follow the menu path GOTO->Display condition->memory use

  2. Select tabstrip: Memory use - ranked list

The second method provides a very detailed list

  1. While in debug mode, choose GOTO->System Areas->internal information

  2. A list appears on the debug screen

  3. By default the area editbox contains a ?

  4. Now enter DSEG in that field.

  5. Press Return .

  6. You will get a list of all the tables active in that program along with some other attributes.

  7. The type and size of the records determine if they are internal tables and how many records there are.

You can play around and try the other area than DSEG, some are interesting.

Showing a progress bar in ABAP

This process is very easy but a lot of programmers don't know how to do it. You just have to call the ABAP FM SAPGUI_PROGRESS_INDICATOR, at the appropriate points.

Below is a simple example, give it a try !!

REPORT zdany_progress_bar.
DATA: percentage_text TYPE c LENGTH 5.
DO 100 TIMES.
     
    WAIT UP TO '0.5' SECONDS.
    percentage_text(3) = sy-index.
    percentage_text+3 = '%'.
     
     
    CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
    EXPORTING
     
        percentage = sy-index
        text = percentage_text.
     
     
ENDDO.

Manipulating Timestamps

Actually, we should use time stamp in our abap programs instead of the traditional date and time fields.

When we have to do some calculation on a time stamp is not as easy as on a date field.

For example, to add an hour to a timestamp, many people will:

  1. convert the time stamp into a standard date and field

  2. add an hour

  3. convert back the date and time to a timestamp

However, it is the slowest method you can use.

Instead, use class CL_ABAP_TSTMP.

It enables you to make whatever calculation you want on a time stamp.

In the following example, 1 hour is added

REPORT zdany_tstamp.DATA : l_tstamp TYPE timestamp, l_tstamp_out TYPE timestamp. GET TIME STAMP FIELD l_tstamp.TRY. CALL METHOD cl_abap_tstmp=>add EXPORTING tstmp = l_tstamp secs = 3600 <<<===--- 1 hour = 3600 seconds RECEIVING r_tstmp = l_tstamp_out. CATCH cx_parameter_invalid_range . WRITE 'invalid range'. EXIT. CATCH cx_parameter_invalid_type . WRITE 'invalid type'. EXIT.ENDTRY. WRITE l_tstamp time zone 'UTC '.SKIP.WRITE l_tstamp_out time zone 'UTC '.

Generating your own standard F4 help

To avoid the standard F4 help to be show, insert the event PROCESS ON-VALUE-REQUEST request in the program and add a field statement for the field that should trigger the F4 help. In the module called from PROCESS ON-VALUE-REQUEST request, call function module F4IF_FIELD_VALUE_REQUEST.

Example:

process before output.

.....

process after input.

.....

PROCESS ON VALUE-REQUEST. FIELD sflight-carrid MODULE f4_help_for_carrid.

MODULE f4_help_for_carrid INPUT.

* NOTE:

* Tabname/fieldname is the name of the table and field

* for which F4 should be shown.

*

* Dynprog/Dynpnr/Dynprofield are the names of the Progran/Dynpro/Field

* in which the f4 value should be returned.

*

* Value: The value of the Dynpro field when calling the F4 help.

* You can limit the values shown, by inseting a value in this parameter

* e.g 'A*' to show only values beginning with A

CALL FUNCTION 'F4IF_FIELD_VALUE_REQUEST'
    EXPORTING
        tabname     = 'SFLIGHT'
        fieldname   = 'CARRID'
*        SEARCHHELP  = ' '
*        SHLPPARAM   = ' '
        dynpprog    = 'ZDANY_F4_OWN_CALL'
        dynpnr      = '0100'
        dynprofield = 'SFLIGHT-CARRID'
*        STEPL       = 0
        value       = 'A*'
*        MULTIPLE_CHOICE     = ' '
*        DISPLAY             = ' '
*        SUPPRESS_RECORDLIST = ' '
*        CALLBACK_PROGRAM    = ' '
*        CALLBACK_FORM       = ' '
*    TABLES
*        RETURN_TAB =
*    EXCEPTIONS
*        FIELD_NOT_FOUND   = 1
*        NO_HELP_FOR_FIELD = 2
*        INCONSISTENT_HELP = 3
*        NO_VALUES_FOUND   = 4
*        OTHERS            = 5
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
     
ENDMODULE. " F4_help_for_carrid INPUT

To control F4 help in a selection screen use the AT SELECTION-SCREEN ON VALUE-REQUEST FOR

event.

Note that for ranges both the low and high value of the field must have there own ON VALUE-REQUEST

Example:

AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_prctr-low.

PERFORM f4_help_carrid.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_prctr-high.

PERFORM f4_help_carrid.

Creating an ALV Grid in 3 lines

Did you know that you can create an ALV Grid very fast; you don't need to define a layout, a fieldcatalog, a container and all the other small things we usually define in an ALV Grid. If we don't need to finetune the ALV Grid and just want to display a list on the screen or to the printer, here is a very simple way to proceed:

DATA: l_alv      TYPE REF TO   cl_gui_alv_grid,
      lt_sflight TYPE TABLE OF sflight.
     
SELECT * FROM sflight INTO TABLE lt_sflight.
     
* Creation of the ALV object, when we use cl_gui_container=>screen0 as parent, the ALVGrid control will
* automatically use the full screen to display the grid, NO CONTAINER DEFINITION IS REQUIRED !
CREATE OBJECT l_alv EXPORTING i_parent = cl_gui_container=>screen0.
     
* calling the display of the grid, the system will automatically create the fieldcatalog based
* on the table name you pass in parameter
CALL METHOD l_alv->set_table_for_first_display
     EXPORTING i_structure_name = 'SFLIGHT'
     CHANGING  it_outtab        = lt_sflight.
     
* You have to create an EMPTY screen, put NOTHING in the layout and this is going to work
CALL SCREEN 100

Instead of creating an empty screen 100, you can also define an empty selection screen in you program and use it, no more screen painter required !

SELECTION-SCREEN BEGIN OF SCREEN 1001.

SELECTION-SCREEN END OF SCREEN 1001.

CALL SELECTION-SCREEN 1001.


Modifying the F4 standard calendar

When you press F4 on any date field the standard calendar opens in order for you to choose a date. When you do not want the user to choose a weekend day or a holiday, you can do it.

Two different type of calendars are defined in SAP, the holiday calendar and the factory calendar.

These calendars are defined in the customizing under :

SPRO -> General settings -> maintain calendar

in this screen, all the default holidays are predefined by country, you can add or delete holiday as you want. I tried to create the Dany's day in ISP but I'm stuck on a small access problem... stupid security !

Because a holiday can be different by country, the factory calendar is stored for each plants, in table T001W, field FABKL.

here is a small example on how to call the calendar :

CALL FUNCTION 'F4_DATE'
   EXPORTING
     date_for_first_month = '20031208'
holiday_calendar_id = 'CA'           "<<==-- Here is how you point on a holiday calendar
*     factory_calendar_id = T001W-FABKL    "<<==-- ... or a factory one
     display = ' '
   IMPORTING
     select_date = select_date
   EXCEPTIONS
     OTHERS = 4.

Here is an example of the result, a red square marks each holiday.



Saving an internal table in Microsoft Excel format

While you are debugging your program, you can save the content of an internal table.

  1. Display the content of the internal table in the debugger.

  2. Then press ctrl-F11 or right-mouse and click "Save As Excel Worksheet".

  3. Enter the From-index and To-index for the lines you want to save.

  4. Choose folder/filename and save.


Generating a number range automatically

If you need a unique key in a table or a sequential number for any other purpose, you can use a range object .

Ranges are maintained in transaction SNRO

After maintaining the first screen you have to maintain the intervals by clicking the button "number ranges"

These informations are stored in tables :

- TNRO Definition of number range objects

- NRIV Number range intervals. Note: Field NRLEVEL Contains the last assigned number.

In you program you read the next number by using the function NUMBER_GET_NEXT

DATA l_number TYPE i.
CALL FUNCTION 'NUMBER_GET_NEXT'
    EXPORTING
        nr_range_nr = '01'
        object = 'ZTEST'
        quantity = '1'
    IMPORTING
        number = l_number
*       quantity = ' '
*       RETURNCODE =
    EXCEPTIONS
        interval_not_found = 1
        number_range_not_intern = 2
        object_not_found = 3
        quantity_is_0 = 4
        quantity_is_not_1 = 5
        interval_overflow = 6
        OTHERS = 7.

display l_number.

each time you call NUMBER_GET_RANGE the number is automatically increased.

You can also create the number range in your program instead of using SNRO with the functions:

NUMBER_RANGE_INTERVAL_LIST : verify if a number range already exist

NUMBER_RANGE_ENQUEUE : lock the specifier number range

NUMBER_RANGE_INTERVAL_UPDATE : create the number range

NUMBER_RANGE_UPDATE_CLOSE : commit changes NUMBER_RANGE_DEQUEUE : unlock


Defining a local type dynamically

You can now define a local type dynamically.

This is only supported in 6.40. Here's how it goes:

REPORT ZDANY_DYN_LOCAL_TYPES.

****************** hardcoded "old style" local type *******************
* This is a normal hardcoded local type
 types : begin of typ_hardcoded,
         l_count type i,
         lt_sflight type sflight.
 types : end of typ_hardcoded.
* create a table based on hardcoded type
 data : lt_hardcoded type table of typ_hardcoded.
     
****************** dynamic "new wave" local type *******************
 types: typ_count type i.
     
 field-symbols :  type any table.
 data: dref type ref to data,
       itab_type type ref to cl_abap_tabledescr,
       struct_type type ref to cl_abap_structdescr,
       elem_type type ref to cl_abap_elemdescr,
       comp_tab type cl_abap_structdescr=>component_table,
       comp_fld type cl_abap_structdescr=>component.

* We read information about each fields of SFLIGHT (see ABAP FAQ #2)

struct_type ?= cl_abap_typedescr=>describe_by_name( 'SFLIGHT' ).

* We also need the information about the type "typ_count", note that

* we should use class cl_abap_elemdescr instead of cl_abap_typedescr

elem_type ?= cl_abap_elemdescr=>describe_by_name( 'TYP_COUNT' ).

* we read all fleids of SFLIGHT and create a component table

comp_tab = struct_type->get_components( ).

* We add manually the counter

comp_fld-name = 'L_COUNT'.

comp_fld-type = elem_type.

insert comp_fld into comp_tab index 1.

* we create the structure

struct_type = cl_abap_structdescr=>create( comp_tab ).

* ... and the internal table

itab_type = cl_abap_tabledescr=>create( struct_type ).

* The new thing here is the "type handle" which create a pointer to a

* handle

create data dref type handle itab_type.

* we finally assign a field symbol to the pointer because we cannot

* directly access a pointer.

assign dref->* to .

* At the end of this small program, internal table lt_hardcoded and

* lt_dynamic are the same

break-point.


Using macros

First : DO NOT use macros in a new program, there is a lot of better way to do it.

Some people come to my desk and tell me they found a "magic" function which the code behind is invisible and it's impossible to trace this function. In some old programs, you can see a strange call to what it look like a function but it's not, it's a macro.

The macros are stored in table TRMAC.

One of the most used macros is "break". To put a break-point in your code that will break only for your user name, you probably use "break my_user_name". This is not part of the ABAP language despite what a lot of people think; it's a macro. If you have a look in table TRMAC, you will see :

BREAK 000 * USER specific BREAK-POINT

BREAK 001 if sy-uname = '&1'

BREAK 002 break-point

BREAK 003 endif

Here is how to create a simple macro, for the sake of understanding what old programs do. Again, do not

create new macros unless you absolutely must.

REPORT zdany_macro.

*Macro definition
DEFINE ZMULTIPLY.
  MULTIPLY &1 BY &2.
END-OF-DEFINITION.
     
DATA: number1 TYPE i VALUE 2,
      number2 TYPE i VALUE 5.
     
* calling the macro, no easy way of knowing this is a macro
ZMULTIPLY number1 number2.
     
WRITE number1.

Back to top

Using dynamic SELECT statements

The very useful SELECT statement could be fully dynamic from release 6.10 and up.

For more information about the dynamic select, you can read the document "Enhanced ABAP programming with Dynamic Open SQL" from Adrian Görler and Ulrich Koch. Here is the link

https://webphl07.phl.sap.corp/~sapidb/011000358700002805272003E , this is a PDF file.

Here is an example of a fully dynamic select.

REPORT zdany_dynamic_select.

* We use some parameters to dynamically control the select, this is not very 
* clever but this is just a test program !!
PARAMETER : p_tabnam TYPE tabname DEFAULT 'SFLIGHT',
            p_selfl1 TYPE edpline DEFAULT 'CARRID',
            p_selfl2 TYPE edpline DEFAULT 'CONNID',
            p_selfl3 TYPE edpline DEFAULT 'FLDATE',
            p_selfl4 TYPE edpline DEFAULT 'PRICE',
            p_selfl5 TYPE edpline DEFAULT 'CURRENCY',
            p_where1 TYPE edpline DEFAULT 'PRICE > 300',
            p_where2 TYPE edpline DEFAULT 'AND CURRENCY = ''EUR'''.
     
FIELD-SYMBOLS :  TYPE ANY TABLE,
                 TYPE ANY,
                 TYPE ANY.
     
DATA: lt_where    TYPE TABLE OF edpline,
      lt_sel_list TYPE TABLE OF edpline,
      lt_group    TYPE TABLE OF edpline,
      l_having    TYPE string,
      l_wa_name   TYPE string,
      l_sel_list  TYPE edpline,
      dref        TYPE REF TO data,
      itab_type   TYPE REF TO cl_abap_tabledescr,
      struct_type TYPE REF TO cl_abap_structdescr,
      elem_type   TYPE REF TO cl_abap_elemdescr,
      comp_tab    TYPE cl_abap_structdescr=>component_table,
      comp_fld    TYPE cl_abap_structdescr=>component.
     
TYPES: f_count TYPE i.
     
* Creation of the output table including a non standard field, f_count
* see ABAP FAQ #14 for more information on this topic
struct_type ?= cl_abap_typedescr=>describe_by_name( p_tabnam ).
elem_type   ?= cl_abap_elemdescr=>describe_by_name( 'F_COUNT' ).
comp_tab = struct_type->get_components( ).
     
* We remove the unnecessary fields
LOOP AT comp_tab INTO comp_fld.
   IF comp_fld-name <> p_selfl1 AND
      comp_fld-name <> p_selfl2 AND
      comp_fld-name <> p_selfl3 AND
      comp_fld-name <> p_selfl4 AND
      comp_fld-name <> p_selfl5.
         DELETE TABLE comp_tab WITH TABLE KEY name = comp_fld-name.
   ENDIF.
ENDLOOP.
     
comp_fld-name = 'F_COUNT'.
comp_fld-type = elem_type.
APPEND comp_fld TO comp_tab.
     
struct_type = cl_abap_structdescr=>create( comp_tab ).
itab_type   = cl_abap_tabledescr=>create( struct_type ).
     
l_wa_name = 'l_WA'.
CREATE DATA dref TYPE HANDLE itab_type.
ASSIGN dref->* TO .
CREATE DATA dref TYPE HANDLE struct_type.
ASSIGN dref->* TO .
     
* Creation of the selection fields and the "group by" clause
APPEND p_selfl1 TO lt_sel_list.
APPEND p_selfl1 TO lt_group.
APPEND p_selfl2 TO lt_sel_list.
APPEND p_selfl2 TO lt_group.
APPEND p_selfl3 TO lt_sel_list.
APPEND p_selfl3 TO lt_group.
APPEND p_selfl4 TO lt_sel_list.
APPEND p_selfl4 TO lt_group.
APPEND p_selfl5 TO lt_sel_list.
APPEND p_selfl5 TO lt_group.
APPEND 'COUNT(*) AS F_COUNT' TO lt_sel_list.
     
* creation of the "where" clause
APPEND p_where1 TO lt_where.
APPEND p_where2 TO lt_where.
     
* Creation of the "having" clause
l_having = 'count(*) >= 1'.
     
* THE dynamic select
SELECT          (lt_sel_list)
       FROM     (p_tabnam)
       INTO CORRESPONDING FIELDS OF TABLE 
       WHERE    (lt_where)
       GROUP BY (lt_group)
       HAVING   (l_having)
       ORDER BY (lt_group).
     
* display of the results
LOOP AT  ASSIGNING .
   LOOP AT comp_tab INTO comp_fld.
      ASSIGN COMPONENT comp_fld-name OF STRUCTURE  TO .
      WRITE: .
   ENDLOOP.
   SKIP.
ENDLOOP.

Back to top

Using JavaScript in ABAP

You can code JavaScript directly in your ABAP code.

If you want to do some JavaScript tests in ABAP there is a good program to use : DEMO_JAVA_SCRIPT_MINI_EDITOR. When you run this program, you can code your Java in an ABAP editor, compile and execute it to test the result.

Nowe, here is a small example on how to insert JavaScript in ABAP:

*&---------------------------------------------------------------------*
*& Report ZDANY_JAVASCRIPT_TEST
*&---------------------------------------------------------------------*
REPORT ZDANY_JAVASCRIPT_TEST.
     
data: l_JS_PROCESSOR type ref to CL_JAVA_SCRIPT,
      l_RETURN_VALUE type STRING,
      l_SOURCE       type STRING.
     
* Creation of a new javaScript
l_JS_PROCESSOR = CL_JAVA_SCRIPT=>CREATE( ).
     
* this is the Javascript code
concatenate
   'var l_source = "Hello World,"; '
   'l_source += " I''m"; '
   'l_source += " JavaScript!"; '
   'l_source; '
    into l_SOURCE separated by CL_ABAP_CHAR_UTILITIES=>CR_LF.
     
* we compile the JavaScript code
l_JS_PROCESSOR->COMPILE( SCRIPT_NAME = 'DANYTEST.JS' SCRIPT = L_SOURCE ).
     
* Any syntax error ?
if l_JS_PROCESSOR->LAST_CONDITION_CODE <> 0.
   write: / 'Error in COMPILE', l_JS_PROCESSOR->LAST_ERROR_MESSAGE.
   exit.
else.
   write / 'JavaScript was compiled'.
endif.
     
* Let's go and run the script
l_JS_PROCESSOR->EXECUTE( SCRIPT_NAME = 'DANYTEST.JS' ).
     
* Any problem during execution ?
if l_JS_PROCESSOR->LAST_CONDITION_CODE <> 0.
   write: / 'Error in EXECUTE',l_JS_PROCESSOR->LAST_ERROR_MESSAGE.
   exit.
else.
   write / 'JavaScript was executed'.
endif.
     
* we read the output variable
l_RETURN_VALUE = l_JS_PROCESSOR->EVALUATE( JAVA_SCRIPT = 'l_source;' ).
     
write : / l_RETURN_VALUE.

Saving an internal table in Microsoft Excel format

You can compare the source code of a program / method / function from different systems with transaction SE39. This is very useful if you want to be sure that your transport was successful or to see whether the same version runs on both machines.

  1. Start SE39

  2. Choose Compare different systems

  3. Enter both program names and the RFC destination of the remote program

  4. Choose Display

Here is an example of the result, note that the system show difference in blue

You can also compare table content :

  • Start transaction OY19

  • Choose Manual selection

  • Enter the name of the table that you want to compare

  • Choose Execute

For results such as these:


Saving an internal table in Microsoft Excel format

You can use standard program RPR_ABAP_SOURCE_SCAN to search ABAP program code/screen logic for specific texts (strings.)

This program offers many more options than programs RSRSCAN1 or RKCTSEAR. The benefits of using this program are as follows:

  • Several texts can be entered for which the system searches. The search text should be entered without formatting characters(*,+). Only the texts are applied in the search, i.e. selection option conditions such as greater than, equal to, etc., are ignored

  • You can restrict the search to either the program code or the flow logic of the selected screens or both the program code and the flow logic of the screens.

  • You can set the option to ignore the comments for search.

  • Found location +/- x lines: Here we can specify how many program lines before and after the found location of the search string should be included in the output.

  • We can also specify the option to search in all the includes used in the specified programs


Managing persistent objects with object services

There is a way to avoid building a fully object-oriented program while still working with non-object-oriented relational database. The object services layer now provides a persistence framework that closes the object-relational gap. You no longer need to write SQL code as objects are transparently loaded from the database when needed. You must create a persistent class.

Choose transaction SE24 and create a persistent class; this class must be protected.

In the class builder, a new button is added in the main toolbar - "Persistence" - press it :

in the next screen, you just have to map which fields you need in your persistent class

After having saved the previous screen, you will notice that the system creates a set/get method for each field that you selected.

Activate the whole class. Now that we have a persistent object to access the database table SFLIGHT, we must access it in a program. Here is a small example to read/write data into SFLIGHT using persistent objects.

REPORT zdany_sflight_persistent.
     
   DATA : l_flight       TYPE REF TO zcl_dany_sflight,
          l_flight_agent TYPE REF TO zca_dany_sflight,
          l_seatsfree    TYPE i,
          l_seatsocc     TYPE i.
     
* Reference to the class agent, ALWAYS required for any operation
   l_flight_agent = zca_dany_sflight=>agent.
     
   TRY.
*We read a record from SFLIGHT using a unique key
      l_flight = l_flight_agent->get_persistent(
          i_carrid = 'LH'
          i_connid = '0400'
          i_fldate = '20031030' ).
     
*We read a specific field
      l_seatsfree = l_flight->get_seatsmax( ) - l_flight->get_seatsocc( ).
      IF l_seatsfree > 0.
         l_seatsocc = l_flight->get_seatsocc( ) + 1.
* We write back a specific field into the DB
         l_flight->set_seatsocc( l_seatsocc ).
      ENDIF.
   ENDTRY.
     
 COMMIT WORK.

There are lots of other methods and techniques that you can use in persistent classes.

Contact Dany Charbonneau for more info.

Debugging ABAP programs from JAVA applications

You can do ABAP debugging from java applications here is how :

  1. Check whether your user has debugging authority. Auth. object S_DEVELOP has to contain 'DEBUG'

    • Use su01; ROLES

    • Double click the different roles ->

    • new session will open

    • Choose Authorizations -> Display Authorization Data

  2. go to the ABAP coding

  3. go to the menu Utilities -> Settings / choose tab "ABAP editor " / choose tab "Debugging" check the chek - box "Actv." in the User field enter the user used in the Java logon (not the alias of the user!! e.g. for BRUNO enter "3B1968D7DD1")

  4. Press enter or choose OK to get back to your source code

  5. If you set your next break-point a pop-up will occur to ask you if you want to set an external break-point or a session break-point --> click external break-point (= former HTTP break-point) -->

if you run you Java application now and the coding with the break-point is called a new R/3 (CRM) window will open and you will see you code in debug mode (may take some seconds)


Defining a default variant

There are 2 different ways to define a default variant.

Method 1 - By assigning a variant directly on the transaction code. This is the easiest way but if the program was called from another program or directly from SE38, the default variant will be ignored.

Method 2 - By assigning a variant in the code, here is a short example of this:

* The code must be in the INITIALIZATION section
INITIALIZATION.
* We must check if a default variant was already entered by the user in a batch job or in the transaction code
* we do not want to overwrite it ! the current variant is store in the sy-slset field
IF sy-slset IS INITIAL.
    CALL FUNCTION 'RS_SUPPORT_SELECTIONS'
    EXPORTING
        report = sy-cprog                "actual program name
        variant = 'SAPDEFAULT'     "default variant name
    EXCEPTIONS
        variant_not_existent = 0
        variant_obsolete = 0
        OTHERS = 0.
ENDIF.
     
* After the initialization we start the real code of our program in the section START-OF-SELECTION
START-OF-SELECTION.
Here is how to create a  the variant "SAPDEFAULT" always using as a default date today minus 30 days:
     
Goto -> variant -> save as variant
     

Here is the standard variant save screen. Enter a name and a description and press "execute". Very few know how to handle the weird looking bottom part of this screen:

  1. Check the variables for which you want to maintain default values

  2. Choose selection variables button and see the next one

The first part is a legend of the column headers (T D B Z). Because we want to create a date, we double click on the traffic lights of the column "D" for Dynamic date calculation. when the traffic light turn green, you can press on the down arrow in the "T" column. This will bring a popup with all possibilities you can imagine for defaulting a date. From a usability point of view, this is not really good screens but nevertheless, this tool is very powerful.


Creating Activable Breakpoints and Assertions

You can now create (de)activable breakpoints in your programs. You can release these breakpoints in production and a customer will have the opportunity to activate and debug your code more easily.

The following is an activable break-point : BREAK-POINT ID dany.

The checkpoint group is defined by double clicking on the checkpoint group in the editor OR directly via transaction SAAB.

Below is the SAAB screen. In the breakpoints part of the screen, you can set it to "inactive" or "break". All breakpoint groups will be shipped inactive by default.

Assert :

An assertion is a condition which must be true during program execution. By using asserts in your program, you can find cause of error in shorter time. The reaction when violating an assertion depend on a customizing and could be :

  1. Start the debugger from this assert

  2. Do nothing, ignore the assert

  3. Log the assertion in a log

  4. Terminate the program with runtime error ASSERTION_FAILED

The assertions are defined in SAAB (exactly like the breakpoints, see screen above).Here is an example of a use for an assertion :

METHOD sort_by_name.
     
DATA: l_f1 TYPE i VALUE 2,
      l_f2 TYPE c LENGTH 10 VALUE 'test',
      l_t1 TYPE TABLE OF sflight.
     
   the_sorting_algorithm.
     
   ASSERT ID        dany
          SUBKEY    'danysub1'
          FIELDS    l_f1 l_f2 l_t1
          CONDITION itab->is_sorted_by_name( ) <> ' '.                
ENDMETHOD.

This will ensure that the table is sorted. Below is the result of the log for this assert


Using Shared Objects

Shared objecta are SAP's answer to an age-old request by programmers. Up until now, the only way to share variables between programs was to use EXPORT/IMPORT TO/FROM MEMORY. This method was very slow because the "sending" program had to copy variables from its memory to the shared memory, and the "receiving" program had to copy these variables from the shared memory into its own program memory. This generated two copies for basically nothing.

Here are the benefits of shared objects:

  1. Copy-free: very fast access

  2. Versioning management: you can handle many version of the variables at the same time

  3. Preloading: you can now request a specific variable no matter if the "sending" program already created them

  4. Automatic propagation from a database or to different application servers

  5. Could be client dependant

  6. Easy monitoring

Here is a very simple example but you can do very powerful shared object, see documentation for more information.

Step 1 :

You have to define a Root class using SE24, In this class you will defined all variables you want to share in the attributes tab, This class must be "Shared memory enabled" :

Step 2 : You have to define your shared memory object using the transaction SHMA. It is important to put the class you created in step 1 in the field "root class".

Step 3 : You have to write a program to write to the shared memory.

DATA : hdl  TYPE REF TO zcl_sm_area,
       root TYPE REF TO zcl_root_area.
     
* Create the default instance for write, 
* when we attach for write, an exclusive lock is performed on the shared memory object  
  hdl = zcl_sm_area=>attach_for_write( ).
     
*when we create our root object to access variables, we must use the new keyword addition AREA HANDLE
  CREATE OBJECT root AREA HANDLE hdl.
* Create the link between the root object and the shared memory object
  hdl->set_root( root ).
* put data in the shared memory variable
  root->big_var = 'hello world!'.
* commit
hdl->detach_commit( ). 

Step 4 : You have to create a program to read from the shared memory

DATA : hdl TYPE REF TO zcl_sm_area.
     
* Open default instance for read
  hdl = zcl_sm_area=>attach_for_read( ).
*Access root object component to write the variable
  WRITE / hdl->root->big_var.
*Release lock
  hdl->detach( ).

Step 5: You can monitor the result in transaction SHMM

Defining dynamic orders in an ABAP sort

You can easily define dynamic fields in an ABAP sort using ( ) :

data : l_fieldname type dd03l-fieldname value 'CARRID'.

SORT sflight by (l_fieldname) DESCENDING.

BUT you CANNOT define the order (ascending or descending) dynamically :

SORT sflight by (l_fieldname) (l_order). <<==-- This is impossible in ABAP.

Now, with the new tree control­, when you want to give fully customizable tree, ou need to dynamically set the order in the sort command.

The first method is by using a CREATE SUBROUTINE POOL with your sort. Each time you will run the program, this subroutine will be recompiled. This is VERY slow and we should avoid using this command whenever it's possible.

The second method is a simple trick that have no major impact on performance. You duplicate each fields you want to sort, 1 copy for ascending and 1 for descending. You move the fieldname only in 1 of those fields depending on what order you want.

Here is a small example on how to do that:

*&---------------------------------------------------------------------*
*& Report ZDANY_DYN_SORT
*&---------------------------------------------------------------------*
REPORT z_dany_dyn_sort.
* s_field* - field name for sorting ( F1,F2,F3,F4,F5 or space )
* s_ord* - ASC or DES ( ascending or descending)
     
PARAMETERS: s_field1(6) DEFAULT 'FIELD1', s_ord1(3) DEFAULT 'ASC',
            s_field2(6) DEFAULT 'FIELD2', s_ord2(3) DEFAULT 'DES',
            s_field3(6) DEFAULT 'FIELD3', s_ord3(3) DEFAULT 'ASC',
            s_field4(6) DEFAULT 'FIELD4', s_ord4(3) DEFAULT 'DES',
            s_field5(6) DEFAULT 'FIELD5', s_ord5(3) DEFAULT 'ASC'.
     
TYPES: BEGIN OF ltt_fields,
       field1(6),
       field2(6),
       field3(6),
       field4(6),
       field5(6),
END OF ltt_fields.
     
DATA: l_field_asc1(6),
      l_field_asc2(6),
      l_field_asc3(6),
      l_field_asc4(6),
      l_field_asc5(6),
      l_field_des1(6),
      l_field_des2(6),
      l_field_des3(6),
      l_field_des4(6),
      l_field_des5(6),
      lt_fields TYPE TABLE OF ltt_fields,
      ls_fields TYPE ltt_fields,
      l_flag_invalid_field,
      l_flag_not_asc_des.
     
FIELD-SYMBOLS  TYPE ANY.
     
INITIALIZATION.
     
* Just to fill an internal tables for testing
 DO 3 TIMES.
  ls_fields-field1 = sy-index.
  DO 3 TIMES.
    ls_fields-field2 = sy-index.
    DO 3 TIMES.
      ls_fields-field3 = sy-index.
      DO 3 TIMES.
        ls_fields-field4 = sy-index.
        DO 3 TIMES.
          ls_fields-field5 = sy-index.
          APPEND ls_fields TO lt_fields.
        ENDDO.
      ENDDO.
    ENDDO.
  ENDDO.
ENDDO.
     
START-OF-SELECTION.
     
* The order must be "ASC" or "DES" or space, any other value is rejected
l_flag_not_asc_des = 'X'.
CHECK ( s_ord1 = 'ASC' OR s_ord1 = 'DES' OR s_ord1 IS INITIAL ) AND
      ( s_ord2 = 'ASC' OR s_ord2 = 'DES' OR s_ord2 IS INITIAL ) AND
      ( s_ord3 = 'ASC' OR s_ord3 = 'DES' OR s_ord3 IS INITIAL ) AND
      ( s_ord4 = 'ASC' OR s_ord4 = 'DES' OR s_ord4 IS INITIAL ) AND
      ( s_ord5 = 'ASC' OR s_ord5 = 'DES' OR s_ord5 IS INITIAL ).
CLEAR l_flag_not_asc_des.
     
* the field name must be = "FIELD1, 2, 3, 4 or 5", any other value is rejected
l_flag_invalid_field = 'X'.
CHECK 'FIELD1FIELD2FIELD3FIELD4FIELD5' CS s_field1 AND
      'FIELD1FIELD2FIELD3FIELD4FIELD5' CS s_field2 AND
      'FIELD1FIELD2FIELD3FIELD4FIELD5' CS s_field3 AND
      'FIELD1FIELD2FIELD3FIELD4FIELD5' CS s_field4 AND
      'FIELD1FIELD2FIELD3FIELD4FIELD5' CS s_field5.
CLEAR l_flag_invalid_field.
     
     
* for a certain field, if the user ask descending order, the name of this field is 
* moved in l_field_des1 AND it's important that l_field_asc1 remain empty.
IF s_field1 IS NOT INITIAL.
  IF s_ord1 = 'ASC'.
     l_field_asc1 = s_field1.
  ELSE.
     l_field_des1 = s_field1.
  ENDIF.
ENDIF.
     
IF s_field2 IS NOT INITIAL.
  IF s_ord2 = 'ASC'.
    l_field_asc2 = s_field2.
  ELSE.
    l_field_des2 = s_field2.
  ENDIF.
ENDIF.
     
IF s_field3 IS NOT INITIAL.
  IF s_ord3 = 'ASC'.
    l_field_asc3 = s_field3.
  ELSE.
    l_field_des3 = s_field3.
  ENDIF.
ENDIF.
     
IF s_field4 IS NOT INITIAL.
  IF s_ord4 = 'ASC'.
    l_field_asc4 = s_field4.
  ELSE.
    l_field_des4 = s_field4.
  ENDIF.
ENDIF.
     
IF s_field5 IS NOT INITIAL.
  IF s_ord5 = 'ASC'.
    l_field_asc5 = s_field5.
  ELSE.
    l_field_des5 = s_field5.
  ENDIF.
ENDIF.
     
* EACH field is used twice in the sort with different name for ascending and descending. 1 of the 
* 2 fields will be empty and the sort will ignore it.
SORT lt_fields BY (l_field_asc1) ASCENDING (l_field_des1) DESCENDING
                  (l_field_asc2) ASCENDING (l_field_des2) DESCENDING
                  (l_field_asc3) ASCENDING (l_field_des3) DESCENDING
                  (l_field_asc4) ASCENDING (l_field_des4) DESCENDING
                  (l_field_asc5) ASCENDING (l_field_des5) DESCENDING.
     
* Display the results
EDITOR-CALL FOR lt_fields.
     
     
END-OF-SELECTION.
* if parameters was not entered correctly
 IF l_flag_not_asc_des = 'X'.
   WRITE: / 'Only ASC for ascending or DES for DESCENDING are allowed for fields S_ORDn'.
 ELSEIF l_flag_invalid_field = 'X'.
   WRITE: / 'S_FIELDn must be = FIELD1, FIELD2, FIELD3, FIELD4 or FIELD5.'.
ENDIF.

Inserting charts

It's a known fact that customers are very sensitive to the appeal of charts. Creating graphical charts (bar, pie char, lines graphs) in ABAP is simple. There are two main methods for creating charts in ABAP

  • Using the class CL_GFW

  • Using the function module GFW_PRES_SHOW

There are also other classes and function modules derived from these ones. Use transaction GRAL to explore all possibilities provided by this class and this FM.

The following are two short examples of the huge potential of function module GFW_PRES_SHOW :

* Contain the constants for the graph typeTYPE-POOLS: GFW. DATA: VALUES TYPE TABLE OF GPRVAL WITH HEADER LINE, COLUMN_TEXTS TYPE TABLE OF GPRTXT WITH HEADER LINE. REFRESH VALUES. REFRESH COLUMN_TEXTS. VALUES-ROWTXT = 'Salary'. VALUES-VAL1 = 50000. VALUES-VAL2 = 51000. APPEND VALUES. VALUES-ROWTXT = 'Life cost'. VALUES-VAL1 = 49000. VALUES-VAL2 = 51200. APPEND VALUES. COLUMN_TEXTS-COLTXT = '2003'. APPEND COLUMN_TEXTS. COLUMN_TEXTS-COLTXT = '2004'. APPEND COLUMN_TEXTS. * Call a chart into a standard container, this function could be used for many * different graphic types depending on the presentation_type field :* gfw_prestype_lines * gfw_prestype_area * gfw_prestype_horizontal_bars * gfw_prestype_pie_chart * gfw_prestype_vertical_bars * gfw_prestype_time_axis CALL FUNCTION 'GFW_PRES_SHOW' EXPORTING CONTAINER = 'CONTAINER' "A screen with an empty container must be defined PRESENTATION_TYPE = GFW_PRESTYPE_LINES TABLES VALUES = VALUES COLUMN_TEXTS = COLUMN_TEXTS EXCEPTIONS ERROR_OCCURRED = 1 OTHERS = 2.

Resulting in this:

The following uses the EXACT same function with a different presentation type

REFRESH VALUES. REFRESH COLUMN_TEXTS. VALUES-ROWTXT = ''. VALUES-VAL1 = 10. VALUES-VAL2 = 35. VALUES-VAL3 = 45. VALUES-VAL4 = 8.sul VALUES-VAL5 = 2. APPEND VALUES. COLUMN_TEXTS-COLTXT = 'Fun'. APPEND COLUMN_TEXTS. COLUMN_TEXTS-COLTXT = 'Cars'. APPEND COLUMN_TEXTS. COLUMN_TEXTS-COLTXT = 'House'. APPEND COLUMN_TEXTS. COLUMN_TEXTS-COLTXT = 'Services'. APPEND COLUMN_TEXTS. COLUMN_TEXTS-COLTXT = 'Others'. APPEND COLUMN_TEXTS. CALL FUNCTION 'GFW_PRES_SHOW' EXPORTING CONTAINER = 'CONTAINER' PRESENTATION_TYPE = GFW_PRESTYPE_PIE_CHART X_AXIS_TITLE = 'Expenses' Y_AXIS_TITLE = 'Expenses2' TABLES VALUES = VALUES COLUMN_TEXTS = COLUMN_TEXTS EXCEPTIONS ERROR_OCCURRED = 1 OTHERS = 2


Knowing when to use SELECT SINGLE or SELECT ... UP TO 1 ROWS

A lot of people use the SELECT SINGLE statement to check for the existence of a value in a database. Other people prefer to use the 'UP TO 1 ROWS' variant of the SELECT statement.

So what's the difference between using 'SELECT SINGLE' statement as against a 'SELECT .... UP TO 1 ROWS' statement ?

If you're considering the statements

SELECT SINGLE field INTO w_field FROM table.

and

SELECT field INTO w_field FROM table UP TO 1 ROWS. ENDSELECT.

then looking at the result, not much apart from the extra ENDSELECT statement. Look at the run time and memory usage and they may be worlds apart.

Why is this ?? The answer is simple.

The 'SELECT SINGLE' statement selects the first row in the database that it finds that fulfils the 'WHERE' clause If this results in multiple records then only the first one will be returned and therefore may not be unique.

The 'SELECT .... UP TO 1 ROWS' statement is subtly different. The database selects all of the relevant records that are defined by the WHERE clause, applies any aggregate, ordering or grouping functions to them and then returns the first record of the result set.

Get the difference ??

If not, here is a good example, credit for this example goes to Richard Harper, a friend of mine on sapfans.com :

Create a Ztable called ZDifference with 2 fields in it, MANDT of type MANDT and POSNR of type POSNR. Make sure both of these are keys. Also create a table maintenance dialog for it (SE11->Utilities->Table Maintenance Generator). Fill the table with ten rows 000001-000010.

Then run the program shown below:

Code: 
****************************************************************** 
* 
*       Program:       Z_Difference 
* 
*       Purpose:       A program that demonstrates the difference 
*                      between SELECT SINGLE and SELECT UP TO n ROWS. 
* 
*                      This program requires the data table Z_DIFFERENCE 
*                      to have been created according to the structure 
*                      outlined in the text above and populated with 
*                      at least 10 records. 
* 
*       Creation Date: 21/04/2004 
* 
*       Requested By: 
* 
*       Reference Doc: 
* 
*       Author:        R Harper 
* 
*       Modification History: 
* 
*   Date    Reason                             Transport     Who 
* 
****************************************************************** 
Report Z_Difference 
       Message-id 38 
       Line-Size  80 
       Line-Count 0 
       No Standard Page Heading. 
* 
Start-Of-Selection. 
     
  Data: w_Single type Posnr, 
        t_Rows   type standard table of Posnr 
                 initial size 0 
                 with header line. 
* 
  Select single Posnr 
    from zDifference 
    into w_Single. 
* 
  Select Posnr 
    into table t_Rows 
    from zDifference 
   up to 1 rows 
   order by Posnr descending. 
* 
   Write :/ 'Select single:', w_Single. 
   Skip 1. 
   Write :/ 'Up to 1 rows :'. 
   Loop at t_Rows. 
        Write t_Rows. 
   EndLoop. 
     

You should see the output:

Select single: 000001

Up to 1 rows : 000010

The first 'SELECT' statement selected the first record in the database according to any selection criterion in the 'WHERE' clause. This is what a 'SELECT SINGLE' does. The second 'SELECT' has asked the database to reverse the order of the records before returning the first row of the result.

In order to be able to do this the database has read the entire table, sort it and then return the first record. If there was no ORDER BY clause then the results would have been identical (ie both '000001') but the second select if given a big enough table to look at would be far slower.

Note that this causes a problem in the Extended Program Check if the full key is not specified in a 'SELECT SINGLE'. Replacing the 'SELECT SINGLE' by an "UP TO 1 ROWS" will give the same exact results without any warning but the program will run slower and consume more memory. This is a good example of a warning that we should ignore... considering you are sure of what you are doing !!


Working around the limitations of a range in SELECT...WHERE...IN

When you use a range table in a select (SELECT * FROM sflight WHERE carrid IN lt_carrid), you sometimes get a short dump with the error DBIF_RSQL_INVALID_RSQL.

A lot of people think that a maximum number of records was reached; rumour has it that it's somewhere between 1000 and 2000 records. This is false and groundless. In fact, the problem is that the "IN" keyword is not native SQL and the compiler converts it into native SQL. There is a limitation on the length of the generated SQL string.

Here is a small example of a program to create a short dump :

DATA : lt_range TYPE RANGE OF sflight-carrid WITH HEADER LINE,
       lt_sflight TYPE TABLE OF sflight.
DO 5000 TIMES.
   lt_range-sign = 'I'.
   lt_range-option = 'EQ'.
   lt_range-low = 'AA'.
   APPEND lt_range.
ENDDO.
SELECT * FROM sflight INTO TABLE lt_sflight WHERE carrid IN lt_range.
     
The compiler convert the SELECT in native SQL like that :
     
... WHERE carrid = lt_range[1]-low OR
                   lt_range[2]-low OR
                   lt_range[3]-low OR
                   ....
                   lt_range[5000]-low.

The short dump occur when the generated SQL caracter string is over a certain threshold. This threshold is variable, could be between 2k and 32k (usually 4k or 8k) depending on the DB system. The threshold is stored in dbs/io_buf_size and could NOT be change by programmers because this is maintained on DB level (oracle, DB2, etc...) by IT.

There are two ways to avoid this problem :

  1. Create some small packages (500 records) and call the SELECT within a loop with APPENDING TABLE keyword

  2. Usually the best way to do it is using a SELECT... FOR ALL ENTRIES IN... instead.


Calling function modules dynamically

When you only know the function name to call at run-time, you have to call your function dynamically. Here is an example of how to call a function dynamically (note: comments were added to an existing example from the standard help)

REPORT ZDANY_DYN_FM_CALL.

*The constants and structures required to use the dynamic function call

*is stored in the type pool ABAP.

type-pools abap.

*This is the name of the function you want to call.

data NAME type STRING value `READ_SPFLI_INTO_TABLE`.

* Parameter table, where you store all parameters, importing, exporting

* and changing data PARA_TAB type ABAP_FUNC_PARMBIND_TAB. data PARA_LINE like line of PARA_TAB.

* Exception table to handle the exception that can occur during the

* execution of the function

data EXCP_TAB type ABAP_FUNC_EXCPBIND_TAB.

data EXCP_LINE like line of EXCP_TAB.

data CARRIER type SPFLI-CARRID.

data JTAB type SPFLI_TAB.

CARRIER = 'XYZ'.

* Name of the first parameter

PARA_LINE-NAME = 'ID'.

* type of the first parameter, could be :

* abap_func_exporting value 10,

* abap_func_importing value 20,

* abap_func_tables value 30,

* abap_func_changing value 40.

PARA_LINE-KIND = ABAP_FUNC_EXPORTING.

*We need the datatype of the parameter to pass

get reference of CARRIER into PARA_LINE-VALUE.

append PARA_LINE to PARA_TAB.

*Same thing for parameter 2

PARA_LINE-NAME = 'ITAB'.

PARA_LINE-KIND = ABAP_FUNC_IMPORTING.

get reference of JTAB into PARA_LINE-VALUE.

append PARA_LINE to PARA_TAB.

*Now we create the possible exceptions

EXCP_LINE-NAME = 'NOT_FOUND'.

EXCP_LINE-VALUE = 1.

insert EXCP_LINE into table EXCP_TAB.

EXCP_LINE-NAME = 'OTHERS'.

EXCP_LINE-VALUE = 4.

insert EXCP_LINE into table EXCP_TAB.

*... and we dynamically call the function with the parameter-table and

* exception-table addition

call function NAME
   parameter-table
      PARA_TAB
   exception-table
      EXCP_TAB.
* We check the result code
case SY-SUBRC.
   when 1.
      message id SY-MSGID type SY-MSGTY number SY-MSGNO.
   when 2.
      message E888(SABAPDOCU) with 'Error in function module'.
endcase.

Downloading ABAP code to your local PC

Creating Z* test programs is a popular method for conducting tests. However, when an environment is about to get shut down, keeping your test programs becomes tricky. You have to launch se38/37/24/80, select your programs one by one, and choose system -> list -> save -> local file, or use function module WS_DOWNLOAD. This is a lengthy procedure that does not even enable you to save screens, tables, or structures.

An ABAP program available for free download at http://www.dalestech.com/ can help you save your test programs.

  1. Choose home -> R/3 entreprise -> direct download entreprise 1.2

  2. download the .ZIP file,

  3. Unzip

  4. Cut and paste in an ABAP program

  5. Compile and run

All your projects (including multiple classes, programs, function groups, screens and tables) can be saved in less than one minute.

If you want to backup your work in order to keep a certain stable version while you are programming, it might be preferable use a tool that is already embedded in the Workbench: in se38/37/24/80, choose utilities -> versions -> generate version