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: 

Asset upload through BDC

Former Member
0 Kudos

hi experts

i will have to upload the asset through tcode AS91.

so i need the code as well as the exact method to upload the data.

help me

4 REPLIES 4

raymond_giuseppi
Active Contributor
0 Kudos

Look at LSMW.

Program is RAALTD01 with input structure BAALTD and BALTB.

Regards

0 Kudos

For documentation look at <a href="http://help.sap.com/saphelp_46c/helpdata/en/2d/4b08b3a77611d195140000e82debf7/frameset.htm">Transfer of Legacy Assets to the R/3 System</a>

Regards

Former Member
0 Kudos

Hi,

here is a sample code to upload data from flat file to bdc using sm30 transaction... I am just sending the code... use it if it helps...

REPORT zrecord02

NO STANDARD PAGE HEADING LINE-SIZE 255.

*INCLUDE bdcrecx1.

TABLES: t005.

TYPE-POOLS: truxs.

CONSTANTS: gc_x VALUE 'X',

gc_land(40) TYPE c VALUE 'Improper land value',

gc_imp(50) TYPE c VALUE 'Import Code is already present',

gc_noimp(60) TYPE c VALUE 'Please enter import code and try',

gc_dynbegin TYPE c VALUE 'X',

gc_mode TYPE c VALUE 'A',

gc_mode1 TYPE c VALUE 'N',

gc_sucess TYPE c VALUE 'S',

gc_flag TYPE c VALUE 'X'.

SELECTION-SCREEN BEGIN OF BLOCK b WITH FRAME TITLE text-t01.

PARAMETERS: p_upl_ps RADIOBUTTON GROUP g DEFAULT 'X',

p_upl_as RADIOBUTTON GROUP g,

p_file TYPE rlgrap-filename,

p_test AS CHECKBOX.

SELECTION-SCREEN END OF BLOCK b.

TYPES: BEGIN OF itab , " structure containing the fields of excel sheet.

land1 TYPE v_t604-land1,

stawn TYPE v_t604-stawn,

text1 TYPE v_t604-text1,

bemeh TYPE v_t604-bemeh,

impma TYPE v_t604-impma,

minol TYPE v_t604-minol,

END OF itab.

TYPES: BEGIN OF itab1, " structure containing the fields of excel sheet.

land1 TYPE v_t604-land1,

stawn TYPE v_t604-stawn,

text1 TYPE v_t604-text1,

bemeh TYPE v_t604-bemeh,

impma TYPE v_t604-impma,

minol TYPE v_t604-minol,

err(30) TYPE c,

END OF itab1.

TYPES: BEGIN OF errdata,

land1 TYPE t005-land1,

stawn TYPE t604-stawn,

END OF errdata.

DATA: gi_errdata TYPE TABLE OF errdata," with header line,

gi_errdata1 TYPE TABLE OF errdata,

gw_err TYPE errdata.

TYPES: BEGIN OF land,

land1 TYPE t005-land1,

END OF land. "*

TYPES: BEGIN OF import,

stawn TYPE t604-stawn,

END OF import.

DATA: BEGIN OF temp_str,

line(1000) TYPE c,

END OF temp_str.

DATA: i_temp LIKE STANDARD TABLE OF temp_str WITH HEADER LINE,

i_itab1 TYPE STANDARD TABLE OF itab1 WITH HEADER LINE.

DATA: gi_itab TYPE STANDARD TABLE OF itab WITH HEADER LINE, " internal table to store data

gi_itab_a TYPE STANDARD TABLE OF itab WITH HEADER LINE,

gi_itab_b TYPE STANDARD TABLE OF itab WITH HEADER LINE,

gi_itab_c TYPE STANDARD TABLE OF itab WITH HEADER LINE,

gi_itab_d TYPE STANDARD TABLE OF itab WITH HEADER LINE,

gi_itab_e TYPE STANDARD TABLE OF itab WITH HEADER LINE,

gw_itab TYPE itab, " work area to store data

gw_validitab TYPE itab,

gw_finalitab TYPE itab.

DATA: gi_a_land TYPE STANDARD TABLE OF land WITH HEADER LINE,

gi_b_land TYPE STANDARD TABLE OF land WITH HEADER LINE,

