cancel
Showing results for 
Search instead for 
Did you mean: 

calling record in internal table

Former Member
0 Kudos

Hi,

I have an internal table itab of this type:

types: begin of tdat

fld1(10) type c,

fld2(10) type c,

fld3(10) type c,

end of tdat.

All I want to do is assign the second field of the second record of the internal table to a variable. How do I do so?

thanks!

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Hope this helps.

Data: G_assigned_variable(10).

Read table tdat index 2.

if sy-subrc = 0.

g_assigned_variable = tdat-fld2.

endif.

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Not sure what you requirement is......but you can do this too.



report zrich_0001.


data: begin of itab occurs 0,
      fld1(10)  type c,
      fld2(10)  type c,
      fld3(10)  type c,
      end of itab.

field-symbols: <fs>.

data: some_variable(10).


itab-fld1 = '1'.
itab-fld2 = '2'.
itab-fld3 = '3'.
append itab.

itab-fld1 = '4'.
itab-fld2 = '5'.
itab-fld3 = '6'.
append itab.

itab-fld1 = '7'.
itab-fld2 = '8'.
itab-fld3 = '9'.
append itab.

assign itab-fld2 to <fs>.
read table itab index 2.
check sy-subrc = 0.
some_variable = <fs>.


Regards,

Rich Heilman

Former Member
0 Kudos

i am a little confused about your requirement but here's what I think should be the code :

loop at itab.

if sy-tabix eq 2. " Second Record

var = itab-fld2.

endif.

endloop.

Former Member
0 Kudos

why are you confused by my requirement?

former_member188685
Active Contributor
0 Kudos

hi Kevin,

are you looking for some thing else. or is the above code solves your problem.

regards

vijay

Former Member
0 Kudos

I think this solves the problem. I'm just trying to figure out how to read specific fields from records in a two-dimensional internal table. That's all.

Former Member
0 Kudos

data : begin of itab occurs 0,

fld1(10) type c,

fld2(10) type c,

fld3(10) type c,

end of idat.

read table itab with key 2.

if sy-subrc = 0.

variable = itab-fld2.

endif.

former_member188685
Active Contributor
0 Kudos

Hi,

try this

data: v_fld2(10).

loop at itdat .

if sy-tabix = 2.

v_fld2 = itdat-fld2.

exit.

endif.

endloop.

regards

vijay