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: 

need small bdc programe code to transfer data into table

laxman_sankhla3
Participant
0 Kudos

hi

i want to transfer Non SAP data into SAP by using BDC call transaction method.

i want to transfer only in ztable .

Employee Name and Employee No.

please help me .

thanks in advanced.

8 REPLIES 8

Former Member
0 Kudos

If its from a file I have a program that will load data into a Z table using direct update. It uses Objects though so it will depend on the version of your SAP system.

What version are you using.

0 Kudos

version is 4.7

thanks

Former Member
0 Kudos

no need to go for bdc program ,use modify command or insert command..

See the below sample program :

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

  • Program : ZLWMI151_UPLOAD(Data load to ZBATCH_CROSS_REF Table)

  • Type : Upload program

  • Author : Seshu Maramreddy

  • Date : 05/16/2005

  • Transport : DV3K919574

  • Transaction: None

  • Description: This program will get the data from XLS File

  • and it upload to ZBATCH_CROSS_REF Table

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

REPORT ZLWMI151_UPLOAD no standard page heading

line-size 100 line-count 60.

*tables : zbatch_cross_ref.

data : begin of t_text occurs 0,

werks(4) type c,

cmatnr(15) type c,

srlno(12) type n,

matnr(7) type n,

charg(10) type n,

end of t_text.

data: begin of t_zbatch occurs 0,

werks like zbatch_cross_ref-werks,

cmatnr like zbatch_cross_ref-cmatnr,

srlno like zbatch_cross_ref-srlno,

matnr like zbatch_cross_ref-matnr,

charg like zbatch_cross_ref-charg,

end of t_zbatch.

data : g_repid like sy-repid,

g_line like sy-index,

g_line1 like sy-index,

$v_start_col type i value '1',

$v_start_row type i value '2',

$v_end_col type i value '256',

$v_end_row type i value '65536',

gd_currentrow type i.

data: itab like alsmex_tabline occurs 0 with header line.

data : t_final like zbatch_cross_ref occurs 0 with header line.

selection-screen : begin of block blk with frame title text.

parameters : p_file like rlgrap-filename obligatory.

selection-screen : end of block blk.

initialization.

g_repid = sy-repid.

at selection-screen on value-request for p_file.

CALL FUNCTION 'F4_FILENAME'

EXPORTING

PROGRAM_NAME = g_repid

IMPORTING

FILE_NAME = p_file.

start-of-selection.

  • Uploading the data into Internal Table

perform upload_data.

perform modify_table.

top-of-page.

CALL FUNCTION 'Z_HEADER'

  • EXPORTING

  • FLEX_TEXT1 =

  • FLEX_TEXT2 =

  • FLEX_TEXT3 =

.

&----


*& Form upload_data

&----


  • text

----


FORM upload_data.

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

EXPORTING

FILENAME = p_file

I_BEGIN_COL = $v_start_col

I_BEGIN_ROW = $v_start_row

I_END_COL = $v_end_col

I_END_ROW = $v_end_row

TABLES

INTERN = itab

EXCEPTIONS

INCONSISTENT_PARAMETERS = 1

UPLOAD_OLE = 2

OTHERS = 3.

IF SY-SUBRC <> 0.

write:/10 'File '.

ENDIF.

if sy-subrc eq 0.

read table itab index 1.

gd_currentrow = itab-row.

loop at itab.

if itab-row ne gd_currentrow.

append t_text.

clear t_text.

gd_currentrow = itab-row.

endif.

case itab-col.

when '0001'.

t_text-werks = itab-value.

when '0002'.

t_text-cmatnr = itab-value.

when '0003'.

t_text-srlno = itab-value.

when '0004'.

t_text-matnr = itab-value.

when '0005'.

t_text-charg = itab-value.

endcase.

endloop.

endif.

append t_text.

ENDFORM. " upload_data

&----


*& Form modify_table

&----


  • Modify the table ZBATCH_CROSS_REF

----


FORM modify_table.

loop at t_text.

t_final-werks = t_text-werks.

t_final-cmatnr = t_text-cmatnr.

t_final-srlno = t_text-srlno.

t_final-matnr = t_text-matnr.

t_final-charg = t_text-charg.

t_final-erdat = sy-datum.

t_final-erzet = sy-uzeit.

t_final-ernam = sy-uname.

t_final-rstat = 'U'.

append t_final.

clear t_final.

endloop.

delete t_final where werks = ''.

describe table t_final lines g_line.

sort t_final by werks cmatnr srlno.

  • Deleting the Duplicate Records

perform select_data.

describe table t_final lines g_line1.

modify zbatch_cross_ref from table t_final.

if sy-subrc ne 0.

write:/ 'Updation failed'.

else.

Skip 1.

Write:/12 'Updation has been Completed Sucessfully'.

