Skip to content

zenrosadira/abap-tbox-random-data

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 

Repository files navigation

ABAP Random Data Generator

ex1

A utility class that simplifies the generation of random data and allows for quick population of variables (tables, structures, scalar data). The data generated is devoid of meaning but is consistent with types domain: if fixed values are expected, one of these values will be randomly assigned; if a value table is assigned, values will be randomly chosen from it. Additionally, it is possible to configure ranges and value dimensions.

It can be useful for preparing performance stress tests or managing test automation.

Quick Start

* To generate a random table
DATA t_sflight TYPE TABLE OF sflight.
DATA(tab_rand) = ztbox_cl_rand=>table( ).
tab_rand->generate( IMPORTING table = t_sflight ).

* To generate a random structure
DATA s_sflight TYPE sflight.
DATA(str_rand) = ztbox_cl_rand=>struct( ).
str_rand->generate( IMPORTING struct = s_sflight ).

* To generate a random value
DATA amount TYPE wrbtr.
DATA(val_rand) = ztbox_cl_rand=>value( ).
val_rand->generate( IMPORTING value = amount ).

Configuration

You can decide the number of rows in the generated table

DATA t_sbook TYPE TABLE OF sbook.
DATA(tab_rand) = ztbox_cl_rand=>table( ).

tab_rand->rows( `10000` ). " Default is 100
tab_rand->generate( IMPORTING table = t_sbook ). 
" Now t_sbook has exactly 10000 rows 

The number of rows can also be a range in the form [min, max]

tab_rand->rows( `[10, 2000]` ).
tab_rand->generate( IMPORTING table = t_sbook ). 
" Now t_sbook has a number of rows randomly chosen between 10 and 2000

You can manage fields configuration using ->field( ) method.

tab_rand->field( `MANDT` )->fixed( sy-mandt ). " To always assign the same value
tab_rand->field( `FORCURAM` )->range( `[1, 1000]` ). " To assign value randomly chosen from an interval
tab_rand->field( `FLDATE` )->range( `[19990101, 20251231]` ). " As above, also applies to dates and times
tab_rand->field( `FORCURAM` )->decimals( 2 ). " To set decimals precision for packed/float fields
tab_rand->field( `PASSNAME` )->len( `5` ). " To assign char-value with fixed length
tab_rand->field( `PASSNAME` )->len( `[3, 14]` ). " To assign char-value with a randomly chosen length
tab_rand->field( `PASSNAME` )->ascii( ). " To genere words using ASCII characters
tab_rand->field( `PASSNAME` )->words_upper( ). " To generate words in upper case
tab_rand->field( `WUNIT` )->use_check_table( abap_false ). " To de-activate the use of domain check-table

tab_rand->generate( IMPORTING table = t_sbook ).

The same ->field( ) configurations can be applied to structure generator too.

DATA s_uni TYPE bapimtcs_unicode.
DATA(str_rand) = ztbox_cl_rand=>struct( ).
* For string field generation you can set the number of words to generate and the length of each word
* (for both, fixed or randomly chosen from a range),
str_rand->field( `DATA` )->words_number( `[1, 15]` )->words_len( `[5, 10]` ). 

str_rand->generate( IMPORTING struct = s_uni ).

And you can configure the single value too.

DATA order_num TYPE n LENGTH 10.
DATA(val_rand) = ztbox_cl_rand=>value( ).
val_rand->len( `6` ).
val_rand->generate( IMPORTING value = order_num ). " It could be any value of the form `0000XXXXXX`.

Installation

Install this project using abapGit abapGit

About

Simple ABAP random data generator

Topics

Resources

Stars

Watchers

Forks

Languages