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: 

At New Field and At End of Field not working

Former Member
0 Kudos

Dear Experts,

Please have a look on the below code and advice me what wen wrong as

at new and at end of statement not working, please advice.

LOOP AT I_FINAL INTO S_FINAL.

    AT NEW KUNRG.
      SELECT NAME1 FROM KNA1 INTO S_NAME WHERE KUNNR = S_FINAL-KUNRG.
      ENDSELECT.
      SKIP.
 WRITE :/10 'Customer Name :', S_NAME,
            'Code :         ', S_FINAL-KUNRG.
      WRITE :/10 'For the period from ', S_DATE-LOW,
                ' To ', S_DATE-HIGH.
      SKIP.
      WRITE AT 5(95) SY-ULINE.
      SKIP.
      WRITE :/10 'Serial',
              20 'Billing',
              32 'Invoice',
              46 'Invoice',
              66 'Invoice'.
      WRITE :/10 '  No. ',
              20 '  No.  ',
              32 'Number',
              46 ' Date  ',
              66 'Amount '.
      SKIP.
      WRITE AT 5(95) SY-ULINE.
      G_SI_NUM = 0.
    ENDAT.


    G_SI_NUM = G_SI_NUM + 1.

    WRITE: /05 G_SI_NUM,
            17 S_FINAL-VBELN,
            29 S_FINAL-EXNUM NO-ZERO,
            43 S_FINAL-FKDAT,
            55 S_FINAL-NETWR RIGHT-JUSTIFIED.

    SKIP.
    AT END OF KUNRG.
      SUM.
      WRITE AT 5(95) SY-ULINE.
      WRITE :/17 'Total',
              55 S_FINAL-NETWR  RIGHT-JUSTIFIED.
      SKIP.
      WRITE AT 5(95) SY-ULINE.
    ENDAT.

  ENDLOOP.

Its calculating every single vbeln as new field and taking the total for each vbeln

but I need total for each ( Kunrg ) Customer.

Please advice

Karthik

1 ACCEPTED SOLUTION

andreas_mann3
Active Contributor
0 Kudos

your itab must be defined as follows:

data: begin of S_FINAL occurs 0,

kunrg type kna1-kunnr,

VBELN type bseg-VBELN,

....

A.

6 REPLIES 6

Former Member
0 Kudos

Hi,

data : sum1 type vbrk-NETWR.

LOOP AT I_FINAL INTO S_FINAL.

AT NEW KUNRG.

SELECT NAME1 FROM KNA1 INTO S_NAME WHERE KUNNR = S_FINAL-KUNRG.

ENDSELECT.

SKIP.

WRITE :/10 'Customer Name :', S_NAME,

'Code : ', S_FINAL-KUNRG.

WRITE :/10 'For the period from ', S_DATE-LOW,

' To ', S_DATE-HIGH.

SKIP.

WRITE AT 5(95) SY-ULINE.

SKIP.

WRITE :/10 'Serial',

20 'Billing',

32 'Invoice',

46 'Invoice',

66 'Invoice'.

WRITE :/10 ' No. ',

20 ' No. ',

32 'Number',

46 ' Date ',

66 'Amount '.

SKIP.

WRITE AT 5(95) SY-ULINE.

G_SI_NUM = 0.

ENDAT.

G_SI_NUM = G_SI_NUM + 1.

WRITE: /05 G_SI_NUM,

17 S_FINAL-VBELN,

29 S_FINAL-EXNUM NO-ZERO,

43 S_FINAL-FKDAT,

55 S_FINAL-NETWR RIGHT-JUSTIFIED.

SKIP.

sum1 = sum1 + S_FINAL-NETWR .

AT END OF KUNRG.

WRITE AT 5(95) SY-ULINE.

WRITE :/17 'Total',

55 sum1 RIGHT-JUSTIFIED.

SKIP.

WRITE AT 5(95) SY-ULINE.

clear sum1.

ENDAT.

ENDLOOP.

Former Member
0 Kudos

I_FINAL is sorted by KUNRG?

0 Kudos

yes, I have already sorted it

andreas_mann3
Active Contributor
0 Kudos

your itab must be defined as follows:

data: begin of S_FINAL occurs 0,

kunrg type kna1-kunnr,

VBELN type bseg-VBELN,

....

A.

0 Kudos

Wow....its working fine now !!

Thank u , please can u adivce me what is the logic behind this !!

0 Kudos

Hi Karthik,

The logic behid this is,

When you declare a Internal table and you are using it for subsequent statemnets like At new and At end.

The fileds should be in a order i.e first field should be repeated for other line items.and if the combination breaks then the pointers goes into At new.

A B C

1 1 2

1 1 2

1 2 2

1 2 3

2 1 2

AT NEW <FIELD>

fn1..

ENDAT

When I say At new of 'A' then fn1 execute at line 5 -Only depends on First field

When I say At new of 'B' then fn1 execute at line 3 and line 5 -Depends on FIrst field and Second Field

When I say At new of 'C' then fn1 execute at line 3 ,4 and line 5 -Depends on First ,Second and Third Field

Hope this helps.

Regards,

Amit Teja Vutpala