Skip to Content
author's profile photo
Former Member

regarding at new

sort it_po by ebeln ebelp matnr.

loop at it_po.

at new ebeln.

at new ebelp.

at new matnr.

sum.

write:/ it_po-menge.

write:/ it_po-ebeln,it_po-ebelp,it_po-matnr.

endat.

endat.

endat.

endloop.

in the above code i have to sum for each new value of material for each line item for each purchase order.

Thanx in advance

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

3 Answers

  • Posted on Jul 27, 2004 at 12:09 PM

    Hi,

    1)I'd try to change the programm and would use

    function 'REUSE_ALV_GRID_DISPLAY'

    (here's a link with ext. example)

    http://www.abapforum.com/forum/viewtopic.php?t=1544

    or

    2) correct your coding

    I think you want to sum the field matnr:

    so you must redefine your table

    data : begin of it_po...

    matnr,

    ebeln,

    ebelp,

    ...

    sort it_po.

    loop at it_po.

    write:/ it_po-matnr,it_po-ebeln,it_po-ebelp, it_po-menge.

    at end of matnr.

    write:/'Total', it_po-menge under it_po-menge.

    endat.

    endloop.

    grx Andreas

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Well you are right with saying that matnr should be the first field.what about the new occurence of ebeln and ebelp being displayed?

  • author's profile photo
    Former Member
    Posted on Jul 27, 2004 at 12:35 PM

    If you can change the table let it have this structure

    begin of it_po,

    ebeln,

    ebelp,

    matnr,

    ..

    ..

    end of it_po.

    LOOP AT it_po.

    sum.

    at end of matnr.

    write : /it_po-menge,

    /it_po-ebeln, it_po-ebelp, it_po-matnr.

    endat.

    ENDLOOP.

    Add comment
    10|10000 characters needed characters exceeded

    • Hello all and Pavan Lanka

      In Paven's ex. the sum command is put in a wrong place. The code should be:

      LOOP AT it_po.

      at end of matnr.

      sum.

      write : /it_po-menge,

      /it_po-ebeln, it_po-ebelp, it_po-matnr.

      endat.

      ENDLOOP.

      Best regards

      Thomas Madsen Nielsen

  • Posted on Jul 27, 2004 at 06:39 PM

    Hi!

    Will this be a more feasible code?

    ==>

    data: lv_new .

    data: begin of it_po,

    ebeln,

    ebelp,

    matnr,

    ..

    ..

    end of it_po.

    SORT it_po by ebeln ebelp matnr .

    LOOP AT it_po.

    clear lv_new .

    at end of matnr.

    lv_new = 'X' .

    endat.

    ...

    if lv_new = 'X' .

    ...

    sum.

    write : /it_po-menge,

    /it_po-ebeln, it_po-ebelp, it_po-matnr.

    ...

    endif .

    ...

    ENDLOOP.

    Srikar, "AT NEW X", is a control level processing statement, it will be triggered when any of the fields left to X (here: ebeln, ebelp) or X itself is changed. But between "AT NEW X" and "ENDAT" the fields right to X in the header of it_po

    will contain just ' * 's and it is restored after "ENDAT".

    *--Serdar

    Add comment
    10|10000 characters needed characters exceeded

    • Hello

      I agree with Anjaiah Surgi that some things in this question do not make sense.

      Anyway I would like to explain why nested AT NEW commands are not necesary.

      SAP's documentation is a little cryptic talking about a control level key without explaining what that is.

      The control level key is a key concatenated from the field in the control break command (at new) and all fields from the record structure before this field.

      This is also a little cryptic so here is an example.

      data : begin of it_po,

      ebeln,

      ebelp,

      matnr,

      menge,

      end of it_po.

      ....

      at new MATNR

      .....

      ENDAT

      Here the control level key is ebelnebelpmatnr

      I think this example is what you try to obtain when you write:

      at new ebeln.

      at new ebelp.

      at new matnr.

      .....

      endat.

      endat.

      endat.

      From SAP's documentation:

      The control level structure with internal tables is static. It corresponds exactly to the sequence of columns in the internal table (from left to right). In this context, the criteria according to which you sort the internal table are unimportant.

      At the start of a new control level, the following occurs in the output area of the current LOOP statement:

      - All character type fields (on the right) are filled with "*" after the current control level key.

      - All other fields (on the right) are set to their initial values after the current control level key.

      I hope this helps a little. When you know how control break commands work you will find it easy. Its just difficult to explain in few words.

      Best regards

      Thomas Madsen Nielsen