Skip to Content
0
Former Member
Apr 16, 2014 at 04:02 AM

bdc uploading problem for cs01

267 Views

i have created a bdc program for uploading data through cs01. in debugging mode , the header details is uploading and then corresponding item details are uploading. but when i check in sm35 it is uploading only one item and header. i attached the program. please check and tell me.... its very urgent...

REPORT ZR_CS01_UPLOAD NO STANDARD PAGE HEADING.

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

***declaration part***

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

***declaration of flatfile***

types: begin of ty_flatfile,

matnr type RC29N-MATNR, "MATERIAL NUMBER

werks type RC29N-WERKS, "PLANT

stlan type RC29N-STLAN, "BOM QUANTITY

DATUV TYPE RC29N-DATUV, "VALID FROM DATE

ZTEXT TYPE RC29K-ZTEXT, "BOM TEXT

BMENG(10) TYPE c, "Base quantity

STLST TYPE RC29K-STLST, "BOM status

idnrk type RC29P-IDNRK, "BOM component

menge(10) type c, "Component quantity

postp type RC29P-POSTP, "Item Category (Bill of Material)

POSNR TYPE RC29P-POSNR, " BOM ITEM NUMBER

END OF ty_flatfile.

data: ta_flatfile TYPE TABLE OF ty_flatfile,

wa_flatfile type ty_flatfile,

* ta_flatfile type TABLE OF ty_flatfile,

wa_flatfile1 type ty_flatfile.

***declaration of bdc data***

data: ta_bdcdata TYPE TABLE OF bdcdata,

wa_bdcdata type bdcdata.

***declaration of excel file handling table***

FIELD-SYMBOLS: <fs> type any. "field symbol for alsm_excel

DATA: TA_EXCEL TYPE TABLE OF ALSMEX_TABLINE, "table to contain excel sheet values

WA_EXCEL TYPE ALSMEX_TABLINE.

***declaration of other parameters***

data: V_brow type i VALUE 2, "BEGIN OF ROW

V_bcol type i value 1, "BEGIN OF COL

V_erow type i value 65536, "END OF ROW

V_ecol type i value 256. "END OF COLUMN

data: V_tabix type sy-tabix, "current line.

v_lines type i, "total number of records

v_index type i, "hold column in excel conversion

v_flag ,

V_sear type string,

G_FIELD TYPE STRING,

G_COUNTER(2) TYPE N VALUE 00.

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

***SELECTION SCREEN***

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

***SELECTION SCREEN DESIGN***

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

SELECTION-SCREEN SKIP 3.

PARAMETERS: p_file type IBIPPARMS-PATH . "input file

SELECTION-SCREEN SKIP 3.

SELECTION-SCREEN END OF BLOCK b1.

***SELECTION SCREEN VALUE REQUEST***

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.

CALL FUNCTION 'F4_FILENAME' "f4 help for file name

EXPORTING

PROGRAM_NAME = SYST-CPROG

DYNPRO_NUMBER = SYST-DYNNR

FIELD_NAME = 'P_FILE'

IMPORTING

FILE_NAME = P_FILE.

***SELECTION SCREEN EVENT***

AT SELECTION-SCREEN. "validation

if p_file <> ''.

V_sear = p_file.

SEARCH V_sear for '.xls'.

if sy-subrc <> 0.

message 'please provide excel file. it is not valid' type 'E'.

ENDIF.

ENDIF.

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

***START OF SELECTION***

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

START-OF-SELECTION.

PERFORM EXCEL_UPLOAD.

PERFORM EXCEL_CONVERSION.

PERFORM NO_RECORDS.

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

***END OF SELECTION***

END-OF-SELECTION.

* if ta_flatfile is NOT INITIAL.

* loop at ta_flatfile INTO wa_flatfile.

* MOVE-CORRESPONDING wa_flatfile to wa_flaTfile1.

* APPEND wa_flatfile1 to ta_flatfile.

* ENDLOOP.

* ENDIF.

if ta_flatfile is NOT INITIAL.

* sort ta_flatfile by matnr.

loop at ta_flatfile INTO wa_flatfile.

MOVE-CORRESPONDING wa_flatfile to wa_flatfile1.