gi_c_land TYPE STANDARD TABLE OF land WITH HEADER LINE,

gw_land TYPE land. "*

DATA: gi_a_import TYPE STANDARD TABLE OF import WITH HEADER LINE,

gi_b_import TYPE STANDARD TABLE OF import WITH HEADER LINE,

gi_c_import TYPE STANDARD TABLE OF import WITH HEADER LINE,

gw_import TYPE import. "*

DATA: gi_err_itab TYPE STANDARD TABLE OF itab1 WITH HEADER LINE,

gw_err_itab TYPE itab1,

gw_itab1 TYPE itab1.

DATA: gi_bdcdata TYPE TABLE OF bdcdata,

gi_msg TYPE TABLE OF bdcmsgcoll.

DATA: gw_bdcdata TYPE bdcdata,

gw_msg TYPE bdcmsgcoll.

DATA: gv_datab TYPE char12, "Varible to hold the data

gv_date TYPE char2,

gv_mon TYPE char2,

gv_year TYPE char4,

gv_no_succs TYPE i,

gv_no_error TYPE i,

gv_msg TYPE char100,

gv_id TYPE i.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

PERFORM get_file.

  • PERFORM upload.

TOP-OF-PAGE.

PERFORM gf_header.

END-OF-PAGE.

EXIT.

START-OF-SELECTION.

PERFORM upload.

PERFORM get_data.

IF p_test = gc_x.

PERFORM validations.

PERFORM display.

ELSE.

PERFORM validations.

PERFORM bdc.

PERFORM display.

ENDIF.

PERFORM no_of_records.

END-OF-SELECTION.

EXIT.

&----


*& Form get_file

&----


  • text

----


FORM get_file.

CALL FUNCTION 'F4_FILENAME'

  • EXPORTING

  • PROGRAM_NAME = SYST-CPROG

  • DYNPRO_NUMBER = SYST-DYNNR

  • FIELD_NAME = ' '

IMPORTING

file_name = p_file.

ENDFORM. "get_file

&----


*& Form upload

&----


  • text

----


FORM upload.

DATA: lv_file TYPE string.

lv_file = p_file.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = lv_file

filetype = 'ASC'

has_field_separator = ''

  • HEADER_LENGTH = 0

  • READ_BY_LINE = 'X'

dat_mode = 'X'

  • CODEPAGE = ' '

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • CHECK_BOM = ' '

  • VIRUS_SCAN_PROFILE =

  • NO_AUTH_CHECK = ' '

  • IMPORTING

  • FILELENGTH =

  • HEADER =

TABLES

data_tab = i_temp

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.

ENDFORM. "upload

&----


*& Form get_data

&----


  • text

----


FORM get_data.

DATA:lv_id TYPE sy-tabix.

gv_id = 0.

IF i_temp[] IS INITIAL.

WRITE: /5 'Given File is empty'.

EXIT.

ELSE.

LOOP AT i_temp.

lv_id = sy-tabix.

SPLIT i_temp-line AT '|' INTO gi_itab-land1 gi_itab-stawn gi_itab-text1 gi_itab-bemeh gi_itab-impma gi_itab-minol."table gi_itab.

IF gi_itab-land1 IS INITIAL." AND gi_itab-stawn IS INITIAL.

gi_itab-land1 = 'CA'.

ENDIF.

IF gi_itab-stawn IS NOT INITIAL.

APPEND gi_itab.

ELSE.

APPEND gi_itab.

READ TABLE gi_itab INTO gw_itab WITH KEY stawn = space.

IF sy-subrc = 0.

gw_err_itab-land1 = gw_itab-land1.

gw_err_itab-stawn = gw_itab-stawn.

gw_err_itab-text1 = gw_itab-text1.

gw_err_itab-bemeh = gw_itab-bemeh.

gw_err_itab-impma = gw_itab-impma.

gw_err_itab-minol = gw_itab-minol.

gw_err_itab-err = gc_noimp.

APPEND gw_err_itab TO gi_err_itab.

gv_id = gv_id + 1.

DELETE gi_itab INDEX lv_id.

ENDIF.

ENDIF.

ENDLOOP.

ENDIF.

ENDFORM. "get_data

&----


