ABAP Function Example - HR_IN_CHG_INR_WRDS

I was asked to create a custom invoice in sap scripts,which is completed now, the value was supposed to be converted in words, so I used the FM * CALL FUNCTION 'HR_IN_CHG_INR_WRDS'. 

By: Walia

This function module is the right one.  I have also made a program for the credit note.  I have used this function module.
You can take the help from here ..

*&---------------------------------------------------------------------*
*& Report  ZFI_CREDIT_NOTE_CREATION
*&
*&---------------------------------------------------------------------*

REPORT  ZFI_CREDIT_NOTE_CREATION NO STANDARD PAGE HEADING LINE-SIZE 120 line-count 72
message-id zvarun.

tables : vbrk,vbrp,kna1,konv,spell ,bsak.

data : camt like bsak-dmbtr.
data : begin of itab occurs 0,
vbeln like vbrk-vbeln,
fkdat like vbrk-fkdat,
xblnr like vbrk-xblnr,
knumv like vbrk-knumv,
kunrg like vbrk-kunrg,
matnr like vbrp-matnr,
arktx like vbrp-arktx,
fkimg like vbrp-fkimg,
posnr like vbrp-posnr,
end of itab.


data : begin of itab1 occurs 0,
knumv like konv-knumv,
kposn like konv-kposn,
kschl like konv-kschl,
kawrt like konv-kawrt,
kwert like konv-kwert,
KBETR LIKE KONV-KBETR,
end of itab1.

data : qty like vbrp-fkimg.
*data : tot type p decimals 2.
*data : tot1 type p decimals 2.
*data : tot2 type p decimals 2.
*data : tot3 type p decimals 2.
*data : tot like konv-kawrt.
data : sub_tot like konv-kawrt.
DATA : TOT2 LIKE KONV-KAWRT.
*DATA : TOT3 LIKE KONV-KAWRT.
*data :   tot_wsp(15) type p.
data :   tot_wsp(15) type p decimals 2.
data :   unit_wsp like konv-kawrt.
data :   tot_cst like konv-kWERT.
data :   tot_VAT like konv-kWERT.
*data :   unit_cst like konv-kawrt.
data : h_vbeln like vbrk-vbeln.
DATA : UNIT_MRP LIKE KONV-KBETR.
data  line_no(3) type n.
data : credit_amt like konv-kwert.
DATA :   cnt type i.
data  amt_word like spell-word.
data : v_i_amount TYPE PC207-BETRG.
data : i_value like konv-kwert.
data : amt_in_words(255) TYPE c,
tmp_amt  type TDSYMVALUE.
data : spell_fig(80).
DATA : VAT_AMT LIKE KONV-KWERT.
DATA : AMT LIKE KONV-KWERT.


selection-screen : begin of block blk1 with frame title text-001.
select-options : vbeln for vbrk-vbeln obligatory.
selection-screen : end of block blk1.

at selection-screen.
  select * from vbrk where vbeln in vbeln.
  endselect.
  if sy-subrc ne 0.
  message e999 with 'Docoment No does not exist....check'.
endif.

start-of-selection.
refresh : itab.
  clear  : itab.
  select a~vbeln a~fkdat a~xblnr a~kunrg a~knumv
         b~matnr b~arktx b~fkimg b~posnr
         into corresponding fields of table itab from
         vbrk as a inner join vbrp as b
         on a~vbeln = b~vbeln
         where a~vbeln in vbeln.
 sort itab by vbeln xblnr knumv matnr.
 loop at itab.
*   LOOP AT ITAB.

  unit_wsp = 0.
  tot_wsp  = 0.
  tot_cst  = 0.
  UNIT_MRP = 0.
     refresh : itab1.
    clear : itab1.
    select knumv kposn kschl kawrt kwert KBETR from konv into table itab1
    where knumv = itab-knumv and
    kposn = itab-posnr and
    kschl in ('ZVAT','ZCST','ZWSP','ZMRP').
    sort itab1 by knumv.
      loop at itab1.
     CASE ITAB1-KSCHL.

   WHEN 'ZWSP'.
        unit_wsp =  itab1-kawrt / itab-fkimg.
        tot_wsp = itab1-kawrt.
   WHEN 'ZMRP'.
        UNIT_MRP =  ITAB1-KBETR.
   WHEN 'ZCST'.
        tot_cst = itab1-kwert.
  WHEN 'ZVAT'.
        TOT_VAT = ITAB1-KWERT.

     ENDCASE.

ENDLOOP.


    qty     =  qty + itab-fkimg.
    tot2    =  tot2 +  tot_wsp .
    sub_tot =  tot2 + tot_cst + tot_vat.

*     refresh : itab1.
*    clear : itab1.
*    select knumv kposn kschl kawrt kwert KBETR from konv into table itab1
*    where knumv = itab-knumv and
*    kposn = itab-posnr and
*    kschl in ('ZVAT','ZCST','ZWSP','ZMRP').
*    sort itab1 by knumv.
*
* loop at itab1.
*     CASE ITAB1-KSCHL.
*when 'ZWSP' or 'ZVAT' OR 'ZCST'.
*   credit_amt = credit_amt + ITAB1-KWERT.
**   when 'ZVAT'.
**   credit_amt = credit_amt + ITAB1-KWERT.
*
*  ENDCASE.
  endloop.

*     ENDLOOP.

 line_no = 0.
  new-page.
  skip 1.
  write : /5(115)  'TEST RETAIL LIMITED ' centered.
  write : /5(115)  'Test Unit ' centered.
  write : /5(115)  'PHASE IV ' centered.
  write : /5(115)  'E-MAIL : info@yourdomain.in' centered.
  SKIP 1.
  write : 2(118) SY-Uline.
  write : /5(115)  'CREDIT NOTE' centered.
*    line_no = 10.

 data : fig1(70),
       fig2(20),
       fig3(20).
tmp_amt = sub_tot.
v_i_amount = tmp_amt.

call function 'HR_IN_CHG_INR_WRDS'
  exporting
    amt_in_num               = v_i_amount
 IMPORTING
   AMT_IN_WORDS             =  amt_in_words
 EXCEPTIONS
   DATA_TYPE_MISMATCH       = 1
   OTHERS                   = 2.

if sy-subrc <> 0.
 MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
move space to spell_fig.
split amt_in_words at 'Rupees' into fig1 fig2 .
concatenate fig1 'AND' fig2 'Only*' into spell_fig separated by space.



*camt = credit_amt.
*     call function 'ZSPELL_AMOUNT'
*       exporting
*            amount    = camt
*            currency  = 'INR'
*            filler    = ' '
*            language  = sy-langu
*       importing
*            in_words  = spell
*       exceptions
*            not_found = 1
*            too_large = 2
*            others    = 3.
*
*  concatenate : spell-word 'AND' spell-decword 'PAISE'
*        into spell-word separated by ' '.
*  write spell-word to amt_word.



    select single * from kna1 where kunnr = itab-kunrg.
     write :/2(10)  kna1-kunnr,
          20(35)  kna1-name1,
          90(15)  'CREDIT NOTE NO.',
          106(10) itab-vbeln.
  write :/19(35)  kna1-stras,
          90(15)  'DATE',
          106(10) ITAB-FKDAT.
  write :/20(20)  kna1-ort01,
            (10)  kna1-pstlz.
  write : /20(3)  'PH:',
          24(16)  KNA1-TELF1,
           41(4)  'FAX:',
          46(30)  KNA1-TELFX.

  skip 2.
  write : /1 'Dear Sir,'.
  skip 1.

  write : /20(45) 'We advise having Credited your account with a ',
          (11) 'sum of Rs. ',
          (15) sub_tot.

  write : /1(1) '(',
          2(78) spell_fig,
          80(1) ')'.
  write : /1 ' towards sale return as per particulars given below : '.

  skip 3.


  write : 2(118)  sy-uline.
  write : /3(10)  'ARTICLE NO',
          22(20)  'ARTICLE DESCRIPTION',
          53(10)  'QUANTITY',
           69(3)  'MRP',
           86(3)  'WSP',
          100(9)  'TOTAL WSP'.
  WRITE : /67(8)  'per UNIT',
           84(8)  'per UNIT',
          101(6)  'in Rs.'.
 WRITE : /2(118)  SY-ULINE.
  skip.
*  line_no = line_no + 4.
  LOOP AT ITAB.

  unit_wsp = 0.
  tot_wsp  = 0.
  tot_cst  = 0.
  UNIT_MRP = 0.
     refresh : itab1.
    clear : itab1.
    select knumv kposn kschl kawrt kwert KBETR from konv into table itab1
    where knumv = itab-knumv and
    kposn = itab-posnr and
    kschl in ('ZVAT','ZCST','ZWSP','ZMRP').
    sort itab1 by knumv.
      loop at itab1.
     CASE ITAB1-KSCHL.

   WHEN 'ZWSP'.
        unit_wsp =  itab1-kawrt / itab-fkimg.
        tot_wsp = itab1-kawrt.
   WHEN 'ZMRP'.
        UNIT_MRP =  ITAB1-KBETR.
   WHEN 'ZCST'.
        tot_cst = itab1-kwert.
  WHEN 'ZVAT'.
        TOT_VAT = ITAB1-KWERT.

     ENDCASE.

ENDLOOP.


write : /2(18)   itab-matnr,
          (25)   itab-arktx,
          (13)   itab-fkimg,
        65(11)   UNIT_MRP,
          (15)   unit_wsp,
          (15)   tot_wsp.



***        line_no = line_no + 1.
***        if line_no > 68.
***       write :/60(10) '___CONT___'.
***           skip 3.

*       line_no = 1.
***     endif.

*   cnt = cnt + 1.
      endloop.
* qty     =  qty + itab-fkimg.
*    tot2    =  tot2 +  tot_wsp .
*    sub_tot =  tot2 + tot_cst + tot_vat.

*      IF CNT > 1.
      skip 2.



      WRITE : /47(13)  QTY.
  write : /2(140)  sy-uline.
  write : /50      'Total WSP                    :',
          93(15)   tot2.
   WRITE :/50      'Sale Return Amount           :',
          93(15)   tot2.
   write :/50      'VAT                          :',
          93(15)   tot_vat.
   WRITE :/50      'C.S.T                        :',
          93(15)   tot_cst.
   WRITE :/50      'Net Amount                   :',
       93(15)      sub_tot.

*   write :/50      'Rounding off                 :'.
*   write :/50      'Net Amount                   :'.
*ENDIF.
SKIP 3.
CLEAR : TOT2,TOT_VAT,TOT_CST,SUB_TOT.
clear credit_amt.

More Abapers Questions:

ABAP Books List
ABAP/4 Certification, Programming and Object Oriented Programming Books

Smart Forms
SAP Smartforms

ABAP Menu:
ABAP Example Hints and Tips

Return to Index:-
SAP ABAP/4 Programming, Basis Administration, Configuration Hints and Tips

(c) www.gotothings.com All material on this site is Copyright.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
All product names are trademarks of their respective companies.  The site www.gotothings.com is in no way affiliated with SAP AG.
Any unauthorised copying or mirroring is prohibited.