skip 1.

Write:/12 'Records in file ',42 g_line .

write:/12 'Updated records in Table',42 g_line1.

endif.

delete from zbatch_cross_ref where werks = ''.

ENDFORM. " modify_table

&----


*& Form select_data

&----


  • Deleting the duplicate records

----


FORM select_data.

select werks

cmatnr

srlno from zbatch_cross_ref

into table t_zbatch for all entries in t_final

where werks = t_final-werks

and cmatnr = t_final-cmatnr

and srlno = t_final-srlno.

sort t_zbatch by werks cmatnr srlno.

loop at t_zbatch.

read table t_final with key werks = t_zbatch-werks

cmatnr = t_zbatch-cmatnr

srlno = t_zbatch-srlno.

if sy-subrc eq 0.

delete table t_final .

endif.

clear: t_zbatch,

t_final.

endloop.

ENDFORM. " select_data

Reward Points if it is helpful

Thanks

Seshu

Former Member
0 Kudos

Hi,

Here is a program I had created for MM01 transac. Please Modify as applicable.

REPORT ZMP_CALL_TRANSC.

&----


  • TEMPLATES

&----


TYPES: BEGIN OF X_FF,

MATNR(20), " material number

MBRSH(20), " industry sector

MTART(40), " material type

MAKTX(40), " material description

MEINS(3), " unit of measure

MATKL(4), "material grp

TRAGR(4), "tRANSPORTATION GRP

END OF X_FF.

&----


  • DECLARATIONS

&----


  • Flat file

DATA: I_FF TYPE X_FF OCCURS 0 WITH HEADER LINE.

  • BDC Data

DATA: I_BDC LIKE BDCDATA OCCURS 0 WITH HEADER LINE.

  • messages

DATA: I_MSG LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.

&----


  • SOS

&----


START-OF-SELECTION.

  • Get Flat file Data

PERFORM GET_DATA.

  • Get BDC file data

PERFORM GENERATE.

&----


*& Form GET_DATA

&----


FORM GET_DATA .

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = 'C:\EXAMPLE.TXT'

FILETYPE = 'ASC'

HAS_FIELD_SEPARATOR = 'X'

  • HEADER_LENGTH = 0

  • READ_BY_LINE = 'X'

  • DAT_MODE = ' '

  • IMPORTING

  • FILELENGTH =

  • HEADER =

TABLES

DATA_TAB = I_FF

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.

  • DELETE I_FF INDEX 1.

  • ENDIF.

*

LOOP AT I_FF.

WRITE : I_FF-MBRSH.

ENDLOOP.

ENDFORM. " GET_DATA

&----


*& Form GENERATE

&----


FORM GENERATE .

DATA : LV_MSG(255).

LOOP AT I_FF.

PERFORM POPULATE USING : 'X' 'SAPLMGMM' '0060',

'' 'BDC_OKCODE' '/00',

'' 'RMMG1-MATNR' I_FF-MATNR,

'' 'RMMG1-MBRSH' I_FF-MBRSH,

'' 'RMMG1-MTART' I_FF-MTART,

'X' 'SAPLMGMM' '0070',

'' 'BDC_OKCODE' '=SP02',

'' 'MSICHTAUSW-KZSEL(01)' 'X',

'' 'MSICHTAUSW-KZSEL(02)' 'X',

'' 'MSICHTAUSW-KZSEL(04)' 'X',

'' 'MSICHTAUSW-KZSEL(05)' 'X',

'' 'MSICHTAUSW-KZSEL(06)' 'X',

'' 'MSICHTAUSW-KZSEL(07)' 'X',

'' 'MSICHTAUSW-KZSEL(09)' 'X',

'X' 'SAPLMGMM' '4004',

'' 'BDC_OKCODE' '=ENTR',

'' 'MAKT-MAKTX' I_FF-MAKTX,

'' 'MARA-MEINS' I_FF-MEINS,

'' 'MARA-MATKL' I_FF-MATKL,

  • '' 'BDC_OKCODE' '/00',

'X' 'SAPLMGMM' '4000',

'' 'BDC_OKCODE' '=BU',

'' 'BDC_CURSOR' 'mara-tragr',

'' 'MARA-TRAGR' I_FF-TRAGR,

  • 'X' 'SAPLMGMM' '4004',

  • '' 'BDC_OKCODE' '=entr',

  • '' 'MAKT-MAKTX' I_FF-MAKTX,

  • '' 'MARA-MEINS' I_FF-MEINS,

*

  • 'X' 'SAPLMGMM' '4004',

  • '' 'BDC_OKCODE' '/00',

  • '' 'MAKT-MAKTX' I_FF-MAKTX,

  • '' 'MARA-MEINS' I_FF-MEINS,

'X' 'SAPLSPO1' '0300',

