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: 

field symbol with table field

Former Member
0 Kudos

Hi !

here is my problem :

I have a table define like this :

matnr XXXX01 YYYY01 ZZZZ01 XXXX02 YYYY02 ZZZZ02 XXXX03 YYYY03 ZZZZ03 ... up to 12

when i read the header, i want to select the first field that is empty (for exemple XXXX02) and see if the next one (XXXX03) is filled. IF the next one is not filled i want to take the next until i found one that is filled. for exemple XXXX05 and then put the value in the first one (XXXX02).

So my probleme is that i don't know what is the name of the field. I tried something with the field symbol but i don't know how it work.

I'd like to wrote something like that :

IF itab-<fs> IS INITIAL.

<fs> would be the concatenation of XXXX and a counter (01,02,03...).

Thanks for you help !

1 ACCEPTED SOLUTION

naimesh_patel
Active Contributor
0 Kudos

Try to implement logic like this in your code:

Data: l_fldname(30),
l_cnt(2) type n.

Loop at itab.
Do 12 times.
l_cnt = l_cnt + 1.
concatenate 'ITAB-XXXX' l_cnt into l_fldname.
assign (l_fldname) to <FS>.

if not <FS> is initial.
exit.
endif.
enddo.
endloop.

Regards,

Naimesh Patel

9 REPLIES 9

former_member195698
Active Contributor
0 Kudos

Hi,

You can try.

Assign component wf_field of structure itab to <fs>.

Then check

if <fs> is initial.

where wf_field will store the name of the field.

Regards,

Abhishek

naimesh_patel
Active Contributor
0 Kudos

Try to implement logic like this in your code:

Data: l_fldname(30),
l_cnt(2) type n.

Loop at itab.
Do 12 times.
l_cnt = l_cnt + 1.
concatenate 'ITAB-XXXX' l_cnt into l_fldname.
assign (l_fldname) to <FS>.

if not <FS> is initial.
exit.
endif.
enddo.
endloop.

Regards,

Naimesh Patel

0 Kudos

thank you very much, but i still have a problem.

I wrote this and the test doesnt work (wt_month is a table with 01, 02, 03, ...)

LOOP AT wt_month.

CLEAR wv_found.

wv_index = sy-tabix.

CONCATENATE wc_zone1 wt_month-month INTO wv_zone.

ASSIGN COMPONENT wv_zone OF STRUCTURE wt_final_new TO <wf_zone1>.

IF <wf_zone1> IS INITIAL.

wv_index = wv_index + 1.

LOOP AT wt_month2 FROM wv_index.

CONCATENATE wc_zone1 wt_month2 INTO wv_zone.

ASSIGN COMPONENT wv_zone

OF STRUCTURE wt_final_new TO <wf_zone2>.

IF NOT <wf_zone2> IS INITIAL.

<wf_zone1> = <wf_zone2>.

LOOP AT wt_zone.

CONCATENATE wt_zone-zone wt_month-month INTO wv_zone.

ASSIGN COMPONENT wv_zone

OF STRUCTURE wt_final_new TO <wf_zone1>.

CONCATENATE wt_zone-zone wt_month2-month INTO wv_zone.

ASSIGN COMPONENT wv_zone

OF STRUCTURE wt_final_new TO <wf_zone2>.

<wf_zone1> = <wf_zone2>.

ENDLOOP.

wv_found = 'X'.

ENDIF.

ENDLOOP.

IF wv_found IS INITIAL.

  • SELECT

ENDIF.

ENDIF.

ENDLOOP.

0 Kudos

Change your first assign statement like this:

ASSIGN COMPONENT wv_zone OF STRUCTURE <b>WT_MONTH</b> TO <wf_zone1>.

Regards,

Naimesh Patel

0 Kudos

no wt_month is a table with numbers (01,02,03...), i use this instead of an incrementation for other reasons.

0 Kudos

please i really need your help.

maybe the problem is the declaration of the field symbol ? I declare as type any.

0 Kudos

It looks like, all your ASSIGN statments are right.

Put break point after the assign statment, check the content of your original field and field-symbol. You will some better idea, what is going wrong.

Regards,

Naimesh Patel

Former Member
0 Kudos

I use this code to sweep all the fields in a table...


  loop at t_asgnas.
    clear v_linea.
    do 137 times.
      clear v_campo.
      assign component sy-index of structure t_asgnas to <campo>.
      v_campo = <campo>.
      shift v_campo left deleting leading space.
      v_len = strlen( v_campo ).
      if v_len <= 0. v_len = 1. endif.
      concatenate v_linea
                  v_campo+0(v_len)
                  into v_linea separated by '^'.
    enddo.
  write / v_linea.
  endloop.

You could change the logic and make it skip 3 fields everytime, as to land on the XXXX__ fields on every cycle.

I would try to code with your logic but i don't have the time right now... I hope you find use to it.

0 Kudos

argh it was my constant that had to be in upper case !

thank you all for your help ! i gave you reward points