11-23-2014 8:09 AM
Dear Experts,
When i was trying to call the fm 'converison_exit_alpha_input ' is not resulting the output with leading zeros. Need help in resolving the same.
A piece of coding is as below..
*&---------------------------------------------------------------------*
*& Form POPULATE_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM POPULATE_DATA .
LOOP AT GT_MCHA INTO GS_MCHA.
GS_FINAL-MATNR = GS_MCHA-MATNR.
GS_FINAL-WERKS = GS_MCHA-WERKS.
GS_FINAL-CHARG = GS_MCHA-CHARG.
GS_FINAL-J_3ASIZE = GS_MCHA-J_3ASIZE.
READ TABLE GT_MSKA INTO GS_MSKA WITH KEY MATNR = GS_MCHA-MATNR
WERKS = GS_MCHA-WERKS
CHARG = GS_MCHA-CHARG
J_3ASIZE = GS_MCHA-J_3ASIZE.
GS_FINAL-VBELN = GS_MSKA-VBELN.
GS_FINAL-POSNR = GS_MSKA-POSNR.
GS_FINAL-LGORT = GS_MSKA-LGORT.
GS_FINAL-KALAB = GS_MSKA-KALAB.
READ TABLE GT_MCHB INTO GS_MCHB WITH KEY CHARG = GS_MCHA-CHARG
MATNR = GS_MCHA-MATNR.
GS_FINAL-CLABS = GS_MCHB-CLABS.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = GS_FINAL-CHARG
IMPORTING
OUTPUT = GS_FINAL-CHARG.
APPEND GS_FINAL TO GT_FINAL.
CLEAR : GS_FINAL, GS_MCHA , GS_MSKA , GS_MCHB.
11-23-2014 4:49 PM
Hallo Shrikanth,
normally the function module should work as you expected but only with numeric values. Please check if the field GS_FINAL-CHARG does not contain any character. Best to check in debugger looking at the Hex-String of the field.
Bye, Volker
11-23-2014 5:13 PM
Hi Srikanth,
I would suggest you to defined local variable of length char10 and store parameter OUTPUT value in it. Further, transfer local variable value into GS_FINAL-CHARG.
Regards,
Sudeesh Soni
11-23-2014 5:32 PM
Hello vn,
For material number conversion, the most commonly used are :
CONVERSION_EXIT_MATN1_INPUT
CONVERSION_EXIT_MATN1_OUTPUT
However, you have also some others in various function groups :
MGV_MATN3 conversion exit matn3
CONVERSION_EXIT_MATN3_INPUT Conversion exit MATN3 for LAMA
CONVERSION_EXIT_MATN3_OUTPUT Conversion exit matn3
MGV_NUMBER_CONVERSION
CONVERSION_EXIT_MATN2_INPUT
CONVERSION_EXIT_MATN2_OUTPUT
CONVERSION_EXIT_MATNV_INPUT
CONVERSION_EXIT_MATNV_OUTPUT
MG_MATN1_RANGE MATN1 Conversion with Ranges
CONVERSION_EXIT_MATN1_RANGE_I Conversion Exit MATN1, External Range -> Internal Range
CONVERSION_EXIT_MATN1_RANGE_O Conversion Exit MATN1, Internal Range -> External Range
OMCV
CONVERSION_EXIT_MATN1_INPUT
CONVERSION_EXIT_MATN1_OUTPUT
CONVERSION_EXIT_MATNL_INPUT
CONVERSION_EXIT_MATNL_OUTPUT
CONVERSION_EXIT_MATNW_INPUT
CONVERSION_EXIT_MATNW_OUTPUT
Cheers,
Alex
11-24-2014 4:47 AM
Hi Srikanth,
Could you please tell us the data type of the field GS_FINAL-CHARG.
Regards,
Satish
11-24-2014 5:49 AM
Dear Satish,
Yes , the data type is a char, which i'm considering from MCHA, but the type i'm displaying the numeric value in the report. Pls suggest how to convert the char type with leading zeros.
Best rgds/thnks,
Srikanth.
11-24-2014 7:01 AM
No. The data type is not CHAR. It is char with a specific length. Without the exact type of GS_FINAL-CHARG it is not possible to diagnose your problem.
By the way, your programming technique is not good. GS_FINAL should not be defined globally. It should be defined in the form. As a general principle the number of global variables should be kept to an absolute minimum. Secondly, FORMs are now deprecated (used in old code, but now obsolete).
11-24-2014 5:30 AM
Hi,
I think you will be referring CHARG in MCHA table which doesn't have conversion routine in its domain. But LIFNR in the same table has the same FM as conversion which you can see by clicking the domain. As mentioned already, it will work for numeric value.
If you just want leading zeros for a character, you can use unpack also as below.
data lv_1 type char10.
lv_1 = '234'.
unpack lv_1 to lv_1.
write lv_1.
11-24-2014 5:40 AM
11-24-2014 5:52 AM
Hello Sathish,
FYI.
Please note that leading zeros can be added to even char fields, for example take the field MATNR, AUFNR etc. There are so many fields which is a char field. It is about whether those fields have conversion routine declared in their respective domain.
Hope you got it.
Thanks & Regards,
Satish
11-24-2014 5:55 AM
Hi srikanth,
Is there other char besides 0~9 in string GS_FINAL-CHARG?
In my experience,only the string of puer digital can be output with leading zeros .
For example:
DATA CHAR(10) VALUE '8A9D'.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = CHAR
IMPORTING
OUTPUT = CHAR.
You will get 'CHAR = '8A9D''.
Regasds.
11-24-2014 5:58 AM
Hi,
As per my knowledge the data field which you are referrign to is of type CHAR10.
You might be facing an issue with the FM becuse of the value which it might be holding. If the value within it is only contains numbers then the FM provides appropriate output, whereas the FM doesn't work in case of alphanumeric values. Please check the simple code below which shows the difference.
DATA: lv_charg TYPE charg_d VALUE '10',
lv_charg1 TYPE charg_d VALUE '10AB'.
WRITE: / '-----------Correct----------',
/ lv_charg.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = lv_charg
IMPORTING
output = lv_charg.
WRITE: / lv_charg.
WRITE: / '-----------InCorrect----------',
/ lv_charg1.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = lv_charg1
IMPORTING
output = lv_charg1.
WRITE: / lv_charg1.
Regards,
Mayur Priyan. S
11-24-2014 6:00 AM
Hi,
If it is char, it will work.
data lv_charg type mchb-charg.
lv_charg = '1234'.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = lv_charg
IMPORTING
OUTPUT = lv_charg
.
write lv_charg.
If not, check what is happening in debugging and find what is getting passed as input and what is coming as output.
11-24-2014 6:01 AM
Hi Srikanth,
When we check the domain of the CHARG field in SE11, we find there is no conversion exit maintained for it as marked below,
Regards,
Satish
11-24-2014 6:09 AM
Hi,
it is converting the value and adding leading ZERO's but if the result is started with character it is not convering.
data lv_charg type mcha-charg.
select single charg from mcha into lv_charg where matnr = '350-100'.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = lv_charg
IMPORTING
OUTPUT = lv_charg
.
write 😕 lv_charg.
Regards
Sathish
11-24-2014 6:28 AM
Hi Srikanth,
Please use the below code it is working fine, i just checked in my system.
SHIFT lwa_charg RIGHT DELETING TRAILING space.
TRANSLATE lwa_charg USING ' 0'.
WRITE : lwa_charg.
Regards,
Satish
11-24-2014 7:05 AM
Don't use this code. It is bad programming. The correct approach is the function modules. Find out why that's not working and fix the issue.
11-24-2014 6:30 AM
The earlier step that I have mentioned can be used to find the existence of conversion routine for a field. If the domain has conversion routine then it is advisable to use the same in program.
Please get back if you still have any issues.
Regards,
Satish
11-24-2014 6:42 AM
Dear satish,
I tried the same the output is not displayed with the leading zeros..
SHIFT LV_CHARG RIGHT DELETING TRAILING space.
TRANSLATE lV_CHARG USING ' 0'.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = LV_CHARG
IMPORTING
OUTPUT = LV_CHARG.
11-24-2014 6:45 AM
Dear Srikanth,
You need not use the conversion routine at all. You can simply use my code and check the output in debugger, It will be appended with zeros.
Regards,
Satish
11-24-2014 6:46 AM
take the conversion routine 'CONVERSION_EXIT_ALPHA_INPUT' from the code. It will work. As I have mentioned below you can also use OVERLAY command instead of TRANSLATE. Both will work.
Regards,
Satish
11-24-2014 6:54 AM
Dear Srikanth,
Did you ensure that while translate command as below,
TRANSLATE lV_CHARG USING ' 0'.
there is space before zero in single quotation as ' 0'.
Regards,
Satish
11-24-2014 7:04 AM
Both will work, but the function module is the correct way. Using overlay and translate is bad programming.
11-24-2014 6:44 AM
You can also use the below command to achieve the requirement,
SHIFT lwa_charg RIGHT DELETING TRAILING space.
OVERLAY lwa_charg with '0000000000'. " Here we are overlaying with ten zeros since field length is 10.
Hope you got it. Please get back if issue still persists.
Regards,
Satish
11-24-2014 7:03 AM
This is not a good way of programming the leading zero issue. The correct way is to use conversion function modules.
11-24-2014 7:10 AM
Thanks for suggesting. Do we have function modules for this kind of scenario. If so please suggest us.
Regards,
Satish
11-24-2014 7:24 AM
Yes we do. It's called CONVERSION_EXIT_ALPHA_INPUT. This is what you should use to deal with leading zeros. Instead of casting around for other "solutions", you should figure out why the standard way of dealing with leading zeros isn't working for you.
Then fix it. This is NOT rocket science.
11-24-2014 7:09 AM
The below code will also help you in achieving your requirement, please find the Image below which shows the runtime performance,
DATA : charlength TYPE i,
final_length TYPE I,
lwa_charg TYPE mcha-charg,
lwa TYPE mcha-charg.
lwa_charg = 'ed12'.
charlength = strlen( lwa_charg ).
final_length = 10 - charlength.
lwa = lwa_charg.
DO final_length TIMES.
CONCATENATE '0' lwa INTO lwa.
ENDDO.
11-24-2014 7:25 AM
11-24-2014 7:15 AM
Hi Srikanth,
Batch field 'CHARG' need not have leading zeros . Batch value will alwyas be same in both external and internal format. (i.e. if external format has leading zeros , then internal format will have the same and vice versa).
Also the exit 'CONVERSION_EXIT_ALPHA_INPUT' will not be applicable for CHARG since this is not declared as Conversion Routine at domain level.
11-24-2014 7:20 AM
Hi arul,
Request to suggest the correct function module for to get the CHARG with leading zeros.
Best rgds/thnks,
Srikanth.
11-24-2014 7:25 AM
CONVERSION_EXIT_ALPHA_INPUT
Again. Find out why it is working for YOU and fix it. It isn't rocket science. Do not use anything else to deal with leading zeros. Unless you're going in the other direction, in which case use CONVERSION_EXIT_ALPHA_OUTPUT.
Thread locked to prevent any further useless discussion.