is it a structure or an internal table? - abap

TYPES: BEGIN OF PPP
------
END OF PPP,
xxx TYPE STANDARD TABLE OF PPP
My question is will xxx be an internal table or a structure?

it will be an internal table. its lines will be of the type PPP.

DATA: xxx TYPE STANDARD TABLE OF PPP, "produces table with lines of type ppp
yyy type PPP. "produces flat structure of type ppp.
yyy is a structure of type PPP and can be appended to xxx since they are of the same type.

TYPES: BEGIN OF PPP
------
END OF PPP,
xxx TYPE STANDARD TABLE OF PPP
xxx won't be either a structure or an internal table, but a table type.
If you declare:
DATA: lt_xxx TYPE xxx.
Then you would have a standard internal table with its structure based on PPP structure definition (since xxx is a table tabe based on PPP).

Here XXX will be the internal table - that hold the structure of PPP

Paulo is right;
xxx won't be either a structure or an internal table, but a table
type.
Or you can create Structure or Internal Table with statement below:
DATA: ls_xxx TYPE ppp. " <<-- Structure
DATA: lt_xxx TYPE STANDARD TABLE OF ppp. " <<-- Internal Table
DATA: lt_xxx2 TYPE xxx. " <<-- Internal Table

Related

Select all the field names in a ROW() type column

I am working with a table that includes a column that is basically a payload array of data, and I am trying to get a way to pull all key names in it. I initially tried to unnest it, but got errors because the column type is a ROW().
So when I run something like:
SELECT DATA_TYPE
FROM INFORMATION_SCHEMA.COLUMNS
WHERE
TABLE_NAME = 'tablename' AND
COLUMN_NAME = 'column'
OUTPUT:
row(id varchar, gameid varchar, type varchar, action varchar, accountid varchar)
Ideally, I am looking for a way to get an output in just the form of:
| |
| -------- |
| id |
| gameid |
|type|
|action|
|accountid|
Is this something that is easily possible with ROW() type columns? Otherwise I can probably parse the original output I am getting to do what I need, but it would be nice to skip a contrived step if possible.
If your column is in row format you can do:
select payload.*
from mydb

Generating a decrementing ID while inserting data on a Teradata table

I'm trying to insert data from a query (or a volatile table) to another table which has a id column ( with only type smallint and not null constraint) which should be unique, on Teradata using teradata SQL Assistant the min(id) = -5 and i should insert the new data with a lower id.
This is a simple example:
table a
id| aa |bb
-3|text |text_2
-5|text_3|text_4
and the data i should insert is for example :
aa | bb
text_5|text_6
text_7|text_8
text_9|text_10
so the result should be like
id| aa |bb
-3|text |text_2
-5|text_3|text_4
-6|text_5|text_6
-7|text_7|text_8
-8|text_9|text_10
I tried to pass by creating volatile table with a generated id start by -5 increment by -1 no cycle.
But I get an error
Expected something like a name or a unicode delimited identifier or a cycle keyword between an integer and ','
There is any other way to do it please ?

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.

PostgreSQL query -- column does not exist

I am trying to update a table using a temporary table.
Schema | Name | Type | Owner
------------+----------------------+----------+----------
pg_temp_11 | tmp_x | table | postgres
public | entities | table | postgres
However I am getting this error:
UPDATE entities SET "Name" = "tmp_x.Name" FROM tmp_x WHERE "entities.Ent_ID" = "tmp_x.Ent_ID";
ERROR: column "tmp_x.Name" does not exist -- the column Name exists
LINE 1: UPDATE entities SET "Name" = "tmp_x.Name" FROM tmp_x WHERE "...
What is the problem? The quotes around table columns?
You are surrounding multiple individual objects with double quotes. If you are using object delimiters (double quotes), they need to be on each item, not on the entire combination:
UPDATE entities SET "Name" = "tmp_x"."Name" FROM tmp_x WHERE "entities"."Ent_ID" = "tmp_x"."Ent_ID";

How to select a table dynamically with HSQLDB and Hibernate?

I have a table with references to other tables. Stored is the table name and the entity id.
Like this:
ref_table
id | table_name | refId
-------+------------+-------
1 | test | 6
2 | test | 9
3 | other | 5
Now I try to formulate an SQL/FUNCTION that returns the correct entities from the correct tables. Something like:
SELECT * FROM resolveId(3)
I would expect to get the entity with the id "5" from the table "other". Is this possible? I would guess I can do it with a stored procedure (CREATE FUNCTION). The function would have to inspect the "ref_table" and return the name of the table to use in the SQL statement ... but how exactly?
If you want to use the resuling entities in select statements or joins, you should use CREATE FUNCTION with RETURNS TABLE ( .. )
There is a limitation in HSQLDB routines which disallows dynamically creating SQL. Therefore the body of the CREATE FUNCTION may include a CASE or IF ELSE block that switches to a pre-defined SELECT statement based on the input value (1, 2, 3, ..).
The details of CREATE FUNCTION are documented here:
http://hsqldb.org/doc/2.0/guide/sqlroutines-chapt.html#N12CC4
There is one example for an SQL function with RETURNS TABLE.