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

calculation in internal table

Former Member
0 Likes
862

SELECT

        KONV~KNUMV

        konv~kposn

        konv~kschl

        konv~kbetr as kbetr2

into  CORRESPONDING FIELDS OF TABLE it_display3 from konv

for ALL ENTRIES IN it_display where

               konv~knumv = it_display-knumv AND

               konv~kschl = 'ZCAS'.

LOOP AT it_display.

READ TABLE it_display3 WITH KEY knumv = it_display-knumv . ( You also need to match the KPOSN )

IF sy-subrc = 0.

       it_display-kbetr2 = ( it_display3-kbetr2 / 10 ).

MODIFY it_display.

ENDIF.

ENDLOOP.

I have created another select statement for pr00 as in the above manner.

i wanted to do konv~kschl = PR00 - konv~kschl=ZCAS (PR00 - ZCAS). how to write . I wanted knumv in the selection parameter for this . data should populate based on the selection parameter



1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
824

Hi,

You can use the following statement.

SELECT

        KONV~KNUMV

        konv~kposn

        konv~kschl

        konv~kbetr as kbetr2

into  CORRESPONDING FIELDS OF TABLE it_display3 from konv

for ALL ENTRIES IN it_display where

               konv~knumv = it_display-knumv AND

               konv~kschl  IN ('ZCAS','PR00').

lets take 2 variable V_ZCAS and Z_PR00

in order for calculation you can do the following.

loop at it_display.


read it_display3 with key Knumv = it_display-knumv and kposn = it_display-kposn and kschl = 'ZCAS'.

if sy-subrc = 0.

add the value of 'ZCAS'

V_ZCAS = it_display3-kbetr / 10 .

endif.

clear it_display3. ( Should clear the work area )

read it_display3 with key Knumv = it_display-knumv and kposn = it_display-kposn and kschl = 'PR00'.

if sy-subrc = 0.

add the value of 'PR00'

V_PR00 = it_display3-kbetr / 10 .

endif.

clear it_display3. ( Should clear the work area )

total = Z_PR00 - V_ZCAS.

endloop.

Regards,

Rahul Singh

Now you can close this thread .....

6 REPLIES 6
Read only

Former Member
0 Likes
824

Hi,

I am combining the select for both ZCAS and PR00 conditions in the below query.

SELECT

        KONV~KNUMV

        konv~kposn

        konv~kschl

        konv~kbetr as kbetr2

into  CORRESPONDING FIELDS OF TABLE it_display3 from konv

for ALL ENTRIES IN it_display where

               konv~knumv = it_display-knumv AND

               ( konv~kschl = 'ZCAS'

                 or KONV~kschl = 'PR00').

sort it_display3 by kschl.

it_display4[] = it_display3[].

delete it_display3 where kschl NE 'ZCAS'. " This internal table will have only ZCAS

delete it_display4 where kschl NE 'PR00'. " This internal table will have only PR00

LOOP AT it_display.

* ZCAS value

READ TABLE it_display3 WITH KEY knumv = it_display-knumv . ( You also need to match the KPOSN )

IF sy-subrc = 0.

       lv_kbetr1 = ( it_display3-kbetr2 / 10 ).

ENDIF.

*PR00 value

READ TABLE it_display4 WITH KEY knumv = it_display-knumv . ( You also need to match the KPOSN )

IF sy-subrc = 0.

       lv_kbetr2 = ( it_display4-kbetr2 / 10 ).

ENDIF.

lv_kbetr3 = lv_kbetr2 - lv_kbetr1. " PR00 minus ZCAS

*lv_kbetr3 will have the value for PR00 minus ZCAS

ENDLOOP.

Cheers

~Niranjan

Read only

Former Member
0 Likes
825

Hi,

You can use the following statement.

SELECT

        KONV~KNUMV

        konv~kposn

        konv~kschl

        konv~kbetr as kbetr2

into  CORRESPONDING FIELDS OF TABLE it_display3 from konv

for ALL ENTRIES IN it_display where

               konv~knumv = it_display-knumv AND

               konv~kschl  IN ('ZCAS','PR00').

lets take 2 variable V_ZCAS and Z_PR00

in order for calculation you can do the following.

loop at it_display.


read it_display3 with key Knumv = it_display-knumv and kposn = it_display-kposn and kschl = 'ZCAS'.

if sy-subrc = 0.

add the value of 'ZCAS'

V_ZCAS = it_display3-kbetr / 10 .

endif.

clear it_display3. ( Should clear the work area )

read it_display3 with key Knumv = it_display-knumv and kposn = it_display-kposn and kschl = 'PR00'.

if sy-subrc = 0.

add the value of 'PR00'

V_PR00 = it_display3-kbetr / 10 .

endif.

clear it_display3. ( Should clear the work area )

total = Z_PR00 - V_ZCAS.

endloop.

Regards,

Rahul Singh

Now you can close this thread .....

Read only

0 Likes
824

I tried this code and it is not working for me.

Read only

Former Member
0 Likes
824

Hi,

You can try this statement:

SELECT

        KONV~KNUMV

        konv~kposn

        konv~kschl

        konv~kbetr as kbetr2

into  CORRESPONDING FIELDS OF TABLE it_display3 from konv

for ALL ENTRIES IN it_display where

               konv~knumv = it_display-knumv AND

               konv~kschl IN ('ZCAS','PR00').

LOOP AT it_display.

READ TABLE it_display3 WITH KEY knumv = it_display-knumv .

IF sy-subrc = 0.

* ZCAS value

if t_display3-kschl = 'ZCAS'.

       lv_kbetr = ( it_display3-kbetr2 / 10 ).

ELSE.

*PR00 value

        lv_kbetr = ( it_display3-kbetr2 / 10 ).

ENDIF.

if lv_kbetr is not initial.

it_display-kbetr2 =   lv_kbetr.

MODIFY it_display.

endif.

ENDIF.

ENDLOOP.

Read only

0 Likes
824

Akash check your code once again.

Read only

0 Likes
824

Thanks for the correction...