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 : You cannot use an internal table as a work area

Former Member
0 Kudos

Hi, I am new to ABAP .

My Use case is,

I want to get all "not processed " ,"Partially processed" and "Completed" orders for a given Customer Number.

For that,  I am selecting some fields of "VBAK" table on basis of "KUNNR" and JOINING "VBUK" table on "VBLEN".

In "VBUK" i am using "GBSTK" to check the order status.

I want to return this list from this Function Module.

Im using  " into  it_vbak" clause, the field order in select statement and the order in structure is same.

I have written folloing code.

FUNCTION ZCUSTOMER_ORDER.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  EXPORTING
*"     REFERENCE(ORDERS) TYPE  ZTABLECUSTALLORDER
*"----------------------------------------------------------------------
TABLES:VBAK,VBUK.


DATA: it_vbak TYPE TABLE OF  ZALLORDERS INITIAL SIZE 100,
        wa_vbak TYPE ZALLORDERS.


*DATA: it_vbak like standard table of ZALLORDERS,
*      wa_vbak TYPE it_vbak.

*DATA: ty_VBAK1 like standard table of ty_VBAK with header line with key VBLEN.
*DATA: wa_VBAK like Line of ty_VBAK1.

select  VBAK~VBELN
         VBAK~ERNAM
         VBAK~ANGDT
         VBAK~BNDDT
   VBAK~BSTNK
    VBAK~BSTDK
    VBAK~TELF1
   VBAK~NETWR
   VBAK~WAERK
   VBUK~GBSTK

  into  it_vbak
   from VBAK
join VBUK on ( VBAK~VBELN = VBUK~VBELN ) where
VBUK~GBSTK in ('A','B','C') and  VBAK~KUNNR = '0000000001'.

loop at it_vbak into  wa_vbak.
    WRITE:/ wa_vbak-vblen,
            wa_vbak-angdt,
             wa_vbak-bnddt.


endloop.

*READ TABLE it_vbak INTO ORDERS.

ENDFUNCTION.

The  "ZTABLECUSTALLORDER" is my export type from Function module, This is a table of structure (Line Type) .

The structure is ZALLORDERS, The components are displayed in following Image.

When i am trying to compile this code, it is giving "

You cannot use an internal table as a work area

" error.

Could some one please help me, what i am doing which is incorrect here.

Thanks in advance

18 REPLIES 18

kamesh_g
Contributor
0 Kudos

hi

in your select query use' into table'

select  VBAK~VBELN

         VBAK~ERNAM

         VBAK~ANGDT

         VBAK~BNDDT

   VBAK~BSTNK

    VBAK~BSTDK

    VBAK~TELF1

   VBAK~NETWR

   VBAK~WAERK

   VBUK~GBSTK


  into  TABLE  it_vbak  "change here

   from VBAK

join VBUK on ( VBAK~VBELN = VBUK~VBELN ) where

VBUK~GBSTK in ('A','B','C') and  VBAK~KUNNR = '0000000001'.

Former Member
0 Kudos

Hi Gunwant,

In addition to what Kamesh suggest, you should also replace the following data declaration:

DATA: it_vbak TYPE TABLE OF  ZALLORDERS INITIAL SIZE 100,
        wa_vbak TYPE ZALLORDERS.

with

DATA: it_vbak TYPE standard table of ZALLORDERS,
        wa_vbak LIKE line of it_vbak.

ronaldo_aparecido
Contributor
0 Kudos

The error ocurred because you typed

into  it_vbak

and the correct is


into table  it_vbak


Former Member
0 Kudos

Hi Gunwant,

Thi serror occurred as you are fetching multiple rows in your select query, thus you are passing table IT_VBAK but you are not supporting it with TABLE keyword. Please change the select query INTO clause to ''INTO TABLE IT_VBAK''.

This should solve your problem.

Please revert if still any issue.

Regards,

DN.

Former Member
0 Kudos

HI,

select  VBAK~VBELN

         VBAK~ERNAM

         VBAK~ANGDT

         VBAK~BNDDT

   VBAK~BSTNK

    VBAK~BSTDK

    VBAK~TELF1

   VBAK~NETWR

   VBAK~WAERK

   VBUK~GBSTK


  into table it_vbak....

Please check the line of code. When you try to execute it, it will give the error and its line.

Regards

Purnand

uppu_narayan
Active Participant
0 Kudos

hi gunwant,

       check the syntax you are inserting into a table so you got to specify INTO TABLE in the select query..........

regards,

naryan

Former Member
0 Kudos

Hi Gunwant,

In the select statement you should use "INTO TABLE it_vbak" because it_vbak is an internal table. If you want to select single record from database, then use SELECT SINGLE <your_fields> INTO wa_vbak. Here workarea is used.

