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

help in the abap code

Former Member
0 Likes
2,333

hi folks,

I am checking for various condition types through this code for various orders. Each order has a different set of condition records.

My requirement: when a order has a condition record for the condition type 'ZAGR' (AGREED PRICE) it should execute that block and ignore all the other condition types for that record and directly go to 'ZBET'to fetch the final amount

How to incorporate that piece code here?

The code goes like this...

loop at cdata into zcdata where

knumv = bodyitabtotal-knumv.

case zcdata-kschl.

when 'ZRAT' OR 'ZFLE' OR 'ZRCR' OR 'ZFIX'.

.

.

.

when 'ZAGR'.

.

.

.

when 'ZONT'.

concatenate zzkeyword zpofield

into CTEXT3

separated by space

MOVE zcdata-kbetr to w_accitab-zrate.

MOVE zcdata-kwert to w_accitab-zsubtotal.

.

.

.

when 'ZSMG'.

.

.

.

when 'ZBET'.

if zcdata-kbetr = ' ' AND zcdata-kwert = ' '.

MOVE ' ' TO w_accitab-zamount.

ELSE.

MOVE zcdata-kwert to w_accitab-zamount.

ENDIF.

when others.

continue.

endcase.

Thanks

Santhosh

18 REPLIES 18
Read only

Former Member
0 Likes
2,187

Hi

First option:

You prepare ne ITab and fill all the records with condition type ZBET. Read the itab in each condition type statements for the final amount.

Second option:

Set a flag to 'X' when ever condition record found. then execute the ZBET only when the flag is 'X'. startign of the case statement the flag will be clear for the order.

so for every condition record add the check if flad is initial. so ass soon as it encounters the first condition record...the next is ZBET is executed.

Hope this helps

Thanks

Balu

Read only

0 Likes
2,187

slight correction.... it should ignore 'ZBET' too. i.e when it encounters any data in the 'ZAGR' condition type it should exit from the loop.

Sorry abt that..

Santhosh

Read only

Former Member
0 Likes
2,187

Hi

so your reqirement is:

you have orders with multiple condition records. When you program loop encounters the ZAGR condition it should only process that condtion for the order and exit from the loop and proceed with other order....and what ever condition records exceuted prior to ZAGR they will stay..

When ZAGR is executed.. ZBET shouldnot be executed...ZBET should execute only for other condition types..is this your requirement??

I need more clarity on your requirement.

Thanks

Balu

Read only

Former Member
0 Likes
2,187

hi

Further to previous reply.. you can set a flag in ZAGR to 'X' and check that in ZBET if the flag is initial then process other wise donot process.

Clear the flag at new order.

This will work

Thanks

Balu

Read only

0 Likes
2,187

This code will exit the loop completly.

when 'ZAGR'.
EXIT.

This code will exit the current loop and continue to the next record for processing.

when 'ZAGR'.
CONTINUE.

Regards,

Rich HEilman

Read only

0 Likes
2,187

Thanks Balu, It really helped. The idea is good. But I have an situation in the condition table where I fetch the records.

There is a record for the condition type ' ZONT' i.e 'online price ' before the 'ZAGR' how to manage it here?

For the condition type 'ZBET' it works before in the condition table the record for 'ZBET' comes after 'ZAGR' but there are condition types that have records before ''ZAGR'.

How to go about it?

Thanks

Santhosh

Read only

0 Likes
2,187

I cannot use ' EXIT' because I have to append the data the itable within the loop every time it runs. I cannot 'exit' from loop.

Santhosh

Read only

0 Likes
2,187

You wrote....

<i>slight correction.... it should ignore 'ZBET' too. i.e when it encounters any data in the 'ZAGR' condition type it should exit from the loop.</i>

So my question is, what is your requirement exactly.

Regards,

Rich Heilman

Read only

0 Likes
2,187

Sorry for the confusion.

Requirement: I am looping through the internal table that has the records for various condition types from KONV. The focal point is ' ZAGR' condition type, but this is not the first record in KONV there are records pertained to other condition types before 'ZAGR' like 'ZONT' and few more after 'ZAGR' like 'ZBET'

