tags:

views:

325

answers:

1

I am new to ABAP coding and 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.

Any help would be appreciated.

+4  A: 

I think the site is hiding any code it finds between < >. It looks like you've declared a field symbol, but I can't actually see what you named it.

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_xblnr
  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.

Bryan Cain
That fixes it, and that makes some sense. I guess the append initial kind of allocates some chunk of memory to put the query results in.I think I fixed all of the formatting problems with the code snippet thanks for pointing that out.Thanks.
Mosquito Mike
I'd suggest reading up on field symbols a bit as well. If you are a newbie I'm allmost sure that you would not require field symbols for the majority of what you need to do. When used correctly they can make your life much easier, but if you get it wrong it can be a horror to debug.
Esti