You are on page 1of 19

*-------------------------------------------------------------------*

*& Report ZMM01_VALIDATE_POST


*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZMM01_VALIDATE_POST.
INCLUDE ZMM01_VALIDATE_POST_top.
INCLUDE ZMM01_VALIDATE_POST_scr.
INCLUDE ZMM01_VALIDATE_POST_codex.
INCLUDE ZMM01_VALIDATE_POST_bdc.
AT SELECTION-SCREEN on VALUE-REQUEST FOR p_src.
Perform f4_help_src.
AT SELECTION-SCREEN OUTPUT.
PERFORM sub_screen.
START-OF-SELECTION.
Perform load_file.
PERFORM validate_file.
End-of-SELECTION.
PERFORM display_alv.

*&---------------------------------------------------------------------*
*& 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,

lang2 type spras,


desc2 type maktx,
signal(4) type c,
chk type c,
err_desc type string,
END OF ty_alv,
begin of ty_load,
line(200) type c,
end of ty_load,
begin of ty_error,
line(250) type c,
end of ty_error.
data : T_alv type STANDARD TABLE OF ty_alv INITIAL SIZE 1,
w_alv type ty_alv,
t_alv_TMP type STANDARD TABLE OF ty_alv INITIAL SIZE 1.
data : t_post type STANDARD TABLE OF ty_alv INITIAL SIZE 1,
w_post type ty_alv.
*data T_err_msg type STANDARD TABLE OF ty_alv.
data : T_error type STANDARD TABLE OF ty_error INITIAL SIZE 1,
w_error type ty_error.
data : T_err_post type STANDARD TABLE OF ty_error INITIAL SIZE 1,
w_err_post type ty_error.
data : T_load type STANDARD TABLE OF ty_load INITIAL SIZE 1,
w_load type ty_load.
data : t_fcat type slis_t_fieldcat_alv,
w_fcat type slis_fieldcat_alv.
data : t_bdc type STANDARD TABLE OF bdcdata INITIAL SIZE 1,
w_bdc type bdcdata.
data : T_MSG type STANDARD TABLE OF bdcmsgcoll INITIAL SIZE 1,
w_msg type bdcmsgcoll.

*&---------------------------------------------------------------------*
*& Include
ZMM01_VALIDATE_POST_SCR
*&---------------------------------------------------------------------*

SELECTION-SCREEN begin of BLOCK b1 WITH FRAME TITLE text-006..


SELECTION-SCREEN skip.
SELECTION-SCREEN begin of BLOCK b2 WITH FRAME TITLE text-008.
SELECTION-SCREEN skip.
SELECTION-SCREEN begin of BLOCK b5 WITH FRAME.
PARAMETERS p_pre RADIOBUTTON GROUP r1 DEFAULT 'X' USER-COMMAND U.
PARAMETERS p_app RADIOBUTTON GROUP r1.
SELECTION-SCREEN begin of line.
PARAMETERS p_ser AS CHECKBOX USER-COMMAND flag1 .
SELECTION-SCREEN COMMENT 4(45) text-010 FOR FIELD p_ser .
SELECTION-SCREEN end of line.
SELECTION-SCREEN end of BLOCK b5.
SELECTION-SCREEN skip.
SELECTION-SCREEN begin of BLOCK b3 WITH FRAME TITLE text-009 .
SELECTION-SCREEN skip.
SELECTION-SCREEN begin of BLOCK b6 WITH FRAME .
PARAMETERS p_test RADIOBUTTON GROUP r2 DEFAULT 'X' USER-COMMAND U
MODIF ID id1.
PARAMETERS p_real RADIOBUTTON GROUP r2 MODIF ID id1.
SELECTION-SCREEN begin of line .
PARAMETERS p_mode AS CHECKBOX USER-COMMAND flag1 MODIF ID id1.
SELECTION-SCREEN COMMENT 4(47) text-011 FOR FIELD p_mode MODIF ID id1.
SELECTION-SCREEN end of line.
SELECTION-SCREEN end of BLOCK b6.
SELECTION-SCREEN skip.
SELECTION-SCREEN begin of BLOCK b4 WITH FRAME TITLE text-007 .
SELECTION-SCREEN skip.
SELECTION-SCREEN begin of BLOCK b7 WITH FRAME .
PARAMETERS : p_src type string MODIF ID id2.
***
p_error type string,
***
p_arc type string.
SELECTION-SCREEN skip.
SELECTION-SCREEN end of BLOCK b7.
SELECTION-SCREEN end of BLOCK b4.
SELECTION-SCREEN end of BLOCK b3 .
SELECTION-SCREEN end of BLOCK b2 .
SELECTION-SCREEN end of BLOCK b1 .

*&---------------------------------------------------------------------*
*& 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.

*
*
*
*
*
*
*

CALL FUNCTION 'F4_DXFILENAME_TOPRECURSION'


EXPORTING
I_LOCATION_FLAG
= 'A'
I_SERVER
= 'A'
I_PATH
=
FILEMASK
= '*.*'
FILEOPERATION
= 'R'
IMPORTING
O_LOCATION_FLAG
=
O_SERVER
=
O_PATH
= p_app
ABEND_FLAG
=
EXCEPTIONS
RFC_ERROR
=1
ERROR_WITH_GUI
=2

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

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.


ENDIF.
else.
open DATASET
endif.
loop at t_load into w_load.
" t_load contains flat file contents
split w_load-line at ',' into w_alv-matnr
w_alv-mtart
w_alv-mbrsh
w_alv-meins
w_alv-en_desc
w_alv-lang2
w_alv-desc2.
append w_alv to t_alv.
clear w_alv.
endloop.

" Now v hav to validate T_alv

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,