*& Form gf_header

&----


  • text

----


FORM gf_header.

NEW-LINE. " Dispalay the header section

ULINE.

WRITE:/ text-006.

WRITE:/ text-007.

SKIP 1.

WRITE: AT /1 'PROGRAM NAME:'(022),sy-repid,

'DATE :'(023),sy-datum,

AT 100 'TIME :'(024),sy-timlo.

WRITE: AT /1 'FILENAME:'(025),p_file.

ULINE.

SKIP 1.

WRITE:/ text-008.

WRITE:/ text-009.

WRITE:/ text-010.

WRITE: AT 20 text-011.

WRITE: AT 33 text-012.

WRITE: AT 55 text-013.

WRITE: AT 70 text-014.

WRITE: AT 95 text-015.

ULINE.

NEW-LINE.

NEW-LINE.

ENDFORM. "gf_header

&----


*& Form validations

&----


  • text

----


FORM validations.

DATA: lv_line TYPE i.

DATA: lv_id TYPE sy-tabix.

LOOP AT gi_itab INTO gw_itab.

APPEND gw_itab-land1 TO gi_a_land.

ENDLOOP.

  • APPEND gw_itab-stawn TO gi_a_import.

LOOP AT gi_itab INTO gw_itab.

gw_err-land1 = gw_itab-land1.

gw_err-stawn = gw_itab-stawn.

APPEND gw_err TO gi_errdata.

ENDLOOP.

SORT gi_a_land BY land1.

REFRESH gi_b_land.

SELECT land1

FROM t005

INTO TABLE gi_b_land

FOR ALL ENTRIES IN gi_a_land

WHERE land1 EQ gi_a_land-land1.

IF sy-subrc = 0.

LOOP AT gi_itab INTO gw_itab.

READ TABLE gi_b_land INTO gw_land WITH KEY land1 = gw_itab-land1 BINARY SEARCH.

IF sy-subrc = 0.

gw_validitab-land1 = gw_itab-land1.

gw_validitab-stawn = gw_itab-stawn.

gw_validitab-text1 = gw_itab-text1.

gw_validitab-bemeh = gw_itab-bemeh.

gw_validitab-impma = gw_itab-impma.

gw_validitab-minol = gw_itab-minol.

APPEND gw_validitab TO gi_itab_a. "appending correct values to internal table.

ELSE.

gw_err_itab-land1 = gw_itab-land1.

gw_err_itab-stawn = gw_itab-stawn.

gw_err_itab-text1 = gw_itab-text1.

gw_err_itab-bemeh = gw_itab-bemeh.

gw_err_itab-impma = gw_itab-impma.

gw_err_itab-minol = gw_itab-minol.

gw_err_itab-err = gc_land.

APPEND gw_err_itab TO gi_err_itab. "Appending incorrect values.

ENDIF.

ENDLOOP.

ENDIF.

SELECT land1 stawn

FROM t604

INTO TABLE gi_errdata1

FOR ALL ENTRIES IN gi_errdata

WHERE land1 = gi_errdata-land1 AND stawn = gi_errdata-stawn.

IF sy-subrc <> 0.

EXIT.

ELSE.

LOOP AT gi_itab_a INTO gw_validitab. " gi_itab_a into gw_validitab.

CLEAR gw_err_itab.

lv_id = sy-tabix.

READ TABLE gi_errdata1 INTO gw_err WITH KEY land1 = gw_validitab-land1 stawn = gw_validitab-stawn.

IF sy-subrc = 0.

gw_err_itab-land1 = gw_validitab-land1.

gw_err_itab-stawn = gw_validitab-stawn.

gw_err_itab-text1 = gw_validitab-text1.

gw_err_itab-bemeh = gw_validitab-bemeh.

gw_err_itab-impma = gw_validitab-impma.

gw_err_itab-minol = gw_validitab-minol.

gw_err_itab-err = gc_imp.

APPEND gw_err_itab TO gi_err_itab.

DELETE gi_itab_a INDEX lv_id.

ENDIF.

ENDLOOP.

ENDIF.

ENDFORM. "validations

&----


*& Form no_of_records

&----


  • text

----


FORM no_of_records.

DATA: lv_line TYPE i,

