Quantcast
Channel: SCN : Document List - ABAP Development
Viewing all articles
Browse latest Browse all 935

BPO creation (PS Module) program Through BDC

$
0
0

Dear,

there is a program which creates BPO. ITS very important BDC in PS module.

 

************************************************************************

*                PROGRAM INFORMATION

************************************************************************

*  PROGRAM....... ZPS_BPO_CREATE_BDC

*  TITLE......... Creation Of BPO

*  AUTHOR........ SABYASACHI KARFORMA

 

* START DATE.... 05/07/2013

* END DATE.......05/07/2013

* DEV.CLASS......ZPS

* TCODE..........ZPS_BPO_UPLOAD

*  R/3 RELEASE....SAP ECC 6.0

*  TRANSPORTNR... AEDK900252

*  COPIED FROM... N/A

*---------------------------------------------------------------------

*                PROGRAM FUNCTION:

* This conversion program is to Upload BPO.

*---------------------------------------------------------------------

*  PROGRAM TYPE.. Executable

*  LOGICAL DB.... N/A

************************************************************************

 

************************************************************************

*                CHANGE HISTORY

************************************************************************

*  DATE CHANGE... <Date of change written>

*  AUTHOR........ <Author name>

*  CHANGE DESCR.. <Description of change>

*  R/3 RELEASE... <Release>

*  TRANSPORTNR... <Transport number>

************************************************************************

************************************************************************

 

 

 

 

report zps_bpo_create_bdc

        no standard page heading line-size 255.

 

types: begin of ty_header,

        extnr type extnr,

        ref_extnr type extnr,

*       KOKRS TYPE KOKRS,

        meeht type meins,

*       KSTAR TYPE KSTAR,

        bukrs type bukrs,

        werks type werks_d,

        prctr type prctr,

        kstar type kstar,

        btgrp type btgrp,

        ktext type ktext,

        ltext type kltxt,

        klvar type ck_klvar,

        menge type menge_kpf,

        end of ty_header.

 

types: begin of ty_item,

        extnr type extnr,

        typps type typps,

        herk2 type herk2,

        herk3 type herk3,

        menge type menge_kpf,

        meeht type meins,

        ltext type kltxt,

        lpreis type lpreis,

        lpeinh type peinh,

        kstar type kstar,

        lpreifx type lpreifx,

        arbpl type kkek_arbpl,

        arbplwerk type kkek_arbplwerk,

        end of ty_item.

 

*include bdcrecx1.

 

parameters: p_file type localfile obligatory.

 

parameters: beg_row type i default '2' no-display,

       beg_col type i default '2' no-display ,

       end_col type i default '25' no-display,

       end_row type i default '9999' no-display.

 

data: it_excel type standard table of alsmex_tabline,

       wa_excel type alsmex_tabline.

 

data: it_header type standard table of ty_header,

       wa_header type ty_header,

       it_item type standard table of ty_item,

       wa_item type ty_item.

data: gv_extnr type extnr.

data: bdcdata type  bdcdata occurs 0 with header line.

data: it_msg type standard table of bdcmsgcoll,

       wa_msg type bdcmsgcoll.

data: message(120) type c.

 

data: menge(20) type c.

data: price(11) type c.

 

at selection-screen on value-request for p_file.

   call function 'F4_FILENAME'

     exporting

       program_name  = syst-cprog

       dynpro_number = syst-dynnr

*     FIELD_NAME    = 'P_FILE'

     importing

       file_name     = p_file.

 

 

start-of-selection.

 

   call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'

     exporting

       filename                      = p_file

       i_begin_col                   = beg_col

       i_begin_row                   = beg_row

       i_end_col                     = end_col

       i_end_row                     = end_row

     tables

       intern                        = it_excel

* EXCEPTIONS

*   INCONSISTENT_PARAMETERS       = 1

*   UPLOAD_OLE                    = 2

*   OTHERS                        = 3

             .

   if sy-subrc <> 0.