while looping through the records if an order has an arecord for 'ZAGR' means that the order has been set for an flat rate of agreed price and all the other condition types for that record is not required because it is a flat rate - but there may be records for other condition types for the same order and I should not pick up that data for the order because it is a flat rate.Therefore I should skip all the other condition types.

Like Balu suggessted I used a flag and with the help of it I was succeeded in getting rid of all the condition types that come after ZAGR on the KONV table but there are condtion types like 'ZONT' that are populated befroe 'ZAGR' in the KONV table.

So when the data is fetched and looped it pikcs up the data for 'ZONT' because it is prior to 'ZAGR' in the table.

I have to avoid it.

I hope I have explained my requirement clearly.

Thanks

Santhosh

Read only

0 Likes
2,186

Now I think I understand......




* Check cdata for a ZAGR entry, if there is one, just process that 
* record, othewise do your loop.
read table cdata into zcdata with key kschl = 'ZAGR'.
if sy-subrc  = 0.

* Then do what ever you need to do

else.
* Otherwise process the table as normal.

  loop at cdata into zcdata
           where knumv = bodyitabtotal-knumv.

    case zcdata-kschl.
      when 'ZRAT' or 'ZFLE' or 'ZRCR' or 'ZFIX'.

      when 'ZAGR'.

      when 'ZONT'.
        concatenate zzkeyword zpofield
        into ctext3
        separated by space
        move zcdata-kbetr to w_accitab-zrate.
        move zcdata-kwert to w_accitab-zsubtotal.

      when 'ZSMG'.

      when 'ZBET'.
        if zcdata-kbetr = ' ' and zcdata-kwert = ' '.
          move ' ' to w_accitab-zamount.
        else.
          move zcdata-kwert to w_accitab-zamount.
        endif.
      when others.
        continue.
    endcase.

  endloop.

endif.


Regards,

Rich Heilman

Read only

0 Likes
2,186

Rich,

I need the 'knumv' to be checked too because it is unique to each order, and I am running this within a loop.

The format of the code goes like this...

select distinct ...... into table bodyitab1(internal table)

*fetching all the information of the sales orders into the table

insert lines of bodyitab1 into table bodyitabtotal.

.

.

loop at bodyitabtotal

.

.

.

  • reading all the data into various variables and reading into 'w_accitab'

select knumv kschl kbetr kwert kinak

from konv into table cdata for all entries in

bodyitabtotal where konv~knumv = bodyitabtotal-knumv

.

.

*fetching the rates, amounts, for each sales order based on 'knumv' and checking for the condition types

loop at cdata into zcdata where knumv = bodyitabtotal-knumv.

case zcdata-kschl.

when 'ZAGR'.

.

.

.

append w_accitab to accitab.

clear accitab-zamount.

clear accitab.

clear w_accitab.

endloop.

endif.

endloop.

here the loop ends and this completes the cycle for one order

so when I use the read statement it has to check for 'ZAGR' for that order only but if you see the query

cdata' has the condition records for all entries in 'bodyitabtotal' because all orders do not have 'ZAGR' condition type

I hope you understand the flow of the program.

thanks

Santhosh

Read only

0 Likes
2,186

Hi Santhosh,

Is this how it looks.


LOOP AT bodyitabtotal.
*-- select all condition records from konv for the 
*   currect order in the loop into internal table
  REFRESH cdata.
  SELECT knumv kschl kbetr kwert kinak
    FROM konv 
    INTO TABLE cdata 
   WHERE knumv = bodyitabtotal-knumv.
  READ TABLE cdata INTO zcdata 
               WITH KEY kschl = 'ZAGR'.
  IF sy-subrc = 0.
*-- ZAGR condition type exists for this order
  ELSE.
    LOOP AT cdata INTO zcdata.
*-- do processing of all other condition types
    ENDLOOP.
  ENDIF.
ENDLOOP.

Remember, in your code, you are in the loop of 'bodyitabtotal' and then in your 'select from konv', you are doing a 'for all entries in bodyitabtotal'. This is wrong because you only want the condition records of the current order not all orders.

Hope this is clear.

Srinivas

Read only

0 Likes
2,186

Ok, how about this.




<b>read table cdata into zcdata with key 
                 knumv = bodyitabtotal-knumv
                 kschl = 'ZAGR'.</b>
