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

In Internal Table logic not matching

sravya_ch
Participant
0 Likes
1,894

Hi all

There are 11 machines and for each machine there are 3 shifts . i want to get sum of 3 shifts and write it into another internal table . with the code i have written in debugging mode .if i clear the data i am not getting the sum . if i dont clear it it is adding to next machine number .


LOOP AT ITAB  .
  IF ( ITAB-EQUNR EQ 'ACM-P-01' ) OR ( ITAB-EQUNR EQ 'ACM-P-02' ) OR
     ( ITAB-EQUNR EQ 'ACM-P-03' ) OR ( ITAB-EQUNR EQ 'ACM-P-04' ) OR
     ( ITAB-EQUNR EQ 'ACM-P-05' ) OR ( ITAB-EQUNR EQ 'ACM-P-06' ) OR
     ( ITAB-EQUNR EQ 'ACM-P-07' ) OR ( ITAB-EQUNR EQ 'ACM-P-08' ) OR
     ( ITAB-EQUNR EQ 'ACMA01' ) OR ( ITAB-EQUNR EQ 'ACMA02' ) OR ( ITAB-EQUNR EQ 'ACMA03') .

      CASE ITAB-SHIFT .
       when  'A'.
        MOVE ITAB-PRO TO  ACM1A.
       when  'B'.
        MOVE ITAB-PRO TO  ACM1B.
       WHEN  'C'.
        MOVE ITAB-PRO TO  ACM1C.
      ENDCASE.
  ENDIF.
  ITAB-PRO1 = ACM1A + ACM1B + ACM1C.
APPEND ITAB2.

ENDLOOP.

Sravya

Hi all

There are 11 machines and for each machine there are 3 shifts . i want to get sum of 3 shifts and write it into another internal table . with the code i have written in debugging mode .if i clear the data i am not getting the sum . if i dont clear it it is adding to next machine number .


LOOP AT ITAB  .
  IF ( ITAB-EQUNR EQ 'ACM-P-01' ) OR ( ITAB-EQUNR EQ 'ACM-P-02' ) OR
     ( ITAB-EQUNR EQ 'ACM-P-03' ) OR ( ITAB-EQUNR EQ 'ACM-P-04' ) OR
     ( ITAB-EQUNR EQ 'ACM-P-05' ) OR ( ITAB-EQUNR EQ 'ACM-P-06' ) OR
     ( ITAB-EQUNR EQ 'ACM-P-07' ) OR ( ITAB-EQUNR EQ 'ACM-P-08' ) OR
     ( ITAB-EQUNR EQ 'ACMA01' ) OR ( ITAB-EQUNR EQ 'ACMA02' ) OR ( ITAB-EQUNR EQ 'ACMA03') .

      CASE ITAB-SHIFT .
       when  'A'.
        MOVE ITAB-PRO TO  ACM1A.
       when  'B'.
        MOVE ITAB-PRO TO  ACM1B.
       WHEN  'C'.
        MOVE ITAB-PRO TO  ACM1C.
      ENDCASE.
  ENDIF.
  ITAB-PRO1 = ACM1A + ACM1B + ACM1C.
APPEND ITAB2.

ENDLOOP.

Sravya

16 REPLIES 16
Read only

Former Member
0 Likes
1,861

Hi,

Please look at the code below

SORT ITAB BY EQUNR SHIFT.

LOOP AT ITAB WHERE ITAB-EQUNR EQ 'ACM-P-01' OR ITAB-EQUNR EQ 'ACM-P-02' OR ITAB-EQUNR EQ 'ACM-P-03' OR ITAB-EQUNR EQ 'ACM-P-04' OR ITAB-EQUNR EQ 'ACM-P-05' OR ITAB-EQUNR EQ 'ACM-P-06' OR ITAB-EQUNR EQ 'ACM-P-07u2019 OR ITAB-EQUNR EQ 'ACM-P-08' OR ITAB-EQUNR EQ 'ACMA01' OR ITAB-EQUNR EQ 'ACMA02' OR ITAB-EQUNR EQ 'ACMA03'.

IF ITAB-SHIFT = u2018Au2019 OR ITAB-SHIFT = u2018Bu2019 OR ITAB-SHIFT = u2018Cu2019.

ITAB2-PRO1 = ITAB2-PRO1 + ITAB-PRO.

ENDIF.

