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

Get Latest Condition Record

Hi Experts,

I have a requirement to get the latest condition record given a material and a particular month.

How do I code this?

Any help will is greatly appreciated.

Thanks,

Jay

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

5 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jul 07, 2009 at 01:41 AM

    Hi,

    You can try to select single that table with condition descending by date. It's automatically get the last record.

    Regards.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      hi,

      Suppose you have a condition record table A853 with fields MATNR KBETR.

      declare an internal table with same structure.

      data : begin of i_a853 occurs 0,

      matnr like a853-matnr,

      kbetr like a853-kbetr,

      datab like a853-datab,

      end of i_a853

      write query for all the fields to pass data into I_A853.

      select matnr kbetr from a853

      into i_a853

      where matnr = s_matnr. (Say s_matnr is your selection variable)

      if not i_a853[] is initial.

      sort i_a853 by datab descending.

      endif.

      now if you read i_a853 with index 1, you will get the latest records against the material.

      Regds,

      Anil

  • author's profile photo Former Member
    Former Member
    Posted on Jul 14, 2009 at 10:21 AM

    Hi ,

    just use select endselect statements for that.

    select

    endselect.

    you will get the last record in the selection.

    Please let me know if you still need any more help.

    Thanks and regards.

    Rajeshwar

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 14, 2009 at 09:43 AM

    Hi

    Given below parameters:

    PA-BUMON: 05/2009

    PA-MTART: FERT

    Now, I wanted to get all the latest condition record (KBETR) of Materials with mtyp FERT given validity period of May 2009 (from May 1 - 31) and also display the last condition record of the previous month May which is April 2009. Condition record depends on the month(PA-BUMON) that is key in.

    Can you help me how to do so?

    Thank you experts!

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 14, 2009 at 10:16 AM

    Hi,

    Suppose your condition table is A017, and for material vendor purc org and plant combination you want to fetch latest condition record number. Please check the sample code-:

    TYPES: BEGIN OF t_a017,

    lifnr TYPE elifn, "Vendor

    matnr TYPE matnr, "Material Number

    ekorg TYPE ekorg, "Purchase Organization

    werks TYPE werks_d, "Plant

    datab TYPE kodatab, "Validity start date of the condition record

    knumh TYPE knumh, "Condition Record Number

    END OF t_a017.

    DATA: it_a017 TYPE STANDARD TABLE OF t_a017,

    wa_a017 TYPE t_a017.

    SELECT lifnr

    matnr

    ekorg

    werks

    datab

    knumh INTO TABLE it_a017

    FROM a017

    FOR ALL ENTRIES IN it_excel

    WHERE matnr = it_excel-matnr

    AND lifnr = it_excel-lifnr

    AND ekorg = it_excel-ekorg

    AND werks = it_excel-werks.

    IF sy-subrc = 0.

    SORT it_a017 DESCENDING BY lifnr matnr ekorg werks datab.

    *Delete all other entries except the latest validity record for one

    *combition set of vendor, material, plant and purc org

    DELETE ADJACENT DUPLICATES FROM it_a017 COMPARING lifnr matnr ekorg werks.

    ENDIF.

    Thanks,

    Shobhit

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi,

      You can refer the following code.

      TYPES: BEGIN OF t_a017,

      lifnr TYPE elifn, "Vendor

      matnr TYPE matnr, "Material Number

      ekorg TYPE ekorg, "Purchase Organization

      werks TYPE werks_d, "Plant

      datab TYPE kodatab, "Validity start date of the condition record

      knumh TYPE knumh, "Condition Record Number

      END OF t_a017.

      DATA: it_a017 TYPE STANDARD TABLE OF t_a017,

      wa_a017 TYPE t_a017.

      SELECT lifnr

      matnr

      ekorg

      werks

      datab

      knumh INTO TABLE it_a017

      FROM a017

      FOR ALL ENTRIES IN it_ekpo

      WHERE matnr = it_ekpol-matnr

      AND lifnr = it_ekpo-lifnr

      AND ekorg = it_ekpo-ekorg

      AND werks = it_ekpo-werks.

      loop at it_a017 into wa_a017 where datab <= pa-bumon and

      databi >= pa-bumon and

      matnr = t_ekpo-matnr.

      move-correspponding it_a017 to it_temp.

      append temp.

      clear temp.

      endloop.

      sort it_temp desecnding by datab matnr.

      DELETE ADJACENT DUPLICATES FROM it_temp COMPARING lifnr matnr ekorg werks.

      Here it_temp will hold the latest condition record.

      Regards,

      Vik

      Edited by: vikred on Jul 22, 2009 6:33 AM

      Edited by: vikred on Jul 22, 2009 6:34 AM

  • author's profile photo Former Member
    Former Member
    Posted on Jul 22, 2009 at 04:40 AM

    Hi Jay,

    Use all available key fields in the select query where clause. Then to get latest conditon record for the particular month, ensure that you are getting records less than last day of that month. E.g. to get latest record for June,

    datbi le 20090630 .

    Then sort table by DATBI descending.

    Read first line or use delete adjacent duplicates.

    Thanks & Regards,

    Anil Salekar

    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.