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

Internal Order master (KO01) upload program

$
0
0

Hello,

kindly follow this program to upload internal order master. Explicit error handling also present in this code.

 

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

*                PROGRAM INFORMATION

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

*  PROGRAM....... ZFI_KO01_BDC

*  TITLE......... INTERNAL ORDER MASTER UPLOAD

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

 

* START DATE.... 15/07/2013

* END DATE.......16/07/2013

* DEV.CLASS......ZFI

* TCODE..........ZKO01_BDC

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

*  TRANSPORTNR...  AEDK900286

*  COPIED FROM... N/A

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

*                PROGRAM FUNCTION:

* This conversion program is to Upload INTERNAL ORDER MASTER.

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

*  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 zfi_ko01_bdc

        no standard page heading line-size 255.

 

 

types: begin of ty_ko01,

        auart type auart,

        ktext type coas-ktext,

        bukrs type bukrs,

        gsber type coas-gsber,

        werks type werks_d,

        scope type char5,

        prctr type prctr,

        waers type aufwaers,

        astkz type c,

        end of ty_ko01.

 

data: it_ko01 type standard table of ty_ko01,

       wa_ko01 type ty_ko01.

 

data: bdcdata like bdcdata occurs 0 with header line.

 

 

data: it_msg type standard table of bdcmsgcoll,

       wa_msg type bdcmsgcoll.

 

data: it_excel type standard table of alsmex_tabline initial size 0,

       wa_excel type alsmex_tabline.

 

data: message(90) type c.

 

data: it_vrm type vrm_values,

       wa_vrm type vrm_value.

 

 

 

selection-screen: begin of block b1 with frame title text-001.

parameters : p_file type rlgrap-filename obligatory,

              beg_col type i default '1' no-display,

              end_col type i default '9' no-display,

              beg_row type i default '6' no-display,

              end_row type i default  '9999' no-display,

              update type c as listbox visible length 20.

selection-screen: end of block b1.

 

at selection-screen output.

 

   wa_vrm-key = 'A'.

   wa_vrm-text = 'FOREGROUND'.

   append wa_vrm to it_vrm.

 

    wa_vrm-key = 'E'.

   wa_vrm-text = 'ERROR DISPLAY'.

   append wa_vrm to it_vrm.

 

    wa_vrm-key = 'N'.

   wa_vrm-text = 'BACKGROUND'.

   append wa_vrm to it_vrm.

   clear wa_vrm.

  call function 'VRM_SET_VALUES'

    exporting

      id                    = 'UPDATE'

      values                = it_vrm

*  EXCEPTIONS

*    ID_ILLEGAL_NAME       = 1

*    OTHERS                = 2

            .

  if sy-subrc <> 0.

* Implement suitable error handling here

  endif.

 

 

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 '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 eq 0.

* Implement suitable error handling here

* LOOP  AT IT_EXCEL INTO WA_EXCEL WHERE

 

  loop at it_excel into wa_excel.

*BREAK AN_ABAP1.

    case wa_excel-col.

      when '0001'.

        wa_ko01-auart = wa_excel-value.

       when '0002'.

        wa_ko01-ktext = wa_excel-value.

        when '0003'.

        wa_ko01-bukrs = wa_excel-value.

         when '0004'.

        wa_ko01-gsber = wa_excel-value.

        when '0005'.

        wa_ko01-werks = wa_excel-value.

         when '0006'.

        wa_ko01-scope = wa_excel-value.

         when '0007'.

        wa_ko01-prctr = wa_excel-value.

         when '0008'.

        wa_ko01-waers = wa_excel-value.

        when '0009'.

        wa_ko01-astkz = wa_excel-value.

        endcase.

         at end of row.

         append wa_ko01 to it_ko01.

          clear wa_ko01.

        endat.

 

*       CLEAR WA_EXCEL.

        endloop.

        else.

          message 'ERROR IN DATA UPLOAD FROM EXCEL FILE' type 'E'.

        endif.

 

 

*perform open_group.

 

loop at it_ko01 into wa_ko01.

   clear bdcdata.

   refresh bdcdata.

 

perform bdc_dynpro      using 'SAPMKAUF' '0100'.

perform bdc_field       using 'BDC_CURSOR'

                               'COAS-AUART'.

perform bdc_field       using 'BDC_OKCODE'

                               '/00'.

perform bdc_field       using 'COAS-AUART'

                              " '0400'.

                              wa_ko01-auart.

perform bdc_dynpro      using 'SAPMKAUF' '0600'.

perform bdc_field       using 'BDC_OKCODE'

                               '=BUT2'.

perform bdc_field       using 'COAS-KTEXT'

                               "'Training Proram'.

                                wa_ko01-ktext.

perform bdc_field       using 'BDC_CURSOR'

                               'COAS-SCOPE'.

perform bdc_field       using 'COAS-BUKRS'

                               "'1111'.

                                wa_ko01-bukrs.

perform bdc_field       using 'COAS-GSBER'

                               "'7777'.

                                wa_ko01-gsber.

perform bdc_field       using  'COAS-WERKS'

                                wa_ko01-werks.

perform bdc_field       using 'COAS-SCOPE'

                              " 'OCOST'.

                               wa_ko01-scope.

perform bdc_field       using 'COAS-PRCTR'

                               "'7777'.

                                wa_ko01-prctr.

perform bdc_dynpro      using 'SAPMKAUF' '0600'.

perform bdc_field       using 'BDC_OKCODE'

                               '=VARI'.

perform bdc_field       using 'COAS-KTEXT'

                               "'Training Proram'.

                               wa_ko01-ktext.

perform bdc_field       using 'BDC_CURSOR'

                               'COAS-ASTKZ'.

perform bdc_field       using 'COAS-WAERS'

                               "'INR'.

                                wa_ko01-waers.

perform bdc_field       using 'COAS-ASTKZ'

                               "'X'.

                                wa_ko01-astkz.

perform bdc_dynpro      using 'SAPMKAUF' '0600'.

perform bdc_field       using 'BDC_OKCODE'

                               '=SICH'.

perform bdc_field       using 'COAS-KTEXT'

                               "'Training Proram'.

                               wa_ko01-ktext.

perform bdc_field       using 'BDC_CURSOR'

                               'COAS-AUTYP'.

perform bdc_field       using 'COAS-WAERS'

                               "'INR'.

                               wa_ko01-waers.

*perform bdc_transaction using 'KO01'.

 

call transaction 'KO01' using bdcdata mode update update 'S' messages into it_msg.

clear wa_ko01.

*CONTINUE.

endloop.

 

*perform close_group.

 

 

 

 

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 eq 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.

 

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

*        Insert field                                                  *

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

form bdc_field using fnam fval.

*  if fval <> nodata.

     clear bdcdata.

     bdcdata-fnam = fnam.

     bdcdata-fval = fval.

     append bdcdata.

*  endif.

endform.

 

 

 

 

Thanks

Sabyasachi


Viewing all articles
Browse latest Browse all 935

Trending Articles



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