AT END OF EQUNR.

APPEND ITAB2.

CLEAR ITAB2.

ENDAT.

ENDLOOP.

Hope this will help you.

Regards,

Smart Varghese

Read only

0 Likes
1,861

Hi smartvarghese

actually its a useful answer but i am not getting the sum .

ThankQ

Sravya

Read only

0 Likes
1,861

Hi,

You have to display the sum for each individual machine or for a combination of any of the 11 machines?

Vikranth

Read only

0 Likes
1,861

Hi Vikranth.Reddy

sum of each machine.

Sravya

Read only

0 Likes
1,861

Hi

the code that is give by smartvarghese is ok but here i am getting the sum of all the machines .but i want sum of each machine .



SORT ITAB BY EQUNR SHIFT.
LOOP AT ITAB WHERE EQUNR EQ 'ACM-P-01' OR EQUNR EQ 'ACM-P-02' OR
                   EQUNR EQ 'ACM-P-03' OR EQUNR EQ 'ACM-P-04' OR
                   EQUNR EQ 'ACM-P-05' OR EQUNR EQ 'ACM-P-06' OR
                   EQUNR EQ 'ACMA01' OR EQUNR EQ 'ACMA02' OR EQUNR EQ 'ACMA03'
                   or EQUNR EQ 'ACM-P-07' OR EQUNR EQ 'ACM-P-08'.

IF ITAB-SHIFT = 'A' OR ITAB-SHIFT = 'B' OR ITAB-SHIFT = 'C'.
ITAB2-PRO1 = ITAB2-PRO1 + ITAB-PRO.
ENDIF.

AT END OF shift.
APPEND ITAB2.

ENDAT.

ENDLOOP.

Sravya

Read only

0 Likes
1,861

Hi Sravya,

Just go thorugh the code once more.

Here it is.

SORT ITAB BY EQUNR SHIFT.

LOOP AT ITAB WHERE ITAB-EQUNR EQ 'ACM-P-01' OR ITAB-EQUNR EQ 'ACM-P-02' OR ITAB-EQUNR EQ 'ACM-P-03' OR ITAB-EQUNR EQ 'ACM-P-04' OR ITAB-EQUNR EQ 'ACM-P-05' OR ITAB-EQUNR EQ 'ACM-P-06' OR ITAB-EQUNR EQ 'ACM-P-07u2019 OR ITAB-EQUNR EQ 'ACM-P-08' OR ITAB-EQUNR EQ 'ACMA01' OR ITAB-EQUNR EQ 'ACMA02' OR ITAB-EQUNR EQ 'ACMA03'.

IF ITAB-SHIFT = u2018Au2019 OR ITAB-SHIFT = u2018Bu2019 OR ITAB-SHIFT = u2018Cu2019.

ITAB2-PRO1 = ITAB2-PRO1 + ITAB-PRO.

ENDIF.

AT END OF EQUNR.

APPEND ITAB2. ( Here the new table will be appended)

CLEAR ITAB2. ( Here the sum for each machine will be cleared)

ENDAT.

ENDLOOP.

N.B. Assumption ITAB2 is internal table with headerline.

Regards,

Smart Varghese

Read only

0 Likes
1,861

Hi smartvarghese

i want to get here sum of each machine . and then append it .

but here it is getting shift data and appending . but its doing the sum of all the machines . i think there will be small change where we can get sum according to machine.

Sravya

Read only

0 Likes
1,861

Hello Sravya,

As per the code you have written, the sum will be calculated when the if condition satisfies any of the 11 machines. If you have to calculate the sum for individual machines, you will have to write 11 if conditions.


sort itab by equnr.

loop at itab.
IF ITAB-EQUNR EQ 'ACM-P-01' .
CASE ITAB-SHIFT .
       when  'A'.
        MOVE ITAB-PRO TO  ACM1A.
       when  'B'.
        MOVE ITAB-PRO TO  ACM1B.
       WHEN  'C'.
        MOVE ITAB-PRO TO  ACM1C.
      ENDCASE.
 ITAB2-PRO1 = ACM1A + ACM1B + ACM1C.
APPEND ITAB2.
CLEAR: ACM1A, ACM1B, ACM1C.
  ENDIF.

