Home > Default > Adding Data to the database for SAP Transactions

Adding Data to the database for SAP Transactions

October 11Hits:1
Advertisement
Hi
I'm new to the whole ABAP. I would like to enquire about adding transaction data in SAP through ABAP but it must be immediate.
I know that one can use a BAPI to add data and can rollback if any problems occur.
But if no BAPI exists how does one write code to add a document to the SAP database but with everything SAP transaction requires like the BAPI. What is the process and how???
So let say I wanted to do FB01 which is SAP FI document and must be immediate. There is a BAPI that exists for it but if there was not one how would I do this???
I know one can also use BDC but that creates a batch and then needs to be executed in SM35, I want a way to add data for two or three SAP transactions, if any problems occur with any of the steps rollback everything else commit everything to the database.
Any simple detail examples (code) that satisfy the above will be greatly appreciated and REWARDED.
Thanks in advance

Answers

Luis,
i have a code exactly same BDC for FB01.
refer:
REPORT z_etching_fb01
       NO STANDARD PAGE HEADING LINE-SIZE 255.
*etching invoice load
INCLUDE bdcrecx1.
TYPE-POOLS: truxs , slis.
*PARAMETERS: dataset(132) LOWER CASE DEFAULT
*                              'c:\temp\etchingload.txt'.
PARAMETER: pfile LIKE rlgrap-filename." OBLIGATORY.
SELECTION-SCREEN BEGIN OF BLOCK a WITH FRAME TITLE text-001.
PARAMETER:    p_kunnr LIKE kna1-kunnr OBLIGATORY,           "kna1-kunnr
              p_bukrs LIKE bseg-bukrs,
              p_mwskz LIKE t007a-mwskz OBLIGATORY,"t007a-mwskz
              p_prctr LIKE cepc-prctr OBLIGATORY,"cepc-prctr
*            p_newko LIKE ska1-saknr OBLIGATORY DEFAULT 41000000,"
            p_budat LIKE bkpf-budat OBLIGATORY ,
            p_hkont LIKE bseg-hkont OBLIGATORY DEFAULT 41000000 ,
            p_waers TYPE waers OBLIGATORY DEFAULT 'GBP'."tcurr-waers
SELECTION-SCREEN END OF BLOCK a.
SELECTION-SCREEN BEGIN OF BLOCK b WITH FRAME TITLE text-002.
PARAMETER : report AS CHECKBOX DEFAULT 'X'.
SELECTION-SCREEN END OF BLOCK b.
***    DO NOT CHANGE - the generated data section - DO NOT CHANGE    ***
*   If it is nessesary to change the data section use the rules:
*   1.) Each definition of a field exists of two lines
*   2.) The first line shows exactly the comment
*       '* data element: ' followed with the data element
*       which describes the field.
*       If you don't have a data element use the
*       comment without a data element name
*   3.) The second line shows the fieldname of the
*       structure, the fieldname must consist of
*       a fieldname and optional the character '_' and
*       three numbers and the field length in brackets
*   4.) Each field must be type C.
*** Generated data section with specific formatting - DO NOT CHANGE  ***
*                          ALV                                           *
DATA: it_fieldcat     TYPE    slis_t_fieldcat_alv,
      wa_fieldcat     LIKE    LINE OF it_fieldcat,
      it_top_of_page  TYPE    slis_t_listheader,
      ls_layout       TYPE    slis_layout_alv,
      gt_events       TYPE    slis_t_event.
DATA: it_raw TYPE truxs_t_text_data.
DATA: BEGIN OF record,
* data element: BLDAT
        bldat_001(010),   "Invoice Date
* data element: BLART
        blart_002(002),   " Doc Type DR or DG if credit
* data element: BUKRS
        bukrs_003(004),   " Company Code
* data element: BUDAT
        budat_004(010),   "Posting Date
* data element: MONAT
        monat_005(002),   "period"
* data element: WAERS
        waers_006(005),   "Currency
* data element: XBLNR1
        xblnr_007(016),   "Invoice Number
* data element: BKTXT
        bktxt_008(025),   "PO number
* data element: SAEOBJART
        docid_009(010),
* data element: NEWBS
        newbs_010(002),   "posting Key
* data element: NEWKO
        newko_011(017),   "Customer number or GL account
* data element: WRBTR
        wrbtr_012(016),   "Amount
* data element: DZTERM
        zterm_013(004),
* data element: DZBD1T
        zbd1t_014(003),
