Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Upload Notepad File (Tab delimited) into Ztable

Former Member
0 Kudos
365

Hi Experts,

My requirement is about download transparent table data's (12 Fields) into excel file and after excel file being verified upload same file into customized ztable.

Download function is working fine. FM (MS_EXCEL_OLE_STANDARD_DAT).

I have a problem in upload. WS_UPLOAD is the function module I am using.

Note: for this first I have convert excel file into notepad file (Tab delimited) format then I upload into ztable. (Because direct excel upload is not working)

Customized Ztable Structure

Field Data Element Data Type

1. MANDT MANDT CLNT (key)

2. ZLAYOUT CHAR18 CHAR

3. ZKURST KURST CHAR

4. ZWSDAT DATS DATS

5. ZDOCTY DOCTY CHAR

6. ZBUDAT DATS DATS

7. ZRBUKRS BUKRS CHAR

8. ZRPRCTR PRCTR CHAR

9. ZRACCT RACCT CHAR

10. ZSPRCTR PPRCTR CHAR

11. ZHSL VLCUR_PCA CURR

12. ZKSL1 VGCUR_PCA CURR

13. ZKSL2 VGCUR_PCA CURR

Internal table for upload

DATA: BEGIN OF ITAB_IN1 OCCURS 0,

MANDT TYPE ZPCAT-MANDT,

LAYOUT TYPE ZPCAT-ZLAYOUT,

EXCHANGE_RATE TYPE ZPCAT-ZKURST,

VALUE_DATE TYPE ZPCAT-ZWSDAT,

DOCUMENT_TYPE TYPE ZPCAT-ZDOCTY,

POSTING_DATE LIKE ZPCAT-ZBUDAT,

COMPANY_CODE TYPE ZPCAT-ZRBUKRS,

PROFIT_CENTER TYPE ZPCAT-ZRPRCTR,

ACCOUNT_NUMBER TYPE ZPCAT-ZRACCT,

PARTNER_PROFIT_CENTER TYPE ZPCAT-ZSPRCTR,

COMPANY_CODE_CURRENCY TYPE ZPCAT-ZHSL,

PROFIT_CENTER_CURRENCY_C TYPE ZPCAT-ZKSL1,

PROFIT_CENTER_CURRENCY_S TYPE ZPCAT-ZKSL1,

END OF ITAB_IN1.

I am new to this forum and abap, kindly please advise with understandable coding example.

Thanks.

Regards

skumar.

1 ACCEPTED SOLUTION

Former Member
0 Kudos
111

HI Sukumar,

Here no need to Convert Excel file to txt file b'coz facility is available to upload Excel file directly into Internal Table.

check this one

DATA : BEGIN OF IT_FIELD_INFO OCCURS 0,
                              FIELDNAME   LIKE  DD03L-FIELDNAME,
                              POSITION(4) TYPE  N,
                           END OF IT_FIELD_INFO.
     DATA : IT_FILE    LIKE  ALSMEX_TABLINE OCCURS 0 WITH HEADER LINE.
     DATA : L_PASS   LIKE  SY-TABIX.
     DATA : BEGIN OF ITAB1 OCCURS 0,
                    MATNR_001(018),
                   WERKS_002(004),
                   STTAG_003(010),
                   VERWE_007(003),
                   STATU_008(003),
                 END OF iTAB1.
PARAMETERS : P_FILE  LIKE  RLGRAP-FILENAME  OBLIGATORY. " Declaration
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
" FM for File Selection
  CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
    EXPORTING
      PROGRAM_NAME  = SY-REPID
      DYNPRO_NUMBER = SY-DYNNR
    CHANGING
      FILE_NAME     = P_FILE1.

