# String Problem

str1 = Invoice Reference Number: 111, 222, 333, 444

I need to get all the numeric data and set it in the variables .

(variables will have the value of the trimmed numbers).

var1 = 111

var2 = 222

var3 = 333

var4 = 444

kindly take note that number of variables may depend on the numbers in the string.

given above, code sets 4 variables(var1, var2, var3 & var4) because there is 4 combination of numbers.

how to do this in code? is it possible to declare variables on looping?

any help is greatly appreciated.

##### Tags:

##### Naimesh Patel replied

You can tri with this logic:

REPORT ZTEST_NP_123. DATA: STR TYPE STRING. STR = 'Invoice Reference Number: 111, 222, 333, 444'. DATA: L_PART1 TYPE STRING, L_PART2 TYPE STRING. DATA: BEGIN OF IT_NO OCCURS 0, NUM(10), END OF IT_NO. SPLIT STR AT ':' INTO L_PART1 L_PART2. SPLIT L_PART2 AT ',' INTO TABLE IT_NO. loop at it_no. write: / it_no-num. endloop.

Regards,

Naimesh Patel