* data element: DZFBDT
        zfbdt_015(010),
* data element: DZUONR
        zuonr_016(018),   "Invoice Number
* data element: SGTXT
        sgtxt_017(050),   " PO number
* data element: NEWBS
        newbs_018(002),
* data element: NEWKO
        newko_019(017),   "GL Account
* data element: WRBTR
        wrbtr_020(016),   "Amount
* data element: MWSKZ
        mwskz_021(002),   "Tax
* data element: DZUONR
        zuonr_022(018),   "Invoice Number
* data element: SGTXT
        sgtxt_023(050),   "PO Number
* data element: PRCTR
        prctr_024(010),   "Profit Center
* data element: WRBTR
        wrbtr_025(016),   " Amount
* data element: MWSKZ
        mwskz_026(002),   "Tax
* data element: DZUONR
        zuonr_027(018),   "Invoice Number
* data element: SGTXT
        sgtxt_028(050),   "PO Number
* data element: FMORE
        fmore_029(001),
* data element: PRCTR
        prctr_030(010),   "Pr Center
* data element: FWSTE
        fwste_01_031(016),
      END OF record.
DATA: BEGIN OF it_excel OCCURS 0,
* data element: XBLNR1
      xblnr_007(016),   "Invoice Number
* data element: BLDAT
      bldat_001(010),   "Invoice Date
* data element: WRBTR
      wrbtr_012(016),   "Amount
* data element: WRBTR
      wrbtr_025(016),   " Tax Amount
* data element: WRBTR
      wrbtr_020(016),   "Gross Amount
* data element: BLART
      blart_002(002),   " No of units
* data element: MONAT
      monat_005(002),   "No of units second test"
* data element: BKTXT
        bktxt_008(025),   "PO number
* data element: SGTXT
      sgtxt_017(050),   " PO number
* data element: BUKRS
      bukrs_003(004),   " Company Code
* data element: BUDAT
      budat_004(010),   "Posting Date
*        budat_004 TYPE string,   "Posting Date
* data element: WAERS
      waers_006(005),   "Currency*
* data element: NEWKO
      newko_011(017),   "Customer number or GL account
* data element : kunnr
      kunnr_019(010),   " customer
      mwskz(002),
     prctr(010),
      date(002),
      month(002),
** data element: BKTXT
*      bktxt_008(025),   "PO number
** data element: SAEOBJART
*      docid_009(010),
** data element: NEWBS
*      newbs_010(002),   "posting Key
** data element: DZTERM
*      zterm_013(004),
** data element: DZBD1T
*      zbd1t_014(003),
** data element: DZFBDT
*      zfbdt_015(010),
** data element: DZUONR
*      zuonr_016(018),   "Invoice Number
** data element: NEWBS
*      newbs_018(002),
** data element: NEWKO
*      newko_019(017),   "GL Account
** data element: MWSKZ
*      mwskz_021(002),   "Tax
** data element: DZUONR
*      zuonr_022(018),   "Invoice Number
** data element: SGTXT
*      sgtxt_023(050),   "PO Number
** data element: PRCTR
*      prctr_024(010),   "Profit Center
** data element: MWSKZ
*      mwskz_026(002),   "Tax
** data element: DZUONR
*      zuonr_027(018),   "Invoice Number
** data element: SGTXT
*      sgtxt_028(050),   "PO Number
** data element: FMORE
*      fmore_029(001),
** data element: PRCTR
*      prctr_030(010),   "Pr Center
** data element: FWSTE
*      fwste_01_031(016),
    END OF it_excel.
DATA : BEGIN OF it_bkpf OCCURS 0,
        belnr LIKE bkpf-belnr,
        budat LIKE bkpf-budat,
        bldat LIKE bkpf-bldat,
        xblnr LIKE bkpf-xblnr,
        bktxt LIKE bkpf-bktxt,
        total LIKE bseg-dmbtr,
        numdocs TYPE p DECIMALS 0,
        END OF it_bkpf,
        BEGIN OF it_bseg OCCURS 0,
          belnr LIKE bseg-belnr,
          dmbtr LIKE bseg-dmbtr,
          mwsts LIKE bseg-mwsts,
          pswsl LIKE bseg-pswsl,
          END OF it_bseg,
          BEGIN OF it_final OCCURS 0,
            belnr LIKE bkpf-belnr,
            budat LIKE bkpf-budat,
            bldat LIKE bkpf-bldat,
            xblnr LIKE bkpf-xblnr,
            bktxt LIKE bkpf-bktxt,
            dmbtr LIKE bseg-dmbtr,
            mwsts LIKE bseg-mwsts,
            pswsl LIKE bseg-pswsl,
            END OF it_final.
