‎2005 Sep 09 9:29 PM
Hi,
Can anybody explain is initial in the following code.
Select matnr from mara into table itab_mara.
if not itab_mara[] is initial.
select maktx from makt into itab_makt for all entries
in itab_mara whre matnr = itab_mara-matnr.
endif.
Thanks,
Sriram.
‎2005 Sep 12 4:21 AM
Hello Sriram,
Apart from the explanations given by the others, which I agree with, there's one small syntax issue with your code -
select matnr
from mara
into table itab_mara.
if not itab_mara[] is initial.
select maktx
from makt
into itab_makt
for all entries in itab_mara
where matnr = itab_mara-matnr.
<b>endselect.</b>
endif.When you don't say INTO TABLE, then you need to have the SELECT...ENDSELECT. And within that you might append the data to the internal table.
select matnr
from mara
into table itab_mara.
if not itab_mara[] is initial.
select maktx
from makt
into <b>table</b> itab_makt
for all entries in itab_mara
where matnr = itab_mara-matnr.
endif.Regards,
Anand Mandalika.
‎2005 Sep 09 9:44 PM
Hi sriram,
Checked ur code, it seems it checks whether atleast one record exist in the internal table.
with regards,
praveen.
‎2005 Sep 09 9:45 PM
Sriram,
Basically IS INITIAL is used to check where the table ot variable or field is empty or not.
In your case...you are selecting materials in to a table and if that table is not empty then retrieve the material description from makt table.
If the internal table is empty then the if condition is false and the statements inside the IF condition doesnt execute.
Thanks,
Naren
‎2005 Sep 15 7:03 AM
IS INITIAL mean : if value of the variable is still same as it was at the time of declaration of varible.
regards
‎2005 Sep 15 11:36 PM
Hi Sriram,
If these answers helped you, please reward and close the post.
Thanks,
Srinivas
‎2005 Sep 09 10:00 PM
In addition to what Naren correctly explained, the reason why you are doing this in your particular case is that when you use "for all entries in itab" option, and if your "itab" is empty, then the SQL returns you all the entries in the database. So it is essential to check if there are any contents in your itab before you use this option.
Hope this is clear.
Regards,
Srinivas
‎2005 Sep 11 4:14 PM
Hi Sriram,
Please take time to go through your previous posts and close them if answered.
Thanks,
Srinivas
‎2005 Sep 12 4:21 AM
Hello Sriram,
Apart from the explanations given by the others, which I agree with, there's one small syntax issue with your code -
select matnr
from mara
into table itab_mara.
if not itab_mara[] is initial.
select maktx
from makt
into itab_makt
for all entries in itab_mara
where matnr = itab_mara-matnr.
<b>endselect.</b>
endif.When you don't say INTO TABLE, then you need to have the SELECT...ENDSELECT. And within that you might append the data to the internal table.
select matnr
from mara
into table itab_mara.
if not itab_mara[] is initial.
select maktx
from makt
into <b>table</b> itab_makt
for all entries in itab_mara
where matnr = itab_mara-matnr.
endif.Regards,
Anand Mandalika.
‎2005 Sep 12 4:23 AM
Good catch Anand. I completely missed that there is no "into table" addtion in his example.
Srinivas
‎2005 Sep 14 7:42 PM
If these responses helped, please reward and close the post.
Srinivas