Uploading Data From Excel into FB50

This is the sample coding for uploading the data from Excel into FB50.

REPORT  ZMFC_FB50.

TYPE-POOLS: TRUXS.

DATA : BEGIN OF ITAB  OCCURS 0,
        DOCDATE TYPE STRING,
        REF     LIKE ACGL_HEAD-XBLNR,
         TEXT    LIKE ACGL_HEAD-BKTXT,
        AMT     TYPE STRING,
        COSTCENTER LIKE ACGL_ITEM-KOSTL,
        GL1      LIKE ACGL_ITEM-HKONT,
        GL2     LIKE ACGL_ITEM-HKONT,
        VEND    LIKE ACGL_ITEM-HKONT,
        TEXT2   LIKE ACGL_ITEM-SGTXT, 
        TEXT3   LIKE ACGL_ITEM-SGTXT,
        DC(1)   TYPE C,
        AMT1    TYPE  STRING,
       END OF ITAB.
 

DATA:BDCDATA LIKE BDCDATA OCCURS  0 WITH HEADER LINE.

DATA: IT_RAW TYPE TRUXS_T_TEXT_DATA.  "work table for excel upload
 

*Selection Screen

SELECTION-SCREEN BEGIN OF  BLOCK BK1 WITH FRAME TITLE TEXT-100.
PARAMETERS: P_FILE  TYPE  RLGRAP-FILENAME.
SELECTION-SCREEN END OF BLOCK BK1.
 

* At selection screen to get the file name uploaded

AT SELECTION-SCREEN ON VALUE-REQUEST  FOR P_FILE.
  CALL FUNCTION 'F4_FILENAME'
    EXPORTING
      FIELD_NAME =  'P_FILE'
    IMPORTING
      FILE_NAME  = P_FILE.
 

START-OF-SELECTION.

**********Uploading excel data into internal table************ 

  CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
    EXPORTING
*     I_FIELD_SEPERATOR        = 
      I_LINE_HEADER            =  'X'
      I_TAB_RAW_DATA           =  IT_RAW       " WORK TABLE
      I_FILENAME               =  P_FILE 
    TABLES
      I_TAB_CONVERTED_DATA     =   ITAB     "ACTUAL DATA
   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.

  LOOP AT ITAB.

    IF ITAB-GL1 IS NOT  INITIAL AND ITAB-TEXT NE 'CASH'.
      REFRESH BDCDATA.
       CLEAR BDCDATA.

      PERFORM BDC_DYNPRO      USING 'SAPMF05A' '1001'.
       PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                    '=BU'.
       PERFORM BDC_FIELD       USING 'ACGL_HEAD-BLDAT'
                                    ITAB-DOCDATE.
*      PERFORM bdc_field       USING 'ACGL_HEAD-WAERS' 
*                                    'INR'.
      PERFORM BDC_FIELD       USING 'ACGL_HEAD-BUDAT' 
                                    ITAB-DOCDATE.
      PERFORM BDC_FIELD       USING 'ACGL_HEAD-XBLNR'
                                    ITAB- REF.
      PERFORM BDC_FIELD       USING 'ACGL_HEAD-BKTXT'
                                    ITAB- TEXT.
      PERFORM BDC_FIELD       USING 'ACGL_HEAD-BLART'
                                     'SA'.
*      PERFORM bdc_field       USING 'BDC_CURSOR'
*                                    'ACGL_ITEM-PRCTR(02)'.
       PERFORM BDC_FIELD       USING 'ACGL_ITEM-HKONT(01)'
                                    ITAB-GL1.
      IF ITAB-DC =  'D'.
        ITAB-DC = 'S'.
      ENDIF.
      IF ITAB-DC = 'C'.
        ITAB-DC =  'H'.
      ENDIF.

      PERFORM BDC_FIELD       USING 'ACGL_ITEM-SHKZG(01)' 
                                    ITAB-DC.
      PERFORM BDC_FIELD       USING 'ACGL_ITEM-WRBTR(01)'
                                ITAB-AMT. 
      PERFORM BDC_FIELD       USING 'ACGL_ITEM-MWSKZ(01)'
                                    'v0' .
      PERFORM BDC_FIELD       USING 'ACGL_ITEM-SGTXT(01)'
                                    ITAB-TEXT2.
       PERFORM BDC_FIELD       USING 'ACGL_ITEM-GSBER(01)'
                                    '3599'.
       PERFORM BDC_FIELD       USING 'ACGL_ITEM-PRCTR(01)'
                                    'MCL_WALAYA'.
       PERFORM BDC_FIELD       USING 'ACGL_ITEM-KOSTL(01)'
                                ITAB-COSTCENTER.
      PERFORM BDC_FIELD        USING 'ACGL_ITEM-HKONT(02)'
                                    '24500000'.
      IF ITAB-DC =  'S'.
        PERFORM BDC_FIELD       USING 'ACGL_ITEM-SHKZG(02)'
                                             'H'.
      ENDIF.
      IF ITAB-DC = 'H'.
        PERFORM BDC_FIELD        USING 'ACGL_ITEM-SHKZG(02)'
                                            'S'.
      ENDIF.
      PERFORM BDC_FIELD       USING 'ACGL_ITEM-WRBTR(02)'
                                    ITAB-AMT.
       PERFORM BDC_FIELD       USING 'ACGL_ITEM-GSBER(02)'
                                    '3599'.
       PERFORM BDC_FIELD       USING 'ACGL_ITEM-PRCTR(02)'
                                    'MCL_WALAYA'.
       CALL TRANSACTION 'FB50' USING BDCDATA MODE 'E'.
     ENDIF.
  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.

   CLEAR BDCDATA.
  BDCDATA-FNAM = FNAM.
  BDCDATA-FVAL = FVAL.
  APPEND BDCDATA.

ENDFORM.                    "BDC_FIELD 

ABAP

See Also:
BAPI Sample To Upload Data From Flat File To VA01

Tables
Database Table

ABAP Books List
ABAP/4 Certification, Programming, Smartforms, Sapscripts and Object Oriented Programming Books

Smart Forms
SAP Smartforms

ABAP Menu:
ABAP Example Hints and Tips

Return to Index:-
SAP ABAP/4 Programming, Basis Administration, Configuration Hints and Tips

(c) www.gotothings.com All material on this site is Copyright.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
All product names are trademarks of their respective companies.  The site www.gotothings.com is in no way affiliated with SAP AG.
Any unauthorised copying or mirroring is prohibited.