Sample ABAP program to create random data in a notepad file

 Below is the program in ABAP to prepare a question paper with 20 questions on Arithmetic operations on two numbers.

The program will generate numbers and arithmetic operations randomly.

The program will save these random questions in a .txt file on the local system.

REPORT.

*--Structure type

TYPES: BEGIN OF TYP_NUM,

N1 TYPE I,

OP TYPE C,

N2 TYPE I,

CH TYPE C,

END OF TYP_NUM.

DATA OPT TYPE I.

DATA WA TYPE TYP_NUM.

DATA ITAB TYPE TABLE OF TYP_NUM.

DO 20 TIMES.

CALL FUNCTION 'RANDOM_I4'

EXPORTING

RND_MIN = 10

RND_MAX = 90

IMPORTING

RND_VALUE = WA-N1.

CALL FUNCTION 'RANDOM_I4'

EXPORTING

RND_MIN = 10

RND_MAX = 90

IMPORTING

RND_VALUE = WA-N2.

CALL FUNCTION 'RANDOM_I4'

EXPORTING

RND_MIN = 1

RND_MAX = 4

IMPORTING

RND_VALUE = OPT.

CASE OPT.

WHEN 1.

WA-OP = '+'.

WHEN 2.

WA-OP = '-'.

WHEN 3.

WA-OP = 'x'.

WHEN 4.

WA-OP = '/'.

ENDCASE.

WA-CH = '='.

APPEND WA TO ITAB.

CLEAR WA.

ENDDO.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

FILENAME = 'c:/ques_paper.txt'

TABLES

DATA_TAB = ITAB.

 

Comments

Popular posts from this blog

Domains and Data Elements

Sample ABAP program for Updating notepad file data to Internal table and Sending it to Application server

OPEN SQL EXAMPLES IN ABAP – PART 2