* Implement suitable error handling here

   endif.

   loop at it_excel into wa_excel.

     at new row.

       clear wa_excel.

       clear wa_item.

     endat.

     case wa_excel-col.

       when '0001'.

         wa_header-extnr = wa_excel-value.

 

       when '0002'.

         wa_header-ref_extnr = wa_excel-value.

 

       when '0003'.

         wa_header-meeht = wa_excel-value.

       when '0004'.

         wa_header-bukrs = wa_excel-value.

       when '0005'.

         wa_header-werks = wa_excel-value.

       when '0006'.

         wa_header-prctr = wa_excel-value.

       when '0007'.

          wa_header-kstar = wa_excel-value.

       when '0008'.

          wa_header-btgrp = wa_excel-value.

       when '0009'.

         wa_header-ktext = wa_excel-value.

       when '0010'.

         wa_header-ltext = wa_excel-value.

       when '0011'.

         wa_header-klvar = wa_excel-value.

       when '0012'.

         wa_header-menge = wa_excel-value.

       when '0013'.

         wa_item-typps = wa_excel-value.

       when '0014'.

         wa_item-herk2 = wa_excel-value.

       when '0015'.

         wa_item-herk3 = wa_excel-value.

       when '0016'.

         wa_item-menge = wa_excel-value.

       when '0017'.

         wa_item-meeht = wa_excel-value.

       when '0018'.

         wa_item-ltext = wa_excel-value.

       when '0019'.

         wa_item-lpreis = wa_excel-value.

       when '0020'.

         wa_item-lpeinh = wa_excel-value.

       when '0021'.

         wa_item-kstar = wa_excel-value.

          when '0022'.

         wa_item-lpreifx = wa_excel-value.

       when '0023'.

         wa_item-arbpl = wa_excel-value.

       when '0024'.

         wa_item-arbplwerk = wa_excel-value.

 

 

 

     endcase.

 

           at end of row.

           append wa_header to it_header.

           wa_item-extnr = wa_header-extnr.

           append wa_item to it_item.

           clear wa_header.

           clear wa_item.

           endat.

   endloop.

*perform open_group.

 

loop at it_header into wa_header.

 

   if wa_header-extnr ne gv_extnr.

   gv_extnr = wa_header-extnr.

   clear bdcdata.

   refresh bdcdata.

   perform bdc_dynpro      using 'SAPMK70B' '1000'.

   perform bdc_field       using 'BDC_CURSOR'

                                 'RK70B-EXTNR'.

   perform bdc_field       using 'BDC_OKCODE'

                                 '/00'.

   perform bdc_field       using 'RK70B-EXTNR'

                                 "'TEST-75'.

                                 wa_header-extnr.

   perform bdc_field       using 'RK70B-REF_EXTNR'

                                " 'test-1'.

                                wa_header-ref_extnr.

   perform bdc_field       using 'RK70B-KOKRS'

                                 '1111'.

   perform bdc_dynpro      using 'SAPMK70B' '1100'.

   perform bdc_field       using 'BDC_CURSOR'

                                 'RK70B-LTEXT'.

   perform bdc_field       using 'BDC_OKCODE'

                                 '/00'.

   perform bdc_field       using 'RK70B-MEEHT'

                                 "'m3'.

                                 wa_header-meeht.

    perform bdc_field      using 'RK70B-KSTAR'

                                 wa_header-kstar.

   perform bdc_field       using 'RK70B-BUKRS'

                                 "'1111'.

                                 wa_header-bukrs.

 

   perform bdc_field       using 'RK70B-BTGRP'

                                 wa_header-btgrp.

 

   perform bdc_field       using 'RK70B-WERKS'

                                 "'z001'.

                                 wa_header-werks.

   perform bdc_field       using 'RK70B-PRCTR'

                                 "'p001'.

                                 wa_header-prctr.

 

   perform bdc_field       using 'RK70B-KTEXT'

                                 "'TES"T7'.

                                 wa_header-ktext.

   perform bdc_field       using 'RK70B-LTEXT'

                                 "'TEST 6'.

                                 wa_header-ltext.

   perform bdc_dynpro      using 'SAPLKKEA' '1300'.

   perform bdc_field       using 'BDC_CURSOR'

                                 'RK70_KKEA-MENGE'.

   perform bdc_field       using 'BDC_OKCODE'

                                 '=GOON'.

   perform bdc_field       using 'RK70_KKEA-KLVAR'

                                 "'pg'.

                                 wa_header-klvar.

 

   perform bdc_field       using 'RK70_KKEA-MENGE'

                                " '                  1'.

                                wa_header-menge.

 

   loop at it_item into wa_item where extnr eq wa_header-extnr.