IF ITAB-EQUNR EQ 'ACM-P-02' .
CASE ITAB-SHIFT .
       when  'A'.
        MOVE ITAB-PRO TO  ACM1A.
       when  'B'.
        MOVE ITAB-PRO TO  ACM1B.
       WHEN  'C'.
        MOVE ITAB-PRO TO  ACM1C.
      ENDCASE.
 ITAB2-PRO1 = ACM1A + ACM1B + ACM1C.
APPEND ITAB2.
CLEAR: ACM1A, ACM1B, ACM1C.
  ENDIF.

.
.
.
.
.
"Until the end of all 11 machines

Vikranth

Read only

0 Likes
1,861

Hi

ya i am aware of that i was trying that i can reduce the code line

thankq

Sravya

Read only

0 Likes
1,861

Hi,

Please check the order of the fields in your internal table.

It should be in the order EQUNR and then SHIFT.

N.B. the first field of the internal table should be EQUNR and second one SHIFT.

If you have a different order for your internal table , the AT END OF will never give the desired or correct result.

Regards,

Smart Varghese

Read only

0 Likes
1,861

I dont think using OR or AND conditions you can reduce the code with the same logic for getting the sum for different machines. if you want to reduce the code lines you can put the case statements which are repititive in a perform and call the form


sort itab by equnr.
 
loop at itab.
IF ITAB-EQUNR EQ 'ACM-P-01' .
perform sum using itab-shift.
 ENDIF.
 
IF ITAB-EQUNR EQ 'ACM-P-02' .
perform sum using itab-shift.
ENDIF.
.
.
.

endloop.

form sum using itab-shift.
CASE ITAB-SHIFT .
       when  'A'.
        MOVE ITAB-PRO TO  ACM1A.
       when  'B'.
        MOVE ITAB-PRO TO  ACM1B.
       WHEN  'C'.
        MOVE ITAB-PRO TO  ACM1C.
      ENDCASE.
 ITAB2-PRO1 = ACM1A + ACM1B + ACM1C.
APPEND ITAB2.
CLEAR: ACM1A, ACM1B, ACM1C.
endform.

Vikranth

Read only

0 Likes
1,861

Hi

it was not the first field there are fileds like date ,time ,equnr,text,dcnr,shift,dur,pro

If any one change the logic also no problem please give your ideas.no need to send according to code existing .

Sravya

Read only

Former Member
0 Likes
1,861

you want to sum the total for all the machines for one shift?

why dont you use collect?

or

sort itab by shift.

loop at itab.
 itab2-total = itab2-total + itab-pro.

 at end of shift.
   itab2-shift = itab-shift.
  append itab2.
 endat.

endloop.

Read only

0 Likes
1,861

Hi Soumyaprakash Mishra

The code which u have give is not working

Thankq i will try it

Read only

venkat_o
Active Contributor
0 Likes
1,861

Hi Sravya, Try this way.



SORT itab BY equnr.
LOOP AT itab  .
  CASE itab-shift .
    WHEN  'A'.
      MOVE itab-pro TO  acm1a.
    WHEN  'B'.
      MOVE itab-pro TO  acm1b.
    WHEN  'C'.
      MOVE itab-pro TO  acm1c.
  ENDCASE.
  itab2-pro1 = acm1a + acm1b + acm1c.
  AT END OF equnr.
    IF ( itab-equnr EQ 'ACM-P-01' ) OR ( itab-equnr EQ 'ACM-P-02' ) OR
       ( itab-equnr EQ 'ACM-P-03' ) OR ( itab-equnr EQ 'ACM-P-04' ) OR
       ( itab-equnr EQ 'ACM-P-05' ) OR ( itab-equnr EQ 'ACM-P-06' ) OR
       ( itab-equnr EQ 'ACM-P-07' ) OR ( itab-equnr EQ 'ACM-P-08' ) OR
       ( itab-equnr EQ 'ACMA01' )   OR ( itab-equnr EQ 'ACMA02' )   OR
       ( itab-equnr EQ 'ACMA03') .
      APPEND itab2.
      CLEAR itab2.
    ENDIF.
  ENDAT.
ENDLOOP.
Thanks Venkat.O

Read only

Former Member
0 Likes
1,861

Hi Sravya,

i guess this code will help

ENDIF.

ITAB-PRO1 = ACM1A + ACM1B + ACM1C + itab-pro1.

modify itab transporting pro1.

clear: itab,

acm1a,

acm1b,

acm1c.

APPEND ITAB2.