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 table fields using Field Symbols

Former Member
0 Likes
2,483

I am using COSS tables , I want to read the fields WTG001…..WOG016 . I just want to read the fields where ever it has some value . How can I achieve this task using field symbols ? I just want where ever I find record , I have to get out of select .

I am thinking it should be like

Select ( using field symbols )

If not find

Continue

Else

Exit .

Endselect

Can some one post me the code .

Cheers

Usman

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,381

hi,

i and doing the same thing with table cosp. this is how you can do.

data: begin of lst_coss,
       wtg001 like coss-wtg001,
       wtg002 like coss-wtg002,
       wtg003 like coss-wtg003,
       wtg004 like coss-wtg004,
       wtg005 like coss-wtg005,
       wtg006 like coss-wtg006,
       wtg007 like coss-wtg007,
       wtg008 like coss-wtg008,
       wtg009 like coss-wtg009,
       wtg0010 like coss-wtg0010,
       wtg0011 like coss-wtg0011,
       wtg0012 like coss-wtg0012,
       wtg0013 like coss-wtg0013,
       wtg0014 like coss-wtg0014,
       wtg0015 like coss-wtg0015,
       wtg0016 like coss-wtg0016,
   end of lst_coss.

data: lit_coss type table coss with header line.

data: total like coss-wtg001.

field-symbol: <fs>.

select * from coss into table lit_coss upto 10 rows.

loop at lit_coss.
   lst_coss = lit_coss.
   do 16 times.
       assign component sy-index of structure lst_csoo to <fs>.
       total = total + <fs>.
   while.

   write:/0 'object: ' 10 lit_coss-objnr,
                 25 'tran. curr', 40 total.

   clear: lst_coss, total.

endloop.

i hope this will work for you.

Thanks,

Pratik

8 REPLIES 8
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,381

I don't think that its a good idea to do it that way, and I don't think it is possible to do a dynamic field list, try something like this.\



report zrich_0001.

data: icoss type table of coss with header line.
data: field_name(30) type c.
data: index(4) type c.
data: n(2) type n.

field-symbols: <fs>.


start-of-selection.

  select * into table icoss from coss
               up to 100 rows.       " For Testing

  loop at icoss.

    do.
      n = sy-index.
      index = n.
      concatenate 'WTG0' index into field_name.
      assign component field_name of structure icoss to <fs>.
      if sy-subrc <> 0.
        exit.
      endif.
      if not <fs> is initial.
        write:/ field_name, 'has a value', <fs>.
      endif.
    enddo.

  endloop.

Regards,

Rich Heilman

Read only

0 Likes
1,381

Hi Usman,

If you are not retrieving any data but just interested in checking if a value exists.. you could use the following ugly SELECT too..


select * from COSS up to 1 rows
         where ( WTGO01 gt 0 or WTGO01 gt 0 or & so on ).
endselect.
if sy-subrc eq 0.
" has a value.
endif.

Regards,

Suresh Datti

Read only

0 Likes
1,381

I used the following logic and able to read the results for table . Now I have opposite requirement . for example .

After reading the value from main internal table using field symbol . I have to assign it back to other internal table different fields .

I am getting an input file which has different record it contain the values from WTG001 TO WTG016.

I am declaring another internal table with same structure , I am reading what is the next empty value in table lets say I find ‘WTG005’ . In my excel sheet ‘WTG001’ has value . remember its going to be different for every record in my excel sheet .

Now using the old logic I decide next available empty field is ‘wtg005’ . I have to assign the value of main internal table to the separate field of new( 2nd internal table ) using fild symbols .

I hope I explain you , if you still need clarification do let me know .

Cheers

Usman

Read only

sergey_korolev
Active Contributor
0 Likes
1,381

Actually you don't need filed symbols here, DO... VARYING is more sufficient:

<b>DATA</b>: wtg TYPE coss-wtg001.
<b>DO </b> 16 <b>TIMES</b>
  <b>VARYING</b> wtg <b>FROM</b> coss-wtg001 <b>NEXT</b> coss-wtg002.

<b>ENDDO</b>.

Read only

Former Member
0 Likes
1,382

hi,

i and doing the same thing with table cosp. this is how you can do.

data: begin of lst_coss,
       wtg001 like coss-wtg001,
       wtg002 like coss-wtg002,
       wtg003 like coss-wtg003,
       wtg004 like coss-wtg004,
       wtg005 like coss-wtg005,
       wtg006 like coss-wtg006,
       wtg007 like coss-wtg007,
       wtg008 like coss-wtg008,
       wtg009 like coss-wtg009,
       wtg0010 like coss-wtg0010,
       wtg0011 like coss-wtg0011,
       wtg0012 like coss-wtg0012,
       wtg0013 like coss-wtg0013,
       wtg0014 like coss-wtg0014,
       wtg0015 like coss-wtg0015,
       wtg0016 like coss-wtg0016,
   end of lst_coss.

data: lit_coss type table coss with header line.

data: total like coss-wtg001.

field-symbol: <fs>.

select * from coss into table lit_coss upto 10 rows.

loop at lit_coss.
   lst_coss = lit_coss.
   do 16 times.
       assign component sy-index of structure lst_csoo to <fs>.
       total = total + <fs>.
   while.

   write:/0 'object: ' 10 lit_coss-objnr,
                 25 'tran. curr', 40 total.

   clear: lst_coss, total.

endloop.

i hope this will work for you.

Thanks,

Pratik

Read only

0 Likes
1,381

I am doing almost the same thing , but I want to assign the value of lit_coss-WTG009 field to lst_coss-WTG001 ( 2nd internal table _ .. USING feild symbol .

How Can I achive this task ..

Cheers

usman

Read only

0 Likes
1,381

Well I don’t think after reading table using field symbol , and get its value in field symbol and assign it back to another internal table new field using field symbol . I also came across this kind of situation but we use command "DO" Syntax was like that

Do No times varying var1 from table_variable next last_table variable

Hope this’ll give you some idea .

Thanks

Read only

0 Likes
1,381

Usman,

I did not get your requirement. Can you please explain in detail ( with example if possible )?

Thanks,