Professional Documents
Culture Documents
IMP Report ZMM01 Validate, Display ALV, Post, Download Error
IMP Report ZMM01 Validate, Display ALV, Post, Download Error
*&---------------------------------------------------------------------*
*& Include
ZMM01_VALIDATE_POST_TOP
*&---------------------------------------------------------------------*
type-pools slis.
types : begin of ty_alv,
matnr type matnr,
mtart type mtart,
mbrsh type mbrsh,
meins type meins,
en_desc type maktx,
*&---------------------------------------------------------------------*
*& Include
ZMM01_VALIDATE_POST_SCR
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Include
ZMM01_VALIDATE_POST_CODEX
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&
Form f4_help_src
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM f4_help_src .
if p_pre = 'X'.
data p_app(255) type c.
CALL FUNCTION 'GUI_FILE_LOAD_DIALOG'
EXPORTING
WINDOW_TITLE
= 'Please select the file to load....'
*
DEFAULT_EXTENSION
=
*
DEFAULT_FILE_NAME
=
*
WITH_ENCODING
=
*
FILE_FILTER
=
*
INITIAL_DIRECTORY
=
IMPORTING
*
FILENAME
=
*
PATH
=
FULLPATH
= p_src
*
USER_ACTION
=
*
FILE_ENCODING
=
.
else.
*
*
*
*
*
*
*
OTHERS
=3
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
p_src = p_app.
endif.
ENDFORM.
" f4_help_src
*&---------------------------------------------------------------------*
*&
Form load_file
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM load_file .
if p_pre = 'X'.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME
= p_src
*
HAS_FIELD_SEPARATOR
=''
TABLES
DATA_TAB
= t_load
EXCEPTIONS
FILE_OPEN_ERROR
=1
FILE_READ_ERROR
=2
NO_BATCH
=3
GUI_REFUSE_FILETRANSFER
=4
INVALID_TYPE
=5
NO_AUTHORITY
=6
UNKNOWN_ERROR
=7
BAD_DATA_FORMAT
=8
HEADER_NOT_ALLOWED
=9
SEPARATOR_NOT_ALLOWED
= 10
HEADER_TOO_LONG
= 11
UNKNOWN_DP_ERROR
= 12
ACCESS_DENIED
= 13
DP_OUT_OF_MEMORY
= 14
DISK_FULL
= 15
DP_TIMEOUT
= 16
OTHERS
= 17
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
ENDFORM.
" load_file
*&---------------------------------------------------------------------*
*&
Form validate_file
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM validate_file .
" For validations
types : begin of ty_mara,
matnr type matnr,
end of ty_mara,
begin of ty_t134,
mtart type mtart,
end of ty_t134,
begin of ty_t137,
mbrsh type mbrsh,
end of ty_t137,
begin of ty_t006,
MSEHI type MSEHI,
end of ty_t006.
data : t_mara type STANDARD TABLE OF ty_mara INITIAL SIZE 1,
t_t134 type STANDARD TABLE OF ty_t134 INITIAL SIZE 1,
if sy-subrc = 0.
w_alv-signal = '@09@'. " yellow
w_alv-chk = ' '.
" Chkbox will be un-checked
w_alv-err_desc = 'Material already exists. change the material'.
MODIFY t_alv from w_alv INDEX sy-tabix TRANSPORTING signal chk err_desc.
endif.
else.
w_alv-signal = '@09@'.
" yellow
w_alv-chk = 'X'.
" Chkbox will be un-checked
w_alv-err_desc = 'Beware ! Material Number is blank.'.
MODIFY t_alv from w_alv INDEX sy-tabix TRANSPORTING signal chk err_desc.
endif.
******* validation of MTART
if w_alv-mtart is INITIAL.
w_alv-signal = '@0A@'.
" red
w_alv-chk = '-'.
w_alv-err_desc = 'Material Type cann''t be Blank'.
modify t_alv from w_alv TRANSPORTING signal chk err_desc.
continue.
" Exit the current loop pass
else.
read TABLE t_t134 into w_t134 with KEY mtart = w_alv-mtart BINARY SEARCH.
if sy-subrc <> 0.
w_alv-signal = '@0A@'.
" red
w_alv-chk = '-'.
w_alv-err_desc = 'Material Type is not Valid'.
modify t_alv from w_alv TRANSPORTING signal chk err_desc .
continue.
endif.
endif.
*
w_alv-signal = '@0A@'.
" red
w_alv-chk = '-'.
w_alv-err_desc = 'UOM is Blank'.
modify t_alv from w_alv TRANSPORTING signal chk err_desc.
continue.
" Exit the current loop pass
else.
read TABLE t_t006 into w_t006 with KEY msehi = w_alv-meins BINARY SEARCH.
if sy-subrc <> 0.
w_alv-signal = '@0A@'.
" red
w_alv-chk = '-'.
w_alv-err_desc = 'UOM is not Valid'.
modify t_alv from w_alv TRANSPORTING signal chk err_desc .
CLEAR W_alv.
continue.
endif.
endif.
if w_alv-en_desc is INITIAL and w_alv-desc2 is INITIAL.
w_alv-signal = '@0A@'.
" red
w_alv-chk = '-'.
w_alv-err_desc = 'Atleast one description is mandatory.'.
modify t_alv from w_alv TRANSPORTING signal chk err_desc.
add 1 to v_index.
CONTINUE.
ENDIF.
** either both should be there or none of them.
if w_alv-lang2 is not INITIAL and w_alv-desc2 is INITIAL.
CLEAR W_alv.
w_alv-signal = '@0A@'.
" red
w_alv-chk = '-'.
w_alv-err_desc = 'Second lang is there but description is blank.'.
modify t_alv from w_alv TRANSPORTING signal chk err_desc.
CONTINUE.
endif.
***** either both should be there or none of them.
if w_alv-lang2 is INITIAL and w_alv-desc2 is not INITIAL.
CLEAR W_alv.
w_alv-signal = '@0A@'.
" red
w_alv-chk = '-'.
w_alv-err_desc = 'Second lang is blank but description is there.'.
modify t_alv from w_alv TRANSPORTING signal chk err_desc.
CONTINUE.
endif.
w_alv-signal = '@08@'.
" green
w_alv-chk = 'X'.
modify t_alv from w_alv TRANSPORTING signal chk .
endloop.
ENDFORM.
" validate_file
*&---------------------------------------------------------------------*
*&
Form display_alv
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM display_alv .
PERFORM sub_fill_fcat.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM
= sy-repid
I_CALLBACK_PF_STATUS_SET
= 'MYPF'
I_CALLBACK_USER_COMMAND
= 'MYCMD'
*
I_CALLBACK_TOP_OF_PAGE
=''
IT_FIELDCAT
= t_fcat
TABLES
T_OUTTAB
= t_alv
EXCEPTIONS
PROGRAM_ERROR
=1
OTHERS
=2
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM.
" display_alv
*&---------------------------------------------------------------------*
*&
Form MYPF
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
*
-->VAR
text
*----------------------------------------------------------------------*
FORM MYPF USING var.
set pf-status 'ZRZPF'.
endform.
"MYPF
*&---------------------------------------------------------------------*
*&
Form MYCMD
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
*
-->UCOM
text
*
-->RS
text
*----------------------------------------------------------------------*
FORM MYCMD USING UCOM type sy-ucomm
RS type slis_selfield.
* **** Loopig at T_alv table to separate the correct & error records
loop at t_alv into w_alv.
*** Separating the Error records(i.e.where red signal is there & chkbox is not there)
** into T_error
if w_alv-chk = '-'.
CONCATENATE w_alv-matnr
w_alv-mtart
w_alv-mbrsh
w_alv-meins
w_alv-en_desc
w_alv-lang2
w_alv-desc2 INTO w_error SEPARATED BY ','.
append w_error to T_error. " T_error table contains all eror records
" in Notepad file format
endif.
" So passing this table to GUI_DOWNLD will dwnld
" the eror recrds.
*
OR
" Other way is to Pass T_MSG in Call xactn syntax only
*** Separating the Correct(green or yellow ) records into T_post
*** In this scenario v r posting that records (only green or yellow) where CHECKBOX
is ticked.
if w_alv-chk = 'X'.
append w_alv to t_post. " T_post will contain only that records which r to be
posted.
CLEAR w_alv.
endif.
endloop.
case ucom.
when 'DOWNLOAD'.
perform download_error_rec.
when 'POST'.
if p_real = 'X'.
perform post_green_rec.
perform download_error_post.
endif.
endcase.
rs-refresh = 'X'.
ENDFORM.
"MYCMD
*&---------------------------------------------------------------------*
*&
Form download_error_rec
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM download_error_rec .
data s_path type string.
data f_name type string.
** data count(2) type n VALUE 1.
CONCATENATE sy-datum sy-uzeit 'error_rec' into f_name .
** add 1 to count.
CALL FUNCTION 'GUI_FILE_SAVE_DIALOG'
EXPORTING
WINDOW_TITLE
= 'Provide the path to download Error Files first b4 Posting
'
*
*
*
*
*
*
*
DEFAULT_EXTENSION
= '.txt'
DEFAULT_FILE_NAME
= f_name
WITH_ENCODING
=
FILE_FILTER
=
INITIAL_DIRECTORY
=
IMPORTING
FILENAME
=
PATH
=
FULLPATH
= s_path
USER_ACTION
=
FILE_ENCODING
=
.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
FILENAME
= s_path
TABLES
DATA_TAB
= t_error
EXCEPTIONS
FILE_WRITE_ERROR
=1
NO_BATCH
=2
GUI_REFUSE_FILETRANSFER = 3
INVALID_TYPE
=4
NO_AUTHORITY
=5
UNKNOWN_ERROR
=6
HEADER_NOT_ALLOWED
=7
SEPARATOR_NOT_ALLOWED = 8
FILESIZE_NOT_ALLOWED = 9
HEADER_TOO_LONG
= 10
DP_ERROR_CREATE
= 11
DP_ERROR_SEND
= 12
DP_ERROR_WRITE
= 13
UNKNOWN_DP_ERROR
= 14
ACCESS_DENIED
= 15
DP_OUT_OF_MEMORY
= 16
DISK_FULL
= 17
DP_TIMEOUT
= 18
FILE_NOT_FOUND
= 19
DATAPROVIDER_EXCEPTION = 20
CONTROL_FLUSH_ERROR
= 21
OTHERS
= 22.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM.
" download_error_rec
*&---------------------------------------------------------------------*
*&
Form sub_fill_fcat
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM sub_fill_fcat .
perform
perform
perform
perform
perform
perform
perform
perform
perform
perform
fill_fcat
fill_fcat
fill_fcat
fill_fcat
fill_fcat
fill_fcat
fill_fcat
fill_fcat
fill_fcat
fill_fcat
USING
USING
USING
USING
USING
USING
USING
USING
USING
USING
'SIGNAL' 'SIGNAL_LIGHT'
''
5.
'CHK'
'CHECKBOX'
'X'
10.
'MATNR' 'MATERIAL NO.'
'X'
20.
'MTART' 'MATERIAL TYPE'
'X'
6.
'MBRSH' 'INDUSTRY SEC'
'X'
3.
'MEINS' 'UOM'
'X'
5.
'EN_DESC' 'ENG_DESC'
'X'
15.
'LANG2' '2nd LANG'
'X'
5.
'DESC2' '2ND DESC'
'X'
20.
'ERR_DESC' 'ERROR DESCRIPTION' ''
50.
ENDFORM.
" sub_fill_fcat
*&---------------------------------------------------------------------*
*&
Form fill_fcat
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
*
-->P_0693 text
*
-->P_0694 text
*
-->P_0695 text
*
-->P_0696 text
*
-->P_5
text
*----------------------------------------------------------------------*
FORM fill_fcat USING VALUE(P_fnam)
VALUE(P_text)
VALUE(P_edit)
VALUE(P_len).
clear w_fcat.
w_fcat-fieldname = P_fnam.
w_fcat-seltext_m = P_text.
w_fcat-edit = P_edit.
if w_fcat-fieldname = 'CHK'.
w_fcat-checkbox = 'X'.
endif.
w_fcat-outputlen = P_len.
append w_fcat to t_fcat.
ENDFORM.
" fill_fcat
*&---------------------------------------------------------------------*
*&
Form sub_screen
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM sub_screen .
loop AT SCREEN.
if P_ser <> 'X'and screen-group1 = 'ID1'. " This screen-active will work on ......
screen-active = '0'.
" what 'ID' u passes in screen-group1
MODIFY SCREEN.
" or what 'Name' u passes in screen-name.
endif.
if P_MODE <> 'X'and screen-group1 = 'ID2' .
screen-active = '0'.
MODIFY SCREEN.
endif.
endloop.
ENDFORM.
" sub_screen
*&---------------------------------------------------------------------*
*& Include
ZMM01_VALIDATE_POST_BDC
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&
Form post_green_rec
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM post_green_rec .
data l_grid type ref to cl_gui_alv_grid.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
E_GRID = l_grid.
CALL METHOD L_GRID->CHECK_CHANGED_DATA.
ENDFORM.
" post_green_rec
*&---------------------------------------------------------------------*
*&
Form sub_download_error
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM download_error_post .
data ls_path type string.
data f_name type string.
CONCATENATE sy-datum sy-uzeit 'error_rec' into f_name .
CALL FUNCTION 'GUI_FILE_SAVE_DIALOG'
EXPORTING
WINDOW_TITLE
= 'Provide the path to download Error File '
DEFAULT_EXTENSION
= '.txt'
DEFAULT_FILE_NAME
= f_name
*
WITH_ENCODING
=
*
FILE_FILTER
=
*
INITIAL_DIRECTORY
=
IMPORTING
*
FILENAME
=
*
PATH
=
FULLPATH
= ls_path
*
USER_ACTION
=
*
FILE_ENCODING
=
.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
FILENAME
= ls_path
TABLES
DATA_TAB
= T_err_post
EXCEPTIONS
FILE_WRITE_ERROR
=1
NO_BATCH
=2
GUI_REFUSE_FILETRANSFER = 3
INVALID_TYPE
=4
NO_AUTHORITY
=5
UNKNOWN_ERROR
=6
HEADER_NOT_ALLOWED
=7
SEPARATOR_NOT_ALLOWED = 8
FILESIZE_NOT_ALLOWED = 9
HEADER_TOO_LONG
= 10
DP_ERROR_CREATE
= 11
DP_ERROR_SEND
= 12
DP_ERROR_WRITE
= 13
UNKNOWN_DP_ERROR
= 14
ACCESS_DENIED
= 15
DP_OUT_OF_MEMORY
= 16
DISK_FULL
= 17
DP_TIMEOUT
= 18
FILE_NOT_FOUND
= 19
DATAPROVIDER_EXCEPTION = 20
CONTROL_FLUSH_ERROR
= 21
OTHERS
= 22.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM.
" download_error_post
*&---------------------------------------------------------------------*
*&
Form fill_bdc
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM fill_bdc .
PERFORM FILL_BDC_SCRN USING 'SAPLMGMM' '0060'.
PERFORM FILL_BDC_FLD USING 'BDC_OKCODE' '=AUSW'.
" Okcode of SELECT
VIEW Button
PERFORM FILL_BDC_FLD USING 'RMMG1-MATNR' W_post-MATNR.
PERFORM FILL_BDC_FLD USING 'RMMG1-MBRSH' W_post-MBRSH.
PERFORM FILL_BDC_FLD USING 'RMMG1-MTART' W_post-MTART.
PERFORM FILL_BDC_SCRN USING 'SAPLMGMM' '0070'.
PERFORM FILL_BDC_FLD USING 'BDC_OKCODE' '=ENTR'.
" Okcode of ENTER
Button
PERFORM FILL_BDC_FLD USING 'MSICHTAUSW-KZSEL(01)' 'X'.
perform FILL_BDC_SCRN
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
*
-->VALUE(P_FNAM) text
*
-->VALUE(P_FVAL) text
*----------------------------------------------------------------------*
FORM FILL_BDC_FLD USING VALUE(P_FNAM)
VALUE(P_FVAL).
clear w_bdc.
w_bdc-fnam = p_fnam.
w_bdc-fval = p_fval.
append w_bdc to t_bdc.
ENDFORM.
"FILL_BDC_FLD