at FIRST.

perform bdc_open_group. "bdc new session

ENDAT.

at NEW matnr.

clear wa_bdcdata.

v_flag = 'X'.

perform bdc_header_insert.

ENDat.

* perform bdc_item_insert.

G_COUNTER = G_COUNTER + 1.

perform bdc_dynpro using 'SAPLCSDI' '0140'.

perform bdc_field using 'BDC_CURSOR'

'RC29P-POSTP(01)'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

CONCATENATE 'RC29P-IDNRK(' g_counter ')' into g_field.

perform bdc_field using G_FIELD

WA_FLATFILE1-IDNRK.

CONCATENATE 'RC29P-MENGE(' g_counter ')' into g_field.

perform bdc_field using G_FIELD

WA_FLATFILE1-MENGE.

CONCATENATE 'RC29P-POSTP(' g_counter ')' into g_field.

perform bdc_field using G_FIELD

WA_FLATFILE1-POSTP.

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'

WA_FLATFILE1-POSNR.

perform bdc_field using 'RC29P-IDNRK'

WA_FLATFILE1-IDNRK.

perform bdc_field using 'RC29P-MENGE'

WA_FLATFILE1-MENGE.

perform bdc_field using 'RC29P-MEINS'

'EA'.

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'.

CONCATENATE 'RC29P-POSNR(' g_counter ')' into g_field.

perform bdc_field using 'BDC_CURSOR'

G_FIELD.

perform bdc_field using 'BDC_OKCODE'

'=FCBU'.

at END OF matnr.

perform bdc_insert.

ENDAT.

at LAST.

PERFORM bdc_close_group.

ENDAT.

ENDLOOP.

else.

MESSAGE 'no data for uploading' type 'E'.

ENDIF.


*&---------------------------------------------------------------------*

*& Form EXCEL_UPLOAD

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

* --> p1 text

* <-- p2 text

*----------------------------------------------------------------------*

FORM EXCEL_UPLOAD .

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

EXPORTING

FILENAME = P_FILE

I_BEGIN_COL = V_BCOL

I_BEGIN_ROW = V_BROW

I_END_COL = V_ECOL

I_END_ROW = V_EROW

TABLES

INTERN = TA_EXCEL

EXCEPTIONS

INCONSISTENT_PARAMETERS = 1

UPLOAD_OLE = 2

OTHERS = 3.

ENDFORM. " EXCEL_UPLOAD

*&---------------------------------------------------------------------*

*& Form EXCEL_CONVERSION

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

* --> p1 text

* <-- p2 text

*----------------------------------------------------------------------*

FORM EXCEL_CONVERSION .

if ta_excel is NOT INITIAL.

sort ta_excel by row col.

clear wa_excel.

clear wa_flatfile.

LOOP AT ta_excel INTO wa_excel.

move wa_excel-col to v_index.

ASSIGN COMPONENT v_index OF STRUCTURE wa_flatfile to <fs>.

if sy-subrc = 0.

move wa_excel-value to <fs>.

ENDIF.

at END OF row.

append wa_flatfile to ta_flatfile.

clear wa_flatfile.

ENDAT.

ENDLOOP.

else.

MESSAGE 'no data for conversion' type 'I'.

ENDIF.

ENDFORM. " EXCEL_CONVERSION

*&---------------------------------------------------------------------*

*& Form NO_RECORDS

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

* --> p1 text

* <-- p2 text

*----------------------------------------------------------------------*

FORM NO_RECORDS .

DESCRIBE TABLE ta_flatfile LINES v_lines.

if v_lines = 0.

MESSAGE 'NO RECORDS TO UPLOAD' TYPE 'E'.

V_FLAG = 'X'.

ENDIF.

ENDFORM. " NO_RECORDS

*&---------------------------------------------------------------------*

*& Form BDC_OPEN_GROUP

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

* --> p1 text

* <-- p2 text

*----------------------------------------------------------------------*

FORM BDC_OPEN_GROUP .

CALL FUNCTION 'BDC_OPEN_GROUP'

EXPORTING

CLIENT = SY-MANDT

* DEST = FILLER8

GROUP = 'ZCS01'

* HOLDDATE = FILLER8

KEEP = 'X'

USER = SY-UNAME

* RECORD = FILLER1

PROG = SY-CPROG

* DCPFM = '%'

* DATFM = '%'

* IMPORTING

* QID =

EXCEPTIONS

CLIENT_INVALID = 1

DESTINATION_INVALID = 2

GROUP_INVALID = 3

GROUP_IS_LOCKED = 4

HOLDDATE_INVALID = 5

INTERNAL_ERROR = 6

QUEUE_ERROR = 7

RUNNING = 8

SYSTEM_LOCK_ERROR = 9

USER_INVALID = 10

OTHERS = 11

.

IF SY-SUBRC <> 0.

* Implement suitable error handling here

ENDIF.

ENDFORM. " BDC_OPEN_GROUP

*&---------------------------------------------------------------------*

*& Form BDC_HEADER_INSERT

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

* --> p1 text

* <-- p2 text

*----------------------------------------------------------------------*

FORM BDC_HEADER_INSERT .

perform bdc_dynpro using 'SAPLCSDI' '0100'.

perform bdc_field using 'BDC_CURSOR'

'RC29N-STLAN'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_field using 'RC29N-MATNR'

WA_FLATFILE1-MATNR.

perform bdc_field using 'RC29N-WERKS'

WA_FLATFILE1-WERKS.

perform bdc_field using 'RC29N-STLAN'

WA_FLATFILE1-STLAN.

perform bdc_field using 'RC29N-DATUV'

WA_FLATFILE1-DATUV.

perform bdc_dynpro using 'SAPLCSDI' '0110'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_field using 'RC29K-ZTEXT'

WA_FLATFILE1-ZTEXT.

perform bdc_field using 'RC29K-BMENG'

WA_FLATFILE1-BMENG.

perform bdc_field using 'RC29K-STLST'

WA_FLATFILE1-STLST.

perform bdc_field using 'BDC_CURSOR'

'RC29K-EXSTL'.

perform bdc_dynpro using 'SAPLCSDI' '0111'.

perform bdc_field using 'BDC_CURSOR'

'RC29K-LABOR'.

perform bdc_field using 'BDC_OKCODE'

'/00'.


FORM BDC_INSERT .

CALL FUNCTION 'BDC_INSERT'

EXPORTING

TCODE = 'CS01'

* POST_LOCAL = NOVBLOCAL

* PRINTING = NOPRINT

* SIMUBATCH = ' '

* CTUPARAMS = ' '

TABLES

DYNPROTAB = TA_BDCDATA

EXCEPTIONS

INTERNAL_ERROR = 1

NOT_OPEN = 2

QUEUE_ERROR = 3

TCODE_INVALID = 4

PRINTING_INVALID = 5

POSTING_INVALID = 6

OTHERS = 7

.

* IF SY-SUBRC <> 0.

** Implement suitable error handling here

* ENDIF.

*

FORM BDC_CLOSE_GROUP .

CALL FUNCTION 'BDC_CLOSE_GROUP'

EXCEPTIONS

NOT_OPEN = 1

QUEUE_ERROR = 2

OTHERS = 3

.

* IF SY-SUBRC <> 0.

** Implement suitable error handling here

* ENDIF.

ENDFORM. " BDC_CLOSE_GROUP

FORM BDC_DYNPRO USING PROGRAM

SCREEN.

WA_BDCDATA-PROGRAM = PROGRAM.

WA_BDCDATA-DYNPRO = SCREEN.

WA_BDCDATA-DYNBEGIN = 'X'.

APPEND WA_BDCDATA TO TA_BDCDATA.

CLEAR WA_BDCDATA.

ENDFORM. " BDC_DYNPRO

*&---------------------------------------------------------------------*

*& Form BDC_FIELD

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

* -->P_0297 text

* -->P_0298 text

*----------------------------------------------------------------------*

FORM BDC_FIELD USING FNAM FVAL.

WA_BDCDATA-FNAM = FNAM.

WA_BDCDATA-FVAL = FVAL.

APPEND WA_BDCDATA TO TA_BDCDATA.

CLEAR WA_BDCDATA.

ENDFORM. " BDC_FIELD

ENDFORM. "