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: 

help in internal table

Former Member
0 Kudos
240

hi folks,

anybody who could help me in this aspect...

types: begin of structbdata,

bdate type jhtfp-fbuda,

predition type jhtfp-vavtyp,

adnumber type jhtfp-aubel,

adsize type jhamot-breite_s,

bunits type jhamot-HOEHE_S,

end of structbdata.

data bdata type standard table of structbdata with key adnumber initial

size 10.

select fbuda vavtyp aubel breite_ieh hoehe_i_eh from zzjhtfp INNER JOIN

jhamot ON zzjhtfpaubel = jhamotavm_nr INTO BDATA WHERE zzjhtfp~kunnr

= p_custid.

i have declared the internal table type -structbdata and declare internal table bdata to read the data from the query below.

error i am getting is internal table cannot be treated as a work area.

hence forth the results of the query is not getting stored in the internal table.

thanks in advance guys.

santhosh

1 ACCEPTED SOLUTION

Former Member
0 Kudos
109

Hi Santhosh,

If you are selecting the entries from the database table into your internal table in one single shot, then you have to use the INTO TABLE option as follows


SELECT fbuda vavtyp aubel breite_ieh hoehe_i_eh 
  FROM zzjhtfp INNER JOIN jhamot ON zzjhtfp~aubel = jhamot~avm_nr 
  INTO table bdata
 WHERE zzjhtfp~kunnr = p_custid.

Now if you are not doing it this way, but you are in a SELECT, ENDSELECT loop, then you do need a workarea. You need to define your internal table WITH HEADER LINE or define another workarea like your internal table type and then move it to your internal table as follows


DATA: s_bdata TYPE structbdata.

SELECT fbuda vavtyp aubel breite_ieh hoehe_i_eh 
  FROM zzjhtfp INNER JOIN jhamot ON zzjhtfp~aubel = jhamot~avm_nr 
  INTO s_bdata
 WHERE zzjhtfp~kunnr = p_custid.
*-- Do your processing, validations here
APPEND s_bdata to bdata.
CLEAR s_bdata.

ENDSELECT.

Hope this helps,

Srinivas

11 REPLIES 11

Former Member
0 Kudos
109

you should write into table BDATA and not into BDATA .

Former Member
0 Kudos
109

Hi Santhosh,

The fields you are selecting seem to have no correspondence with the fields in the internal table.

The internal table should match the fields in your select statement.

So for a preference, your internal table should have the same names, and MUST have the same field definitions.

So I would create your internal table with fields like this:

fbuda

vavtyp

aubel

breite_ieh

hoehe_i_eh

Then you can use SELECT ... INTO TABLE BDATA.

If you want to have a different structure and field names in your internal table then use field alias's. This would be like:

SELECT fbuda as bdate ... INTO CORRESPONDING FIELDS OF TABLE BDATA.

Hope that helps.

Brad

0 Kudos
109

Thank you Brad, for your input. I did try that and the query is correct as I fixed the bug - it is compling with no syntax errors -the only thing is not executing. I did run the program in the debugg mode and when it comes to the query the data from the view(zzjhtfp - I am reading the data from the view and not from the table -Is that anything to do with???) is not stored in the internal table it is totally blank. otherwise I did fix the query in terms of syntax.

Thanks a lot for your input. If you have any leads that would be helpful.

Santhosh

0 Kudos
109

The question is how did you fix it?

Do you use into corresponding now? And if so did you adjust the field names that structure and table will match?

What is sy-subrc right after the select? sy-subrc = 4 would indicate that the where condition could not retrieve a record. Do you have an empty internal table or are there empty lines - this would mean that the structure and table still do not match.

Christian

0 Kudos
109

Did you check that there is data getting selected in your view. SE16 --> view Name??

Further join is on zzjhtfpaubel = jhamotavm_nr

both the fields may not have the same type.

if one contains 1234 and other '0001234' then need to check if that will work.

0 Kudos
109

thanks alot.

prefixed the term 'table'BDATA into the query. But I do not understand that how the structure and the table fields do not match because I have created the internal table declaring the type structure, in the query I have mentioned the field names in the same order as the fields declared in the view.

The internal table has empty lines and how does the structure and the table not matching. I do not understand that part.

your input would help....

santhosh

0 Kudos
109

hi Ram,

for the view I have borrowed the data element from the tables(jhamot) i have not created any new data elements and data type.Also the view has the data stored in them. So they have the same data type.

santhosh

Former Member
0 Kudos
110

Hi Santhosh,

If you are selecting the entries from the database table into your internal table in one single shot, then you have to use the INTO TABLE option as follows


SELECT fbuda vavtyp aubel breite_ieh hoehe_i_eh 
  FROM zzjhtfp INNER JOIN jhamot ON zzjhtfp~aubel = jhamot~avm_nr 
  INTO table bdata
 WHERE zzjhtfp~kunnr = p_custid.

Now if you are not doing it this way, but you are in a SELECT, ENDSELECT loop, then you do need a workarea. You need to define your internal table WITH HEADER LINE or define another workarea like your internal table type and then move it to your internal table as follows


DATA: s_bdata TYPE structbdata.

SELECT fbuda vavtyp aubel breite_ieh hoehe_i_eh 
  FROM zzjhtfp INNER JOIN jhamot ON zzjhtfp~aubel = jhamot~avm_nr 
  INTO s_bdata
 WHERE zzjhtfp~kunnr = p_custid.
*-- Do your processing, validations here
APPEND s_bdata to bdata.
CLEAR s_bdata.

ENDSELECT.

Hope this helps,

Srinivas

0 Kudos
109

thanks srinivas. I have already included the header line to my code. the data is there in the view but it is not read into the internal table.

here is my updated code

types: begin of structbdata,

fbuda type jhtfp-fbuda,

vavtyp type jhtfp-vavtyp,

aubel type jhtfp-aubel,

breite_s type jhamot-breite_s,

hoehe_s type jhamot-HOEHE_S,

end of structbdata.

data bdata type standard table of structbdata with key aubel with

header line initial size 10.

select fbuda vavtyp aubel breite_s HOEHE_S from zzjhtfp INNER JOIN jhamot ON zzjhtfpaubel = jhamotavm_nr INTO table BDATA WHERE zzjhtfp~kunnr = p_custid.

Your help is really appreciated.

santhosh

0 Kudos
109

Hi Santhosh,

If it is just a case of data not coming into your internal table, then it is certainly a case of data's internal/external representation. Check if your AUBEL and AVM_NR store the data internally in the exact same way(i.e., leading zeros etc). Also, check if your p_custid and KUNNR are also similar. Remember, SE16 does some of the conversions for you, if the fields have conversion exits associated with them. Your program may not be doing that.

Best way to test it out is, take out the join and do the individual selects. See where it fails.

Srinivas

0 Kudos
109

Hi,

For fix the error, I suggest you to do the following.

1. write the field names in select as zzjhtfp~aubel

instead of aubel.similarly for other fields with that <b>~</b> symbol.

2. Remove <b>where condition</b> and check.If data is coming,then problem is in p_custid.

select fbuda vavtyp aubel breite_s HOEHE_S from zzjhtfp INNER JOIN jhamot ON zzjhtfpaubel = jhamotavm_nr INTO table BDATA .

3. Remove the <b>on condition</b>.If data is coming,then problem in join.

select fbuda vavtyp aubel breite_s HOEHE_S from zzjhtfp INNER JOIN jhamot INTO table BDATA WHERE zzjhtfp~kunnr = p_custid.

Hope this fix the problem.

Regards,

J.Jayanthi