Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 9129

Calculating grandtotal on sapscript

$
0
0

Hi gurus I have an assignment to modify a Plant Maintenance picking slip.The customer wants the form to pick data from MM material master and then add a markup of 10% on the price field. The total price field should be quantity * unit price plus 10% markup.That i did.Now my task is to create the grand total for all line items. see images below

 

picki.png

pick.png

 

 

 

 

 

 

 

 

 

 

 

 

Below is my code snippet to calculate GrandTotal price.

 

 

TABLES: RESB, MBEW, MARA, MVKE, AUFK.

 

FORM calc_grandtotprice TABLES IN_PAR STRUCTURE itcsy

   OUT_PAR STRUCTURE itcsy.

 

 

 

   TYPES: BEGIN OF ity_total,

 

 

     grandtotprice TYPE MBEW-VERPR,

     MATNR      TYPE RESB-MATNR,

     BDMNG TYPE RESB-BDMNG,

     VERPR   TYPE MBEW-VERPR,

      STPRS  TYPE MBEW-STPRS,

   END OF ity_total.

 

   DATA it_total type standard table of  ity_total.

   DATA wa_total type ity_total.

 

 

 

   DATA: qty like RESBD-BDMNG.

   DATA: price(20), output_price(20), output_totprice(20),  output_grandtotprice(20), price_markup like MBEW-VERPR.

   DATA:grandtotprice like MBEW-VERPR.

   DATA: commission(16) TYPE P DECIMALS 2.

   DATA: tot_price LIKE MBEW-VERPR.

   DATA:material_no LIKE RESBD-MATNR.

   DATA:resnum LIKE RESBD-RSNUM.

   DATA: plant LIKE RESBD-WERKS.

   DATA: order_num LIKE RESBD-AUFNR.

   DATA: rpos LIKE RESBD-RSPOS.

 

 

   READ TABLE IN_PAR WITH KEY 'RESBD-RSNUM'.

   CHECK sy-subrc = 0.

   resnum = IN_PAR-value.

 

  READ TABLE IN_PAR WITH KEY 'RESBD-MATNR'.

   CHECK sy-subrc = 0.

  material_no = IN_PAR-value.

 

* READ TABLE IN_PAR WITH KEY 'RESBD-RSPOS'.

*  CHECK sy-subrc = 0.

* rpos = IN_PAR-value.

 

 

   qty = 0.

   price = 0.

   commission = '0.00'.

   tot_price = 0.

   grandtotprice = 0.

 

   IF sy-subrc EQ 0.

 

 

 

     Select * from RESB INTO CORRESPONDING FIELDS OF WA_TOTAL where RSNUM = resnum AND  MATNR = material_no .

       CHECK sy-subrc = 0.

    WA_TOTAL-MATNR = material_no.

     "WA_TOTAL-RSNUM = resnum.

 

  "WA_TOTAL-RSPOS = rpos.

       qty = WA_TOTAL-BDMNG.

 

 

 

       IF qty NE 0.

         SELECT SINGLE * FROM MBEW INTO CORRESPONDING FIELDS OF WA_TOTAL WHERE MATNR = WA_TOTAL-MATNR .

         CHECK sy-subrc = 0.

 

         price = WA_TOTAL-VERPR.

       ENDIF.

ENDSELECT.

endif.

       commission = ( 10 / 100 ) * price.

       price = price + commission.

       tot_price = qty * price.

 

 

 

grandtotprice = tot_price + grandtotprice.

*WA_TOTAL-GRANDTOTPRICE =  grandtotprice.

 

 

"LOOP AT it_total INTO wa_total.

"    WA_TOTAL-GRANDTOTPRICE =  grandtotprice.

 

READ TABLE OUT_PAR WITH KEY 'GRAND_TOTPRICE'.

   IF sy-subrc = 0.

     output_grandtotprice = output_grandtotprice + grandtotprice.

 

     write output_grandtotprice to OUT_PAR-value.

     MODIFY OUT_PAR INDEX sy-tabix.

   ENDIF.

 

 

ENDFORM.  

 

""""I have created a new wiindow for the grandtotal and below is the code snippet in sapscript

 

DEFINE &GRAND_TOTPRICE& = '0.0'.

PERFORM CALC_GRANDTOTPRICE IN PROGRAM ZCALC_GRANDTOTPRICE

USING  &RESBD-RSNUM&

USING  &RESBD-MATNR&

                                                                       

USING  &RESBD-RSPOS&

CHANGING &GRAND_TOTPRICE&

ENDPERFORM

 

TOTAL:&GRAND_TOTPRICE&

 

 

 

My challenge is that it is picking the total for the last line item only and i have tested using the debuger and am seeing that in_par is already populated by the 2nd line item instead of the first one.Where could i have gone wrong.

 

 

Regards

 

Rejo


Viewing all articles
Browse latest Browse all 9129

Trending Articles