REFRESH IT_FILE.  " Your Internal Table 
  CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
    EXPORTING
      FILENAME                    = P_FILE  " Your Excel file
      I_BEGIN_COL              = 1
      I_BEGIN_ROW             = 1
      I_END_COL                  = 200
      I_END_ROW                = 1
    TABLES
      INTERN                       = IT_FILE    .
  CLEAR IT_FILE.    
  IF NOT IT_FILE[] IS INITIAL.  
   LOOP AT IT_FILE WHERE ROW = 1 .   " Collecting Field Information
      CLEAR IT_FIELD_INFO.
      IT_FIELD_INFO-FIELDNAME = IT_FILE-VALUE.
      TRANSLATE IT_FIELD_INFO-FIELDNAME TO UPPER CASE.
      IT_FIELD_INFO-POSITION = IT_FILE-COL .
      APPEND IT_FIELD_INFO .
    ENDLOOP.
  ENDIF.

  LOOP AT IT_FILE .
    IF L_PASS <> IT_FILE-ROW AND IT_FILE-ROW > 1 .
      APPEND ITAB1.
      CLEAR ITAB1 .
    ENDIF.
       L_PASS = IT_FILE-ROW .
 READ TABLE IT_FIELD_INFO WITH KEY POSITION = IT_FILE-COL.
  IF IT_FIELD_INFO-FIELDNAME = 'MATERIAL NO '.
     ITAB1-MATNR_001 = IT_FILE-VALUE.
    ELSEIF IT_FIELD_INFO-FIELDNAME = 'PLANT'.
    ITAB1-WERKS_002 = IT_FILE-VALUE.
    ELSEIF IT_FIELD_INFO-FIELDNAME = 'DATE'.
      ITAB1-STTAG_003 = IT_FILE-VALUE.
    ELSEIF IT_FIELD_INFO-FIELDNAME = 'USAGE'.
      ITAB1-VERWE_007 = IT_FILE-VALUE.
    ELSEIF IT_FIELD_INFO-FIELDNAME = 'STATUS'.
     ITAB1-STATU_008 = IT_FILE-VALUE.
   ENDIF.
 ENDLOOP.
  APPEND ITAB1.
   CLEAR ITAB1 .

So after this Exercise your Internal Table IT_TAB1 will be having all the data from excel file

Hope this will help you

7 REPLIES 7

Former Member
0 Kudos
112

HI Sukumar,

Here no need to Convert Excel file to txt file b'coz facility is available to upload Excel file directly into Internal Table.

check this one

DATA : BEGIN OF IT_FIELD_INFO OCCURS 0,
                              FIELDNAME   LIKE  DD03L-FIELDNAME,
                              POSITION(4) TYPE  N,
                           END OF IT_FIELD_INFO.
     DATA : IT_FILE    LIKE  ALSMEX_TABLINE OCCURS 0 WITH HEADER LINE.
     DATA : L_PASS   LIKE  SY-TABIX.
     DATA : BEGIN OF ITAB1 OCCURS 0,
                    MATNR_001(018),
                   WERKS_002(004),
                   STTAG_003(010),
                   VERWE_007(003),
                   STATU_008(003),
                 END OF iTAB1.
PARAMETERS : P_FILE  LIKE  RLGRAP-FILENAME  OBLIGATORY. " Declaration
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
" FM for File Selection
  CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
    EXPORTING
      PROGRAM_NAME  = SY-REPID
      DYNPRO_NUMBER = SY-DYNNR
    CHANGING
      FILE_NAME     = P_FILE1.

