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

Is initial

Former Member
0 Likes
5,502

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.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
3,480

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.

9 REPLIES 9
Read only

Former Member
0 Likes
3,480

Hi sriram,

Checked ur code, it seems it checks whether atleast one record exist in the internal table.

with regards,

praveen.

Read only

Former Member
0 Likes
3,480

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

Read only

0 Likes
3,480

IS INITIAL mean : if value of the variable is still same as it was at the time of declaration of varible.

regards

Read only

0 Likes
3,480

Hi Sriram,

If these answers helped you, please reward and close the post.

Thanks,

Srinivas

Read only

Former Member
0 Likes
3,480

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

Read only

Former Member
0 Likes
3,480

Hi Sriram,

Please take time to go through your previous posts and close them if answered.

Thanks,

Srinivas

Read only

Former Member
0 Likes
3,481

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.

Read only

0 Likes
3,480

Good catch Anand. I completely missed that there is no "into table" addtion in his example.

Srinivas

Read only

0 Likes
3,480

If these responses helped, please reward and close the post.

Srinivas