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

custom structure

Former Member
0 Likes
1,569

There is a custom structure in se11, in which one of the fields say f3 is of the type standard transparent table. Now how do I refernce the fiels of this table through an internal table.

An internal table declared of this custom structure type has a structure like f1, f2, f3-fa, f3-fb, f3-fc.... where fa, fb, fc are fields of the standard transparent table.

Thanks.

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,522

Here is a better example of how to get the values of your deep structure.



report  zrich_0001.

data: begin of ispfli occurs 0,
       carrid type spfli-carrid,
       connid type spfli-connid,
     <b>  ibookings type standard table of sbook,</b>
      end of ispfli.

data: xspfli like line of ispfli.
data: xbookings type sbook.

loop at ispfli.


  read table <b>ispfli-ibookings into xbookings</b> index 1.
  if sy-subrc = 0.
    write:/ <b>xbookings-customid</b>.
  endif.

endloop.

Regards,

Rich Heilman

12 REPLIES 12
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,522

You can reference like this. I hope that this is what you mean.


data: begin of itab occurs 0,
      fld <b>type stru-f3-fa</b>,
      end of itab.

Regards,

Rich Heilman

Read only

0 Likes
1,522

hi try the below code....

data: begin of itab occurs 0,

fld type f3-fa,

end of itab.

Cheers,

Abdul Hakim

Read only

0 Likes
1,522

I think I see what you are talking about now. It is a little tricky. Here ZSPFLI is my structure, it contains CARRID CONNID and a table type of SBOOK.




report  zrich_0001.


<b>data: ispfli type table of ZSPFLI with header line.
data: xspfli like line of ispfli.

data: xbookings like line of ispfli-ibookings.</b>

data: begin of itest occurs 0,
     <b> fld like xbookings-customid,</b>
      end of itest.

loop at ispfli.


  read table ispfli-ibookings into xbookings index 1.
  if sy-subrc = 0.
    write:/ xbookings-customid.
  endif.

endloop

REgards,

Rich Heilman

Read only

Former Member
0 Likes
1,522

Thanks for replying Rich....but I get an error for this saying that 'the stru is a flat type...'

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,522

If you mean how to get the value of these fields in your internal table, then just remember that it is another internal table and must be read. For example.

itab is structure like your custom structure, one field, F3 is a table itself, so you will need to read this.

loop itab into wa.

read table wa-f3 index 1.  " Or however you need to read it.
if sy-subrc = 0.
  write:/ wa-f3-fa.
endif.




endloop.

Regards,

Rich HEilman

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,523

Here is a better example of how to get the values of your deep structure.



report  zrich_0001.

data: begin of ispfli occurs 0,
       carrid type spfli-carrid,
       connid type spfli-connid,
     <b>  ibookings type standard table of sbook,</b>
      end of ispfli.

data: xspfli like line of ispfli.
data: xbookings type sbook.

loop at ispfli.


  read table <b>ispfli-ibookings into xbookings</b> index 1.
  if sy-subrc = 0.
    write:/ <b>xbookings-customid</b>.
  endif.

endloop.

Regards,

Rich Heilman

Read only

0 Likes
1,522

Hi

data: begin of ispfli occurs 0,

carrid type spfli-carrid,

connid type spfli-connid,

ibookings type standard table of sbook,

end of ispfli.

how to insert the values into above internal table ispfli

Read only

0 Likes
1,522

Very good question. It can be done simply like this.



report  zrich_0001.


data: begin of ispfli occurs 0,
      carrid type spfli-carrid,
      connid type spfli-connid,
      ibookings type standard table of sbook,
      end of ispfli.

data: xspfli like line of ispfli.
data: xbookings like line of ispfli-ibookings.

select carrid connid into corresponding fields of table
        ispfli from spfli.


<b>loop at ispfli.
  select * from sbook into table ispfli-ibookings
                where carrid = ispfli-carrid
                  and connid = ispfli-connid.
  modify ispfli.
endloop.</b>


loop at ispfli.

  write:/ ispfli-carrid, ispfli-connid.

  read table ispfli-ibookings into xbookings index 1.
  if sy-subrc = 0.
    write:/ 'THe first customer to book is:', xbookings-customid.
  endif.


endloop.

Regards,

Rich Heilman

Read only

0 Likes
1,522

sorry

deleted

Message was edited by: SAP ABAP

Read only

0 Likes
1,522

Hi rich

loop at ispfli.

write:/ ispfli-carrid, ispfli-connid.

read table ispfli-ibookings into xbookings index 1.

if sy-subrc = 0.

write:/ 'THe first customer to book is:', xbookings-customid.

endif.

endloop.

rich, in the above code what is the use of index , here u r looping ispfli suppose if i write like this then what happens

loop at ispfli.

write:/ ispfli-carrid, ispfli-connid.

xbookings = ispfli-ibbokings.

write:/ 'THe first customer to book is:', xbookings-customid.

endloop.

Read only

0 Likes
1,522

ispfli-ibookings is a internal table within the internal table ispfli. The read statement here is simply just reading the first record in that table(ibookings)

Doing this statement will not work.

xbookings = ispfli-ibbokings.

Here you see that you are trying to move the internal table into the workarea called xbookings. ISPFLI-IBOOKINGS has no header line, so this does not help. You will get a syntax error.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
1,522

Thanks!