REFRESH IT_FILE.  " Your Internal Table 
  CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
    EXPORTING
      FILENAME                    = P_FILE  " Your Excel file
      I_BEGIN_COL              = 1
      I_BEGIN_ROW             = 1
      I_END_COL                  = 200
      I_END_ROW                = 1
    TABLES
      INTERN                       = IT_FILE    .
  CLEAR IT_FILE.    
  IF NOT IT_FILE[] IS INITIAL.  
   LOOP AT IT_FILE WHERE ROW = 1 .   " Collecting Field Information
      CLEAR IT_FIELD_INFO.
      IT_FIELD_INFO-FIELDNAME = IT_FILE-VALUE.
      TRANSLATE IT_FIELD_INFO-FIELDNAME TO UPPER CASE.
      IT_FIELD_INFO-POSITION = IT_FILE-COL .
      APPEND IT_FIELD_INFO .
    ENDLOOP.
  ENDIF.

  LOOP AT IT_FILE .
    IF L_PASS <> IT_FILE-ROW AND IT_FILE-ROW > 1 .
      APPEND ITAB1.
      CLEAR ITAB1 .
    ENDIF.
       L_PASS = IT_FILE-ROW .
 READ TABLE IT_FIELD_INFO WITH KEY POSITION = IT_FILE-COL.
  IF IT_FIELD_INFO-FIELDNAME = 'MATERIAL NO '.
     ITAB1-MATNR_001 = IT_FILE-VALUE.
    ELSEIF IT_FIELD_INFO-FIELDNAME = 'PLANT'.
    ITAB1-WERKS_002 = IT_FILE-VALUE.
    ELSEIF IT_FIELD_INFO-FIELDNAME = 'DATE'.
      ITAB1-STTAG_003 = IT_FILE-VALUE.
    ELSEIF IT_FIELD_INFO-FIELDNAME = 'USAGE'.
      ITAB1-VERWE_007 = IT_FILE-VALUE.
    ELSEIF IT_FIELD_INFO-FIELDNAME = 'STATUS'.
     ITAB1-STATU_008 = IT_FILE-VALUE.
   ENDIF.
 ENDLOOP.
  APPEND ITAB1.
   CLEAR ITAB1 .

So after this Exercise your Internal Table IT_TAB1 will be having all the data from excel file

Hope this will help you

Former Member
0 Kudos
111

Hi

I don't think you need to convert your excel data into notepad and then upload it to sap.

SAP by itself has provided the function Module ALSM_EXCEL_TO_INTERNAL_TABLE to read the data from excel sheet. Try using it.

Regards

Gaurav Gupta

Former Member
0 Kudos
111

hi skumar,

use fm

TEXT_CONVERT_XLS_TO_SAP to upload excel file

CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'

EXPORTING

i_line_header = 'X'

i_tab_raw_data = gt_raw

i_filename = p_file

TABLES

i_tab_converted_data = gt_datatab[]

EXCEPTIONS

conversion_failed = 1

OTHERS = 2.

i hope this will help you in solving your query.

Thanks

Tanmaya

Former Member
0 Kudos
111

GUI_UPLOAD will work for EXCEL upload. It depends on whether you have used the correct FILETYPE or not. Show us how you used GUI_UPLOAD.

Vikranth

0 Kudos
111

Hi thank for valuable suggestions. below is FM for upload. please advice.

DATA : W_LINES1(8) TYPE P, "No. of Lines in Part A

W_LINES2(8) TYPE P, "No. of Lines in Part B

P_FILTY LIKE RLGRAP-FILETYPE VALUE 'DAT'. "File Type for Upload

CALL FUNCTION 'WS_UPLOAD'

EXPORTING

FILENAME = P_IFILE1

FILETYPE = P_FILTY

TABLES

DATA_TAB = ITAB_IN1

EXCEPTIONS

CONVERSION_ERROR = 1

FILE_OPEN_ERROR = 2

FILE_READ_ERROR = 3

INVALID_TABLE_WIDTH = 4

INVALID_TYPE = 5

NO_BATCH = 6

UNKNOWN_ERROR = 7

OTHERS = 8.

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 error encountered, display error message.

IF SY-SUBRC NE 0.

WRITE : / 'Invalid File', P_IFILE1.

ENDIF.

  • delete itab_in where uid is initial and ltype is initial.

*-- Count number of lines filled in Internal Table ITAB

DESCRIBE TABLE ITAB_IN1 LINES W_LINES1.

WRITE:/01 'Lines Uploaded = ', W_LINES1.

0 Kudos
111

WS_UPLOAD is obsolete and is not recommended to be used anymore. Try with GUI_UPLOAD passing the same parameters.

0 Kudos
111

Hi all

Thank you for kind assistance. I have used FM GUI_UPLOAD.

see u again

Regards

skumar.