2016 Jan 28 5:00 AM
hi ,
i am doing bdc for t-code WG21.
i write code for it. but after processing it . there is no effect in material group also code not giving any errors for this.
below is my code please see and help me.
report Z_GROUPBDCINSERT
no standard page heading line-size 255.
*----------------------------------------------------------------------*
* 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')
w_msg1(51).
DATA: E_GROUP_OPENED.
* message texts
TABLES: T100.
TYPES: BEGIN OF ty_record,
MATKL type MATKL,
wgbez type wgbez,
end of ty_record.
DATA: lt_mat type TABLE OF TY_RECORD,
wa_mat type TY_RECORD.
PARAMETERS p_name type IBIPPARMS-PATH OBLIGATORY.
at SELECTION-SCREEN ON VALUE-REQUEST FOR p_name.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
field_name = ' '
IMPORTING
FILE_NAME = p_name.
TYPES:
ty_record1(4096) TYPE c OCCURS 0 .
DATA:w_struct TYPE TY_RECORD1.
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
I_FIELD_SEPERATOR = 'X'
I_LINE_HEADER = 'X'
I_TAB_RAW_DATA = W_STRUCT
I_FILENAME = p_name
TABLES
I_TAB_CONVERTED_DATA = LT_MAT
EXCEPTIONS
CONVERSION_FAILED = 1
OTHERS = 2
.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
start-of-selection.
loop at LT_MAT into WA_MAT.
perform bdc_dynpro using 'SAPMWWG2' '1000'.
perform bdc_field using 'BDC_CURSOR'
'T023D-MATKL'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'T023D-MATKL'
WA_MAT-matkl.
perform bdc_dynpro using 'SAPMWWG2' '1100'.
perform bdc_field using 'BDC_CURSOR'
'T023TD-WGBEZ'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'T023TD-WGBEZ'
WA_MAT-wgbez.
perform bdc_dynpro using 'SAPMWWG2' '1100'.
perform bdc_field using 'BDC_CURSOR'
'T023TD-WGBEZ'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'T023TD-WGBEZ'
WA_MAT-wgbez.
perform bdc_dynpro using 'SAPMWWG2' '1100'.
perform bdc_field using 'BDC_CURSOR'
'T023TD-WGBEZ'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'T023TD-WGBEZ'
WA_MAT-wgbez.
perform bdc_dynpro using 'SAPMWWG2' '1100'.
perform bdc_field using 'BDC_CURSOR'
'WWGD-CLASS1'.
perform bdc_field using 'BDC_OKCODE'
'=SAVE'.
perform bdc_field using 'T023TD-WGBEZ'
WA_MAT-wgbez.
perform bdc_transaction using 'WG21'.
ENDLOOP.
* WRITE:/ 'success record:-' ,'|', cnt.
* WRITE:/ 'unsuccess record:-' , '|',cnt1.
*----------------------------------------------------------------------*
* Start new transaction according to parameters *
*----------------------------------------------------------------------*
FORM BDC_TRANSACTION USING TCODE.
DATA: L_MSTRING(480).
DATA: L_SUBRC LIKE SY-SUBRC.
REFRESH MESSTAB.
CALL TRANSACTION TCODE USING BDCDATA
MODE 'N'
UPDATE 's'
MESSAGES INTO MESSTAB.
if sy-subrc = 0.
* cnt = cnt + 1.
* else.
* cnt1 = cnt1 + 1.
write 'data insert'.
ENDIF.
LOOP AT MESSTAB into W_MSG1 WHERE MSGTYP eq 'I'.
MESSAGE ID MESSTAB-MSGID
TYPE MESSTAB-MSGTYP
NUMBER MESSTAB-MSGNR
INTO L_MSTRING
WITH MESSTAB-MSGV1
MESSTAB-MSGV2
MESSTAB-MSGV3
MESSTAB-MSGV4.
WRITE: / MESSTAB-MSGTYP, L_MSTRING(250).
ENDLOOP.
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 <> space.
CLEAR BDCDATA.
BDCDATA-FNAM = FNAM.
BDCDATA-FVAL = FVAL.
APPEND BDCDATA.
ENDIF.
ENDFORM.
2016 Jan 28 6:50 AM
In you program you didn't manage the failure in CALL TRANSACTION, you didn't handle the sy-subrc NE 0 case and didn't also write anytthing when error/abort messages are returned in MESSTAB. You always consider that the call was successful and only write 'I'nformation message, not 'E'rror, 'W'arning, 'A'bort or even 'S'uccess ones.
So, please, first correct your code and test again.
Regards,
Raymond
2016 Jan 28 5:51 AM
Did you try with mode 'A' (display all ) ? It might become clear why it is going wrong.
2016 Jan 28 5:56 AM
2016 Jan 28 6:24 AM
2016 Jan 28 6:45 AM
Hi Hasmukh,
I Have just gone through the code.. but not in depth.....
It looks like minor change needed in the below statement
CALL TRANSACTION TCODE USING BDCDATA
MODE 'N'
UPDATE 's'
MESSAGES INTO MESSTAB.
UPDATE 'S'
Please use upper case if you have used lower case in code.
Thanks,
Anand.
2016 Jan 28 7:09 AM
2016 Jan 28 7:23 AM
Hi Hasmukh,
Can you try call transaction immediately after the loop and endloop.. avoid separate Form and end form for call translation.
Thanks,
Anand
2016 Jan 28 9:31 AM
hi anand , my code is same as per u said . but it not inserting record into the table.
thanks
2016 Jan 28 6:50 AM
In you program you didn't manage the failure in CALL TRANSACTION, you didn't handle the sy-subrc NE 0 case and didn't also write anytthing when error/abort messages are returned in MESSTAB. You always consider that the call was successful and only write 'I'nformation message, not 'E'rror, 'W'arning, 'A'bort or even 'S'uccess ones.
So, please, first correct your code and test again.
Regards,
Raymond
2016 Jan 28 7:08 AM
hi thanks ,
but it also not work i try this below code after change.
please check and reply .
it still not insert any record into the table.
------------------------------------------------------------------------------------------------------
FORM BDC_TRANSACTION USING TCODE.
DATA: L_MSTRING(480).
DATA: L_SUBRC LIKE SY-SUBRC.
REFRESH MESSTAB.
CALL TRANSACTION TCODE USING BDCDATA
MODE 'A'
UPDATE 'S'
MESSAGES INTO MESSTAB.
if sy-subrc NE 0.
* cnt = cnt + 1.
* else.
* cnt1 = cnt1 + 1.
write 'data not insert'.
else.
write 'insert'.
ENDIF.
LOOP AT MESSTAB into W_MSG1 WHERE MSGTYP eq 'E'.
MESSAGE ID MESSTAB-MSGID
TYPE MESSTAB-MSGTYP
NUMBER MESSTAB-MSGNR
INTO L_MSTRING
WITH MESSTAB-MSGV1
MESSTAB-MSGV2
MESSTAB-MSGV3
MESSTAB-MSGV4.
WRITE: / MESSTAB-MSGTYP, L_MSTRING(250).
ENDLOOP.
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 <> space.
CLEAR BDCDATA.
BDCDATA-FNAM = FNAM.
BDCDATA-FVAL = FVAL.
APPEND BDCDATA.
ENDIF.
ENDFORM.
2016 Jan 28 7:54 AM
Could you
Regards,
Raymond
2016 Jan 28 9:30 AM
hi raymond ,
i try as per u said but in affect first time in table ,when i again execute new record new file it will processed but data is not inserted in second time into the table.
my code is below.
report ZNEW_GROUPINSERT
no standard page heading line-size 255.
*----------------------------------------------------------------------*
* 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.
TYPES: BEGIN OF ty_record,
MATKL type MATKL,
wgbez type wgbez,
end of ty_record.
PARAMETERS p_FILE TYPE IBIPPARMS-PATH OBLIGATORY.
DATA: lt_mat type TABLE OF TY_RECORD,
wa_mat type TY_RECORD.
at SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
IMPORTING
FILE_NAME = P_FILE
.
TYPES:
ty_record1(4096) TYPE c OCCURS 0 .
DATA:w_struct TYPE TY_RECORD1.
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
I_FIELD_SEPERATOR = 'X'
* I_LINE_HEADER =
I_TAB_RAW_DATA = W_STRUCT
I_FILENAME = p_file
TABLES
I_TAB_CONVERTED_DATA = LT_MAT
EXCEPTIONS
CONVERSION_FAILED = 1
OTHERS = 2
.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
start-of-selection.
loop at lt_mat INTO wa_mat.
perform bdc_dynpro using 'SAPMWWG2' '1000'.
perform bdc_field using 'BDC_CURSOR'
'T023D-MATKL'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'T023D-MATKL'
wa_mat-matkl.
perform bdc_dynpro using 'SAPMWWG2' '1100'.
perform bdc_field using 'BDC_CURSOR'
'T023TD-WGBEZ'.
perform bdc_field using 'BDC_OKCODE'
'=SAVE'.
perform bdc_field using 'T023TD-WGBEZ'
wa_mat-wgbez.
perform bdc_transaction using 'WG21'.
ENDLOOP.
*----------------------------------------------------------------------*
* Start new transaction according to parameters *
*----------------------------------------------------------------------*
FORM BDC_TRANSACTION USING TCODE.
DATA: L_MSTRING(480).
DATA: L_SUBRC LIKE SY-SUBRC.
REFRESH MESSTAB.
CALL TRANSACTION TCODE USING BDCDATA
MODE 'A'
UPDATE 'S'
MESSAGES INTO MESSTAB.
WRITE: / 'CALL_TRANSACTION',
TCODE,
'returncode:'(I05),
L_SUBRC,
'RECORD:',
SY-INDEX.
LOOP AT MESSTAB.
MESSAGE ID MESSTAB-MSGID
TYPE MESSTAB-MSGTYP
NUMBER MESSTAB-MSGNR
INTO L_MSTRING
WITH MESSTAB-MSGV1
MESSTAB-MSGV2
MESSTAB-MSGV3
MESSTAB-MSGV4.
WRITE: / MESSTAB-MSGTYP, L_MSTRING(250).
ENDLOOP.
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 <> SPACE.
CLEAR BDCDATA.
BDCDATA-FNAM = FNAM.
BDCDATA-FVAL = FVAL.
APPEND BDCDATA.
ENDIF.
ENDFORM.
2016 Jan 28 10:18 AM
Hi Hasmukh,
Write the call transaction statement.. Inside the loop.
If you write outside loop only one record (last record) will be inserted in your table.
So write the call transaction statement inside the loop so that it can write each and every record into your table..
Below is the sample code...
Loop lt_mat into wa_mat.
perform bdc_dynpro using 'SAPMWWG2' '1000'.
perform bdc_field using 'BDC_CURSOR'
'T023D-MATKL'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'T023D-MATKL'
wa_mat-matkl.
perform bdc_dynpro using 'SAPMWWG2' '1100'.
perform bdc_field using 'BDC_CURSOR'
'T023TD-WGBEZ'.
perform bdc_field using 'BDC_OKCODE'
'=SAVE'.
perform bdc_field using 'T023TD-WGBEZ'
wa_mat-wgbez.
CALL TRANSACTION TCODE USING BDCDATA
MODE 'A'
UPDATE 'S'
MESSAGES INTO MESSTAB.
Endloop.
Thanks,
Anand
2016 Jan 28 10:24 AM
Hi,
In your scenario,
CALL TRANSACTION 'WG21' USING BDCDATA
MODE 'A'
UPDATE 'S'
MESSAGES INTO MESSTAB.
Use the above statement... before the line of ENDLOOP (keyword).
Thanks,
Anand
2016 Jan 28 10:54 AM
hi anand ,
i also try this. now it not take data from file for particular field which i map and its working same as before.
2016 Jan 28 11:51 AM
Hi Hasmukh,
Did u check the data declaration:
BDCDATA LIKE BDCDATA
Make sure you are using BDCDATA as internal table and not structure, in your case probably you are using the BDCDATA as structure.
Also you need to REFRESH BDCDATA before ENDLOOP statement.
It would be a better approach if you use IT_BDCDATA as internal table and WA_BDCDATA as part of work area declaration.
Warm Regards,
Dinesh
2016 Jan 29 12:24 PM
Hi,
Did you Check LT_MAT contains Data properly,
please check TEXT_CONVERT_XLS_TO_SAP function module I_TAB_RAW_DATA = W_STRUCT
W_STRUCT is type of truxs_t_text_data.
Once check it.
and Clear WA_MAT after call transaction
2016 Jan 29 12:58 PM
Hi,
Try this BAPI - 'BAPI_MATL_GROUP_SAVEREPLICA' or FM 'MATL_GROUP_UPDATE'
Maybe this can help.
Regards,
LeoBuryan
2016 Jan 29 3:36 PM
Hi Hasmukh,
Pls. let us know whether you were able to resolve the issue.
If the issue persists kindly let us know, we all would love to help you.
Warm Regards,
Dinesh;)
2016 Jan 30 5:50 AM