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: 

BDC PROGRAM

Former Member
0 Kudos
125

BDC-THE FLAT FILE OF MATERIAL IS NOT BEING UPLOADED BY CALL TRANSACTION METHOD (READ FROM FILE METHOD) WHAT SHOULD I DO?

8 REPLIES 8

Former Member
0 Kudos
87

Hi,

U have to use tabulated txt file still it is not working check the exetension of file .

Send me errrors

Rewards points if it is useful.

0 Kudos
87

Hello bhatia,

I have used tabulated file only and the extension of the file is .txt file only.

Still I am not able to upload to the flat file.

0 Kudos
87
  • remember to close the flat file when executing the program.

  • check the extension of the file.

regards,

srinivas

Former Member
0 Kudos
87

hi,

what is the format of ur flatfile?

check my example:

TABLES : IBIPPARMS.

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

*& Types

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

TYPES : BEGIN OF TY_ITAB,

MATNR TYPE MATNR, "MATERIAL NO

WERKS TYPE WERKS, "PLANT

STLAN TYPE STLAN, "BOM USAGE

DATUV TYPE DATUV, "VALID DATE

BMENG TYPE BMENG, "BASE QUANTITY

IDNRK TYPE IDNRK, "COMPONENT

MENGE TYPE RC29P-MENGE, "QUANTITY

MEINS TYPE MEINS, "UNIT

POSTP TYPE POSTP, "ITEM CATEGORY

END OF TY_ITAB.

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

*& DATA Declaration

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

DATA : IT_ITAB TYPE TABLE OF TY_ITAB WITH HEADER LINE.

DATA : IT_BDCDATA TYPE TABLE OF BDCDATA WITH HEADER LINE.

DATA : IT_BDCMSGCOLL TYPE TABLE OF BDCMSGCOLL WITH HEADER LINE.

DATA : P_FILE1 TYPE STRING ,"FILE NAME

V_LINES TYPE I.

DATA : IT1_ITAB like IT_ITAB occurs 0 with header line.

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

*& SELECTION-SCREEN DECLARATION

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

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.

PARAMETERS : P_FILE TYPE LOCALFILE OBLIGATORY."FILE NAME

SELECTION-SCREEN END OF BLOCK B1 .

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

  • AT-SELECTION-SCREEN DECALRATION *

  • *

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

----


AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.

----


clear : P_FILE.

CALL FUNCTION 'F4_FILENAME'

EXPORTING

PROGRAM_NAME = SYST-CPROG

DYNPRO_NUMBER = SYST-DYNNR

IMPORTING

FILE_NAME = P_FILE.

IF P_FILE IS NOT INITIAL.

  • VALIDATE FILE TYPE

PERFORM SUB_VALIDATE_txt_TYPE.

ENDIF.

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

  • START-OF-SELECTION

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

start-of-selection.

perform upload.

perform bdc.

&----


*& Form upload

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM upload .

clear : P_FILE1.

P_FILE1 = P_FILE.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = P_FILE1

FILETYPE = 'ASC'

HAS_FIELD_SEPARATOR = 'X'

TABLES

DATA_TAB = IT_ITAB

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.

endif.

ENDFORM. " upload

form bdc.

*COPY DATA FROM IT_ITAB INTO IT_ITAB1

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

IT1_ITAB[] = IT_ITAB[].

*IF SY-SUBRC <> 0 OR IT_ITAB IS INITIAL.

    • UNABLE TO UPLOAD DATA FROM FLAT FILE

*MESSAGE I003(ZMSG).

*ENDIF.

&----


*& Form bdc

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


*FORM BDC.

LOOP AT IT_ITAB.

REFRESH IT_BDCDATA .

*FIRST SCREEN

perform bdc_dynpro using 'SAPLCSDI' '0100'.

perform bdc_field using 'BDC_CURSOR'

'RC29N-DATUV'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_field using 'RC29N-MATNR'

IT_ITAB-MATNR.

perform bdc_field using 'RC29N-WERKS'

IT_ITAB-WERKS.

perform bdc_field using 'RC29N-STLAN'

IT_ITAB-STLAN.

perform bdc_field using 'RC29N-DATUV'

