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

Loop process

Former Member
0 Likes
817

Hi experts

I have internal table as follows

LEVEL IDNRK VALUE

0 FHETC120210H 0

1 SHETC120210H 0

2 CHETC1202A 0

3 D00110254A 29

4 G1110A 0

5 Y10120NC000 60

1 PLB0033 2

1 PSF5001 0

1 PST0009 20

1 PST0040 23

1 PLD0053 0

1 PCB7130 17

I want to calculate the value of each material.

For example

value of level 0 material ie F = sum of level 1 value

value of level 1 material ie S = value of level 2 * some value.

value of level 2 material ie C = value of level 2 * some value.

How to form the loop and process this.

Thanks in advance.

Regards

Rajaram

7 REPLIES 7
Read only

Former Member
0 Likes
792

Hi experts

I have internal table as follows

LEVEL IDNRK VALUE

0 FHETC120210H 0

1 SHETC120210H 0

2 CHETC1202A 0

3 D00110254A 29

4 G1110A 0

5 Y10120NC000 60

1 PLB0033 2

1 PSF5001 0

1 PST0009 20

1 PST0040 23

1 PLD0053 0

1 PCB7130 17

I want to calculate the value of each material.

For example

value of level 0 material ie F = sum of level 1 values

value of level 1 material ie S = value of level 2 * some value.

value of level 2 material ie C = value of level 3 * some value.

How to form the loop and process this.

Thanks in advance.

Regards

Rajaram

Read only

Former Member
0 Likes
792

Hi,

LOOP AT ITAB.

<b>IF ITAB-LEVEL = 1.

<<u>value</u> of level 0 material ie F = sum of level 1 value>

ELSEIF ITAB-LEVEL = 2.

<<u>value</u> of level 1 material ie S = value of level 2 * some value.>

ELSEIF ITAB-LEVEL = 3.

<<u>value</u> of level 2 material ie C = value of level 2 * some value.>

ENDIF.</b>

ENDLOOP.

Regards,

Pavan

Replace the value in the underlined part by ITAB-VALUE.

Message was edited by:

Pavan Pachimatla

Read only

Former Member
0 Likes
792

Hi Raja

U r query is not clear can u throw some more explanataion.

Regards,

kiran.M

Read only

0 Likes
792

have internal table as follows

LEVEL IDNRK VALUE

0 FHETC120210H 0

1 SHETC120210H 4

2 CHETC1202A 13

3 D00110254A 29

4 G1110A 0

5 Y10120NC000 60

1 PLB0033 2

1 PSF5001 0

1 PST0009 20

1 PST0040 23

1 PLD0053 0

1 PCB7130 17

I want to calculate the value of each material.

For example

value of level 0 material ie F = sum of level 1 values

value of level 1 material ie S = value of level 2 * some value.

value of level 2 material ie C = value of level 3 * some value.

How to form the loop and process this.

Thanks in advance.

Regards

Rajaram

Read only

former_member189059
Active Contributor
0 Likes
792

See this code, i think your requirement is almost the same

TYPES: BEGIN OF itab_type,
  name,
  num TYPE i,
  flag,
 END OF itab_type.

DATA: itab TYPE itab_type OCCURS 0.
DATA: itab_wa1 LIKE LINE OF itab.
DATA: itab_wa2 LIKE LINE OF itab.

itab_wa1-name = 'A'.
itab_wa1-num = 10.
APPEND itab_wa1 TO itab.
itab_wa1-name = 'D'.
itab_wa1-num = 20.
APPEND itab_wa1 TO itab.
itab_wa1-name = 'B'.
itab_wa1-num = 10.
APPEND itab_wa1 TO itab.
itab_wa1-name = 'D'.
itab_wa1-num = 30.
APPEND itab_wa1 TO itab.
itab_wa1-name = 'A'.
itab_wa1-num = 40.
APPEND itab_wa1 TO itab.
itab_wa1-name = 'E'.
itab_wa1-num = 20.
APPEND itab_wa1 TO itab.

SORT itab BY name.

DATA: lv_tabix LIKE sy-tabix.
DATA: total TYPE i.
DATA: subtotal TYPE i.

LOOP AT itab INTO itab_wa1 WHERE flag = ''.
  WRITE:/ itab_wa1-name , itab_wa1-num.
  lv_tabix = sy-tabix + 1.
  subtotal = itab_wa1-num..
  LOOP AT itab INTO itab_wa2 FROM lv_tabix WHERE name = itab_wa1-name.
    subtotal = subtotal + itab_wa2-num.
    WRITE:/  itab_wa2-num.
    itab_wa2-flag = 'X'.
    MODIFY itab FROM itab_wa2.
  ENDLOOP.
  IF sy-subrc = 0.
    WRITE:/ 'subtotal = ' , subtotal.
  ENDIF.
  total = total + subtotal.
ENDLOOP.
WRITE:/ 'total = ' , total.

Read only

Former Member
0 Likes
792

Hi Raja Ram,

You can use the following AT NEW itab-field1/ON change of evaents between loop ....endloop.

LOOP AT ITAB.

AT NEW ITAB-F1.

SUM.

write:

/ itab-f1.

ENDAT.

ENDLOOP.

Regards,

Rama chary.Pammi

Read only

0 Likes
792

no some of the values i have to do multiplication operation also.