Error when SELECT...FOR ALL ENTRIES have currency fields - abap

I get this error:
In a SELECT access, the read file could not be placed in the target field provided.
when executing this line of code:
SELECT vbeln
posnr
matnr
netpr
netwr
kondm
FROM vbap INTO TABLE t_tab
FOR ALL ENTRIES IN postab
WHERE vbeln = postab-vbeln.
I try one by one, and every time I put a currency field it will trigger this dump. Anyone know the root cause?

How is your t_tab declared? It seems like it is declared like a structure or, maybe, component order is wrong. Try to make declarations like this:
DATA: postab LIKE TABLE OF vbap,
t_tab LIKE TABLE OF vbap.
and replace INTO clause with this piece of code
FROM vbap INTO CORRESPONDING FIELDS OF TABLE t_tab

If your fields in the t_tab have other names then the fields your selecting be sure to match these with as:
SELECT vbeln AS ....
posnr AS ....
matnr AS ....
netpr
netwr
kondm
FROM vbap INTO TABLE t_tab
FOR ALL ENTRIES IN postab
WHERE vbeln = postab-vbeln.
If they have the same names try INTO CORRESPONDING FIELDS OF TABLE.
Also be sure that the fields in the t_tab have the right format.

Related

Alter table struct in Hive

I have a Hive table and I want to update the struct. The table was created like this:
CREATE TABLE orig (columnname
struct<a:string, b:string,
c:array<struct<d:string, e:string>>,
f:array<struct<g:string>>,
h:string,
i:array<struct<j:string>>>);
I need to change some names of struct like this:
change 'a' to 'new_a', 'b' to 'new_b'
also I need to add some fields inside the struct:
a:string,
b:string,
b1:string,
b2:string,
c:array<struct<d:string, e:string>>,
f:array<struct<g:string,g3:string>>,
h:string,
i:array<struct<j:string>>>);
How can I do this? Someone to help me.

Screen Painter shows wrong field names when adding fields from table KNA1

In the Screen Painter, I'm trying to add fields from table KNA1 declared globally in my program:
TABLES: VBAK, VBAP, KNA1.
What shows up in the program fields list are the fields from table VBAP assigned to table KNA1 The fields specific to KNA1 are not in the list.
In real life, there is no VBELN field in table KNA1, however there should be a KUNNR field.
How to fix this bug ?

Select into internal table and data type compatible error

I created a structure in SE11 with the following columns:
column name type (data element)
----------- -------------------
mandt mandt
itemdesc arktx
quantity lfimg
tweight gsgew
I created a table type ZPACK_DETAIL in SE11 whose line type is the structure above.
Then I used the code below to declare an internal table and fill it with data from the database table:
DATA : dresult TYPE zpack_detail .
SELECT arktx lfimg ntgew
FROM lips AS detail LEFT JOIN marm AS material
ON detail~matnr = material~matnr
LEFT OUTER JOIN vbak
ON detail~vgbel = vbak~vbeln
INTO TABLE dresult
WHERE detail~vbeln = '001'.
The activation reports this warning message:
The data type of the component ITEMDESC of DRESULT is not compatible with the data type of LFIMG.
Can someone give me a hint what's wrong? Is there something wrong with the way I'm declaring the internal table?
In fact there are couple of issues with your code.
You have to declare your variable as an internal table. ZPACK_DETAIL is a structure table and not a table type.
DATA: dresult TYPE STANDARD TABLE OF zpack_detail WITH EMPTY KEY.
Second of all. You should not use MANDT field as your query is not client indepentent. Remove this field from your structure or use INTO CORRESPONDING FIELDS OF TABLE and adjust your projection to SELECT arktx AS itemdesc lfimg AS quantity ntgew AS tweight.

Which has better performance: SELECT...ENDSELECT (1 by 1) or SELECT...INTO TABLE / LOOP AT

I have to read 10.000.000 records from a table.
Is it better:
to read these records one by one using SELECT ... ENDSELECT (without internal table)
or to read all of them at once using SELECT ... INTO TABLE itab and then LOOP through this internal table?
If all 10,000,000 entries fit into ABAP's main memory, you should select all of them with a single SELECT ... INTO TABLE ..., followed by a LOOP.
This reduces expensive database interaction to a minimum and will be fastest.
If the records don't fit into main memory, you need to retrieve them in packages. Check out the PACKAGE SIZE addition of the SELECT statement.
They have about the same speed
Contrary to popular belief, SELECT ... ENDSELECT does not fetch the rows one-by-one, so its performance is not much worse than SELECT ... INTO TABLE. See the explanation here.
The big problem with SELECT ... ENDSELECT is that it prevents other performance improvements
Consider this coding:
SELECT matnr FROM mara
INTO lv_matnr WHERE (...).
SELECT SINGLE ebeln
FROM ekpo
INTO lv_ebeln
WHERE matnr = lv_matnr.
SELECT SINGLE zfield
FROM ztable
INTO lv_zfield
WHERE matnr = lv_matnr.
...
ENDSELECT.
Most of the time will be spent with the SELECT SINGLEs on table ekpo and ztable, and often the solution for this is using FOR ALL ENTRIES1, however you need an internal table for that.
So it has to be converted into a SELECT ... INTO TABLE anyway:
SELECT matnr FROM mara
INTO TABLE lt_matnr WHERE (...).
IF lt_mara IS NOT INITIAL.
SELECT matnr, ebeln FROM ekpo
INTO TABLE #lt_ekpo "make it SORTED by matnr"
FOR ALL ENTRIES IN #lt_matnr
WHERE matnr = #table_line.
SELECT matnr, zfield FROM ztable
INTO TABLE #lt_ztable "make it SORTED by matnr"
FOR ALL ENTRIES IN #lt_matnr
WHERE matnr = #table_line.
ENDIF.
LOOP AT lt_matnr ASSIGNING <fs_mara>.
READ TABLE lt_ekpo ASSIGNING <fs_ekpo>
WITH KEY matnr = <fs_matnr>.
READ TABLE lt_ztable ASSIGNING <fs_ztable>
WITH KEY matnr = <fs_matnr>.
...
ENDLOOP.
You should avoid SELECT ... ENDSELECT, not because of its own performance, but to make other improvements easier.
You should use JOINs whenever you can instead of FOR ALL ENTRIES

ABAP statement to get all the data of a database table

can someone tell me how to write a statement to get all the fields of a database table instead of creating a work area with each field name of database table?
DATA gt_dd03l TYPE STANDARD TABLE OF dd03l INITIAL SIZE 0.
SELECT * FROM dd03l "Table Fields
INTO TABLE gt_dd03l
WHERE tabname = 'table name'.
You can do the following:
* define Table type of Business Partner Table BUT000
data: lt_table type table of but000 .
* Create Structure of the corresponding table type
data: ls_table like line of lt_table .