IT_ITAB-DATUV.

*SECOND SCREEN

perform bdc_dynpro using 'SAPLCSDI' '0110'.

perform bdc_field using 'BDC_CURSOR'

'RC29K-BMENG'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_field using 'RC29K-BMENG'

IT_ITAB-BMENG.

perform bdc_field using 'RC29K-STLST'

'1'.

*THIRD SCREEN

LOOP AT IT1_ITAB WHERE MATNR = IT_ITAB-MATNR.

perform bdc_dynpro using 'SAPLCSDI' '0111'.

perform bdc_field using 'BDC_CURSOR'

'RC29K-LABOR'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_dynpro using 'SAPLCSDI' '0140'.

perform bdc_field using 'BDC_CURSOR'

'RC29P-POSTP(02)'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

*perform bdc_field using 'RC29P-IDNRK(01)'

  • IT_ITAB-IDNRK.

perform bdc_field using 'RC29P-IDNRK(SY-TABIX)'

IT_ITAB-IDNRK.

perform bdc_field using 'RC29P-IDNRK(02)'

'100017'.

perform bdc_field using 'RC29P-MENGE(SY-TABIX)'

IT_ITAB-MENGE.

perform bdc_field using 'RC29P-MENGE(02)'

'200'.

perform bdc_field using 'RC29P-MEINS(SY-TABIX)'

IT_ITAB-MEINS.

perform bdc_field using 'RC29P-MEINS(02)'

'kg'.

perform bdc_field using 'RC29P-POSTP(SY-TABIX)'

IT_ITAB-POSTP.

perform bdc_field using 'RC29P-POSTP(02)'

'l'.

ENDLOOP.

perform bdc_dynpro using 'SAPLCSDI' '0130'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_field using 'BDC_CURSOR'

'RC29P-POSNR'.

perform bdc_field using 'RC29P-POSNR'

'0010'.

perform bdc_field using 'RC29P-IDNRK'

'100012'.

perform bdc_field using 'RC29P-MENGE'

'150'.

perform bdc_field using 'RC29P-MEINS'

'KG'.

perform bdc_dynpro using 'SAPLCSDI' '0131'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_field using 'BDC_CURSOR'

'RC29P-POTX1'.

perform bdc_field using 'RC29P-SANKA'

'X'.

perform bdc_dynpro using 'SAPLCSDI' '0130'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_field using 'BDC_CURSOR'

'RC29P-POSNR'.

perform bdc_field using 'RC29P-POSNR'

'0020'.

perform bdc_field using 'RC29P-IDNRK'

'100017'.

perform bdc_field using 'RC29P-MENGE'

'200'.

perform bdc_field using 'RC29P-MEINS'

'KG'.

perform bdc_dynpro using 'SAPLCSDI' '0131'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_field using 'BDC_CURSOR'

'RC29P-POTX1'.

perform bdc_field using 'RC29P-SANKA'

'X'.

perform bdc_dynpro using 'SAPLCSDI' '0140'.

perform bdc_field using 'BDC_CURSOR'

'RC29P-POSNR(01)'.

perform bdc_field using 'BDC_OKCODE'

'=FCBU'.

*perform bdc_transaction using 'CS01'.

*perform close_group.

CALL TRANSACTION 'CS01' USING IT_BDCDATA MODE 'N'

UPDATE 'S'

MESSAGES INTO IT_BDCMSGCOLL.

CLEAR IT_ITAB.

ENDLOOP.

endform.

**GET THE NUMBER OF LINES

*DESCRIBE TABLE IT_BDCMSGCOLL LINES V_LINES.

**ENDFORM.

&----


*& Form SUB_VALIDATE_TXT_TYPE

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM SUB_VALIDATE_txt_TYPE .

DATA : STR1 TYPE LOCALFILE,

STR2 TYPE CHAR3.

SPLIT P_FILE AT '.' INTO STR1 STR2.

TRANSLATE STR2 TO LOWER CASE.

IF STR2 NE 'txt'.

  • please enter '.txt' file format

MESSAGE I001(ZMSG).

LEAVE LIST-PROCESSING.

ENDIF.

