Application Development and Automation 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: 
Read only

reading data from internal table

Former Member
0 Likes
336

when I read a data from the internal table I should be able to validate the correct entry

My internal table is like this

Field1 Field2

X

Y

Z

Z

Z

X

Y

Z

Z

Z

The validation is like this it should follow XYZZ or XYZZZZ or XYZZZZZZZ else it should throw an error message

How to identify whether the file format is in the above order or not

Kindly response.

Thanks

Yamini.A

2 REPLIES 2
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
319

Something like this?



data: begin of itab occurs 0,
      field1 type c,
      fleld2 type c,
      end of itab.

data: istr type table of string with header line..

itab-field1 = 'X'.  append itab.
itab-field1 = 'Y'.  append itab.
itab-field1 = 'Z'.  append itab.
itab-field1 = 'Z'.  append itab.
itab-field1 = 'Z'.  append itab.
itab-field1 = 'X'.  append itab.
itab-field1 = 'Y'.  append itab.
itab-field1 = 'Z'.  append itab.
itab-field1 = 'Z'.  append itab.
itab-field1 = 'Z'.  append itab.
itab-field1 = 'Z'.  append itab.
itab-field1 = 'Z'.  append itab.
itab-field1 = 'X'.  append itab.
itab-field1 = 'Y'.  append itab.
itab-field1 = 'Z'.  append itab.
itab-field1 = 'Z'.  append itab.
itab-field1 = 'Z'.  append itab.
itab-field1 = 'Z'.  append itab.
itab-field1 = 'Z'.  append itab.
itab-field1 = 'Z'.  append itab.
itab-field1 = 'Z'.  append itab.
itab-field1 = 'Z'.  append itab.

loop at itab.

  if itab-field1 = 'X'
    and sy-tabix > 1.
    append istr.
    clear istr.
  endif.

  concatenate istr itab-field1 into istr.

 at last.
 append istr.
 endat.

endloop.


loop at istr.
  write:/ istr.
  if istr(3) <> 'XYZ'.
   write:/  'There is a problem with the format'.
  endif.
endloop.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
319

loop at itab.

case field1.

when 'X'.

if sy-tabix > 1.

*-- skip the first time

if v_zcount < 2.

clear v_zcount.

*-- error

else.

clear v_zcount.

endif.

when 'Y'.

when 'Z'.

v_zcount = v_zcount + 1.

endcase.

endloop.