Quantcast
Channel: SCN: Message List - ABAP Connectivity
Viewing all articles
Browse latest Browse all 3125

Re: BDC for f-02 for multple header data i.e start trasaction for each new entr

$
0
0

sample excel format for multiple line items posting f-02.


when upload the excel data hole data will posted one document number

402850191000CK01CK01CHassitext1
501000001000CK01CK01CHassitext2
402850202000CK01CK01CHassitext3
402850212000CK01CK01CHassitext4
501000014000CK01CK01CHassitext5
402850229000CK01CK01CHassitext6
501000003000CK01CK01CHassitext7
501000013000CK01CK01CHassitext8
501000023000CK01CK01CHassitext9
402850192500CK01CK01CHassitext10
402850192500CK01CK01CHassitext11
501000005000CK01CK01CHassitext12

     sample coding:

REPORT zfi_bdcf02

        NO STANDARD PAGE HEADING LINE-SIZE 255.

TYPE-POOLS: truxs.

 

TYPES: BEGIN OF st_out,

          newbs  TYPE newbs,

          newko  TYPE newko,

          wrbtr  TYPE wrbtr,

          gsber  TYPE gsber,

          prctr  TYPE prctr,

          ZUONR  type bseg-ZUONR,

          SGTXT  type SGTXT,

          xblnr type xblnr,

          END   OF st_out.

 

