Application Development 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: 

Error: Internal Tables, Field symbol has not yet been assigned

Former Member
0 Kudos


Hi all friend, I am try understand this error: Field symbol has not yet been assigned

I get a dump after run this abap program.

REPORT ZINTERNALTABLES.

tables: bsis.

types: begin of it_bsis_line,

  zuonr like bsis-zuonr,

  belnr like bsis-belnr,

end of it_bsis_line.

data: it_bsis type table of it_bsis_line, lv_i type i.

field-symbols <fst_bsis_line> type any table.

field-symbols <fs> like line of it_bsis.

clear <fst_bsis_line>.

lv_i = 1.

select * up to 10 rows from bsis into table <fst_bsis_line> where zuonr ne ''.

loop at <fst_bsis_line> assigning <fs>.

  write:/ lv_i,' - ', <fs>-zuonr, ' - ', <fs>-belnr.

  lv_i = lv_i + 1.

endloop.

the problem is in this line:

   17 field-symbols <fs> like line of it_bsis.

>>>>> clear <fst_bsis_line>.

   19 lv_i = 1.

any advice what I do wrong?

thanks

1 ACCEPTED SOLUTION

Former Member
0 Kudos

To initialize field symbols you should use  keyword UNASSIGN instead of CLEAR.

And you can not use field symbol <fst_bsis_line> directly in the select statement. Instead put it in an internal table and then assign the contents to the FS as below:

tables: bsis.

types: begin of it_bsis_line,

   zuonr like bsis-zuonr,

   belnr like bsis-belnr,

end of it_bsis_line.

data: it_bsis type table of it_bsis_line,

       lv_i type i.

field-symbols <fst_bsis_line> type any table.

field-symbols <fs> like line of it_bsis.

UNASSIGN <fst_bsis_line>.

lv_i = 1.

select * up to 10 rows from bsis into CORRESPONDING FIELDS

                    OF table it_bsis where zuonr ne ''.

ASSIGN it_bsis  to <fst_bsis_line>.

loop at <fst_bsis_line> assigning <fs>.

   write:/ lv_i,' - ', <fs>-zuonr, ' - ', <fs>-belnr.

   lv_i = lv_i + 1.

endloop.

For further details refer:

17 REPLIES 17

Former Member
0 Kudos

To initialize field symbols you should use  keyword UNASSIGN instead of CLEAR.

And you can not use field symbol <fst_bsis_line> directly in the select statement. Instead put it in an internal table and then assign the contents to the FS as below:

tables: bsis.

types: begin of it_bsis_line,

   zuonr like bsis-zuonr,

   belnr like bsis-belnr,

end of it_bsis_line.

data: it_bsis type table of it_bsis_line,

       lv_i type i.

field-symbols <fst_bsis_line> type any table.

field-symbols <fs> like line of it_bsis.

UNASSIGN <fst_bsis_line>.

lv_i = 1.

select * up to 10 rows from bsis into CORRESPONDING FIELDS

                    OF table it_bsis where zuonr ne ''.

ASSIGN it_bsis  to <fst_bsis_line>.

loop at <fst_bsis_line> assigning <fs>.

   write:/ lv_i,' - ', <fs>-zuonr, ' - ', <fs>-belnr.

   lv_i = lv_i + 1.

endloop.

For further details refer:

0 Kudos

hi Tiki Patra.

tested the code:

REPORT Z_JE_CC.

tables: bsis.

types: begin of it_bsis_line,

  zuonr like bsis-zuonr,

  belnr like bsis-belnr,

end of it_bsis_line.

data: it_bsis type table of it_bsis_line, lv_i type i, lv_mod type i.

field-symbols <fst_bsis_line> type any table.

field-symbols <fs> like line of it_bsis.

*clear <fst_bsis_line>.

IF <fst_bsis_line> IS ASSIGNED.

*  clear <fst_bsis_line>.

  unassign <fst_bsis_line>.

ENDIF.

lv_i = 1.

*select * up to 10 rows from bsis into table <fst_bsis_line> where zuonr ne ''.

select * up to 10 rows from bsis into corresponding fields of table it_bsis where zuonr ne ''.

assign it_bsis to <fst_bsis_line>.

if sy-subrc = 0.

  loop at <fst_bsis_line> assigning <fs>.

    write:/ lv_i,' - ', <fs>-zuonr, ' - ', <fs>-belnr.  

    lv_mod = lv_i mod 3.

    if ( lv_mod = 0 ).

      uline.

    endif.

    lv_i = lv_i + 1.

  endloop.

else.

  uline.

  write:/ 'Error Consulta vacia!!!'.

endif.

and give me this result:

My original code (with Internal tables and workarea):

REPORT Z_JE_CC.

tables: bsis.
data: it_bsis type table of bsis.
data: wa_bsis like line of it_bsis, lv_i type i, lv_mod type i.

clear it_bsis.
clear wa_bsis.
lv_i = 1.

