Application Development 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: 

BDC program in Foreground and Background

manoj_goyal2
Participant
0 Kudos

Hi,

I have a requirement from client to write a BDC program which can upload the data in TABLES in foreground and background. There will be a flag for FOREGROUND on the screen, if user clicks the FOREGROUND FLAG then data should be uploaded in foreground and if flag is blank than should be in background. What statements should I used to accomplish this logic in a BDC program.

Thanks.

minisap

3 REPLIES 3

Former Member
0 Kudos

Hello,

Check this sample.


SELECTION-SCREEN BEGIN OF BLOCK BLCK1 WITH FRAME TITLE TEXT-002.
PARAMETERS: FILENAME LIKE EPSF-EPSDIRNAM
            DEFAULT '\\FS000P01\D48\ANSKA\SAP_R3_ANSKA_FILES.TXT'.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN ULINE.
PARAMETERS: AP RADIOBUTTON GROUP GRP1,
            PC RADIOBUTTON GROUP GRP1.
SELECTION-SCREEN END OF BLOCK BLCK1.

START-OF-SELECTION.
  IF NOT AP IS INITIAL.
    
    PERFORM UPLOAD_APPLICATION_SERVER TABLES IT_FILE
                                      USING  FILENAME
                                    CHANGING RC.
  ENDIF.
  IF NOT PC IS INITIAL.
    PERFORM UPLOAD_WORKSTATION TABLES IT_FILE
                               USING  FILENAME
                             CHANGING RC.
  ENDIF.

FORM UPLOAD_APPLICATION_SERVER TABLES   P_ITAB_DATA STRUCTURE IT_FILE
                               USING    P_FILENAME
                               CHANGING P_RC.
  CHECK P_RC IS INITIAL.
  OPEN DATASET P_FILENAME FOR INPUT IN TEXT MODE.
  IF SY-SUBRC = 0.
    DO.
      READ DATASET P_FILENAME INTO P_ITAB_DATA.
      IF SY-SUBRC <> 0.
        EXIT.
      ENDIF.
      APPEND P_ITAB_DATA.
    ENDDO.
    CLOSE DATASET P_FILENAME.
    P_RC = 0.
  ELSE.
    P_RC = 4.
  ENDIF.


ENDFORM.                    " upload_application_server

FORM UPLOAD_WORKSTATION TABLES   P_ITAB_DATA STRUCTURE IT_FILE
                        USING    P_FILENAME
                        CHANGING P_RC.

  DATA: FILENAME LIKE  RLGRAP-FILENAME.

  FILENAME = P_FILENAME.
  CLEAR P_RC.

  CALL FUNCTION 'WS_UPLOAD'
    EXPORTING
*   CODEPAGE                      = ' '
      FILENAME                      = FILENAME
      FILETYPE                      = 'ASC'
*   HEADLEN                       = ' '
*   LINE_EXIT                     = ' '
*   TRUNCLEN                      = ' '
*   USER_FORM                     = ' '
*   USER_PROG                     = ' '
*   DAT_D_FORMAT                  = ' '
* IMPORTING
*   FILELENGTH                    =
    TABLES
      DATA_TAB                      = P_ITAB_DATA
    EXCEPTIONS
      CONVERSION_ERROR              = 1
      FILE_OPEN_ERROR               = 2
      FILE_READ_ERROR               = 3
      INVALID_TYPE                  = 4
      NO_BATCH                      = 5
      UNKNOWN_ERROR                 = 6
      INVALID_TABLE_WIDTH           = 7
      GUI_REFUSE_FILETRANSFER       = 8
      CUSTOMER_ERROR                = 9
      OTHERS                        = 10
            .
  IF SY-SUBRC <> 0.
    P_RC = SY-SUBRC.
  ENDIF.


ENDFORM.                    " upload_workstation

Hope this will solve ur issue.

Cheers,

Vasanth

0 Kudos

Thanks Vasanth M for your code. I know how to upload the data in the internal table. My problem is to how to put logic to upload the data from internal tableto SAP tables in foreground and background.

Former Member
0 Kudos

For foreground, you can use CALL TRANSACTION and for background, you can use the session method.

Rob