0% found this document useful (0 votes)
18 views12 pages

Zanytable Update

Uploaded by

abm.ramesh0112
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views12 pages

Zanytable Update

Uploaded by

abm.ramesh0112
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 12

*&---------------------------------------------------------------------*

*& Report ZANYTABLE_UPDATE


*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT zanytable_update.

TYPE-POOLS: slis.
DATA: subrc TYPE sy-subrc,
it_flds TYPE lvc_t_fcat,
wa_flds LIKE LINE OF it_flds,
is_lvc_cat TYPE lvc_s_fcat,
new_table TYPE REF TO data,
new_line TYPE REF TO data,
f_name TYPE string,
v_uname TYPE sy-uname,
ico TYPE string,
it_lvc_cat TYPE lvc_t_fcat,
ques TYPE string,
butxt TYPE string,
ans,
v_name TYPE string,
v_path TYPE string,
v_fullpath TYPE string,
v_filter TYPE string,
v_uact TYPE i,
v_guiobj TYPE REF TO cl_gui_frontend_services,
v_filename TYPE string,
it_fcat TYPE lvc_t_fcat,
wa_fcat LIKE LINE OF it_fcat,
nm(40),
wa_retab LIKE zzretab,
retab TYPE ddshretval OCCURS 1 WITH HEADER LINE,
valtab TYPE zzupdinfty OCCURS 0 WITH HEADER LINE,
BEGIN OF fcat1 OCCURS 1,
fldnm(60),
END OF fcat1,
BEGIN OF fcat OCCURS 1,
fldnm(60),
dty(4),
len(6),
END OF fcat,
rpbenerr TYPE rpbenerr OCCURS 0,
BEGIN OF sum_tab OCCURS 1,
srno(9),
subrc TYPE sy-subrc,
stat(10),
END OF sum_tab,
srno(9) TYPE c,
gd_layout TYPE slis_layout_alv,
fldcat TYPE slis_t_fieldcat_alv,
fc TYPE slis_t_fieldcat_alv WITH HEADER LINE.

DATA: BEGIN OF wa_user,


paramval TYPE char100,
END OF wa_user,
it_user LIKE TABLE OF wa_user.

FIELD-SYMBOLS: <itab> TYPE table,


<pannnn_wa> TYPE any,
<pannnn_wa1> TYPE any,
<fcat> TYPE STANDARD TABLE.

SELECTION-SCREEN BEGIN OF BLOCK rad1 WITH FRAME TITLE tit.


PARAMETER tab_name TYPE dd02l-tabname OBLIGATORY.
SELECTION-SCREEN COMMENT 66(79) chk.
PARAMETER file TYPE rlgrap-filename.
PARAMETER opr TYPE zzdelm-zzdelm1.

SELECTION-SCREEN SKIP 1.
SELECTION-SCREEN PUSHBUTTON /1(60) name2 USER-COMMAND cust
VISIBLE LENGTH 21.
SELECTION-SCREEN PUSHBUTTON 25(55) name USER-COMMAND fif
VISIBLE LENGTH 12.
SELECTION-SCREEN END OF BLOCK rad1.

AT SELECTION-SCREEN OUTPUT.

"Start:Addition of Auth. Object as part of BDO changes abm3708.


INITIALIZATION.
"START : Addition of authorization object as per SAP recommendations
CALL FUNCTION 'AUTHORITY_CHECK_TCODE'
EXPORTING
tcode = 'ZTABLEUPD'
EXCEPTIONS
ok = 1
not_ok = 2
OTHERS = 3.

IF sy-subrc <> 1.
MESSAGE e172(00) WITH 'ZTABLEUPD'.
ENDIF.
"END : Addition of authorization object as per SAP recommendations
"End:Addition of Auth. Object as part of BDO changes by abm3708.

tit = 'Custom Selection'.


CALL FUNCTION 'ICON_CREATE'
EXPORTING
name = 'ICON_EXPORT'
text = TEXT-001
info = TEXT-002
add_stdinf = 'X'
IMPORTING
result = name
EXCEPTIONS
icon_not_found = 0
outputfield_too_short = 0
OTHERS = 0.

IF retab[] IS INITIAL.
ico = 'ICON_ENTER_MORE'.
ELSE.
ico = 'ICON_DISPLAY_MORE'.
ENDIF.
CALL FUNCTION 'ICON_CREATE'
EXPORTING
name = ico
text = 'Custom Field selection'
* INFO = TEXT-004
add_stdinf = 'X'
IMPORTING
result = name2
EXCEPTIONS
icon_not_found = 0
outputfield_too_short = 0
OTHERS = 0.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR file .

