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: 

Negative Condition checking in read statement

Former Member
0 Kudos

Hi,

i have table, which i have to read, key on which i am going to read that will be determined dynamically. now i have to check the value for the key field is initial or not. i can't use a loop here as it doesn't allow me to mention where condition field dynamically.

thanks & regards,

prabhu

1 ACCEPTED SOLUTION

gautam_totekar
Active Participant
0 Kudos

check for the key field beforyour read statement.

say if the dynamic key field is v_key.

then you can have the code as

If v_key is not initial.

read table I_ITAB into WA_ITAB with key colx = v_key.

endif.

5 REPLIES 5

gautam_totekar
Active Participant
0 Kudos

check for the key field beforyour read statement.

say if the dynamic key field is v_key.

then you can have the code as

If v_key is not initial.

read table I_ITAB into WA_ITAB with key colx = v_key.

endif.

0 Kudos

i think i am misunderstood... what i meant is a situation as below

 read table itab assigning <lfs> with key (<lfs1>) NE space 

<lfs1> will have the name of the key field. and i have to check if any record in itab is having this field as not initial.

hope this time it is clearer

0 Kudos

Hi use this:


DATA: BEGIN OF it OCCURS 0,     "your dynamic table 
        field1 TYPE c,
        field2 TYPE c,
      END OF it.

it-field1 = '1'.
it-field2 = 'A'.
APPEND it.
it-field1 = ''.
it-field2 = 'B'.
APPEND it.

it-field1 = '2'.
it-field2 = 'C'.
APPEND it.

FIELD-SYMBOLS: <struct> TYPE ANY,
               <comp>   TYPE ANY.

LOOP AT it ASSIGNING <struct>.   "loop at your dynamic table
  ASSIGN COMPONENT 'FIELD1' OF STRUCTURE <struct> TO <comp>.   "FIELD1 is determined dynamically
  IF sy-subrc = 0 AND <comp> is not initial.   
    WRITE <comp>.   "will write out <comp> for each entry which has non initial value in <comp> (here FIELD1)
  ENDIF.
ENDLOOP.

Please note that your <lfs> must hold name 'FIELD1' inside, than you can replace it with below code


..
  ASSIGN COMPONENT <lfs> OF STRUCTURE <struct> TO <comp>.  

Regards

Marcin

One thing to be added here:

You can't read table comparing its key field with negative condition NE , only comparison EQ are allowed in READ TABLE statement, that's why I chose above approach.

Edited by: Marcin Pciak on May 26, 2009 4:51 PM

0 Kudos

Prabhu,

If your internal table is not too large or if you are not too concerned about the performance, here is a solution for you.

1) Sort the table by the dynamic column you are interested in using DESCENDING option. (SORT can take variable columns.) This sends intial values to the bottom of the table.

2) Use READ as you discussed in an earlier post.

3) If the record has INITIAL for the record that was read, then that means there are no records with non-initial value.

Former Member
0 Kudos

Hello,

Your key field is decided dynamically.

You can try read statement,



data: w_field type string.

<condition..>
w_field = <field>.   "<-- give the field name which you want to check

read table <table> with key (w_field) = <value>.

Hope this helps you.

Regrads,

Sachinkumar Mehta.