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: 

count problem

Former Member
0 Kudos

Hi,

i am in do loop.Even though im clearing variable used for count , its still using the last value while counting next value.

do 2 times.

loop at itab.

program logic......

count1 = count1 + x.

endloop.

itab-count1 = count1.

clear count1.

enddo.

i am downloading internal table values to excel sheet .

for 1week if i have value 10

for 2week it should be 2 , but its showing 12.

thx.

5 REPLIES 5

Former Member
0 Kudos

Your statements below are outside the ENDLOOP. Move them inside the LOOP, ENDLOOP.

itab-count1 = count1.

clear count1.

Former Member
0 Kudos

HI,

Do 2 times.

*-- is there any condition to loop at this internal table or not.. i think there should be a condition for second week..

loop at itab.

endloop.

enddo.

Paste your complete code to have a better understandig and a better reply

Thanks

mahesh

Former Member
0 Kudos

Hi Raghu,

Change the code to as follows. Change the value of count1 inside the LOOP..ENDLOOP

do 2 times.

<b>clear count1.</b>

loop at itab.

program logic......

count1 = count1 + x.

<b>itab-count1 = count1.</b>

<b>modify itab index sy-tabix.</b>

endloop.

enddo.

Thanks,

Vinay

marcelo_ramos
Active Contributor
0 Kudos

Hi,


do 2 times.
  clear count1.
  loop at itab. "Don't need to use a condition here ?
     ...
     count1 = count1 + x.
     itab-count1 = count1.
     modify itab index sy-tabix.
  endloop.
enddo.

Regards.

Marcelo Ramos

0 Kudos

Hi all,

here is the code .

in selection screen i have date, work order type, func location and planner group.

in this im calculating remaining hours ( planned hours - actual hours )for each work order type for the week starting sunday and ending saturday.

************************************************************************

REPORT z_wok NO STANDARD PAGE HEADING " LINE-SIZE 132

MESSAGE-ID z_rag.

*-Tables----


TABLES: aufk,iloa,afih,s022,afru,afvv,sscrfields,caufv,afko.

*-Selection screen----


SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME TITLE text-001.

SELECT-OPTIONS: s_date FOR aufk-erdat, " date

s_auart FOR aufk-auart, " Work order type

s_tplnr FOR iloa-tplnr, "Functional Location

s_ingpr FOR afih-ingpr. " Planner Group

SELECTION-SCREEN END OF BLOCK blk1.

SELECTION-SCREEN:BEGIN OF LINE,

PUSHBUTTON 2(25) text-020 USER-COMMAND cli1,

END OF LINE.

RANGES: r_date FOR aufk-erdat.

-Global Types----


TYPES:BEGIN OF t_tab,

aufnr LIKE aufk-aufnr,

auart LIKE aufk-auart,

arbei LIKE plpo-arbei,

ismnw LIKE afru-ismnw,

date1 TYPE aufk-erdat,

date2 TYPE aufk-erdat,

datef1 TYPE aufk-erdat,

datef2 TYPE aufk-erdat,

datef3 TYPE aufk-erdat,

datef5 TYPE aufk-erdat,

v_newdat TYPE aufk-erdat,

v_cnt TYPE afru-ismnw,

v_cnt1 TYPE afru-ismnw,

v_cnt2 TYPE afru-ismnw,

v_cnt3 TYPE afru-ismnw,

v_cnt4 TYPE afru-ismnw,

rhrs TYPE afru-ismnw,

rhrs1 TYPE afru-ismnw,

rhrs2 TYPE afru-ismnw,

rhrs3 TYPE afru-ismnw,

rhrs4 TYPE afru-ismnw,

ingpr LIKE afih-ingpr,

v_status1(20) TYPE c,

stat(5) TYPE c,

aueru LIKE afru-aueru,

tplnr LIKE iloa-tplnr,

ssedd LIKE mcafvgv-ssedd,

sttxt LIKE bsvx-sttxt,

erdat TYPE aufk-erdat,

END OF t_tab.

*TYPES : BEGIN OF t_tab1,

  • v_cnt1 TYPE afru-ismnw,

  • v_cnt2 TYPE afru-ismnw,

  • v_cnt3 TYPE afru-ismnw,

  • v_cnt4 TYPE afru-ismnw,

  • date2 TYPE aufk-erdat,

  • datef5 TYPE aufk-erdat,

  • END OF t_tab1.

TYPES : BEGIN OF t_tab1,

v_cnt1(30) TYPE C,

v_cnt2(30) TYPE C,

