11-24-2007 3:34 AM
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.
11-24-2007 3: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
11-24-2007 3: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
11-24-2007 3:45 AM
loop at it_no.
write: / it_no-num.
endloop.
this code only displays the data..
how can i declare that var1 = 111 etc.?
take note that the number variables may depend of string number. if there 7 combination of numbers in string, program should declare 7 variables also. did you get me?
thnks!
11-24-2007 3:48 AM
You can read table IT_NO and use the field NUM to have the values
Or change the code like:
data: var1(10),
var2(10),
var3(10),
var4(10),
var5(10),
var6(10),
var7(10).
SPLIT STR AT ':' INTO L_PART1 L_PART2.
SPLIT L_PART2 AT ',' INTO var1 var2 var3 var4 var5 var6 var7.
Regards,
Naimesh Patel
11-24-2007 3:52 AM
what if there is 100 combination of numbers
should i declare:
data: var1(10) up to var100(10)
thank you!
11-24-2007 3:55 AM
But instead of this you can use the internal table IT_NO and use the LOOP to read that.
Otherwise you have to defind like:
data: var1(10)
var2(10),
...
var100(10).
Regards,
Naimesh Patel
11-24-2007 4:02 AM
sorry I did not read this:
You can read table IT_NO and use the field NUM to have the values
anyways i'll try the code and reward you points.
I just got another question..
because your the only one helping me out, id like to put points for all your reply.
is it possible or only one option per person reply?
11-24-2007 4:04 AM
11-24-2007 3: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
11-24-2007 4:06 AM
11-24-2007 4:16 AM
Hi,
Yes, You can reward points to one or more or all replies to the person who answered to your question.
You can find answer for your question in this link for the below 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