t_t137 type STANDARD TABLE OF ty_t137 INITIAL SIZE 1,


t_t006 type STANDARD TABLE OF ty_t006 INITIAL SIZE 1,
w_mara type ty_mara,
w_t134 type ty_t134,
w_t137 type ty_t137,
w_t006 type ty_t006.
data v_index type sy-index VALUE 1.
data count type i value 1.
select matnr from mara into TABLE t_mara
FOR ALL ENTRIES IN t_alv where matnr = t_alv-matnr.
if sy-subrc = 0.
sort t_mara by matnr.
endif.
t_alv_TMP[] = t_ALV[].
SORT T_alv_TMP by mtart.
delete ADJACENT DUPLICATES FROM T_alv_TMP comparing mtART.
select mtaRT from t134 into TABLE t_t134
FOR ALL ENTRIES IN t_alv_TMP where mtart = t_alv_TMP-mtart.
if sy-subrc = 0.
sort t_t134 by mtart.
endif.
REFRESH T_alv_tmp.
select mbrsh from t137 into TABLE t_t137
FOR ALL ENTRIES IN t_alv where mbrsh = t_alv-mbrsh.
if sy-subrc = 0.
sort t_t137 by mbrsh.
endif.
select MSEHI from t006 into TABLE t_t006
FOR ALL ENTRIES IN t_alv where msehi = t_alv-meins.
if sy-subrc = 0.
sort t_t006 by msehi.
endif.

******* On the basis of t_file , v r filling t_alv table


LOOP at t_alv into w_alv.
******** validation of MATNR
if w_alv-matnr is not INITIAL.
read TABLE t_mara into w_mara with KEY matnr = w_alv-matnr BINARY SEARCH.

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.
*

******* validation of MBRSH


if w_alv-mbrsh is INITIAL.
w_alv-signal = '@0A@'.
" red
w_alv-chk = '-'.
w_alv-err_desc = 'Industry Sector is Blank'.
modify t_alv from w_alv TRANSPORTING signal chk err_desc.
continue.
" Exit the current loop pass
else.
read TABLE t_t137 into w_t137 with KEY mbrsh = w_alv-mbrsh BINARY SEARCH.
if sy-subrc <> 0.
w_alv-signal = '@0A@'.
" red
w_alv-chk = '-'.
w_alv-err_desc = 'Industry Sector is not Valid'.
modify t_alv from w_alv TRANSPORTING signal chk err_desc .
continue.
endif.
endif.

******* validation of MEINS


if w_alv-meins is INITIAL.

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.

*** Posting the records by saying CALL TRANSACTION.


LOOP at t_post into w_post.
PERFORM fill_bdc.
** This Call Xactn will be called once for every records
CALL TRANSACTION 'MM01' USING T_BDC MODE 'A' MESSAGES INTO T_MSG.
if sy-subrc = 0.
READ TABLE T_MSG INTO w_msg with key MSGTYP = 'E'.
if sy-subrc = 0.
CONCATENATE w_post-matnr
w_post-mtart
w_post-mbrsh
w_post-meins
w_post-en_desc
w_post-lang2
w_post-desc2 INTO w_err_post SEPARATED BY ','.
append w_err_post to T_err_post. " T_err_post table Contains 1 field only with
type line(250).
endif.
endif.
refresh t_bdc.
clear w_post.
endloop.

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

using 'SAPLMGMM' '4004'.

if w_post-lang2 is INITIAL and w_post-desc2 is INITIAL.


perform FILL_BDC_FLD using 'BDC_OKCODE' '=BU'.
" Okcode of Save
button
perform FILL_BDC_FLD using 'MAKT-MAKTX' w_post-en_desc.
perform FILL_BDC_FLD using 'MARA-MEINS' w_post-meins.
exit.
else.
PERFORM FILL_BDC_FLD USING 'BDC_OKCODE' '=ZU01'.
" Okcode of
Additional data button
IF W_post-en_desc IS INITIAL.
W_post-en_desc = 'DUMMYDESC'.
PERFORM FILL_BDC_FLD USING 'MAKT-MAKTX' W_post-en_desc.
ELSE.
PERFORM FILL_BDC_FLD USING 'MAKT-MAKTX' W_post-en_desc.
ENDIF.
PERFORM FILL_BDC_FLD USING 'MARA-MEINS' W_post-MEINS.
endif.
perform FILL_BDC_SCRN using 'SAPLMGMM' '4300'.
perform FILL_BDC_FLD using 'BDC_OKCODE' '=BU'.
" Okcode of Save button
if W_post-en_desc = 'DUMMYDESC'.
perform FILL_BDC_FLD using 'SKTEXT-SPRAS(01)' W_post-lang2.
perform FILL_BDC_FLD using 'SKTEXT-MAKTX(01)' W_post-desc2.
else.
perform FILL_BDC_FLD using 'SKTEXT-SPRAS(02)' W_post-lang2.
perform FILL_BDC_FLD using 'SKTEXT-MAKTX(02)' W_post-desc2.
endif.
ENDFORM.
" fill_bdc
*&---------------------------------------------------------------------*
*&
Form FILL_BDC_SCRN
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
*
-->VALUE(P_PGM) text
*
-->VALUE(P_SCRN) text
*----------------------------------------------------------------------*
FORM FILL_BDC_SCRN USING VALUE(P_PGM)
VALUE(P_SCRN).
clear w_bdc.
w_bdc-program = p_pgm.
w_bdc-dynpro = p_scrn.
w_bdc-dynbegin = 'X'.
append w_bdc to t_bdc.
ENDFORM.
"FILL_BDC_SCRN
*&---------------------------------------------------------------------*
*&
Form FILL_BDC_FLD

*&---------------------------------------------------------------------*
*
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