v_cnt3(30) TYPE C,

v_cnt4(30) TYPE C,

date2 TYPE aufk-erdat,

datef5 TYPE aufk-erdat,

END OF t_tab1.

-Global Structures / Internal Tables----


DATA : it_tab TYPE t_tab OCCURS 0 WITH HEADER LINE.

DATA : it_tab1 TYPE t_tab1 OCCURS 0 WITH HEADER LINE.

DATA : wa_tab LIKE it_tab OCCURS 0 WITH HEADER LINE.

-Global Variables----


DATA : v_dat LIKE s022-ssedd.

DATA : v_lfdat LIKE v_dat.

DATA : v_aufnr LIKE aufk-aufnr.

DATA : v_status LIKE bsvx-sttxt.

DATA : v_objnr LIKE aufk-objnr.

DATA : aufnr LIKE it_tab-aufnr.

DATA : auart LIKE it_tab-auart.

DATA : p_tabix LIKE sy-tabix.

DATA : v_ismnw LIKE afru-ismnw.

DATA : v_arbei LIKE afvv-arbei.

DATA : v_cnt TYPE afru-ismnw.

DATA : v_cnt1 TYPE afru-ismnw.

DATA : v_cnt2 TYPE afru-ismnw.

DATA : v_cnt3 TYPE afru-ismnw.

DATA : v_cnt4 TYPE afru-ismnw.

DATA : v_rhrs TYPE afru-ismnw.

DATA : v_rhrs1 TYPE afru-ismnw.

DATA : v_rhrs2 TYPE afru-ismnw.

DATA : v_rhrs3 TYPE afru-ismnw.

DATA : v_rhrs4 TYPE afru-ismnw.

DATA : v_newdat LIKE aufk-erdat.

DATA : date2 LIKE aufk-erdat,

datef2 LIKE aufk-erdat,

datef5 LIKE aufk-erdat.

DATA : v_count1(6) TYPE c,

v_count2(6) TYPE c,

v_count3(6) TYPE c,

v_count4(6) TYPE c.

*DATA : it_tab1 TYPE t_tab1 OCCURS 0 WITH HEADER LINE.

DATA : date1 TYPE aufk-erdat, out_date TYPE aufk-erdat.

DATA : daytxt TYPE hrvsched-daytxt.

DATA : daynr TYPE hrvsched-daynr.

DATA : dayfree TYPE hrvsched-noday.

DATA: v_date1 LIKE t5a4a-dlydy.

DATA : v_weeks LIKE pc26w-weeks.

date1 = s_date-low.

*date2 = s_date-low.

DATA : datef1 LIKE aufk-erdat,

datef3 LIKE aufk-erdat,

v_datef1 LIKE t5a4a-dlydy.

datef1 = s_date-high.

*datef2 = s_date-high.

v_cnt = 0.

v_cnt1 = 0.

v_cnt2 = 0.

v_cnt3 = 0.

v_cnt4 = 0.

&----


*& Calculates Week Day for s_date-low *

&----


CALL FUNCTION 'RH_GET_DATE_DAYNAME'

EXPORTING

langu = 'E'

date = date1

calid = '01'

IMPORTING

daynr = daynr

daytxt = daytxt

dayfree = dayfree

EXCEPTIONS

no_langu = 1

no_date = 2

no_daytxt_for_langu = 3

invalid_date = 4

OTHERS = 5.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

*

IF daytxt = 'Monday'.

v_date1 = 1.

ELSE.

IF daytxt = 'Tuesday'.

v_date1 = 2.

ELSE.

IF daytxt = 'Wednesday'.

v_date1 = 3.

ELSE.

IF daytxt = 'Thursday'.

v_date1 = 4.

ELSE.

IF daytxt = 'Friday'.

v_date1 = 5.

ELSE.

IF daytxt = 'Saturday'.

v_date1 = 6.

ENDIF.

ENDIF.

ENDIF.

ENDIF.

ENDIF.

ENDIF.

&----


*& *

*& Set the s_date-low to nearest Sunday *

*& *

&----


CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL'

EXPORTING

date = date1

days = v_date1

months = 0

signum = '-'

years = 0

IMPORTING

calc_date = date2.

&----


*& *

*& Calculates Week Day for s_date-high *

*& *

&----


CALL FUNCTION 'RH_GET_DATE_DAYNAME'

EXPORTING

langu = 'E'

date = datef1

calid = '01'

IMPORTING

daynr = daynr

daytxt = daytxt

dayfree = dayfree

EXCEPTIONS