*  PERFORM bdc_field       USING 'RK70_KKEA-EXTNR'

*                                'TEST-1'.

   perform bdc_dynpro      using 'SAPLKKDI' '1301'.

   perform bdc_field       using 'BDC_CURSOR'

                                 'RK70L-PRICE_MANUAL(01)'.

   perform bdc_field       using 'BDC_OKCODE'

                                 '=PINS'.

*perform bdc_field       using 'RK70E-LST_SETNR'

*                              '    1'.

   perform bdc_field       using 'RK70L-PMARK(01)'

                                 'X'.

   perform bdc_dynpro      using 'SAPLKKDI' '1301'.

   perform bdc_field       using 'BDC_CURSOR'

                                 'RK70L-KSTAR(01)'.

   perform bdc_field       using 'BDC_OKCODE'

                                 '/00'.

*perform bdc_field       using 'RK70E-LST_SETNR'

*                              '    1'.

   if wa_item-typps eq 'M'.

   perform bdc_field       using 'RK70L-TYPPS(01)'

                                " 'm'.

                                wa_item-typps.

   perform bdc_field       using 'RK70L-HERK2(01)'

                                " '1'.

                                wa_item-herk2.

   perform bdc_field       using 'RK70L-HERK3(01)'

                                 "'z001'.

                                 wa_item-herk3.

   menge = wa_item-menge.

condense menge.

 

   perform bdc_field       using 'RK70L-MENGE(01)'

                                 "'                   1'.

                                 menge.

   perform bdc_field       using 'RK70L-LPREIFX(01)'

                                  wa_item-lpreifx.

   perform bdc_field       using  'RK70L-ARBPL(01)'

                                  wa_item-arbpl.

   perform bdc_field       using  'RK70L-ARBPLWERK(01)'

                                  wa_item-arbplwerk.

   perform bdc_field       using 'BDC_OKCODE'

                                 '/00'.

 

 

 

 

else.

 

perform bdc_field       using 'RK70L-TYPPS(01)'

                                " 'm'.

                                wa_item-typps.

   perform bdc_field       using 'RK70L-HERK2(01)'

                                " '1'.

                                wa_item-herk2.

   perform bdc_field       using 'RK70L-HERK3(01)'

                                 "'z001'.

                                 wa_item-herk3.

   perform bdc_field       using 'BDC_OKCODE'

                                 '/00'.

 

 

menge = wa_item-menge.

condense menge.

 

   perform bdc_field       using 'RK70L-MENGE(01)'

                                 "'                   1'.

                                 menge.

   perform bdc_field       using 'RK70L-MEEHT(01)'

                                 "'bag'.

                                 wa_item-meeht.

   perform bdc_field       using 'RK70L-LTEXT(01)'

                                 "'Cement OPC  - 43 Grade'.

                                 wa_item-ltext.

    perform bdc_dynpro      using 'SAPLKKDI' '1301'.

   perform bdc_field       using 'BDC_CURSOR'

                                 'RK70L-KSTAR(01)'.

   perform bdc_field       using 'BDC_OKCODE'

                                 '=SICH'.

   perform bdc_field       using 'BDC_OKCODE'

                               '/00'.

   price wa_item-lpreis.

   condense price.

   perform bdc_field       using 'RK70L-LPREIS(01)'

                                 "'              415.09'.

                                 price.

   perform bdc_field       using 'RK70L-LPEINH(01)'

                                " '     1'.

                                wa_item-lpeinh.

   perform bdc_field       using 'RK70L-KSTAR(01)'

                                 "'40100230'.

                                 wa_item-kstar.

 

    perform bdc_field       using 'RK70L-LPREIFX(01)'

                                  wa_item-lpreifx.

 

   endif.

   clear wa_item.

   endloop.

*perform bdc_dynpro      using 'SAPLKKDI' '1301'.

