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: 

How to delete this

former_member582701
Contributor
0 Kudos
98

Hi!

SELECT INTERFACENAME ZTABLE EXPDAYS EXPERRORDAYS

FROM ZGL_MPF_CONFIG

INTO TABLE it_configtable.

LOOP AT it_configtable

DELETE FROM (it_configtable-ztable) WHERE (status = 'P' AND

processdat > SY-DATUM + it_configtable-expdays).

ENDLOOP.

SAP tells me status and processdat are unknow.

How i can delete this?

1 ACCEPTED SOLUTION

uwe_schieferstein
Active Contributor
0 Kudos
76

Hello Manel

Itab's with header lines are messing up any program. Thus, use table types and workareas instead:

  DATA:
    ld_date             TYPE d,
    lt_configtable    TYPE STANDARD TABLE OF zgl_mpf_config,
    ls_config          TYPE zgl_mpf_config.

SELECT INTERFACENAME ZTABLE EXPDAYS EXPERRORDAYS
FROM ZGL_MPF_CONFIG
INTO TABLE lt_configtable.


  LOOP at lt_configtable INTO ls_config
                                    WHERE ( status = 'P' ).
"   You have to calculate your date yourself...
     ld_date = syst-datum + ls_config-expdays.

     IF ( ls_config-processdat > ld_date ).
       DELETE lt_configtable INDEX syst-tabix.
     ENDIF.
  ENDLOOP.

Regards

Uwe

6 REPLIES 6

uwe_schieferstein
Active Contributor
0 Kudos
77

Hello Manel

Itab's with header lines are messing up any program. Thus, use table types and workareas instead:

  DATA:
    ld_date             TYPE d,
    lt_configtable    TYPE STANDARD TABLE OF zgl_mpf_config,
    ls_config          TYPE zgl_mpf_config.

SELECT INTERFACENAME ZTABLE EXPDAYS EXPERRORDAYS
FROM ZGL_MPF_CONFIG
INTO TABLE lt_configtable.


  LOOP at lt_configtable INTO ls_config
                                    WHERE ( status = 'P' ).
"   You have to calculate your date yourself...
     ld_date = syst-datum + ls_config-expdays.

     IF ( ls_config-processdat > ld_date ).
       DELETE lt_configtable INDEX syst-tabix.
     ENDIF.
  ENDLOOP.

Regards

Uwe

0 Kudos
76

Hello Manel

I did not read your question carefully enough.

Since you are using a dynamic DELETE statement you cannot use a static WHERE clause. Instead define the where clause dynamic, too.

...
  DATA:
    ld_where_clause     TYPE string.



  LOOP at lt_configtable INTO ls_config.
"   You have to calculate your date yourself...
     ld_date = syst-datum + ls_config-expdays.

"   Concatenate your dynamic WHERE clause
    CONCATENATE ' STATUS = P'
                ' AND PROCESSDAT > ''' ld_date ''''
        INTO gd_where_clause.
 
    DELETE FROM (wa_configtable -ztable) WHERE (ld_where_clause).
  ENDLOOP.

For details refer to the ABAP keyword documentation for SELECT & WHERE clause.

Regards

Uwe

Former Member
0 Kudos
76

Hi,

Declare the fields <b>status</b> and <b>processdat</b> in ur internal table.

And no need to specify the loop.

SELECT INTERFACENAME ZTABLE EXPDAYS EXPERRORDAYS

FROM ZGL_MPF_CONFIG

INTO TABLE it_configtable.

DELETE FROM (it_configtable-ztable) WHERE (status = 'P' AND

processdat > SY-DATUM + it_configtable-expdays).

Former Member
0 Kudos
76

hi,

check whether ur internal table is with or with out header line. your coding only works when internal table is with header line. if internal table is without header line then try like this while creating an work area for internal table as

data: begin of wa_wa_configtable.

.........................

.............................

end of wa_wa_configtable .

LOOP AT wa_configtable from it_configtable

DELETE FROM (wa_configtable -ztable) WHERE (status = 'P' AND

processdat > SY-DATUM + it_configtable-expdays).

ENDLOOP.

if useful reward some points.

with regards,

suresh.

Former Member
0 Kudos
76

try with field symbols

field-symbols : <FS> type any.
data : v_date like sy-datum.

LOOP AT it_configtable.
assign (it_configtable-ztable) to <FS>.
v_date = SY-DATUM + it_configtable-expdays.
DELETE FROM <FS> WHERE status = 'P' AND
                                        processdat GT v_date.
ENDLOOP.

former_member582701
Contributor
0 Kudos
76

I have not explain the scenario too good,

ZTABLE is the name of the database table where i have to delete the records when status and processdat (fields of all ztables) verify the conditions.

The problem is that status and processdat are not in the internal table. This fields are in table of database!

Thanks!