Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Field Symbol Problem

Former Member
0 Likes
920

Hi,

I have written a code in normal loop expression where it will place the value of total at first vbeln.

like this:

AT END OF vbeln.
  w_output-tot_disc = w_total_disc.
  MODIFY i_output FROM w_output TRANSPORTING tot_disc
                                          WHERE vbeln = w_temp-vbeln.
  CLEAR w_total_disc.

 ENDAT.                             " AT END OF....

and i have written the same code using field symbol for dynamic creation.

where i_output = <l_table>

w_output = <l_line>

like this:

AT END OF vbeln.
    assign component 'TOT_DISC' of structure <l_line> TO
<l_field>.
    <l_field> = w_total_disc.
      MODIFY <l_table> FROM <l_line> transporting <l_field> where vbeln = w_temp-vbeln.
      CLEAR w_total_disc.

    ENDAT.                             " AT END OF....

but it gives an error

Error: The specified type has no structure and therefore no component called
"<L_FIELD>" . . . .

please help.

Thanks..

8 REPLIES 8
Read only

Sandeep_Panghal
Product and Topic Expert
Product and Topic Expert
0 Likes
886

Hello,

How you have declared (<l_line>) , does it have TOT_DISC ?

Rgds,

Sandeep

Read only

0 Likes
886

*Dynamic Creation of columns............

  • Create a new Table

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = i_fieldcat

IMPORTING

ep_table = new_table.

*where i_fieldcat table contains 'TOT_DISC' value.

  • Creates a new Line with the same structure of the table.

ASSIGN new_table->* TO <l_table>.

CREATE DATA new_line LIKE LINE OF <l_table>.

ASSIGN new_line->* TO <l_line>.

Read only

Former Member
0 Likes
886

Hi,

Insert this following code....


AT END OF vbeln.
    assign component 'TOT_DISC' of structure <l_line> TO
<l_field>.
    if <l_field> is assigned.    "-----> use this..
    <l_field> = w_total_disc.
      MODIFY <l_table> FROM <l_line> transporting <l_field> where vbeln = w_temp-vbeln.
      CLEAR w_total_disc.
     endif.      "-----
    ENDAT.  

And check whether <l_line> contains a field name 'TOT_DISC' in debugger...

Read only

0 Likes
886

Yes. <l_line> contains the 'TOT_DISC' at run time.

that's the reason it is throwing an error while compling.

how to define dynamic work area ?? any idea ?

Read only

0 Likes
886

Hi,

Check this code.... this also creates a dynamic internal table and workarea....


DATA: struct_type TYPE REF TO cl_abap_structdescr,
      comp_tab    TYPE cl_abap_structdescr=>component_table,
      dref        TYPE REF TO data,
      itab_type   TYPE REF TO cl_abap_tabledescr,
      wa_comp     LIKE LINE OF comp_tab,
      index       TYPE char10.

FIELD-SYMBOLS : <tab> TYPE STANDARD TABLE,
                <wa> TYPE ANY,
                <temp>.        "<-----------check how declared

PARAMETER col TYPE i.

DO col TIMES.
  index = sy-index.
  CONCATENATE 'COL' index INTO wa_comp-name.
  CONDENSE wa_comp-name NO-GAPS.
  wa_comp-type ?= cl_abap_datadescr=>describe_by_name( 'I' ).
  APPEND  wa_comp TO comp_tab.
ENDDO.

struct_type = cl_abap_structdescr=>create( comp_tab ).
itab_type   = cl_abap_tabledescr=>create( struct_type ).
CREATE DATA dref TYPE HANDLE itab_type.
ASSIGN dref->* TO <tab>.
CREATE DATA dref TYPE HANDLE struct_type.
ASSIGN dref->* TO <wa>.

ASSIGN COMPONENT 'COL2' OF STRUCTURE <wa> TO <temp>.       "This works perfectly....

BREAK-POINT.

Read only

former_member226519
Active Contributor
0 Likes
886

define the work area as follows:

data: if_buffer type ref to data.

field-symbols: <if_buffer> type standard table,

<wa_buffer> type any,

<f_tot_disc> type tot_disc.

try.

create data if_buffer type standard table of TABLENAME.

catch cx_root.

...

endtry.

assign if_buffer->* to <if_buffer>.

....

loop at <if_buffer> assigning <wa_buffer>.

assign component 'TOT_DISC' of structure <wa_buffer> to <f_tot_disc>.

endloop.

Read only

Former Member
0 Likes
886

Hi,

No need to do all this :

What you are doing is incorrect :

MODIFY <l_table> FROM <l_line> transporting <l_field> where vbeln = w_temp-vbeln.

Try this :

With field symbols, you can directly access the table components of an entry in the internal table.

Now assuming that <l_table> is pointing to the current line of the table i_output. You can just write the code

<l_table>-TOL_disc = w_total_disc. This will update the field tot_disc of the line to which the field-symbol <l_table> is assigned to.

regards,

Advait

Read only

Former Member
0 Likes
886

Thanks. problem got solved