if sy-subrc  = 0.
 
* Then do what ever you need to do
 
else.
* Otherwise process the table as normal.
 
  loop at cdata into zcdata
           where knumv = bodyitabtotal-knumv.


Regards,

Rich Heilman

Read only

0 Likes
2,186

Rich,

Coming closer...

Here is my latest code....

loop at cdata into zcdata where knumv = bodyitabtotal-knumv.

zzconditionnumber = bodyitabtotal-knumv.

read table cdata into zcdata

with key knumv = zzconditionnumber

kschl = 'ZAGR'.

if sy-subrc = 0.

CTEXT3 = 'AGREED PRICE'.

MOVE zcdata-kbetr to w_accitab-zrate.

MOVE zcdata-kwert to w_accitab-zamount.

???????

else.

case zcdata-kschl.

.

.

.

.

when others.

continue.

endcase.

MOVE CTEXT3 to w_accitab-zdescription.

CLEAR CTEXT3.

append w_accitab to accitab.

clear accitab.

clear w_accitab.

endif.

endloop.

endloop.

My question is when it finds a record for 'ZAGR' I read the data into the work area and has to exit the case.... endcase statement and process the

statement

MOVE CTEXT3 ....

How can I do it? How can I get out of the case... endcase statement and not the loop.

Thanks

Santhosh

Read only

0 Likes
2,186

Santhosh,

I am not sure why you are reading the same internal table while looping at the same. You don't have to do that. Just change it like this.


LOOP AT cdata INTO zcdata 
             WHERE knumv = bodyitabtotal-knumv.
  IF zcdata-kschl = 'ZAGR'.
    CTEXT3 = 'AGREED PRICE'.
    MOVE zcdata-kbetr to w_accitab-zrate.
    MOVE zcdata-kwert to w_accitab-zamount.
  ELSE.
    CASE zcdata-kschl.
      WHEN 'ABCD'.
        ....
        ....
      WHEN OTHERS.
    ENDCASE.
  ENDIF.
  MOVE CTEXT3 to w_accitab-zdescription.
  CLEAR CTEXT3.
  APPEND w_accitab TO accitab.
  CLEAR accitab.
  CLEAR w_accitab.
ENDLOOP.

Hope you read my previous post.

Srinivas

Read only

0 Likes
2,186

You said that if there is a ZAGR, you only want that record, right? You need to do a READ for that condition type first, if you got one, just process that record, if you don't have one, the LOOP and process as you were before.




* Read the cDATA table first to see if there is a ZAGR, if there is
* you only want that record, correct?  If SY-SUBRC = 0,  then do 
* what ever you need to do when you have a ZAGR.

<b>read table cdata into zcdata with key
                 knumv = bodyitabtotal-knumv
                 kschl = 'ZAGR'.</b>

<b>if sy-subrc  = 0.</b>

  ctext3 = 'AGREED PRICE'.
  move zcdata-kbetr to w_accitab-zrate.
  move zcdata-kwert to w_accitab-zamount.

<b>else.</b>
* Otherwise loop at the Cdata table and process as normal.

<b>  loop at cdata into zcdata
           where knumv = bodyitabtotal-knumv.</b>

    case zcdata-kschl.
      when 'ZRAT' or 'ZFLE' or 'ZRCR' or 'ZFIX'.


      when 'ZONT'.
        concatenate zzkeyword zpofield
        into ctext3
        separated by space
        move zcdata-kbetr to w_accitab-zrate.
        move zcdata-kwert to w_accitab-zsubtotal.

      when 'ZSMG'.

      when 'ZBET'.
        if zcdata-kbetr = ' ' and zcdata-kwert = ' '.
          move ' ' to w_accitab-zamount.
        else.
          move zcdata-kwert to w_accitab-zamount.
        endif.
      when others.
        continue.
    endcase.

<b>  endloop.</b>

endif.

Regards,

Rich HEilman

Read only

0 Likes
2,186

Please reward and close the issue if this is resolved.

Read only

Former Member
0 Likes
2,186

Hi,

Sort the ITab with KNUMV and KSCHL... this case the ZAGR excutes first....if no other condition rec starts with ZA..

this is may not be right solution but according to your condition records...this should work....

Thanks

balu