select * up to 10 rows from bsis into table it_bsis where zuonr ne ''.

if sy-subrc = 0.
  loop at it_bsis into wa_bsis.
    write:/ lv_i,'  -  ',wa_bsis-zuonr,' - ',wa_bsis-belnr.
    lv_mod = lv_i mod 3.
    if ( lv_mod = 0 ).
      uline.
    endif.
    lv_i = lv_i + 1.
  endloop.
else.
  uline.
  write:/ 'Error Consulta vacia!!!'.
endif.

give me this result:

I think the first result, is wrong, checked the fields displayed:

write:/ lv_i,' - ', <fs>-zuonr, ' - ', <fs>-belnr.  

write:/ lv_i,'  -  ',wa_bsis-zuonr,' - ',wa_bsis-belnr.

and the fields are the same, any advice? or explain why give me diferent results?

Cheers.

thanks.

matt
Active Contributor
0 Kudos

First of all, you should your program in debug and check the contents of the table and the values. Then search via SE16 and see if these values exist.

Databases attached to SAP are relational. There's no concept of order. Your SQL simply brings back the first 10 records found in the table. So you may get different results that way.

A few tips:

1) Why prefix your field symbols with FS? The fact that they're in angle brackets is sufficient. Concentrate instead on giving them meaningful names. <fst_bsis_line> is a bad name. As said, the fs is pointless. Something like <bsis_lines> - SAP advise now against the use of prefixes like t_)

2) In your select name the fields you're selecting. It's more explicit, which is better programming. It may even perform better.

3) Since the program goes straight into selection, the clears/unassigns are not necessary. With sensible use of local variables and modularisation, you don't need to ensure that variables are empty before putting a value in.

0 Kudos

Hi Miguel Enriquez,

Both program above is  right.

The problem is index of table.

The first program uses index ~1, second one ~0. Both index of table have  difference result of sorted so when you get top 10 rows will be difference.

You can use ST05 tcode  to check it.

Hope it helpful

Regards,

Hung Nguyen

0 Kudos


hi hung, thanks for answer.

First:

not know why: this sql statement:

select * up to 10 rows from bsis into corresponding fields of table it_bsis where zuonr ne '' order by zuonr.

take much time and finally not execute, if I remove: order by zuonr

run fast and display results.

Second:

when try in ST05

1) Activate the trace

and

2) Enter SQL Statement:

select * up to 10 rows from bsis into corresponding fields of table it_bsis where zuonr ne ''.

and click on Explain Button it show at the bottom:

SQL Error 102: Incorrect syntax near up.

How to test and check the index number?

Third:

I understand that the result is correct. (Not understand why 1 sql statement take index 0 and other 1)

For try get same result I try do an:

order by zuonr,

but take much time and not execute the program.

Thanks

0 Kudos

Hi Matthew.

i understand your tip about variable names, correct it later.

Too understand about clear/unassuigns the Field Symbol.

Too specified the field names on select sql statement instead of *

understand your comment:

Databases attached to SAP are relational. There's no concept of order. Your SQL simply brings back the first 10 records found in the table. So you may get different results that way.

if NOT specify a order by in sql statement, the results are inconsistent/random? i think for fix it, i need specify a order by in the sql statement:

select * up to 10 rows from bsis into corresponding fields of table it_bsis where zuonr ne '' order by zuonr.

i try but take much time and not execute, any advice why?

Thanks Friend

matt
Active Contributor
0 Kudos

Miguel Enriquez wrote:

  if NOT specify a order by in sql statement, the results are inconsistent/random?

The results are simply undefined. I.e. there is no definite set of results you will get - you cannot rely on the set of results always being the same. With some databases, you may get the order the records are stored on disk, or the order the records were stored in time.


select * up to 10 rows from bsis into corresponding fields of table it_bsis where zuonr ne '' order by zuonr.

i try but take much time and not execute, any advice why?

Think about what must be happening on the database so that the ORDER BY gives you an exact result? Can the result be supplied without looking at all records that match the WHERE clause?

What you think the difference could be? Hint - read the ABAP documentation on UP TO ... ROWS. ABAP Keyword Documentation

0 Kudos

hi, hung nguyen I do the trace incorrectly (I am on wrong option)

I added 2 images first of the first program and second for second program.

How to know the index you mentioned:

The first program uses index ~1, second one ~0. Both index of table have  difference result of sorted so when you get top 10 rows will be difference.

thanks.

0 Kudos

Hi Matthew I thing the process is the next(in a select statement): correct please if not:

1) select take all records that comply with the condition or conditions specified on where clause (sample, take 50,000 records.)

2) Next apply the order by clause. (I think here is the problem, because are millions of records right)?

3) Next apply the up to 10 rows and take the first 10 rows ?

4) with these 10 rows fill the Internal table it_bsis.

I am right or I am wrong?

additionally I see the abap documentation about up to n rows and say its arbitrary results:

