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

ways to append bdcdata

Pratik_Ingawale
Participant
0 Likes
3,053

Hi,

I have a issue.

1) In my bdc recording when i debug perform dynpro it goes to form all data gets append into bdcdata,

but when it comes out of form, bdcdata doesnot show any value,

i have created in subriutine,

2) is their any way to append my bdcdata from FORM to bdcdata recording.

PLEASE help as i am a fresher.

22 REPLIES 22
Read only

Former Member
0 Likes
2,346

Hi Rohan,

After Recording done to the Transaction Recording must be saved then check the radio button Transfer from Recording Program will be generated.

Copy the program and paste it in the program which you need.

BDCDATA is the internal table which will be filled.From this table you want to append it to the DB tables.

Let me know for further clarifications.

Thanks & Regards.

Pavan.N

Read only

0 Likes
2,346

Hi,

the values get append to bdcdata_tab but after coming out of end form table is blank,

and when it again goes to form the table bdcdata_tab is filled.

DATA: bdcdata_wa  TYPE bdcdata,
        bdcdata_tab TYPE TABLE OF bdcdata.


FORM  bdc_dynpro USING program dynpro.
   CLEAR bdcdata_wa.
   bdcdata_wa-program  = program.
   bdcdata_wa-dynpro   = dynpro.
   bdcdata_wa-dynbegin = 'X'.

APPEND bdcdata_wa TO bdcdata_tab.
ENDFORM.                    "

*----------------------------------------------------------------------*
*        Insert field                                                  *
*----------------------------------------------------------------------*
FORM bdc_field USING fnam fval.
   CLEAR bdcdata_wa.
   bdcdata_wa-fnam = fnam.
   bdcdata_wa-fval = fval.

APPEND bdcdata_wa TO bdcdata_tab.
ENDFORM.                    "BDC_FIELD

Read only

Former Member
0 Likes
2,346

Hi Rohan,

you can move the local data declaration bdcdata from your FORM routine to the top of your report (or your TOP include) to get a global declaration which you can access in your whole programm. But don't forget to refresh bdcdata in the beginning of your FORM routine in this case.

Regards,

Klaus

Read only

0 Likes
2,346

 

BUT in FORM it shows values in table.


call transaction 'XD01' using bdcdata_tab(table doesnot get filled)
                 mode 'A'
                 UPDATE 'S'
                 MESSAGES INTO IT_MESSAGES.

Read only

0 Likes
2,346

Hi Rohan,

the refresh is needed before filling table bdcdata again with data for the next transcation, if you have declared the table with DATA outside your FORM routine as a global internal table. You should do this to get the data access outside the FORM. You mustn't have duplicate declarations of bdcdata global and within the form routine, but only the global definition.

Please remove DATA declarartion of bdcdata within the FORM routine, after you have made the global definition (TOP include or at the data declaration at top of your main report).

Regards,

Klaus

Read only

RaymondGiuseppi
Active Contributor
0 Likes
2,346

Look a classic "scope of variable" case, perform a search in main program for BDCDATA, where it is defined global area/form, is it redefined as local, as parameter of form, that will impact its visibility.

Regards,

Raymond

Read only

0 Likes
2,346

hi, raymond

can u clarify little.

Read only

0 Likes
2,346

Step 1 - Look for definition of BDCDATA variable in your report, and post result.

Read only

0 Likes
2,346

BDCDATA is define globally in top of my program

Read only

0 Likes
2,346

The behaviour you are explaining leads to think Raymond is right, and your "global" declaration is not as global as you think.

Few time ago I decided to trash all my Batch-Input knowledge and start from scratch. Nothing like a macro definition to solve that kind of scope-related problem, nor to must include some weird SAP standard code in my programs.

AND I created a semi-automatic way to convert my recordings to Batch-Inputs.

Take a look here ... and remember: do NOT use batch-inputs if there is another way to perform your actions, they are not future-proof.

Read only

Former Member
0 Likes
2,346

Hi Rohan,

Internal tables declared within perfrom are local to the subroutine.

Declare the table globally that is in the beginning of the program and append it in the subroutine.

Please check the program DEMO_PROGRAM_CALL_TRANSACTION for details.

OR you can refer to this link

https://wiki.sdn.sap.com/wiki/display/Snippets/Simple%20BDC%20Program

Hope it helps

Cheers

Read only

pavanm592
Contributor
0 Likes
2,346

Hi Rohan,

you can refer the below code to fill the bdcdata table.

data:   gt_bdcdata type standard table of bdcdata.

         

perform bdc_dynpro      using 'SAPLMGMM'        '0060'.

