‎2007 Oct 01 8:38 AM
Hi Gurus.
this is my program using bdc call transaction code is MB1C.
its run correctly but first 2 values not entered.....pls check this program....
report ZMB1C_SAN
no standard page heading line-size 255.
TABLES:MARA,
MSEG,
MKPF,
rm07m,
dkacb,
t100.
data: werks(4) type n.
data : w_ftext(200),
w_text(60) type c.
data: scr1(3) type n value 1.
data s1 type string.
data s2 type string.
data s3 type string.
data: count(4) type n.
DATA:
I_MSG TYPE STANDARD TABLE OF BDCMSGCOLL WITH HEADER LINE, " Internal table to store messages from Call Transaction
IT_BDCTAB TYPE BDCDATA OCCURS 0 WITH HEADER LINE. " Internal table for BDC data
DATA :
BEGIN OF IT_DATA OCCURS 10,
werks(4),
matnr(30),
erfmg(30),
lgort(6),
END OF IT_DATA.
data: temp(3) type n value 0.
DATA:BEGIN OF IT_error OCCURS 10,
werks(4),
matnr(30),
erfmg(30),
lgort(6),
END OF IT_error.
data ind(2) type c.
data flag(3) type n.
data cont(3) type n.
DATA: date(10) type c.
data: begin of i_error_log occurs 0,
data(100) type c,
msg(60) type c,
end of i_error_log.
data: begin of i_success occurs 0,
customer(18) type c,
msg(60) type c,
end of i_success.
data : matnr1 like mara-matnr.
&----
SELECTION SCREEN.
&----
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
PARAMETER:
P_FILE TYPE RLGRAP-FILENAME ." OBLIGATORY DEFAULT 'C:\MB1C.TXT'.
SELECTION-SCREEN END OF BLOCK B1.
************************************************************************
Initialization
************************************************************************
INITIALIZATION.
write : sy-datum to date dd/mm/yyyy no-gap.
&----
AT SELECTION SCREEN.
&----
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
PERFORM FILE_HELP .
&----
START-OF-SELECTION
&----
START-OF-SELECTION.
PERFORM READ_INPUT_DATA.
*PERFORM READ_MATNR.
perform verify.
PERFORM BDC_POPULATION.
*
*PERFORM GUI_DOWNLOAD.
*ENDLOOP.
----
END OF SELECTION.
----
END-OF-SELECTION.
----
Form : FILE_HELP
----
FORM FILE_HELP .
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
FIELD_NAME = ' '
IMPORTING
FILE_NAME = P_FILE.
ENDFORM.
.
FORM READ_INPUT_DATA.
DATA: L_FILE TYPE STRING.
L_FILE = P_FILE.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = L_FILE
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
HEADER_LENGTH = 0
READ_BY_LINE = 'X'
DAT_MODE = ' '
CODEPAGE = ' '
IGNORE_CERR = ABAP_TRUE
REPLACEMENT = '#'
CHECK_BOM = ' '
VIRUS_SCAN_PROFILE =
IMPORTING
FILELENGTH =
HEADER =
tables
data_tab = it_data.
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.
ENDFORM.
FORM READ_MATNR.
LOOP AT IT_DATA.
CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
EXPORTING
input = it_data-matnr
IMPORTING
OUTPUT = matnr1
EXCEPTIONS
LENGTH_ERROR = 1
OTHERS = 2
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
select single * from mara where matnr = matnr1.
IF SY-SUBRC ne 0.
it_error-werks = it_data-werks.
it_error-matnr = it_data-matnr.
it_error-erfmg = it_data-erfmg.
it_error-lgort = it_data-lgort.
append it_error.
endif.
endloop.
endform.
form verify .
sort it_data by werks.
loop at it_data.
at new werks.
werks = it_data-werks.
endat.
endloop.
ENDFORM.
----
Form : BDC_POPULATION
----
*
****include bdcrecx1.
****
**
**perform open_group.
*
FORM BDC_POPULATION.
perform bdc_dynpro using 'SAPMM07M' '0400'.
perform bdc_field using 'BDC_CURSOR'
'RM07M-LGORT'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'MKPF-BLDAT'
date.
perform bdc_field using 'MKPF-BUDAT'
date.
perform bdc_field using 'RM07M-BWARTWA'
'561'.
perform bdc_field using 'RM07M-WERKS'
it_data-werks.
perform bdc_field using 'XFULL'
'X'.
perform bdc_dynpro using 'SAPMM07M' '0421'.
perform bdc_field using 'BDC_CURSOR'
'MSEG-LGORT(07)'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'BDC_OKCODE'
'=BU'.
*perform Call.
*
*
*endform. " call_bdc
*&----
**& Form head
*&----
*form call .
loop at it_data.
count = count + 1.
describe table it_data lines count.
if count > 1 and count < 300.
perform bdc_field using 'DKACB-FMORE' 'X'.
concatenate 'MSEG-MATNR(' scr1 ')' into s1.
concatenate 'MSEG-ERFMG(' scr1 ')' into s2.
concatenate 'MSEG-LGORT(' scr1 ')' into s3.
perform bdc_field using s1
it_data-matnr.
perform bdc_field using s2
it_data-erfmg.
perform bdc_field using s3
it_data-lgort.
scr1 = scr1 + 1.
clear: it_bdctab.
if scr1 > 12.
temp = temp + scr1.
perform bdc_field using 'BDC_OKCODE'
'=NLE'.
perform bdc_dynpro using 'SAPMM07M' '0421'.
perform bdc_field using 'BDC_CURSOR' 'MSEG-LGORT(01)'.
scr1 = 0.
endif.
endif.
at last.
perform bdc_field using 'BDC_OKCODE'
'=BU'.
endat.
endloop.
PERFORM CALL_TRAN.
endform. " head
----
Start new screen *
----
form bdc_dynpro using program dynpro.
clear it_bdctab.
it_bdctab-program = program.
it_bdctab-dynpro = dynpro.
it_bdctab-dynbegin = 'X'.
append it_bdctab.
endform.
----
Insert field *
----
form bdc_field using fnam fval.
if fval <> nodata.
clear it_bdctab.
it_bdctab-fnam = fnam.
it_bdctab-fval = fval.
append it_bdctab.
endif.
endform.
&----
*& Form CALL_TRAN
&----
form CALL_TRAN .
DATA: W_MODE TYPE C VALUE 'A'.
CLEAR: IT_BDCTAB,it_DATA[].
CALL TRANSACTION 'MB1C' USING IT_BDCTAB MODE W_MODE MESSAGES INTO I_MSG.
endform. " CALL_TRAN
&----
*& Form gui_download
&----
form gui_download .
call function 'GUI_DOWNLOAD'
exporting
BIN_FILESIZE =
filename = 'C:\Error.TXT'
filetype = 'ASC'
APPEND = ' '
write_field_separator = 'X'
HEADER = '00'
TRUNC_TRAILING_BLANKS = ' '
WRITE_LF = 'X'
COL_SELECT = ' '
COL_SELECT_MASK = ' '
DAT_MODE = ' '
CONFIRM_OVERWRITE = ' '
NO_AUTH_CHECK = ' '
CODEPAGE = ' '
IGNORE_CERR = ABAP_TRUE
REPLACEMENT = '#'
WRITE_BOM = ' '
TRUNC_TRAILING_BLANKS_EOL = 'X'
WK1_N_FORMAT = ' '
WK1_N_SIZE = ' '
WK1_T_FORMAT = ' '
WK1_T_SIZE = ' '
IMPORTING
FILELENGTH =
tables
data_tab = it_data.
.
endform. " gui_download
&----
*& Form CHECK_MSG
&----
text
----
<--P_L_FLAG text
----
form check_msg changing p_l_flag.
clear w_ftext . clear p_l_flag.
loop at i_msg .
perform get_error_message.
Error messages
if i_msg-msgtyp = 'E' or i_msg-msgtyp = 'A' .
move w_ftext to i_error_log-msg.
append i_error_log.
endif .
Success messages
if i_msg-msgtyp = 'S' and i_msg-msgnr = '030' .
clear p_l_flag.
clear i_success.
move : w_ftext to i_success-msg.
append i_success.
endif.
endloop .
endform. " CHECK_MSG
&----
*& Form GET_ERROR_MESSAGE
&----
text
----
--> p1 text
<-- p2 text
----
form get_error_message .
data : l_t1(100) , l_t2(100) , l_t3(100) , l_t4(100) , l_t5(100) .
select single text from t100 into t100-text
where sprsl = i_msg-msgspra
and arbgb = i_msg-msgid
and msgnr = i_msg-msgnr.
if sy-subrc = 0.
clear: w_ftext, l_t1, l_t2, l_t3, l_t4, l_t5.
split t100-text at '&' into l_t1 l_t2 l_t3 l_t4 l_t5.
concatenate l_t1 i_msg-msgv1 l_t2 i_msg-msgv2 l_t3
i_msg-msgv3 l_t4 i_msg-msgv4 l_t5 into w_ftext
separated by ' '.
endif.
endform. " GET_ERROR_MESSAGE
*
this is flat file...
1000 400-522 12 0001
1000 400-522 12 0001
1000 400-522 12 0001
1000 400-522 12 0001
1000 400-523 12 0001
1000 1500-520 12 0001
1000 1500-520 12 0001
1000 80-110f 12 0001
1000 abc100 12 0001
1000 400-522 12 0001
1000 400-523 12 0001
1000 1500-520 12 0001
1000 1500-520 12 0001
1000 80-110f 12 0001
1000 abc100 12 0001
1000 400-522 12 0001
1000 400-523 12 0001
1000 1500-520 12 0001
1000 1500-520 12 0001
1000 80-110f 12 0001
1000 1500-520 12 0001
1000 1500-520 12 0001
1000 1500-520 12 0001
1000 1500-520 12 0001
1000 1500-520 12 0001
1000 1500-520 12 0001
1000 1500-520 12 0001
1000 1500-520 12 0001
1000 1500-520 12 0001
‎2007 Oct 01 9:08 AM
Hi..
You have to Refresh the internal tables (BDCDATA and BDCMSGCOLL before the Call transaction Every time.)
Change this Routine as below:
form CALL_TRAN .
DATA: W_MODE TYPE C VALUE 'A'.
<b>CLEAR: it_BDCTAB[]. "It should not be IT_DATA[]</b>
<b>CLEAR: i_msg[]. </b>
CALL TRANSACTION 'MB1C' USING IT_BDCTAB MODE W_MODE MESSAGES INTO I_MSG.
endform. " CALL_TRAN
<b>Reward if Helpful.</b>
‎2007 Oct 01 10:05 AM
Dear sir,
Thanks for u r reply..
its working good....
but now i m check come condition its not working....
condition is
first store only 20 material in one document number....
then balance material is store in another document number...
this program work on both condition...
at the time of storing balance material its leave some space....
pls check this error.........
pls run it........
report ZMB1C_SAN
no standard page heading line-size 255.
TABLES:MARA,
MSEG,
MKPF,
rm07m,
dkacb,
t100.
data: werks(4) type n.
data : w_ftext(200),
w_text(60) type c.
data: scr1(3) type n value 1.
data s1 type string.
data s2 type string.
data s3 type string.
data: count(4) type n.
DATA:
I_MSG TYPE STANDARD TABLE OF BDCMSGCOLL WITH HEADER LINE, " Internal table to store messages from Call Transaction
IT_BDCTAB TYPE BDCDATA OCCURS 0 WITH HEADER LINE. " Internal table for BDC data
DATA :
BEGIN OF IT_DATA OCCURS 10,
werks(4),
matnr(30),
erfmg(30),
lgort(6),
END OF IT_DATA.
data: temp(3) type n value 0.
DATA:BEGIN OF IT_error OCCURS 10,
werks(4),
matnr(30),
erfmg(30),
lgort(6),
END OF IT_error.
data ind(2) type c.
data flag(3) type n.
data cont(3) type n.
DATA: date(10) type c.
data: begin of i_error_log occurs 0,
data(100) type c,
msg(60) type c,
end of i_error_log.
data: begin of i_success occurs 0,
customer(18) type c,
msg(60) type c,
end of i_success.
data : matnr1 like mara-matnr.
&----
SELECTION SCREEN.
&----
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
PARAMETER:
P_FILE TYPE RLGRAP-FILENAME ." OBLIGATORY DEFAULT 'C:\MB1C.TXT'.
SELECTION-SCREEN END OF BLOCK B1.
************************************************************************
Initialization
************************************************************************
INITIALIZATION.
write : sy-datum to date dd/mm/yyyy no-gap.
&----
AT SELECTION SCREEN.
&----
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
PERFORM FILE_HELP .
&----
START-OF-SELECTION
&----
START-OF-SELECTION.
PERFORM READ_INPUT_DATA.
PERFORM READ_MATNR.
*perform verify.
PERFORM BDC_POPULATION.
*
*PERFORM GUI_DOWNLOAD.
*ENDLOOP.
----
END OF SELECTION.
----
END-OF-SELECTION.
----
Form : FILE_HELP
----
FORM FILE_HELP .
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
FIELD_NAME = ' '
IMPORTING
FILE_NAME = P_FILE.
ENDFORM.
.
FORM READ_INPUT_DATA.
DATA: L_FILE TYPE STRING.
L_FILE = P_FILE.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = L_FILE
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
HEADER_LENGTH = 0
READ_BY_LINE = 'X'
DAT_MODE = ' '
CODEPAGE = ' '
IGNORE_CERR = ABAP_TRUE
REPLACEMENT = '#'
CHECK_BOM = ' '
VIRUS_SCAN_PROFILE =
IMPORTING
FILELENGTH =
HEADER =
tables
data_tab = it_data.
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.
ENDFORM.
FORM READ_MATNR.
LOOP AT IT_DATA.
CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
EXPORTING
input = it_data-matnr
IMPORTING
OUTPUT = matnr1
EXCEPTIONS
LENGTH_ERROR = 1
OTHERS = 2
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
select single * from mara where matnr = matnr1.
IF SY-SUBRC ne 0.
it_error-werks = it_data-werks.
it_error-matnr = it_data-matnr.
it_error-erfmg = it_data-erfmg.
it_error-lgort = it_data-lgort.
append it_error.
endif.
endloop.
endform.
form verify .
sort it_data by werks.
loop at it_data.
at new werks.
werks = it_data-werks.
endat.
endloop.
ENDFORM.
----
Form : BDC_POPULATION
----
*
****include bdcrecx1.
****
**
**perform open_group.
*
FORM BDC_POPULATION.
perform bdc_dynpro using 'SAPMM07M' '0400'.
perform bdc_field using 'BDC_CURSOR'
'RM07M-LGORT'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'MKPF-BLDAT'
date.
perform bdc_field using 'MKPF-BUDAT'
date.
perform bdc_field using 'RM07M-BWARTWA'
'561'.
perform bdc_field using 'RM07M-WERKS'
'1000'.
perform bdc_field using 'XFULL'
'X'.
perform bdc_dynpro using 'SAPMM07M' '0421'.
perform bdc_field using 'BDC_CURSOR'
'MSEG-LGORT(01)'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'BDC_OKCODE'
'=BU'.
*perform Call.
*
*
*endform. " call_bdc
*&----
**& Form head
*&----
*form call .
loop at it_data.
count = count + 1.
concatenate 'MSEG-MATNR(' scr1 ')' into s1.
concatenate 'MSEG-ERFMG(' scr1 ')' into s2.
concatenate 'MSEG-LGORT(' scr1 ')' into s3.
perform bdc_field using s1
it_data-matnr.
perform bdc_field using s2
it_data-erfmg.
perform bdc_field using s3
it_data-lgort.
scr1 = scr1 + 1.
clear: it_bdctab.
if scr1 > 12.
temp = temp + scr1.
perform bdc_field using 'BDC_OKCODE'
'=NLE'.
perform bdc_dynpro using 'SAPMM07M' '0421'.
perform bdc_field using 'BDC_CURSOR' 'MSEG-LGORT(01)'.
scr1 = 0.
endif.
endif.
if count = 20.
perform bdc_field using 'BDC_OKCODE' '=BU'.
perform bdc_dynpro using 'SAPLKACB' '0002'.
perform bdc_field using 'BDC_OKCODE' '=ENTE'.
PERFORM CALL_TRAN.
clear it_bdctab.
refresh it_bdctab.
perform bdc_dynpro using 'SAPMM07M' '0400'.
perform bdc_field using 'BDC_CURSOR'
'RM07M-LGORT'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'MKPF-BLDAT'
date.
perform bdc_field using 'MKPF-BUDAT'
date.
perform bdc_field using 'RM07M-BWARTWA'
'561'.
perform bdc_field using 'RM07M-WERKS'
'1000'.
perform bdc_field using 'XFULL'
'X'.
perform bdc_dynpro using 'SAPMM07M' '0421'.
perform bdc_field using 'BDC_CURSOR'
'MSEG-ERFMG(01)'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'BDC_OKCODE'
'=BU'.
endif.
at last.
perform bdc_field using 'BDC_OKCODE'
'=BU'.
endat.
endloop.
PERFORM CALL_TRAN.
endform. " head
----
Start new screen *
----
form bdc_dynpro using program dynpro.
clear it_bdctab.
it_bdctab-program = program.
it_bdctab-dynpro = dynpro.
it_bdctab-dynbegin = 'X'.
append it_bdctab.
endform.
----
Insert field *
----
form bdc_field using fnam fval.
if fval <> nodata.
clear it_bdctab.
it_bdctab-fnam = fnam.
it_bdctab-fval = fval.
append it_bdctab.
endif.
endform.
&----
*& Form CALL_TRAN
&----
form CALL_TRAN .
DATA: W_MODE TYPE C VALUE 'A'.
CLEAR: IT_BDCTAB.
CALL TRANSACTION 'MB1C' USING IT_BDCTAB MODE W_MODE MESSAGES INTO I_MSG.
endform. " CALL_TRAN
flat file......
1000 400-522 12 0001
1000 400-522 12 0001
1000 400-522 12 0001
1000 400-522 12 0001
1000 400-523 12 0001
1000 1500-520 12 0001
1000 1500-520 12 0001
1000 80-110f 12 0001
1000 abc100 12 0001
1000 400-522 12 0001
1000 400-523 12 0001
1000 1500-520 12 0001
1000 1500-520 12 0001
1000 80-110f 12 0001
1000 abc100 12 0001
1000 400-522 12 0001
1000 400-523 12 0001
1000 1500-520 12 0001
1000 1500-520 12 0001
1000 80-110f 12 0001
1000 1500-520 12 0001
1000 1500-520 12 0001
1000 1500-520 12 0001
1000 1500-520 12 0001
1000 1500-520 12 0001
1000 1500-520 12 0001
1000 1500-520 12 0001
1000 1500-520 12 0001
1000 1500-520 12 0001