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: 

Program to upload data from a tab-delimited file ...

Karan_Chopra_
Active Participant
0 Kudos

I have to upload data from a tab-delimited file with following fields into database table(ZCBU) with same fields:

CBU (parent)

KUNNR (child)

ERDAT (effective from)

MANDT (client)

SFID (salesforce ID)

AEDAT (effective to)

AENAM (assigned by).

This file can be of type PC(txt) or UNIX.

plz tell me how to do this in both type of files

7 REPLIES 7

Former Member
0 Kudos

Declare intrnal table i_final with all those fields .

Now use function fm ws_upload or gui_upload.

Give file name in exporting parameter in function module and type is dat or asc.

then tables you give i_final name.

Once you get data into i_final.Then insert into db table.

Insert zcbu from i_final.

Thanks

varma_narayana
Active Contributor
0 Kudos

Hi Karan..

**Declare an itab like this

DATA : begin of itab occurs 0,

RECORD(200),

end of itab.

**Using the GUI_UPLOAD FM get the Data into ITAB.

**To transfer the Record into the Internal table of ZCBU

LOOP AT ITAB.

SPLIT ITAB AT CL_ABAP_CHAR_UTITLITIES=>HORIZONTAL_TAB

INTO IT_DATA-CBU

IT_DATA-KUNNR .....

APPEND IT_dATA.

ENDLOOP.

***To insert the records in ZCBU Table:

INSERT ZCBU FROM TABLE IT_dATA ACCEPTING DUPLICATE KEYS.

<b>REWARD IF HELPFUL.</b>

Former Member
0 Kudos

Hi,

<b>Sample code:</b>


REPORT ZFILEUPLOAD
       NO STANDARD PAGE HEADING LINE-SIZE 255.

*** Internal table declaration ***

*** End of Internal table declaration ***


SELECTION-SCREEN SKIP.
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-000.
PARAMETERS :
P_PATH        LIKE IBIPPARMS-PATH.  "File path and name
SELECTION-SCREEN END OF BLOCK B1.

INITIALIZATION.
  CTU = 'X'.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_PATH.
  CALL FUNCTION 'F4_FILENAME'
    EXPORTING
      FIELD_NAME = 'PATH'
    IMPORTING
      FILE_NAME  = P_PATH.

START-OF-SELECTION.

  CALL FUNCTION 'WS_UPLOAD'
    EXPORTING
      FILENAME                = P_PATH
      FILETYPE                = 'DAT'
    TABLES
      DATA_TAB                = INTERNAL_TABLE
    EXCEPTIONS
      CONVERSION_ERROR        = 1
      FILE_OPEN_ERROR         = 2
      FILE_READ_ERROR         = 3
      INVALID_TYPE            = 4
      NO_BATCH                = 5
      UNKNOWN_ERROR           = 6
      INVALID_TABLE_WIDTH     = 7
      GUI_REFUSE_FILETRANSFER = 8
      CUSTOMER_ERROR          = 9
      NO_AUTHORITY            = 10
      OTHERS                  = 11.

Regards,

Thangesh

Former Member
0 Kudos

Hi Karan,

Use FM <b>'Gui_Upload'</b>

one tab = 4 spaces.

put these spaces into separate variables. and then move only the field values into other table .

Define your table like this :

TYPES : BEGIN OF T_TAB,

EMP_ID(8),

P1(4),

NAME(10),

P2(4),

SURNAME(10),

P3(4),

PRACTICE(10),

P4(4),

MOB(11),

END OF T_TAB.

TYPES : BEGIN OF T_TAB1,

EMP_ID(8),

NAME(10),

SURNAME(10),

PRACTICE(10),

MOB(11),

END OF T_TAB.

DATA : I_TAB TYPE STANDARD TABLE OF T_TAB WITH HEADER LINE,

I_TAB1 TYPE STANDARD TABLE OF T_TAB1 WITH HEADER LINE

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = V_FILE

FILETYPE = 'ASC'

  • HAS_FIELD_SEPARATOR = 'X'

tables

data_tab = I_TAB

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.

loop at i_tab.

move-corresponding i_tab to i_tab1.

append i_tab1.