ENDFORM. " SUB_VALIDATE_TXT_TYPE

&----


*& Form bdc_dynpro

&----


  • text

----


  • -->P_0160 text

  • -->P_0161 text

----


FORM bdc_dynpro USING PROGRAM DYNPRO.

CLEAR IT_BDCDATA.

IT_BDCDATA-PROGRAM = PROGRAM.

IT_BDCDATA-DYNPRO = DYNPRO.

IT_BDCDATA-DYNBEGIN = 'X'.

APPEND IT_BDCDATA.

ENDFORM. " bdc_dynpro

&----


*& Form bdc_field

&----


  • text

----


  • -->P_0160 text

  • -->P_ENDLOOP text

----


FORM bdc_field USING FNAM FVAL.

CLEAR IT_BDCDATA. .

IT_BDCDATA-FNAM = FNAM.

IT_BDCDATA-FVAL = FVAL.

APPEND IT_BDCDATA.

ENDFORM. " bdc_field

Former Member
0 Kudos
87

Hi:

Check whether BDC table is populated correctly before invoking CALL TRANSACTION statement?

Regards.

Former Member
0 Kudos
87

here is one example

Program1 – uploading data into a table using recording from text file

report ZKIRAN_UPLOAD

no standard page heading line-size 255.

include bdcrecx1.

--


Tables declaration--

tables : zkiran_tab2.

--


data declaration--

data : itab like zkiran_tab2 occurs 15 with header line.

--


selection screen--

selection-screen: begin of block a1.

parameters : i_file like rlgrap-filename default 'D:\Documents and Settings\tzj13g\Desktop\sample.txt'.

selection-screen : end of block a1.

*at selection-screen on value-request for i_file.

*CALL FUNCTION 'F4_FILENAME'

*EXPORTING

*PROGRAM_NAME = sy-repid

  • DYNPRO_NUMBER = SYST-DYNNR

  • FIELD_NAME = ' '

    • IMPORTING

*FILE_NAME = i_file.

start-of-selection.

parameters: dataset(132) lower case.

      • DO NOT CHANGE - the generated data section - DO NOT CHANGE ***

*

  • If it is nessesary to change the data section use the rules:

  • 1.) Each definition of a field exists of two lines

  • 2.) The first line shows exactly the comment

  • '* data element: ' followed with the data element

  • which describes the field.

  • If you don't have a data element use the

  • comment without a data element name

  • 3.) The second line shows the fieldname of the

  • structure, the fieldname must consist of

  • a fieldname and optional the character '_' and

  • three numbers and the field length in brackets

  • 4.) Each field must be type C.

*

      • Generated data section with specific formatting - DO NOT CHANGE ***

data: begin of record,

  • data element: CLASSTAB

TBMA_001(001),

  • data element: TABNAME16

TBMA_VAL_002(016),

  • data element: ZEMPNO

EMPNO_003(010),

  • data element: ZNAME

NAME_004(020),

  • data element: ZDEPTID

DEPTID_005(002),

  • data element: ZDESIG

DESIG_006(010),

  • data element: ZPLACE

PLACE_007(010),

  • data element: CLASSTAB

TBMA_008(001),

  • data element: TABNAME16

TBMA_VAL_009(016),

end of record.

      • End generated data section ***

start-of-selection.

perform u_itab.

perform upload_ztable.

end-of-selection.

&----


*& Form upload_ztable

&----


FORM upload_ztable .

  • perform open_dataset using dataset.

  • perform open_group.

loop at itab.

  • read dataset dataset into record.

  • if sy-subrc <> 0. exit. endif.

perform bdc_dynpro using 'SAPMSRD0' '0102'.

perform bdc_field using 'BDC_CURSOR'

'RSRD1-TBMA_VAL'.

perform bdc_field using 'BDC_OKCODE'

'=SHOW'.

perform bdc_field using 'RSRD1-TBMA'

record-TBMA_001.

perform bdc_field using 'RSRD1-TBMA_VAL'

'ZKIRAN_TAB2'.

perform bdc_dynpro using 'SAPLSD41' '2200'.

perform bdc_field using 'BDC_CURSOR'