lv_line1 TYPE i,

lv_corr TYPE i,

lv_tot TYPE i,

lv_total TYPE i.

DESCRIBE TABLE gi_itab LINES lv_tot.

lv_total = lv_tot + gv_id.

WRITE: /5 'Total number of Records from flat file:', 44 lv_total.

DESCRIBE TABLE gi_itab_a LINES lv_line.

SORT gi_itab_a BY land1 stawn ASCENDING.

DELETE ADJACENT DUPLICATES FROM gi_itab_a COMPARING land1 stawn." INTO TABLE gi_itab_e. move

IF sy-subrc = 0.

DESCRIBE TABLE gi_itab_a LINES lv_line1.

WRITE: /5'No of correctly processed records:', 50 lv_line1.

lv_corr = lv_line - lv_line1.

WRITE: /5 'Number of duplicate records:',44 lv_corr.

ELSE.

WRITE: /5 'Number of correctly processed records:',44 lv_line.

ENDIF.

DESCRIBE TABLE gi_err_itab.

WRITE: /5'No of Error Records:', 44 sy-tfill.

ENDFORM. "validations

&----


*& Form display

&----


  • text

----


FORM display.

IF gi_err_itab[] IS INITIAL.

WRITE: /5 sy-uline.

WRITE: /5 'All the datas are successfully uploaded'.

WRITE: /5 sy-uline.

ELSE.

  • WRITE: /5 sy-uline.

LOOP AT gi_err_itab INTO gw_err_itab.

WRITE: / gw_err_itab-land1, 21 gw_err_itab-stawn, 34 gw_err_itab-text1,56 gw_err_itab-bemeh, 71 gw_err_itab-impma, 97 gw_err_itab-minol.

  • WRITE: /5 sy-uline(65).

  • WRITE: /5 sy-vline,'land1',sy-vline,'Import Code',sy-vline.

ENDLOOP.

WRITE: / sy-uline.

ENDIF.

ENDFORM. "display

&----


*& Form bdc

&----


  • text

----


FORM bdc.

IF gi_itab_a[] IS INITIAL.

  • WRITE: 'No data is correct'.

EXIT.

ELSE.

  • PERFORM open_group.

CONSTANTS: lc_slash TYPE c VALUE '/'.

CLEAR: gv_year, gv_mon, gv_date, gi_bdcdata, gv_datab.

REFRESH gi_bdcdata.

MOVE: sy-datum+0(4) TO gv_year, "Todays data.

sy-datum+4(2) TO gv_mon,

sy-datum+6(2) TO gv_date.

CONCATENATE gv_mon lc_slash gv_date lc_slash gv_year INTO gv_datab.

LOOP AT gi_itab_a.

PERFORM bdc_dynpro USING 'SAPMSVMA' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR'

'VIEWNAME'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=UPD'.

PERFORM bdc_field USING 'VIEWNAME'

'V_T604'.

PERFORM bdc_field USING 'VIMDYNFLDS-LTD_DTA_NO'

'X'.

PERFORM bdc_dynpro USING 'SAPL080E' '0020'.

PERFORM bdc_field USING 'BDC_CURSOR'

'V_T604-BEMEH(01)'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=NEWL'.

PERFORM bdc_dynpro USING 'SAPL080E' '0040'.

PERFORM bdc_field USING 'BDC_CURSOR'

'V_T604-MINOL'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=UEBE'.

PERFORM bdc_field USING 'V_T604-LAND1'

gi_itab_a-land1.

PERFORM bdc_field USING 'V_T604-STAWN'

gi_itab_a-stawn.

PERFORM bdc_field USING 'V_T604-TEXT1'

gi_itab_a-text1.

PERFORM bdc_field USING 'V_T604-BEMEH'

gi_itab_a-bemeh.

PERFORM bdc_field USING 'V_T604-IMPMA'

gi_itab_a-impma.

PERFORM bdc_field USING 'V_T604-MINOL'

gi_itab_a-minol.

PERFORM bdc_dynpro USING 'SAPL080E' '0020'.

PERFORM bdc_field USING 'BDC_CURSOR'

'V_T604-BEMEH(01)'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=BACK'.

PERFORM bdc_dynpro USING 'SAPLSPO1' '0100'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=YES'.

