Former Member

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.

10|10000 characters needed characters exceeded

Related questions

Posted on Nov 24, 2007 at 03:39 AM

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

10|10000 characters needed characters exceeded
• Former Member
Posted on Nov 24, 2007 at 03:57 AM

Hi Newbie,

You can not extend variables in dynamic way but we can achieve this using the help of internal tables.

If your string contains a single common letter which is separating numerics then SPLIT will be used, otherwise string contains different characters in the string which are separating numerics then use the following code.

Ofcourse, this code can be used for both of the cases, but will be relevant for different characters in the string, otherwise SPLIT will be best option.

Check this code.

TYPES: BEGIN OF TY_VAR,

NO(10),

END OF TY_VAR.

DATA IT_VAR TYPE STANDARD TABLE OF TY_VAR WITH HEADER LINE.

DATA V_LENGTH TYPE I.

DATA V_FLAG.

DATA V_POS TYPE I.

DATA V_CHAR.

DATA WA_VAR TYPE TY_VAR.

PARAMETERS: P_NUMBER TYPE STRING.

START-OF-SELECTION.

V_LENGTH = STRLEN( P_NUMBER ).

DO V_LENGTH TIMES.

V_CHAR = P_NUMBER+V_POS(1).

IF V_CHAR CO '0123456789'.

CONCATENATE WA_VAR V_CHAR INTO WA_VAR.

ELSE.

CLEAR WA_VAR.

V_FLAG = 'X'.

ENDIF.

IF WA_VAR IS NOT INITIAL AND V_FLAG = 'X'.

APPEND WA_VAR TO IT_VAR.

CLEAR WA_VAR.

CLEAR V_FLAG.

ENDIF.

ENDDO.

*-Numbers in the string

LOOP AT IT_VAR.

WRITE:/ IT_VAR-NO.

ENDLOOP.

Thanks,

Vinay

10|10000 characters needed characters exceeded
• Former Member Former Member

Hi,

Yes, You can reward points to one or more or all replies to the person who answered to your question.

<b>I posted a thread and marked it as a question. Several people replied and gave me useful advice. I'd like to reward points. What do I do?</b>

https://www.sdn.sap.com/irj/sdn/crphelp

Thanks,

Vinay