perform bdc_field       using    'BDC_CURSOR'     'RMMG1-MATNR'.

*----------------------------------------------------------------------*

*        Start new screen                                              *

*----------------------------------------------------------------------*

form bdc_dynpro using program dynpro.

data : ls_bdcdata type bdcdata.

clear ls_bdcdata.

   ls_bdcdata-program  = program.

   ls_bdcdata-dynpro   = dynpro.

   ls_bdcdata-dynbegin = 'X'.

   append ls_bdcdata to gt_bdcdata.

endform.

*----------------------------------------------------------------------*

*        Insert field                                                  *

*----------------------------------------------------------------------*

form bdc_field using fnam fval.

data : ls_bdcdata type bdcdata.

   if fval <> nodata.

     clear ls_bdcdata.

     ls_bdcdata-fnam = fnam.

     ls_bdcdata-fval = fval.

     append ls_bdcdata to gt_bdcdata.

   endif.

endform.

After filling all the data call the Transaction.

CALL TRANSACTION 'TCODE' USING GT_BDCDATA MODE <A/E/N> UPDATE <S/A/L>

Read only

0 Likes
2,346

the values gets in gt_bdcdata in Form ..

but not in CALL TRANSACTION 'TCODE' USING GT_BDCDATA MODE <A/E/N> UPDATE <S/A/L>(gt_bdcdata)

Read only

0 Likes
2,346

Hi Rohan,

If u look in to my code i am using a  workarea  ls_bdcdatalocally of type  bdcdata,

and i am filling the global internal table gt_bdcdata.

So there is no issue of data not carried to the call transaction.

suppose if u r doing it in a Function Module then u need to export that table.

Reward points if helpful.

Regards,

Pavan

Read only

former_member209120
Active Contributor
0 Likes
2,346

Hi Rohan,

Try like this

REPORT  ZSAMPLE  NO STANDARD PAGE HEADING.

TYPES : BEGIN OF TY_FILE,

        MBRSH TYPE MARA-MBRSH,

        MTART TYPE MARA-MTART,

        MAKTX TYPE MAKT-MAKTX,

        MEINS TYPE MARA-MEINS,

        END OF TY_FILE.

DATA : I_FILE TYPE TABLE OF TY_FILE .

DATA : WA_FILE TYPE  TY_FILE .

DATA : LV_MSG TYPE STRING .

**********************BDC DATA DECLARARATIONS

DATA:   BDCDATA LIKE BDCDATA    OCCURS 0 WITH HEADER LINE.

DATA:   MESSTAB LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.

BREAK-POINT .

CALL FUNCTION 'GUI_UPLOAD'

  EXPORTING

    FILENAME            = 'C:\MARADATA.TXT'

    FILETYPE            = 'ASC'

    HAS_FIELD_SEPARATOR = 'X'

  TABLES

    DATA_TAB            = I_FILE.

LOOP AT I_FILE INTO WA_FILE .

  perform bdc_dynpro      using 'SAPLMGMM' '0060'.

  perform bdc_field       using 'BDC_CURSOR'

                                'RMMG1-MTART'.

  perform bdc_field       using 'BDC_OKCODE'

                                '=AUSW'.

  perform bdc_field       using 'RMMG1-MBRSH'

                                  WA_FILE-MBRSH.

  perform bdc_field       using 'RMMG1-MTART'

                                WA_FILE-MTART.

  perform bdc_dynpro      using 'SAPLMGMM' '0070'.

  perform bdc_field       using 'BDC_CURSOR'

                                'MSICHTAUSW-DYTXT(01)'.

  perform bdc_field       using 'BDC_OKCODE'

                                '=ENTR'.

  perform bdc_field       using 'MSICHTAUSW-KZSEL(01)'

                                'X'.

  perform bdc_dynpro      using 'SAPLMGMM' '4004'.

  perform bdc_field       using 'BDC_OKCODE'

                                '=BU'.

  perform bdc_field       using 'MAKT-MAKTX'

                                 WA_FILE-MAKTX.

  perform bdc_field       using 'BDC_CURSOR'

                                'MARA-MEINS'.

  perform bdc_field       using 'MARA-MEINS'

                                WA_FILE-MEINS.

  perform bdc_field       using 'MARA-MTPOS_MARA'

                                'NORM'.

  CALL TRANSACTION 'MM01'

      USING bdcdata

      UPDATE 'A'

      MODE 'N'

      MESSAGES INTO MESSTAB .

  If SY-SUBRC = 0.

    Perform display_success_rec.

  Else .

    Perform display_error_rec.

  Endif.

  CLEAR WA_FILE .

  REFRESH  BDCDATA.

  CLEAR BDCDATA.

  REFRESH MESSTAB .

  CLEAR MESSTAB.

