Skip to Content
author's profile photo Former Member
Former Member

How to find the max value among line items in an internal table

hi,

I have an internal table with so many documents and each document having so many line items, now i want to find the highest amount among the line items for each document and i want to change the highest value containing line item.

eg : my INT Table is like this

doc A

line item 1.

line item 2.

doc B

line item 1.

line item 2.

line item 3.

doc C

line item 1.

line item 2.

line item 3.

line item 4.

Document wise i want to find out the highest value containing line item& i want to deduct some amount from that.

Kindly sujjest me ......

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

5 Answers

  • Posted on Jan 05, 2014 at 04:48 AM

    Hi

    Sort INT by <DOC> <Line Item>.

    DELETE ADJACENT DUPLICATE FROM INT COMPARING DOC.

    Hope it helps.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 05, 2014 at 05:01 AM

    HI Lokesh.

    If you want these values in another table for processing later, we will create an internal table for that, or we will implement the processing (of deducting the value) in that loop itself.

    begin of ty_final,

    bukrs type bukrs,

    belnr type belnr,

    gjahr type gjahr,

    buzei type buzei

    dmbtr type dmbtr,

    end of ty_final.

    data it_Final type table of ty_final. "Required only if you want to collect all the details to a table.

    data : wa_final type ty_final.

    sort itab by bukrs belnr gjahr buzei.

    clear wa_final.

    loop at itab into wa_tab.

    if wa_tab-dmbtr GT wa_final-dmbtr.

    move corresponding wa_tab to wa_final

    endif.

    at end of belnr.

    append wa_final to it_final. "Required only if you want to collect all the details to a table.

    * If you can do the processing here itself, no need to append to the internal table

    * Just do the deductions / calculations with the values in wa_final.

    clear wa_final.

    endat.

    endloop.

    Another option would be just to sort and do the calculations with the first line. for each belnr.

    sort itab by bukrs belnr gjahr dmbtr descending.

    loop at itab into wa_itab.

    at new belnr.

    *wa_itab will have the line item with maximum amount. Do your processing as required. Either append to another table or perform calculations with the values.

    endat.

    endloop.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 05, 2014 at 05:09 AM

    Hi Lokesh

    sort int by doc amount descending.

    Loop at int into wa.

    at new doc.

    **Do operations ...

    endat.

    endloop.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 05, 2014 at 05:40 AM

    Hi Lokesh,

    Simply do this way!

    Try this example!

    TYPES: BEGIN OF ty_ekpo,
    ebeln TYPE ebeln,
    ebelp TYPE ebelp,
    netwr TYPE ekpo-netwr,
    END OF ty_ekpo.


    DATA: it_ekpo TYPE STANDARD TABLE OF ty_ekpo,
    it_ekpo_max TYPE STANDARD TABLE OF ty_ekpo..


    SELECT ebeln ebelp netwr FROM ekpo
    INTO TABLE it_ekpo
    UP TO 10 ROWS.

    SORT it_ekpo[] by ebeln netwr DESCENDING.
    it_ekpo_max[] = it_ekpo[].

    delete ADJACENT DUPLICATES FROM it_ekpo_max[] COMPARING ebeln.

    * so it_ekpo[] - having the original records with all items
    * it_ekpo_max[] - will have only items having the maximum price values
    * DO THE calculation by looping it_ekpo and reading with it_ekpo_max



    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 05, 2014 at 03:50 PM

    Hi lokesh,

    all the people just triing to say:

    Sort your table in a wise, you got your entry in the first or in the last line and use the READ TABLE statement.

    If you need more informations please read trough the official SAP-Helpsite:

    Sorting Internal Tables (SAP Library - ABAP Programming (BC-ABA))

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.