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

FORM BDC DYNPRO error

Pratik_Ingawale
Participant
0 Likes
2,901

Hey, i am a fresher i wanted to create a bdc in function module, i have written code for it in function module and import parameter as file path,

but it is gives a error as (before the statement 'form",conclude with"endfunction".)

we cant declare FORM in source code...is their any method to declare .please help

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

*        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.

14 REPLIES 14
Read only

RaymondGiuseppi
Active Contributor
0 Likes
2,309

Don't insert the FORM between the FUNCTION and ENDFUNCTION statements, but in an include at the end of the main program source of the function group (include name like L<fgr>F) as a last solution insert those after the ENDFUNCTION, but that is not good practice. (If those are edit function group, usually SAP provide a Z-include in the code of the main function group, name like  ZX<fgr>zzz)

Regards,

Raymond

Read only

0 Likes
2,309

i just have to copy the 2 form in include top..right sir

Read only

0 Likes
2,309

Usually not, in good practice, only insert global declaration in TOP include, if function group is ZXXX, use following includes

- LZXXXXTOP for global data declaration

- LZXXXXF01 - LZXXXXF99 for form declaration <- create one such include in main FG program

-  LZXXXXO01 -  LZXXXXO99 for PBO modules

-  LZXXXXI01 -  LZXXXXI99 for PAI modules

- LZXXXXUXX - do not use (FMs come here)

Navigation thru FM -> Main program -> uncomment / double-click

Regards,

Raymond

Read only

Former Member
0 Likes
2,307

Hi Rohan,

In SHDB transaction you have an option of creating FM. Do the Recording and instead of creating a Program click on FM. See the screenshot,

BR,

Ankit.

Read only

0 Likes
2,307

hi aniket ,

if i create that way,i  have to create internal table of fields reqired,the upload function ,convert excel function call in source code right,and what about form where to declare

Read only

0 Likes
2,307

Hi Rohan,

BDC_DYNPRO and BDC_FIELD are standard SAP generated subroutines and you may try copying these in your Form/Subroutine Include and not Top Include.

Please revert with further questions.

BR,

Ankit.

Read only

0 Likes
2,307

THIS IS MY CODE...

FUNCTION ZNEW_XD01.

*"----------------------------------------------------------------------

*"*"Local interface:

*"  IMPORTING

*"     REFERENCE(FILEPATH) LIKE  RLGRAP-FILENAME

*"     REFERENCE(P_MODE) TYPE  C

*"----------------------------------------------------------------------

*INCLUDE BDCRECXY.

TYPE-POOLS: truxs.

data: bdcdata like bdcdata occurs 0 with header line.

  data: w_mode TYPE c.

DATA: i_text_data TYPE truxs_t_text_data,

       filename_string TYPE string.

DATA : IT_MESSAGES LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.

DATA : V_MESG(50).

DATA: BEGIN OF itab OCCURS 0,

buKRs like RF02D-BUKRS,"OMPANY CODE

VKORG like RF02D-VKORG,  "Sales Organization.

  VTWEG like RF02D-VTWEG,  "Distribution Channel.

SPART like RF02D-SPART,     "Division

KTOKD LIKE RF02D-KTOKD,   "ACCOUNT GROUP.

ANRED LIKE KNA1-ANRED,   "TITLE.

NAME1 like kna1-name1,   "name.

ORT01 like kna1-ort01,   "city.

LAND1 like kna1-land1,  "country.

SPRAS like kna1-spras,   "language.

PSTLZ like kna1-pstlz,   "postal code.

AKONT like knb1-akont,   "Reconciliation Account in General Ledger.

BZIRK like knvv-bzirk, "sales district.

KONDA like KNVV-KONDA,   "price group.

ZTERM like knvv-zterm, "Terms of payment key.

TAXKD like KNVI-TAXKD," Tax classification for customer.

  end of itab.

*

*DATA: BEGIN OF itab OCCURS 0,

*      BUKRS(4),  "company code.

*      VKORG(4),  "Sales Organization.

*      VTWEG(2),  "Distribution Channel.

*      SPART(2),     "Division

*      KTOKD(4),   "account group.

*      ANRED(15), "TITLE

*      name1(35),   "name.

*      ort01(35),   "city.

*      land1(3) ,  "country.

*      spras(1) ,   "language.

*      pstlz(10),   "postal code.

*      akont(10),   "Reconciliation Account in General Ledger.

*      bzirk(6) , "sales district.

*      KONDA(2),   "price group.

*     zterm(4), "Terms of payment key.

*      TAXKD(1).  " Tax classification for customer.

*DATA: END OF itab.

IF p_mode = 'A' OR p_mode = 'N' .

     w_mode = p_mode.

   ELSE.

*Error Message

     MESSAGE 'PLEASE ENTER THE MODE A or N' TYPE 'E'.

  ENDIF.

*

*AT SELECTION-SCREEN ON VALUE-REQUEST FOR FILEpath. "For dropdown filename

*

*CALL FUNCTION 'F4_FILENAME'

*EXPORTING

*PROGRAM_NAME = sy-repid "SYST-CPROG

*DYNPRO_NUMBER = SYST-DYNNR

*FIELD_NAME = 'filepath'

*IMPORTING

*FILE_NAME = FILEpath.

filename_string = FILEPATH.

*

   CALL FUNCTION 'GUI_UPLOAD'

     EXPORTING

       filename                      = filename_string

       filetype                      = 'ASC'

       has_field_separator           = 'X'

*     HEADER_LENGTH                 = 0

*     READ_BY_LINE                  = 'X'

       dat_mode                      = ''

*   IMPORTING

*     FILELENGTH                    =

*     HEADER                        =

     TABLES

       data_tab                      = i_text_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.

   CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'

     EXPORTING

       i_field_seperator          = 'X'

*     I_LINE_HEADER              =

       i_tab_raw_data             = i_text_data

       i_filename                 = filepath

     TABLES

       i_tab_converted_data       = itab

     EXCEPTIONS

       conversion_failed          = 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.

*start-of-selection.

*perform open_group.

LOOP AT ITAB.

perform bdc_dynpro      using 'SAPMF02D' '0100'.

perform bdc_field       using 'BDC_CURSOR'

                               'RF02D-KTOKD'.

perform bdc_field       using 'BDC_OKCODE'

                               '/00'.

perform bdc_field       using 'RF02D-BUKRS'

                               ITAB-BUKRS."'1100'.

perform bdc_field       using 'RF02D-VKORG'

                               ITAB-VKORG."'1000'.

perform bdc_field       using 'RF02D-VTWEG'

                               ITAB-VTWEG."'10'.

perform bdc_field       using 'RF02D-SPART'

                               ITAB-SPART."'01'.

perform bdc_field       using 'RF02D-KTOKD'

                               ITAB-KTOKD."'DEBI'.

perform bdc_dynpro      using 'SAPMF02D' '0110'.

perform bdc_field       using 'BDC_CURSOR'

                               'KNA1-SPRAS'.

perform bdc_field       using 'BDC_OKCODE'

                               '/00'.

perform bdc_field       using 'KNA1-ANRED'

                               ITAB-ANRED."'company'.

perform bdc_field       using 'KNA1-NAME1'

                               ITAB-NAME1."'asd pvt ltd'.

perform bdc_field       using 'KNA1-ORT01'

                               ITAB-ORT01."'pune'.

perform bdc_field       using 'KNA1-PSTLZ'

                               ITAB-PSTLZ."'440018'.

perform bdc_field       using 'KNA1-LAND1'

                               ITAB-LAND1."'in'.

perform bdc_field       using 'KNA1-SPRAS'

                               ITAB-SPRAS."'en'.

perform bdc_dynpro      using 'SAPMF02D' '0120'.

perform bdc_field       using 'BDC_CURSOR'

                               'KNA1-LIFNR'.

perform bdc_field       using 'BDC_OKCODE'

                               '/00'.

perform bdc_dynpro      using 'SAPMF02D' '0125'.

perform bdc_field       using 'BDC_CURSOR'

                               'KNA1-NIELS'.

perform bdc_field       using 'BDC_OKCODE'

                               '/00'.

perform bdc_dynpro      using 'SAPMF02D' '0130'.

perform bdc_field       using 'BDC_CURSOR'

                               'KNBK-BANKS(01)'.

perform bdc_field       using 'BDC_OKCODE'

                               '=ENTR'.

perform bdc_dynpro      using 'SAPMF02D' '0340'.

perform bdc_field       using 'BDC_CURSOR'

                               'RF02D-KUNNR'.

perform bdc_field       using 'BDC_OKCODE'

                               '=ENTR'.

perform bdc_dynpro      using 'SAPMF02D' '0360'.

perform bdc_field       using 'BDC_CURSOR'

                               'KNVK-NAMEV(01)'.

perform bdc_field       using 'BDC_OKCODE'

                               '=ENTR'.

perform bdc_dynpro      using 'SAPMF02D' '0210'.

perform bdc_field       using 'BDC_CURSOR'

                               'KNB1-AKONT'.

perform bdc_field       using 'BDC_OKCODE'

                               '/00'.

perform bdc_field       using 'KNB1-AKONT'

                               ITAB-AKONT."'233100'.

perform bdc_dynpro      using 'SAPMF02D' '0215'.

perform bdc_field       using 'BDC_CURSOR'

                               'KNB1-ZTERM'.

perform bdc_field       using 'BDC_OKCODE'

                               '/00'.

perform bdc_field       using 'KNB1-ZTERM'

                               ITAB-ZTERM."'K000'.

perform bdc_dynpro      using 'SAPMF02D' '0220'.

perform bdc_field       using 'BDC_CURSOR'

                               'KNB5-MAHNA'.

perform bdc_field       using 'BDC_OKCODE'

                               '/00'.

perform bdc_dynpro      using 'SAPMF02D' '0230'.

perform bdc_field       using 'BDC_CURSOR'

                               'KNB1-VRSNR'.

perform bdc_field       using 'BDC_OKCODE'

                               '/00'.

perform bdc_dynpro      using 'SAPMF02D' '0610'.

perform bdc_field       using 'BDC_OKCODE'

                               '/00'.

perform bdc_field       using 'BDC_CURSOR'

                               'RF02D-KUNNR'.

perform bdc_dynpro      using 'SAPMF02D' '0310'.

perform bdc_field       using 'BDC_CURSOR'

                               'KNVV-KONDA'.

perform bdc_field       using 'BDC_OKCODE'

                               '/00'.

perform bdc_field       using 'KNVV-BZIRK'

                               ITAB-BZIRK."'0002'.

perform bdc_field       using 'KNVV-AWAHR'

                               '100'.

perform bdc_field       using 'KNVV-WAERS'

                               'INR'.

perform bdc_field       using 'KNVV-KONDA'

                               ITAB-KONDA."'01'.

perform bdc_field       using 'KNVV-KALKS'

                               '1'.

perform bdc_dynpro      using 'SAPMF02D' '0315'.

perform bdc_field       using 'BDC_CURSOR'

                               'KNVV-LPRIO'.

perform bdc_field       using 'BDC_OKCODE'

                               '/00'.

perform bdc_field       using 'KNVV-KZAZU'

                               'X'.

perform bdc_field       using 'KNVV-ANTLF'

                               '9'.

perform bdc_dynpro      using 'SAPMF02D' '0320'.

perform bdc_field       using 'BDC_CURSOR'

                               'KNVV-ZTERM'.

perform bdc_field       using 'BDC_OKCODE'

                               '/00'.

perform bdc_field       using 'KNVV-ZTERM'

                               ITAB-ZTERM."'k000'.

perform bdc_dynpro      using 'SAPMF02D' '1350'.

perform bdc_field       using 'BDC_CURSOR'

                               'KNVI-TAXKD(01)'.

perform bdc_field       using 'BDC_OKCODE'

                               '=ENTR'.

perform bdc_field       using 'KNVI-TAXKD(01)'

                               ITAB-TAXKD."'1'.

perform bdc_dynpro      using 'SAPMF02D' '1350'.

perform bdc_field       using 'BDC_CURSOR'

                               'RF02D-KUNNR'.

perform bdc_field       using 'BDC_OKCODE'

                               '=ENTR'.

perform bdc_dynpro      using 'SAPMF02D' '0324'.

perform bdc_field       using 'BDC_CURSOR'

                               'KNVP-PARVW(01)'.

perform bdc_field       using 'BDC_OKCODE'

                               '=ENTR'.

*perform bdc_transaction using 'XD01'.

call transaction 'XD01' using bdcdata mode w_mode UPDATE 'A' MESSAGES INTO IT_MESSAGES.

*perform close_group.

ENDLOOP.

CALL FUNCTION 'FORMAT_MESSAGE'

  EXPORTING

    ID              = SY-MSGID

    LANG            = '-D'

    NO              = SY-MSGNO

    V1              = SY-MSGV1

    V2              = SY-MSGV2

    V3              = SY-MSGV3

    V4              = SY-MSGV4

  IMPORTING

    MSG             = V_MESG

  EXCEPTIONS

    NOT_FOUND       = 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.

  LOOP AT IT_MESSAGES WHERE MSGTYP = 'E'.

     WRITE : / 'Message :'(I06) ,V_MESG.

     CLEAR IT_MESSAGES.

   ENDLOOP.

**

ENDFUNCTION.

*INCLUDE BDCRECXY.

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

*        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.

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

Read only

0 Likes
2,307

Is this the code after the changes you have made as suggested by Raymond?

Is  it still showing the same error?

Read only

Former Member
0 Likes
2,307

hello.

In your function code, where you have the perfom BDC_FIELD USING FNAM FVAL, double clic on the name (BDC_FIELD) and create it in another include, not in the same code of the function.

First, comment or delete the form and endform of BDC_FIELD.

Regads

Miguel

Read only

Former Member
0 Likes
2,307

SHDB will create the program for you, it will have everything properly structured. That will not raise any error.

Click the program button on SHDB after recording, and give the program name.

Now if you want this program within another program,

1. copy the program and include it in a subroutine of the main program. (between form and endform statements) and call it using perform statement.

2. Or call the BDC program using SUBMIT program.

The first option would be better considering you wont have to pass the parameters.

Read only

0 Likes
2,307

I want to create a function module for bdc.

Read only

Former Member
0 Likes
2,307

Hi Rohan,

Please declare :

bdcdata        LIKE bdcdata    OCCURS 0 WITH HEADER LINE.

and the above code in a separate INCLUDE.

Regards,

Sowmya

Read only

0 Likes
2,307

YES i have declare

bdcdata like bdcdata occurs 0 with header line.

in which include should i write the program in fm

Read only

Pratik_Ingawale
Participant
0 Likes
2,307

thanks all of you for your help...