2013 Jul 03 1:36 PM
Hi Abaper,
I want to use GUI_UPLOAD function module to load some data.
My program must be dynamic.
The table will contain my data is a parameter (p_table).
My internal table must be created dynamically.
Look my code :
ref_rowtype ?= cl_abap_typedescr=>describe_by_name( p_table ).
gi_tabdescr[] = ref_rowtype->components[].
LOOP AT gi_tabdescr INTO wa_tabdescr.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = wa_tabdescr-name.
wa_fieldcat-datatype = wa_tabdescr-type_kind.
wa_fieldcat-inttype = wa_tabdescr-type_kind.
wa_fieldcat-intlen = wa_tabdescr-length.
wa_fieldcat-decimals = wa_tabdescr-decimals.
APPEND wa_fieldcat TO gi_fieldcat.
ENDLOOP.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = gi_fieldcat
IMPORTING
ep_table = lo_dtable.
ASSIGN lo_dtable->* TO <fs_table>.
Now how to use GUI_UPLOAD ???
I can't use field-symbol ...
I have my table in my FS but i can't use it.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = p_file
filetype = 'DAT'
has_field_separator = 'X'
TABLES
data_tab = <fs_table>.
I hope i'm clear about my problem.
Thank you in advance for your help.
Youri
2013 Jul 03 9:21 PM
Hi Youri,
It can be your fieldsymbol definition. It should be TYPE STANDARD TABLE for use GUI_UPLOAD function. Also you can do it with CL_GUI_FRONTEND_SERVICES:
DATA: lr_struct TYPE REF TO cl_abap_structdescr,
lr_table TYPE REF TO cl_abap_tabledescr,
lr_data TYPE REF TO data,
lv_file TYPE string.
FIELD-SYMBOLS <table> TYPE ANY.
lr_struct ?= cl_abap_typedescr=>describe_by_name( 'MARA' ).
lr_table = cl_abap_tabledescr=>create( p_line_type = lr_struct ).
CREATE DATA lr_data TYPE HANDLE lr_table.
ASSIGN lr_data->* TO <table>.
cl_gui_frontend_services=>gui_upload(
EXPORTING filename = lv_file
has_field_separator = abap_true
CHANGING data_tab = <table> ).
In this example I create a data of table type MARA an filled from a csv (missing part where it retrieves the file name). In this case <table> can be TYPE ANY, TYPE ANY TABLE or TYPE STANDARD TABLE and it will still work.
Regards,
Alex
Hi Youri,
It can be your fieldsymbol definition. It should be TYPE STANDARD TABLE for use GUI_UPLOAD function. Also you can do it with CL_GUI_FRONTEND_SERVICES:
DATA: lr_struct TYPE REF TO cl_abap_structdescr,
lr_table TYPE REF TO cl_abap_tabledescr,
lr_data TYPE REF TO data,
lv_file TYPE string.
FIELD-SYMBOLS <table> TYPE ANY.
lr_struct ?= cl_abap_typedescr=>describe_by_name( 'MARA' ).
lr_table = cl_abap_tabledescr=>create( p_line_type = lr_struct ).
CREATE DATA lr_data TYPE HANDLE lr_table.
ASSIGN lr_data->* TO <table>.
cl_gui_frontend_services=>gui_upload(
EXPORTING filename = lv_file
has_field_separator = abap_true
CHANGING data_tab = <table> ).
In this example I create a data of table type MARA an filled from a csv (missing part where it retrieves the file name). In this case <table> can be TYPE ANY, TYPE ANY TABLE or TYPE STANDARD TABLE and it will still work.
Regards,
Alex
2013 Jul 03 4:52 PM
Hi
this works fine for me
FIELD-SYMBOLS : <wfv_structname> TYPE typename , " Nom de la table
<wft_table> TYPE table , " Table interne dyn
CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
filename = p_file
filetype = 'DAT'
TABLES
data_tab = <wft_table>
EXCEPTIONS
OTHERS = 10.
IF sy-subrc NE space.
WRITE : /3 text-003.
ENDIF.
regards
Fred
PS : the full code could be more simple to understand
REPORT ZBC_SAUVEGARDE_TABLE
NO STANDARD PAGE HEADING.
*------------------------------- TABLES -------------------------------*
TABLES : dd02t.
*-------------------------------- DATA --------------------------------*
DATA : wt_fieldcat TYPE lvc_t_fcat ,
ws_fieldcat TYPE lvc_s_fcat ,
BEGIN OF wt_tablist OCCURS 0 ,
tabname TYPE tabname ,
ddtext TYPE as4text ,
END OF wt_tablist .
FIELD-SYMBOLS : <wfv_structname> TYPE typename , " Nom de la table
<wft_table> TYPE table , " Table interne dyn
<wfs_structure> TYPE ANY . " Structure de la table
*-------------------------- SELECTION SCREEN --------------------------*
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-t01.
PARAMETERS : p_table TYPE tabname ,
p_max type i .
SELECTION-SCREEN END OF BLOCK b1.
SELECTION-SCREEN SKIP 1.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-t02.
PARAMETERS : p_imp RADIOBUTTON GROUP ra1 ,
p_exp RADIOBUTTON GROUP ra1
DEFAULT 'X' ,
p_clear AS CHECKBOX .
SELECTION-SCREEN END OF BLOCK b2.
SELECTION-SCREEN SKIP 1.
SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE text-t03.
PARAMETERS : p_file TYPE localfile
OBLIGATORY .
SELECTION-SCREEN SKIP 1.
PARAMETERS : p_excl RADIOBUTTON GROUP ra2 ,
p_flat RADIOBUTTON GROUP ra2 .
SELECTION-SCREEN END OF BLOCK b3.
*-------------------------------- MAIN --------------------------------*
START-OF-SELECTION.
* Vérification des options de sélection.
PERFORM p_check.
* Déchargement de la table.
IF p_exp EQ 'X'.
PERFORM p_dechargement.
* Chargement de la table.
ELSE.
PERFORM p_chargement.
ENDIF.
END-OF-SELECTION.
*----------------------------------------------------------------------*
* Form P_CHECK. *
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
FORM p_check.
DATA : wlv_tabname TYPE tabname.
* Verifie que la table existe.
SELECT tabname
UP TO 1 ROWS
INTO wlv_tabname
FROM dd02t
WHERE tabname EQ p_table
AND as4local EQ 'A'.
ENDSELECT.
IF sy-subrc NE space.
WRITE : /3 text-001.
STOP.
ENDIF.
* On ne traite que le chargement des tables Z*.
IF p_imp EQ 'X' AND p_table+0(1) NE 'Z'
and sy-uname ne 'FRFGIROD'.
WRITE : /1 text-007.
STOP.
ENDIF.
ENDFORM. " P_CHECK.
*----------------------------------------------------------------------*
* Form P_DECHARGEMENT. *
*----------------------------------------------------------------------*
* Déchargement de la table. *
*----------------------------------------------------------------------*
FORM p_dechargement.
* Création de la table interne dynamique du type de la table.
PERFORM p_create_dyntable
USING p_table.
* Lecture de la table ( et oui un joli select * ! )
SELECT *
up to p_max rows
INTO TABLE <wft_table>
FROM (p_table).
* Si déchargen en format Excel.
IF p_excl EQ 'X'.
CALL FUNCTION 'SAP_CONVERT_TO_XLS_FORMAT'
EXPORTING
i_filename = p_file
TABLES
i_tab_sap_data = <wft_table>
EXCEPTIONS
conversion_failed = 1
OTHERS = 2.
IF sy-subrc NE space.
WRITE : /3 text-003.
ENDIF.
* Si fichier plat.
ELSEIF p_flat EQ 'X'.
CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
filename = p_file
filetype = 'DAT'
TABLES
data_tab = <wft_table>
EXCEPTIONS
OTHERS = 10.
IF sy-subrc NE space.
WRITE : /3 text-003.
ENDIF.
ENDIF.
ENDFORM. " P_DECHARGEMENT.
*----------------------------------------------------------------------*
* Form P_CHARGEMENT. *
*----------------------------------------------------------------------*
* Chargement. *
*----------------------------------------------------------------------*
FORM p_chargement.
DATA : wlv_count_col TYPE i ,
wlv_flag_row TYPE kcd_ex_row_n ,
wlt_file TYPE TABLE OF alsmex_tabline
WITH HEADER LINE ,
wlv_char1 TYPE char1.
FIELD-SYMBOLS : <wlfv_field> TYPE ANY.
* Création de la table interne dynamique du type de la table.
PERFORM p_create_dyntable
USING p_table.
* Lecture du fichier.
* Si déchargen en format Excel.
IF p_excl EQ 'X'.
* Seek number of column.
DESCRIBE TABLE wt_fieldcat LINES wlv_count_col.
* Function to read the Microsoft Excel file.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = p_file
i_begin_col = '1'
i_begin_row = '1'
i_end_col = wlv_count_col
i_end_row = '10000'
TABLES
intern = wlt_file
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.
IF sy-subrc NE space.
WRITE : /3 text-003.
STOP.
ENDIF.
* Set data.
LOOP AT wlt_file.
IF wlt_file-row NE wlv_flag_row.
MOVE wlt_file-row TO wlv_flag_row.
IF wlt_file-row NE 1.
APPEND <wfs_structure> TO <wft_table>.
CLEAR <wfs_structure>.
ENDIF.
ENDIF.
READ TABLE wt_fieldcat
INTO ws_fieldcat
INDEX wlt_file-col.
CHECK sy-subrc EQ space.
ASSIGN COMPONENT ws_fieldcat-fieldname
OF STRUCTURE <wfs_structure>
TO <wlfv_field>.
CATCH SYSTEM-EXCEPTIONS conversion_errors = 1.
MOVE wlt_file-value TO <wlfv_field>.
ENDCATCH.
IF sy-subrc EQ 1.
" A FAIRE
ENDIF.
ENDLOOP.
* Append last time.
APPEND <wfs_structure> TO <wft_table>.
* Si fichier plat.
ELSEIF p_flat EQ 'X'.
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
filename = p_file
filetype = 'DAT'
TABLES
data_tab = <wft_table>
EXCEPTIONS
OTHERS = 10.
IF sy-subrc NE space.
WRITE : /3 text-003.
STOP.
ENDIF.
ENDIF.
* Si vide la table avant.
IF p_clear EQ 'X'.
* Verification avant la suppression de la table.
CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
titlebar = text-004
text_question = text-005
IMPORTING
answer = wlv_char1
EXCEPTIONS
text_not_found = 1
OTHERS = 2.
IF wlv_char1 EQ '2'.
STOP.
ENDIF.
* On supprime tout.
DELETE FROM (p_table).
IF sy-subrc NE space.
WRITE : /3 text-003.
STOP.
ENDIF.
ENDIF.
* Chargement de la base.
MODIFY (p_table) FROM TABLE <wft_table>.
IF sy-subrc NE space.
WRITE : /3 text-003.
STOP.
ENDIF.
ENDFORM. " P_CHARGEMENT.
*----------------------------------------------------------------------*
* Form P_CREATE_DYNTABLE. *
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
FORM p_create_dyntable
USING wpv_tabname TYPE tabname.
DATA : wlt_table TYPE REF TO data ,
wls_table TYPE REF TO data .
* On assigne le nom de la table.
IF <wfv_structname> IS ASSIGNED.
UNASSIGN <wfv_structname>.
ENDIF.
ASSIGN wpv_tabname TO <wfv_structname>.
* Recherche de la description du dictionnaire.
REFRESH wt_fieldcat.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = <wfv_structname>
i_bypassing_buffer = 'X'
CHANGING
ct_fieldcat = wt_fieldcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc NE space.
WRITE : /1 text-003.
STOP.
ENDIF.
* Création de la table interne dynamique.
IF <wft_table> IS ASSIGNED.
UNASSIGN <wft_table>.
ENDIF.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = wt_fieldcat
IMPORTING
ep_table = wlt_table.
ASSIGN wlt_table->* TO <wft_table>.
* Création de la structure du type de la table.
IF <wfs_structure> IS ASSIGNED.
UNASSIGN <wfs_structure>.
ENDIF.
CREATE DATA wls_table LIKE LINE OF <wft_table>.
ASSIGN wls_table->* TO <wfs_structure>.
ENDFORM. " P_CREATE_DYNTABLE.
*------------------------------- EVENTS -------------------------------*
* Au démarage de l'application.
INITIALIZATION.
* On desactive la zone vider la table, elle n'est active que pour
* le chargement.
LOOP AT SCREEN.
IF screen-name EQ 'P_CLEAR'.
MOVE '0' TO screen-active.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
* A l'événement rafraichissement de l'écran.
AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN.
* Si on charge alors on active la zone P_CLEAR.
IF p_imp EQ 'X'.
IF screen-name EQ 'P_CLEAR'.
MOVE '1' TO screen-active.
MODIFY SCREEN.
ENDIF.
ELSE.
IF screen-name EQ 'P_CLEAR'.
MOVE '0' TO screen-active.
MODIFY SCREEN.
ENDIF.
ENDIF.
ENDLOOP.
* Evenement F4 sur P_FILE.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CALL FUNCTION 'F4_FILENAME'
IMPORTING
file_name = p_file.
*Text elements
*----------------------------------------------------------
* 001 Erreur : table inconnue
* 003 Erreur lors de l'export de la table
* 007 Import table *SAP* interdit
* T01 Paramètre de sélection
* T02 Paramètres import / export
* T03 Paramètres supp. d'export
*Selection texts
*----------------------------------------------------------
* P_CLEAR Effacer la table avant
* P_EXCL Fichier Excel
* P_EXP Export
* P_FILE D .
* P_FLAT Fichier plat (tab)
* P_IMP Import
* P_MAX Nombre max d'enreg.
* P_TABLE D .
Message was edited by: Frédéric Girod
2013 Jul 03 8:35 PM
Yes, now my code works well ...
Sorry for my post ...
I'm really sorry for the inconvenience.
My post was useless.
2013 Jul 03 9:21 PM
Hi Youri,
It can be your fieldsymbol definition. It should be TYPE STANDARD TABLE for use GUI_UPLOAD function. Also you can do it with CL_GUI_FRONTEND_SERVICES:
DATA: lr_struct TYPE REF TO cl_abap_structdescr,
lr_table TYPE REF TO cl_abap_tabledescr,
lr_data TYPE REF TO data,
lv_file TYPE string.
FIELD-SYMBOLS <table> TYPE ANY.
lr_struct ?= cl_abap_typedescr=>describe_by_name( 'MARA' ).
lr_table = cl_abap_tabledescr=>create( p_line_type = lr_struct ).
CREATE DATA lr_data TYPE HANDLE lr_table.
ASSIGN lr_data->* TO <table>.
cl_gui_frontend_services=>gui_upload(
EXPORTING filename = lv_file
has_field_separator = abap_true
CHANGING data_tab = <table> ).
In this example I create a data of table type MARA an filled from a csv (missing part where it retrieves the file name). In this case <table> can be TYPE ANY, TYPE ANY TABLE or TYPE STANDARD TABLE and it will still work.
Regards,
Alex
| User | Count |
|---|---|
| 6 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |