cancel
Showing results for 
Search instead for 
Did you mean: 

Reading numbers/digits in Type C field

Former Member
0 Kudos

Hi all, yesterday i opened a thread similar to this and also relating to the same type C field...have a look the following parts of my program:


TABLES: EBAN,                      "Purchase Requisition
        STXH.                      "STXD SAPscript text file header

DATA : BEGIN OF ITAB OCCURS 0,
       BANFN LIKE EBAN-BANFN,      "Purchase requisition number
       BADAT LIKE EBAN-BADAT,      "Requisition (request) date
       TXZ01 LIKE EBAN-TXZ01,      "Short text
       WAERS LIKE EBAN-WAERS,      "Currency Key
       BLCKT LIKE EBAN-BLCKT,      "Reason for Item Block
       SUBT TYPE I,                "Subtotal
       MENGE LIKE EBAN-MENGE,      "Purchase requisition quantity
       MEINS LIKE EBAN-MEINS,      "Purchase requisition unit of measure
       TOTAL TYPE I,               "Total amount
       WERKS LIKE EBAN-WERKS,      "Plant
       KNTTP LIKE EBAN-KNTTP,      "Account assignment category
       AFNAM LIKE EBAN-AFNAM,      "Name of requisitioner/requester
       END OF ITAB.

DATA: V_QUANTITY TYPE I.           "Hold ITAB-MENGE value
DATA: V_SUBTOTAL TYPE I.           "Hold ITAB-BLCKT value
DATA: V_TOTAL TYPE I.              "Hold ITAB-TOTAL value

SELECT BANFN BADAT TXZ01 WAERS BLCKT MENGE MEINS WERKS KNTTP AFNAM
  INTO CORRESPONDING FIELDS OF TABLE ITAB
  FROM EBAN
  WHERE BANFN = I_BANFN AND
        BSTYP = 'B' AND
        BLCKD <> ' '.

LOOP AT ITAB.

  V_QUANTITY = ITAB-MENGE.
  V_SUBTOTAL = ITAB-BLCKT.
  COMPUTE V_TOTAL = V_QUANTITY * V_SUBTOTAL.
  MOVE V_SUBTOTAL TO ITAB-SUBT.
  MOVE V_TOTAL TO ITAB-TOTAL.
  MODIFY ITAB.

ENDLOOP.

With the help i got yesterday, i managed to extract the numbers in that type c field (ITAB-BLCKT) in order to do my calculation...however, i would assume that would only work if the user keys in something like 10000...but what if some of the user might accidentally key in 10,000 (with the comma/"thousand" seperator) instead?

Accepted Solutions (1)

Accepted Solutions (1)

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

You will get an ABAP runtime error is you try to move a character field with the value 1,000 to an integer field. Here is a way to handle it.



report  zrich_0001.

data: i type i.
 
data: c(10) type c.

c = '1,000'.

catch system-exceptions convt_no_number = 1.
  i = c.
endcatch.

if sy-subrc = 1.
  replace all occurrences of ',' in c with space .
  condense c no-gaps.
  i = c.
endif.

write:/ c.
write:/ i.

Regards,

Rich Heilman

Former Member
0 Kudos

you were right about the runtime error...

thanks to ur example, i managed to make it work...

thanks...points are rewarded appropriately

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi

You can insert this piece of code to convert your number to format you need:

DO.

REPLACE ',' WITH SPACE INTO ITAB-BLCKT.

if sy-subrc <> 0. exit. endif.

CONDENSE ITAB-BLCKT.

ENDDO.

This rule is good is comma is not the separator for decimal part.

Max

suresh_datti
Active Contributor
0 Kudos

Hi,

just a small suggestion.. what if the amount was 1,00,000? REPLACE would only get rid of the first comma.. I would use REPLACE ALL OCCURRENCES instead..

Regards,

Suresh Datti