PERFORM bdc_dynpro USING 'SAPLSTRD' '0300'.

PERFORM bdc_field USING 'BDC_CURSOR'

'KO008-TRKORR'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=INSA'.

PERFORM bdc_field USING 'KO008-TRKORR'

'BS7K900776'.

PERFORM bdc_dynpro USING 'SAPLSTR8' '0102'.

PERFORM bdc_field USING 'BDC_CURSOR'

'KO013-PROJECT'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=DOUBLECLICK'.

PERFORM bdc_field USING 'KO013-TARSYSTEM'

'BS7.200'.

PERFORM bdc_dynpro USING 'SAPLSTR8' '0102'.

PERFORM bdc_field USING 'BDC_CURSOR'

'KO013-AS4TEXT'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=CREA'.

PERFORM bdc_field USING 'KO013-AS4TEXT'

'another req'.

PERFORM bdc_field USING 'KO013-TARSYSTEM'

'BS7.200'.

PERFORM bdc_dynpro USING 'SAPLSTRD' '0300'.

PERFORM bdc_field USING 'BDC_CURSOR'

'KO008-TRKORR'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=LOCK'.

PERFORM bdc_field USING 'KO008-TRKORR'

'BS7K900778'.

PERFORM bdc_dynpro USING 'SAPMSVMA' '0100'.

PERFORM bdc_field USING 'BDC_OKCODE'

'/EBACK'.

PERFORM bdc_field USING 'BDC_CURSOR'

'VIEWNAME'.

PERFORM bdc_transaction USING 'SM30'.

ENDLOOP.

ENDIF.

  • PERFORM close_group.

ENDFORM. "bdc

&----


*& Form bdc_dynpro

&----


  • text

----


  • -->X_PROGRAM text

  • -->X_DYNPRO text

----


FORM bdc_dynpro USING x_program TYPE any x_dynpro TYPE any. " BDC sturucture

CLEAR gw_bdcdata.

gw_bdcdata-program = x_program.

gw_bdcdata-dynpro = x_dynpro.

gw_bdcdata-dynbegin = gc_dynbegin.

APPEND gw_bdcdata TO gi_bdcdata.

ENDFORM. "bdc_dynpro

&----


*& Form bdc_field

&----


  • text

----


  • -->X_FNAM text

  • -->X_FVAL text

----


FORM bdc_field USING x_fnam TYPE any x_fval TYPE any.

IF NOT x_fval IS INITIAL.

CLEAR gw_bdcdata.

gw_bdcdata-fnam = x_fnam.

gw_bdcdata-fval = x_fval.

APPEND gw_bdcdata TO gi_bdcdata.

ENDIF.

ENDFORM. "BDC_FIELD

&----


*& Form bdc_transaction

&----


  • text

----


  • -->X_TCODE text

----


FORM bdc_transaction USING x_tcode TYPE any. "BDC Transaction

DATA: lv_flag TYPE c.

CALL TRANSACTION x_tcode USING gi_bdcdata

MODE gc_mode

UPDATE gc_mode1

MESSAGES INTO gi_msg.

IF sy-subrc NE 0.

EXIT.

ENDIF.

CLEAR: lv_flag.

LOOP AT gi_msg INTO gw_msg.

IF gw_msg-msgtyp EQ gc_sucess.

IF lv_flag EQ space.

gv_no_succs = gv_no_succs + 1.

lv_flag = gc_flag.

ENDIF.

ELSE.

CALL FUNCTION 'MESSAGE_TEXT_BUILD'

EXPORTING

msgid = gw_msg-msgid

msgnr = gw_msg-msgnr

msgv1 = gw_msg-msgv1

msgv2 = gw_msg-msgv2

msgv3 = gw_msg-msgv3

msgv4 = gw_msg-msgv4

IMPORTING

message_text_output = gv_msg.

APPEND gv_msg TO gi_msg.

IF lv_flag EQ space.

gv_no_error = gv_no_error + 1.

lv_flag = gc_flag.

ENDIF.

ENDIF.

ENDLOOP.

ENDFORM. "bdc_transaction

Former Member
0 Kudos

hi pratik,

same requirement to me plz if you have any solution try to share

regards

PNK