‎2007 Oct 01 6:51 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 Oct 01 6:57 AM
rayden,
use below code for ref
loop at itab.
if itab-id = space.
do ur processing
elseif itab-name = space.
do ur processing
elseif itab-contactno = space.
do ur processing
endif.
endloop.
reward if helpful,
Karthik
Message was edited by:
Karthik
‎2007 Oct 01 6:57 AM
rayden,
use below code for ref
loop at itab.
if itab-id = space.
do ur processing
elseif itab-name = space.
do ur processing
elseif itab-contactno = space.
do ur processing
endif.
endloop.
reward if helpful,
Karthik
Message was edited by:
Karthik
‎2007 Oct 01 7:15 AM
Hi Karthik,
I have tried. It seem like not working. Any other ways to do?
Regards,
Rayden
‎2007 Oct 01 7:16 AM
‎2007 Oct 01 8:16 AM
Hi Karthik,
It working now.
Here is the sample code.
===========================================================
DATA: tab TYPE ZSTUD00,
itab TYPE TABLE OF zstud00 WITH HEADER LINE,
icount TYPE n.
SELECT *
FROM ZSTUD00
INTO TABLE itab.
loop AT itab.
if itab-fname = ' '.
WRITE: / itab-admno.
endif.
icount = icount + 1.
endloop.
===========================================================
I'm able to do a loop and return the admin number when the fname name is blank. Now if i want to loop though and get the row and column name of the table if the admin number is blank.. is it possible? How do i go about it?
Regards,
Rayden
‎2007 Oct 01 10:45 AM
I'm able to do a loop and return the admin number when the fname name is blank. Now if i want to loop though and get the row and column name of the table if the admin number is blank.. is it possible? How do i go about it?
Do u mean u wanna add the condition for admin no along with the field name and capture the line number? If yes, do so
clear icount.
loop AT itab.
if itab-fname = ' ' OR itab-admno = ' '.
icount = icount + 1.
WRITE: / itab-admno, icount.
endif.
endloop.
‎2007 Oct 01 10:53 AM
Hi Karthik,
Thanks for the reply. let say if i enter a table name in the input field, and need to do the dynamic validation on the data records, If one of the record is blank, how do i know which row and column the data belong to? Any advise on this issu?
Regards,
Rayden
‎2007 Oct 01 11:20 AM
DATA: tab TYPE ZSTUD00,
itab TYPE TABLE OF zstud00 WITH HEADER LINE,
<b>* What's the structure of zstud00? In your case, u will have to check
all fields of that table in the IF condition below like IF itab-field1 = ' ' OR
itab-field1,... itab-fieldn = ' '. for N number of fields in zstud00
Another solution is that u declare itab having ONLY THE FIELDS U NEED
like data: begin of itab occurs 10, field 1 like zstud00-field1,.. field n like
zstud00-fieldn,.. end of itab. ONLY INCLUDE THE FIELDS U NEED TO OUTPUT
FOR ROW & COLUMN see the code below,...
</b>
icount TYPE n.
<b>DATA: v_fname(20). " to hold field name
SELECT *
FROM ZSTUD00
INTO TABLE itab.
clear icount.
loop AT itab.
CLEAR v_fname.
if itab-fname = ' '.
v_fname = 'fname'.
ELSEIF itab-admno = ' '.
v_fname = 'admno'.
.........
ELSEIF itab-n = ' '.
v_fname = 'n.
endif.
icount = icount + 1.
WRITE: / v_fname, 'at row', icount, 'is empty'.
endloop.</b>
‎2007 Oct 01 11:53 AM
Hi Karthik,
Thanks. This required the knowledge of the table structure. Let say if i enter 'spfli' in the input field parameter, then this code not going to work right. Well i think i will create another thread for the dynamic table. Thanks : )
Regards,
Rayden
‎2007 Oct 01 7:14 AM
In the below loop condition ... there is Case statments ...similary for your logic alos use case statements with in loop ..
if initial that means null one 'when' statement , if one value another 'when' statement ... simiarly ..
LOOP AT ITAB.
CLEAR: INDTEXT, EKKEY.
CASE ITAB-CHNGIND.
WHEN 'U'.
INDTEXT(50) = ITAB-FTEXT.
INDTEXT+51 = TEXT-020.
CONDENSE INDTEXT.
WHEN 'D'.
INDTEXT = TEXT-021.
WHEN 'E'.
INDTEXT(5) = ITAB-FTEXT.
INDTEXT+51 = TEXT-021.
CONDENSE INDTEXT.
WHEN 'I'.
INDTEXT = TEXT-022.
ENDCASE.
SKIP.
ENDLOOP."Example Program :DATA: BEGIN OF tab OCCURS 100,
f1 LIKE sg-field1,
f2 LIKE sg-field2,
END OF tab.
DATA: f1 TYPE I,
f2 TYPE I.
START-OF-SELECTION.
GET table.
IF f1 = f2.
f1 = 0.
ELSE.
f1 = 1.
ENDIF.
SELECT * FROM tabl WHERE
field1 EQ sg-field2 AND
field2 BETWEEN sg-field5 AND sg-field6.
MOVE ...
APPEND ...
ENDSELECT.
END-OF-SELECTION.
LOOP AT tab.
AT NEW f1.
CASE F1.
WHEN ... WRITE:/ ...
WHEN ... WRITE:/ ...
ENDCASE.
ENDAT.
WRITE:/ f1, f2, ...
ENDLOOP.Reward points if it is usefull ..
Girish
‎2007 Oct 01 10:25 AM
hi
DATA: tab TYPE Zcheck,
itab TYPE TABLE OF zcheck WITH HEADER LINE,
icount TYPE n.
SELECT *
FROM Zcheck
INTO TABLE itab.
loop AT itab.
if itab-fname = ' '.
WRITE: / itab-admno.
endif.
icount = icount + 1.
endloop.