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

Problem in uploading data...

Former Member
0 Likes
565

Dear All,

I have to upload a file from one Server to SAP Server.

The text file data like under…

                                    • Text file data. ******************

<SMS>

SMSSALE 10139 9890304217 4/12/2006 001US206

aswedfrtghy Anki 98786543213

SMSSALE 10139 9890304217 4/12/2006 001GS102

ghtyujikiuytrewer cccc 98765432123

SMSSER 10139 9890304217 4/12/2006 001MC616

gtyh7890987 Accident Service Anoop 9890500038

SMSSER 10139 9890304217 4/12/2006 001US206

dfrtghyujki Paid Service llll 97654321234

</SMS>

**********************************************************

Now, when the SMSType is SMSSALE then I have to transfer (upload) into different table & if SMSType is SMSSER then to different table…

So how would I have to write procedure for it… or what process I have to do for this…

Please reply with coading….

Regards,

Dharmesh

1 ACCEPTED SOLUTION
Read only

jayanthi_jayaraman
Active Contributor
0 Likes
541

Hi,

1.Declare the internal table .

PARAMETERS P_FILE LIKE RLGRAP-FILENAME DEFAULT 'C:\test.txt'.

data : G_FILE1 TYPE STRING,

itab1 type standard table of db1,

itab2 type standard table of db2.

DATA: BEGIN OF T_INPUT OCCURS 0, " Flat file data

  • Declare the fields in character according to the data

SMSType(10) type c,

.....

END OF T_INPUT.

G_FILE1 = P_FILE.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = G_FILE1

FILETYPE = 'ASC'

HAS_FIELD_SEPARATOR = 'X'

TABLES

DATA_TAB = T_INPUT

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.

*Error message

ENDIF.

2. Loop the internal table and find out the SMStype.

loop at t_input.

if t_input-smstype = 'SMSSALE'.

move-corresponding t_input to itab1.

append t_input to itab1.

else.

move-corresponding t_input to itab2.

append t_input to itab2.

endif.

endloop.

3.Insert the values in two database tables.

insert db1 from table itab1.

insert db2 from table itab2.

PS:Take care of data types conversion if needed.

Kindly reward points by clicking the star on the left of reply,if it helps.

4 REPLIES 4
Read only

Former Member
0 Likes
541

Hi Dharmesh,

Do you mean to upload the file into different internal table depending on the contents of the file?

Better upload to an internal table and then seperate the details from that itab into your desired internal table.

Regards,

Wenceslaus.

Read only

Former Member
0 Likes
541

Hi,

Upload the file using GUI_UPLOAd:

Move the contents into a final internal table say gt_itab.

then based on gt_itab-<SMStype> split the contents into two internal tables gt_itab1 and gt_itab2.

hope this helps:

Regards,

Gayathri

Read only

ferry_lianto
Active Contributor
0 Likes
541

Hi Dharmesh,

You can code something like this ...

report zztest01.
 
Parameters: file1 type localfile default '/usr/sap/test/file1.txt'.
            
 
data: begin of i_input occurs 0,
      rec(100) type c,
      end of i_input.

data: wa_input(100) type c.
 

data: begin of i_smssale occurs 0,
      rec(100) type c,
      end of i_smssale.


data: begin of i_smsser occurs 0,
      rec(100) type c,
      end of i_smsser.

 
start-of-selection.
 
  open dataset file1 for input in text mode.
  
  if sy-subrc = 0.
    do.
      read dataset file1 into wa_input.
      if sy-subrc <> 0.
        exit.
      endif.
      
      i_input-rec = wa_input.
      append i_input.

    enddo.
  endif.

  close dataset file1.

  loop at i_input.
    if i_input-rec(7) = 'SMSSALE'.
      i_smssale-rec = i_input-rec.
      append i_smssale.  
    endif.

    if i_input-rec(6) = 'SMSSER'.
      i_smsser-rec = i_input-rec.
      append i_smsser. 
    endif. 

    ...

  endloop.

Hope this will help.

Regards,

Ferry Lianto

Read only

jayanthi_jayaraman
Active Contributor
0 Likes
542

Hi,

1.Declare the internal table .

PARAMETERS P_FILE LIKE RLGRAP-FILENAME DEFAULT 'C:\test.txt'.

data : G_FILE1 TYPE STRING,

itab1 type standard table of db1,

itab2 type standard table of db2.

DATA: BEGIN OF T_INPUT OCCURS 0, " Flat file data

  • Declare the fields in character according to the data

SMSType(10) type c,

.....

END OF T_INPUT.

G_FILE1 = P_FILE.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = G_FILE1

FILETYPE = 'ASC'

HAS_FIELD_SEPARATOR = 'X'

TABLES

DATA_TAB = T_INPUT

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.

*Error message

ENDIF.

2. Loop the internal table and find out the SMStype.

loop at t_input.

if t_input-smstype = 'SMSSALE'.

move-corresponding t_input to itab1.

append t_input to itab1.

else.

move-corresponding t_input to itab2.

append t_input to itab2.

endif.

endloop.

3.Insert the values in two database tables.

insert db1 from table itab1.

insert db2 from table itab2.

PS:Take care of data types conversion if needed.

Kindly reward points by clicking the star on the left of reply,if it helps.