Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Assert Statement

Former Member
0 Kudos

Could anyone please explain, How can a Assert statement be used?How is the activation and behaviour of ASSERT stament controlled by Checkpoint group? Also please explain When ane where can an ASSERT statement be used?

Thanks

Best regards

Swathi

3 REPLIES 3

uwe_schieferstein
Active Contributor
0 Kudos

Hello Swathi

Following is the ABAP keyword documentation which explains already a lot:

Syntax

ASSERT [ [ID group [SUBKEY sub]]

[FIELDS dobj1 dobj2 ...]

CONDITION ] log_exp.

Effect

This statement defines a conditioned checkpoint (assertion). For log_exp, you can specify any logical expression. When the program reaches an active assertion, the logical expression is evaluated and the program execution continues with the next statement after ASSERT only if the result of log_exp is true. If an assertion is inactive, the logical condition log_exp is not evaluated and the program execution continues with the next statement after ASSERT.

The ASSERT statement allows you to make any implicit assumption/requirement at the time of development explicitly available in your program. For example, at the beginning of a method you may have ASSERT statements which check if the input for the method is correct.

At the end of the method you may have additional ASSERT statements which check the output of your method.

Using transaction SAAB you can switch ASSERT statements on and of on-the-fly!!!

For more details about the ASSERT statement please see the excellent blog by Claudia Dangers:

[How to Instrument Your ABAP Code With Checkpoint Groups|https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/2306] [original link is broken] [original link is broken] [original link is broken];

Regards,

Uwe

Former Member
0 Kudos

A Checkpoint is an ABAP statement instrumenting the code for the purpose of testing, debugging and maintenance.

Checkpoint statements are BREAK-POINT and ASSERT. They are standing in contrast to operative statements building up the program logic.

The new statement ASSERT

An assertion is a condition (expressed by a Boolean expression) which must be true during program execution. It allows us to verify the correct state by explicit declaration of assumptions. Assertions provide insight into expected system behaviour by making assumptions explicit. This makes it easier to maintain the programs.

The two Variants of ASSERT

Assertion that is always active: ASSERT <logical_expression>.

Assertion that can be activated: ASSERT ID <checkpoint_group> CONDITION <logical_expression>.

By specifying the addition ID <checkpoint_group>, the ASSERT statement becomes member of checkpoint group <checkpoint_group> and can be activated.

The activation settings are made within the corresponding checkpoint group. The default setting is inactive. The conditions of inactive assertions are not evaluated. This is important for the performance of productive systems.

Violating assertions

An assertion is violated if the expression does not evaluate to true when processing the ASSERT statement. This indicates an error in the program.

Violating an (always active) assertion terminates the program with runtime error ASSERTION_FAILED.

The consequence of violating an assertion that belongs to a checkpoint group is defined inside the checkpoint group.

Check this SDN link.

/people/claudia.dangers/blog/2005/09/07/how-to-instrument-your-abap-code-with-checkpoint-groups

Regards,

Maha

Former Member
0 Kudos

Hi

just type 'assert' in the editor and press F1, u will get when and where to use.

with regards,

Hema Sundara.