‎2007 Aug 13 9:31 PM
hello experts,
can anyone guide me what is wrong with my code... when the session is created i am getting the only last record into the session... it is processing the last record..it is updating the application with only the last record..
can anyone guide me where i am going wrong....
eport ZCUSTTEST
no standard page heading line-size 255.
*include bdcrecx1.
tables: knvv, lfa1.
data: begin of it_ldata occurs 0,
kunnr like knvv-kunnr,
lifnr like lfa1-lifnr,
end of it_ldata.
data: begin of it_sdata occurs 0,
kunnr like knvv-kunnr,
lifnr like knvv-lifnr,
vkorg like knvv-vkorg,
vtweg like knvv-vtweg,
spart like knvv-spart,
end of it_sdata.
data : it_sldata like it_sdata occurs 0 with header line.
include bdcrecx1.
start-of-selection.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = 'C:\cust.txt'
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = ' '
HEADER_LENGTH = 0
READ_BY_LINE = 'X'
DAT_MODE = ' '
CODEPAGE = ' '
IGNORE_CERR = ABAP_TRUE
REPLACEMENT = '#'
CHECK_BOM = ' '
VIRUS_SCAN_PROFILE =
NO_AUTH_CHECK = ' '
IMPORTING
FILELENGTH =
HEADER =
TABLES
DATA_TAB = it_ldata
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 it_ldata.
*refresh it_sdata.
if it_ldata-kunnr <> ' '.
refresh : it_sdata.
clear : it_sdata.
select kunnr vkorg vtweg spart from knvv into table it_sdata where kunnr = it_ldata-kunnr.
loop at it_sdata.
move it_sdata to it_sldata.
append it_sldata.
*write:/ it_ldata-lifnr.
endloop.
endif.
perform open_group.
perform bdc_dynpro using 'SAPL0VED' '0100'.
perform bdc_field using 'BDC_CURSOR'
'V_EDSDC-KUNNR(01)'.
perform bdc_field using 'BDC_OKCODE'
'=NEWL'.
perform bdc_dynpro using 'SAPL0VED' '0100'.
perform bdc_field using 'BDC_CURSOR'
'V_EDSDC-AUART(01)'.
perform bdc_field using 'BDC_OKCODE'
'=SAVE'.
perform bdc_field using 'V_EDSDC-KUNNR(01)'
it_sldata-kunnr.
perform bdc_field using 'V_EDSDC-LIFNR(01)'
it_ldata-lifnr.
perform bdc_field using 'V_EDSDC-VKORG(01)'
it_sldata-vkorg.
perform bdc_field using 'V_EDSDC-VTWEG(01)'
it_sldata-vtweg.
perform bdc_field using 'V_EDSDC-SPART(01)'
it_sldata-spart.
perform bdc_field using 'V_EDSDC-AUART(01)'
'ZOR'.
perform bdc_dynpro using 'SAPL0VED' '0100'.
perform bdc_field using 'BDC_CURSOR'
'V_EDSDC-KUNNR(02)'.
perform bdc_field using 'BDC_OKCODE'
'=BACK'.
perform bdc_dynpro using 'SAPL0VED' '0100'.
perform bdc_field using 'BDC_CURSOR'
'V_EDSDC-KUNNR(02)'.
perform bdc_field using 'BDC_OKCODE'
'=BACK'.
perform bdc_transaction using 'VOE2'.
perform close_group.
endloop.
‎2007 Aug 13 9:49 PM
Hi,
could you narrow down the code to where the problem is please?
Joirs
‎2007 Aug 13 9:49 PM
Hi,
could you narrow down the code to where the problem is please?
Joirs
‎2007 Aug 13 9:51 PM
s joris,
Problem is some where here in this block of code...
loop at it_ldata.
*refresh it_sdata.
if it_ldata-kunnr <> ' '.
refresh : it_sdata.
clear : it_sdata.
select kunnr vkorg vtweg spart from knvv into table it_sdata where kunnr = it_ldata-kunnr.
loop at it_sdata.
move it_sdata to it_sldata.
append it_sldata.
*write:/ it_ldata-lifnr.
endloop.
endif.
In the final session i am getting only one last record..... something problem in this block
‎2007 Aug 13 9:53 PM
Nitesha
Remove that Refresh : it_sdata.
This stmt will erase all the contents of your internal table.
Regards,
Vinod.
‎2007 Aug 13 9:55 PM
Hello Nitesha,
I found the error , first open the session and use loop command.
within loop should not be bdc_open_group and BDC_CLOSE_GROUP Function module.
once you done ,you will get it.
if you need example one ,just goto se37 -> enter bdc_open_group -> click on where used list.
take one program and do compare with your program
Thanks
Seshu
‎2007 Aug 13 9:59 PM
Hi,
don't use REFRESH.
When you use REFRESH on a table with header line it cleares th ewhole table (instead of the header line).
That is the cause.
additionally:
Using Tables with headerlines is discouraged.
use normal tables and workareas instead..
regards,
Joris
‎2007 Aug 13 10:56 PM
‎2007 Aug 13 9:51 PM
best thing to do is debug it to make sure you are infact uploading all your records and also your Select statement is populating correctly
‎2007 Aug 13 9:53 PM
Hello
I dont see where are you looping over it_sdata.
Please after the select loop over that inernal table
select kunnr vkorg vtweg spart from knvv into table it_sdata where kunnr = it_ldata-kunnr.
loop at it_sdata.
move it_sdata to it_sldata.
append it_sldata.
*write:/ it_ldata-lifnr.
endloop.
endif.
LOOP AT it_sdata . "CHECK HERE
perform open_group.
....
ENDLOOP.-
bYE
Gabriel
‎2007 Aug 14 6:34 AM
Hi,
first you need to concentrate coding standards that is dont use the select statement within loop so you need to avoid this one by using 'for all entries' conncept
1) if not it_ldata[] is initial.
select
kunnr
vkorg
vtweg
spart
from knvv into table it_sdata
FOR ALL ENTRIES IN it_ldata
where kunnr = it_ldata-kunnr.
if sy-subrc = 0.
sort it_ldata by kunnr.
endif.
endif.
while processing no nee for two internal tables are it_sdata and it_ldata .
and you need to use OPEN_GROUP & CLOSE_GROUP perofamnceS without loop. Remaing performances for processing data u can use with in the loop.
the following code covers entire code.
if not it_ldata[] is initial.
select
kunnr
vkorg
vtweg
spart
from knvv into table it_sldata
FOR ALL ENTRIES IN it_ldata
where kunnr = it_ldata-kunnr.
if sy-subrc = 0.
sort it_sldata by kunnr.
endif.
endif.
perform open_group.
LOOP AT IT_SLDATA.
perform bdc_dynpro using 'SAPL0VED' '0100'.
perform bdc_field using 'BDC_CURSOR'
'V_EDSDC-KUNNR(01)'.
perform bdc_field using 'BDC_OKCODE'
'=NEWL'.
perform bdc_dynpro using 'SAPL0VED' '0100'.
perform bdc_field using 'BDC_CURSOR'
'V_EDSDC-AUART(01)'.
perform bdc_field using 'BDC_OKCODE'
'=SAVE'.
perform bdc_field using 'V_EDSDC-KUNNR(01)'
it_sldata-kunnr.
perform bdc_field using 'V_EDSDC-LIFNR(01)'
it_ldata-lifnr.
perform bdc_field using 'V_EDSDC-VKORG(01)'
it_sldata-vkorg.
perform bdc_field using 'V_EDSDC-VTWEG(01)'
it_sldata-vtweg.
perform bdc_field using 'V_EDSDC-SPART(01)'
it_sldata-spart.
perform bdc_field using 'V_EDSDC-AUART(01)'
'ZOR'.
perform bdc_dynpro using 'SAPL0VED' '0100'.
perform bdc_field using 'BDC_CURSOR'
'V_EDSDC-KUNNR(02)'.
perform bdc_field using 'BDC_OKCODE'
'=BACK'.
perform bdc_dynpro using 'SAPL0VED' '0100'.
perform bdc_field using 'BDC_CURSOR'
'V_EDSDC-KUNNR(02)'.
perform bdc_field using 'BDC_OKCODE'
'=BACK'.
perform bdc_transaction using 'VOE2'.
ENDLOOP.
perform close_group.
REWARD me with points if useful.
Regards,
Vijay.