Application Development and Automation 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: 
Read only

regarding bdc

Former Member
0 Likes
489

Hi all,

I am creating bdc with call transaction to upload file from tab separated text file to the transaction 'CJ40'. in my program I am getting sucessfully updated messgae but when I open the transaction is wrongly updated.

can anybody pls suggest me the solution.

here is my code

report ZPS_REPT_WBS_COST_UPLOAD .

tables: bpdy,prps,bpge,proj.

    • internal table for uploaded data

data: BEGIN OF it_itab occurs 0,

v_stufe(3) type c, " level

v_post1(40) type c, " Description

v_posid(24) type c, " old WBS Element

v_wrttp(2) type c, " Amount

v_PSPNR(24) TYPE C, " New WBS Element

v_WERT1(21) TYPE c, " Amount

v_perc(21) type c, " pecentage

END OF it_itab.

    • internal table for parent.

DATA: BEGIN OF it_ITAB_temp OCCURS 0,

v_parent(24) type c,

v_stufe(3) type c,

v_post1(40) type c,

v_posid(24) type c,

v_wrttp(2) type c,

v_PSPNR(24) TYPE C,

v_WERT1 like bpdy-wert1,

v_perc like bpdy-wert1,

END OF it_ITAB_temp.

Data : v_posid1(24).

Data : v_len type i.

Data: v_pspid like proj-pspid.

data: v_perc_old(6).

data: v_file type string.

data : v_pspnr_old(24),

v_wert1_old(21),

v_tabix."sg-001

data: v_stufe_old(3),

v_WERT1(21),

l_wert1(21).

Data v_error type i.

PARAMETER: P_FILE LIKE RLGRAP-FILENAME.

DATA: it_BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE.

DATA: it_BDCMSGCOLL LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.

                • AT SELECTION SCREEN

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.

CALL FUNCTION 'F4_FILENAME'

EXPORTING

PROGRAM_NAME = SYST-CPROG

DYNPRO_NUMBER = SYST-DYNNR

FIELD_NAME = 'P_FILE'

IMPORTING

FILE_NAME = P_FILE

.

START-OF-SELECTION.

PERFORM FILE_UPLOAD.

*PERFORM BDC_POPULATE.

*&----


*

*& FORM FILE_UPLOAD

*

*&----


*

*******uploading file

FORM FILE_UPLOAD.

REFRESH it_ITAB.

v_file = p_file.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = v_file

  • 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 = 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.

MESSAGE ' ERROR IN UPLOADING FILE ' type 'E'.

ENDIF.

          • deleting coulmn headings

clear it_itab.

DELETE it_ITAB INDEX 1.

***For getting Project id.

read table it_itab index 1.

if it_itab-v_stufe = 1.

v_pspid = it_itab-v_pspnr.

endif.

***TO ADD duplicate VALUES

sort it_itab by V_PSPNR.

loop at it_itab.

if it_itab-v_pspnr = v_pspnr_old.

if it_itab-v_wert1 is not initial.

it_itab-v_wert1 = it_itab-v_wert1 + v_wert1_old.

else.

it_itab-v_perc = it_itab-v_perc + v_perc_old.

endif.

v_tabix = sy-tabix - 1.

delete it_itab index v_tabix .

modify it_itab.

endif.

v_pspnr_old = it_itab-v_pspnr.

v_wert1_old = it_itab-v_wert1.

v_perc_old = it_itab-v_perc.

endloop.

****FINDING PARENT

sort it_itab by v_stufe v_posid.

loop at it_itab.

MOVE-CORRESPONDING it_itab TO it_itab_temp.

v_len = strlen( it_itab_temp-v_posid ) - 2.

*v_len = strlen( it_itab_temp-v_posid ) - 3.

*

v_posid1 = it_itab_temp-v_posid+0(v_len).

it_itab_temp-v_parent = v_posid1.

append it_itab_temp.

endloop.

*it_itab_temp contains parent column

*sort it_itab by v_stufe v_posid.

sort it_itab_temp by v_parent.

delete it_itab_temp index 1.

    • for calculating percentages to value

loop at it_itab_temp.

read table it_itab with key v_posid = it_itab_temp-v_parent.

if sy-subrc = 0.

if it_itab_temp-v_wert1 is initial and

it_itab_temp-v_perc is not initial.

it_itab_temp-v_wert1 = ( it_itab-v_wert1 * it_itab_temp-v_perc ) / 100.

move it_itab_temp-v_wert1 to it_itab-v_wert1.

modify it_itab transporting v_wert1 where v_posid = it_itab_temp-v_posid

.

modify it_itab_temp.

endif.

endif.

endloop.

***valdation logic for percentage

loop at it_itab_temp.

at end of v_parent.

sum.

Read table it_itab with key v_posid = it_itab_temp-v_parent.

if sy-subrc = 0.

if it_itab_temp-v_perc > 100.

message I003(0) with 'perecentage is greater than 100'.

stop.

endif.

endif.

endat.

endloop.

clear v_error.

*****valdation logic for value

loop at it_itab_temp.

at end of v_parent.

sum.

Read table it_itab with key v_posid = it_itab_temp-v_parent.

if sy-subrc = 0.

if it_itab_temp-v_wert1 > it_itab-v_wert1.

v_error = 1.

exit.

endif.

endif.

endat.