If the addition ORDER BY is also specified, the rows of the hit list are sorted on the database server and only the number of sorted rows specified in n are passed to the result set. If the addition ORDER BY is not specified, n arbitrary rows that meet the WHERE condition are passed to the result set.


Then I understand

thanks

matt
Active Contributor
0 Kudos

Correct.

0 Kudos

Hi Miguel Enriquez,

You choose a row which there are obj. name column 'BSIS' and Executed operation column 'OPEN' then click on Explain button you will  see it.

thanks,

0 Kudos

VenkatRamesh_V
Active Contributor
0 Kudos

Hi,

IF <fst_bsis_line> IS ASSIGNED.

clear <fst_bsis_line>.

ENDIF.



Hope it helpful.


Regards,

Venkat.


Former Member
0 Kudos

noted only two problems in your code:

1) clear <fst_bsis_line>.

2) Missing of CORRESPONDING FIELDS in select statement


for correction you must follow comments by Tiki Patra and Venkat.

Former Member
0 Kudos

hi all thanks for answer....

I think Tiki Patra has reason:

>>>>>And you can not use field symbol <fst_bsis_line> directly in the select statement. Instead put it in an internal table and then assign the contents to the FS.

because isn't a problem of Clear the table (I think), understand too CLEAR <fst_bsis_line>.  isn't incorrect. is better: UNASSIGN <fst_bsis_line>.    I am right?

the second problem is

>>>>> 2) missing of CORRESPONDING FIELDS in select statement.    (Abdul Raheem Mohammad advice).

ok, I typed the code same as: Tiki Patra (to adapted the advice of Venkat Ramesh) recommended.

thanks for your comments.

I testing the code.

Former Member
0 Kudos

Strange....

hung nguyen answered after Tiki Patra....

and the answer disappeared..

strange Right?

Former Member
0 Kudos

I want if possible solve the problem with the code written above.

but I have solved the problem with this code:

REPORT Z_JE_CC.

tables: bsis.

types: begin of it_bsis_line,

  zuonr like bsis-zuonr,

  belnr like bsis-belnr,

end of it_bsis_line.

data: it_bsis type table of it_bsis_line, lv_i type i, lv_mod type i.

data: it_bsis2 type standard table of bsis.

field-symbols <fst_bsis_line> type any table.

field-symbols <fs> like line of it_bsis.

field-symbols <fs2> type bsis.

field-symbols <fst_bsis_line2> type any table.

*clear <fst_bsis_line>.

IF <fst_bsis_line> IS ASSIGNED.

*  clear <fst_bsis_line>.

  unassign <fst_bsis_line>.

ENDIF.

IF <fst_bsis_line2> IS ASSIGNED.

*  clear <fst_bsis_line>.

  unassign <fst_bsis_line2>.

ENDIF.

lv_i = 1.

*select * up to 10 rows from bsis into table <fst_bsis_line> where zuonr ne ''.

select * up to 10 rows from bsis into corresponding fields of table it_bsis where zuonr ne ''.

select * up to 10 rows from bsis into corresponding fields of table it_bsis2 where zuonr ne ''.

assign it_bsis to <fst_bsis_line>.

assign it_bsis2 to <fst_bsis_line2>.

if sy-subrc = 0.

  loop at <fst_bsis_line2> assigning <fs2>.

    write:/ lv_i,' - ', <fs2>-zuonr, ' - ', <fs2>-belnr.

    lv_mod = lv_i mod 3.

    if ( lv_mod = 0 ).

      uline.

    endif.

    lv_i = lv_i + 1.

  endloop.

else.

  uline.

  write:/ 'Error Consulta vacia!!!'.

endif.

reduced the code:

REPORT Z_JE_CC.

tables: bsis.

data: lv_i type i, lv_mod type i.

data: it_bsis2 type standard table of bsis.

field-symbols <fs2> type bsis.

field-symbols <fst_bsis_line2> type any table.

*clear <fst_bsis_line>.

IF <fst_bsis_line2> IS ASSIGNED.

*  clear <fst_bsis_line>.

  unassign <fst_bsis_line2>.

ENDIF.

lv_i = 1.

*select * up to 10 rows from bsis into table <fst_bsis_line> where zuonr ne ''.

select * up to 10 rows from bsis into corresponding fields of table it_bsis2 where zuonr ne ''.

assign it_bsis2 to <fst_bsis_line2>.

if sy-subrc = 0.

  loop at <fst_bsis_line2> assigning <fs2>.

    write:/ lv_i,' - ', <fs2>-zuonr, ' - ', <fs2>-belnr.

    lv_mod = lv_i mod 3.

    if ( lv_mod = 0 ).

      uline.

    endif.

    lv_i = lv_i + 1.

  endloop.

else.

  uline.

  write:/ 'Error Consulta vacia!!!'.

endif.

I read and read and read and found this great explanation at:

ABAP Field Symbols usage - Advanced use | ABAP Help Blog

but please forget this post,and continue solving the first post.

I am try solving the problem.

this post is only for reference.