ENDLOOP .

*----------------------------------------------------------------------*

*        Start new screen                                              *

*----------------------------------------------------------------------*

FORM BDC_DYNPRO USING PROGRAM DYNPRO.

  CLEAR BDCDATA.

  BDCDATA-PROGRAM  = PROGRAM.

  BDCDATA-DYNPRO   = DYNPRO.

  BDCDATA-DYNBEGIN = 'X'.

  APPEND BDCDATA.

ENDFORM.                    "BDC_DYNPRO

*&---------------------------------------------------------------------*

*&      Form  BDC_FIELD

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*      -->FNAM       text

*      -->FVAL       text

*----------------------------------------------------------------------*

FORM BDC_FIELD USING FNAM FVAL.

*  IF FVAL <> NODATA.

  CLEAR BDCDATA.

  BDCDATA-FNAM = FNAM.

  BDCDATA-FVAL = FVAL.

  APPEND BDCDATA.

*  ENDIF.

ENDFORM.                    "BDC_FIELD

*&---------------------------------------------------------------------*

*&      Form  display_success_rec

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

FORM display_success_rec .

  READ TABLE  MESSTAB WITH KEY MSGTYP = 'S' .

  WRITE : / 'material is created with no:' ,  messtab-msgv1  COLOR 5.

ENDFORM.                    " display_success_rec

*&---------------------------------------------------------------------*

*&      Form  display_error_rec

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

FORM display_error_rec .

  LOOP AT MESSTAB WHERE MSGTYP = 'E' .

    CALL FUNCTION 'FORMAT_MESSAGE'

      EXPORTING

        ID   = MESSTAB-MSGID

        LANG = 'E'

        NO   = MESSTAB-MSGNR

        V1   = MESSTAB-MSGV1

        V2   = MESSTAB-MSGV2

        V3   = MESSTAB-MSGV3

        V4   = MESSTAB-MSGV4

      IMPORTING

        MSG  = LV_MSG.

    WRITE / lv_msg  COLOR 6.

  ENDLOOP .

ENDFORM.                    " display_error_rec

*************************************************************************

FLAT FILE SHOULD BE AS BELOW

*****************************************************************

P    COUP    DESC5    KGS

P    COUP    DESC6    KGS

P    COUP    DESC7    KGx

P    COUP    DESC8    KGS

Read only

0 Likes
2,346

thanks for code

i am doing in function module

Read only

0 Likes
2,346

Same thing we can use in FM also.

Read only

Pratik_Ingawale
Participant
0 Likes
2,346

Thank you experts for your help i created function module for bdc..

just little help

when i call function module from my report it gives following error

CALL_FUNCTION_CONFLICT_TYPE

CX_SY_DYN_CALL_ILLEGAL_TYPE

can u help me to pass my parameter to fm.

Read only

Pratik_Ingawale
Participant
0 Likes
2,346

Finally done

Thanks all of you.

Read only

0 Likes
2,346

Dear Rohan,

Good... Finally You Achieved...

Read only

0 Likes
2,346

Can you please explain us how did you achieved your goals?

In the future someone should land here looking for a solution to a problem like yours, and to have the solution explained should be useful for all of us.

Thanks in advance.

Read only

0 Likes
2,346

write this in globally(include) where u have written 

*----------------------------------------------------------------------*

*        Start new screen                                              *

*----------------------------------------------------------------------*

FORM BDC_DYNPRO USING PROGRAM DYNPRO.

  CLEAR BDCDATA.

  BDCDATA-PROGRAM  = PROGRAM.

  BDCDATA-DYNPRO   = DYNPRO.

  BDCDATA-DYNBEGIN = 'X'.

  APPEND BDCDATA.

ENDFORM.                    "BDC_DYNPRO

*&---------------------------------------------------------------------*

*&      Form  BDC_FIELD

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*      -->FNAM       text

*      -->FVAL       text

*----------------------------------------------------------------------*

FORM BDC_FIELD USING FNAM FVAL.

*  IF FVAL <> NODATA.

  CLEAR BDCDATA.

  BDCDATA-FNAM = FNAM.

  BDCDATA-FVAL = FVAL.

  APPEND BDCDATA.

*  ENDIF.

ENDFORM.                    "BDC_FIELD

perform this in subroutine. and include this in globally where u write new screen and bdc_field

CALL TRANSACTION 'MM01'

      USING bdcdata

      UPDATE 'A'

      MODE 'N'

      MESSAGES INTO MESSTAB .