‎2007 Sep 28 7:12 AM
Hi,
I have a database Table that have 3 column : ID, Name, Contact No. with a total of 50 record.
Problem 1: Loop through all data in each column.
Eg.
I need to do a loop on all data in ID column to check for null value. After ID column, will move to check Name column's data and lastly Contact No column' s data.
How to do that?
Problem 2: Loop through all data in only particular column.
Eg. Only want to check for ID column.
How to get the column name and do the loop on that particular column?
Regards,
Rayden
‎2007 Sep 28 7:15 AM
Move the database table entries to an internal table with the columns that you want and make the search..
‎2007 Sep 28 7:15 AM
Move the database table entries to an internal table with the columns that you want and make the search..
‎2007 Sep 28 7:18 AM
Hi Shakir,
How do i move the column that is needed to itab?
Regards,
Rayden
‎2007 Sep 28 7:21 AM
Hi Rayden-
Declare an internal table with the field of your database table:
Data: begin of itab occurs 0,
ID type Database tabel-ID,
end of itab.
select ID from DBtable into table itab.
then do the processing..
loop at itab where ID = <condition>.
endloop.
Hope this will help.
‎2007 Sep 28 7:15 AM
hi Rayden,
What do you want to achieve by these looping?
thanks
ec
‎2007 Sep 28 7:20 AM
Hi Eric,
I want to do a simple validation on the table, by using ABAP code. Eg. To validate mandatory for certain column or all column. Any idea how to do that?
Regards,
Rayden
‎2007 Sep 28 7:24 AM
Hi
decalre a internal table of type ur database table
and write a select query like what ever fileds you want from that data base , if you want all then select *
and store that values in that internal table
and loop at that internal table into workarea of that table
<b>ex</b> LOOP AT IT_SOBID INTO WA_SOBID.
then it will capture total line values
ID name AND etc..
then you cn chek that very esyly
<b>reward if usefull</b>
‎2007 Sep 28 7:28 AM
Hi Naresh,
If i were to do a loop on all data for 3 column. Let say there is certains field is blank. So i want to get the row number and column name for the error field how to do that? Any code sample for reference?
Regards,
Rayden
‎2007 Sep 28 7:41 AM
Rayden, Check the code given below......
data: itab like table of Ztable with header line.
select * from ztable into table itab.
loop at itab.
write:/ ITAB.
if itab-id is initial.
write: 'ID is INITIAL'.
endif.
if itab-name is initial.
write: 'Name is INITIAL'.
endif.
if itab-contact is initial.
write: 'Contact is INITIAL'.
endif.
endloop.
Reward points if useful, get back in case of query...
Cheers!!!
‎2007 Sep 28 7:18 AM
Hi,
you can write:
loop at itab into wa where ID <> ' '.
endloop.
in this loop it will check for ID field only.
‎2007 Sep 28 7:23 AM
Hi Sonali,
So if i have 3 column to loop i have to code 3 loop statement? How to do it in a more dynamic way. Eg. User select Name. The Loop statement will able to loop the Name column, or ID for ID column. By using 1 loop statement. How to achieve that?
Regards,
Rayden
‎2007 Sep 28 7:21 AM
Hi Rayden,
Its very simple.
Get the records those you want into an internal table using <b>SELECT</b> statement.
Now your internal table is having 3 fields with ID, Name and Contact.
If you want to find only records in which ID is null... U can use loop as below.
loop at itab where ID is initial.
endloop.And one more thing is you can't loop through at only one field. If you are looping means entaire record will be processed... Ofcourse there are some cases with Control break statements like... AT NEW, AT END OF, etc,.
Reward If Helpful.
Regards
--
Sasidhar Reddy Matli.
‎2007 Sep 28 7:37 AM
try like this
first write
data: begin of itab occurs 0,
id type ..........
name type ..............
contact number ...........
end of itab.
select-options: s_id ........................
select id
name
contact from [u r ztable]
in to table itab
where id = s_id.
do the sorting criteria ............
sort itab by id.
delete adjacent duplicate records..........
then write
if itab[] is not initial.
then write loop........
loop at itab..
if itab-id = ' ' and name = ' ' and contact = ' '.
do processing
else.
....
.....
....
endif.
if u want to check the id name contact indvidually
write if id = ' '
move it into work area
if name = ' '.
.....
i hope this would be helpful
reward points if helpful...............