***** End generated data section ***
AT SELECTION-SCREEN ON VALUE-REQUEST FOR pfile.
  PERFORM sub_browse_file. "Get file name
START-OF-SELECTION.
  PERFORM sub_data_load.  " Transfer excel into internal table.
  PERFORM sub_calc_excel.
  IF report = 'X'.
*    PERFORM data_selection.
*    PERFORM data_move.
*********************************GET ALV  DATA
    PERFORM alv_get_data.
*********************************ALV GRID DATA
    PERFORM alv_grid.
  ENDIF.
*if report = ''.
*  PERFORM write.
*  PERFORM open_dataset USING dataset.
  PERFORM open_group.
*  DO.
*    READ DATASET dataset INTO record.
  LOOP AT it_excel.
*   IF sy-subrc <> 0. EXIT. ENDIF.
    PERFORM bdc_dynpro      USING 'SAPMF05A' '0100'.
    PERFORM bdc_field       USING 'BDC_CURSOR'
                                  'RF05A-NEWKO'.
    PERFORM bdc_field       USING 'BDC_OKCODE'
                                  '/00'.
    PERFORM bdc_field       USING 'BKPF-BLDAT'
                                  it_excel-bldat_001.
    PERFORM bdc_field       USING 'BKPF-BLART'
                                  'DR'." record-blart_002.
    PERFORM bdc_field       USING 'BKPF-BUKRS'
                                  it_excel-bukrs_003.
    PERFORM bdc_field       USING 'BKPF-BUDAT'
                                  it_excel-budat_004.
    PERFORM bdc_field       USING 'BKPF-MONAT'
                                '3'. "record-monat_005.
    PERFORM bdc_field       USING 'BKPF-WAERS'
                                  it_excel-waers_006.
    PERFORM bdc_field       USING 'BKPF-XBLNR'
                                  it_excel-xblnr_007.
    PERFORM bdc_field       USING 'BKPF-BKTXT'
                                  it_excel-bktxt_008.
    PERFORM bdc_field       USING 'FS006-DOCID'
                                 '*' ."record-docid_009.
    PERFORM bdc_field       USING 'RF05A-NEWBS'
                                '01'." record-newbs_010.
    PERFORM bdc_field       USING 'RF05A-NEWKO'
                                it_excel-kunnr_019  .
    PERFORM bdc_dynpro      USING 'SAPMF05A' '0301'.
    PERFORM bdc_field       USING 'BDC_CURSOR'
                                  'RF05A-NEWKO'.
    PERFORM bdc_field       USING 'BDC_OKCODE'
                                  '/00'.
    PERFORM bdc_field       USING 'BSEG-WRBTR'
                                it_excel-wrbtr_020."  it_excel-wrbtr_012.
    PERFORM bdc_field       USING 'BSEG-ZTERM'
                                  'NT30' ."  record-zterm_013.
    PERFORM bdc_field       USING 'BSEG-ZBD1T'
                                  '30'."record-zbd1t_014.
    PERFORM bdc_field       USING 'BSEG-ZFBDT'
                                  it_excel-bldat_001."record-zfbdt_015.
    PERFORM bdc_field       USING 'BSEG-ZUONR'
                                  it_excel-xblnr_007."record-zuonr_016.
    PERFORM bdc_field       USING 'BSEG-SGTXT'
                                  it_excel-sgtxt_017.
    PERFORM bdc_field       USING 'RF05A-NEWBS'
                                 '50'." record-newbs_018.
    PERFORM bdc_field       USING 'RF05A-NEWKO'
                               it_excel-newko_011."  record-newko_019."Gl account
    PERFORM bdc_dynpro      USING 'SAPMF05A' '0300'.
    PERFORM bdc_field       USING 'BDC_CURSOR'
                                  'BSEG-SGTXT'.
    PERFORM bdc_field       USING 'BDC_OKCODE'
                                  '/00'.
    PERFORM bdc_field       USING 'BSEG-WRBTR'
                                  it_excel-wrbtr_012."changes from 12 to 20
    PERFORM bdc_field       USING 'BSEG-MWSKZ'
                                 it_excel-mwskz." record-mwskz_021.
    PERFORM bdc_field       USING 'BSEG-ZUONR'
                                it_excel-xblnr_007."  record-zuonr_022.
    PERFORM bdc_field       USING 'BSEG-SGTXT'
                                 it_excel-sgtxt_017."  record-sgtxt_023.
    PERFORM bdc_dynpro      USING 'SAPLKACB' '0002'.
    PERFORM bdc_field       USING 'BDC_CURSOR'
                                  'COBL-PRCTR'.
    PERFORM bdc_field       USING 'BDC_OKCODE'
                                  '=ENTE'.
    PERFORM bdc_field       USING 'COBL-PRCTR'
                                it_excel-prctr ." record-prctr_024.
    PERFORM bdc_dynpro      USING 'SAPMF05A' '0300'.
    PERFORM bdc_field       USING 'BDC_CURSOR'
                                  'BSEG-WRBTR'.
    PERFORM bdc_field       USING 'BDC_OKCODE'
                                  '=STER'.
    PERFORM bdc_field       USING 'BSEG-WRBTR'
                                 it_excel-wrbtr_012." it_excel-wrbtr_025.
    PERFORM bdc_field       USING 'BSEG-MWSKZ'
                                  it_excel-mwskz.
    PERFORM bdc_field       USING 'BSEG-ZUONR'
                                 it_excel-xblnr_007." record-zuonr_027.
    PERFORM bdc_field       USING 'BSEG-SGTXT'
                                 it_excel-sgtxt_017." record-sgtxt_028.
    PERFORM bdc_field       USING 'DKACB-FMORE'
                                 'X' ."record-fmore_029.
    PERFORM bdc_dynpro      USING 'SAPLKACB' '0002'.
    PERFORM bdc_field       USING 'BDC_CURSOR'
                                  'COBL-PARGB'.
    PERFORM bdc_field       USING 'BDC_OKCODE'
                                  '=ENTE'.
    PERFORM bdc_field       USING 'COBL-PRCTR'
                                 it_excel-prctr." record-prctr_030.
    PERFORM bdc_dynpro      USING 'SAPLTAX1' '0300'.
    PERFORM bdc_field       USING 'BDC_CURSOR'
                                  'BSET-FWSTE(01)'.
    PERFORM bdc_field       USING 'BDC_OKCODE'
                                  '=GOBU'.
    PERFORM bdc_field       USING 'BSET-FWSTE(01)'
                                it_excel-wrbtr_025."  record-fwste_01_031.
    PERFORM bdc_transaction USING 'FB01'.
    REFRESH:bdcdata,messtab.
  ENDLOOP.
  REFRESH:bdcdata.