PERFORM f4_help.

CLEAR subrc.
CALL FUNCTION 'DB_EXISTS_TABLE'
EXPORTING
tabname = tab_name
IMPORTING
subrc = subrc.

IF subrc NE 0.
MESSAGE 'The table doesnt exist in the SAP database' TYPE 'S'.
STOP.
ENDIF.

AT SELECTION-SCREEN.
CALL FUNCTION 'HR_BEN_GET_TEXT_TABLE_NAME'
EXPORTING
tabname = tab_name
reaction = 'X'
IMPORTING
text = chk
* SUBRC =
TABLES
error_table = rpbenerr.

* if sy-subrc NE 0.
* MESSAGE 'You are not Authorized to run this program' type 'E'.
* else.
IF tab_name <> 'PA0008'." AND TAB_NAME <> 'PA0014'. "AND TAB_NAME <> 'PA0015' .
* IF sy-uname = 'SFJ_ABAP2' or sy-uname = 'C20050673' or sy-uname = v_uname.
CASE sy-ucomm.
WHEN 'ONLI'.
IF file IS NOT INITIAL.
IF opr EQ 'INS' OR opr EQ 'DEL' OR opr EQ 'MOD'.

PERFORM tab.
PERFORM ltable.
CLEAR: <pannnn_wa>,<itab>.
REFRESH <itab>.

IF retab[] IS NOT INITIAL.


f_name = file.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = f_name
filetype = 'ASC'
has_field_separator = '*'
* HEADER_LENGTH = 0
* READ_BY_LINE = 'X'
* DAT_MODE = ' '
* CODEPAGE = ' '
* IGNORE_CERR = ABAP_TRUE
* REPLACEMENT = '#'
* CHECK_BOM = ' '
* VIRUS_SCAN_PROFILE =
* NO_AUTH_CHECK = ' '
* IMPORTING
* FILELENGTH =
* HEADER =
TABLES
data_tab = <itab>
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.
TRY.
cl_abap_dyn_prg=>check_table_name_str(
EXPORTING
val = tab_name " Input that
shall be checked
packages = '' " Package to which the
table shall belong
RECEIVING
val_str = tab_name " Same as the
input
).
CATCH cx_abap_not_a_table. " The value is not the name of a DB
table
CATCH cx_abap_not_in_package. " The table is not in the given
package
ENDTRY.
CLEAR srno.
LOOP AT <itab> ASSIGNING <pannnn_wa>.
srno = srno + 1.
sum_tab-srno = srno.
MOVE-CORRESPONDING <pannnn_wa> TO <pannnn_wa1>.

IF opr EQ 'INS'.
INSERT (tab_name) FROM <pannnn_wa1>.
ELSEIF opr EQ 'DEL'.
DELETE (tab_name) FROM <pannnn_wa1>.
ELSEIF opr EQ 'MOD'.
UPDATE (tab_name) FROM <pannnn_wa1>.
ENDIF.
sum_tab-subrc = sy-subrc.
IF sy-subrc EQ 0.
sum_tab-stat = 'Sucsess'.
ELSE.
sum_tab-stat = 'Failed'.
ENDIF.
APPEND sum_tab.
CLEAR: <pannnn_wa1>, sum_tab.
ENDLOOP.

IF sy-subrc EQ 0.
MESSAGE 'Requested action executed' TYPE 'S'.
PERFORM alv_display.
ENDIF.
ELSE.
MESSAGE 'Please specify fields' TYPE 'S'.
ENDIF.

ELSE.
MESSAGE 'Please select valid operation' TYPE 'S'.
STOP.
ENDIF.

ELSE.
MESSAGE 'Please specify file' TYPE 'S'.
STOP.
ENDIF.

WHEN 'CUST'.
PERFORM fldlist.

WHEN 'FIF'.

ques = 'Please select from the following file formats available.'.


CONCATENATE 'Table' tab_name INTO butxt SEPARATED BY space.
CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
titlebar = 'Download file format'
* DIAGNOSE_OBJECT = ' '
text_question = ques
text_button_1 = butxt
* ICON_BUTTON_1 = ' '
text_button_2 = 'Cust format'
* ICON_BUTTON_2 = ' '
* DEFAULT_BUTTON = '1'
display_cancel_button = 'X'
* USERDEFINED_F1_HELP = ' '
* START_COLUMN = 25
* START_ROW = 6
* POPUP_TYPE =
* IV_QUICKINFO_BUTTON_1 = ' '
* IV_QUICKINFO_BUTTON_2 = ' '
IMPORTING
answer = ans
* TABLES
* PARAMETER =
EXCEPTIONS
text_not_found = 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.

