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

doubt in using if condition

Former Member
0 Likes
656

<b>Hi i have a got a problem like this in which i have to add the following fields to ED and after that i have to add that filed ED to ED1 and now i have followed the following code by which i'm able to get ED value when JEC1 is not declared but when the JEC1 is declared as below then i'm not able to get the value of ED1 can u suggest me any solution plzzzzz</b>

If KONH-KSCHL=JMOP, then put this value and KONH-KNUMH in KONP-KNUMH, and obtain KONP-KBETR (this is for ED)

Calculate ED as KONP-KBETR/10 * EKPO-NETWR

If KONH-KSCHL=JEC1, then put this value and KONH-KNUMH in KONP-KNUMH, and obtain KONP-KBETR (this is for ECess)

Calculate ED1 as KONP-KBETR/10 * ED

<b>for this conditions i had followed the following steps</b>

LOOP AT JTAB.

concatenate JTAB-werks JTAB-lifnr JTAB-matnr

into val.

SELECT SINGLE KONHKNUMH KONHKSCHL FROM KONH INTO

CORRESPONDING FIELDS OF

KTAB WHERE KONH~VAKEY = VAL .

IF KTAB-KSCHL = 'JMOP' .

.

SELECT SINGLE KONP~KBETR FROM KONP INTO KBTAB WHERE

KONPKNUMH = KTAB-KNUMH AND KONPKSCHL = KTAB-KSCHL

.

ED = KBTAB-KBETR / 10 * JTAB-NETWR .

  • ED1 = KBTAB-KBETR / 10 * ED.

ENDIF.

IF KTAB-KSCHL = 'JEC1' .

SELECT SINGLE KONP~KBETR FROM KONP INTO KBTAB WHERE

KONPKNUMH = KTAB-KNUMH AND KONPKSCHL = KTAB-KSCHL

. ED1 = KBTAB-KBETR / 10 * ED.

ENDIF.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
616

As per your code you would get the value of ED1 as zero since the value of ED has not been calculated. I think try and change the code as below and see if it fits your requirement.

LOOP AT JTAB.

concatenate JTAB-werks JTAB-lifnr JTAB-matnr

into val.

refresh KTAB.

SELECT KONHKNUMH KONHKSCHL FROM KONH INTO

CORRESPONDING FIELDS OF TABLE

KTAB WHERE KONH~VAKEY = VAL .

sort ktab by kschl descending.

Loop at KTAB.

IF KTAB-KSCHL = 'JMOP' .

SELECT SINGLE KONP~KBETR FROM KONP INTO KBTAB WHERE

KONPKNUMH = KTAB-KNUMH AND KONPKSCHL = KTAB-KSCHL.

ED = KBTAB-KBETR / 10 * JTAB-NETWR .

ENDIF.

IF KTAB-KSCHL = 'JEC1' .

SELECT SINGLE KONP~KBETR FROM KONP INTO KBTAB WHERE

KONPKNUMH = KTAB-KNUMH AND KONPKSCHL = KTAB-KSCHL.

ED1 = KBTAB-KBETR / 10 * ED.

ENDIF.

Endloop.

6 REPLIES 6
Read only

Former Member
0 Likes
616

HI,

TRY USING CASE AND ENDCASE .

eg.

case KTAB-KSCHL.

when 'JMOP' .

.

SELECT SINGLE KONP~KBETR FROM KONP INTO KBTAB WHERE

KONP~KNUMH = KTAB-KNUMH AND KONP~KSCHL = KTAB-KSCHL

.

ED = KBTAB-KBETR / 10 * JTAB-NETWR .

  • ED1 = KBTAB-KBETR / 10 * ED.

when 'JEC1' .

SELECT SINGLE KONP~KBETR FROM KONP INTO KBTAB WHERE

KONP~KNUMH = KTAB-KNUMH AND KONP~KSCHL = KTAB-KSCHL

. ED1 = KBTAB-KBETR / 10 * ED.

when ''.

*for null value check.

endcase.

Read only

0 Likes
616

Hi Mr. Vickram

I have tried by using your code even though it was only calculating for ED but not for ED1

Read only

0 Likes
616

Hi pavan,

How would it calculate ED1 when the line is commented out?

  • ED1 = KBTAB-KBETR / 10 * ED.

Read only

0 Likes
616

Hi Mr . Ramana

I think u have seen the upper statement in which i had declared for JMOP in which i had tried to add ED and ED1 at the same time but even though it was not working so i had commented that

Read only

Former Member
0 Likes
617

As per your code you would get the value of ED1 as zero since the value of ED has not been calculated. I think try and change the code as below and see if it fits your requirement.

LOOP AT JTAB.

concatenate JTAB-werks JTAB-lifnr JTAB-matnr

into val.

refresh KTAB.

SELECT KONHKNUMH KONHKSCHL FROM KONH INTO

CORRESPONDING FIELDS OF TABLE

KTAB WHERE KONH~VAKEY = VAL .

sort ktab by kschl descending.

Loop at KTAB.

IF KTAB-KSCHL = 'JMOP' .

SELECT SINGLE KONP~KBETR FROM KONP INTO KBTAB WHERE

KONPKNUMH = KTAB-KNUMH AND KONPKSCHL = KTAB-KSCHL.

ED = KBTAB-KBETR / 10 * JTAB-NETWR .

ENDIF.

IF KTAB-KSCHL = 'JEC1' .

SELECT SINGLE KONP~KBETR FROM KONP INTO KBTAB WHERE

KONPKNUMH = KTAB-KNUMH AND KONPKSCHL = KTAB-KSCHL.

ED1 = KBTAB-KBETR / 10 * ED.

ENDIF.

Endloop.

Read only

Former Member
0 Likes
616

One addition ot this what you can do is use the CHECK statement to find the value of KTAB-KSCHL. Here you can specify whether it is JMOP or JEC1. If it not there it will exit from the loop.