Skip to Content
author's profile photo Former Member
Former Member

Not entering into the loop

Hi Friends,

I have written a BDC program to upload salesorder data. But it is not entering into

<b>LOOP AT ITAB and ENDLOOP.</b>

Can anyone correct the following code.

REPORT SAMPLE NO STANDARD PAGE HEADING.

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

  • TABLES ***********************************************

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

TABLES : VBAK, "Sales doc header data

VBAP, "Sales doc item data

VBKD. "Sales doc business data

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

  • INTERNAL TABLE DECLERATION ************************

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

data : begin of itab occurs 0,

VBELN LIKE VBAK-VBELN, "Sales docu no

AUART LIKE VBAK-AUART, "sales doc type

VKORG LIKE VBAK-VKORG, "sales organization

VTWEG LIKE VBAK-VTWEG, "dist channel

SPART LIKE VBAK-SPART, "division

VKGRP LIKE VBAK-VKGRP, "sales group

VKBUR LIKE VBAK-VKBUR, "sales office

KUNNR LIKE VBAK-KUNNR, "customer no

AUDAT LIKE VBAK-AUDAT, "document date

WAERK LIKE VBAK-WAERK, "SD doc currency

POSNR LIKE VBAP-POSNR, "Sales doc item no

PSTYV LIKE VBAP-PSTYV, "Sales doc item category

WERKS LIKE VBAP-WERKS, "Plant

MATNR LIKE VBAP-MATNR, "Material No

BSTKD LIKE VBKD-BSTKD, "Customer po number

BSTDK LIKE VBKD-BSTDK, "Customer PO date

PRSDT LIKE VBKD-PRSDT, "Date for pricing and exchange rate

ZTERM LIKE VBKD-ZTERM, "Terms of payment key

INCO1 LIKE VBKD-INCO1, "incoterms (part1)

INCO2 LIKE VBKD-INCO2, "incoterms (part2)

end of itab.

data : i_bdcdata like bdcdata occurs 0 with header line.

data : v_date(8).

parameters : p_file like rlgrap-filename default 'C:\TEXT.TXT'.

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

  • START OF SELECTION **********************************

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

START-OF-SELECTION.

CALL FUNCTION 'UPLOAD'

EXPORTING

  • CODEPAGE = ' '

FILENAME = p_file

FILETYPE = 'DAT'

  • ITEM = ' '

  • FILEMASK_MASK = ' '

  • FILEMASK_TEXT = ' '

  • FILETYPE_NO_CHANGE = ' '

  • FILEMASK_ALL = ' '

  • FILETYPE_NO_SHOW = ' '

  • LINE_EXIT = ' '

  • USER_FORM = ' '

  • USER_PROG = ' '

  • SILENT = 'S'

  • IMPORTING

  • FILESIZE =

  • CANCEL =

  • ACT_FILENAME =

  • ACT_FILETYPE =

TABLES

DATA_TAB = itab.

  • EXCEPTIONS

  • CONVERSION_ERROR = 1

  • INVALID_TABLE_WIDTH = 2

  • INVALID_TYPE = 3

  • NO_BATCH = 4

  • UNKNOWN_ERROR = 5

  • GUI_REFUSE_FILETRANSFER = 6

  • OTHERS = 7

.

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

concatenate itab-bstdk4(2) itab-bstdk6(2) itab-bstdk(4) into v_date.

refresh i_bdcdata.

move v_date to itab-bstdk.

perform mybdcdata.

CALL TRANSACTION 'VA01' using i_bdcdata MODE 'A' .

endloop.

&----


*& Form mybdcdata

&----


  • text

----


form mybdcdata.

perform mydata using : 'X' 'SAPMV45A' '0101',

'' 'VBAK-AUART' itab-auart,

'' 'VBAK-VKORG' itab-vkorg,

'' 'VBAK-VTWEG' itab-vtweg,

'' 'VBAK-SPART' itab-spart,

'' 'VBAK-VKBUR' itab-vkbur,

'' 'VBAK-VKGRP' itab-vkgrp,

'' 'BDC_OKCODE' '/00',

'X' 'SAPMV45A' '4001',

'' 'VBKD-BSTKD' itab-bstkd,

'' 'VBKD-BSTDK' itab-bstdk,

'' 'KUAGV-KUNNR' itab-kunnr,

'' 'BDC_OKCODE' 'T\02',

'X' 'SAPMV45A' '4001',

'' 'VBAP-POSNR' itab-posnr,

'' 'VBAP-PSTYV' itab-pstyv,

'' 'VBAP-MATNR' itab-matnr,

'' 'BDC_OKCODE' 'T\04',

'X' 'SAPMV45A' '4002',

'' 'VBKD-ZTERM' itab-zterm,

'' 'VBKD-INCO1' itab-inco1,

'' 'VBKD-INCO2' itab-inco2,

'' 'BDC_OKCODE' 'T\02',

'X' 'SAPMV45A' '4002',

'' 'VBAK-AUDAT' itab-audat,

