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: 

Accessing fields with unknown names

Former Member
0 Kudos

Okay, I'm finding this a bit tricker than I originally thought it would be.

I've got an internal table going by the name of xinttab, and a string zhtml. I also have the following:

data: zrows type i,
      zcols type i,
      zctyp type c.

field-symbols: <fs_xinttab> type any.

zrows = lines( xinttab ).
describe field xinttab type zctyp components zcols.

clear zhtml.
move '<table>' to zhtml.
do zrows times.
  read table xinttab index sy-index assigning <fs_xinttab>.
  concatenate zhtml '<tr>' into zhtml.
  do zcols times.
    concatenate zhtml '<td>' into zhtml.
    concatenate zhtml <fs_xinttab>-somefield into zhtml.
    concatenate zhtml '</td>' into zhtml.
  enddo.
  concatenate zhtml '</tr>' into zhtml.
enddo.
concatenate zhtml '</table>' into zhtml.

Now, obviously that "<fs_xinttab>-somefield" isn't going to do a right lot. So what I need is either a way of determining the name of the field at position <i>x</i> in a structure, or a way of referring to a field by its structure index (as opposed to row index).

Any help on this would be massively appreciated as I'm hoping to get this finished in the next hour or so... :-S

If I'm going about that completely the wrong way please feel free to say so, I don't mind starting again!

1 ACCEPTED SOLUTION

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

You, can use the following statement.

ASSIGN COMPONENT '1' of structure itab to <fs>.

Regards,

RIch Heilman

5 REPLIES 5

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

You, can use the following statement.

ASSIGN COMPONENT '1' of structure itab to <fs>.

Regards,

RIch Heilman

Clemenss
Active Contributor
0 Kudos

define the field-symbol with structure:

field-symbols: <fs_xinttab> like xinttab.

that should do. Or did I misunderstand you?

regards,

Clemens

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Here is a sample.




report zrich_0003 .

data: zrows type i,
      zcols type i,
      zctyp type c.

data: begin of xinttab occurs 0,
      fld1 type c,
      fld2 type c,
      fld3 type c,
      end of xinttab.

data: zhtml type string.

field-symbols: <fs_xinttab> type any.
field-symbols: <fs> type any.



xinttab-fld1 = 'A'.
xinttab-fld2 = 'B'.
xinttab-fld3 = 'C'.
append xinttab.

xinttab-fld1 = 'D'.
xinttab-fld2 = 'E'.
xinttab-fld3 = 'F'.
append xinttab.



describe table xinttab lines zrows.
describe field xinttab type zctyp components zcols.

clear zhtml.

move '<table>' to zhtml.

loop at xinttab assigning <fs_xinttab>.

  concatenate zhtml '<tr>' into zhtml.
  do zcols times.
    concatenate zhtml '<td>' into zhtml.
   <b> assign component sy-index of structure  <fs_xinttab> to <fs>.</b>  
  concatenate zhtml <fs> into zhtml.
    concatenate zhtml '</td>' into zhtml.
  enddo.
  concatenate zhtml '</tr>' into zhtml.
endloop.
concatenate zhtml '</table>' into zhtml.


write:/ zhtml.

Regards,

Rich Heilman

Former Member
0 Kudos

Rich, you're a hero in your own lunchtime!

0 Kudos

Just about ready to break out my italian sub.

Glad that it worked for ya.!!

Regards,

Rich Heilman