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

Read data from a deep structure

Former Member
0 Likes
1,292

Hello gurus,

I need help reading a field from a deep structure.

I am reading in a structure from another FM into my own zFM. This structure looks like the following:

DeepStruct1

-Head (Structure)

-Table1

-


Head (Structure)

-


Field1

-


Field2

-


Field3

-


Table1A

-


Table2A

-Table2

-Table3

-Table4

What I want to do is store Field1 from the Head of Table1 into a varible and I'm not sure how I can do it. Obviously I can't do the following:

var1 = DeepStruct1-Table1-Head-Field1.

So I assume I need to use field symbols. If someone could provide me with an example of what to do I'd be greatly appericative.

Thanks a lot,

Chris

Edited by: chris.davies on Jul 30, 2010 3:05 PM

Edited by: chris.davies on Jul 30, 2010 3:07 PM

1 ACCEPTED SOLUTION
Read only

GrahamRobbo
SAP Mentor
SAP Mentor
0 Likes
1,188

Hi Chis,

you can use field symbols if you like - I prefer references.

Here is some sample code loading data into a deep structure similar to your example. You can use the same technique to read the data out as well.

  TYPES:
    BEGIN OF deep_struct,
      field1 TYPE char10,
      field2 TYPE char10,
      field3 TYPE char10,
      table1a TYPE tihttpnvp,
      table2a TYPE tihttpnvp,
    END OF deep_struct,
    deep_struct_tab TYPE TABLE OF deep_struct.

  DATA:
      BEGIN OF deepstruct1,
        head TYPE sflight,
        table1 TYPE deep_struct_tab,
        table2 TYPE deep_struct_tab,
        table3 TYPE deep_struct_tab,
      END OF deepstruct1.

  DATA: lref1 TYPE REF TO deep_struct,
        lref2 TYPE REF TO ihttpnvp.

* Populate Header
  deepstruct1-head-carrid = 'LH'.
  deepstruct1-head-connid = '3456'.

  DO 10 TIMES.
    APPEND INITIAL LINE TO deepstruct1-table1 REFERENCE INTO lref1.
    lref1->field1 = sy-index.
    lref1->field2 = sy-index.
    lref1->field3 = sy-index.
    DO 10 TIMES.
      APPEND INITIAL LINE TO lref1->table1a REFERENCE INTO lref2.
      lref2->name = 'Table1A'.
      lref2->value = sy-index.
      APPEND INITIAL LINE TO lref1->table2a REFERENCE INTO lref2.
      lref2->name = 'Table2A'.
      lref2->value = sy-index.
    ENDDO.

  ENDDO.

Step through it with the debugger and you will get the idea.

Cheers

Graham Robbo

2 REPLIES 2
Read only

GrahamRobbo
SAP Mentor
SAP Mentor
0 Likes
1,189

Hi Chis,

you can use field symbols if you like - I prefer references.

Here is some sample code loading data into a deep structure similar to your example. You can use the same technique to read the data out as well.

  TYPES:
    BEGIN OF deep_struct,
      field1 TYPE char10,
      field2 TYPE char10,
      field3 TYPE char10,
      table1a TYPE tihttpnvp,
      table2a TYPE tihttpnvp,
    END OF deep_struct,
    deep_struct_tab TYPE TABLE OF deep_struct.

  DATA:
      BEGIN OF deepstruct1,
        head TYPE sflight,
        table1 TYPE deep_struct_tab,
        table2 TYPE deep_struct_tab,
        table3 TYPE deep_struct_tab,
      END OF deepstruct1.

  DATA: lref1 TYPE REF TO deep_struct,
        lref2 TYPE REF TO ihttpnvp.

* Populate Header
  deepstruct1-head-carrid = 'LH'.
  deepstruct1-head-connid = '3456'.

  DO 10 TIMES.
    APPEND INITIAL LINE TO deepstruct1-table1 REFERENCE INTO lref1.
    lref1->field1 = sy-index.
    lref1->field2 = sy-index.
    lref1->field3 = sy-index.
    DO 10 TIMES.
      APPEND INITIAL LINE TO lref1->table1a REFERENCE INTO lref2.
      lref2->name = 'Table1A'.
      lref2->value = sy-index.
      APPEND INITIAL LINE TO lref1->table2a REFERENCE INTO lref2.
      lref2->name = 'Table2A'.
      lref2->value = sy-index.
    ENDDO.

  ENDDO.

Step through it with the debugger and you will get the idea.

Cheers

Graham Robbo

Read only

Former Member
0 Likes
1,188

Search the forum using string "Accessing deep structures"...

If will find what you want...

Before that go to :

KR

Veeranji Reddy P.