‎2009 Dec 18 11:56 AM
Hello Friends,
Consider i have a internal table itab1 defined as
data: begin of itab1 occurs 0,
fid type string,
end of itab1.
I have another internal table itab2 defined as
data: begin of itab2 occurs 0,
f1 type string,
f2 type string,
f3 type string,
end of itab2.
here itab1-fid will only hold fieldnames of itab2. i.e f1, f2, f3.
Now i have to clear itab2 fields based on the content of itab1-fid.
Eg,
loop at itab1.
"here if itab1-fid holds the value 'f1',
"i have to clear the value of itab2-f1.
endloop.
Is this possible using filed symbols?
Vikranth
‎2009 Dec 18 12:30 PM
Hi,
I just tried the same and it is working. Just copy paste the program and see in debugging ITAB2 to get the feel.
report abc.
*--------------------------------------------
data: begin of itab1 occurs 0,
fid type string,
end of itab1.
data: begin of itab2 occurs 0,
f1 type string,
f2 type string,
f3 type string,
end of itab2.
*--------------------------------------------
field-symbols : <FS> type any.
data : fieldname(35) type c.
*--------------------------------------------
itab1-fid = 'F2'.
append itab1.
itab1-fid = 'F3'.
append itab1.
*--------------------------------------------
itab2-f1 = 'This is f1'.
itab2-f2 = 'This is f2'.
itab2-f3 = 'This is f3'.
append itab2.
append itab2.
*--------------------------------------------
loop at itab2.
loop at itab1.
concatenate 'ITAB2-' itab1-fid into fieldname.
assign (fieldname) to <FS> .
clear <FS>.
endloop.
modify itab2.
endloop.
regards,
amit m.
‎2009 Dec 18 12:30 PM
Hi,
I just tried the same and it is working. Just copy paste the program and see in debugging ITAB2 to get the feel.
report abc.
*--------------------------------------------
data: begin of itab1 occurs 0,
fid type string,
end of itab1.
data: begin of itab2 occurs 0,
f1 type string,
f2 type string,
f3 type string,
end of itab2.
*--------------------------------------------
field-symbols : <FS> type any.
data : fieldname(35) type c.
*--------------------------------------------
itab1-fid = 'F2'.
append itab1.
itab1-fid = 'F3'.
append itab1.
*--------------------------------------------
itab2-f1 = 'This is f1'.
itab2-f2 = 'This is f2'.
itab2-f3 = 'This is f3'.
append itab2.
append itab2.
*--------------------------------------------
loop at itab2.
loop at itab1.
concatenate 'ITAB2-' itab1-fid into fieldname.
assign (fieldname) to <FS> .
clear <FS>.
endloop.
modify itab2.
endloop.
regards,
amit m.
‎2009 Dec 18 1:00 PM
Hello Amit/ ilesh,
Thank you for the suggestions. I got the hint now. Now i will be able to proceed according to my requirement
Vikranth
‎2009 Dec 18 12:55 PM
Hi Vikranth Reddy,
As you must be knowing the number of fields in itab2.. you can do it in this way too..
REPORT ZTEST_1.
DATA: BEGIN OF ITAB1 OCCURS 0,
FID TYPE STRING,
END OF ITAB1.
DATA: BEGIN OF ITAB2 OCCURS 0,
F1 TYPE STRING,
F2 TYPE STRING,
F3 TYPE STRING,
END OF ITAB2.
FIELD-SYMBOLS : <FS> TYPE ANY.
FIELD-SYMBOLS : <FS2> TYPE ANY.
FIELD-SYMBOLS : <FS3> TYPE ANY.
DATA : FIELDNAME(35) TYPE C.
DATA : FIELDNAME2(35) TYPE C.
ITAB1-FID = 'F1'.
APPEND ITAB1.
ITAB1-FID = 'F3'.
APPEND ITAB1.
ITAB2-F1 = 'abcd'.
ITAB2-F2 = 'efgh'.
ITAB2-F3 = 'ijkl'.
APPEND ITAB2.
ITAB2-F1 = '1234'.
ITAB2-F2 = 'efdf'.
ITAB2-F3 = 'ijkl'.
APPEND ITAB2.
ITAB2-F1 = 'rewr'.
ITAB2-F2 = 'efgh'.
ITAB2-F3 = 'ijkl'.
APPEND ITAB2.
LOOP AT ITAB1.
CASE SY-TABIX.
WHEN 1.
CONCATENATE 'ITAB2-' ITAB1-FID INTO FIELDNAME.
ASSIGN (FIELDNAME) TO <FS> .
WHEN 2.
CONCATENATE 'ITAB2-' ITAB1-FID INTO FIELDNAME2.
ASSIGN (FIELDNAME2) TO <FS2> .
WHEN OTHERS.
ENDCASE.
ENDLOOP.
LOOP AT ITAB2.
CLEAR <FS>.
CLEAR <FS2>.
MODIFY ITAB2.
WRITE : / SY-VLINE, ITAB2-F1 , SY-VLINE, ITAB2-F2, SY-VLINE, ITAB2-F3, SY-VLINE.
ENDLOOP.
WRITE : 'Test by ilesh'.Hope it will solve your problem..
Thanks & Regards
ilesh 24x7
ilesh Nandaniya