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

Assign and increment

Former Member
0 Likes
1,571

I have a code that add the amount from period 1 up to period 16 to get the total

"determines what periods have been requested and sums them accordingly
LOOP AT s_perio INTO wa_perio.
    IF wa_perio+6(3) = space.
      w_low = wa_perio+3(3).
      w_high = wa_perio+3(3).
    ELSE.
      w_low = wa_perio+3(3).
      IF wa_perio+6(3) = 12.
        w_high = 16.
      ELSE.
        w_high = wa_perio+6(3).
      ENDIF.
    ENDIF.
  ENDLOOP.

  wa_times-sign = c_sign.
  wa_times-option = c_option_bt.
  wa_times-low = w_low.
  wa_times-high = w_high.
  APPEND wa_times TO times.


  ADD st_linerec-wog001 THEN st_linerec-wog002 UNTIL st_linerec-wog016
         GIVING w_total ACCORDING TO times.

Now i want to change the code from add then until... to ASSIGN and INCREMENT (since the first one is not used in classes, an obsolete statement). Am i supposed to use field symbol? and i'm not sure how to use INCREMENT for it.

Thanks.

1 ACCEPTED SOLUTION
Read only

former_member194669
Active Contributor
0 Likes
1,338

Try this way


v_int = times-low.
do.
 concatenate 'ST_LINEREC-WOG' v_int into v_field.
 condense v_field no-gaps.
 assign (v_field) to <fs>
 w_total = w_total + <fs>.
 if times-high eq v_int.
    exit.
 endif.
 v_int = v_int + 1.
enddo. 

I have a code that add the amount from period 1 up to period 16 to get the total

"determines what periods have been requested and sums them accordingly
LOOP AT s_perio INTO wa_perio.
    IF wa_perio+6(3) = space.
      w_low = wa_perio+3(3).
      w_high = wa_perio+3(3).
    ELSE.
      w_low = wa_perio+3(3).
      IF wa_perio+6(3) = 12.
        w_high = 16.
      ELSE.
        w_high = wa_perio+6(3).
      ENDIF.
    ENDIF.
  ENDLOOP.

  wa_times-sign = c_sign.
  wa_times-option = c_option_bt.
  wa_times-low = w_low.
  wa_times-high = w_high.
  APPEND wa_times TO times.


  ADD st_linerec-wog001 THEN st_linerec-wog002 UNTIL st_linerec-wog016
         GIVING w_total ACCORDING TO times.

Now i want to change the code from add then until... to ASSIGN and INCREMENT (since the first one is not used in classes, an obsolete statement). Am i supposed to use field symbol? and i'm not sure how to use INCREMENT for it.

Thanks.

8 REPLIES 8
Read only

former_member194669
Active Contributor
0 Likes
1,339

Try this way


v_int = times-low.
do.
 concatenate 'ST_LINEREC-WOG' v_int into v_field.
 condense v_field no-gaps.
 assign (v_field) to <fs>
 w_total = w_total + <fs>.
 if times-high eq v_int.
    exit.
 endif.
 v_int = v_int + 1.
enddo. 

Read only

0 Likes
1,338

Hi a®s, when i tried your code. It says times is not a table with header line. This is how i declare times

DATA: times TYPE RANGE OF index,
      wa_times LIKE LINE OF times.

Read only

0 Likes
1,338

Try this way


read table times into wa_times index 1.
v_int = wa_times-low.
do.
 concatenate 'ST_LINEREC-WOG' v_int into v_field.
 condense v_field no-gaps.
 assign (v_field) to <fs>
 w_total = w_total + <fs>.
 if wa_times-high eq v_int.
    exit.
 endif.
 v_int = v_int + 1.
enddo. 

Read only

0 Likes
1,338

It gaves msg "Field symbol is not assigned" ,a®s

this is how i applied your code in mine.

FIELD-SYMBOLS <fs> TYPE ANY.
DATA v_int(3) type c.
DATA v_field(17) type C.
 read table times into wa_times index 1.
 v_int = wa_times-low.
do.
 concatenate 'ST_LINEREC-WOG' v_int into v_field.
 condense v_field no-gaps.
 assign (v_field) to <fs>.
 w_total = w_total + <fs>.
 if wa_times-high eq v_int.
    exit.
 endif.
 v_int = v_int + 1.
enddo.

maybe the problem comes from the declaration part?

Read only

0 Likes
1,338

I think v_field not getting proper values

ST_LINEREC-WOG003 i think it getting as ST_LINEREC-WOG3

Try to change this way


field-symbols <fs> type any.
data v_int type i.   "<<
data : v_cint(3) type c.   "<<
data v_field(17) type c.
data: times type range of index,
      wa_times like line of times.

read table times into wa_times index 1.
v_int = wa_times-low.
do.
  unpack v_int to v_cint..  "<<
  concatenate 'ST_LINEREC-WOG' v_cint into v_field.
  condense v_field no-gaps.
  assign (v_field) to <fs>.
  w_total = w_total + <fs>.
  if wa_times-high eq v_int.
    exit.
  endif.
  v_int = v_int + 1.
enddo.

Read only

0 Likes
1,338

awesome, it works!. Thanks a lot a®s !.

Read only

Former Member
0 Likes
1,338

Hi,

try this.

w_total = w_total + : st_linerec-wog001,

st_linerec-wog002,

st_linerec-wog003,

st_linerec-wog004,

st_linerec-wog005,

st_linerec-wog006,

st_linerec-wog007,

st_linerec-wog008,

st_linerec-wog009,

st_linerec-wog010,

st_linerec-wog011,

st_linerec-wog012,

st_linerec-wog013,

st_linerec-wog014 ,

st_linerec-wog015,

st_linerec-wog016 .

Read only

0 Likes
1,338

Hi Sreesudha , thank you for your suggestion but your code will always sum all period no matter what the period the user enter on selection screen.