endloop.

if v_error = 1.

message I002(zh) with 'values are greater than parent WBS Element'.

stop.

else.

PERFORM BDC_POPULATE.

endif.

ENDFORM. " FORM FILE_UPLOAD

*&----


*

*& FORM BDC_POPULATE

*&----


*

FORM BDC_POPULATE.

*CLEAR IT_BDCDATA.

LOOP AT it_ITAB.

CLEAR it_BDCDATA.

REFRESH it_BDCDATA.

perform bdc_dynpro using 'SAPMKBUD' '0200'.

perform bdc_field using 'BDC_CURSOR'

'PRPS-POSID'.

perform bdc_field using 'BDC_OKCODE'

'=EINK'.

perform bdc_field using 'PROJ-PSPID'

v_pspid.

perform bdc_field using 'PRPS-POSID'

it_itab-v_pspnr.

.

perform bdc_field using 'BPDY-VERSN'

'0'.

perform bdc_dynpro using 'SAPLKBPP' '0320'.

*perform bdc_field using 'BDC_CURSOR'

  • 'BPDY-WERT1(01)'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_field using 'BPDY-WERT1(01)'

it_itab-v_wert1.

.

*perform bdc_dynpro using 'SAPLKBPP' '0320'.

*perform bdc_field using 'BDC_CURSOR'

  • 'BPDY-WERT1(01)'.

perform bdc_field using 'BDC_OKCODE'

'=SAVE'.

CALL TRANSACTION 'CJ40' USING IT_BDCDATA MODE 'N' UPDATE 'S'

messages into it_bdcmsgcoll.

*if sy-subrc <> 0.

*move it_itab to it_itab1.

*append it_itab1.

*endif.

*loop at bdc_msgcoll.

*endloop.

*if sy-subrc = 0.

*write:/ it_itab-p_pspnr,'suceesfully updated with', it_itab-p_wert1.

*********for total up

*perform bdc_dynpro using 'SAPMKBUD' '0200'.

*perform bdc_field using 'BDC_CURSOR'

  • 'PROJ-PSPID'.

*perform bdc_field using 'BDC_OKCODE'

  • 'EINK'.

*perform bdc_field using 'PROJ-PSPID'

  • v_pspid.

*perform bdc_field using 'PRPS-POSID'

  • ''.

*perform bdc_field using 'BPDY-VERSN'

  • '0'.

*perform bdc_dynpro using 'SAPLKBPP' '0320'.

*perform bdc_field using 'BDC_CURSOR'

  • 'BPDY-WERT1(01)'.

*perform bdc_field using 'BDC_OKCODE'

  • '=SYNC'.

*perform bdc_field using 'DROPT-PTIME'

  • '1'.

*perform bdc_dynpro using 'SAPLKBPP' '0705'.

*perform bdc_field using 'BDC_CURSOR'

  • 'BPDY-JAHR_VON'.

*perform bdc_field using 'BDC_OKCODE'

  • '=ENTE'.

*perform bdc_field using 'BPDY-JAHR_VON'

  • '2004'.

*perform bdc_field using 'BPDY-JAHR_BIS'

  • '2008'.

*perform bdc_dynpro using 'SAPLKBPP' '0320'.

*perform bdc_field using 'BDC_CURSOR'

  • 'BPDY-WERT1(01)'.

*perform bdc_field using 'BDC_OKCODE'

  • '=SAVE'.

**perform bdc_field using 'DROPT-PTIME'

    • '1'.

*CALL TRANSACTION 'CJ40' USING IT_BDCDATA MODE 'A' UPDATE 'S' .

if sy-subrc = 0.

condense it_itab-v_wert1.

write:/ it_itab-v_pspnr,'suceesfully updated with', it_itab-v_wert1.

else.

write:/ it_itab-v_pspnr,'not updated with', it_itab-v_wert1.

endif.

*if sy-subrc = 0.

*v_error = 2.

*else.

*v_error = 3.

**write:/ 'Planned Cost not Updated '.

*endif.

*clear it_itab.

*

*if v_error = 2.

*message I002(000) with 'sucessusfully uploaded'.

*elseif v_error = 3.

*message e002(000) with 'uploading'.

*endif.

endloop.

endform. "FORM BDC_DATA

*&----


*

*& FORM BDC_DYNPRO

*

*&----


*

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. "FORM BDC_DYNPRO

*&----


*

*& FORM BDC_FIELD

*&----


*

FORM BDC_FIELD USING FNAM FVAL.

IF FVAL <> SPACE.

CLEAR it_BDCDATA.

it_BDCDATA-FNAM = FNAM.

it_BDCDATA-FVAL = FVAL.

APPEND it_BDCDATA.

ENDIF.

ENDFORM. "FORM BDC_FIELD.

reddy

2 REPLIES 2
Read only

amit_khare
Active Contributor
0 Likes
460

Check the data in ITAB before looping for BDC table create.

Since its a tab seperated file migh be internal table fields are getting incorrect data.

Check the threads to know amore about reading TAB Delimited file -

Regards,

Amit

Reward all helpful replies.

Read only

Former Member
0 Likes
460

hi,

Check your flatfile.

Did u took fields in the internal table as same as in the flatfile.

it is not returning sy-subrc = 0. means data is uploading but I think fields got mismathed.check ur intrnal table and flat file.