09-11-2014 10:43 AM
Hi Experts,
I have the following requirement from a client.
I have the name of the Field of Infotype 0008 var1 = 'LGA01' and var2 = 'BET01' stored in a local variable.
The requirement is such that I need to change the value stored in 'BET01'.
Any help would be appreciated.
09-11-2014 10:48 AM
Hi,
You may use Field Symbol like
data : <FS> type any.
var2 = 'BET01'.
Assign var2 to <FS>.
<FS> = change as required.
09-11-2014 10:52 AM
I have an internal table p0008.
It has a field BET01 which is stored in var1.
I need p0008-bet01 = Change required.
Regards
09-11-2014 11:01 AM
Still question is not clear..
var1 = 'BET01'.
concatenate 'P0008-' var1 into var2.
assign (var2) to <fs>.
<fs> = change required.
09-11-2014 3:49 PM
Hi Sagar,
since we're deep in field-symbols already, do what sreekanth already suggested only maky a combination of both. This would be like:
FIELD-SYMBOLS: <FS_P0008> type P0008, <FS_BETNN> type BETRG.
You will have to assign your workarea ( in my example, i assume it is P0008) to FS <FS_P0008>
LOOP AT P0008 ASSIGNING <FS_P0008> WHERE something.
ASSIGN COMPONENT (var2) OF STRUCTURE <FS_P0008> TO <FS_BETNN>
* make your changes to <FS_BETNN>
<FS_BETNN> = new_value. "DONE - BET01 has new value IN THE TABLE
ENDLOOP.
Remember whatever you do to a field-symbol, you do to the assigned variable or table-field.
In this example, you don't actually loop through your infotype table, but instead you move your memory-handle (that is, what a field-symbol is. Almost but not quite like a C-Pointer) over the lines of the table. Whichever line is linked to the field-symbol at that moment, will get the impact of change imediately.
The second filed-symbol gives you the flexibility to change BET02, BET03... as need be, by changing the value of var2.
Best regards - Jörg
09-11-2014 11:11 AM
Are you struggling with repetitive structures?
then do this.
DATA: s_lgart(14) type c value 'GWA_0008-LGA ',
s_betrg(14) type c value 'GWA_0008-BET ',
index(2) type n.
FIELD-SYMBOLS: <fs_lgart> TYPE PA0008-LGA01,
<fs_betrg> TYPE PA0008-BET01.
do 40 times."Since 40 repetitive structures
index = sy-index. "01, 02, 03, 04...
s_lgart+12(2) = index. "GWA_0008-LGA01, GWA_0008-LGA02 ...
s_betrg+12(2) = index. "GWA_0008-BET01, GWA_0008-BET02...
assing (s_lgart) to <fs_betrg>.
assing (s_betrg) to <fs_lgart>.
"<fs_betrg> and <fs_lgart> now store respective values LGA01, BET01 (in first loop), LGA02,BET02 (in second) and so on...
enddo.
09-11-2014 11:14 AM
Hi Sreekanth,
How do I change the value in the Internal table??
I have only one row selected so that is not an issue. I need to change only the value found in BET01 present in internal table.
If change the value in Filed Symbols how will it reflect in my internal table??
09-11-2014 11:23 AM
for that you have to read each record. if only BET01 has to change.
FIELD-SYMBOL : <fs_0008> TYPE P0008.
LOOP AT p0008 ASSIGNING <fs_0008>.
<fs_0008>-BET01 = change required.
endloop.
09-12-2014 4:49 AM
Hi skreekanth,
The value of BET01 is also stored in a variable right.
So I can I do <fs_0008>-var1 = change required.
Will this make changes in the Internal table as well??
09-12-2014 5:01 AM
yes, I will explain the below statement..
LOOP AT p0008 ASSIGNING <fs_0008>. "For each loop <fs_0008>(like a pointer) will point to each record in p0008
<fs_0008>-BET01 = change required. "changing BET01 of current pointing record. After this statement internal table p0008 will get modified.
endloop.
Try this in debug mode. See the changes.
09-15-2014 9:23 AM
Hi Sreekanth,
I have the value of BET01 in a variable
example Var1 = BET01. It is a dynamic value
I have to fetch it and is stored in a variable. It can be anythinh like BET01 or BET02 or LGAT01
Then I have to change the value stored in that particular colum
Fro instance if
Var1 = BET02
itab-BET02 = 10.
I have to change the value in itab-Bet02 = new value
Regards
09-15-2014 9:33 AM
Hi Sagar,
Use Do varying it will help please refer to below link for example
DO 40 TIMES
VARYING LGART FROM GWA_0008-LGA01 NEXT GWA_0008-LGA02
VARYING BETRG FROM GWA_0008-BET01 NEXT GWA_0008-BET02.
" CODE
ENDDO.
Thanks.
09-15-2014 9:39 AM
I want to know how to assign the column name that is stored in the variable to the internal table
09-15-2014 9:55 AM
09-15-2014 10:55 AM