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

bdc_using_call_transaction

Former Member
0 Likes
2,081

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.

1 ACCEPTED SOLUTION
Read only

RaymondGiuseppi
Active Contributor
0 Likes
2,002

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

19 REPLIES 19
Read only

PeterJonker
Active Contributor
0 Likes
2,002

Did you try with mode 'A' (display all ) ? It might become clear why it is going wrong.

Read only

Former Member
0 Likes
2,002

i try this also a mr. peter

Read only

Former Member
0 Likes
2,002

but no data is inserted into the table

Read only

former_member183134
Participant
0 Likes
2,002

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.

Read only

0 Likes
2,002

thanks anand .

but it not working

.

Read only

0 Likes
2,002

Hi Hasmukh,

Can you try call transaction immediately after the loop and endloop.. avoid separate Form and end form for call translation.

Thanks,

Anand

Read only

0 Likes
2,002

hi anand , my code is same as per u said . but it not inserting record into the table.

thanks

Read only

RaymondGiuseppi
Active Contributor
0 Likes
2,003

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

Read only

0 Likes
2,002

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.

Read only

0 Likes
2,002

Could you

  • Reduce your recorded schema, seems you press 2 or 3 times enter before clicking SAVE during SHDB?
  • Check if you get message WW Nr 16 in the returned message table?
  • paste a screenshoot of the last dynpro during execution (during OK_CODE = 'SAVE' pop-up execution)
  • In a temporary version, don't filter MESSTAB on TYPE, some messages can be declared as 'S' or 'W' and explain why data won't be updated
  • Replace  UPDATE 's' with  UPDATE 'S' uppercase

Regards,

Raymond

Read only

0 Likes
2,002

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.


Read only

0 Likes
2,002

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



Read only

0 Likes
2,002

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

Read only

0 Likes
2,002

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.

Read only

former_member214709
Participant
0 Likes
2,002

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

Read only

Former Member
0 Likes
2,002

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

Read only

0 Likes
2,002

Hi,

Try this BAPI - 'BAPI_MATL_GROUP_SAVEREPLICA' or FM 'MATL_GROUP_UPDATE'

Maybe this can help.

Regards,

LeoBuryan

Read only

former_member214709
Participant
0 Likes
2,002

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;)

Read only

0 Likes
2,002

hi dinesh

i solve this problem .

thanks dinesh