2015 Nov 11 12:55 PM
Dear All,
I'm doing little experiments on field symbols , I got stuck at a point. It may be a small thing but I'm not clicking it.
scenario is -
_________________________________________________________________________
* Please don't consider my code , it may wrong, Kindly try to understand what I want to achieve.
_______________________________________ _________________________________
Data str1 type string,
str2 type string,
text1 type string,
text2 type string.
field-symbols <fs1>,<fs2>.
do 2 times.
count = count + 1.
text1 = count.
CONCATENATE 'STR' text1 into text1. " now value in TEXT1 is STR1.
condense text1.
ASSIGN TEXT1 to <fs1>. " Now value of <fs1> is STR1 (Which is a variable defined in the beging)
text2 = 'HELLO'.
ASSIGN TEXT2 to <fs2>. " Assinging value of text2 to <FS2>
ASSIGN <fs2> to <fs1> . " here I'm trying to assign value of <fs2> which is 'HELLO' to the variable STR1, STR1 is already assigned to <FS1>
write : / SRT1,
/ STR2.
Desired O/P.
HELLO
HELLO
So basically my requirement is -
I have to fill 2 variable str1 and str2, which I want to fill on cont = 1 and count = 2 respectively. This I can achieve by using case statement.
but in real scenario I have more than 15 variable. So I want to use field symbol.
I want to fill value of text2 in to the variale which is assign to <FS1> .
(currently I'm having - > Text2 = HELLO , <FS1> = STR1
I want ----- STR1 = TEXT2
means ---> STR1 = 'HELLO').
Is it possible or not. Otherwise I'll go with case statement.
2015 Nov 11 4:39 PM
Hi Bhunesh,
View the code.
DATA: lv_text1 TYPE string,
lv_text2 TYPE string,
lv_dis TYPE string,
lv_cnt TYPE string.
FIELD-SYMBOLS: <fs> TYPE ANY.
DO 2 TIMES.
lv_cnt = sy-index.
CONCATENATE 'LV_TEXT' lv_cnt INTO lv_dis.
CONDENSE lv_dis NO-GAPS.
ASSIGN (lv_dis) to <fs>.
CHECK <fs> IS ASSIGNED.
<fs> = lv_dis.
ENDDO.
WRITE: lv_text1, lv_text2.
Hope it helpful,
Regards,
Venkat.
Dear All,
I'm doing little experiments on field symbols , I got stuck at a point. It may be a small thing but I'm not clicking it.
scenario is -
_________________________________________________________________________
* Please don't consider my code , it may wrong, Kindly try to understand what I want to achieve.
_______________________________________ _________________________________
Data str1 type string,
str2 type string,
text1 type string,
text2 type string.
field-symbols <fs1>,<fs2>.
do 2 times.
count = count + 1.
text1 = count.
CONCATENATE 'STR' text1 into text1. " now value in TEXT1 is STR1.
condense text1.
ASSIGN TEXT1 to <fs1>. " Now value of <fs1> is STR1 (Which is a variable defined in the beging)
text2 = 'HELLO'.
ASSIGN TEXT2 to <fs2>. " Assinging value of text2 to <FS2>
ASSIGN <fs2> to <fs1> . " here I'm trying to assign value of <fs2> which is 'HELLO' to the variable STR1, STR1 is already assigned to <FS1>
write : / SRT1,
/ STR2.
Desired O/P.
HELLO
HELLO
So basically my requirement is -
I have to fill 2 variable str1 and str2, which I want to fill on cont = 1 and count = 2 respectively. This I can achieve by using case statement.
but in real scenario I have more than 15 variable. So I want to use field symbol.
I want to fill value of text2 in to the variale which is assign to <FS1> .
(currently I'm having - > Text2 = HELLO , <FS1> = STR1
I want ----- STR1 = TEXT2
means ---> STR1 = 'HELLO').
Is it possible or not. Otherwise I'll go with case statement.
2015 Nov 11 1:28 PM
Not totally clear what you are trying to achieve.
What I could understood is that you will have Fifteen variable STR1 ... STR15 and you want to populate it from the values TEXT1 to TEXT15 respectively.
If this is correct, then you could do this.
data : LV_STRING TYPE CHAR50,
lv_index type CHAR2.
DO 15 TIMES.
lv_index = lv_index + 1.
concatenate 'STR' lv_index into lv_string.
assign lv_string to <f1>. "<f1> points to STR1 in the first loop pass STR2 in second loop pass and so on
if sy-subrc = 0.
concatenate 'TEXT' lv_index into lv_string.
assign lv_string to <f2>. "<f2> points to TEXT1 in the first loop pass TEXT2 in second loop pass and so on
if sy-subrc = 0.
<f1> = <f2>. "This will move the value from TEXT1 to STR1 for first loop pass TEXT2 to STR2 in second loop pass and so on...
endif.
endif.
ENDDO.
2015 Nov 11 1:44 PM
Hi.
The result is what you want but honestly is not so clear to me
STR01 to STRn will contain the text-content switched as you wrote.
You forgot only two round brackets in your 'code'.
DATA: str01 type string,
str02 type string,
str03 type string,
str04 type string,
str05 type string,
str06 type string,
str07 type string,
str08 type string,
str09 type string,
str10 type string,
str11 type string,
str12 type string,
str13 type string,
str14 type string,
str15 type string,
text1 type string,
text2 type string,
gnumc(2) TYPE n.
data: gtimes TYPE i value 15.
field-symbols: <fs1>,<fs2>.
DATA: outstr1 TYPE string,
outstr2 TYPE string.
DO gtimes TIMES.
ADD 1 to gnumc.
CONCATENATE 'STR' gnumc INTO text1.
CONDENSE text1.
ASSIGN (text1) TO <fs1>.
text2 = 'Hello'.
CONCATENATE text2 gnumc INTO text2. "Only to show differences
ASSIGN text2 TO <fs2>.
<fs1> = <fs2>.
ENDDO.
CLEAR gnumc.
DO gtimes TIMES.
ADD 1 to gnumc.
CONCATENATE 'STR' gnumc INTO text1.
CONDENSE text1.
ASSIGN (text1) TO <fs1>.
WRITE:/ <fs1>.
ENDDO.
Hope to help
2015 Nov 11 4:39 PM
Hi Bhunesh,
View the code.
DATA: lv_text1 TYPE string,
lv_text2 TYPE string,
lv_dis TYPE string,
lv_cnt TYPE string.
FIELD-SYMBOLS: <fs> TYPE ANY.
DO 2 TIMES.
lv_cnt = sy-index.
CONCATENATE 'LV_TEXT' lv_cnt INTO lv_dis.
CONDENSE lv_dis NO-GAPS.
ASSIGN (lv_dis) to <fs>.
CHECK <fs> IS ASSIGNED.
<fs> = lv_dis.
ENDDO.
WRITE: lv_text1, lv_text2.
Hope it helpful,
Regards,
Venkat.
2015 Nov 17 5:52 AM
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |