07-04-2012 8:01 AM
Dear Experts,
Can any one help out with any links or documents working on DYNAMICALLY DELETING THE RECORDS OF THE TABLE & DYNAMICALLY APPENDING THE RECORDS IN THE TABLE
Thanks
Katrice
07-04-2012 8:19 AM
Hi,
Please statement your requirement more clearly. Are you talking about internal table or database table? What do you mean by "DYNAMICALLY"?
07-04-2012 8:30 AM
Hi Micheal.
I want to delete/append records dynamically from the database.
07-04-2012 9:17 AM
Dear Katrice Hwkins,
What kind of "DYNAMIC" do you need? If you want the database table name to be dynamic, you can use a character type variable to hold the database name. The INSERT and DELETE statements both support dynamic database names.
For example.
DATA: dbname TYPE c LENGTH 5 VALUE 'SPFLI'.
DATA: wa_spfli TYPE spfli.
DELETE (dbname) FROM wa_spfli.
INSERT (dbname) FROM wa_spfli.
If you need the work area to be dynamic, try RTTI/RTTC Service. Please read
Best Regards,
07-04-2012 9:36 AM
Table name can be a variable "SELECT FROM (variable)"
(Check Dynamic Program Development in SAP Abap online documentation.)
Regards,
Raymond
07-04-2012 9:42 AM
Hi,
Please go through the following document to create dynamic internal table.
http://wiki.sdn.sap.com/wiki/display/ABAP/Dynamic+Internal+table
Here in the mentioned example, data is being fetched from data base table to the dynamic internal table <dyn_table>.
Here is how you can append data to the dynamic internal table:
* Creating work area for the dynamic internal table
CREATE DATA dy_line LIKE LINE OF <dyn_table>.
ASSIGN dy_line->* TO <dyn_wa>.
Now <dyn_wa> will serve as a work area for the internal table, now you have to fill this work area and then append it to the dynamic internal table.
Since, the field symbol <dyn_wa> is untyped. It has to be filled as follows:
ASSIGN COMPONENT 1 OF STRUCTURE <dyn_wa> TO <dyn_field>.
IF sy-subrc EQ 0.
<dyn_field> = 'First field'.
ENDIF.
ASSIGN COMPONENT 2 OF STRUCTURE <dyn_wa> TO <dyn_field>.
IF sy-subrc EQ 0.
<dyn_field> = 'Second field'.
ENDIF.
Like wise the work area can be filled. For more details on access using field symbols you may visit the follwing link:
http://help.sap.com/saphelp_nw70/helpdata/en/fc/eb3605358411d1829f0000e829fbfe/frameset.htm
once your work area is ready it can be appended as:
APPEND <dyn_wa> TO <dyn_table>.
Similarly, delete operation can be performed as:
DELETE <dyn_table> WHERE 'FIELD1' EQ <condition>.
Hope it helps. Thank you.
Regards,
Kartik
07-04-2012 10:20 AM
Dear Experts,
Thanks for all the help...Can anyone let me know can we delete Fieldsymbols when we are in loop?...Can anyone justify my question?..........
07-04-2012 10:20 AM
Dear Experts,
Thanks for all the help...Can anyone let me know can we delete Fieldsymbols when we are in loop?...Can anyone justify my question?..........
07-04-2012 10:25 AM
You can delete ....
LOOP AT <table> ASSIGNING <FS_WA>.
IF <condition>
delete <table> INDEX sy-tabix or use the actual variable.
ENDIF.
ENDLOOP.
This will delete the entry from the internal table.
Thanks
07-04-2012 10:26 AM
Hi,
What delete are you talking about, do you want to delete an entry in the table ? Do you want to delete the field symbol as such, so that it may not be used further ? Do you want to delete the internal table ?
I do not understand why would anybody want to delete a field symbol as it is. You should only justify your question, whether you really want to delete.
If you do not want to use the field symbol any more then you may unassign it and then free it, and need not use it for further processing.
Thanks and regards,
kartik
07-04-2012 10:36 AM
Hi,
No, you can't. If you use LOOP AT itab ASSIGNING <fs>, you cannot do UNASSIGN <fs>.
The ABAP documentation says "With the addition ASSIGNING, you assign the current line to a field symbol <fs>; within the loop, you are not allowed to assign a different memory area to the field symbol or cancel the assignment with UNASSIGN.
07-04-2012 10:39 AM
Dear Kartik,
I want to delete the record which the FS is pointing towards inside the loop
07-04-2012 10:41 AM
Micheal,Where can i find that documentation which you've stated above.....Thanks for you quick response.
07-04-2012 10:43 AM
Hi,'
As I said before.. Delete using Sy-tabix, so that it deletes the record which the cursor is pointing to.
07-04-2012 10:44 AM
You should declare the internal table as a standard one, use
FIELD-SYMBOLS: <itab> TYPE STANDARD TABLE.
and not
FIELD-SYMBOLS: <itab> TYPE ANY TABLE.
so you can use implicit index operations like
LOOP AT <itab> ASSIGNING <record>.
ASSIGN COMPONENT 'MATNR' OF STRUCTURE <record> TO <field>.
IF <field> CS 'A'.
DELETE <itab>.
ENDIF.
ENDLOOP.
Regards,
Raymond
PS: Be as specific as possible when you post a question, to get faster and more relevant answers. In particular, specify if a table is a database table or an internal table.
...
07-04-2012 10:48 AM
In the ABAP editor (SE38), move your cursor to an ABAP keyword (for example, ASSIGNING) . Press "F1".