**    PERFORM bdc_dynpro      USING 'SAPMF05A' '0100'.
*    PERFORM bdc_field       USING 'BDC_CURSOR'
*                                  'RF05A-NEWKO'.
*    PERFORM bdc_field       USING 'BDC_OKCODE'
*                                  '/00'.
*    PERFORM bdc_field       USING 'BKPF-BLDAT'
*                                  record-bldat_001.
*    PERFORM bdc_field       USING 'BKPF-BLART'
*                                  record-blart_002.
*    PERFORM bdc_field       USING 'BKPF-BUKRS'
*                                  record-bukrs_003.
*    PERFORM bdc_field       USING 'BKPF-BUDAT'
*                                  record-budat_004.
*    PERFORM bdc_field       USING 'BKPF-MONAT'
*                                  record-monat_005.
*    PERFORM bdc_field       USING 'BKPF-WAERS'
*                                  record-waers_006.
*    PERFORM bdc_field       USING 'BKPF-XBLNR'
*                                  record-xblnr_007.
*    PERFORM bdc_field       USING 'BKPF-BKTXT'
*                                  record-bktxt_008.
*    PERFORM bdc_field       USING 'FS006-DOCID'
*                                  record-docid_009.
*    PERFORM bdc_field       USING 'RF05A-NEWBS'
*                                  record-newbs_010.
*    PERFORM bdc_field       USING 'RF05A-NEWKO'
*                                  record-newko_011.
*    PERFORM bdc_dynpro      USING 'SAPMF05A' '0301'.
*    PERFORM bdc_field       USING 'BDC_CURSOR'
*                                  'RF05A-NEWKO'.
*    PERFORM bdc_field       USING 'BDC_OKCODE'
*                                  '/00'.
*    PERFORM bdc_field       USING 'BSEG-WRBTR'
*                                  record-wrbtr_012.
*    PERFORM bdc_field       USING 'BSEG-ZTERM'
*                                  record-zterm_013.
*    PERFORM bdc_field       USING 'BSEG-ZBD1T'
*                                  record-zbd1t_014.
*    PERFORM bdc_field       USING 'BSEG-ZFBDT'
*                                  record-zfbdt_015.
*    PERFORM bdc_field       USING 'BSEG-ZUONR'
*                                  record-zuonr_016.
*    PERFORM bdc_field       USING 'BSEG-SGTXT'
*                                  record-sgtxt_017.
*    PERFORM bdc_field       USING 'RF05A-NEWBS'
*                                  record-newbs_018.
*    PERFORM bdc_field       USING 'RF05A-NEWKO'
*                                  record-newko_019.
*    PERFORM bdc_dynpro      USING 'SAPMF05A' '0300'.
*    PERFORM bdc_field       USING 'BDC_CURSOR'
*                                  'BSEG-SGTXT'.
*    PERFORM bdc_field       USING 'BDC_OKCODE'
*                                  '/00'.
*    PERFORM bdc_field       USING 'BSEG-WRBTR'
*                                  record-wrbtr_020.
*    PERFORM bdc_field       USING 'BSEG-MWSKZ'
*                                  record-mwskz_021.
*    PERFORM bdc_field       USING 'BSEG-ZUONR'
*                                  record-zuonr_022.
*    PERFORM bdc_field       USING 'BSEG-SGTXT'
*                                  record-sgtxt_023.
*    PERFORM bdc_dynpro      USING 'SAPLKACB' '0002'.
*    PERFORM bdc_field       USING 'BDC_CURSOR'
*                                  'COBL-PRCTR'.
*    PERFORM bdc_field       USING 'BDC_OKCODE'
*                                  '=ENTE'.
*    PERFORM bdc_field       USING 'COBL-PRCTR'
*                                  record-prctr_024.
*    PERFORM bdc_dynpro      USING 'SAPMF05A' '0300'.
*    PERFORM bdc_field       USING 'BDC_CURSOR'
*                                  'BSEG-WRBTR'.
*    PERFORM bdc_field       USING 'BDC_OKCODE'
*                                  '=STER'.
*    PERFORM bdc_field       USING 'BSEG-WRBTR'
*                                  record-wrbtr_025.
*    PERFORM bdc_field       USING 'BSEG-MWSKZ'
*                                  record-mwskz_026.
*    PERFORM bdc_field       USING 'BSEG-ZUONR'
*                                  record-zuonr_027.
*    PERFORM bdc_field       USING 'BSEG-SGTXT'
*                                  record-sgtxt_028.
*    PERFORM bdc_field       USING 'DKACB-FMORE'
*                                  record-fmore_029.
*    PERFORM bdc_dynpro      USING 'SAPLKACB' '0002'.
*    PERFORM bdc_field       USING 'BDC_CURSOR'
*                                  'COBL-PARGB'.
*    PERFORM bdc_field       USING 'BDC_OKCODE'
*                                  '=ENTE'.
*    PERFORM bdc_field       USING 'COBL-PRCTR'
*                                  record-prctr_030.
*    PERFORM bdc_dynpro      USING 'SAPLTAX1' '0300'.
*    PERFORM bdc_field       USING 'BDC_CURSOR'
*                                  'BSET-FWSTE(01)'.
*    PERFORM bdc_field       USING 'BDC_OKCODE'
*                                  '=GOBU'.
*    PERFORM bdc_field       USING 'BSET-FWSTE(01)'
*                                  record-fwste_01_031.
*    PERFORM bdc_transaction USING 'FB01'.
*  ENDDO.
  PERFORM close_group.
