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

Validation for BDC program

Former Member
0 Likes
1,074

hi,

In BDC programe I have to check (or) validate the file path at selection screen events .

  • if the selected file is wrong error message should be triggered. how i can do this.

with regards,

Srinath

4 REPLIES 4
Read only

Former Member
0 Likes
730

Hi,

anyway u will call the functuon module to upload the file in the program..there at the end

of function module just write like this....

if sy-subrc NE 0.

message 'File Not Found' type 'S' display like 'E'.

endif.

Regards

Kiran

Edited by: Kiran Saka on Feb 9, 2009 12:33 PM

Read only

Former Member
0 Likes
730

If you are uploading the file from application server, use open dataset statment and if it returns sy-subrc 0, then the file exists.

Otherwise if you are uploading the file from front end, use the method FILE_EXIST of class cl_gui_frontend_service to check if the file exists.

Do this at the event AT SELECTION-SCREEN ON parameter_name

regards,

Advait

Edited by: Advait Gode on Feb 9, 2009 12:21 PM

Read only

Former Member
0 Likes
730

Hello Reddy,

In the following example,

purchase order fields are taken in through a text-file, if the fields do not match the fields of internal table, then just throw an error in GUI_UPLOAD saying , 'FILE CANNOT BE UPLOADED' or say 'UPLOADING FAILED'.


*---------------------------------------------------------------------*
* STRUCTURE FOR PURCHASE ORDER TABLE                                  *
*---------------------------------------------------------------------*
TYPES:
  BEGIN OF type_s_mat,
    eeind TYPE rm06b-eeind,            " Delivery Date
    txz01 TYPE eban-txz01,             " Short Text
    menge TYPE eban-menge,             " Quantity
    meins TYPE eban-meins,             " Units
    preis TYPE eban-preis,             " Price
  END OF type_s_mat.                   " BEGIN OF TYPE_S_MAT

*---------------------------------------------------------------------*
* FIELD STRING FOR PURCHASE ORDER TABLE                               *
*---------------------------------------------------------------------*
DATA:
  fs_mat TYPE type_s_mat.

*---------------------------------------------------------------------*
* INTERNAL TABLE FOR PURCHASE ORDER TABLE                             *
*---------------------------------------------------------------------*
DATA:
     t_mat LIKE
  STANDARD TABLE
        OF fs_mat.

*---------------------------------------------------------------------*
* INTERNAL TABLE FOR BATCH DATA TRANSFER                              *
*---------------------------------------------------------------------*
DATA:
     t_bdc TYPE
  STANDARD TABLE
        OF bdcdata
      WITH HEADER LINE.

*---------------------------------------------------------------------*
* INTERNAL TABLE FOR MESSAGES                                         *
*---------------------------------------------------------------------*
DATA:
t_messages TYPE
  STANDARD TABLE
        OF bdcmsgcoll
      WITH HEADER LINE.

*---------------------------------------------------------------------*
* Work Variables                                                      *
*---------------------------------------------------------------------*
DATA:
  w_filename TYPE rlgrap-filename,     " Selected File-Name
  w_msg(72) TYPE c,                    " Messages
  w_filename1 TYPE string.             " Full-Path

*---------------------------------------------------------------------*
*      INITIALIZATION                                                 *
*---------------------------------------------------------------------*
INITIALIZATION.
  PARAMETERS p_file(128).              " Name of File to be opened

*---------------------------------------------------------------------*
*      AT SELECTION-SCREEN ON VALUE-REQUEST                           *
*---------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
  PERFORM open_mat_file.
  p_file = w_filename.

*---------------------------------------------------------------------*
*      START-OF-SELECTION                                             *
*---------------------------------------------------------------------*
START-OF-SELECTION.
  IF p_file IS INITIAL.
    MESSAGE 'No File Selected' TYPE 'S' DISPLAY LIKE 'E'.
  ELSE.
    PERFORM open_file.
  ENDIF.                               " IF P_FILE IS INITIAL

*&---------------------------------------------------------------------*
*&      Form  open_mat_file
*&---------------------------------------------------------------------*
* This Subroutine opens Material File of the Presentation Server.
*----------------------------------------------------------------------*
* This Subroutine has got no Interface Parameters.
*----------------------------------------------------------------------*
FORM open_mat_file .
  CALL FUNCTION 'F4_FILENAME'
* EXPORTING
*   PROGRAM_NAME        = SYST-CPROG
*   DYNPRO_NUMBER       = SYST-DYNNR
*   FIELD_NAME          = ' '
   IMPORTING
     file_name          = w_filename.
ENDFORM.                               " FORM OPEN_MAT_FILE

*&---------------------------------------------------------------------*
*&      Form  open_file
*&---------------------------------------------------------------------*
* This Subroutine facilitates file upload on Presentation Server.
*----------------------------------------------------------------------*
* This Subroutine has got no Interface Parameters.
*----------------------------------------------------------------------*
FORM open_file .
  w_filename1 = w_filename.
  CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
     filename                      =  w_filename1
     filetype                      = 'ASC'
