2020 May 31 10:58 AM
Hello,
I have created one ztable and i want to apply validation message on 'DATE' Field in TMG that the date should be day after today. (i.e ztable-tripdat eq ( sy-datum + 1 ) ).
I have written below code , But it neither accepting any date. always giving error message on any date. Also have an another issue after pressing "ENTER" it gets save in table and if press on "SAVE" icon , then and then gives error message.Please check my code once.
FORM ZVALIDATE_ENTRY.
* DATA: TRIPDAT TYPE ZTOM_ZDAILY2-TRIPDAT.
DATA lwa_row TYPE ZTOM_ZDAILY2.
LOOP AT total.
clear lwa_row.
if <vim_total_struc> is ASSIGNED.
MOVE-CORRESPONDING <vim_total_struc> to lwa_row.
endif.
if <action> NE 'N' and <action> is NOT INITIAL." and <action> NE 'U'.
if + lwa_row-tripdat NE ( sy-datum + 1 ).
MESSAGE 'Enter Correct Date' TYPE 'S' DISPLAY LIKE 'E'.
vim_abort_saving = 'X'.
exit.
endif.
endif.
ENDLOOP.
ENDFORM.
2020 May 31 12:01 PM
There's a failure in the rendering:
if+ lwa_row-tripdat NE(sy-datum +1).
2020 May 31 1:49 PM
Hey nandini_borse
Didn't you mean to do something like this?
LOOP AT total ASSIGNING <vim_total_struc>. " <-- assign table row to field-symbol
if <vim_total_struc> is ASSIGNED.
MOVE-CORRESPONDING <vim_total_struc> to lwa_row.
endif.
Otherwise I do not see any use for the LOOP AT total. Also, the <vim_total_struc> value is otherwise unknown.
If you actually did mean to do that, then I'd propose to modify your code a bit.
FORM ZVALIDATE_ENTRY.
if <action> = 'N' OR <action> IS INITIAL." and <action> NE 'U'.
" don't check
RETURN.
ENDIF.
DATA(lv_tomorrow) = sy-datum + 1.
" do not allow to save
" if there is any record with TRIPDAT not tomorrow
LOOP AT total ASSIGNING <vim_total_struc>
WHERE tripdat NE lv_tomorrow.
MESSAGE 'Enter Correct Date' TYPE 'S' DISPLAY LIKE 'E'.
vim_abort_saving = 'X'.
RETURN. " <-- exit from the FORM
ENDLOOP.
ENDFORM.
Kind regards,
Mateusz2020 May 31 5:39 PM
Your code doesn't compile: TOTAL is a generic internal table, it doesn't contain TRIPDAT you have to cast it first.
2020 May 31 6:01 PM
Welp, an information about TOTAL internal table and <vim_total_struc> field-symbol types would be helpful.
Anyhow, a dynamic structure creation might help.
DATA:
ld_row TYPE REF TO data.
FIELD-SYMBOLS:
<ls_row> TYPE any.
CREATE DATA ld_row LIKE LINE OF total.
ASSIGN ld_row->* TO <ls_row>.
LOOP AT total ASSIGNING <ls_row>.
MOVE-CORRESPONDING <ls_row> TO lwa_row.
CHECK lwa_row-tripdat NE lv_tomorrow.
ENDLOOP.
Kind regards,
Mateusz
2020 May 31 6:41 PM
If it's a dialog concerning a table, the structure of lines of TOTAL will be made of one component LINE of a length depending on the number of bytes of the columns of the table (possible lengths: 4096, 512, 256, 128, 64, 48, 32), and <VIM_TOTAL_STRUC> is assigned by SAP this way (maintview is a table name if the dialog is on a table):
ASSIGN total TO <vim_total_struc> CASTING TYPE (x_header-maintview).