*perform bdc_field       using 'BDC_CURSOR'

*                              'RK70L-PRICE_MANUAL(01)'.

*perform bdc_field       using 'BDC_OKCODE'

*                              '=PINS'.

*perform bdc_field       using 'RK70E-LST_SETNR'

*                              '    1'.

*perform bdc_field       using 'RK70L-PMARK(01)'

*                              'X'.

*perform bdc_field       using 'RK70L-PMARK(02)'

*                              ''.

*perform bdc_dynpro      using 'SAPLKKDI' '1301'.

*perform bdc_field       using 'BDC_CURSOR'

*                              'RK70L-KSTAR(01)'.

*perform bdc_field       using 'BDC_OKCODE'

*                              '/00'.

*perform bdc_field       using 'RK70E-LST_SETNR'

*                              '    1'.

*perform bdc_field       using 'RK70L-TYPPS(01)'

*                              'm'.

*perform bdc_field       using 'RK70L-HERK2(01)'

*                              '1'.

*perform bdc_field       using 'RK70L-HERK3(01)'

*                              'z001'.

*perform bdc_field       using 'RK70L-MENGE(01)'

*                              '                   1'.

*perform bdc_field       using 'RK70L-MEEHT(01)'

*                              'bag'.

*perform bdc_field       using 'RK70L-LTEXT(01)'

*                              'Cement OPC  - 43 Grade'.

*perform bdc_field       using 'RK70L-LPREIS(01)'

*                              '               415.09'.

*perform bdc_field       using 'RK70L-LPEINH(01)'

*                              '     1'.

*perform bdc_field       using 'RK70L-KSTAR(01)'

*                              '40100230'.

   perform bdc_dynpro      using 'SAPLKKDI' '1301'.

   perform bdc_field       using 'BDC_CURSOR'

                                 'RK70L-KSTAR(01)'.

   perform bdc_field       using 'BDC_OKCODE'

                                 '=SICH'.

*  PERFORM bdc_field       USING 'RK70E-LST_SETNR'

*                                '    1'.

   perform bdc_dynpro      using 'SAPMK70B' '1100'.

   perform bdc_field       using 'BDC_CURSOR'

                                 'RK70B-LTEXT'.

   perform bdc_field       using 'BDC_OKCODE'

                                 '=BUCH'.

*  PERFORM bdc_field       USING 'RK70B-KTEXT'

*                                'TEST7'.

*  PERFORM bdc_field       USING 'RK70B-LTEXT'

*                                'TEST 6'.

*perform bdc_transaction using 'KKE1'.

   call transaction 'KKE1' using bdcdata[] update 'S' mode 'A' messages into it_msg.

 

*perform close_group.

*ENDAT.

else.

   continue.

   endif.

   clear wa_header.

endloop.

 

 

loop at  it_msg into wa_msg.

   call function 'FORMAT_MESSAGE'

    exporting

      id              = wa_msg-msgid

      lang            = 'EN'

      no              = wa_msg-msgnr

      v1              = wa_msg-msgv1

      v2              = wa_msg-msgv2

      v3              = wa_msg-msgv3

      v4              = wa_msg-msgv4

    importing

      msg             = message

*   EXCEPTIONS

*     NOT_FOUND       = 1

*     OTHERS          = 2

             .

   if sy-subrc <> 0.

* Implement suitable error handling here

      if sy-tabix = 1.

     write:/ 'MESSAGE TYPE',

              sy-vline,

             'MESSAGE TEXT'.

     write:/ sy-uline.

     endif.

     write:/ wa_msg-msgtyp under 'MESSAGE TYPE', 14 sy-vlinemessage under 'MESSAGE TEXT'.

     write:/ space.

     write:/ sy-uline.

   endif.

 

 

endloop.

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.

*  if fval <> nodata.

   clear bdcdata.

   bdcdata-fnam = fnam.

   bdcdata-fval = fval.

*IF FNAM EQ 'RK70L-MENGE(01)'.

*  CONDENSE  bdcdata-fval.

*ENDIF.

   append bdcdata.

*  endif.

endform.                    "bdc_field


Viewing all articles
Browse latest Browse all 935

Trending Articles



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