This website is not affiliated with, sponsored by, or approved by SAP AG.

Unexpected field reference

Development (ABAP Development WorkBench, ABAP/4 programming)

Moderators: Snowy, thx4allthefish, YuriT, Gothmog

Unexpected field reference

Postby q4u » Mon Aug 11, 2014 4:54 pm

Hi,
Look at this snippet of code. The ASSIGN statement returns field05 where it should really be field03 from the include. It seems that the include is being treated as just another field of t_data, rather than a structure containing additional fields.
Do I just have to live with this (add the include fields into the structure), or is there a clever way of getting around this? Thanks.

TYPES: BEGIN OF t_data,
field01 type c,
include TYPE t_fields "02,03,04
field05 type c,
END OF t_data,
tt_data TYPE STANDARD TABLE OF t_data,
ts_data TYPE t_data.

DATA: itab_data TYPE tt_data,
wa_data TYPE ts_data.

ASSIGN COMPONENT 3 OF STRUCTURE wa_data TO <fs>. "-> returns field05, would have expected field03

Thanks,
Q4U
q4u
 
Posts: 439
Joined: Wed Mar 08, 2006 7:02 am

Re: Unexpected field reference

Postby Grogan » Tue Aug 12, 2014 4:40 pm

You have declared a structure called INCLUDE within a structure. You could set each of your fields like this:
Code: Select all
wa_data-field01 = '1'.
wa_data-include-field02 = '2'.
wa_data-include-field03 = '3'.
wa_data-include-field04 = '4'.
wa_data-field05 = '5'.

If you intended to have all fields at the same level you need to use the statement INCLUDE:
Code: Select all
TYPES:
  BEGIN OF t_data,
    field01 TYPE c.
    INCLUDE TYPE t_fields. "02,03,04
TYPES:
    field05 TYPE c,
  END OF t_data.
Grogan

Award cash if useful.
Grogan
 
Posts: 365
Joined: Thu Aug 04, 2005 7:16 pm
Location: Australia

Re: Unexpected field reference

Postby q4u » Wed Aug 13, 2014 5:37 am

The second one looks like it might work - I will give it a go and let you know. Thank-you!

Grogan wrote:You have declared a structure called INCLUDE within a structure. You could set each of your fields like this:
Code: Select all
wa_data-field01 = '1'.
wa_data-include-field02 = '2'.
wa_data-include-field03 = '3'.
wa_data-include-field04 = '4'.
wa_data-field05 = '5'.

If you intended to have all fields at the same level you need to use the statement INCLUDE:
Code: Select all
TYPES:
  BEGIN OF t_data,
    field01 TYPE c.
    INCLUDE TYPE t_fields. "02,03,04
TYPES:
    field05 TYPE c,
  END OF t_data.
q4u
 
Posts: 439
Joined: Wed Mar 08, 2006 7:02 am

Re: Unexpected field reference

Postby q4u » Thu Aug 14, 2014 6:11 am

Grogan wrote:You have declared a structure called INCLUDE within a structure. You could set each of your fields like this:
Code: Select all
wa_data-field01 = '1'.
wa_data-include-field02 = '2'.
wa_data-include-field03 = '3'.
wa_data-include-field04 = '4'.
wa_data-field05 = '5'.

If you intended to have all fields at the same level you need to use the statement INCLUDE:
Code: Select all
TYPES:
  BEGIN OF t_data,
    field01 TYPE c.
    INCLUDE TYPE t_fields. "02,03,04
TYPES:
    field05 TYPE c,
  END OF t_data.

I had made a mistake with the 'include' syntax - your include syntax is right and works perfectly. Thank-you!
q4u
 
Posts: 439
Joined: Wed Mar 08, 2006 7:02 am


Return to ABAP

Who is online

Users browsing this forum: No registered users and 4 guests





loading...


This website is not affiliated with, sponsored by, or approved by SAP AG.