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: 

How to upload a flat file from application server in BDC Program

Former Member
0 Kudos

Hi all SAP Experts,

How to upload a flat file from application server in BDC Program?

Please Tel me Urgently

Thank you

Basu

4 REPLIES 4

Former Member
0 Kudos

Hi,

report ZSDBDCP_PRICING no standard page heading

line-size 255.

include zbdcrecx1.

*--Internal Table To hold condition records data from flat file.

Data: begin of it_pricing occurs 0,

key(4),

f1(4),

f2(4),

f3(2),

f4(18),

f5(16),

end of it_pricing.

*--Internal Table To hold condition records header .

data : begin of it_header occurs 0,

key(4),

f1(4),

f2(4),

f3(2),

end of it_header.

*--Internal Table To hold condition records details .

data : begin of it_details occurs 0,

key(4),

f4(18),

f5(16),

end of it_details.

data : v_sno(2),

v_rows type i,

v_fname(40).

start-of-selection.

refresh : it_pricing,it_header,it_details.

clear : it_pricing,it_header,it_details.

  • CALL FUNCTION 'UPLOAD'

  • EXPORTING

  • FILENAME = 'C:\WINDOWS\Desktop\pricing.txt'

  • FILETYPE = 'DAT'

  • TABLES

  • DATA_TAB = it_pricing

  • EXCEPTIONS

  • CONVERSION_ERROR = 1

  • INVALID_TABLE_WIDTH = 2

  • INVALID_TYPE = 3

  • NO_BATCH = 4

  • UNKNOWN_ERROR = 5

  • GUI_REFUSE_FILETRANSFER = 6

  • OTHERS = 7.

WRITE : / 'Condition Records ', P_FNAME, ' on ', SY-DATUM.

OPEN DATASET P_FNAME FOR INPUT IN TEXT MODE.

if sy-subrc ne 0.

write : / 'File could not be uploaded.. Check file name.'.

stop.

endif.

CLEAR : it_pricing[], it_pricing.

DO.

READ DATASET P_FNAME INTO V_STR.

IF SY-SUBRC NE 0.

EXIT.

ENDIF.

  • write v_str.

  • translate v_str using '#/'.

SPLIT V_STR AT ',' INTO it_pricing-key

it_pricing-F1 it_pricing-F2 it_pricing-F3

it_pricing-F4 it_pricing-F5 .

APPEND it_pricing.

CLEAR it_pricing.

ENDDO.

IF it_pricing[] IS INITIAL.

WRITE : / 'No data found to upload'.

STOP.

ENDIF.

loop at it_pricing.

At new key.

read table it_pricing index sy-tabix.

move-corresponding it_pricing to it_header.

append it_header.

clear it_header.

endat.

move-corresponding it_pricing to it_details.

append it_details.

clear it_details.

endloop.

perform open_group.

v_rows = sy-srows - 8.

loop at it_header.

perform bdc_dynpro using 'SAPMV13A' '0100'.

perform bdc_field using 'BDC_CURSOR'

'RV13A-KSCHL'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_field using 'RV13A-KSCHL'

it_header-f1.

perform bdc_dynpro using 'SAPMV13A' '1004'.

perform bdc_field using 'BDC_CURSOR'

'KONP-KBETR(01)'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_field using 'KOMG-VKORG'

it_header-f2.

perform bdc_field using 'KOMG-VTWEG'

it_header-f3.

**Table Control

v_sno = 0.

loop at it_details where key eq it_header-key.

v_sno = v_sno + 1.

clear v_fname.

CONCATENATE 'KOMG-MATNR(' V_SNO ')' INTO V_FNAME.

perform bdc_field using v_fname

it_details-f4.

clear v_fname.

CONCATENATE 'KONP-KBETR(' V_SNO ')' INTO V_FNAME.

perform bdc_field using v_fname

it_details-f5.

if v_sno eq v_rows.

v_sno = 0.

perform bdc_dynpro using 'SAPMV13A' '1004'.

perform bdc_field using 'BDC_OKCODE'

'=P+'.

perform bdc_dynpro using 'SAPMV13A' '1004'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

endif.

endloop.

*--Save

perform bdc_dynpro using 'SAPMV13A' '1004'.

perform bdc_field using 'BDC_OKCODE'

'=SICH'.

perform bdc_transaction using 'VK11'.

endloop.

perform close_group.

regards,

Anji

former_member181962
Active Contributor
0 Kudos
Hi,
   Folow these steps.

open dataset <filename> for input in text mode.

if sy-subrc = 0.
do.
read dataset <filename> into itab-data.
if sy-subrc = 0.
append itab.
clear itab.
else.
exit.
endif.
enddo.
close dataset <filename>.
endif.

Regards,
Ravi

Former Member
0 Kudos

HI..

Just look at the following program..

&----


*& Report ZUPLOADTAB *

*& *

&----


*& Example of Uploading tab delimited file *

*& *

&----


REPORT zuploadtab .

PARAMETERS: p_infile LIKE rlgrap-filename

OBLIGATORY DEFAULT '/usr/sap/'..

DATA: ld_file LIKE rlgrap-filename.

*Internal tabe to store upload data

TYPES: BEGIN OF t_record,

name1 like pa0002-VORNA,

name2 like pa0002-name2,

age type i,

END OF t_record.

DATA: it_record TYPE STANDARD TABLE OF t_record INITIAL SIZE 0,

wa_record TYPE t_record.

*Text version of data table

TYPES: begin of t_uploadtxt,

name1(10) type c,

name2(15) type c,

age(5) type c,

end of t_uploadtxt.

DATA: wa_uploadtxt TYPE t_uploadtxt.

*String value to data in initially.

DATA: wa_string(255) type c.

constants: con_tab TYPE x VALUE '09'.

*If you have Unicode check active in program attributes then you will

*need to declare constants as follows:

*class cl_abap_char_utilities definition load.

*constants:

  • con_tab type c value cl_abap_char_utilities=>HORIZONTAL_TAB.

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

*START-OF-SELECTION

START-OF-SELECTION.

ld_file = p_infile.

OPEN DATASET ld_file FOR INPUT IN TEXT MODE ENCODING DEFAULT.

IF sy-subrc NE 0.

ELSE.

DO.

CLEAR: wa_string, wa_uploadtxt.

READ DATASET ld_file INTO wa_string.

IF sy-subrc NE 0.

EXIT.

ELSE.

SPLIT wa_string AT con_tab INTO wa_uploadtxt-name1

wa_uploadtxt-name2

wa_uploadtxt-age.

MOVE-CORRESPONDING wa_uploadtxt TO wa_upload.

APPEND wa_upload TO it_record.

ENDIF.

ENDDO.

CLOSE DATASET ld_file.

ENDIF.

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

*END-OF-SELECTION

END-OF-SELECTION.

*!! Text data is now contained within the internal table IT_RECORD

  • Display report data for illustration purposes

  • Use GUI_DOWNLOAD function moduel to download to a flat file

loop at it_record into wa_record.

write:/ sy-vline,

(10) wa_record-name1, sy-vline,

(10) wa_record-name2, sy-vline,

(10) wa_record-age, sy-vline.

endloop.

Regards

Rk

Message was edited by:

Rk Pasupuleti

Former Member
0 Kudos

Hi ,

look at this...

i think it will help ful....

OPEN DATASET W_PHY_FNAME FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

IF SY-SUBRC = 0.

LOOP AT Itab.

TRANSFER itab TO W_PHY_FNAME.

ENDLOOP.

CLOSE DATASET W_PHY_FNAME.

ENDIF.

Regards,

mahendar.