*  PERFORM close_dataset USING dataset.
*endif.
*&      Form  sub_browse_file
*       text
*  -->  p1        text
*  <--  p2        text
FORM sub_browse_file .
  CALL FUNCTION 'F4_FILENAME'
   EXPORTING
     program_name        = syst-cprog
     dynpro_number       = syst-dynnr
*   FIELD_NAME          = ' '
   IMPORTING
     file_name           = pfile.
ENDFORM.                    " sub_browse_file
*&      Form  sub_data_load
*       text
*  -->  p1        text
*  <--  p2        text
FORM sub_data_load .
  CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
    EXPORTING
*     I_FIELD_SEPERATOR          =
      i_line_header              = 'X'
      i_tab_raw_data             = it_raw
      i_filename                 = pfile
    TABLES
      i_tab_converted_data       = it_excel[]
*   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.
ENDFORM.                    " sub_data_load
**&      Form  data_selection
**       text
**  -->  p1        text
**  <--  p2        text
*FORM data_selection .
*  SELECT * FROM bkpf
*      INTO CORRESPONDING FIELDS OF TABLE it_bkpf
*      WHERE budat = p_budat AND
*      bukrs = p_bukrs.
*  IF NOT it_bkpf[] IS INITIAL.
*    SELECT belnr dmbtr mwsts pswsl
*        FROM bseg INTO TABLE it_bseg
*        FOR ALL ENTRIES IN it_bkpf
*        WHERE belnr = it_bkpf-belnr AND
*        kunnr = p_kunnr AND
*        hkont = p_hkont AND
*        pswsl = p_waers.
*  ENDIF.
*ENDFORM.                    " data_selection
**&      Form  data_move
**       text
**  -->  p1        text
**  <--  p2        text
*FORM data_move.
*  SORT : it_bseg BY belnr,
*          it_bkpf BY belnr.
*  LOOP AT it_bseg.
*    it_final-dmbtr = it_bseg-dmbtr.
*    it_final-belnr = it_bseg-belnr.
*    it_final-mwsts = it_bseg-mwsts.
*    it_final-pswsl = it_bseg-pswsl.
*    READ TABLE it_bkpf WITH KEY belnr = it_bseg-belnr BINARY SEARCH.
*    IF sy-subrc = 0.
*      it_final-budat = it_bkpf-budat.
*      it_final-bldat = it_bkpf-bldat.
*      it_final-xblnr = it_bkpf-xblnr.
*      it_final-bktxt = it_bkpf-bktxt.
*    ENDIF.
*    APPEND it_final.
*    CLEAR it_final.
*  ENDLOOP.
*ENDFORM.                    " data_move
*&      Form  alv_get_data
*       text
*  -->  p1        text
*  <--  p2        text
FORM alv_get_data .
  CLEAR it_fieldcat.