DATA: p_bldat1(10TYPE c,

       p_budat1(10TYPE c,

       p_valut1(10TYPE c,

       lv_wrbtr(16TYPE c,

       lv_wrbtr1(16) TYPE c.

 

 

DATA: it_out TYPE TABLE OF st_out WITH HEADER LINE.

DATA: it_out1 TYPE TABLE OF st_out WITH HEADER LINE.

DATA: it_bdcdata TYPE TABLE OF bdcdata,

       wa_bdcdata TYPE bdcdata.

DATA: it_type TYPE truxs_t_text_data.

 

SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME TITLE text-002.

PARAMETERS       : p_bldat TYPE bkpf-bldat OBLIGATORY, "DOCUMENT DATE

                    p_blart TYPE bkpf-blart DEFAULT 'SA',

                    p_valut TYPE bseg-valut,

                    p_bukrs TYPE bkpf-bukrs DEFAULT 'TH01',

                    p_budat TYPE bkpf-budat OBLIGATORY,

                    p_monat TYPE bkpf-monat OBLIGATORY,

                    p_waers TYPE bkpf-waers DEFAULT 'INR',

                    p_xblnr type bkpf-xblnr,

                    p_bktxt TYPE bkpf-bktxt.

SELECTION-SCREEN END OF BLOCK blk1.

 

SELECTION-SCREEN BEGIN OF BLOCK blk WITH FRAME TITLE text-001.

PARAMETER p_file TYPE rlgrap-filename."" OBLIGATORY DEFAULT 'C:\Users\Thpl2\Desktop\BDC.xlsx'.

SELECTION-SCREEN END OF BLOCK blk.

 

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file .

 

   CALL FUNCTION 'F4_FILENAME'

* EXPORTING

*   PROGRAM_NAME        = SYST-CPROG

*   DYNPRO_NUMBER       = SYST-DYNNR

*   FIELD_NAME          = ' '

     IMPORTING

       file_name = p_file.

 

 

START-OF-SELECTION.

   CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'

     EXPORTING

*     I_FIELD_SEPERATOR    =

*     I_LINE_HEADER        =

       i_tab_raw_data       = it_type

       i_filename           = p_file

     TABLES

       i_tab_converted_data = it_out

* EXCEPTIONS

*     CONVERSION_FAILED    = 1

*     OTHERS               = 2

     .

   IF sy-subrc <> 0.

* Implement suitable error handling here

   ENDIF.

 

   DATA : lv_count TYPE i.

   CLEAR lv_count.

   LOOP AT it_out.

     WRITE: p_bldat TO p_bldat1.

     WRITE: p_budat TO p_budat1.

     WRITE: p_valut TO p_valut1.

     lv_count = lv_count + 1.

     IF lv_count = 1.

 

       PERFORM bdc_dynpro      USING 'SAPMF05A' '0100'.

       PERFORM bdc_field       USING 'BDC_CURSOR'

                                     'BKPF-BKTXT'.

       PERFORM bdc_field       USING 'BDC_OKCODE'

                                     '/00'.

       PERFORM bdc_field       USING 'BKPF-BLDAT'

                                     p_bldat1.

       PERFORM bdc_field       USING 'BKPF-BLART'

                                      p_blart.

       PERFORM bdc_field       USING 'BKPF-BUKRS'

                                     p_bukrs.

       PERFORM bdc_field       USING 'BKPF-BUDAT'

                                      p_budat1  .

       PERFORM bdc_field       USING 'BKPF-MONAT'

                                     p_monat.

       PERFORM bdc_field       USING 'BKPF-WAERS'

                                     p_waers.

       PERFORM bdc_field       USING 'BKPF-BKTXT'

                                     p_bktxt.

       PERFORM bdc_field       USING 'FS006-DOCID'

                                     '*'.

       PERFORM bdc_field       USING 'RF05A-NEWBS'

                                      it_out-newbs .

       PERFORM bdc_field       USING 'RF05A-NEWKO'

                                     it_out-newko.

       PERFORM bdc_dynpro      USING 'SAPMF05A' '0300'.

       PERFORM bdc_field       USING 'BDC_CURSOR'

                                     'RF05A-NEWKO'.

       PERFORM bdc_field       USING 'BDC_OKCODE'

                                     '/00'.

 

       lv_wrbtr = it_out-wrbtr.

       CONDENSE lv_wrbtr.

       PERFORM bdc_field       USING 'BSEG-WRBTR'

                                      lv_wrbtr.

*      PERFORM bdc_field       USING 'BSEG-VALUT'

*                                     p_valut1.

       perform bdc_field       using 'BSEG-ZUONR'

                                      it_out-zuonr.

       PERFORM bdc_field       USING 'BSEG-SGTXT'

                                    it_out-sgtxt.

     ELSE.

       PERFORM bdc_field       USING 'RF05A-NEWBS'

                                     it_out-newbs.

       PERFORM bdc_field       USING 'RF05A-NEWKO'

                                     it_out-newko.

       PERFORM bdc_field       USING 'DKACB-FMORE'

                                     'X'.

       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-GSBER'

                                     it_out-gsber.

       PERFORM bdc_field       USING 'COBL-PRCTR'

                                     it_out-prctr.

       PERFORM bdc_dynpro      USING 'SAPMF05A' '0300'.

       PERFORM bdc_field       USING 'BDC_CURSOR'

                                     'RF05A-NEWKO'.

       PERFORM bdc_field       USING 'BDC_OKCODE'

                                     '/00'.

       lv_wrbtr = it_out-wrbtr.

       CONDENSE lv_wrbtr.

       PERFORM bdc_field       USING 'BSEG-WRBTR'

                                    lv_wrbtr.

*      PERFORM bdc_field       USING 'BSEG-VALUT'

*                                    p_valut1.

       perform bdc_field       using 'BSEG-ZUONR'

                                  it_out-zuonr.

       PERFORM bdc_field       USING 'BSEG-SGTXT'

                                     it_out-sgtxt.

     ENDIF.

   ENDLOOP.

 

   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-GSBER'

                                 it_out-gsber.

   PERFORM bdc_field       USING 'COBL-PRCTR'

                                 it_out-prctr.

 

   PERFORM bdc_dynpro      USING 'SAPMF05A' '0300'.

   PERFORM bdc_field       USING 'BDC_CURSOR'

                                 'BSEG-WRBTR'.

   PERFORM bdc_field       USING 'BDC_OKCODE'

                                 '=AB'.

    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-GSBER'

                                 it_out-gsber.

   PERFORM bdc_field       USING 'COBL-PRCTR'

                                 it_out-prctr.

   PERFORM bdc_dynpro      USING 'SAPMF05A' '0700'.

   PERFORM bdc_field       USING 'BDC_CURSOR'

                                 'RF05A-NEWBS'.

   PERFORM bdc_field       USING 'BDC_OKCODE'

                                 '=BU'.

   perform bdc_field       using 'BKPF-XBLNR'

                           it_out-xblnr.

   DATA t_message TYPE TABLE OF bdcmsgcoll WITH HEADER LINE.

   CLEAR t_message[].

 

 

   CALL TRANSACTION 'F-02' USING it_bdcdata

         MODE 'A' UPDATE 'S' MESSAGES INTO t_message.

   CLEAR it_bdcdata[].

 

 

   IF NOT sy-subrc EQ 0.

    read table t_message WITH key msgtyp = 'E'.

         IF sy-subrc EQ 0.

            t_message = 'Error in BDC update'.

         ENDIF.

ELSE.

         t_message = 'Updated successfully'.

 

ENDIF.

 

 

FORM bdc_dynpro USING program dynpro.

   CLEAR wa_bdcdata.

   wa_bdcdata-program  = program.

   wa_bdcdata-dynpro   = dynpro.

   wa_bdcdata-dynbegin = 'X'.

   APPEND wa_bdcdata TO it_bdcdata.

   CLEAR wa_bdcdata.

ENDFORM.

 

 

FORM bdc_field USING fnam fval.

*  IF FVAL <> NODATA.

   CLEAR wa_bdcdata.

   wa_bdcdata-fnam = fnam.

   wa_bdcdata-fval = fval.

   APPEND wa_bdcdata TO it_bdcdata.

*  ENDIF.

   CLEAR wa_bdcdata.

ENDFORM.




Viewing all articles
Browse latest Browse all 3125

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>