2013 Jul 18 9:06 AM
Hi All,
I have a field Cost code in a table in which values like C0004,0000000067, 0000000253 are maintained for a single Person.
In the final output in my report I want to display the Cost Code of a single person like this in one single column:
C0004,067, 253. (comma separated)
Pls note : The field type in table is character of length 10. If the field is numeric that is no alphabets then minimum 3 characters should be displayed.
That is if value is 0000000067 then it should be displayed as 067. And if it is 0000000253 then as 253. And alphanumeric should be displayed as it is.
On run-time how can I figure out if the field is numeric or alpha-numeric?
I used following thing like:
LV_KOSTL = WA_HRT1018-KOSTL.
LV_KOSTL = LV_KOSTL+7(3).
That is tried deleting 7 leading zeroes.
But it gives a dump when the value comes as alphanumeric.
Please help.
Regards,
Pranita
2013 Jul 18 10:27 AM
Hi,
You can also use NUMERIC_CHECK FM to check if the value is NUMC or CHAR. Based on which you can truncate the leading zeros in the string.
Hope it helps.
Regards,
Adithi
2013 Jul 18 9:51 AM
Hi Pranita,
You can try this way
First check if any alphabets contains in the Cost Code( i.e of type CHAR10 )
IF lv_cost_code CA 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.
output = lv_cost_code.
ELSE.
output = lv_cost_code+7(3).
ENDIF.
2013 Jul 18 9:53 AM
Hi Pranita,
Make use of the check condition for your requirement.
CO '0123456789'.
Regards.
2013 Jul 18 10:09 AM
you can use describe field statement to get data type of a varriable :
data flag type mara-matnr.
data comp type string.
DESCRIBE FIELD flag TYPE comp.
write : / comp.
2013 Jul 18 10:32 AM
Hi Ganga,
Use this functional module
NUMERIC_CHECK
DATA : temp1(10) VALUE '000012',
htype TYPE dd01v-datatype,
slet TYPE i,
var(3).
CALL FUNCTION 'NUMERIC_CHECK'
EXPORTING
string_in = temp1
IMPORTING
htype = htype.
IF htype = 'NUMC'.
slet = STRLEN( temp1 ).
slet = slet - 3.
var = temp1+slet(3).
ENDIF.
WRITE 😕 var.
DATA : temp1(10) VALUE 'C00012',
htype TYPE dd01v-datatype,
slet TYPE i,
var(3).
CALL FUNCTION 'NUMERIC_CHECK'
EXPORTING
string_in = temp1
IMPORTING
htype = htype.
IF htype = 'NUMC'.
slet = STRLEN( temp1 ).
slet = slet - 3.
var = temp1+slet(3).
WRITE 😕 'I am numaric', var.
else.
WRITE 😕 'I am char', temp1.
ENDIF.
2013 Jul 18 10:18 AM
Hi,
Try this way to check whether the field contains only numerics and not alphabits.
IF lv_cost CA '0123456789' AND
lv_cost NA 'sy-abcde.
lv_field = lv_cost+7(3).
ELSE.
lv_field = lv_cost.
ENDIF.
Thanks & Regards
Bala Krishna
2013 Jul 18 10:26 AM
Hi Pranita,
Use this below code, it works for both string variable and integer variable.
DATA:
lv_value TYPE i VALUE '0000038', "lv_value can be integer or char or string.
lv_final TYPE string,
lv_len TYPE i.
**** Move the value to string variable.
MOVE lv_value TO lv_final.
**** Useful incase of value copied from integer type
CONDENSE lv_final NO-GAPS.
**** Remove the leading zero's
SHIFT lv_final LEFT DELETING LEADING '0' .
**** Insert zero's if necessary
lv_len = strlen( lv_final ).
WHILE lv_len < 3.
ADD 1 TO lv_len.
CONCATENATE '0' lv_final INTO lv_final.
ENDWHILE.
2013 Jul 18 10:27 AM
Hi,
You can also use NUMERIC_CHECK FM to check if the value is NUMC or CHAR. Based on which you can truncate the leading zeros in the string.
Hope it helps.
Regards,
Adithi
2013 Jul 18 10:58 AM
Thanks a lot for the responses.
I solved the problem using the FM NUMERIC_CHECK.
2013 Jul 18 11:51 AM
One more thing.
If I need to make an FM for this that usr inputs any numeric string with any no of leading zeros.
But the result should be just 3 charaters.
2013 Jul 18 12:08 PM
Hi Pranita,
For that see this code..
DATA : temp1(100) VALUE '0000000000012',
htype TYPE dd01v-datatype,
slet TYPE i,
var(3).
CALL FUNCTION 'NUMERIC_CHECK'
EXPORTING
string_in = temp1
IMPORTING
htype = htype.
IF htype = 'NUMC'.
slet = STRLEN( temp1 ).
slet = slet - 3.
var = temp1+slet(3).
WRITE 😕 'I am numaric', var.
else.
WRITE 😕 'I am char', temp1.
ENDIF.
2013 Jul 18 12:59 PM
Hi Pranita,
FM CONVERSION_EXIT_ALPHA_OUTPUT is the FM to truncate the leading zeros.
Also can use:
SHIFT a LEFT DELETING LEADING '0'.
But don't think there is would any FM to truncate upto a certain value.
What if the numeric value in your query has more than 3 digits say 00123234 then truncating until 3 would not serve the purpose.
Regards,
Adithi
2013 Jul 18 10:34 AM
Hi,
You can use FM numeric_check to check whether the value is numeric.
CALL FUNCTION 'NUMERIC_CHECK'
EXPORTING
STRING_IN = X
IMPORTING
STRING_OUT = X
HTYPE = H_TYPE.
If variable X contains a character then H_TYPE will return 'CHAR'. Check this and then you can decide to get 3 characters or whole string.
Regards,
Mahen.