***************** Document number
*  wa_fieldcat-col_pos    = '1'.                    " ALV O/P COL-1
  wa_fieldcat-fieldname  = 'XBLNR_007'.
  wa_fieldcat-seltext_m  = 'Document number'.
  wa_fieldcat-just       = 'L'.
  wa_fieldcat-no_zero(1) = 'X'.
  wa_fieldcat-outputlen  = 15.
  wa_fieldcat-tabname    = 'IT_EXCEL'.
  APPEND wa_fieldcat TO it_fieldcat.
  CLEAR wa_fieldcat.
***************** Posting Date
*  wa_fieldcat-col_pos    = '2'.                    " ALV O/P COL-1
  wa_fieldcat-fieldname  = 'BUDAT_004'.
  wa_fieldcat-seltext_m  = 'Posting Date'.
  wa_fieldcat-just       = 'L'.
  wa_fieldcat-no_zero(1) = 'X'.
  wa_fieldcat-outputlen  = 20.
  wa_fieldcat-tabname    = 'IT_EXCEL'.
  APPEND wa_fieldcat TO it_fieldcat.
  CLEAR wa_fieldcat.
******************** Document Date
*  wa_fieldcat-col_pos    = '3'.                     " ALV O/P COL-2
  wa_fieldcat-fieldname  = 'BLDAT_001'.
  wa_fieldcat-seltext_m  = 'Document Date'.
  wa_fieldcat-just       = 'L'.
  wa_fieldcat-tabname    = 'IT_EXCEL'.
  wa_fieldcat-outputlen  = 15.
  APPEND wa_fieldcat TO it_fieldcat.
  CLEAR wa_fieldcat.
********************* REFERENCE DOCUMENT
**  wa_fieldcat-col_pos    = '4'.                     " ALV O/P COL-2
*  wa_fieldcat-fieldname  = 'XBLNR'.
*  wa_fieldcat-seltext_m  = 'REFERENCE DOCUMENT'.
*  wa_fieldcat-just       = 'L'.
*  wa_fieldcat-tabname    = 'IT_EXCEL'.
**  wa_fieldcat-outputlen  = 15.
*  APPEND wa_fieldcat TO it_fieldcat.
*  CLEAR wa_fieldcat.
***************** DOCUMENT HEADER TEXT
*  wa_fieldcat-col_pos    = '5'.                     " ALV O/P COL-3
  wa_fieldcat-fieldname  = 'SGTXT_017'.
  wa_fieldcat-seltext_m  = 'DOCUMENT HEADER TEXT'.
  wa_fieldcat-just       = 'L'.
  wa_fieldcat-tabname    = 'IT_EXCEL'.
