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

SERVICE MASTER UPLOAD Program Through BAPI With Long Text

$
0
0

Hi,

Its very important program for service master upload(MM module).

 

 

 

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

*                PROGRAM INFORMATION

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

*  PROGRAM....... ZMM_SERVICE_BAPI

*  TITLE......... SERVICE MASTER UPLOAD

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

* FUNCTIONAL....

* START DATE.... 23/07/2013

* END DATE.......23/07/2013

* DEV.CLASS......ZMM

* TCODE..........ZMM_SERVICE

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

*  TRANSPORTNR...  AEDK900242

*  COPIED FROM... N/A

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

*                PROGRAM FUNCTION:

* This conversion program is to Upload SERVICE 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 zmm_service_bapi  no standard page heading .

 

****Data Declaration

tables : asmd, asmdt.

type-pools: truxs.

 

types : begin of ty_serv,

         asktx type asmdt-asktx,

         astyp type asmd-astyp,

         meins type asmd-meins,

         matkl type asmd-matkl,

         bklas type asmd-bklas,

         chgtext type asmd-chgtext,

         text(1000) type c,

         ser_no type asmd-ean11,

         end of ty_serv.

 

data  : line1 type tdline,

         line2 type tdline.

 

data : it_serv type bapisrv_asmd,

        ls_return like bapiret2 occurs 0 with header line.

data : header like thead,

        lines like tline occurs 0 with header line.

data : service like   bapisrv_asmd-service.

data : im_service_datax like   bapisrv_asmdx.

data : it_desc type table of bapisrv_asmdt with header line.

data : tab_serv type table of ty_serv with header line.

data : wa_serv type  ty_serv.

data : it_intern type alsmex_tabline occurs 0 with header line.

data : tab_text type table of bapisrv_text ,

        wa_text type bapisrv_text .

data : wasmd type asmd,

        wasmdt type asmdt.

 

***** Selection file from selection screen

 

selection-screen begin of block b1 with frame title t1.

selection-screen comment 30(30) lb2.

selection-screen begin of line.

selection-screen comment 5(30) lb1.

 

parameters : p_file type rlgrap-filename obligatory ,

              p_begcol type i default 1 no-display,

              p_begrow type i default 3 no-display,

              p_endcol type i default 8 no-display,

              p_endrow type i default 32000 no-display.

selection-screen end of line.

selection-screen end of block b1.

 

 

*****Initialization Event

 

initialization.

   lb1 = 'File Name for Service Upload'.

   format color 3.

   lb2 = 'FILE SHOULD BE IN EXCEL FORMAT'.

   format color off.

   t1 = 'Service Upload'.

 

******At selection Screen Event

 

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 Event

 

 

start-of-selection.

   perform convert_text_itab.

 

   perform  upload_service.

 

*&---------------------------------------------------------------------*

*&      Form  UPLOAD_SERVICE

*&---------------------------------------------------------------------*

*       text

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

*  -->  p1        text

*  <--  p2        text

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

form upload_service .

   loop at tab_serv.

     clear it_serv.

     clear : line1 , line2.

     translate tab_serv-astyp to upper case.

     condense tab_serv-meins.

     translate tab_serv-meins to upper case.

     it_serv-matl_group = tab_serv-matkl.

 

     call function 'CONVERSION_EXIT_CUNIT_INPUT'

       exporting

         input                = tab_serv-meins

         language             = sy-langu

      importing

        output               = it_serv-base_uom .

 

 

*    IT_SERV-BASE_UOM   = TAB_SERV-MEINS.

     it_serv-serv_cat   = tab_serv-astyp.

     it_serv-val_class  = tab_serv-bklas.

     it_serv-chgtext = tab_serv-chgtext.

     it_serv-ean_upc = tab_serv-ser_no.

     clear it_desc.

     refresh it_desc.

 

     it_desc-language = 'E'.

     it_desc-short_text = tab_serv-asktx.

     append it_desc.

     clear ls_return.

     refresh ls_return.

 

 

     call function 'BAPI_SERVICE_CREATE'

       exporting

         im_service_data     = it_serv

         im_service_datax    = im_service_datax

       importing

         service             = service

       tables

         return              = ls_return

         service_description = it_desc.

 

 

     call function 'BAPI_TRANSACTION_COMMIT'

       exporting

         wait = 'X'.

 

     loop at ls_return.

 

       if ls_return-type = 'E'.

 

         write:/ 'Error:' ,ls_return-message ,'for SERVICES:' , tab_serv-asktx color 6.

       elseif ls_return-type = 'S'.

 

         write  : / 'SERVICE CREATED' , service color 5.

         call function 'BAPI_TRANSACTION_COMMIT'

           exporting

             wait = 'X'.

 

         clear ls_return.

       endif.

     endloop.

     if not service is initial.

       header-tdobject = 'ASMD'.

       header-tdname = service.

       header-tdid 'LTXT'.

       header-tdspras = sy-langu.

       lines-tdformat = '*'.

       lines-tdline = tab_serv-asktx.

       append lines.

 

 

 

       call function 'SAVE_TEXT'

         exporting

           header          = header

           savemode_direct = 'X'

         tables

           lines           = lines

         exceptions

           id              = 1

           language        = 2

           name            = 3

           object          = 4

           others          = 5.

       if sy-subrc <> 0.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

       endif.

 

       call function 'COMMIT_TEXT'.

 

       if sy-subrc = 0.

         write : / 'update successfully'.

       endif.

       refresh : tab_text[] , ls_return[]  , lines[] , it_desc[].

       clear : header , it_serv , im_service_datax , service.

     endif.

   endloop.

 

 

 

endform.                    " UPLOAD_SERVICE

*&---------------------------------------------------------------------*

*&      Form  CONVERT_TEXT_ITAB

*&---------------------------------------------------------------------*

*       text

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

*  -->  p1        text

*  <--  p2        text

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

form convert_text_itab .

 

   call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'

     exporting

       filename    = p_file

       i_begin_col = p_begcol

       i_begin_row = p_begrow

       i_end_col   = p_endcol

       i_end_row   = p_endrow

     tables

       intern      = it_intern.

 

   if it_intern[] is not initial.

     data : lv_index type i.

     field-symbols <fs>.

*--- Sorting the internal table

     sort it_intern by row col.

     clear it_intern.

     loop at it_intern.

       move it_intern-col to lv_index.

*--- Assigning the each record to an internal table row

       assign component lv_index of structure tab_serv to <fs>.

*--- Asigning the field value to a field symbol

       move it_intern-value to <fs>.

       at end of row.

         append tab_serv.

         clear tab_serv.

       endat.

     endloop.

   else.

     write:/ 'Data doesnot present in Excel File' color 6.

   endif.

endform.                    "CONVERT_TEXT_ITAB

 

 

 

 

Regards

Sabyasachi Karforma


Viewing all articles
Browse latest Browse all 935

Trending Articles



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