endloop.

Reward points if helpful.

Regards,

Hemant

varma_narayana
Active Contributor
0 Kudos

Hi Karan..

Small spelling mistake in my code....

Tab delimiter can be identified using a Predefined Constant.

CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB

just correct it..

<b>reward if helpful</b>

Former Member
0 Kudos

Hi Karan

Please use this way to do it .

DATA: it_zcbu like zcbu OCCURS 0 with header line.

CALL FUNCTION 'WS_UPLOAD'

  • EXPORTING

  • CODEPAGE = ' '

FILENAME = 'C:\filename.txt'

FILETYPE = 'DAT'

  • HEADLEN = ' '

  • LINE_EXIT = ' '

  • TRUNCLEN = ' '

  • USER_FORM = ' '

  • USER_PROG = ' '

  • DAT_D_FORMAT = ' '

  • IMPORTING

  • FILELENGTH =

TABLES

DATA_TAB = it_zcbu.

INSERT zcbu FROM TABLE it_zcbu.

Regards

wiboon

Former Member
0 Kudos

Hi,

DATA: bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE.

DATA: xfile TYPE string.

DATA: BEGIN OF itab OCCURS 0,

empno TYPE zmemp-empno,

name TYPE zmemp-first_name,

last TYPE zmemp-last_name,

comp TYPE zmemp-comp,

place TYPE zmemp-place,

END OF itab.

PARAMETER : p_file TYPE rlgrap-filename OBLIGATORY.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

  • Form to get the file path of legacy data stored on presentation server

PERFORM get_file_path.

START-OF-SELECTION.

MOVE p_file TO xfile.

  • to get the data from excel sheet data into an internal table

PERFORM get_data.

LOOP AT itab .

REFRESH bdcdata.

PERFORM bdc_dynpro USING 'ZM_EMPLOYEE' '9001'.

PERFORM bdc_field USING 'BDC_CURSOR'

'S9001_EMPNO'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=CREA'.

PERFORM bdc_field USING 'S9001_EMPNO'

itab-empno.

PERFORM bdc_dynpro USING 'ZM_EMPLOYEE' '9002'.

PERFORM bdc_field USING 'BDC_CURSOR'

'S9002_PLACE'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=SAVE'.

PERFORM bdc_field USING 'S9002_EMPNO'

itab-empno.

PERFORM bdc_field USING 'S9002_FIRST_NAME'

itab-name.

PERFORM bdc_field USING 'S9002_LAST_NAME'

itab-last.

PERFORM bdc_field USING 'S9002_COMP'

itab-comp.

PERFORM bdc_field USING 'S9002_PLACE'

itab-place.

PERFORM bdc_dynpro USING 'ZM_EMPLOYEE' '9001'.

PERFORM bdc_field USING 'BDC_CURSOR'

'S9001_EMPNO'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=BACK'.

CALL TRANSACTION 'ZMEMP'

USING bdcdata

UPDATE 'A'

MODE 'N'.

ENDLOOP.

----


  • Start new screen *

----


FORM bdc_dynpro USING program dynpro.

CLEAR bdcdata.

bdcdata-program = program.

bdcdata-dynpro = dynpro.

bdcdata-dynbegin = 'X'.

APPEND bdcdata.

ENDFORM. "BDC_DYNPRO

----


  • Insert field *

----


FORM bdc_field USING fnam fval.

CLEAR bdcdata.

bdcdata-fnam = fnam.

bdcdata-fval = fval.

APPEND bdcdata.

ENDFORM. "BDC_FIELD

&----


*& Form get_file_path

&----


FORM get_file_path .

CALL FUNCTION 'KD_GET_FILENAME_ON_F4'

CHANGING

file_name = p_file.

ENDFORM. " get_file_path

&----


*& Form get_data

&----


FORM get_data .

DATA : lines1 TYPE i.

MOVE p_file TO xfile.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = xfile

filetype = 'ASC'

has_field_separator = 'X'

TABLES

data_tab = itab.

DESCRIBE TABLE itab LINES lines1.

WRITE : / lines1 , 'REcords uploaded' .

ENDFORM. " get_data

Regards,

Nihar Swain,