'' 'VBAK-WAERK' itab-waerk,

'' 'VBKD-PRSDT' itab-prsdt.

  • '' 'BDC_OKCODE' 'T\07'.

endform. "mybdcdata

&----


*& Form mydata

&----


  • text

----


  • -->A1 text

  • -->A2 text

  • -->A3 text

----


form mydata using a1 a2 a3.

if a1 = 'X'.

clear i_bdcdata.

i_bdcdata-dynbegin = a1.

i_bdcdata-program = a2.

i_bdcdata-dynpro = a3.

append i_bdcdata.

else.

clear i_bdcdata.

i_bdcdata-fnam = a2.

i_bdcdata-fval = a3.

append i_bdcdata.

endif.

endform. "mydata

waiting for ur reply...

Thanks

Raj

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Mar 05, 2007 at 09:51 PM

    Hi,

    Did you check if the file exits ..

    Also uncomment the exceptions part of the function module..So that you can find what exactly is the problem..

    TABLES

    DATA_TAB = itab.

    EXCEPTIONS

    CONVERSION_ERROR = 1

    INVALID_TABLE_WIDTH = 2

    INVALID_TYPE = 3

    NO_BATCH = 4

    UNKNOWN_ERROR = 5

    GUI_REFUSE_FILETRANSFER = 6

    OTHERS = 7

    IF SY-SUBRC <> 0.

    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

    ENDIF.

    Thanks,

    Naren

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Mar 06, 2007 at 05:22 PM

    Hi Rajkumar,

    Try this code i have changed in between.

    just cheking itab wether itab contains records or not.

    if itab has no records check ur flat file.

    REPORT SAMPLE NO STANDARD PAGE HEADING.

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

                                • TABLES ***********************************************

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

                                TABLES : VBAK, "Sales doc header data

                                VBAP, "Sales doc item data

                                VBKD. "Sales doc business data

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

                                                                    • INTERNAL TABLE DECLERATION ************************

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

                                                                    data : begin of itab occurs 0,

                                                                    VBELN LIKE VBAK-VBELN, "Sales docu no

                                                                    AUART LIKE VBAK-AUART, "sales doc type

                                                                    VKORG LIKE VBAK-VKORG, "sales organization

                                                                    VTWEG LIKE VBAK-VTWEG, "dist channel

                                                                    SPART LIKE VBAK-SPART, "division

                                                                    VKGRP LIKE VBAK-VKGRP, "sales group

                                                                    VKBUR LIKE VBAK-VKBUR, "sales office

                                                                    KUNNR LIKE VBAK-KUNNR, "customer no

                                                                    AUDAT LIKE VBAK-AUDAT, "document date

                                                                    WAERK LIKE VBAK-WAERK, "SD doc currency

                                                                    POSNR LIKE VBAP-POSNR, "Sales doc item no

                                                                    PSTYV LIKE VBAP-PSTYV, "Sales doc item category

                                                                    WERKS LIKE VBAP-WERKS, "Plant

                                                                    MATNR LIKE VBAP-MATNR, "Material No

                                                                    BSTKD LIKE VBKD-BSTKD, "Customer po number

                                                                    BSTDK LIKE VBKD-BSTDK, "Customer PO date

                                                                    PRSDT LIKE VBKD-PRSDT, "Date for pricing and exchange rate

                                                                    ZTERM LIKE VBKD-ZTERM, "Terms of payment key

                                                                    INCO1 LIKE VBKD-INCO1, "incoterms (part1)

                                                                    INCO2 LIKE VBKD-INCO2, "incoterms (part2)

                                                                    end of itab.

                                                                    data : i_bdcdata like bdcdata occurs 0 with header line.

                                                                    data : v_date(8).

                                                                    parameters : p_file like rlgrap-filename default 'C:\TEXT.TXT'.

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

                                                                                                      • START OF SELECTION **********************************

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

                                                                                                      START-OF-SELECTION.

                                                                                                      <b>perform upload_data.

                                                                                                      if not itab[ ] is initial .

                                                                                                      perform bdc_populate.</b>

                                                                                                      <b>else.

                                                                                                      write :/ ' no records in itab '.

                                                                                                      endif.</b>

                                                                                                      <b>form upload_data.</b>

                                                                                                      CALL FUNCTION 'UPLOAD'

                                                                                                      EXPORTING

                                                                                                      • CODEPAGE = ' '

                                                                                                      FILENAME = p_file

                                                                                                      FILETYPE = 'DAT'

                                                                                                      • ITEM = ' '

                                                                                                      • FILEMASK_MASK = ' '

                                                                                                      • FILEMASK_TEXT = ' '

                                                                                                      • FILETYPE_NO_CHANGE = ' '

                                                                                                      • FILEMASK_ALL = ' '

                                                                                                      • FILETYPE_NO_SHOW = ' '

                                                                                                      • LINE_EXIT = ' '

                                                                                                      • USER_FORM = ' '

                                                                                                      • USER_PROG = ' '

                                                                                                      • SILENT = 'S'

                                                                                                      • IMPORTING

                                                                                                      • FILESIZE =

                                                                                                      • CANCEL =

                                                                                                      • ACT_FILENAME =

                                                                                                      • ACT_FILETYPE =

                                                                                                      TABLES

                                                                                                      DATA_TAB = itab.

                                                                                                      • EXCEPTIONS

                                                                                                      • CONVERSION_ERROR = 1

                                                                                                      • INVALID_TABLE_WIDTH = 2

                                                                                                      • INVALID_TYPE = 3

                                                                                                      • NO_BATCH = 4

                                                                                                      • UNKNOWN_ERROR = 5

                                                                                                      • GUI_REFUSE_FILETRANSFER = 6

                                                                                                      • OTHERS = 7

                                                                                                      .

                                                                                                      IF SY-SUBRC <> 0.

                                                                                                      • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

                                                                                                      • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

                                                                                                      ENDIF.

                                                                                                      <b>endform.</b>

                                                                                                      form bdc_populate.

                                                                                                      loop at itab.

                                                                                                      concatenate itab-bstdk4(2) itab-bstdk6(2) itab-bstdk(4) into v_date.

                                                                                                      refresh i_bdcdata.

                                                                                                      move v_date to itab-bstdk.

                                                                                                      perform mybdcdata.

                                                                                                      CALL TRANSACTION 'VA01' using i_bdcdata MODE 'A' .

                                                                                                      endloop.

                                                                                                      <b>endform.</b>

                                                                                                      &----


                                                                                                      *& Form mybdcdata

                                                                                                      &----


                                                                                                      • text

                                                                                                      ----


                                                                                                      form mybdcdata.

                                                                                                      perform mydata using : 'X' 'SAPMV45A' '0101',

                                                                                                      '' 'VBAK-AUART' itab-auart,

                                                                                                      '' 'VBAK-VKORG' itab-vkorg,

                                                                                                      '' 'VBAK-VTWEG' itab-vtweg,

                                                                                                      '' 'VBAK-SPART' itab-spart,

                                                                                                      '' 'VBAK-VKBUR' itab-vkbur,

                                                                                                      '' 'VBAK-VKGRP' itab-vkgrp,

                                                                                                      '' 'BDC_OKCODE' '/00',

                                                                                                      'X' 'SAPMV45A' '4001',

                                                                                                      '' 'VBKD-BSTKD' itab-bstkd,

                                                                                                      '' 'VBKD-BSTDK' itab-bstdk,

                                                                                                      '' 'KUAGV-KUNNR' itab-kunnr,

                                                                                                      '' 'BDC_OKCODE' 'T\02',

                                                                                                      'X' 'SAPMV45A' '4001',

                                                                                                      '' 'VBAP-POSNR' itab-posnr,

                                                                                                      '' 'VBAP-PSTYV' itab-pstyv,

                                                                                                      '' 'VBAP-MATNR' itab-matnr,

                                                                                                      '' 'BDC_OKCODE' 'T\04',

                                                                                                      'X' 'SAPMV45A' '4002',

                                                                                                      '' 'VBKD-ZTERM' itab-zterm,

                                                                                                      '' 'VBKD-INCO1' itab-inco1,

                                                                                                      '' 'VBKD-INCO2' itab-inco2,

                                                                                                      '' 'BDC_OKCODE' 'T\02',

                                                                                                      'X' 'SAPMV45A' '4002',

                                                                                                      '' 'VBAK-AUDAT' itab-audat,

                                                                                                      '' 'VBAK-WAERK' itab-waerk,

                                                                                                      '' 'VBKD-PRSDT' itab-prsdt.

                                                                                                      • '' 'BDC_OKCODE' 'T\07'.

                                                                                                      endform. "mybdcdata

                                                                                                      &----


                                                                                                      *& Form mydata

                                                                                                      &----


                                                                                                      • text

                                                                                                      ----


                                                                                                      • -->A1 text

                                                                                                      • -->A2 text

                                                                                                      • -->A3 text

                                                                                                      ----


                                                                                                      form mydata using a1 a2 a3.

                                                                                                      if a1 = 'X'.

                                                                                                      clear i_bdcdata.

                                                                                                      i_bdcdata-dynbegin = a1.

                                                                                                      i_bdcdata-program = a2.

                                                                                                      i_bdcdata-dynpro = a3.

                                                                                                      append i_bdcdata.

                                                                                                      else.

                                                                                                      clear i_bdcdata.

                                                                                                      i_bdcdata-fnam = a2.

                                                                                                      i_bdcdata-fval = a3.

                                                                                                      append i_bdcdata.

                                                                                                      endif.

                                                                                                      endform. "mydata

                                                                                                      Regards.

                                                                                                      Francis.

                                                                                                      Add a comment
                                                                                                      10|10000 characters needed characters exceeded

                                                                                                    Before answering

                                                                                                    You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
                                                                                                    You must be Logged in to submit an answer.

                                                                                                    Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.