Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic delete and apppend

Former Member
0 Kudos

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

15 REPLIES 15

former_member129652
Active Participant
0 Kudos

Hi,

Please statement your requirement more clearly.  Are you talking about internal table or database table?  What do you mean by "DYNAMICALLY"?

0 Kudos

Hi Micheal.

I want to delete/append records dynamically from the database.

0 Kudos

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,

raymond_giuseppi
Active Contributor
0 Kudos

Table name can be a variable "SELECT FROM (variable)"

(Check Dynamic Program Development in SAP Abap online documentation.)

Regards,

Raymond

Kartik2
Contributor
0 Kudos

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

Former Member
0 Kudos

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?..........

Former Member
0 Kudos

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?..........

JJosh
Active Participant
0 Kudos

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

0 Kudos

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

0 Kudos

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.

Former Member
0 Kudos

Dear Kartik,

I want to delete the record which the FS is pointing towards inside the loop

Former Member
0 Kudos

     Micheal,Where can i find that documentation which you've stated above.....Thanks for you quick response.

JJosh
Active Participant
0 Kudos

Hi,'

As I said before.. Delete using Sy-tabix, so that it deletes the record which the cursor is pointing to.

0 Kudos

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.

...

0 Kudos

In the ABAP editor (SE38), move your cursor to an ABAP keyword (for example, ASSIGNING) .  Press "F1".