‎2007 Jan 18 7:12 PM
Hi all
Why do we need to declare a workarea to do any database related operations.can we not get records directly from database instead of creating a workarea or internaltable...what makes difference.
Thanks and Regards
‎2007 Jan 18 7:18 PM
You can read from the database in a few ways, the first way is with a SELECT...ENDSELECT, this is not the best way as it is a round trip for each record, here you must define a work area to read the data into, even if you use a TABLES statement for the table name, it is still a work area.
tables: mara.
select * from mara.
endselect.Or you can use a work area defined by a DATA statement.
Data: xmara type mara.
select * from mara into xmara.
endselect.Or a single select.
data: xmara type mara.
Select Single * into xmara from mara
where matnr = p_matnr.The most efficient way for multplie records is an arry fetch here, you can specify an internal table .
data: imara type table of mara with header line.
select * into table imara from mara
up to 100 rows.But in the OO context, header lines(which are like implicit work areas) are not allowed, so you need a work area to read the data from the internal table.
data: imara type table of mara .
data: xmara like line of imara.
select * into table imara from mara
up to 100 rows.
loop at imara into xmara.
write:/ xmara-matnr, xmara-mtart.
endloop.
Regards,
Rich Heilman
‎2007 Jan 18 7:18 PM
You can read from the database in a few ways, the first way is with a SELECT...ENDSELECT, this is not the best way as it is a round trip for each record, here you must define a work area to read the data into, even if you use a TABLES statement for the table name, it is still a work area.
tables: mara.
select * from mara.
endselect.Or you can use a work area defined by a DATA statement.
Data: xmara type mara.
select * from mara into xmara.
endselect.Or a single select.
data: xmara type mara.
Select Single * into xmara from mara
where matnr = p_matnr.The most efficient way for multplie records is an arry fetch here, you can specify an internal table .
data: imara type table of mara with header line.
select * into table imara from mara
up to 100 rows.But in the OO context, header lines(which are like implicit work areas) are not allowed, so you need a work area to read the data from the internal table.
data: imara type table of mara .
data: xmara like line of imara.
select * into table imara from mara
up to 100 rows.
loop at imara into xmara.
write:/ xmara-matnr, xmara-mtart.
endloop.
Regards,
Rich Heilman
‎2007 Jan 18 7:21 PM
Hi Popi,
We can also do database related operations without creating work area too. But it is a good practise to have work areas.
Generally we will get data into internal tables from database. For LDBs(Logical databases ) you doesnt require internal tables or work areas.
Thanks,
Vinay
‎2007 Jan 18 7:22 PM
Hi,
The reason you need to use work area or internal table if you want to manipulate/ modify the data otherwise you can read directly from database.
Regards,
Ferry Lianto
‎2007 Jan 18 7:33 PM
Hi
Can we not modify directly in the database?
Thanks and Regards
popi
‎2007 Jan 18 7:36 PM
Hi,
We can directly modify database content using MODIFY statement but updating database tables directly is not a good practise.
Check this link for MODIFY statement
http://www.sts.tu-harburg.de/teaching/sap_r3/ABAP4/modify_d.htm
Better to Update them through transactions or BDCs.
Thanks,
Vinay
‎2007 Jan 18 7:38 PM
‎2007 Jan 18 7:44 PM
Hi vinay
can u please be more specific that why is it using a workarea r internal table is a best practice...what ever modifications we r doing we r doing to the database only either it is thru workarea r direct.sorry for bothering u all..this question is bothering me soo much...not able to move any forward
Thanks and Regards
popi
‎2007 Jan 18 7:56 PM
I dopn't think you need either a work area or a tables statement. For example:
REPORT ztest.
UPDATE ztest
SET f1 = space
WHERE f2 = 'X'.
I'm not recommending doing it this way, just saying that syntactically, it's correct and will work.
Rob
Message was edited by:
Rob Burbank
‎2007 Jan 18 7:57 PM
‎2007 Jan 18 8:06 PM
I recall seeing this in an SAP note some time ago. It was just a quick database ZAP, but I was a bit surprised that they would use it.
(It was note 301795. We had to implement it after upgrading to 4.6C)
Rob
Message was edited by:
Rob Burbank
‎2007 Jan 18 7:33 PM
Hi,
Using a Work Area or Internal Tables is a best practice. Using TABLES Statements & then not mentioning anythin in the INTO is an obsolete way. Also, TABLES reserves some space in the memory before the data is fetched.
Reward points if the answer is helpful.
Regards,
Mukul