‎2009 Aug 19 7:40 PM
Hello All,
I've an internal table with 15 fields. First 5 fields are all text fields and the next 10 fields are of type DMBTR. I have to validate each of these fields. Currently I've coded as follows:
data: begin of itab1 occurs 0,
text1 type char4,
text2 type char2,
text3 type char10,
text4 type char6,
text5 type char4,
amt1 type dmbtr,
amt2 type dmbtr,
amt3 type dmbtr,
amt4 type dmbtr,
amt5 type dmbtr,
amt6 type dmbtr,
amt7 type dmbtr,
amt8 type dmbtr,
amt9 type dmbtr,
amt10 type dmbtr,
end of itab1.
perform some steps and
collect data into itab1.
loop at itab1.
if itab1-amt1 CA 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' or
itab1-amt1 CA 'abcdefghijklmnopqrstuvwxyz' or
itab1-amt1 CA '~`!@#$%^&*()-_=+[{]}\|;:'",<.>/?'.
write:/ 'error'.
endif.
if itab1-amt2 CA 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' or
itab1-amt2 CA 'abcdefghijklmnopqrstuvwxyz' or
itab1-amt2 CA '~`!@#$%^&*()-_=+[{]}\|;:'",<.>/?'.
write:/ 'error'.
endif.
...
...
...
if itab1-amt10 CA 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' or
itab1-amt10 CA 'abcdefghijklmnopqrstuvwxyz' or
itab1-amt10 CA '~`!@#$%^&*()-_=+[{]}\|;:'",<.>/?'.
write:/ 'error'.
endif.
endloop.
Do we have a better approach to do this, instead of repeating the same step for 10 fields?
Thanks in advance.
Siri
‎2009 Aug 19 7:55 PM
or using field symbols
data: fieldname(11) type c value 'ITAB1-AMT',
idx(2) type c.
field-symbls <field> type any.
loop at itab1.
do 10 times.
write sy-index to idx. "' 1', ' 2'...'10'
condense idx. "'1', '2'...'10'
concatenate fieldname idx into fieldname. "ITAB-AMT1, ITAB-AMT2 ...
assign (fieldname) to <field>. "now <field> stores appropriate value
if <field> CA 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' or
<field> CA 'abcdefghijklmnopqrstuvwxyz' or
<field> CA '~`!@#$%^&*()-_=+[{]}\|;:'",<.>/?'.
write: / 'error'.
endif.
enddo.
endloop.
Regards
Marcin
‎2009 Aug 19 7:47 PM
Hi,
You could Macros instead:
DEFINE check_number.
if not itab1-amt&1 co '0123456789'.
write:/ 'error'.
endif.
END-OF-DEFINITION.
check_number: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10.
BUT, as you declared your fields as type of DMBTR, and this is a CURRENCY type, if you try to assign a character that is not a number, should give you a Dump.
Regards,
Frisoni
‎2009 Aug 19 7:55 PM
or using field symbols
data: fieldname(11) type c value 'ITAB1-AMT',
idx(2) type c.
field-symbls <field> type any.
loop at itab1.
do 10 times.
write sy-index to idx. "' 1', ' 2'...'10'
condense idx. "'1', '2'...'10'
concatenate fieldname idx into fieldname. "ITAB-AMT1, ITAB-AMT2 ...
assign (fieldname) to <field>. "now <field> stores appropriate value
if <field> CA 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' or
<field> CA 'abcdefghijklmnopqrstuvwxyz' or
<field> CA '~`!@#$%^&*()-_=+[{]}\|;:'",<.>/?'.
write: / 'error'.
endif.
enddo.
endloop.
Regards
Marcin
‎2009 Aug 19 8:37 PM
Thank You Marcin Pciak and Frisoni
It worked. I've awarded points to you both.
Siri