Application Development and Automation 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: 
Read only

Table

Former Member
0 Likes
903

hi all,

can anyone pls help me regarding this: I have 2 newly created tables, however there's no test data in it. so they gave me test data which is in an excel. i need to create a program that will put the test data which is in excel to the newly created table in se12. I think im going to upload this test data. can anyone assist me pls.

thanx in advance,

jc

6 REPLIES 6
Read only

gopi_narendra
Active Contributor
0 Likes
854

Make use of the function module ALSM_EXCEL_TO_INTERNAL_TABLE

Sample Code of how to use it

call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'

exporting

FILENAME = P_FILE

I_BEGIN_COL = 1

I_BEGIN_ROW = 1

I_END_COL = 256

I_END_ROW = 65356

tables

INTERN = IT_DATA

exceptions

INCONSISTENT_PARAMETERS = 1

UPLOAD_OLE = 2

others = 3.

if SY-SUBRC <> 0.

message E024(PC).

endif.

loop at IT_DATA into IS_DATA.

at new ROW.

clear IS_TAB.

endat.

if IS_DATA-COL eq '001'.

move IS_DATA-VALUE to IS_TAB-WERKS.

endif.

if IS_DATA-COL eq '002'.

move IS_DATA-VALUE to IS_TAB-MATNR.

endif.

if IS_DATA-COL eq '003'.

move IS_DATA-VALUE to IS_TAB-ZLL_CONFMODE.

endif.

if IS_DATA-COL eq '004'.

move IS_DATA-VALUE to IS_TAB-ZLL_LOW.

endif.

if IS_DATA-COL eq '005'.

move IS_DATA-VALUE to IS_TAB-ZLL_HIGH.

endif.

at end of ROW.

IS_TAB-MANDT = SY-MANDT.

append IS_TAB to IT_TAB.

endat.

clear IS_DATA.

endloop.

Regards

Gopi

Message was edited by: Gopi Narendra

Read only

0 Likes
854

Hi gopi,

regarding to your reply, for my 1st table i have 14 columns in excel and to my 2nd table i have 2 columns in excel. how can i do this. thanx a lot.

regards,

jc

Read only

0 Likes
854

my requirement was for 5 columns, so u extend the same for 14 columns in first table and extedn it for 2 columns in the 2nd table

Read only

Former Member
0 Likes
854

Hi,

Use GUI_UPLOAD Function module to upload the data. Once you get the data in internal table, use INSERT <TABLE NAME> statement.

TABLES : ZMARA.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

PATH = '.....

IMPORTING

TABLE = ITAB

EXCEPTIONS.......

LOOP AT ITAB.

ZMARA-MATNR = ITAB-MATNR.

ZMARA-MAKTX = ITAB-MAKTX.

INSERT INTO ZMARA VALUES ZMARA.

ENDLOOP.

For uploading of excel file, refer

Best regards,

Prashant

Read only

Former Member
0 Likes
854

Hi,

Try this Report:


REPORT  ZHRQ001T  .

*-----------------------------------------------------------------------
* T.A.B.L.E.
*-----------------------------------------------------------------------
TYPE-POOLS: truxs.
TABLES: ZHR_PER.
*-----------------------------------------------------------------------
* D.A.T.A.
*-----------------------------------------------------------------------
DATA: IT_ZHR_PER LIKE ZHR_PER OCCURS 0 WITH HEADER LINE.

DATA: BEGIN OF IT_TEMP1 OCCURS 0,
        COMP(4)  TYPE C,
        DIVI(4)  TYPE C,
        TDIV(50) TYPE C,
        DEPT(4)  TYPE C,
        TDEP(50) TYPE C,
        SECT(4)  TYPE C,
        TSEC(50) TYPE C,
        EFEC(8)  TYPE C,
        EXPR(8)  TYPE C,
        ACTI(1)  TYPE C,
      END OF IT_TEMP1.

