Application Development 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: 

Deep Structure - Assigning Values To Fields

Former Member
0 Kudos

Hi All,

I know that this is a simple one but I am just not getting it...

I pulled the following example code from an earlier thread. Here the code show how to read a value from a deep strucure:

LOOP AT <main_table> INTO <main_wa> .

LOOP AT <main_wa>-<inner_table> INTO <inner_wa> .

<var_1> = <inner_wa>-<field_to_be_read> .

...

ENDLOOP .

ENDLOOP .

That's OK - But how do I assign multiple values to the <inner_table>?

I am reading the values from another internal table - so, say for each record in <main_table> I would like to make 2 entries in <main_table>-<inner table>.

My struture is the following make-up (i.e. one embedded structure):

Field1 - Key

Field2

Field3

Field4

Field5

Table1 - Multiple Entries relating to key.

Any help would be much appreciated!

Cheers,

Niall

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi All,

Thanks for the replies.

I perhaps should have mentioned that I am working in an OO context so I cannot use internal tables with headers.

When I try to loop through the internal structure (as below) I get an error saying: '"wa_main_table-inner_table" is neither specified under "tables" or defined as an internal table'

loop at main_table into wa_main_table.

loop at wa_main_table-inner_table into wa_inner_table.

endloop.

endloop.

I know I am probably doing something silly here. I just cant see what!

Thanks,

Niall

7 REPLIES 7

Former Member
0 Kudos

Hi,

code below should work.

Regards,

Gagan

data : inner_tab_temp like <inner_table> occurs 0.

inner_wa like line of inner_tab_temp.

inner_wa-f1 = 'abc'.

inner_wa-f2 = 'cde'.

append inner_wa to inner_tab_temp.

inner_wa-f1 = 'xyz'.

inner_wa-f2 = 'def'.

append inner_wa to inner_tab_temp.

<main_table>-f1 = abc.

<main_table>-f2 = cde.

<main_table>-<inner_table>[] = inner_wa[].

append <main_table>.

andreas_mann3
Active Contributor
0 Kudos

Hi Niall,

here's an example:

*key
DATA : BEGIN OF key,
        ryear TYPE filct-ryear,
        rcomp TYPE filct-rcomp,
        racct TYPE filct-racct,
        rlevl TYPE filct-rlevl,
        END OF key.
* values
DATA:BEGIN OF twert OCCURS 0,
      per TYPE bkpf-monat,
      hb1 TYPE filct-kslvt,
      hb2 TYPE filct-kslvt,
      hb3 TYPE filct-kslvt,
END OF twert.
*itab with deep structure
DATA  : BEGIN OF ktab OCCURS 0.
        INCLUDE STRUCTURE key.
DATA :  w LIKE twert,
        END OF ktab.
...
*fill deep str.
    LOOP AT itab INTO wa.
      MOVE-CORRESPONDING wa TO ktab.
        CASE wa-rlevl.
          WHEN space OR 0.
            MOVE betrag TO : ktab-w-hb1.
          WHEN 1.
            MOVE betrag TO : ktab-w-hb2.
          WHEN OTHERS.                         
            MOVE betrag TO : ktab-w-hb3.
        ENDCASE.
        COLLECT ktab.
      ENDDO.
    ENDLOOP.

regards Andreas

Former Member
0 Kudos

Hi All,

Thanks for the replies.

I perhaps should have mentioned that I am working in an OO context so I cannot use internal tables with headers.

When I try to loop through the internal structure (as below) I get an error saying: '"wa_main_table-inner_table" is neither specified under "tables" or defined as an internal table'

loop at main_table into wa_main_table.

loop at wa_main_table-inner_table into wa_inner_table.

endloop.

endloop.

I know I am probably doing something silly here. I just cant see what!

Thanks,

Niall

0 Kudos

Hi Niall,

Withoput looking at the rest of the code (the data declarations), it is not possible to say what could be

wrong.

The following snippet of code compiles for me. Check it out and compare it with yours...

class test definition.
  public section.
    data : begin of line,
             number type i,
             innertable type table of spfli,
           end of line.
           
    data: inner_itab_line type spfli,
          itab like table of line.

    methods : test_method.

endclass.

class test implementation.

  method test_method.
  
    loop at itab into line.
    
      loop at line-innertable into inner_itab_line.
*      write your logic here...*
      endloop.
      
    endloop.
    
  endmethod.
  
endclass.

If you're still unable to discover the error, paste your code here...

regards,

Anand Mandalika.

Former Member
0 Kudos

Hi Anand,

Solved!

Many thanks for your input. It was down to my table definition. I had been staring at the issue for so long I thought I had tried eveything!

These really are great forums.

Kind regards,

Niall

0 Kudos

And thanks to Gagan and Andreas too! Much appreciated...

N.

0 Kudos

Hi Niall,

Good to know that your problem is solved. And thanks for rewarding the points as well.

Regards,

Anand Mandalika.