Assign SELECT result to field-symbol GETWA_NOT_ASSIGNED - abap

I am confused as to why the commented out query doesn't work.
REPORT z_hello_world_local.
TYPES: BEGIN OF bkpf_type,
xblnr TYPE bkpf-xblnr,
END OF bkpf_type.
DATA: t_bkpf TYPE TABLE OF bkpf_type.
FIELD-SYMBOLS: <bkpf> TYPE bkpf_type.
*This query does not work?
*SELECT xblnr
* INTO CORRESPONDING FIELDS OF <bkpf> UP TO 1 ROWS
* FROM bkpf
* WHERE belnr = '1800001017'.
* ENDSELECT.
*
DATA: t_xblnr TYPE bkpf-xblnr.
*This query works and in my head it is roughly the same thing.
SELECT SINGLE xblnr
INTO t_xblnr
FROM bkpf
WHERE belnr = '1800001017'.
write 'Done'.
If I run the commented out query I get the error:
Runtime Errors GETWA_NOT_ASSIGNED Date and Time
08/26/2009 19:54:19
Short text
Field symbol has not yet been assigned.
Why do I get this runtime error?

I assume (based on the error and the pieces of code that I can't actually see) that you're trying to select data directly into a field symbol. You can't do that. A field symbol is not a memory area, it is (basically) a pointer.
You could do one of the following:
data: wa_bkpf type bkpf_type.
select xblnr
into corresponding fields of wa_bkpf
up to 1 rows
from bkpf
where xblnr = '1800001017'.
endselect.
or
field-symbols: <bkpf> type bkpf_type.
append initial line to t_bkpf assigning <bkpf>.
select xlbnr
into corresponding fields <bkpf>
up to 1 rows
from bkpf
where xblnr = '1800001017'.
endselect.
In this case, you are pointing the field symbol to a new line that you've added to the internal table.
or
select xblnr
into corresponding fields of table t_bkpf
from bkpf
where xlbnr = '1800001017'.
In this case, you will retrieve all documents that match and place them directly into your internal table.

Related

SELECT does not return rows when queried by VBELN

I'm trying to display table in alv from an internal table where rows are added form a table stored in the database. Without a where condition I see rows displayed in alv but with a where condition in the select statement no rows are returned.
Here is the code:
REPORT ZSAM.
DATA: IT_1 TYPE STANDARD TABLE OF VBAK.
select vbeln audat netwr waerk vkorg vtweg
from VBAK
into corresponding fields of Table IT_1
where vbeln > 4500
and vbeln < 6000.
Any idea why using where condition makes it not return any rows and how to fix?
vbeln is a field with ten positions and uses ALPHA conversion routine (see the domain behind the data element). This means the value is filled with leading zeros (as long as it does contain numbers only). As this is a character type field, you also have to use apostrophes for the comparison. So, the WHERE condition has to be like this:
WHERE vbeln GT '0000004500'
AND vbeln LT '0000006000'
You can try to use range;
First usage;
DATA: r_vbeln TYPE RANGE OF vbeln.
DATA: s_vbeln LIKE LINE OF r_vbeln.
s_vbeln-option = 'BT'.
s_vbeln-sign = 'I'.
s_vbeln-low = '0000004501'.
s_vbeln-high = '0000005999'.
APPEND s_vbeln TO r_vbeln.
SELECT condition; WHERE vbeln IN r_vbeln.
Second usage;
DATA: r_vbeln TYPE RANGE OF vbeln.
DATA: s_vbeln LIKE LINE OF r_vbeln.
s_vbeln-option = 'GT'.
s_vbeln-sign = 'I'.
s_vbeln-low = '0000004500'.
APPEND s_vbeln TO r_vbeln.
s_vbeln-option = 'LT'.
s_vbeln-sign = 'I'.
s_vbeln-low = '0000006000'.
APPEND s_vbeln TO r_vbeln.
SELECT condition; WHERE vbeln IN r_vbeln.

read from internal table with loop and no results

In the below code, I read data from database table with SELECT into the internal table dresult.
Reading the first line of the internal table displays the expected result, but using the LOOP displays nothing.
What's the issue?
Note: I tried to remove ENDSELECT and it worked. Why?
REPORT ZTEST02.
"Detail Informaion
TYPES : BEGIN OF details,
d1 type arktx, " description
d2 type lfimg, "quantity
END OF details.
DATA : dresult TYPE TABLE OF details WITH HEADER LINE,
t_dresult TYPE details,
sdno TYPE vbeln.
PARAMETERS packo TYPE vbeln OBLIGATORY MATCHCODE OBJECT f4_likp.
START-OF-SELECTION.
SELECT arktx,lfimg
INTO #dresult
FROM lips as detail
LEFT JOIN marm as material
ON detail~matnr = material~matnr
LEFT OUTER JOIN vbak
ON detail~vgbel = vbak~vbeln
WHERE detail~vbeln = #packo.
ENDSELECT.
READ TABLE dresult into t_dresult INDEX 1.
write: t_dresult-d1,t_dresult-d2.
LOOP AT dresult INTO t_dresult.
write: t_dresult-d1,t_dresult-d2.
ENDLOOP.
With SELECT ... ENDSELECT you select the data into a work area (INTO #dresult - which is actually the header line of the internal table with the same name). As result the internal table dresult does not contain any data, so the LOOP and the READ TABLE won't work.
I would declare the internal table without HEADER LINE and remove ENDSELECT:
DATA: dresult type STANDARD TABLE OF details,
...
SELECT ...
INTO TABLE #dresult
Moreover, after READ TABLE, it is always good to check if an entry was found:
READ TABLE ...
IF sy-subrc EQ 0.
...
ENDIF.

how can I get values from the table

I concatenated values of select-options and a parameter. The condition of that query is based on the concatenated data. I can get all the data i need.
here's my code:
TABLES: bkpf.
SELECT-OPTIONS: s_belnr FOR bkpf-belnr NO-EXTENSION OBLIGATORY .
PARAMETERS: p_ghjahr LIKE bkpf-gjahr DEFAULT sy-datum(4) OBLIGATORY. "Fiscal
DATA: it_con TYPE TABLE OF BKPF,
ls_con TYPE bkpf-AWKEY,
lv_belnr LIKE bkpf-belnr,
IT TYPE STANDARD TABLE OF BKPF,
WA TYPE BKPF.
IF s_belnr-high IS INITIAL.
CONCATENATE s_belnr-low p_ghjahr INTO ls_con.
APPEND ls_con TO it_con.
ELSE.
lv_belnr = s_belnr-low.
WHILE lv_belnr LE s_belnr-high.
CONCATENATE lv_belnr p_ghjahr INTO ls_con.
APPEND ls_con TO it_con.
ADD 1 TO lv_belnr.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = lv_belnr
IMPORTING
output = lv_belnr.
ENDWHILE.
ENDIF.
LOOP AT it_concats INTO ls_concats.
SELECT BELNR
FROM BKPF
INTO CORRESPONDING FIELDS OF TABLE IT
FOR ALL ENTRIES IN IT_CONCATS
WHERE AWKEY EQ IT_CONCATS-AWKEY.
ENDLOOP.
LOOP AT IT INTO WA.
WRITE: / WA-BELNR.
ENDLOOP.
Ignoring (because your question is too vague), the type of document you are looking for, I'll suggest something like
(WARNING, I do NOT provide full answers, just code snipets who you must tune to make it work; if someone wants to improve my answer, feel free to do it, and I'll gladly will vote the new one as the good one... if it is)
data: awkey_range type range of bkpf-awkey,
awkey_line like line of awkey_range.
* Fill the awkey_range with something like
awkey_line-sign = 'I'.
awkey_line-option = 'EQ'.
* loop at bkpf_table into bkpf_line.
* concatenate bkpf_line-belnr bkpf_line-ghjahr into awkey_line-low.
* append awkey_line to awkey_range.
* endloop.
* And then a single SQL
select *
from bkpf
into table IT "Ouch, what a name
where awkey in awkey_range.
And it should work, if I'm not missing something.

How can I sum up or collect the data on the same field?

Hi ABAP users I would like to ask if what process I can make to COLLECT the data on the same field? all I want to do is to sum up or collect the data in dmbtr that belongs to same date, (date field monat) (werks to plant codes)
it_zfi_vbrp_bseg_1-num3 = it_zfi_vbrp_bseg_1-werks.
it_zfi_vbrp_bseg_1-num2 = it_zfi_vbrp_bseg_1-dmbtr.
COLLECT it_zfi_vbrp_bseg_1.
DELETE ADJACENT DUPLICATES FROM it_zfi_vbrp_bseg_1 COMPARING ALL FIELDS.
Sort it_zfi_vbrp_bseg_1 by werks.
LOOP AT it_zfi_vbrp_bseg_1 into wa_zfi_vbrp_bseg_1 WHERE monat = '01'.
IF wa_zfi_vbrp_bseg_1-werks EQ '4030'.
WRITE:/, AT pos wa_zfi_vbrp_bseg_1-dmbtr.
ENDIF.
ENDLOOP.
Any configuration in my codes guys?
Suppose, you already extended standard bseg table with monat field, then you should do like this:
TYPES: BEGIN OF ty_zfi_vbrp_bseg_1,
werks TYPE bseg-werks,
monat TYPE monat,
dmbtr TYPE bseg-dmbtr,
END OF ty_zfi_vbrp_bseg_1.
DATA: it_zfi_vbrp_bseg_1 TYPE TABLE OF ty_zfi_vbrp_bseg_1,
is_zfi_vbrp_bseg_1 TYPE ty_zfi_vbrp_bseg_1.
SELECT werks, monat, dmbtr
INTO TABLE #DATA(lt_bseg)
FROM bseg
WHERE werks = '4030'.
* summation of months
LOOP AT lt_bseg ASSIGNING FIELD-SYMBOL(<fs_line>).
CLEAR: is_zfi_vbrp_bseg_1.
MOVE-CORRESPONDING <fs_line> TO is_zfi_vbrp_bseg_1.
COLLECT is_zfi_vbrp_bseg_1 INTO it_zfi_vbrp_bseg_1.
ENDLOOP.
* output the results
LOOP AT it_zfi_vbrp_bseg_1 ASSIGNING FIELD-SYMBOL(<zfi_line>).
IF <zfi_line>-werks EQ '4030'.
WRITE: / <zfi_line>-werks, <zfi_line>-monat, <zfi_line>-dmbtr.
ENDIF.
ENDLOOP.
Couple of notes to your incorrect code:
COLLECT doesn't work like single statement and should be executed in loop.
To sum with COLLECT statement you should declare work area so that all non-key fields would be numeric. Key fields (even if it is implicit key) can be of any type, as opposed to what Ray said. N type is also OK.
DELETE ADJACENT DUPLICATES is redundant here, because after COLLECT (which makes summation by primary key) you won't have any dups.
This all comes down to how you define your internal table it_zfi_vbrp_bseg_1
For COLLECT to work, you need to define it with character type keys followed by packed field types:
data: begin of it_zfi_vbrp_bseg_1 occurs 0,
werks type werks,
month(2) type c,
dmbtr type dmbtr,
end of it_zfi_vbrp_bseg_1.
That will work.
This will not:
data: begin of it_zfi_vbrp_bseg_1 occurs 0.
include structure vbrp.
data: monat type monat,
dmbtr type dmbtr,
end of it_zfi_vbrp_bseg.
Read the help on COLLECT and define your summary table accordingly.

Show table data on screen

I have a database table named zrswheel .I entered 3 datas and want to show them on screen.Here s my code
REPORT ZRS_WHEEL.
TYPES:
BEGIN OF ty_zrswheel,
lv_brand TYPE c,
lv_dimension TYPE i,
lv_pressure TYPE i,
END OF ty_zrswheel.
DATA:
wa_zrswheel TYPE ty_zrswheel,
it_zrswheel TYPE TABLE of ty_zrswheel.
SELECT dimension pressure brand
FROM zrswheel
INTO TABLE it_zrswheel.
*WHERE ID=''.
IF sy-subrc NE 0.
write: 'There is an Error in retrieving data.'.
ELSE.
LOOP AT it_zrswheel INTO wa_zrswheel.
WRITE: wa_zrswheel-lv_dimension,wa_zrswheel-lv_brand,wa_zrswheel-lv_pressure.
NEW-LINE.
ENDLOOP.
ENDIF.
When I execute I get this error:
Runtime Errors : DBIF_RSQL_INVALID_RSQL
Except. CX_SY_OPEN_SQL_DB
What is the structure of your zrswheel?
Does it fit to your internal structure ty_zrswheel?
Without knowing the structure of zrswheel, nobody can help you.
The following is just a guess from my side.
It is very unusual to call fields in a structure like lv_.
So I think your zrswheel is defined as:
dimension type c,
brand type i
pressure type i
I think your report should look like:
REPORT ZRS_WHEEL.
DATA:
wa_zrswheel TYPE zrswheel,
it_zrswheel TYPE TABLE of zrswheel.
SELECT * FROM zrswheel INTO TABLE it_zrswheel.
LOOP AT it_zrswheel INTO wa_zrswheel.
WRITE: / wa_zrswheel-dimension,wa_zrswheel-brand,wa_zrswheel-pressure.
ENDLOOP.
IF sy-subrc NE 0.
write: 'Nothing found'.
ENDIF.
If you want only select an extract of zrswheel, then try:
REPORT ZRS_WHEEL.
TYPES:
BEGIN OF ty_zrswheel,
brand LIKE zrswheel-brand, "or lv_brand?
dimension LIKE zrswheel-dimension, "or lv_dimension?,
pressure LIKE zrswheel-pressure, "or lv_pressure?,
END OF ty_zrswheel.
DATA:
wa_zrswheel TYPE ty_zrswheel,
it_zrswheel TYPE TABLE of ty_zrswheel.
SELECT *FROM zrswheel
INTO corresponding fields of TABLE it_zrswheel.
LOOP AT it_zrswheel INTO wa_zrswheel.
WRITE: / wa_zrswheel-dimension,wa_zrswheel-brand,wa_zrswheel-pressure.
ENDLOOP.
IF sy-subrc NE 0.
write: 'There is an Error in retrieving data.'.
ENDIF.
Remark:
I'm not sure about the correct syntax of INTO CORRESPONDING FIELDS - please check the online help or wait for my update when I have a SAP-system to check the syntax)
Check your order of fields in the structure and in the select statement. Ensure the data types and length match for the fields .