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

Unable to exit the loop.

Former Member
0 Likes
773

Hello experts,

I am able to use the following code to update email IDs from flat file to xk02 for the corresponding vendors. But once the records are over, the loop does not exit. It still remains on the xk02 screen and asks for vendor id while there are no more records in the flat file. Please let me know how to exit the loop.Also if I want all the records in the flat file to be entered directly at one go, instead of pressing ENTER for all the records, what should I do ? I've attached a sample flat file for ref.

*Source internal table (when text file)

data : begin of itab occurs 1,

       f1 type RF02K-lifnr,

       f2 type LFA1-lfurl,

       end of itab.

*source internal table (when excel)

*DATA: ITAB TYPE STANDARD TABLE OF ALSMEX_TABLINE WITH HEADER LINE.

*target internal table

data : bdcdata type bdcdata occurs 1 with header line.

 

*Fields for Selection screen F4 input

DATA : V_FILE TYPE STRING.

 

*Selection screen

SELECTION-SCREEN BEGIN OF BLOCK blck WITH FRAME TITLE text-011.

PARAMETERS : p_file TYPE RLGRAP-FILENAME.

SELECTION-SCREEN END OF BLOCK blck.

*Code for F4 help

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

CALL FUNCTION 'F4_FILENAME'

       EXPORTING

         program_name  = syst-cprog

         dynpro_number = syst-dynnr

*       field_name    =  p_file

       IMPORTING

         file_name     = p_file.

start-of-selection.

  v_file = p_file.

*Upload data from text file.

  CALL FUNCTION 'GUI_UPLOAD'

    EXPORTING

      FILENAME            = v_file

      FILETYPE            = 'ASC'

      HAS_FIELD_SEPARATOR = 'X'

    TABLES

      DATA_TAB            = itab.

     

loop at itab.

refresh bdcdata.

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

    perform bdc_dynpro      using 'SAPMF02K' '0101'.

    perform bdc_field       using 'BDC_CURSOR'

                                  'USE_ZAV'.

    perform bdc_field       using 'BDC_OKCODE'

                                  '/00'.

    perform bdc_field       using 'RF02K-LIFNR'

                                   itab-f1.

    perform bdc_field       using 'RF02K-BUKRS'

                                  'seml'.

    perform bdc_field       using 'RF02K-EKORG'

                                  'sepo'.

    perform bdc_field       using 'RF02K-D0110'

                                  'X'.

    perform bdc_field       using 'USE_ZAV'

                                  'X'.

    perform bdc_dynpro      using 'SAPMF02K' '0111'.

    perform bdc_field       using 'BDC_OKCODE'

                                  '=UPDA'.

    perform bdc_field       using 'BDC_CURSOR'

                                  'SZA1_D0100-SMTP_ADDR'.

    perform bdc_field       using 'SZA1_D0100-SMTP_ADDR'

                                   itab-f2.

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

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

***PUSH DATA

CALL TRANSACTION 'XK02' USING BDCDATA MODE 'A'.

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

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

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

*        Insert field                                                *

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

FORM BDC_FIELD USING FNAM FVAL.

  IF FVAL <> SPACE.

    CLEAR BDCDATA.

    BDCDATA-FNAM = FNAM.

    BDCDATA-FVAL = FVAL.

    APPEND BDCDATA.

  ENDIF.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
721

Hi satya prakash,

please use 'N' instead of 'A' in call transaction and check the program.

CALL TRANSACTION 'XK02' USING BDCDATA MODE 'N'.

Regards,

Karthik

4 REPLIES 4
Read only

Former Member
0 Likes
722

Hi satya prakash,

please use 'N' instead of 'A' in call transaction and check the program.

CALL TRANSACTION 'XK02' USING BDCDATA MODE 'N'.

Regards,

Karthik

Read only

0 Likes
721

Karthik,

Thaks a lot. It helped me out. I've included a small if-else loop at the end of my prog :

  IF sy-subrc <> 0.

*    Error Found

    WRITE : / 'DATA Not INSERTED'.

  ELSE.

    WRITE : / 'DATA INSERTED'.

    exit.

  ENDIF .

This is showing 'DATA INSERTED' after all the records are updated.Can you please help me how to keep an exit button on my end screen after all the records are updated.

Regards,
Satya Prakash

Read only

laurent_fournier2
Contributor
0 Likes
721

Your file has many empty lines. Try deleting the empty lines before starting the BI process.

Delete : itab where f2 is initial.

Regards.

Read only

0 Likes
721

Hi Laurent,

Thanks a lot for that info. Now I've included a small if-else loop at the end of my prog :

  IF sy-subrc <> 0.

*    Error Found

    WRITE : / 'DATA Not INSERTED'.

  ELSE.

    WRITE : / 'DATA INSERTED'.

    exit.

  ENDIF .

This is showing 'DATA INSERTED' after all the records are updated.Can you please help me how to keep an exit button on my end screen after all the records are updated.

Regards,
Satya Prakash