*  wa_fieldcat-outputlen  = 15.
  APPEND wa_fieldcat TO it_fieldcat.
  CLEAR wa_fieldcat.
*******************Invoice Net amount
*  wa_fieldcat-col_pos    = '6'.                     " ALV O/P COL-4
  wa_fieldcat-fieldname  = 'WRBTR_012'.
  wa_fieldcat-seltext_m  = 'Invoice Net amount'.
  wa_fieldcat-just       = 'L'.
  wa_fieldcat-tabname    = 'IT_EXCEL'.
*  wa_fieldcat-outputlen  = 15.
  APPEND wa_fieldcat TO it_fieldcat.
  CLEAR wa_fieldcat.
*********** Tax Amount
*  wa_fieldcat-col_pos    = '7'.                     " ALV O/P COL-5
  wa_fieldcat-fieldname  = 'WRBTR_025'.
  wa_fieldcat-seltext_m  = 'Tax Amount'.
  wa_fieldcat-just       = 'L'.
* wa_fieldcat-no_zero(1) = 'X'.
  wa_fieldcat-tabname    = 'IT_EXCEL'.
  APPEND wa_fieldcat TO it_fieldcat.
  CLEAR wa_fieldcat.
*********** NEt Amount
*  wa_fieldcat-col_pos    = '7'.                     " ALV O/P COL-5
  wa_fieldcat-fieldname  = 'WRBTR_020'.
  wa_fieldcat-seltext_m  = 'Net Amount'.
  wa_fieldcat-just       = 'L'.
* wa_fieldcat-no_zero(1) = 'X'.
  wa_fieldcat-tabname    = 'IT_EXCEL'.
  APPEND wa_fieldcat TO it_fieldcat.
  CLEAR wa_fieldcat.
*********** General ledger currency
*  wa_fieldcat-col_pos    = '7'.                     " ALV O/P COL-5
  wa_fieldcat-fieldname  = 'WAERS_006'.
  wa_fieldcat-seltext_l  = 'General ledger currency'.
  wa_fieldcat-just       = 'L'.
* wa_fieldcat-no_zero(1) = 'X'.
  wa_fieldcat-outputlen  = 25.
  wa_fieldcat-tabname    = 'IT_EXCEL'.
  APPEND wa_fieldcat TO it_fieldcat.
  CLEAR wa_fieldcat.
ENDFORM.                    " alv_get_data
*&      Form  alv_grid
*       text
*  -->  p1        text
*  <--  p2        text
FORM alv_grid .
*  PERFORM fill_list_header USING it_top_of_page[].
*  PERFORM event-build USING gt_events[].
  PERFORM fill_layout USING ls_layout.
MESSAGE 'Please press F3 to generate a session or call transaction method after getting report!' TYPE 'I'.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program = sy-repid
      is_layout          = ls_layout
      it_fieldcat        = it_fieldcat
      it_events          = gt_events[]
      i_save             = 'A'
    TABLES
      t_outtab           = it_excel
    EXCEPTIONS
      program_error      = 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.
ENDFORM.                    " alv_grid
*                                     FORM FILL_LAYOUT                      *
FORM fill_layout  USING    p_ls_layout  TYPE slis_layout_alv.
  p_ls_layout-zebra       = 'X'.
  p_ls_layout-cell_merge  = 'X'.
ENDFORM.                                                         "fill_layout
*&      Form  sub_calc_excel
*       text
*  -->  p1        text
*  <--  p2        text
FORM sub_calc_excel .
      data: idate TYPE sy-datum,
          tdat8 type string.
  LOOP AT it_excel.
    CONCATENATE  it_excel-blart_002 '/' it_excel-monat_005 '/' it_excel-bktxt_008 INTO
        it_excel-sgtxt_017.
    it_excel-bukrs_003 = p_bukrs.
*    it_excel-budat_004 = p_budat.
    it_excel-waers_006 = p_waers.
    it_excel-newko_011 = p_hkont.
    it_excel-kunnr_019 = p_kunnr.
    it_excel-mwskz     = p_mwskz.
    it_excel-prctr     = p_prctr.
    idate              = p_budat.
    CALL FUNCTION 'DATUMSAUFBEREITUNG'
     EXPORTING
*       FLAGM                 = ' '
*       FLAGW                 = ' '
       IDATE                 = idate