Former Member
0 Kudos

Hi Gunwant,

"INTO TABLE" is your keyword..

Thanks,

Anish

0 Kudos

Hi ,

Thanks For all the help,

I changed the code as suggested by u people.

But i am facing a new error.

The work area (or internal table) "IT_VBAK" is not flat, or contains  
reference or internal tables as components. components. components.  

components. components.

My Code Is

FUNCTION zcustomer_order.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  EXPORTING
*"     REFERENCE(ORDERS) TYPE  ZTABLECUSTALLORDER
*"----------------------------------------------------------------------

TABLES:vbak,vbuk.


   DATA: it_vbak TYPE  TABLE OF ZALLORDERS WITH HEADER LINE,
           wa_vbak TYPE ZALLORDERS.




   SELECT  vbak~vbeln
           vbak~ernam
           vbak~angdt
           vbak~bnddt
     vbak~bstnk
      vbak~bstdk
      vbak~telf1
     vbak~netwr
     vbak~waerk
     vbuk~gbstk

   INTO TABLE it_vbak
     FROM  vbak
   JOIN vbuk ON ( vbak~vbeln = vbuk~vbeln )

   WHERE vbuk~gbstk IN ('A','B','C') AND  vbak~kunnr = '0000000001'.

0 Kudos

What is the definition of type ZALLORDERS, looks not compatible with the SELECT statement, is it a table/structure in ddic, I hope this is not already a table type giving an internal table of internal table ?

(Ref: read Open SQL - Work Areas in Statements for prerequisites on itab/wa to be target of a SELECT statemebnt)

Regards,

Raymond

0 Kudos

Hi Gunwant,

Please remove the extension 'WITH HEADER LINE' and make sure that ZALLORDERS has all the fields in seq as you are using in select query. The error may result if your ZALLORDER has include structure with different fields in it.

Regards,

DN.

0 Kudos

Hi Deepak,

Thanks For the reply,

I did that, i removed the "WITH HEADER LINE" part and checked . it is still not working.

Also the "ZALLORDERS" has exact sequence as select query as maintained in my question.

Actually i want to export the results by using "Table witch has Line type of structure ZALLORDERS"

As highlighted in bellow snap, "ZTABLECUSTALLORDES" is table type, which has "ZALLORDERS"

structure as line type.

0 Kudos

Hi Raymond,

"ZALLORDERS" is a structure, as shown in attached snap in my first post (The Question).

I want to return a table of "ZALLORDERS" or in general , i want to return a collection of ""ZALLORDERS"" from this function.

For this , i have created a Table type , which has the structure as line type.

Now, i clearheaded this type as a return type of the function module.  That means i have to

collect result from above query to this type of variable. (now i don't know if this is the correct way to do. )

0 Kudos

The problem should come from field NETWR which reference type box is checked, can you reset this box and try again ?

Regards,

Raymond

0 Kudos

Hi Raymond,

Thanks for the reply.

That was the problem Sir.

I removed "NETWR" from structure definition,select query and it got compiled.

Now , how to solve this problem. I want this value, its the currency ( vbak-NETWR).

I want to call this function from java program , the function is end point operation.

0 Kudos

The error is because you are using line type which act as Internal table as mention in your comment

if you want to use this you need to use this in table section instead of export.

Export/Import/Changing should have the structures and not the internal table use work area instead of Line type.

Define reference(Order) type ZTABlECUSTALLORDERS in TABLE instead of EXPORT.

Check and revert.

Regards,

Rahul

0 Kudos

Insert NETWR back, but don't chek the "Ref To" box, it should perform now.

Regards,

Raymond

kamesh_g
Contributor
0 Kudos
  1. TABLES:vbak,vbuk. 
  2.   
  3.   
  4.    DATA: it_vbak TYPE  standard TABLE OF ZALLORDERS , 
  5.            wa_vbak TYPE ZALLORDERS. 
  6.   
  7.   
  8.   
  9.   
  10.    SELECT  vbak~vbeln 
  11.            vbak~ernam 
  12.            vbak~angdt 
  13.            vbak~bnddt 
  14.      vbak~bstnk 
  15.       vbak~bstdk 
  16.       vbak~telf1 
  17.      vbak~netwr 
  18.      vbak~waerk 
  19.      vbuk~gbstk 
  20.   
  21.    INTO TABLE it_vbak 
  22.      FROM  vbak 
  23.    JOIN vbuk ON ( vbak~vbeln = vbuk~vbeln ) 
  24.   
  25.    WHERE vbuk~gbstk IN ('A','B','C') AND  vbak~kunnr = '0000000001'
  26.   

Try this. with standard table of in data declaration.