'' 'BDC_OKCODE' '=YES'.

CALL TRANSACTION 'MM01' USING I_BDC MODE 'A' UPDATE 'S' MESSAGES INTO I_MSG.

IF NOT I_MSG[] IS INITIAL.

LOOP AT I_MSG.

CALL FUNCTION 'FORMAT_MESSAGE'

EXPORTING

ID = I_MSG-MSGID

LANG = SY-LANGU

NO = I_MSG-MSGNR

V1 = I_MSG-MSGV1

V2 = I_MSG-MSGV2

V3 = I_MSG-MSGV3

V4 = I_MSG-MSGV4

IMPORTING

MSG = LV_MSG

EXCEPTIONS

NOT_FOUND = 1

OTHERS = 2.

IF SY-SUBRC = 0.

WRITE:/ LV_MSG.

ENDIF.

ENDLOOP.

ENDIF.

CLEAR: I_BDC[],I_MSG[].

ENDLOOP.

*ENDLOOP.

ENDFORM. " GENERATE

&----


*& Form POPULATE

&----


FORM POPULATE USING VALUE(P_0131)

VALUE(P_0132)

VALUE(P_0133).

IF P_0131 = 'X'.

I_BDC-PROGRAM = P_0132.

I_BDC-DYNPRO = P_0133.

I_BDC-DYNBEGIN = 'X'.

ELSE.

I_BDC-FNAM = P_0132.

I_BDC-FVAL = P_0133.

ENDIF.

APPEND I_BDC.

CLEAR I_BDC.

ENDFORM. " POPULATE

Reward if helpful.

Former Member
0 Kudos

You got an email address I can send it to.

Unlike the program mentioned below, my program is not hardcoded for a specific table. It will do any table. It reads the data dictionary and builds an internal table dynamically.

It may need tweaking for your system though.

0 Kudos

MY ID IS

laxmanmca@gmail.com

thanks.

0 Kudos

K.Kiran.

Message was edited by:

Kiran K

S0025444845
Active Participant
0 Kudos

Hi,

You can take help of this code

first u have to go to SHDB tcode n do the transaction recording n then with the help of recording u can do the neccessary changes with help of below code

&----


*& REPORT ZREPORT_BDC *

*& *

&----


*& *

*& *

&----


REPORT zreport_bdc .

TABLES: rf02k, lfa1, lfm1.

TYPES: BEGIN OF itb_file,

lifnr TYPE rf02k-lifnr,

ekorg TYPE rf02k-ekorg,

ktokk TYPE rf02k-ktokk,

anred TYPE lfa1-anred,

name1 TYPE lfa1-name1,

sortl TYPE lfa1-sortl,

ort01 TYPE lfa1-ort01,

pstlz TYPE lfa1-pstlz,

land1 TYPE lfa1-land1,

spras TYPE lfa1-spras,

waers TYPE lfm1-waers,

END OF itb_file.

DATA: gt_bdc TYPE TABLE OF bdcdata,

gw_bdc TYPE bdcdata,

gt_file TYPE TABLE OF itb_file,

gw_file TYPE itb_file.

DATA: it_msg TYPE TABLE OF bdcmsgcoll.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = 'C:\RUCHI.TXT'

  • FILETYPE = 'ASC'

has_field_separator = 'X'

  • HEADER_LENGTH = 0

  • READ_BY_LINE = 'X'

  • DAT_MODE = ' '

  • CODEPAGE = ' '

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • CHECK_BOM = ' '

  • IMPORTING

  • FILELENGTH =

  • HEADER =

TABLES

data_tab = gt_file

  • 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 gt_file INTO gw_file.

gw_bdc-program = 'SAPMF02K'.

gw_bdc-dynpro = '0107'.

gw_bdc-dynbegin = 'X'.

APPEND gw_bdc TO gt_bdc.

CLEAR gw_bdc.

gw_bdc-fnam = 'BDC_CURSOR'.

gw_bdc-fval = 'RF02K-KTOKK'.

APPEND gw_bdc TO gt_bdc.

CLEAR gw_bdc.

gw_bdc-fnam = 'BDC_OKCODE'.

gw_bdc-fval = '/00'.

APPEND gw_bdc TO gt_bdc.

CLEAR gw_bdc.

gw_bdc-fnam = 'RF02K-LIFNR'.

gw_bdc-fval = gw_file-lifnr.

APPEND gw_bdc TO gt_bdc.

CLEAR gw_bdc.

gw_bdc-fnam = 'RF02K-EKORG'.

gw_bdc-fval = gw_file-ekorg.

APPEND gw_bdc TO gt_bdc.

CLEAR gw_bdc.

gw_bdc-fnam = 'RF02K-KTOKK'.

gw_bdc-fval = gw_file-ktokk.