*     has_field_separator           = ' '
*    HEADER_LENGTH                 = 0
*    READ_BY_LINE                  = 'X'
*    DAT_MODE                      = ' '
*    CODEPAGE                      = ' '
*    IGNORE_CERR                   = ABAP_TRUE
*    REPLACEMENT                   = '#'
*  IMPORTING
*    FILELENGTH                    =
*    HEADER                        =
    TABLES
      data_tab                     = t_mat
   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 'Uploading Failed'  TYPE 'S' DISPLAY LIKE 'E'.
  ELSE.
    PERFORM populating_bdc.
  ENDIF.                               " IF SY-SUBRC NE 0
ENDFORM.                               " FORM OPEN_FILE

*&---------------------------------------------------------------------*
*&      Form  populating_bdc
*&---------------------------------------------------------------------*
* This Subroutine Populates data in Transaction ME51
*----------------------------------------------------------------------*
* This Subroutine has got no Interface Parameters.
*----------------------------------------------------------------------*
FORM populating_bdc .
  LOOP AT t_mat INTO fs_mat.
    PERFORM screens USING 'SAPMM06B' '0100'.
    PERFORM fields USING 'EBAN-BSART' 'NB'.
    PERFORM fields USING 'EBAN-KNTTP' 'X'.
    PERFORM fields USING 'RM06B-LPEIN' 'T'.
    PERFORM fields USING 'RM06B-EEIND' fs_mat-eeind.
    PERFORM fields USING 'EBAN-WERKS' '1000'.
    PERFORM fields USING 'EBAN-EKGRP' '100'.
    PERFORM fields USING 'EBAN-MATKL' '006'.
    PERFORM fields USING 'BDC_OKCODE' '/00'.

    PERFORM screens USING 'SAPMM06B' '0106'.
    PERFORM fields USING 'EBAN-TXZ01' fs_mat-txz01.
    PERFORM fields USING 'EBAN-MENGE' fs_mat-menge.
    PERFORM fields USING 'EBAN-MEINS' fs_mat-meins.
    PERFORM fields USING 'BDC_OKCODE' '/00'.

    PERFORM screens USING 'SAPMM06B' '0102'.
    PERFORM fields USING 'EBAN-PREIS' fs_mat-preis.
    PERFORM fields USING 'BDC_OKCODE' '/00'.

    PERFORM screens USING 'SAPMM06B' '0505'.
    PERFORM fields USING 'COBL-KOSTL' '1000'.
    PERFORM fields USING 'BDC_OKCODE' '/00'.

    PERFORM screens USING 'SAPMM06B' '0106'.
    PERFORM fields USING 'BDC_OKCODE' 'BU'.

    CALL TRANSACTION 'ME51' USING t_bdc MODE 'A' MESSAGES INTO
    t_messages.
    IF sy-subrc EQ 0.
      LOOP AT t_messages.
        CALL FUNCTION 'FORMAT_MESSAGE'
          EXPORTING
            id        = t_messages-msgid
            lang      = sy-langu
            no        = t_messages-msgnr
            v1        = t_messages-msgv1
            v2        = t_messages-msgv2
            v3        = t_messages-msgv3
            v4        = t_messages-msgv4
          IMPORTING
            msg       = w_msg
          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.
        ELSE.
          WRITE:/ w_msg.
        ENDIF.                         " IF SY-SUBRC <> 0
      ENDLOOP.                         " LOOP AT T_MAT INTO FS_MAT
    ENDIF.                             " IF SY-SUBRC EQ 0
  ENDLOOP.                             " LOOP T_MAT INTO FS_MAT
ENDFORM.                               " FORM POPULATING_BDC

*&---------------------------------------------------------------------*
*&      Form  screens
*&---------------------------------------------------------------------*
* This Subroutine populates program name and screen numbers.
*----------------------------------------------------------------------*
*      -->VALUE(P_PROG)   PROGRAM NAME
*      -->VALUE(P_SCRNO)  SCREEN NUMBER
*----------------------------------------------------------------------*
FORM screens USING value(p_prog) value(p_scrno).
  t_bdc-program = p_prog.
  t_bdc-dynpro = p_scrno.
  t_bdc-dynbegin = 'X'.
  APPEND t_bdc.
ENDFORM.                               " FORM SCREENS

*&---------------------------------------------------------------------*
*&      Form  fields
*&---------------------------------------------------------------------*
* This Subroutine populates Field Value and Field name
*----------------------------------------------------------------------*
*      -->VALUE(P_FNAM)  Field Name
*      -->VALUE(P_FVAL)  Field Value
*----------------------------------------------------------------------*
FORM fields USING value(p_fnam) value(p_fval).
  t_bdc-fnam = p_fnam.
  t_bdc-fval = p_fval.
  APPEND t_bdc.
ENDFORM.                               " FORM FIELDS

Hope the above given example, helps you.

Thanks: Zahackson

Read only

Former Member
0 Likes
730

Hi srinath,

AT SELECTION-SCREEN ON  p_file.

call function 'f4_filename'
.....
if sy-subrc <> 0.
  message 'Error in File' type 'E'.
endif.

Regards,

Sravanthi