Skip to Content
avatar image
Former Member

calculation of total in sap script

Hi All,

Please help me out for this requirement.

I have an amount field reguh-rbetr. I need to show the sum of this field as TOTAL.

How can we do it? Please let me know. Is there any function in the script itself or do we need to calculate it in the program? Pl gimme example code.

Regards,

Priya

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Best Answer
    avatar image
    Former Member
    Nov 17, 2007 at 02:11 PM

    Hi priya,

    In program it self you caliculate the total,use the text element and pass that varible to script.

    Thanks

    Ashok

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi

      see the sample codes of the Subroutines and do accordingly

      How to call a subroutine form SAPscripts

      The Form :

      /:PERFORM CDE_CENT IN PROGRAM ZKRPMM_PERFORM_Z1MEDRUCK

      /:USING &EKKO-EBELN&

      /:CHANGING &CDECENT&

      /:ENDPERFORM

      The report :

      REPORT zkrpmm_perform_z1medruck .

      DATA : BEGIN OF it_input_table OCCURS 10.

      INCLUDE STRUCTURE itcsy.

      DATA : END OF it_input_table.

      • déclaration de la table output_table contenant les

      variables exportées

      DATA : BEGIN OF it_output_table OCCURS 0.

      INCLUDE STRUCTURE itcsy.

      DATA : END OF it_output_table.

      DATA : w_ebeln LIKE ekko-ebeln,

      • w_vbeln LIKE vbak-vbeln,

      w_zcdffa LIKE vbak-zcdffa.

      *----


      *

      • FORM CDE_CENT

      *

      *----


      *

      FORM cde_cent TABLES input output.

      it_input_table[] = input[].

      it_output_table[] = output[].

      READ TABLE it_input_table INDEX 1.

      MOVE it_input_table-value TO w_ebeln.

      CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

      EXPORTING

      input = w_ebeln

      IMPORTING

      output = w_ebeln.

      SELECT SINGLE zcdffa FROM ekko

      INTO w_zcdffa

      WHERE ebeln = w_ebeln.

      it_output_table-name = 'CDECENT'.

      MOVE w_zcdffa TO it_output_table-value.

      MODIFY it_output_table INDEX 1.

      output[] = it_output_table[].

      ENDFORM.

      *************************************************************************

      /: PERFORM

      /: USING &INVAR1&

      /: USING &INVAR2&

      ......

      /: CHANGING &OUTVAR1&

      /: CHANGING &OUTVAR2&

      ......

      /: ENDPERFORM

      INVAR1 and INVAR2 are variable symbols and may be of any of the four SAPscript symbol types.

      OUTVAR1 and OUTVAR2 are local text symbols and must therefore be character strings.

      Example:

      In script form

      /: PERFORM READ_TEXTS IN PROGRAM 'Z08M1_FORM_EKFORM1'

      /: USING &EKKO-EKORG&

      /: USING &EKPO-WERKS&

      /: USING &EKKO-EKGRP&

      /: USING &EKKO-BSTYP&

      /: CHANGING &COMPNAME&

      /: CHANGING &SENDADR&

      /: CHANGING &INVCADR&

      /: CHANGING &COMPADR&

      /: CHANGING &COVERLTR&

      /: CHANGING &SHIPADR&

      /: CHANGING &REMINDER&

      /: CHANGING &REJECTION&

      /: CHANGING &POSTADR&

      /: CHANGING &LOGO&

      /: ENDPERFORM

      In program

      *----


      *

      • FORM Read_texts - To extract the standard texts from the table *

      *----


      *

      FORM READ_TEXTS TABLES IN_PAR STRUCTURE ITCSY

      OUT_PAR STRUCTURE ITCSY.

      DATA : L_EKORG TYPE EKORG,

      L_WERKS TYPE WERKS_D,

      L_BSTYP TYPE BSTYP,

      L_EKGRP TYPE BKGRP.

      READ TABLE IN_PAR WITH KEY 'EKKO-EKORG' .

      CHECK SY-SUBRC = 0.

      L_EKORG = IN_PAR-VALUE.

      READ TABLE IN_PAR WITH KEY 'EKPO-WERKS' .

      CHECK SY-SUBRC = 0.

      L_WERKS = IN_PAR-VALUE.

      READ TABLE IN_PAR WITH KEY 'EKKO-EKGRP' .

      CHECK SY-SUBRC = 0.

      L_EKGRP = IN_PAR-VALUE.

      READ TABLE IN_PAR WITH KEY 'EKKO-BSTYP' .

      CHECK SY-SUBRC = 0.

      L_BSTYP = IN_PAR-VALUE.

      CLEAR Z08M1_ORG_TEXTS.

      SELECT SINGLE * FROM Z08M1_ORG_TEXTS WHERE EKORG = L_EKORG

      AND WERKS = L_WERKS

      AND EKGRP = L_EKGRP

      AND BSTYP = L_BSTYP.

      IF SY-SUBRC NE 0.

      SELECT SINGLE * FROM Z08M1_ORG_TEXTS WHERE EKORG = L_EKORG

      AND WERKS = L_WERKS

      AND EKGRP = L_EKGRP

      AND BSTYP = SPACE.

      ENDIF.

      READ TABLE OUT_PAR WITH KEY 'COMPNAME'.

      OUT_PAR-VALUE = Z08M1_ORG_TEXTS-TXT_COMP.

      MODIFY OUT_PAR INDEX SY-TABIX.

      READ TABLE OUT_PAR WITH KEY 'SENDADR'.

      OUT_PAR-VALUE = Z08M1_ORG_TEXTS-TXT_ADRS.

      MODIFY OUT_PAR INDEX SY-TABIX.

      READ TABLE OUT_PAR WITH KEY 'INVCADR'.

      OUT_PAR-VALUE = Z08M1_ORG_TEXTS-TXT_INVC.

      MODIFY OUT_PAR INDEX SY-TABIX.

      READ TABLE OUT_PAR WITH KEY 'COMPADR'.

      OUT_PAR-VALUE = Z08M1_ORG_TEXTS-TXT_CPAD.

      MODIFY OUT_PAR INDEX SY-TABIX.

      READ TABLE OUT_PAR WITH KEY 'COVERLTR'.

      OUT_PAR-VALUE = Z08M1_ORG_TEXTS-TXT_COVR.

      MODIFY OUT_PAR INDEX SY-TABIX.

      READ TABLE OUT_PAR WITH KEY 'SHIPADR'.

      OUT_PAR-VALUE = Z08M1_ORG_TEXTS-TXT_SHIP.

      MODIFY OUT_PAR INDEX SY-TABIX.

      READ TABLE OUT_PAR WITH KEY 'REMINDER'.

      OUT_PAR-VALUE = Z08M1_ORG_TEXTS-TXT_RMDR.

      MODIFY OUT_PAR INDEX SY-TABIX.

      READ TABLE OUT_PAR WITH KEY 'REJECTION'.

      OUT_PAR-VALUE = Z08M1_ORG_TEXTS-TXT_RJCT.

      MODIFY OUT_PAR INDEX SY-TABIX.

      READ TABLE OUT_PAR WITH KEY 'POSTADR'.

      OUT_PAR-VALUE = Z08M1_ORG_TEXTS-TXT_POST.

      MODIFY OUT_PAR INDEX SY-TABIX.

      READ TABLE OUT_PAR WITH KEY 'LOGO'.

      OUT_PAR-VALUE = Z08M1_ORG_TEXTS-TXT_LOGO.

      MODIFY OUT_PAR INDEX SY-TABIX.

      ENDFORM.

      *************************************************************************

      REPORT ZMPO1 .

      form get_freight tables in_par structure itcsy out_par structure itcsy.

      tables: ekko,konv,t685t.

      data: begin of itab occurs 0,

      ebeln like ekko-ebeln,

      knumv like ekko-knumv,

      end of itab.

      data: begin of itab1 occurs 0,

      knumv like konv-knumv,

      kposn like konv-kposn,

      kschl like konv-kschl,

      kbetr like konv-kbetr,

      waers like konv-waers,

      kwert like konv-kwert,

      end of itab1.

      data: begin of iout occurs 0,

      kschl like konv-kschl,

      vtext like t685t-vtext,

      kbetr like konv-kbetr,

      kwert like konv-kwert,

      end of iout.

      data v_po like ekko-ebeln.

      read table in_par with key 'EKKO-EBELN'.

      if sy-subrc = 0.

      v_po = in_par-value.

      select

      ebeln

      knumv

      from ekko

      into table itab

      where ebeln = v_po.

      if sy-subrc = 0.

      loop at itab.

      select

      knumv

      kposn

      kschl

      kbetr

      waers

      kwert

      into table itab1

      from konv

      where knumv = itab-knumv and

      kappl = 'M'.

      endloop.

      loop at itab1.

      if itab1-kposn <> 0.

      select single * from t685t

      where kschl = itab1-kschl

      and kappl = 'M'

      and spras = 'EN'.

      iout-vtext = t685t-vtext.

      iout-kschl = itab1-kschl.

      iout-kbetr = itab1-kbetr.

      iout-kwert = itab1-kwert.

      append iout.

      clear iout.

      endif.

      endloop.

      sort itab1 by kposn.

      loop at iout.

      sort iout by kschl.

      if ( iout-kschl eq 'GSDC' OR

      iout-kschl eq 'GSFR' OR

      iout-kschl eq 'GSIR' ).

      at end of kschl.

      read table iout index sy-tabix.

      sum.

      • write:/ iout-kschl,iout-vtext,iout-kwert.

      out_par-name = 'A1'.

      out_par-value = iout-vtext.

      append out_par.

      out_par-name = 'A2'.

      out_par-value = iout-kwert.

      append out_par.

      endat.

      endif.

      endloop.

      endif.

      endif.

      endform.

      • IN THE FORM I AM WRITING THIS CODE.

      /:DEFINE &A1& = ' '

      /:DEFINE &A2& = ' '

      /:PERFORM GET_FREIGHT IN PROGRAM ZMFORM_PO1

      /:USING &EKKO-EBELN&

      /:CHANGING &A1&

      /:CHANGING &A2&

      /:ENDPERFORM

      • &A1&

      • &A2&

      This Code is to be written in the PO form under ADDRESS window.

      -

      -


      /:DEFINE &A1& = ' '

      /:DEFINE &A2& = ' '

      /:DEFINE &A3& = ' '

      /:DEFINE &A4& = ' '

      /:DEFINE &A5& = ' '

      /:DEFINE &A6& = ' '

      /:PERFORM GET_VENDOR IN PROGRAM ZMFORM_PO

      /:USING &EKKO-EBELN&

      /:CHANGING &A1&

      /:CHANGING &A2&

      /:CHANGING &A3&

      /:CHANGING &A4&

      /:CHANGING &A5&

      /:CHANGING &A6&

      /:ENDPERFORM

      • &A1&

      • &A2&

      • &A3&

      • &A4&

      • &A5&

      • &A6&

      Regards

      Anji

  • avatar image
    Former Member
    Nov 17, 2007 at 10:40 PM

    Hi

    In the Program(if it is not the std program) itself you can calculate the totals for that field using LOOP..ENDloop..In between AT end of the doc use SUM..

    and put it in a variable and print it in the script

    If the program is not accessable then write a PERFORM Subroutine and create the program and calculate in that program and pass back to script

    Regards

    Anji

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Nov 21, 2007 at 07:19 AM

    Hi

    <b>SAPscripts How to calculate Totals and Subtotals</b>

    I have some doubs in BDC and SMART FORMS. I want to change the material number using the transaction code MM02 through BDC.

    In scripts and smartforms how to calculate totals and subtotals?

    To calculate totals and sub totals in sap scripts you have to use subroutines.

    Say if you have to add the unit price (KOMVD-KBERT) then in the main window whereever tat value is picked write this routine

    /: DEFINE &TOT_PRICE&

    /: PERFORM F_GET_PRICE IN PROGRAM <subroutine prog name> /:USING &KOMVD-KBERT& /:CHANGING &TOT_PRICE& /:ENDPERFORM

    Then write the variable where ever you want it to be printed (mostly it will be in footer window)

    Then create subroutine pool program and you have to write the code.

    FORM F_GET_PRICE tables int_cond structure itcsy

    outt_cond structure itcsy. data : value type kbert.

    statics value1 type kbert.

    Read int_cond table index 1.

    value = int_cond-value.

    value1 = value1 + value.

    Read outt_cond table index 1.

    outt_cond-value = value1.

    Modify outt_cond index 1.

    ENDFORM.

    I have given a rough outline, please be aware of the variable conversions as Int_cond-value and outt_cond-value are characters.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Naresh,

      Thanks for the reply. It is helpful one. But i want to display this total in another window. My doubt is that if i declare the routine in hte main window of the script, and if i use the variable, say , &hspell&, in hte total window, will the value get displayed?

      Regards,

      Priya

  • avatar image
    Former Member
    Dec 02, 2007 at 12:22 PM

    done

    Add comment
    10|10000 characters needed characters exceeded