IF ans EQ '1' OR ans EQ '2'.


IF ans EQ '2' AND retab[] IS INITIAL.
MESSAGE 'Please select fields' TYPE 'S'.
STOP.
ENDIF.
CONCATENATE 'Table' tab_name 'file format' INTO v_name SEPARATED
BY space.
IF ans EQ '2'.
CONCATENATE 'Custom' v_name INTO v_name SEPARATED BY space.
ENDIF.
CREATE OBJECT v_guiobj.
CALL METHOD v_guiobj->file_save_dialog
EXPORTING
default_extension = 'xls'
default_file_name = v_name
file_filter = 'Microsoft Excel Workbook'
CHANGING
filename = v_name
path = v_path
fullpath = v_fullpath
user_action = v_uact.

IF v_uact = v_guiobj->action_cancel.
EXIT.
ENDIF.
* CONCATENATE 'P' IFT INTO tb_name.
PERFORM file_format.
PERFORM tab.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
* BIN_FILESIZE =
filename = v_fullpath
filetype = 'ASC'
* APPEND = ' '
write_field_separator = '*'
* HEADER = '00'
* TRUNC_TRAILING_BLANKS = ' '
* WRITE_LF = 'X'
* COL_SELECT = ' '
* COL_SELECT_MASK = ''
* DAT_MODE = ' '
* CONFIRM_OVERWRITE = ' '
* NO_AUTH_CHECK = ' '
* CODEPAGE = ' '
* IGNORE_CERR = ABAP_TRUE
* REPLACEMENT = '#'
* WRITE_BOM = ' '
* TRUNC_TRAILING_BLANKS_EOL = 'X'
* WK1_N_FORMAT = ' '
* WK1_N_SIZE = ' '
* WK1_T_FORMAT = ''
* WK1_T_SIZE = ' '
* WRITE_LF_AFTER_LAST_LINE = ABAP_TRUE
* SHOW_TRANSFER_STATUS = ABAP_TRUE
* IMPORTING
* FILELENGTH =
TABLES
data_tab = <fcat>
fieldnames = fcat1
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.
STOP.
ENDIF.

CLEAR fcat1.
REFRESH: <fcat>,fcat1.
ENDIF.

ENDCASE.
* ELSE.
* MESSAGE 'You are not Authorized to run this program' type 'E'.
* ENDIF.
ELSE.
MESSAGE 'You are not Authorized to Change' TYPE 'E'.
ENDIF.
* endif.
*&---------------------------------------------------------------------*
*& Form TAB
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM tab.

TYPES: BEGIN OF lty_databuffer,


tabname TYPE tabname,
tabref TYPE REF TO data,
strucref TYPE REF TO data,
END OF lty_databuffer.

STATICS: st_databuffer TYPE HASHED TABLE OF lty_databuffer


WITH UNIQUE KEY tabname.
DATA: l_databuffer TYPE lty_databuffer.

CREATE DATA l_databuffer-tabref TYPE TABLE OF (tab_name).


CREATE DATA l_databuffer-strucref TYPE (tab_name).
INSERT l_databuffer INTO TABLE st_databuffer.
ASSIGN l_databuffer-tabref->* TO <itab>.
ASSIGN l_databuffer-tabref->* TO <fcat>.
ASSIGN l_databuffer-strucref->* TO <pannnn_wa>.
ASSIGN l_databuffer-strucref->* TO <pannnn_wa1>.
ENDFORM. "TAB

*&---------------------------------------------------------------------*
*& Form FLDLIST
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM fldlist.
CLEAR: it_flds,retab.
REFRESH: it_flds,retab,valtab.
*CONCATENATE CHK 'Infotype Field list' INTO NM SEPARATED BY SPACE.

CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'


EXPORTING
i_structure_name = tab_name
CHANGING
ct_fieldcat = it_flds
EXCEPTIONS
OTHERS = 1.

LOOP AT it_flds INTO wa_flds.

valtab-fldnm = wa_flds-fieldname.
valtab-fldtxt = wa_flds-scrtext_l.
APPEND valtab.
CLEAR: wa_flds,valtab.
ENDLOOP.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
ddic_structure = 'ZZUPDINFTY'
retfield = 'FLDNM'
* PVALKEY = ' '
* DYNPPROG = ' '
* DYNPNR =
* DYNPROFIELD =
* STEPL =
window_title = nm
* VALUE = ' '
value_org = 'S'
multiple_choice = 'X'
* DISPLAY = ' '
callback_program = sy-repid
* CALLBACK_FORM =
* MARK_TAB =
* IMPORTING
* USER_RESET =
TABLES
value_tab = valtab
* FIELD_TAB =
return_tab = retab
* DYNPFLD_MAPPING =
EXCEPTIONS
parameter_error = 1
no_values_found = 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.
STOP.
ENDIF.
ENDFORM. "FLDLIST