'DD02D-TABCLTEXT'.

perform bdc_field using 'BDC_OKCODE'

'=TDED'.

perform bdc_dynpro using '/1BCDWB/DBZKIRAN_TAB2' '0101'.

perform bdc_field using 'BDC_CURSOR'

'ZKIRAN_TAB2-PLACE'.

perform bdc_field using 'BDC_OKCODE'

'=SAVE'.

perform bdc_field using 'ZKIRAN_TAB2-EMPNO'

ITAB-EMPNO.

perform bdc_field using 'ZKIRAN_TAB2-NAME'

ITAB-NAME.

perform bdc_field using 'ZKIRAN_TAB2-DEPTID'

ITAB-DEPTID.

perform bdc_field using 'ZKIRAN_TAB2-DESIG'

ITAB-DESIG.

perform bdc_field using 'ZKIRAN_TAB2-PLACE'

ITAB-PLACE.

perform bdc_dynpro using '/1BCDWB/DBZKIRAN_TAB2' '0101'.

perform bdc_field using 'BDC_OKCODE'

'/EBACK'.

perform bdc_field using 'BDC_CURSOR'

'ZKIRAN_TAB2-EMPNO'.

perform bdc_dynpro using 'SAPLSD41' '2200'.

perform bdc_field using 'BDC_CURSOR'

'DD02D-TABCLTEXT'.

perform bdc_field using 'BDC_OKCODE'

'=WB_BACK'.

perform bdc_dynpro using 'SAPMSRD0' '0102'.

perform bdc_field using 'BDC_CURSOR'

'RSRD1-TBMA_VAL'.

perform bdc_field using 'BDC_OKCODE'

'=BACK'.

perform bdc_field using 'RSRD1-TBMA'

record-TBMA_008.

perform bdc_field using 'RSRD1-TBMA_VAL'

record-TBMA_VAL_009.

perform bdc_transaction using 'SE11'.

endloop.

  • perform close_group.

  • perform close_dataset using dataset.

ENDFORM. " upload_ztable

&----


*& Form upload_itab

&----


FORM u_itab .

break-point.

CALL FUNCTION 'WS_UPLOAD'

EXPORTING

  • CODEPAGE = ' '

FILENAME = i_file

FILETYPE = 'DAT'

  • HEADLEN = ' '

  • LINE_EXIT = ' '

  • TRUNCLEN = ' '

  • USER_FORM = ' '

  • USER_PROG = ' '

  • DAT_D_FORMAT = ' '

  • IMPORTING

  • FILELENGTH =

TABLES

DATA_TAB = itab

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

.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

Former Member
0 Kudos
87

one more example

Program2- Updating data into table from text file

&----


*& Report YTEST

*&

&----


*&

*&

&----


REPORT YTEST.

--


Table declaration--

TABLES : ZKIRAN_T1.

--


variable declaration--

--


interna table s declaration--

DATA : ITAB LIKE ZKIRAN_T1 OCCURS 10 WITH HEADER LINE.

--


selectio-screen--

selection-screen: begin of block b1.

parameters : p_file like rlgrap-filename default 'D:\Documents and Settings\tzj13g\Desktop\sample.txt'.

selection-screen : end of block b1.

start-of-selection.

perform upload_itab.

perform display.

-at selection-screen--


&----


*& Form upload_itab

&----


FORM upload_itab .

CALL FUNCTION 'WS_UPLOAD'

EXPORTING

  • CODEPAGE = ' '

FILENAME = p_file

FILETYPE = 'ASC'

  • HEADLEN = ' '

  • LINE_EXIT = ' '

  • TRUNCLEN = ' '

  • USER_FORM = ' '

  • USER_PROG = ' '

  • DAT_D_FORMAT = ' '

  • IMPORTING

  • FILELENGTH =

TABLES

DATA_TAB = itab

  • 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

.

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_itab

&----


*& Form display

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM display .

modify zkiran_t1 from table itab.

ENDFORM. " display

Former Member
0 Kudos
87

Hi i will tell u how recording BDC for MM01 ,

Goto Tcode SHDB ,

Click on New Recording ,