no_langu = 1

no_date = 2

no_daytxt_for_langu = 3

invalid_date = 4

OTHERS = 5.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

IF daytxt = 'Monday'.

v_datef1 = 5.

ELSE.

IF daytxt = 'Tuesday'.

v_datef1 = 4.

ELSE.

IF daytxt = 'Wednesday'.

v_datef1 = 3.

ELSE.

IF daytxt = 'Thursday'.

v_datef1 = 2.

ELSE.

IF daytxt = 'Friday'.

v_datef1 = 1.

ENDIF.

ENDIF.

ENDIF.

ENDIF.

ENDIF.

&----


*& *

*& Set s_date-high to nearest Saturday *

*& *

&----


CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL'

EXPORTING

date = datef1

days = v_datef1

months = 0

signum = '+'

years = 0

IMPORTING

calc_date = datef2.

&----


*& *

*& Calculates number for weeks for selection screen dates *

*& *

&----


CALL FUNCTION 'HR_IE_NUM_PRSI_WEEKS'

EXPORTING

tax_year_begin = date2

period_begin = date2

period_end = datef2

IMPORTING

num_weeks = v_weeks.

-At Selection Screen_----


AT SELECTION-SCREEN.

IF sscrfields-ucomm = 'CLI1'.

SUBMIT zire0007 VIA SELECTION-SCREEN

AND RETURN.

ENDIF.

-Initialization----


*INITIALIZATION.

-Main Program logic----


START-OF-SELECTION.

WRITE : /10 'wok_ord', 20 'ord_typ',30 'plan_hrs', 45 'act_hrs', 55 'rem_hrs', 70 'status'.

SET PF-STATUS 'ZPMT_INLI'.

SELECT aaufnr aauart a~erdat INTO CORRESPONDING FIELDS OF TABLE it_tab

FROM aufk AS a

INNER JOIN iloa AS d ON abukrs = dbukrs

INNER JOIN afih AS f ON aaufnr = faufnr

WHERE a~auart IN s_auart

AND a~auart NE 'PM04'

AND a~auart NE 'PM09'

AND a~werks = 'M600'

AND d~tplnr IN s_tplnr

AND f~ingpr IN s_ingpr

AND a~erdat IN s_date.

IF sy-subrc <> 0.

MESSAGE i001.

RETURN.

ENDIF.

SORT it_tab BY aufnr.

DELETE ADJACENT DUPLICATES FROM it_tab COMPARING aufnr.

it_tab1-v_cnt1 = 'PM01'.

IT_TAB1-V_CNT2 = 'PM02'.

IT_TAB1-v_CNT3 = 'PM03'.

IT_TAB1-V_CNT4 = 'PM99'.

IT_TAB1-DATE2 = 'START_DATE'.

IT_TAB1-DATEF5 = 'END_DATE'.

APPEND IT_TAB1.

LOOP AT it_tab.

CLEAR v_aufnr.

CLEAR v_arbei.

CLEAR v_ismnw.

v_aufnr = it_tab-aufnr.

SELECT SINGLE ismnw INTO v_ismnw FROM afru

WHERE aufnr = v_aufnr.

it_tab-ismnw = v_ismnw.

SELECT SINGLE a~arbei INTO v_arbei FROM afvv AS a

INNER JOIN caufv AS b ON aaufpl = baufpl

WHERE b~aufnr = v_aufnr.

it_tab-arbei = v_arbei.

MODIFY it_tab.

p_tabix = sy-tabix.

SELECT SINGLE objnr FROM aufk

INTO v_objnr

WHERE aufnr = it_tab-aufnr.

CALL FUNCTION 'STATUS_TEXT_EDIT'

EXPORTING

flg_user_stat = 'X'

objnr = v_objnr

only_active = 'X'

spras = sy-langu

IMPORTING

line = v_status.

  • exceptions

  • object_not_found = 01.

IF v_status CS 'PCNF'.

REPLACE 'PCNF' IN v_status WITH 'ABCD'.

ENDIF.

IF ( v_status NS 'CNF' OR v_status NS 'TECO' OR v_status NS 'CLSD' OR v_status NS 'DLFL' )

AND ( v_status CS 'ABCD' OR v_status CS 'CRTD' OR v_status CS 'REL' )

AND ( V_STATUS NS 'CNF' )

AND ( v_status NS 'TECO' OR v_status NS 'ABCD' ).

IF v_status CS 'ABCD'.

REPLACE 'ABCD' IN v_status WITH 'PCNF'.

ENDIF.