*&---------------------------------------------------------------------*
*& Form LTABLE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM ltable.

IF retab[] IS NOT INITIAL.

LOOP AT retab.

is_lvc_cat-fieldname = retab-fieldval.
is_lvc_cat-ref_field = retab-fieldval.
is_lvc_cat-ref_table = tab_name.
APPEND is_lvc_cat TO it_lvc_cat.
ENDLOOP.

CALL METHOD cl_alv_table_create=>create_dynamic_table


EXPORTING
it_fieldcatalog = it_lvc_cat
IMPORTING
ep_table = new_table.
ASSIGN new_table->* TO <itab>.
CREATE DATA new_line LIKE LINE OF <itab>.
ASSIGN new_line->* TO <pannnn_wa>.

ENDIF.

ENDFORM. "LTABLE

*&---------------------------------------------------------------------*
*& Form f4_help
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM f4_help .

CALL FUNCTION 'F4_FILENAME'


EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
field_name = 'FILE'
IMPORTING
file_name = file.

ENDFORM. "f4_help

*&---------------------------------------------------------------------*
*& Form FILE_FORMAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM file_format.

CLEAR: fcat,it_fcat,wa_fcat,fcat1.
REFRESH: fcat,it_fcat,fcat1.
* CONCATENATE 'P' IFT INTO table_name.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = tab_name
CHANGING
ct_fieldcat = it_fcat
EXCEPTIONS
OTHERS = 1.

IF ans EQ '2'.
LOOP AT retab.
READ TABLE it_fcat INTO wa_fcat WITH KEY fieldname =
retab-fieldval.
IF sy-subrc EQ 0.
fcat1-fldnm = wa_fcat-scrtext_m.
fcat1-fldnm = wa_fcat-scrtext_l.
APPEND fcat1.
CLEAR fcat1.
CLEAR wa_fcat.
ENDIF.
ENDLOOP.

ELSE.
LOOP AT it_fcat INTO wa_fcat.

IF wa_fcat-scrtext_l IS NOT INITIAL.


fcat1-fldnm = wa_fcat-scrtext_l.
ELSEIF wa_fcat-scrtext_m IS NOT INITIAL.
fcat1-fldnm = wa_fcat-scrtext_m.
ELSE.
fcat1-fldnm = wa_fcat-fieldname.
ENDIF.
APPEND fcat1.
CLEAR: fcat1.
ENDLOOP.
ENDIF.

ENDFORM. "FILE_FORMAT

*&---------------------------------------------------------------------*
*& Form ALV_DISPLAY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM alv_display.

IF sum_tab[] IS NOT INITIAL.


gd_layout-colwidth_optimize = 'X'.

fc-col_pos = 1.
fc-fieldname = 'SRNO'.
fc-seltext_l = 'Record No'.
fc-tabname = 'SUM_TAB'.
APPEND fc TO fldcat.
CLEAR fc.

fc-col_pos = 2.
fc-fieldname = 'STAT'.
fc-seltext_l = 'Status'.
fc-tabname = 'SUM_TAB'.
APPEND fc TO fldcat.
CLEAR fc.

fc-col_pos = 3.
fc-fieldname = 'SUBRC'.
fc-seltext_l = 'SY-SUBRC'.
fc-tabname = 'SUM_TAB'.
APPEND fc TO fldcat.
CLEAR fc.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'


EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER = ' '
* I_BUFFER_ACTIVE = ' '
i_callback_program = sy-repid
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
* I_CALLBACK_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_END_OF_LIST = ' '
* I_STRUCTURE_NAME =
* I_BACKGROUND_ID = ' '
* I_GRID_TITLE =
* I_GRID_SETTINGS =
is_layout = gd_layout
it_fieldcat = fldcat
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
i_default = 'X'
i_save = 'X'
* IS_VARIANT =
* IT_EVENTS =
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* IT_ALV_GRAPHICS =
* IT_HYPERLINK =
* IT_ADD_FIELDCAT =
* IT_EXCEPT_QINFO =
* I_HTML_HEIGHT_TOP =
* I_HTML_HEIGHT_END =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = sum_tab
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.

ELSE.
MESSAGE 'File is empty' TYPE 'S'.
ENDIF.
CLEAR: sum_tab,fldcat.
REFRESH: sum_tab,fldcat.

ENDFORM. "ALV_DISPLAY

You might also like