DATA: it_raw TYPE truxs_t_text_data.
*-----------------------------------------------------------------------
* S.E.L.L.E.C.T.I.O.N.  .S.C.R.E.E.N.
*-----------------------------------------------------------------------
SELECTION-SCREEN BEGIN OF BLOCK BLC1 WITH FRAME TITLE TEXT-S10.
         PARAMETER:   P_FILE  LIKE rlgrap-filename  OBLIGATORY.
  SELECTION-SCREEN END OF BLOCK BLC1.

*-----------------------------------------------------------------------
* I.N.I.T.I.A.L.I.Z.A.T.I.O.N.
*-----------------------------------------------------------------------
INITIALIZATION.
  CLEAR: IT_TEMP1[], IT_ZHR_PER[].
*-----------------------------------------------------------------------
* I.N.C.L.U.D.E.
*-----------------------------------------------------------------------
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
  CALL FUNCTION 'F4_FILENAME'
    EXPORTING
      field_name = 'P_FILE'
    IMPORTING
      file_name  = p_file.

*-----------------------------------------------------------------------
* M.A.I.N.  .P.R.O.G.R.A.M.
*-----------------------------------------------------------------------
START-OF-SELECTION.
  PERFORM UPLOAD_FILE TABLES IT_TEMP1.
  PERFORM GET_DATA.
  PERFORM SAVE_DATA.
END-OF-SELECTION.

*-----------------------------------------------------------------------
* S.U.B.R.O.U.T.I.N.E.
*-----------------------------------------------------------------------
*&---------------------------------------------------------------------*
*&      Form  UPLOAD_FILE
*&---------------------------------------------------------------------*
FORM UPLOAD_FILE TABLES ITAB.
  CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
    EXPORTING
*     I_FIELD_SEPERATOR        =
      i_line_header            =  ''          
      i_tab_raw_data           =  it_raw       "' WORK TABLE
      i_filename               =  p_file
    TABLES
      i_tab_converted_data     = IT_TEMP1[]    "'ACTUAL DATA
   EXCEPTIONS
      conversion_failed        = 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.                    " UPLOAD_FILE

*&---------------------------------------------------------------------*
*&      Form  GET_DATA
*&---------------------------------------------------------------------*
FORM GET_DATA.
  LOOP AT IT_TEMP1.
      CLEAR IT_ZHR_PER.
      IT_ZHR_PER-MANDT   = SY-MANDT.
      IT_ZHR_PER-WERKS   = IT_TEMP1-COMP.
      IT_ZHR_PER-BTRTL1  = IT_TEMP1-DIVI.
      IT_ZHR_PER-BTRTL2  = IT_TEMP1-DEPT.
      IT_ZHR_PER-BTRTL3  = IT_TEMP1-SECT.
      IT_ZHR_PER-EFDATE  = IT_TEMP1-EFEC.
      IT_ZHR_PER-ENDDA   = IT_TEMP1-EXPR.
      IT_ZHR_PER-ZDIVI1  = IT_TEMP1-TDIV.
      IT_ZHR_PER-ZDIVI2  = IT_TEMP1-TDEP.
      IT_ZHR_PER-ZDIVI3  = IT_TEMP1-TSEC.

      IF IT_TEMP1-ACTI IS NOT INITIAL.
        IT_ZHR_PER-ACTIVE  = 'X'.
      ENDIF.
      COLLECT IT_ZHR_PER.
  ENDLOOP.
ENDFORM.                    " GET_DATA

*&---------------------------------------------------------------------*
*&      Form  SAVE_DATA
*&---------------------------------------------------------------------*
FORM SAVE_DATA .
  IF IT_ZHR_PER[] IS NOT INITIAL.
    DELETE ADJACENT DUPLICATES FROM IT_ZHR_PER.
    MODIFY ZHR_PER FROM TABLE IT_ZHR_PER.
    IF SY-SUBRC = 0.
      COMMIT WORK AND WAIT.
      MESSAGE I398(00) WITH 'Data Uploaded Succesfully'.
    ENDIF.
  ENDIF.
ENDFORM.                    " SAVE_DATA

Notes:

  • ZHR_PER is customer table

  • IT_TEMP1 have same columns with Excel columns

Read only

Former Member
0 Likes
854

u can used a function module

Call FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'

then move all data into internal table

okay