05-10-2013 4:11 PM
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
05-10-2013 5:03 PM
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'.
05-10-2013 5:46 PM
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.
05-10-2013 7:02 PM
The error ocurred because you typed
into it_vbak
and the correct is
into table it_vbak
05-11-2013 3:07 AM
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.
05-11-2013 6:34 AM
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
05-11-2013 7:40 AM
hi gunwant,
check the syntax you are inserting into a table so you got to specify INTO TABLE in the select query..........
regards,
naryan
05-11-2013 5:23 PM
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.
05-11-2013 6:00 PM
05-14-2013 8:54 AM
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'.
05-14-2013 9:40 AM
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
05-14-2013 9:40 AM
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.
05-14-2013 9:52 AM
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.
05-14-2013 10:02 AM
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. )
05-14-2013 10:37 AM
The problem should come from field NETWR which reference type box is checked, can you reset this box and try again ?
Regards,
Raymond
05-14-2013 10:59 AM
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.
05-14-2013 11:54 AM
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
05-14-2013 12:00 PM
Insert NETWR back, but don't chek the "Ref To" box, it should perform now.
Regards,
Raymond
05-14-2013 4:17 PM
Try this. with standard table of in data declaration.