‎2007 May 10 6:14 PM
Hi,
I want to do selection screen validation in Abap Query.
For that iam writing error message, it is asking message class.
Please let me know how i can do input field validation in abap query.
regards,
vijay
‎2007 May 10 6:17 PM
Hello,
Please check this.
REPORT z6.
DATA digit(11) VALUE ' 0123456789'.
PARAMETERS: text(16) DEFAULT '20,000.00'.
DATA c_text(16).
DATA amount TYPE p DECIMALS 2.
DATA n TYPE n.
DATA i TYPE i.
c_text = text.
CATCH SYSTEM-EXCEPTIONS conversion_errors = 1.
MOVE c_text TO amount.
ENDCATCH.
IF sy-subrc EQ 1.
CALL FUNCTION 'PREPARE_STRING'
EXPORTING
i_valid_chars = digit
i_xvalid_check = 'X'
i_xchar_repl = 'X'
i_xtoupper = 'X'
CHANGING
c_string = c_text.
CONDENSE c_text NO-GAPS.
DESCRIBE FIELD amount DECIMALS n.
i = 10 ** n.
amount = c_text / i.
ENDIF.
WRITE:/ text, 50 amount.
Reward points if helpful.
Regards,
Deepu.K
‎2007 May 10 6:17 PM
Hello,
Please check this.
REPORT z6.
DATA digit(11) VALUE ' 0123456789'.
PARAMETERS: text(16) DEFAULT '20,000.00'.
DATA c_text(16).
DATA amount TYPE p DECIMALS 2.
DATA n TYPE n.
DATA i TYPE i.
c_text = text.
CATCH SYSTEM-EXCEPTIONS conversion_errors = 1.
MOVE c_text TO amount.
ENDCATCH.
IF sy-subrc EQ 1.
CALL FUNCTION 'PREPARE_STRING'
EXPORTING
i_valid_chars = digit
i_xvalid_check = 'X'
i_xchar_repl = 'X'
i_xtoupper = 'X'
CHANGING
c_string = c_text.
CONDENSE c_text NO-GAPS.
DESCRIBE FIELD amount DECIMALS n.
i = 10 ** n.
amount = c_text / i.
ENDIF.
WRITE:/ text, 50 amount.
Reward points if helpful.
Regards,
Deepu.K
‎2007 May 10 6:18 PM
message E001(ZGEN).
u can giuve the message class in bracket as shown above.
‎2007 May 10 6:19 PM
Hi,
REPORT ZIIEQQUOTE NO STANDARD PAGE HEADING
LINE-SIZE 150
LINE-COUNT 64
MESSAGE-ID zz . " Message Class
*---------------------------------------------------------------------
* SELECTION SCREEN
*---------------------------------------------------------------------
SELECTION-SCREEN BEGIN OF BLOCK b4 WITH FRAME TITLE text-020.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001 .
PARAMETERS: p_locl RADIOBUTTON GROUP g1 " desktop file
DEFAULT 'X' USER-COMMAND fil,
p_phys RADIOBUTTON GROUP g1. " appln server file
SELECTION-SCREEN END OF BLOCK b1.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-002 .
PARAMETERS: p_ifile TYPE dxfile-filename LOWER CASE, " source file
p_afile TYPE dxfile-filename LOWER CASE, " asset class file
p_cfile TYPE dxfile-filename LOWER CASE, " Cost center file
p_dfile TYPE dxfile-filename LOWER CASE, " Depr key file
p_ofile TYPE dxfile-filename LOWER CASE. " Audit file
SELECTION-SCREEN END OF BLOCK b2.
SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE text-015.
PARAMETERS: p_test RADIOBUTTON GROUP g2 DEFAULT 'X', " test run
p_create RADIOBUTTON GROUP g2. " data migretion
SELECTION-SCREEN END OF BLOCK b3.
SELECTION-SCREEN END OF BLOCK b4.
*---------------------------------------------------------------------
* AT SELECTION-SCREEN
*---------------------------------------------------------------------
AT SELECTION-SCREEN.
PERFORM check_screen USING p_ifile p_afile p_cfile p_dfile
p_ofile p_locl p_phys.
*&---------------------------------------------------------------------*
*& Form check_screen
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM check_screen USING p_ifile1 TYPE dxfile-filename
p_afile1 TYPE dxfile-filename
p_cfile1 TYPE dxfile-filename
p_dfile1 TYPE dxfile-filename
p_ofile1 TYPE dxfile-filename
p_locl1 TYPE any p_phys1 TYPE any .
IF sy-ucomm EQ 'FIL'.
CLEAR:p_ofile1, p_ifile1, p_afile1, p_cfile1, p_dfile1.
EXIT.
ENDIF.
IF p_ifile1 IS INITIAL.
SET CURSOR FIELD 'P_IFILE1'.
MESSAGE e000 WITH text-013.
ENDIF.
IF p_afile1 IS INITIAL.
SET CURSOR FIELD 'P_AFILE1'.
MESSAGE e000 WITH text-068.
ENDIF.
IF p_cfile1 IS INITIAL.
SET CURSOR FIELD 'P_CFILE1'.
MESSAGE e000 WITH text-069.
ENDIF.
IF p_dfile1 IS INITIAL.
SET CURSOR FIELD 'P_DFILE1'.
MESSAGE e000 WITH text-070.
ENDIF.
IF p_ofile1 IS INITIAL.
SET CURSOR FIELD 'P_OFILE1'.
MESSAGE e000 WITH text-014.
ENDIF.
IF p_phys1 EQ 'X'.
CLEAR: g_file_flag.
g_file_flag = 'I'.
PERFORM check_phys_file USING p_ifile1.
g_file_flag = 'A'.
PERFORM check_phys_file USING p_afile1.
g_file_flag = 'C'.
PERFORM check_phys_file USING p_cfile1.
g_file_flag = 'D'.
PERFORM check_phys_file USING p_dfile1.
ELSEIF p_locl1 EQ 'X'.
CLEAR: g_file_flag.
g_file_flag = 'I'.
PERFORM check_local_file USING p_ifile1.
g_file_flag = 'A'.
PERFORM check_local_file USING p_afile1.
g_file_flag = 'C'.
PERFORM check_local_file USING p_cfile1.
g_file_flag = 'D'.
PERFORM check_local_file USING p_dfile1.
ENDIF.
ENDFORM. " check_screen
*&---------------------------------------------------------------------*
*& Form check_phys_file
*&---------------------------------------------------------------------*
* Validation of Physical File
*----------------------------------------------------------------------*
FORM check_phys_file USING p_file TYPE any.
DATA: l_str(300) TYPE c.
CLEAR l_str.
OPEN DATASET p_file IN TEXT MODE FOR INPUT ENCODING DEFAULT.
IF sy-subrc <> 0.
IF g_file_flag = 'I'.
MESSAGE e000 WITH text-021.
ELSEIF g_file_flag = 'A'.
MESSAGE e000 WITH text-095.
ELSEIF g_file_flag = 'C'.
MESSAGE e000 WITH text-096.
ELSEIF g_file_flag = 'D'.
MESSAGE e000 WITH text-097.
ENDIF.
ENDIF.
READ DATASET p_file INTO l_str.
IF sy-subrc <> 0.
IF g_file_flag = 'I'.
MESSAGE e000 WITH text-017.
ELSEIF g_file_flag = 'A'.
MESSAGE e000 WITH text-098.
ELSEIF g_file_flag = 'C'.
MESSAGE e000 WITH text-099.
ELSEIF g_file_flag = 'D'.
MESSAGE e000 WITH text-100.
ENDIF.
ENDIF.
CLEAR: g_file_flag.
CLOSE DATASET p_file.
ENDFORM. " check_phys_file
*&---------------------------------------------------------------------*
*& Form check_local_file
*&---------------------------------------------------------------------*
* Validation of Local File
*----------------------------------------------------------------------*
FORM check_local_file USING p_file TYPE any.
DATA: l_size TYPE i.
CLEAR: l_size.
CALL FUNCTION 'TMP_GUI_GET_FILE_EXIST'
EXPORTING
fname = p_file
IMPORTING
* exist = l_exist
filesize = l_size
EXCEPTIONS
fileinfo_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
IF g_file_flag = 'I'.
MESSAGE e000 WITH text-016.
ELSEIF g_file_flag = 'A'.
MESSAGE e000 WITH text-101.
ELSEIF g_file_flag = 'C'.
MESSAGE e000 WITH text-102.
ELSEIF g_file_flag = 'D'.
MESSAGE e000 WITH text-103.
ENDIF.
ENDIF.
IF l_size IS INITIAL.
IF g_file_flag = 'I'.
MESSAGE e000 WITH text-024.
ELSEIF g_file_flag = 'A'.
MESSAGE e000 WITH text-107.
ELSEIF g_file_flag = 'C'.
MESSAGE e000 WITH text-108.
ELSEIF g_file_flag = 'D'.
MESSAGE e000 WITH text-109.
ENDIF.
ENDIF.
CLEAR: g_file_flag.
ENDFORM. " check_local_fileRegards
Sudheer
‎2007 May 10 7:50 PM
Hi there. You can create your own message class and include it in the REPORT statement as others have shown above. To create your own message class, go to transaction SE91. Enter a name for your class; it should start with Z. Now click on the "Create" button. Choose a package to assign to the message class (usually whatever package you use for program changes should be okay) and save. Now go to the "Messages" tab. Here you can create your messages. Then when you want to reference the message in your program, you would use something like
MESSAGE e001. " use the three digit number of your message
Use an E before the number for an error message, a W for a warning message, or an I for an informational message. I hope this helps.
- April King