Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Module pool screen field conversion/representation

Former Member
0 Likes
2,043

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

1 ACCEPTED SOLUTION
Read only

RaymondGiuseppi
Active Contributor
0 Likes
1,379

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

8 REPLIES 8
Read only

Former Member
0 Likes
1,379

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.

Read only

0 Likes
1,379

Hallo Tiki,

Thanks a ton for your reply.

I will get back to you after I have performed the necessary tests.

Best Regards,KC

Read only

RaymondGiuseppi
Active Contributor
0 Likes
1,380

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

Read only

0 Likes
1,379

Hallo Raymond,

Thank you very much for your reply. I guess Message types are not permitted inside conversion exits.

Please confirm.

warm regards,

KC

Read only

0 Likes
1,379

you have to handle the messages through exceptions i think.

Read only

0 Likes
1,379

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

Read only

0 Likes
1,379

Hello Raymond,

Thanks for your valuable inputs. I could get the desired result.

warm regards,

Keerthi

Read only

0 Likes
1,379

Hallo Tiki,

Thanks for your time and inputs. Your answer was very helpful.

Warm Regards,Keerthi