APPEND gw_bdc TO gt_bdc.

CLEAR gw_bdc.

gw_bdc-program = 'SAPMF02K'.

gw_bdc-dynpro = '0110'.

gw_bdc-dynbegin = 'X'.

APPEND gw_bdc TO gt_bdc.

CLEAR gw_bdc.

gw_bdc-fnam = 'BDC_CURSOR'.

gw_bdc-fval = 'LFA1-SPRAS'.

APPEND gw_bdc TO gt_bdc.

CLEAR gw_bdc.

gw_bdc-fnam = 'BDC_OKCODE'.

gw_bdc-fval = '/00'.

APPEND gw_bdc TO gt_bdc.

CLEAR gw_bdc.

gw_bdc-fnam = 'LFA1-ANRED'.

gw_bdc-fval = gw_file-anred.

APPEND gw_bdc TO gt_bdc.

CLEAR gw_bdc.

gw_bdc-fnam = 'LFA1-NAME1'.

gw_bdc-fval = gw_file-name1.

APPEND gw_bdc TO gt_bdc.

CLEAR gw_bdc.

gw_bdc-fnam = 'LFA1-SORTL'.

gw_bdc-fval = gw_file-sortl.

APPEND gw_bdc TO gt_bdc.

CLEAR gw_bdc.

gw_bdc-fnam = 'LFA1-ORT01'.

gw_bdc-fval = gw_file-ort01.

APPEND gw_bdc TO gt_bdc.

CLEAR gw_bdc.

gw_bdc-fnam = 'LFA1-PSTLZ'.

gw_bdc-fval = gw_file-pstlz.

APPEND gw_bdc TO gt_bdc.

CLEAR gw_bdc.

gw_bdc-fnam = 'LFA1-LAND1'.

gw_bdc-fval = gw_file-land1.

APPEND gw_bdc TO gt_bdc.

CLEAR gw_bdc.

gw_bdc-fnam = 'LFA1-SPRAS'.

gw_bdc-fval = gw_file-spras.

APPEND gw_bdc TO gt_bdc.

CLEAR gw_bdc.

gw_bdc-program = 'SAPMF02K'.

gw_bdc-dynpro = '0120'.

gw_bdc-dynbegin = 'X'.

APPEND gw_bdc TO gt_bdc.

CLEAR gw_bdc.

gw_bdc-fnam = 'BDC_CURSOR'.

gw_bdc-fval = 'LFA1-KUNNR'.

APPEND gw_bdc TO gt_bdc.

CLEAR gw_bdc.

gw_bdc-fnam = 'BDC_OKCODE'.

gw_bdc-fval = '/00'.

APPEND gw_bdc TO gt_bdc.

CLEAR gw_bdc.

gw_bdc-program = 'SAPMF02K'.

gw_bdc-dynpro = '0310'.

gw_bdc-dynbegin = 'X'.

APPEND gw_bdc TO gt_bdc.

CLEAR gw_bdc.

gw_bdc-fnam = 'BDC_CURSOR'.

gw_bdc-fval = 'LFM1-WAERS'.

APPEND gw_bdc TO gt_bdc.

CLEAR gw_bdc.

gw_bdc-fnam = 'BDC_OKCODE'.

gw_bdc-fval = '/00'.

APPEND gw_bdc TO gt_bdc.

CLEAR gw_bdc.

gw_bdc-fnam = 'LFM1-WAERS'.

gw_bdc-fval = gw_file-waers.

APPEND gw_bdc TO gt_bdc.

CLEAR gw_bdc.

gw_bdc-program = 'SAPMF02K'.

gw_bdc-dynpro = '0320'.

gw_bdc-dynbegin = 'X'.

APPEND gw_bdc TO gt_bdc.

CLEAR gw_bdc.

gw_bdc-fnam = 'BDC_CURSOR'.

gw_bdc-fval = 'RF02K-LIFNR'.

APPEND gw_bdc TO gt_bdc.

CLEAR gw_bdc.

gw_bdc-fnam = 'BDC_OKCODE'.

gw_bdc-fval = '=ENTR'.

APPEND gw_bdc TO gt_bdc.

CLEAR gw_bdc.

gw_bdc-program = 'SAPMF02K'.

gw_bdc-dynpro = '0300'.

gw_bdc-dynbegin = 'X'.

APPEND gw_bdc TO gt_bdc.

CLEAR gw_bdc.

gw_bdc-fnam = 'BDC_OKCODE'.

gw_bdc-fval = '=YES'.

APPEND gw_bdc TO gt_bdc.

CLEAR gw_bdc.

CALL TRANSACTION 'MK01' USING gt_bdc MODE 'A' MESSAGES INTO it_msg.

if sy-subrc eq 0.

message text-001 type 'S'.

endif.

ENDLOOP.