*       IMONT                 = ' '
*       IWEEK                 = ' '
     IMPORTING
*       MDAT4                 =
*       MDAT6                 =
*       TDAT4                 =
*       TDAT6                 =
        TDAT8                 = tdat8
*       WDAT4                 =
*       WDAT6                 =
*     EXCEPTIONS
*       DATFM_UNGUELTIG       = 1
*       DATUM_UNGUELTIG       = 2
*       OTHERS                = 3
    IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
      it_excel-budat_004 = tdat8.
*    CONCATENATE it_excel-budat_004+4(2) '/' it_excel-budat_004+6(2) '/'  it_excel-budat_004+0(4)
*                INTO it_excel-budat_004.
*    SPLIT it_excel-bldat_001 AT '/' INTO it_excel-month it_excel-date.
*    CONCATENATE it_excel-date '.' it_excel-month '.' it_excel-bldat_001+6(4) INTO it_excel-bldat_001.
    MODIFY it_excel.
    CLEAR it_excel.
  ENDLOOP.
ENDFORM.                    " sub_calc_excel
*&      Form  write
*       text
*  -->  p1        text
*  <--  p2        text
*form write .
*OPEN DATASET dataset FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
*data: wa_excel like line of it_excel.
*loop at it_excel into wa_excel.
*TRANSFER wa_excel to dataset.
*endloop.
*CLOSE DATASETdataset.
*endform.                    " write

Read other 6 answers

Tags:

Related Articles

  • Adding Data to the database for SAP TransactionsOctober 11

    Hi I'm new to the whole ABAP. I would like to enquire about adding transaction data in SAP through ABAP but it must be immediate. I know that one can use a BAPI to add data and can rollback if any problems occur. But if no BAPI exists how does one wr

  • How to Transfer the Data from ORACLE APPS to SAPNovember 30

    Hi Gurus, Here are my couple of quieries regarding Data Migration from Legacy(Oracle Apps) to SAP. 1. How to link between Legacy system(ORACLE APPS) and SAP ? 2. How to migrate the data from Oracle tables to SAP directly, instead of loading the flat

  • Failed to retrieve data from the database when adding jdbc datasourceNovember 30

    I'm having problems adding some tables to the selected tables list using the database expert. I get the error messages "Failed to retrieve data from the database" followed by "Unknown Database Connection Error". I thought it may be a p

  • Data fetching from Standard tables or transaction to SAP PINovember 30

    Dear Friends !      Good day ! How are you ?       I have one requirement , My client asks me to develop a solution in that I should get the data from standard SAP tables like EKKO, EKPO ( MM related ) etc..  and send it to PI system and then PI syst

  • How to upload the data from legacy system database to SAP data baseOctober 11

    Hi. We are doing analysis of Legacy system and which needs to be converted to SAP system i.e. SAP implementation. I just want to know , how we migrate the existing whole data( from legacy system) into SAP system. and which method is the best method t

  • Failed to retrieve data from the database crystal reports 2008 in SAP  B1October 11

    Hello friends,              I am using Crystal report 2008 with SAP B1 PL 8.8. When I run any report,  it runs correctly from Crystal Report. But whenever I try to open the same report through SAP ( Tools -> Preview External Crystal Report ), it prom

  • Adding new custom fields in SAP transaction?November 30

    Hi, System - ECC 6.0 I need to add some new custom fields in Contract Object(PSOBWORK). Can any one tell me what are the ways I can do this, and what is the best way to add custom fields in SAP transaction? I highly appreciate your help on this. Than

  • Data transfer from oracle database(external database) to sap databaseNovember 30

    Hi Abapers, I have a requirment like excel data upload from oracle database(external database) to SAP database .Plz any one can help me how to create a bdc program for this requarment. Advance thanks you. JnanaHI use function module 'ASLM_EXCEL_TO_IN

  • How to block sap transactions from particular dateNovember 30

    how to block sap transactions from particular dateHi If it is G/L Account inactive means. Go to => Financial => Chart of Account => Select the Account to be Blocked = > Account Details You can found the Active and Inactive Parameters.  You can

  • Adding field in standard SAP transaction output results.October 11

    Hi, I have to add a new field in standard SAP transaction output results. Can any one tell me what are the ways (brief explanation) that I can do this? If using exists - then what kind of exists I have to use? And how to find out the possibility with

Copyright (C) 2019 wisumpire.com, All Rights Reserved. webmaster#wisumpire.com 14 q. 0.717 s.