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: 

Logic required for the requirement (urgent)

former_member404244
Active Contributor
0 Kudos

HI experts,

can anyone help me out regarding the following logic.

The logic will check for both complete and partial goods receipts and invoice receipts. Based on the PO line item history it will calculate the totals into following categories:

(1) Total PO Line Item value with both GR & IR

(2) Total PO Line Item value with GR but no IR

(3) Total PO Line Item value with IR but no GR

For a single PO line, it is possible to have the Total Line Item Value divided into one or more of the above three categories at the same time. For example, if for a PO line item with 100 unit at $10.00 per unit, there is a GR for 50 Units and IR for only 30 units, the three columns above will be populated as:

(1) Total PO Line Item value with both GR & IR – 30 x 10 = 300

(2) Total PO Line Item value with GR but no IR – 20 x 10 = 200

(3) Total PO Line Item value with IR but no GR – 0 x 10 = 0

Similarly, if for a PO line item with 100 units and $10.00 per unit, there is a GR for 50 units and IR for 70 units, the three columns will be populated as:

(1) Total PO Line Item value with both GR & IR – 50 x 10 = 500

(2) Total PO Line Item value with GR but no IR – 0 x 10 = 0

(3) Total PO Line Item value with IR but no GR – 20 x 10 = 200

Regards,

Nagaraj

7 REPLIES 7

Former Member
0 Kudos

Please try and follow the below for your requirement.

SELECT ebeln ebelp vgabe wrbtr menge into table itab

from ekbe

where ebeln in so_ebeln

and vgabe in ('1','2').

sort itab.

loop at itab.

at new ebelp.

lgrir = 0.

lgrnir = 0.

lngrir = 0.

ltotgr = ltotir = 0.

endat.

if itab-vgabe = '1'.

ltotgr = ltotgr + itab-menge.

else.

ltotir = ltotir + itab-menge.

endif.

at end of ebelp.

if ltotir >= ltotgr.

lgrir = ltotgr.

lngrir = ltotir - ltotgr.

lgrnir = 0.

else.

lgrir = ltotir.

lgrnir = ltotgr - ltotir.

lngrir = 0.

endif.

endat.

endloop.

former_member404244
Active Contributor
0 Kudos

Hi Anrag,

Thanks for the reply .

Regards,

Nagaraj

former_member404244
Active Contributor
0 Kudos

Hi rich,

can u help me out regarding my query.

regards,

Nagaraj

0 Kudos

Is there some problem, the given logic should be able to give you the correct value for each po line in terms of quantity. As for value, can you specify if you mean $10 is the standard price for the material. In that case you can get the same from MBEW.

Regards

Anurag

0 Kudos

Anurag's answer looks pretty good to me, as suggested you can get the standard price from MBEW, field STPRS.

Is his logic not completely working for you?

Regards,

Rich Heilman

0 Kudos

Maybe this example will help....



report zrich_0002 .


data: iekbe type table of ekbe with header line.
data: xmbew type mbew.
data: xekpo type ekpo.

data: begin of ibuckets occurs 0,
      ebeln type ekpo-ebeln,
      ebelp type ekpo-ebelp,
      pgrir type p decimals 2,  " Total GR & IR
      pgr   type p decimals 2,  " Total GR
      pir   type p decimals 2,  " Total IR
      pgrni type p decimals 2,  "GR no IR
      pirng type p decimals 2,  "IR no GR
      end of ibuckets.




parameters: p_ebeln type ekko-ebeln,
            p_ebelp type ekpo-ebelp.


start-of-selection.

  clear iekbe.  refresh iekbe.
  select * into table iekbe from ekbe
              where ebeln = p_ebeln
                and ebelp = p_ebelp
                and vgabe in ('1','2').


  loop at iekbe.

    clear ibuckets.

    ibuckets-ebeln = iekbe-ebeln.
    ibuckets-ebelp = iekbe-ebelp.


    select single * from ekpo into xekpo
                  where ebeln = iekbe-ebeln
                    and ebelp = iekbe-ebelp.

    select single * from mbew into xmbew
                   where matnr = xekpo-matnr.

    case iekbe-vgabe.
      when  '1'.

        ibuckets-pgrir = iekbe-menge * xmbew-stprs.
        ibuckets-pgr   = iekbe-menge * xmbew-stprs.

      when '2'.

        ibuckets-pgrir = iekbe-menge * xmbew-stprs.
        ibuckets-pir   = iekbe-menge * xmbew-stprs.

    endcase.

    collect ibuckets.

  endloop.


  loop at ibuckets.
    ibuckets-pgrni = ibuckets-pgr - ibuckets-pir.
    ibuckets-pirng = ibuckets-pir - ibuckets-pgr.

    if ibuckets-pgrni < 0.
      clear ibuckets-pgrni.
    endif.

    if ibuckets-pirng < 0.
      clear ibuckets-pirng.
    endif.

    modify ibuckets.
  endloop.

  loop at ibuckets.
    write:/    ibuckets-ebeln,
               ibuckets-ebelp ,
               ibuckets-pgrir,
               ibuckets-pgr   ,
               ibuckets-pir  ,
               ibuckets-pgrni ,
               ibuckets-pirng .
  endloop.

Regards,

Rich Heilman

former_member404244
Active Contributor
0 Kudos

hi rich and anurag,

Thanks a lot for ur help.I have the developed the logic basing on anurag's reply and confirmed from ur reply.Once again thanks a lot.

cheers

Nagaraj