‎2015 Feb 05 8:56 AM
Hello ABAP Gurus,
I hope you would be able to provide some input for this issue that i am facing.
I have the following requirement:-
in a module pool selection screen, a field 10 Char long needs to be represented as 13 Char.
For Eg. if i enter 123456789Y and press enter, it should be converted to 123-456-78-9Y.
This conversion is just for representation, but in the database, it should be saved as 123456789Y.
How can I achieve this? I tried writing a conversion exit input and output, but I am not sure how to validate my screen field first before converting it into the required format.
Validation for eg: if a user enters more than 10 Char, then error message, any special characters also error. Whhere can I validate? Inside the conversion or in PAI?
Please share your knowledge.
Warm Regards,KC
‎2015 Feb 05 10:21 AM
You can execute your check in the input conversion exit, sample :
FUNCTION conversion_exit_zrgs_input.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(INPUT)
*" EXPORTING
*" VALUE(OUTPUT)
*"----------------------------------------------------------------------
DATA: lv_text TYPE c LENGTH 13.
IF input CN '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ- '.
MESSAGE 'Invalid character(s)' TYPE 'E'.
ENDIF.
lv_text = input.
TRANSLATE lv_text USING '- '.
CONDENSE lv_text NO-GAPS.
IF strlen( lv_text ) GT 10.
MESSAGE 'Too many characters' TYPE 'E'.
ENDIF.
output = lv_text.
ENDFUNCTION.FUNCTION CONVERSION_EXIT_ZRGS_OUTPUT.
*"--------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(INPUT)
*" EXPORTING
*" VALUE(OUTPUT)
*"--------------------------------------------------------------------
CONCATENATE input+0(3) '-' input+3(3) '-' input+6(2) '-' input+8(2) INTO output.
ENDFUNCTION.Regards,
Raymond
‎2015 Feb 05 9:38 AM
Hi, you can validate the field in PAI itself before converting the string as below:
CASE sy-ucomm.
WHEN 'ENTE'.
IF strlen( inp ) > 10.
MESSAGE 'Enter only 10 characters' TYPE 'S' DISPLAY LIKE 'E'.
exit.
ENDIF.
CONCATENATE inp+0(3) inp+4(3) inp+7(2) inp+9(2) INTO inp1
SEPARATED BY '-'.
inp = inp1.
ENDCASE.
where inp is the screen field name. you can similarly put check for special characters.
‎2015 Feb 05 1:09 PM
Hallo Tiki,
Thanks a ton for your reply.
I will get back to you after I have performed the necessary tests.
Best Regards,KC
‎2015 Feb 05 10:21 AM
You can execute your check in the input conversion exit, sample :
FUNCTION conversion_exit_zrgs_input.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(INPUT)
*" EXPORTING
*" VALUE(OUTPUT)
*"----------------------------------------------------------------------
DATA: lv_text TYPE c LENGTH 13.
IF input CN '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ- '.
MESSAGE 'Invalid character(s)' TYPE 'E'.
ENDIF.
lv_text = input.
TRANSLATE lv_text USING '- '.
CONDENSE lv_text NO-GAPS.
IF strlen( lv_text ) GT 10.
MESSAGE 'Too many characters' TYPE 'E'.
ENDIF.
output = lv_text.
ENDFUNCTION.FUNCTION CONVERSION_EXIT_ZRGS_OUTPUT.
*"--------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(INPUT)
*" EXPORTING
*" VALUE(OUTPUT)
*"--------------------------------------------------------------------
CONCATENATE input+0(3) '-' input+3(3) '-' input+6(2) '-' input+8(2) INTO output.
ENDFUNCTION.Regards,
Raymond
‎2015 Feb 05 1:06 PM
Hallo Raymond,
Thank you very much for your reply. I guess Message types are not permitted inside conversion exits.
Please confirm.
warm regards,
KC
‎2015 Feb 05 1:20 PM
‎2015 Feb 05 1:23 PM
Just look at some standard conversion-exits that raise errors for technical format (look for date or time exit as CONVERSION_EXIT_GLDAT_INPUT) or conversion exit that rely on a database table (as CONVERSION_EXIT_MATN1_INPUT) those raise errors.
NB: Remember those INPUT FM are implicitly called in the PAI, so raising an error is correct, of course when you use those in a program, then use exception error_message. (Note also I did not raise any error in the OUTPUT FM, as it is executed in PBO (or WRITE statements) where error messages can trigger strange behavior...)
Regards,
Raymond
‎2015 Feb 12 1:47 PM
Hello Raymond,
Thanks for your valuable inputs. I could get the desired result.
warm regards,
Keerthi
‎2015 Feb 12 1:48 PM
Hallo Tiki,
Thanks for your time and inputs. Your answer was very helpful.
Warm Regards,Keerthi