Give The Recording Name and Tranction Code For which U have to write BDC Suppose MM01 for ur Requirtment ,

Click on Start Recoding ,

Give the value :

Material: 01ABC.

Industry Sector:Food & Related Product,

Material Type : Finished Product ,

One this kept in ur mind when ever u recorded a BDC First u see Industry Sector and Material type Should be Match other wish i will give error .

After Giving Three Fields in First Screen Press Select Views

Choose Basic Data1 and Basic Data2 then press continue button .

In Third Screen give the Material Description : meal.

unit of measured : BT Then Press save buttom .again save and back

Select the recoding name click on program and give the program name then continue ,

Plz carefully this BDC code For MM01 given bellow...............................

REPORT zm_mm01_bdc NO STANDARD PAGE HEADING LINE-SIZE 255.

DATA: ibdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE.

DATA: messtab LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE.

DATA: message(255).

DATA: BEGIN OF ITAB OCCURS 0,

MATNR TYPE MARA-MATNR,

MBRSH TYPE MARA-MBRSH,

MTART TYPE MARA-MTART,

END OF ITAB.

CALL FUNCTION 'UPLOAD'

EXPORTING

filename = ' '

filetype = ' '

  • has_field_separator = 'X'

TABLES

data_tab = itab.

  • DESCRIBE TABLE itab LINES lines1.

  • WRITE : / lines1 , 'REcords uploaded' .

START-OF-SELECTION.

LOOP AT ITAB.

REFRESH IBDCDATA.

PERFORM bdc_dynpro USING 'SAPLMGMM' '0060'.

PERFORM bdc_field USING 'BDC_CURSOR'

'RMMG1-MTART'.

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

PERFORM bdc_field USING 'RMMG1-MATNR'

ITAB-MATNR.

PERFORM bdc_field USING 'RMMG1-MBRSH'

ITAB-MBRSH.

PERFORM bdc_field USING 'RMMG1-MTART'

ITAB-MTART.

PERFORM bdc_dynpro USING 'SAPLMGMM' '0070'.

PERFORM bdc_field USING 'BDC_CURSOR'

'MSICHTAUSW-DYTXT(02)'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=ENTR'.

PERFORM bdc_field USING 'MSICHTAUSW-KZSEL(01)'

'X'.

PERFORM bdc_field USING 'MSICHTAUSW-KZSEL(02)'

'X'.

PERFORM bdc_dynpro USING 'SAPLMGMM' '4004'.

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

PERFORM bdc_field USING 'MAKT-MAKTX'

'TEST MATERIAL'.

PERFORM bdc_field USING 'BDC_CURSOR'

'MARA-MEINS'.

PERFORM bdc_field USING 'MARA-MEINS'

'EA'.

PERFORM bdc_dynpro USING 'SAPLMGMM' '4004'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=BU'.

PERFORM bdc_field USING 'BDC_CURSOR'

'MAKT-MAKTX'.

PERFORM bdc_field USING 'MAKT-MAKTX'

'TEST MATERIAL'.

CALL TRANSACTION 'MM01'

USING ibdcdata

UPDATE 'A'

MODE 'E'

MESSAGES INTO messtab.

ENDLOOP.

IF NOT messtab[] IS INITIAL.

LOOP AT messtab.

CALL FUNCTION 'FORMAT_MESSAGE'

EXPORTING

id = messtab-msgid

lang = messtab-msgspra

no = messtab-msgnr

IMPORTING

msg = message

EXCEPTIONS

not_found = 1

OTHERS = 2.

ENDLOOP.

ENDIF.

----


  • Start new screen *

----


FORM bdc_dynpro USING program dynpro.

CLEAR ibdcdata.

ibdcdata-program = program.

ibdcdata-dynpro = dynpro.

ibdcdata-dynbegin = 'X'.

APPEND ibdcdata.

ENDFORM. "BDC_DYNPRO

----


  • Insert field *

----


FORM bdc_field USING fnam fval.

CLEAR ibdcdata.

ibdcdata-fnam = fnam.

ibdcdata-fval = fval.

APPEND ibdcdata.

ENDFORM. "BDC_FIELD

Regards,

Nihar Swain.........