it_tab-sttxt = v_status.

MODIFY it_tab.

ELSE.

DELETE it_tab INDEX p_tabix.

ENDIF.

****07/05

  • SELECT SINGLE ssedd FROM s022 INTO v_dat

  • WHERE aufnr = it_tab-aufnr.

*

  • CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL'

  • EXPORTING

  • date = v_dat

  • days = 42

  • months = 0

  • signum = '+'

  • years = 0

  • IMPORTING

  • calc_date = v_lfdat.

*

  • IF it_tab-ssedd > v_lfdat.

  • DELETE it_tab INDEX p_tabix.

  • ENDIF.

ENDLOOP.

SORT it_tab BY aufnr.

DELETE ADJACENT DUPLICATES FROM it_tab COMPARING aufnr.

DO v_weeks TIMES.

CLEAR v_cnt1.

CLEAR v_cnt2.

CLEAR v_cnt3.

CLEAR v_cnt4.

CLEAR v_cnt.

CLEAR datef5.

CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL'

EXPORTING

date = date2

days = 7

months = 0

signum = '+'

years = 0

IMPORTING

calc_date = datef5.

REFRESH r_date.

r_date-low = date2.

r_date-high = datef5.

r_date-sign = 'I'.

r_date-option = 'BT'.

APPEND r_date.

SORT it_tab BY erdat.

LOOP AT it_tab.

IF it_tab-erdat BETWEEN r_date-low AND r_date-high.

CLEAR v_aufnr.

CLEAR v_rhrs.

CLEAR v_rhrs1.

CLEAR v_rhrs2.

p_tabix = sy-tabix.

v_aufnr = it_tab-aufnr.

IF ( it_tab-sttxt CS 'REL' OR it_tab-sttxt NS 'TECO' ).

it_tab-rhrs = it_tab-arbei - it_tab-ismnw.

DELETE it_tab WHERE rhrs < 0.

DELETE it_tab WHERE sttxt CS ' DLFL '.

ENDIF.

IF it_tab-auart = 'PM01'.

it_tab-rhrs1 = it_tab-arbei - it_tab-ismnw.

ELSE.

IF it_tab-auart = 'PM02'.

it_tab-rhrs2 = it_tab-arbei - it_tab-ismnw.

ELSE.

IF it_tab-auart = 'PM03'.

it_tab-rhrs3 = it_tab-arbei - it_tab-ismnw.

ELSE.

IF it_tab-auart = 'PM99'.

it_tab-rhrs4 = it_tab-arbei - it_tab-ismnw.

ENDIF.

ENDIF.

ENDIF.

ENDIF.

MODIFY it_tab.

v_cnt = v_cnt + it_tab-rhrs.

v_cnt1 = v_cnt1 + it_tab-rhrs1.

v_cnt2 = v_cnt2 + it_tab-rhrs2.

v_cnt3 = v_cnt3 + it_tab-rhrs3.

v_cnt4 = v_cnt4 + it_tab-rhrs4.

ELSE.

CLEAR v_newdat.

CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL'

EXPORTING

date = datef5

days = 1

months = 0

signum = '+'

years = 0

IMPORTING

calc_date = v_newdat.

date2 = v_newdat.

ENDIF.

ENDLOOP.

it_tab1-v_cnt1 = v_cnt1.

it_tab1-v_cnt2 = v_cnt2.

it_tab1-v_cnt3 = v_cnt3.

it_tab1-v_cnt4 = v_cnt4.

it_tab1-date2 = r_date-low.

it_tab1-datef5 = r_date-high.

APPEND it_tab1.

ENDDO.

LOOP AT it_tab.

WRITE : /10 it_tab-aufnr, 20 it_tab-auart, 30 it_tab-arbei, 45 it_tab-ismnw, 55 it_tab-rhrs,70 it_tab-sttxt.

ENDLOOP.

WRITE : /60 v_cnt,70 v_cnt1,80 v_cnt2, 85 v_cnt3,90 v_cnt4.

AT USER-COMMAND.

CASE sy-ucomm.

WHEN 'DOWNLOAD'(001).

PERFORM draw_graph.

ENDCASE.

&----


*& Form DRAW_GRAPH

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM draw_graph.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = 'H:\test525.xls'

filetype = 'ASC'

write_field_separator = 'X'

TABLES

data_tab = it_tab1

EXCEPTIONS

file_write_error = 1

no_batch = 2

gui_refuse_filetransfer = 3

invalid_type = 4

OTHERS = 5.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDFORM. " draw_graph