SAP ABAP - Upload and Download Custom Program Template with BDS
Open OAOR transaction Code
execute and upload excel file
Create ABAP Program with this Code
*&---------------------------------------------------------------------*
*& Report YUPLOAD_TEST
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT yupload_test.
START-OF-SELECTION.
CALL SCREEN 100.
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
SET PF-STATUS 'PF100'.
SET TITLEBAR 'TL100'.
ENDMODULE.
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
CASE sy-ucomm.
WHEN 'BACK'.
LEAVE PROGRAM.
WHEN 'DNLD'.
PERFORM popup_download_template.
ENDCASE.
ENDMODULE.
FORM popup_download_template.
TYPES : BEGIN OF ty_output,
itext TYPE intxt,
comp_id TYPE bds_compid,
checkbox(1),
END OF ty_output.
DATA :
it_output TYPE STANDARD TABLE OF ty_output INITIAL SIZE 0,
wa_output TYPE ty_output,
li_signature LIKE STANDARD TABLE OF bapisignat WITH HEADER LINE,
li_all_connections LIKE STANDARD TABLE OF bdn_con WITH HEADER LINE,
li_files LIKE bapifiles OCCURS 5 WITH HEADER LINE,
classname TYPE bapibds01-classname,
classtype TYPE bapibds01-classtype,
objkey TYPE swotobjid-objkey.
DATA:
ls_fieldcat TYPE slis_fieldcat_alv,
lt_fieldcat TYPE slis_t_fieldcat_alv,
ls_fieldcatlog TYPE slis_fieldcat_alv,
lt_fieldcatlog TYPE slis_t_fieldcat_alv,
lt_layout TYPE slis_layout_alv.
DATA fu_filepath TYPE string.
DATA destop TYPE string.
DATA fc_path_document TYPE string.
DATA : lv_logical_system LIKE bapibds01-log_system,
lv_oldpath TYPE string,
lv_newpath TYPE string,
lv_subrc TYPE i.
REFRESH : it_output, li_signature, li_all_connections.
classname = 'SOFFICEINTEGRATION'.
classtype = 'OT'.
objkey = 'ZTEMPLATES'.
"Get file Signature
CALL FUNCTION 'BDS_ALL_CONNECTIONS_GET'
EXPORTING
* LOGICAL_SYSTEM = LV_LOGICAL_SYSTEM
classname = classname
classtype = classtype
objkey = objkey
client = sy-mandt
* ALL = ' '
TABLES
signature = li_signature
all_connections = li_all_connections.
REFRESH :lt_fieldcat.
*Appending the selected values to the output table
CLEAR li_all_connections.
LOOP AT li_all_connections.
wa_output-itext = li_all_connections-descript.
wa_output-comp_id = li_all_connections-comp_id.
APPEND wa_output TO it_output.
CLEAR wa_output.
CLEAR li_all_connections.
ENDLOOP.
CLEAR ls_fieldcat.
ls_fieldcat-row_pos = '1'.
ls_fieldcat-col_pos = '1'.
ls_fieldcat-fieldname = 'CHECKBOX'.
ls_fieldcat-tabname = 'IT_OUTPUT'.
ls_fieldcat-seltext_m = 'SELECT'.
APPEND ls_fieldcat TO lt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-row_pos = '1'.
ls_fieldcat-col_pos = '2'.
ls_fieldcat-fieldname = 'ITEXT'.
ls_fieldcat-tabname = 'IT_OUTPUT'.
ls_fieldcat-seltext_m = 'DESCRIPTION'.
ls_fieldcat-outputlen = 50.
APPEND ls_fieldcat TO lt_fieldcat.
* Display data in a POPUP
CALL FUNCTION 'REUSE_ALV_POPUP_TO_SELECT'
EXPORTING
i_zebra = 'X'
it_fieldcat = lt_fieldcat
i_tabname = 'IT_OUTPUT'
i_checkbox_fieldname = 'CHECKBOX'
TABLES
t_outtab = it_output.
*Appending the selected infotypes only to internal table
READ TABLE it_output WITH KEY checkbox = 'X' TRANSPORTING NO FIELDS.
IF sy-subrc = 0.
CALL METHOD cl_gui_frontend_services=>get_desktop_directory
CHANGING
desktop_directory = destop.
CALL METHOD cl_gui_frontend_services=>directory_browse
EXPORTING
window_title = 'Title'
initial_folder = destop
CHANGING
selected_folder = fu_filepath.
REFRESH li_files.
LOOP AT it_output INTO wa_output WHERE checkbox = 'X'.
CLEAR li_signature.
READ TABLE li_signature[] INTO li_signature
WITH KEY prop_name = 'DESCRIPTION' prop_value = wa_output-itext.
CLEAR li_files.
li_files-doc_count = li_signature-doc_count.
li_files-comp_id = wa_output-comp_id.
li_files-directory = fu_filepath.
APPEND li_files.
CLEAR wa_output.
ENDLOOP.
CALL FUNCTION 'BDS_BUSINESSDOCUMENT_GET_FILES'
EXPORTING
logical_system = lv_logical_system
classname = classname
classtype = classtype
client = sy-mandt
object_key = objkey
TABLES
files = li_files
signature = li_signature
EXCEPTIONS
nothing_found = 1
error_kpro = 2
internal_error = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 RAISING internal_error.
ENDIF.
ENDIF.
ENDFORM.
Test program
Comments
Post a Comment