‎2007 Jul 17 8:52 AM
Hi im creating a bdc for prd posting...
And i,m using both aleternative session and call transaction .
i want to print the records which are successfully posted and failure happened.
Plz help
Kesav
‎2007 Jul 17 8:54 AM
hi,
Use BDCMSGCOLL.
It will handle both the error and success messages.
‎2007 Jul 17 8:54 AM
Hi,
Use this,
messages of call transaction
DATA: MESSTAB LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.
CALL TRANSACTION TCODE USING BDCDATA
MODE CTUMODE
UPDATE CUPDATE
MESSAGES INTO MESSTAB.
L_SUBRC = SY-SUBRC.
IF SMALLLOG <> 'X'.
WRITE: / 'CALL_TRANSACTION',
TCODE,
'returncode:'(I05),
L_SUBRC,
'RECORD:',
SY-INDEX.
LOOP AT MESSTAB.
SELECT SINGLE * FROM T100 WHERE SPRSL = MESSTAB-MSGSPRA
AND ARBGB = MESSTAB-MSGID
AND MSGNR = MESSTAB-MSGNR.
IF SY-SUBRC = 0.
L_MSTRING = T100-TEXT.
IF L_MSTRING CS '&1'.
REPLACE '&1' WITH MESSTAB-MSGV1 INTO L_MSTRING.
REPLACE '&2' WITH MESSTAB-MSGV2 INTO L_MSTRING.
REPLACE '&3' WITH MESSTAB-MSGV3 INTO L_MSTRING.
REPLACE '&4' WITH MESSTAB-MSGV4 INTO L_MSTRING.
ELSE.
REPLACE '&' WITH MESSTAB-MSGV1 INTO L_MSTRING.
REPLACE '&' WITH MESSTAB-MSGV2 INTO L_MSTRING.
REPLACE '&' WITH MESSTAB-MSGV3 INTO L_MSTRING.
REPLACE '&' WITH MESSTAB-MSGV4 INTO L_MSTRING.
ENDIF.
CONDENSE L_MSTRING.
WRITE: / MESSTAB-MSGTYP, L_MSTRING(250).
ELSE.
WRITE: / MESSTAB.
ENDIF.
ENDLOOP.
SKIP.
ENDIF.
Reward if useful!
‎2007 Jul 17 8:56 AM
dear prasad,,,,i have applied this...but my question is i need to print all the records posted and among them highlight the succesfull one and failed one
‎2007 Jul 17 9:13 AM
Check your transaction messages. If you get a success message when saving your document, double click on it and get it's ID and Number.
After the CALL TRANSACTION (using the MESSAGES variant), check your messages table looking for that ID and Number. If you find it, write your row as a success, if not, write it as a failure (will be helpful if you manage to keep all your failures into another internal table, to be able to get more information about the BI process).
I found in the past not all "failed" transactions deliver error messages, it's because that I say you to keep that ID and Number.
Good luck,
Vic
‎2007 Jul 18 9:19 AM
ya i got it somehow.
Im giving my program below...just check if its correct.
Its consists of a include file which i m specifying seperately..
Please tell if there is any possibilities of error....
****************************************************************************************************
MAIN PRG
***************
----
Program : ZBDC_PRD_POSTING_UPLOAD *
Project Manager/Leader : B.R.Srikanth *
Author : Kesavadas T *
Category : BDC PROGRAM *
Run Frequency : As and when required *
Description : PRD POSTING *
Development Class : ZPP *
Remarks : *
----
Change History *
-------------- *
Date Author Description Change Id *
----- ------ ------------ --------- *
*
*
----
REPORT zbdc_posting
NO STANDARD PAGE HEADING LINE-SIZE 255
MESSAGE-ID zpp.
******************
include bdcrecx1.
******************
PARAMETERS: dataset(132) LOWER CASE.
type-pools:slis.
tables:MAKT.
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 OCCURS 0,
budat_002(010),
bktxt_004(025),
matnr_005(018),
werks_006(004),
alort_007(004),
erfmg_008(017),
END OF record.
End generated data section ***
***********INTERNAL TABLE TO STORE MESSAGE STATUS**********
data: begin of messages occurs 0,
budat_002(010),
bktxt_004(025),
matnr_005(018),
maktx type makt-maktx,
werks_006(004),
alort_007(004),
erfmg_008(017),
text(100) ,
msgtyp type c,
cellcolor type lvc_t_scol,
end of messages.
***INTERNAL TABLES TO STORE ACCEPTED AND REJECTED PRD ENTRIES*****
DATA: it_acc LIKE TABLE OF record WITH HEADER LINE.
DATA: it_rej LIKE TABLE OF record WITH HEADER LINE.
********************************************************************
******INTERNAL TABLE TO STORE UPLOADED DATA****************
DATA: BEGIN OF st_record1 ,
matnr_005(018),
werks_006(004),
budat_002(010),
bktxt_004(025),
erfmg_007(017),
erfmg_008(017),
alort_007(004),
END OF st_record1.
DATA: record1 LIKE TABLE OF st_record1 WITH HEADER LINE.
**************************************************************
DATA: wk_elpro type mkal-alort,
wk_makt type makt-maktx.
*************************************************************
data:alvfld type slis_t_fieldcat_alv with header line,
v_events TYPE slis_t_event WITH HEADER LINE,
wk_events LIKE LINE OF v_events,
it_list_comments TYPE slis_t_listheader,
wk_list_comments LIKE LINE OF it_list_comments,
wa_color type lvc_s_scol,
wk_layout type slis_layout_alv..
CONSTANTS: c_formname_top_of_page TYPE slis_formname
VALUE 'F_TOP_OF_PAGE'.
********************
START-OF-SELECTION.
********************
PERFORM upload_fun.
PERFORM open_group.
PERFORM fill_bdc_table.
PERFORM close_group.
loop at messages.
select single maktx into wk_makt
from makt client specified
where mandt = sy-mandt
and matnr = messages-matnr_005.
move:wk_makt to messages-maktx.
modify messages.
clear: messages,wk_makt.
endloop.
perform assign_colors.
PERFORM f_event_build.
perform assign_columns.
if CTU = 'X'.
sort messages by matnr_005 ascending.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
i_background_id = 'ALV_BACKGROUND'
it_fieldcat = alvfld[]
is_layout = wk_layout
it_events = v_events[]
TABLES
t_outtab = messages
EXCEPTIONS
program_error = 1
OTHERS = 2.
endif.
END-OF-SELECTION.
--
FORM upload_fun.
REFRESH: record1,it_acc,it_rej,RECORD,messages.
CALL FUNCTION 'UPLOAD'
EXPORTING
filename = ' '
filetype = 'DAT'
TABLES
data_tab = record1
EXCEPTIONS
conversion_error = 1
invalid_table_width = 2
invalid_type = 3
no_batch = 4
unknown_error = 5
gui_refuse_filetransfer = 6
OTHERS = 7.
CLEAR record1.
--
DELETE record1 WHERE ( erfmg_007 = 0 OR erfmg_007 = ' ' )
AND ( erfmg_008 = 0 OR erfmg_008 = ' ' ).
DESCRIBE TABLE record1[].
IF sy-tfill > 0.
----
LOOP AT record1 WHERE erfmg_007 NE 0 AND erfmg_007 NE ' '.
MOVE: record1-budat_002 TO it_acc-budat_002,
record1-bktxt_004 TO it_acc-bktxt_004,
record1-matnr_005 TO it_acc-matnr_005,
record1-werks_006 TO it_acc-werks_006,
record1-erfmg_007 TO it_acc-erfmg_008.
APPEND it_acc.
CLEAR: it_acc,record1.
ENDLOOP.
DELETE it_acc WHERE erfmg_008 = 0 OR erfmg_008 = ' '.
LOOP AT it_acc .
--
SELECT SINGLE elpro INTO wk_elpro
FROM mkal client specified
WHERE mandt = sy-mandt
and matnr = it_acc-matnr_005
AND werks = it_acc-werks_006.
MOVE wk_elpro TO it_acc-alort_007.
MODIFY it_acc.
CLEAR: wk_elpro, it_acc.
ENDLOOP.
--
LOOP AT record1 WHERE erfmg_008 NE 0 AND erfmg_008 NE ' '.
MOVE: record1-budat_002 TO it_rej-budat_002,
record1-bktxt_004 TO it_rej-bktxt_004,
record1-matnr_005 TO it_rej-matnr_005,
record1-werks_006 TO it_rej-werks_006,
record1-erfmg_008 TO it_rej-erfmg_008,
record1-alort_007 TO it_rej-alort_007.
APPEND it_rej.
CLEAR: it_rej,record1.
ENDLOOP.
DELETE it_rej WHERE erfmg_008 = 0 OR erfmg_008 = ' '.
--
APPEND LINES OF it_acc TO record.
APPEND LINES OF it_rej TO record.
SORT record BY alort_007 ASCENDING.
FREE : it_rej, it_acc, record1.
ELSE.
MESSAGE i937.
STOP.
ENDIF.
ENDFORM. " UPLOAD_FUN
--
FORM fill_bdc_table.
data: l_mstring(480).
IF NOT record[] IS INITIAL.
LOOP AT record.
PERFORM bdc_dynpro USING 'SAPLBARM' '0800'.
PERFORM bdc_field USING 'BDC_CURSOR' 'RM61B-BKTXT'.
PERFORM bdc_field USING 'BDC_OKCODE' '=ISTDA'.
PERFORM bdc_field USING 'RM61B-BUDAT' record-budat_002.
PERFORM bdc_field USING 'RM61B-BKTXT' record-bktxt_004.
PERFORM bdc_field USING 'RM61B-MATNR' record-matnr_005.
PERFORM bdc_field USING 'RM61B-WERKS' record-werks_006.
PERFORM bdc_field USING 'RM61B-ALORT' record-alort_007.
PERFORM bdc_field USING 'RM61B-ERFMG' record-erfmg_008.
PERFORM bdc_dynpro USING 'SAPLCOWB' '0130'.
PERFORM bdc_field USING 'BDC_OKCODE' '=WEIT'.
PERFORM bdc_field USING 'BDC_CURSOR' 'G_COWB_HEADER-MNGTXT'.
PERFORM bdc_transaction USING 'MFBF'.
l_mstring = t100-text. "CONTAINS THE MESSAGE THROWN
if l_mstring cs '&1'.
replace '&1' with messtab-msgv1 into l_mstring.
replace '&2' with messtab-msgv2 into l_mstring.
replace '&3' with messtab-msgv3 into l_mstring.
replace '&4' with messtab-msgv4 into l_mstring.
else.
replace '&' with messtab-msgv1 into l_mstring.
replace '&' with messtab-msgv2 into l_mstring.
replace '&' with messtab-msgv3 into l_mstring.
replace '&' with messtab-msgv4 into l_mstring.
endif.
condense l_mstring.
****MOVE RESPECTIVE MESSAGES AND RECORDS TO ITAB**************
move-corresponding record to messages.
move:l_mstring to messages-text.
move:messtab-msgtyp to messages-msgtyp.
append messages.
clear messages.
ENDLOOP.
ENDIF.
ENDFORM. "fill_bdc_table
--
form assign_columns .
refresh alvfld.
alvfld-fieldname = 'MATNR_005'.
alvfld-seltext_m = 'PART NO'.
append alvfld.
alvfld-fieldname = 'MAKTX'.
alvfld-seltext_m = 'Description'.
append alvfld.
alvfld-fieldname = 'WERKS_006'.
alvfld-seltext_m = 'Plant'.
append alvfld.
alvfld-fieldname = 'BUDAT_002'.
alvfld-seltext_m = 'Posting Date'.
append alvfld.
alvfld-fieldname = 'BKTXT_004'.
alvfld-seltext_m = 'Shift'.
append alvfld.
alvfld-fieldname = 'ERFMG_008'.
alvfld-seltext_m = 'Qty'.
append alvfld.
alvfld-fieldname = 'ALORT_007'.
alvfld-seltext_m = 'Stgloc'.
append alvfld.
alvfld-fieldname = 'TEXT'.
alvfld-seltext_m = 'Processed Status'.
append alvfld.
endform. " assign_columns
--
form f_event_build .
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
i_list_type = 0
IMPORTING
et_events = v_events[].
READ TABLE v_events WITH KEY name = slis_ev_top_of_page
INTO wk_events.
wk_LAYOUT-COLTAB_FIELDNAME = 'CELLCOLOR'. "FOR COLOUMN COLOR
wk_layout-colwidth_optimize = 'X'.
IF sy-subrc = 0.
MOVE c_formname_top_of_page TO wk_events-form.
MODIFY v_events FROM wk_events INDEX sy-tabix.
ENDIF.
endform. " f_event_build
--
FORM f_top_of_page.
CLEAR: it_list_comments[].
wk_list_comments-typ = 'H'. "H=Header, S=Selection, A=Action
wk_list_comments-key = ''.
wk_list_comments-info = 'BDC UPLOAD STATUS FOR PRD POSTING'.
APPEND wk_list_comments TO it_list_comments.
CLEAR wk_list_comments.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
i_logo = 'ENJOYSAP_LOGO'
it_list_commentary = it_list_comments.
ENDFORM. "F_TOP_OF_PAGE
--
form assign_colors .
loop at messages.
case messages-msgtyp.
when 'E'.
move: 'TEXT' to wa_color-fname.
move '6' to wa_color-color-col.
move '0' to wa_color-color-int.
move '1' to wa_color-color-inv.
append wa_color to messages-cellcolor.
modify messages transporting cellcolor.
when 'S'.
move: 'TEXT' to wa_color-fname.
move '5' to wa_color-color-col.
move '0' to wa_color-color-int.
move '1' to wa_color-color-inv.
append wa_color to messages-cellcolor.
modify messages transporting cellcolor.
endcase.
endloop.
endform. " assign_colors
**********************************************************************************************
INCLUDE PROGRAM
*******************************
***INCLUDE BDCRECX1.
for programs doing a data transfer by creating a batch-input session
and
for programs doing a data transfer by CALL TRANSACTION USING
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS SESSION RADIOBUTTON GROUP CTU. "create session
SELECTION-SCREEN COMMENT 3(20) TEXT-S07 FOR FIELD SESSION.
selection-screen position 45.
PARAMETERS CTU RADIOBUTTON GROUP CTU. "call transaction
SELECTION-SCREEN COMMENT 48(20) TEXT-S08 FOR FIELD CTU.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 3(20) TEXT-S01 FOR FIELD GROUP.
selection-screen position 25.
PARAMETERS GROUP(12). "group name of session
SELECTION-SCREEN COMMENT 48(20) TEXT-S05 FOR FIELD CTUMODE.
selection-screen position 70.
PARAMETERS CTUMODE LIKE CTU_PARAMS-DISMODE DEFAULT 'N'.
"A: show all dynpros
"E: show dynpro on error only
"N: do not display dynpro
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 3(20) TEXT-S02 FOR FIELD USER.
selection-screen position 25.
PARAMETERS: USER(12) DEFAULT SY-UNAME. "user for session in batch
SELECTION-SCREEN COMMENT 48(20) TEXT-S06 FOR FIELD CUPDATE.
selection-screen position 70.
PARAMETERS CUPDATE LIKE CTU_PARAMS-UPDMODE DEFAULT 'L'.
"S: synchronously
"A: asynchronously
"L: local
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 3(20) TEXT-S03 FOR FIELD KEEP.
selection-screen position 25.
PARAMETERS: KEEP AS CHECKBOX. "' ' = delete session if finished
"'X' = keep session if finished
SELECTION-SCREEN COMMENT 48(20) TEXT-S09 FOR FIELD E_GROUP.
selection-screen position 70.
parameters E_GROUP(12). "group name of error-session
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 3(20) TEXT-S04 FOR FIELD HOLDDATE.
selection-screen position 25.
PARAMETERS: HOLDDATE LIKE SY-DATUM.
SELECTION-SCREEN COMMENT 51(17) TEXT-S02 FOR FIELD E_USER.
selection-screen position 70.
PARAMETERS: E_USER(12) DEFAULT SY-UNAME. "user for error-session
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 51(17) TEXT-S03 FOR FIELD E_KEEP.
selection-screen position 70.
PARAMETERS: E_KEEP AS CHECKBOX. "' ' = delete session if finished
"'X' = keep session if finished
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 51(17) TEXT-S04 FOR FIELD E_HDATE.
selection-screen position 70.
PARAMETERS: E_HDATE LIKE SY-DATUM.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(33) TEXT-S10 FOR FIELD NODATA.
PARAMETERS: NODATA DEFAULT '/' LOWER CASE. "nodata
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(33) FOR FIELD SMALLLOG.
PARAMETERS: SMALLLOG as checkbox. "' ' = log all transactions
"'X' = no transaction logging
SELECTION-SCREEN END OF LINE.
----
data definition
----
Batchinputdata of single transaction
DATA: BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE.
messages of call transaction
DATA: MESSTAB LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.
error session opened (' ' or 'X')
DATA: E_GROUP_OPENED.
message texts
TABLES: T100.
----
at selection screen *
----
AT SELECTION-SCREEN.
group and user must be filled for create session
IF SESSION = 'X' AND
GROUP = SPACE OR USER = SPACE.
MESSAGE E613(MS).
ENDIF.
----
open dataset *
----
FORM OPEN_DATASET USING P_DATASET.
OPEN DATASET P_DATASET
FOR INPUT IN TEXT MODE
ENCODING DEFAULT.
IF SY-SUBRC <> 0.
WRITE: / TEXT-E00, SY-SUBRC.
STOP.
ENDIF.
ENDFORM.
----
close dataset *
----
FORM CLOSE_DATASET USING P_DATASET.
CLOSE DATASET P_DATASET.
ENDFORM.
----
create batchinput session *
(not for call transaction using...) *
----
FORM OPEN_GROUP.
IF SESSION = 'X'.
SKIP.
WRITE: /(20) 'Create group'(I01), GROUP.
SKIP.
open batchinput group
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING CLIENT = SY-MANDT
GROUP = GROUP
USER = USER
KEEP = KEEP
HOLDDATE = HOLDDATE.
WRITE: /(30) 'BDC_OPEN_GROUP'(I02),
(12) 'returncode:'(I05),
SY-SUBRC.
ENDIF.
ENDFORM.
----
end batchinput session *
(call transaction using...: error session) *
----
FORM CLOSE_GROUP.
IF SESSION = 'X'.
close batchinput group
CALL FUNCTION 'BDC_CLOSE_GROUP'.
WRITE: /(30) 'BDC_CLOSE_GROUP'(I04),
(12) 'returncode:'(I05),
SY-SUBRC.
ELSE.
IF E_GROUP_OPENED = 'X'.
CALL FUNCTION 'BDC_CLOSE_GROUP'.
WRITE: /.
WRITE: /(30) 'Fehlermappe wurde erzeugt'(I06).
E_GROUP_OPENED = ' '.
ENDIF.
ENDIF.
ENDFORM.
----
Start new transaction according to parameters *
----
FORM BDC_TRANSACTION USING TCODE.
DATA: L_MSTRING(480).
DATA: L_SUBRC LIKE SY-SUBRC.
batch input session
IF SESSION = 'X'.
CALL FUNCTION 'BDC_INSERT'
EXPORTING TCODE = TCODE
TABLES DYNPROTAB = BDCDATA.
IF SMALLLOG <> 'X'.
WRITE: / 'BDC_INSERT'(I03),
TCODE,
'returncode:'(I05),
SY-SUBRC,
'RECORD:',
SY-INDEX.
ENDIF.
call transaction using
ELSE.
REFRESH MESSTAB.
CALL TRANSACTION TCODE USING BDCDATA
MODE CTUMODE
UPDATE CUPDATE
MESSAGES INTO MESSTAB.
L_SUBRC = SY-SUBRC.
IF SMALLLOG <> 'X'.
WRITE: / 'CALL_TRANSACTION',
TCODE,
'returncode:'(I05),
L_SUBRC,
'RECORD:',
SY-INDEX.
LOOP AT MESSTAB.
SELECT SINGLE * FROM T100 WHERE SPRSL = MESSTAB-MSGSPRA
AND ARBGB = MESSTAB-MSGID
AND MSGNR = MESSTAB-MSGNR.
IF SY-SUBRC = 0.
L_MSTRING = T100-TEXT.
IF L_MSTRING CS '&1'.
REPLACE '&1' WITH MESSTAB-MSGV1 INTO L_MSTRING.
REPLACE '&2' WITH MESSTAB-MSGV2 INTO L_MSTRING.
REPLACE '&3' WITH MESSTAB-MSGV3 INTO L_MSTRING.
REPLACE '&4' WITH MESSTAB-MSGV4 INTO L_MSTRING.
ELSE.
REPLACE '&' WITH MESSTAB-MSGV1 INTO L_MSTRING.
REPLACE '&' WITH MESSTAB-MSGV2 INTO L_MSTRING.
REPLACE '&' WITH MESSTAB-MSGV3 INTO L_MSTRING.
REPLACE '&' WITH MESSTAB-MSGV4 INTO L_MSTRING.
ENDIF.
CONDENSE L_MSTRING.
WRITE: / MESSTAB-MSGTYP, L_MSTRING(250).
ELSE.
WRITE: / MESSTAB.
ENDIF.
ENDLOOP.
SKIP.
ENDIF.
Erzeugen fehlermappe ************************************************
IF L_SUBRC <> 0 AND E_GROUP <> SPACE.
IF E_GROUP_OPENED = ' '.
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING CLIENT = SY-MANDT
GROUP = E_GROUP
USER = E_USER
KEEP = E_KEEP
HOLDDATE = E_HDATE.
E_GROUP_OPENED = 'X'.
ENDIF.
CALL FUNCTION 'BDC_INSERT'
EXPORTING TCODE = TCODE
TABLES DYNPROTAB = BDCDATA.
ENDIF.
ENDIF.
REFRESH BDCDATA.
ENDFORM.
----
Start new screen *
----
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
CLEAR BDCDATA.
BDCDATA-PROGRAM = PROGRAM.
BDCDATA-DYNPRO = DYNPRO.
BDCDATA-DYNBEGIN = 'X'.
APPEND BDCDATA.
ENDFORM.
----
Insert field *
----
FORM BDC_FIELD USING FNAM FVAL.
IF FVAL <> NODATA.
CLEAR BDCDATA.
BDCDATA-FNAM = FNAM.
BDCDATA-FVAL = FVAL.
APPEND BDCDATA.
ENDIF.
ENDFORM.
‎2007 Jul 18 9:20 AM
ya i got it somehow.
Im giving my program below...just check if its correct.
Its consists of a include file which i m specifying seperately..
Please tell if there is any possibilities of error....
****************************************************************************************************
MAIN PRG
***************
REPORT zbdc_posting
NO STANDARD PAGE HEADING LINE-SIZE 255
MESSAGE-ID zpp.
******************
include bdcrecx1.
******************
PARAMETERS: dataset(132) LOWER CASE.
type-pools:slis.
tables:MAKT.
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 OCCURS 0,
budat_002(010),
bktxt_004(025),
matnr_005(018),
werks_006(004),
alort_007(004),
erfmg_008(017),
END OF record.
End generated data section ***
***********INTERNAL TABLE TO STORE MESSAGE STATUS**********
data: begin of messages occurs 0,
budat_002(010),
bktxt_004(025),
matnr_005(018),
maktx type makt-maktx,
werks_006(004),
alort_007(004),
erfmg_008(017),
text(100) ,
msgtyp type c,
cellcolor type lvc_t_scol,
end of messages.
***INTERNAL TABLES TO STORE ACCEPTED AND REJECTED PRD ENTRIES*****
DATA: it_acc LIKE TABLE OF record WITH HEADER LINE.
DATA: it_rej LIKE TABLE OF record WITH HEADER LINE.
********************************************************************
******INTERNAL TABLE TO STORE UPLOADED DATA****************
DATA: BEGIN OF st_record1 ,
matnr_005(018),
werks_006(004),
budat_002(010),
bktxt_004(025),
erfmg_007(017),
erfmg_008(017),
alort_007(004),
END OF st_record1.
DATA: record1 LIKE TABLE OF st_record1 WITH HEADER LINE.
**************************************************************
DATA: wk_elpro type mkal-alort,
wk_makt type makt-maktx.
*************************************************************
data:alvfld type slis_t_fieldcat_alv with header line,
v_events TYPE slis_t_event WITH HEADER LINE,
wk_events LIKE LINE OF v_events,
it_list_comments TYPE slis_t_listheader,
wk_list_comments LIKE LINE OF it_list_comments,
wa_color type lvc_s_scol,
wk_layout type slis_layout_alv..
CONSTANTS: c_formname_top_of_page TYPE slis_formname
VALUE 'F_TOP_OF_PAGE'.
********************
START-OF-SELECTION.
********************
PERFORM upload_fun.
PERFORM open_group.
PERFORM fill_bdc_table.
PERFORM close_group.
loop at messages.
select single maktx into wk_makt
from makt client specified
where mandt = sy-mandt
and matnr = messages-matnr_005.
move:wk_makt to messages-maktx.
modify messages.
clear: messages,wk_makt.
endloop.
perform assign_colors.
PERFORM f_event_build.
perform assign_columns.
if CTU = 'X'.
sort messages by matnr_005 ascending.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
i_background_id = 'ALV_BACKGROUND'
it_fieldcat = alvfld[]
is_layout = wk_layout
it_events = v_events[]
TABLES
t_outtab = messages
EXCEPTIONS
program_error = 1
OTHERS = 2.
endif.
END-OF-SELECTION.
--
FORM upload_fun.
REFRESH: record1,it_acc,it_rej,RECORD,messages.
CALL FUNCTION 'UPLOAD'
EXPORTING
filename = ' '
filetype = 'DAT'
TABLES
data_tab = record1
EXCEPTIONS
conversion_error = 1
invalid_table_width = 2
invalid_type = 3
no_batch = 4
unknown_error = 5
gui_refuse_filetransfer = 6
OTHERS = 7.
CLEAR record1.
--
DELETE record1 WHERE ( erfmg_007 = 0 OR erfmg_007 = ' ' )
AND ( erfmg_008 = 0 OR erfmg_008 = ' ' ).
DESCRIBE TABLE record1[].
IF sy-tfill > 0.
----
LOOP AT record1 WHERE erfmg_007 NE 0 AND erfmg_007 NE ' '.
MOVE: record1-budat_002 TO it_acc-budat_002,
record1-bktxt_004 TO it_acc-bktxt_004,
record1-matnr_005 TO it_acc-matnr_005,
record1-werks_006 TO it_acc-werks_006,
record1-erfmg_007 TO it_acc-erfmg_008.
APPEND it_acc.
CLEAR: it_acc,record1.
ENDLOOP.
DELETE it_acc WHERE erfmg_008 = 0 OR erfmg_008 = ' '.
LOOP AT it_acc .
--
SELECT SINGLE elpro INTO wk_elpro
FROM mkal client specified
WHERE mandt = sy-mandt
and matnr = it_acc-matnr_005
AND werks = it_acc-werks_006.
MOVE wk_elpro TO it_acc-alort_007.
MODIFY it_acc.
CLEAR: wk_elpro, it_acc.
ENDLOOP.
--
LOOP AT record1 WHERE erfmg_008 NE 0 AND erfmg_008 NE ' '.
MOVE: record1-budat_002 TO it_rej-budat_002,
record1-bktxt_004 TO it_rej-bktxt_004,
record1-matnr_005 TO it_rej-matnr_005,
record1-werks_006 TO it_rej-werks_006,
record1-erfmg_008 TO it_rej-erfmg_008,
record1-alort_007 TO it_rej-alort_007.
APPEND it_rej.
CLEAR: it_rej,record1.
ENDLOOP.
DELETE it_rej WHERE erfmg_008 = 0 OR erfmg_008 = ' '.
--
APPEND LINES OF it_acc TO record.
APPEND LINES OF it_rej TO record.
SORT record BY alort_007 ASCENDING.
FREE : it_rej, it_acc, record1.
ELSE.
MESSAGE i937.
STOP.
ENDIF.
ENDFORM. " UPLOAD_FUN
--
FORM fill_bdc_table.
data: l_mstring(480).
IF NOT record[] IS INITIAL.
LOOP AT record.
PERFORM bdc_dynpro USING 'SAPLBARM' '0800'.
PERFORM bdc_field USING 'BDC_CURSOR' 'RM61B-BKTXT'.
PERFORM bdc_field USING 'BDC_OKCODE' '=ISTDA'.
PERFORM bdc_field USING 'RM61B-BUDAT' record-budat_002.
PERFORM bdc_field USING 'RM61B-BKTXT' record-bktxt_004.
PERFORM bdc_field USING 'RM61B-MATNR' record-matnr_005.
PERFORM bdc_field USING 'RM61B-WERKS' record-werks_006.
PERFORM bdc_field USING 'RM61B-ALORT' record-alort_007.
PERFORM bdc_field USING 'RM61B-ERFMG' record-erfmg_008.
PERFORM bdc_dynpro USING 'SAPLCOWB' '0130'.
PERFORM bdc_field USING 'BDC_OKCODE' '=WEIT'.
PERFORM bdc_field USING 'BDC_CURSOR' 'G_COWB_HEADER-MNGTXT'.
PERFORM bdc_transaction USING 'MFBF'.
l_mstring = t100-text. "CONTAINS THE MESSAGE THROWN
if l_mstring cs '&1'.
replace '&1' with messtab-msgv1 into l_mstring.
replace '&2' with messtab-msgv2 into l_mstring.
replace '&3' with messtab-msgv3 into l_mstring.
replace '&4' with messtab-msgv4 into l_mstring.
else.
replace '&' with messtab-msgv1 into l_mstring.
replace '&' with messtab-msgv2 into l_mstring.
replace '&' with messtab-msgv3 into l_mstring.
replace '&' with messtab-msgv4 into l_mstring.
endif.
condense l_mstring.
****MOVE RESPECTIVE MESSAGES AND RECORDS TO ITAB**************
move-corresponding record to messages.
move:l_mstring to messages-text.
move:messtab-msgtyp to messages-msgtyp.
append messages.
clear messages.
ENDLOOP.
ENDIF.
ENDFORM. "fill_bdc_table
--
form assign_columns .
refresh alvfld.
alvfld-fieldname = 'MATNR_005'.
alvfld-seltext_m = 'PART NO'.
append alvfld.
alvfld-fieldname = 'MAKTX'.
alvfld-seltext_m = 'Description'.
append alvfld.
alvfld-fieldname = 'WERKS_006'.
alvfld-seltext_m = 'Plant'.
append alvfld.
alvfld-fieldname = 'BUDAT_002'.
alvfld-seltext_m = 'Posting Date'.
append alvfld.
alvfld-fieldname = 'BKTXT_004'.
alvfld-seltext_m = 'Shift'.
append alvfld.
alvfld-fieldname = 'ERFMG_008'.
alvfld-seltext_m = 'Qty'.
append alvfld.
alvfld-fieldname = 'ALORT_007'.
alvfld-seltext_m = 'Stgloc'.
append alvfld.
alvfld-fieldname = 'TEXT'.
alvfld-seltext_m = 'Processed Status'.
append alvfld.
endform. " assign_columns
--
form f_event_build .
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
i_list_type = 0
IMPORTING
et_events = v_events[].
READ TABLE v_events WITH KEY name = slis_ev_top_of_page
INTO wk_events.
wk_LAYOUT-COLTAB_FIELDNAME = 'CELLCOLOR'. "FOR COLOUMN COLOR
wk_layout-colwidth_optimize = 'X'.
IF sy-subrc = 0.
MOVE c_formname_top_of_page TO wk_events-form.
MODIFY v_events FROM wk_events INDEX sy-tabix.
ENDIF.
endform. " f_event_build
--
FORM f_top_of_page.
CLEAR: it_list_comments[].
wk_list_comments-typ = 'H'. "H=Header, S=Selection, A=Action
wk_list_comments-key = ''.
wk_list_comments-info = 'BDC UPLOAD STATUS FOR PRD POSTING'.
APPEND wk_list_comments TO it_list_comments.
CLEAR wk_list_comments.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
i_logo = 'ENJOYSAP_LOGO'
it_list_commentary = it_list_comments.
ENDFORM. "F_TOP_OF_PAGE
--
form assign_colors .
loop at messages.
case messages-msgtyp.
when 'E'.
move: 'TEXT' to wa_color-fname.
move '6' to wa_color-color-col.
move '0' to wa_color-color-int.
move '1' to wa_color-color-inv.
append wa_color to messages-cellcolor.
modify messages transporting cellcolor.
when 'S'.
move: 'TEXT' to wa_color-fname.
move '5' to wa_color-color-col.
move '0' to wa_color-color-int.
move '1' to wa_color-color-inv.
append wa_color to messages-cellcolor.
modify messages transporting cellcolor.
endcase.
endloop.
endform. " assign_colors
**********************************************************************************************
INCLUDE PROGRAM
*******************************
***INCLUDE BDCRECX1.
for programs doing a data transfer by creating a batch-input session
and
for programs doing a data transfer by CALL TRANSACTION USING
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS SESSION RADIOBUTTON GROUP CTU. "create session
SELECTION-SCREEN COMMENT 3(20) TEXT-S07 FOR FIELD SESSION.
selection-screen position 45.
PARAMETERS CTU RADIOBUTTON GROUP CTU. "call transaction
SELECTION-SCREEN COMMENT 48(20) TEXT-S08 FOR FIELD CTU.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 3(20) TEXT-S01 FOR FIELD GROUP.
selection-screen position 25.
PARAMETERS GROUP(12). "group name of session
SELECTION-SCREEN COMMENT 48(20) TEXT-S05 FOR FIELD CTUMODE.
selection-screen position 70.
PARAMETERS CTUMODE LIKE CTU_PARAMS-DISMODE DEFAULT 'N'.
"A: show all dynpros
"E: show dynpro on error only
"N: do not display dynpro
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 3(20) TEXT-S02 FOR FIELD USER.
selection-screen position 25.
PARAMETERS: USER(12) DEFAULT SY-UNAME. "user for session in batch
SELECTION-SCREEN COMMENT 48(20) TEXT-S06 FOR FIELD CUPDATE.
selection-screen position 70.
PARAMETERS CUPDATE LIKE CTU_PARAMS-UPDMODE DEFAULT 'L'.
"S: synchronously
"A: asynchronously
"L: local
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 3(20) TEXT-S03 FOR FIELD KEEP.
selection-screen position 25.
PARAMETERS: KEEP AS CHECKBOX. "' ' = delete session if finished
"'X' = keep session if finished
SELECTION-SCREEN COMMENT 48(20) TEXT-S09 FOR FIELD E_GROUP.
selection-screen position 70.
parameters E_GROUP(12). "group name of error-session
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 3(20) TEXT-S04 FOR FIELD HOLDDATE.
selection-screen position 25.
PARAMETERS: HOLDDATE LIKE SY-DATUM.
SELECTION-SCREEN COMMENT 51(17) TEXT-S02 FOR FIELD E_USER.
selection-screen position 70.
PARAMETERS: E_USER(12) DEFAULT SY-UNAME. "user for error-session
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 51(17) TEXT-S03 FOR FIELD E_KEEP.
selection-screen position 70.
PARAMETERS: E_KEEP AS CHECKBOX. "' ' = delete session if finished
"'X' = keep session if finished
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 51(17) TEXT-S04 FOR FIELD E_HDATE.
selection-screen position 70.
PARAMETERS: E_HDATE LIKE SY-DATUM.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(33) TEXT-S10 FOR FIELD NODATA.
PARAMETERS: NODATA DEFAULT '/' LOWER CASE. "nodata
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(33) FOR FIELD SMALLLOG.
PARAMETERS: SMALLLOG as checkbox. "' ' = log all transactions
"'X' = no transaction logging
SELECTION-SCREEN END OF LINE.
----
data definition
----
Batchinputdata of single transaction
DATA: BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE.
messages of call transaction
DATA: MESSTAB LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.
error session opened (' ' or 'X')
DATA: E_GROUP_OPENED.
message texts
TABLES: T100.
----
at selection screen *
----
AT SELECTION-SCREEN.
group and user must be filled for create session
IF SESSION = 'X' AND
GROUP = SPACE OR USER = SPACE.
MESSAGE E613(MS).
ENDIF.
----
open dataset *
----
FORM OPEN_DATASET USING P_DATASET.
OPEN DATASET P_DATASET
FOR INPUT IN TEXT MODE
ENCODING DEFAULT.
IF SY-SUBRC <> 0.
WRITE: / TEXT-E00, SY-SUBRC.
STOP.
ENDIF.
ENDFORM.
----
close dataset *
----
FORM CLOSE_DATASET USING P_DATASET.
CLOSE DATASET P_DATASET.
ENDFORM.
----
create batchinput session *
(not for call transaction using...) *
----
FORM OPEN_GROUP.
IF SESSION = 'X'.
SKIP.
WRITE: /(20) 'Create group'(I01), GROUP.
SKIP.
open batchinput group
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING CLIENT = SY-MANDT
GROUP = GROUP
USER = USER
KEEP = KEEP
HOLDDATE = HOLDDATE.
WRITE: /(30) 'BDC_OPEN_GROUP'(I02),
(12) 'returncode:'(I05),
SY-SUBRC.
ENDIF.
ENDFORM.
----
end batchinput session *
(call transaction using...: error session) *
----
FORM CLOSE_GROUP.
IF SESSION = 'X'.
close batchinput group
CALL FUNCTION 'BDC_CLOSE_GROUP'.
WRITE: /(30) 'BDC_CLOSE_GROUP'(I04),
(12) 'returncode:'(I05),
SY-SUBRC.
ELSE.
IF E_GROUP_OPENED = 'X'.
CALL FUNCTION 'BDC_CLOSE_GROUP'.
WRITE: /.
WRITE: /(30) 'Fehlermappe wurde erzeugt'(I06).
E_GROUP_OPENED = ' '.
ENDIF.
ENDIF.
ENDFORM.
----
Start new transaction according to parameters *
----
FORM BDC_TRANSACTION USING TCODE.
DATA: L_MSTRING(480).
DATA: L_SUBRC LIKE SY-SUBRC.
batch input session
IF SESSION = 'X'.
CALL FUNCTION 'BDC_INSERT'
EXPORTING TCODE = TCODE
TABLES DYNPROTAB = BDCDATA.
IF SMALLLOG <> 'X'.
WRITE: / 'BDC_INSERT'(I03),
TCODE,
'returncode:'(I05),
SY-SUBRC,
'RECORD:',
SY-INDEX.
ENDIF.
call transaction using
ELSE.
REFRESH MESSTAB.
CALL TRANSACTION TCODE USING BDCDATA
MODE CTUMODE
UPDATE CUPDATE
MESSAGES INTO MESSTAB.
L_SUBRC = SY-SUBRC.
IF SMALLLOG <> 'X'.
WRITE: / 'CALL_TRANSACTION',
TCODE,
'returncode:'(I05),
L_SUBRC,
'RECORD:',
SY-INDEX.
LOOP AT MESSTAB.
SELECT SINGLE * FROM T100 WHERE SPRSL = MESSTAB-MSGSPRA
AND ARBGB = MESSTAB-MSGID
AND MSGNR = MESSTAB-MSGNR.
IF SY-SUBRC = 0.
L_MSTRING = T100-TEXT.
IF L_MSTRING CS '&1'.
REPLACE '&1' WITH MESSTAB-MSGV1 INTO L_MSTRING.
REPLACE '&2' WITH MESSTAB-MSGV2 INTO L_MSTRING.
REPLACE '&3' WITH MESSTAB-MSGV3 INTO L_MSTRING.
REPLACE '&4' WITH MESSTAB-MSGV4 INTO L_MSTRING.
ELSE.
REPLACE '&' WITH MESSTAB-MSGV1 INTO L_MSTRING.
REPLACE '&' WITH MESSTAB-MSGV2 INTO L_MSTRING.
REPLACE '&' WITH MESSTAB-MSGV3 INTO L_MSTRING.
REPLACE '&' WITH MESSTAB-MSGV4 INTO L_MSTRING.
ENDIF.
CONDENSE L_MSTRING.
WRITE: / MESSTAB-MSGTYP, L_MSTRING(250).
ELSE.
WRITE: / MESSTAB.
ENDIF.
ENDLOOP.
SKIP.
ENDIF.
Erzeugen fehlermappe ************************************************
IF L_SUBRC <> 0 AND E_GROUP <> SPACE.
IF E_GROUP_OPENED = ' '.
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING CLIENT = SY-MANDT
GROUP = E_GROUP
USER = E_USER
KEEP = E_KEEP
HOLDDATE = E_HDATE.
E_GROUP_OPENED = 'X'.
ENDIF.
CALL FUNCTION 'BDC_INSERT'
EXPORTING TCODE = TCODE
TABLES DYNPROTAB = BDCDATA.
ENDIF.
ENDIF.
REFRESH BDCDATA.
ENDFORM.
----
Start new screen *
----
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
CLEAR BDCDATA.
BDCDATA-PROGRAM = PROGRAM.
BDCDATA-DYNPRO = DYNPRO.
BDCDATA-DYNBEGIN = 'X'.
APPEND BDCDATA.
ENDFORM.
----
Insert field *
----
FORM BDC_FIELD USING FNAM FVAL.
IF FVAL <> NODATA.
CLEAR BDCDATA.
BDCDATA-FNAM = FNAM.
BDCDATA-FVAL = FVAL.
APPEND BDCDATA.
ENDIF.
ENDFORM.
‎2007 Jul 17 8:54 AM
hi,
Use BDCMSGCOLL.
It will handle both the error and success messages.