Application Development 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: 

Different logic w/o using AT-New

Former Member
0 Kudos

Hi all,

In the following code i am updating the log version in int_vrson according to recordes found in int_log

The code is runing ok, but i am looking for different logic to perform the same idea with out using AT-New

Sample of data could be retrieved to internal table int_vrson after select statment is done.

nomtk nomit version

1234 10 1

1234 10 2----> should have new version 3 after performing the logic

1234 20 1---->should have new version 2 after performing the logic

1234 30 2---->should have new version 3 after performing the logic

1235 10 1---->should have new version 2 after performing the logic

1235 20 2---->should have new version 3 after performing the logic

data  int_vrson TYPE STANDARD TABLE OF zehs_tkt_log WITH HEADER LINE.
DATA: int_log TYPE STANDARD TABLE OF zehs_tkt_log WITH HEADER LINE.

SELECT *
  FROM zehs_tkt_log
  INTO CORRESPONDING FIELDS OF TABLE int_vrson
  FOR ALL ENTRIES IN int_log
    WHERE nomtk EQ int_log-nomtk AND
          nomit EQ int_log-nomit.

SORT int_vrson BY nomtk nomit version DESCENDING.
  LOOP AT int_log.
    READ TABLE int_vrson WITH KEY nomtk = int_log-nomtk nomit = int_log-nomit.
    IF sy-subrc <> 0.
      int_log-version = 001.
      int_log-idate = sy-datum.
      int_log-itime = sy-uzeit.
      MODIFY int_log.
    ELSE.
      LOOP AT int_vrson WHERE nomtk EQ int_log-nomtk AND
                              nomit EQ int_log-nomit.
        DATA wf_vrs TYPE i.
        wf_vrs = int_vrson-version.
        AT NEW nomit.
          int_vrson-version = wf_vrs .
          IF sy-subrc EQ 0.
            int_log-version = int_vrson-version + 001.
            int_log-idate = sy-datum.
            int_log-itime = sy-uzeit.
            MODIFY int_log.
          ELSE.
            int_log-version = 001.
            int_log-idate = sy-datum.
            int_log-itime = sy-uzeit.
            MODIFY int_log.
          ENDIF.
        ENDAT.
      ENDLOOP.
    ENDIF.
  ENDLOOP.

  MODIFY zehs_tkt_log FROM TABLE int_log.

BR,

Ali

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

If you think of improving performance, better having a look at this nested where clause... You have just read the second table for check, why not using the returned index:


DATA: l_tabix TYPE sytabix.
"...
READ TABLE int_vrson WITH KEY nomtk = int_log-nomtk nomit = int_log-nomit.
IF sy-subrc NE 0.
    "...  
ELSE.
  l_tabix = sy-tabix.
  LOOP AT int_vrson FROM l_tabix. "WHERE nomtk EQ int_log-nomtk AND
                                   "nomit EQ int_log-nomit.
    IF nomtk NE int_log-nomtk AND nomit NE int_log-nomit.    
      EXIT.
    ENDIF.
    "...

Kr,

Manu.

11 REPLIES 11

Former Member
0 Kudos

What is the matter with AT NEW?

(If it's not broken, why fix it?)

Rob

0 Kudos

Is there any alternative solution instead of using AT-New?

0 Kudos

Of course - you can keep track of it programmatically. But why bother? AT NEW works and is efficient.

Rob

0 Kudos

Hhi Rob,

My concern is that, when using SCI it said that as an error.

Program ZER08042 Include ZER842F01 Row 394 Column 0
The LOOP statement processing will be limited
(FROM, TO and WHERE additions in LOOP)
Interaction with group change processing (AT NEW, ...) is undefined
==> The LOOP statement processing will be limited (FROM, TO
and WHERE additions in LOOP) Interaction with group change
processing (AT NEW, ...) is undefined

BR,

Ali

Former Member
0 Kudos

Hi,

If you think of improving performance, better having a look at this nested where clause... You have just read the second table for check, why not using the returned index:


DATA: l_tabix TYPE sytabix.
"...
READ TABLE int_vrson WITH KEY nomtk = int_log-nomtk nomit = int_log-nomit.
IF sy-subrc NE 0.
    "...  
ELSE.
  l_tabix = sy-tabix.
  LOOP AT int_vrson FROM l_tabix. "WHERE nomtk EQ int_log-nomtk AND
                                   "nomit EQ int_log-nomit.
    IF nomtk NE int_log-nomtk AND nomit NE int_log-nomit.    
      EXIT.
    ENDIF.
    "...

Kr,

Manu.

0 Kudos

How is that more efficient?

Rob

0 Kudos

Hi Rob,

Well, parallel cursor is quite famous now isn't it?

http://wiki.sdn.sap.com/wiki/display/Snippets/CopyofABAPCodeforParallelCursor-Loop+Processing

Kr,

Manu.

0 Kudos

It is, but if you check the wiki you quote, you'll see that it uses the binary search option of the READ statement. The snippet you provided doesn't.

And the OP is asking about AT NEW. Without delving into both sets of code, I don't think you're looking at the correct spot.

But since I still don't know what the OP is trying to achieve, it's hard to say.

Rob

0 Kudos

Hi Rob,

May be the control break inside a conditional loop shows a critical error in SLIN check. Considering this case Manu's suggesttion will be his solution.

Also not sure why he has used at new because his loop wiil revolve around the same nomit (nomit EQ int_log-nomit).

@OP - Just remove the at new, there is no need of logic change( Implement the suggestion above if you need a better performance or use sorted internal tables).

Kesav

0 Kudos

Hi Rob,

you'll see that it uses the binary search option of the READ statement. The snippet you provided doesn't.

Well indeed... in fact I would even remove that useless READ statement as well...I was just in a lazy mode when replying...;)

A nested LOOP WHERE can never be optimized in terms of performance... whatever the AT NEW is used or not...

I though all this was about performance enhancement, that is why I proposed this.

Kr,

m.

0 Kudos

> May be the control break inside a conditional loop shows a critical error in SLIN check. Considering this case Manu's suggesttion will be his solution.

And that does appear to be the case. It would have helped non-critical thinkers like me if the OP had mentioned that in the OP.

;-)Rob