Archive for January, 2013

ABAP – Removing the last character from a string

data: var1 type string,       str_len type i. var1 = 'abc1234f'. str_len = STRLEN( var1 ).  //" str_len = 8." str_len = str_len - 1.       // "str_len = 8 - 1 =7." var1 = var1+0(str_len).  // "var1 = abc1234"  . " f "  is removed.   Explanation: var1+0(str_len) means var1 starting location 0, number of ...

. Read More →

ABAP – Getting last character of string

data: var1 type string,       len type i, var2 type i. var = 'abc1234f'. len = strlen( var ). var2 = len - 1. write: 'The last character is', var1+var2(1). //Output: The last character is f. In the last line var1+var2(1) , var1+var2 indicates the 8th character of the string ...

. Read More →

ABAP – ALSM_EXCEL_TO_INTERNAL_TABLE

The Function Module  ALSM_EXCEL_TO_INTERNAL_TABLE is used for uploding data from the excel sheet to the internal table in the program. Importing Parameters filename                     -  Name of the excel filename. i_begin_col              - Starting  column. i_begin_row         ...

. Read More →

ABAP – Uploading from the excel to one table

Program to uplaod data from excel file to database table   1. Initialization: DATA: WA_ZTAR_0008 TYPE ZTAR_0008, it_ZTAR_0008 TYPE STANDARD TABLE OF ZTAR_0008. DATA: p_file1 TYPE rlgrap-filename. CONSTANTS: c_colbeg TYPE i VALUE 1, c_rowbeg TYPE i VALUE 2, c_colend TYPE i VALUE 7, c_rowend TYPE i VALUE 95384. DATA:it_alsmex_tabline TYPE STANDARD TABLE OF alsmex_tabline, wa_alsmex_tabline TYPE alsmex_tabline.   2. Selection Option: *--- Upload File details SELECTION-SCREEN BEGIN OF BLOCK block1 WITH FRAME TITLE text-t01. PARAMETERS: p_ws_fil TYPE string.  " WS File name SELECTION-SCREEN END   OF BLOCK block1. **&--------------------------------------------------------------------- ** *At Selection Screen **&--------------------------------------------------------------------- ** AT SELECTION-SCREEN. IF  p_ws_fil IS INITIAL. MESSAGE 'Provide Work Station file path and name'(002) TYPE 'E'. WRITE: 'Provide Work Station file path and name'(002). endif. *&--------------------------------------------------------------------- * *At Selection Screen on Value Request for Upload/Download files *&--------------------------------------------------------------------- AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_ws_fil. *Get the File name and path on Work Station PERFORM get_ws_file CHANGING p_ws_fil.   3. Start of selection:   * Read input file PERFORM frm_upload_file  USING p_ws_fil. *end-of-selection. PERFORM update_table.   4. Sub routines:   *&---------------------------------------------------------------------* *&      Form  GET_WS_FILE *&---------------------------------------------------------------------* *       text *----------------------------------------------------------------------* *      <--P_P_WS_FIL  text *----------------------------------------------------------------------* FORM get_ws_file CHANGING file TYPE any. DATA: p_file TYPE rlgrap-filename. CALL FUNCTION 'F4_FILENAME' EXPORTING *   PROGRAM_NAME  = SYST-CPROG *   DYNPRO_NUMBER = SYST-DYNNR field_name    = 'P_FILE' IMPORTING file_name     = p_file. file = p_file. ENDFORM.                    " GET_WS_FILE *&---------------------------------------------------------------------* *&      Form  FRM_UPLOAD_FILE *&---------------------------------------------------------------------* *       text *----------------------------------------------------------------------* *      -->P_P_WS_FIL  text *----------------------------------------------------------------------* FORM frm_upload_file  USING    p_file TYPE any. REFRESH it_ztar_0008. CLEAR wa_ztar_0008. p_file1 = p_file. CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE' EXPORTING filename                = p_file1 i_begin_col             = c_colbeg i_begin_row             = c_rowbeg i_end_col               = c_colend i_end_row               = c_rowend TABLES intern                  = it_alsmex_tabline EXCEPTIONS inconsistent_parameters = 1 upload_ole              = 2 OTHERS                  = 3. IF sy-subrc <> 0. *    implement suitable error handling here ENDIF. data: l_date(10) type c. DATA: l_date1 TYPE endda, lv_dd TYPE char02, lv_mm TYPE char02, lv_yyyy TYPE char04. IF it_alsmex_tabline IS NOT INITIAL. LOOP AT it_alsmex_tabline INTO wa_alsmex_tabline. AT NEW row. CLEAR wa_ztar_0008. ENDAT. CASE wa_alsmex_tabline-col. WHEN '0001'. wa_ztar_0008-pernr = wa_alsmex_tabline-value. WHEN '0002'. l_date = wa_alsmex_tabline-value. SPLIT l_date AT '/' INTO lv_mm  lv_dd  lv_yyyy. IF strlen( lv_dd ) LT 2. CONCATENATE '0' lv_dd INTO lv_dd. ENDIF. IF strlen( lv_mm ) LT 2. CONCATENATE '0' lv_mm INTO lv_mm. ENDIF. CONCATENATE lv_yyyy lv_mm lv_dd   INTO l_date1. wa_ztar_0008-endda = l_date1. CLEAR :l_date1, l_date, lv_dd , lv_mm , lv_yyyy. WHEN '0003'. l_date = wa_alsmex_tabline-value. SPLIT l_date AT '/' INTO lv_mm  lv_dd  lv_yyyy. IF strlen( lv_dd ) LT 2. CONCATENATE '0' lv_dd INTO lv_dd. ENDIF. IF strlen( lv_mm ) LT 2. CONCATENATE '0' lv_mm INTO lv_mm. ENDIF. CONCATENATE lv_yyyy lv_mm lv_dd   INTO l_date1. wa_ztar_0008-begda =  l_date1. CLEAR :l_date1, l_date, lv_dd , lv_mm , lv_yyyy. WHEN '0004'. wa_ztar_0008-trfar = wa_alsmex_tabline-value. WHEN '0005'. wa_ztar_0008-trfgb = wa_alsmex_tabline-value. WHEN '0006'. wa_ztar_0008-trfgr = wa_alsmex_tabline-value. WHEN '0007'. wa_ztar_0008-TRFST = wa_alsmex_tabline-value. ENDCASE. AT END OF row. APPEND wa_ztar_0008 TO it_ztar_0008. CLEAR: wa_ztar_0008, wa_alsmex_tabline. ENDAT. ENDLOOP. ENDIF. *} Del HPDEV0248   28/11/2012 ENDFORM.                    " FRM_UPLOAD_FILE *&---------------------------------------------------------------------* *&      Form  UPDATE_TABLE *&---------------------------------------------------------------------* *       text *----------------------------------------------------------------------* *  -->  p1        text *  <--  p2        text *----------------------------------------------------------------------* FORM update_table . IF NOT it_ztar_0008 IS INITIAL. INSERT ZTAR_0008 FROM TABLE it_ztar_0008 ACCEPTING DUPLICATE KEYS . COMMIT WORK. IF sy-subrc = 0. WRITE: 'Records has been updated from input file to ZTAR_0008 Table'(003). ELSE. WRITE: 'Records has not updated from input file'(004). ENDIF. ELSE. WRITE : 'Data is not available in input file '(005). ENDIF. ENDFORM.                    " UPDATE_TABLE          

. Read More →

ABAP – Deleting from the a table

Deleting from the table for example T777F depending on some condition   TABLES:T777F. DATA: IT_T777F TYPE STANDARD TABLE OF T777F. SELECT * FROM T777F INTO TABLE IT_T777F WHERE FCODE = <value>. IF SY-SUBRC EQ 0.   DELETE  T777F FROM TABLE IT_T777F.   COMMIT WORK. ENDIF. IF SY-SUBRC EQ 0.   WRITE: 'RECORDS DELETED SUCCESSFULLY'. ENDIF.

. Read More →

ABAP – Coping records from one table to another

Copying from the table T777F  into the table  ZCOPY_ T777F   TABLES: T777F, ZCOPY_ T777F. DATA: IT_T777F  TYPE STANDARD TABLE OF  T777F   SELECT * FROM T777F INTO table IT_T777F. INSERT ZCOPY_ T777F FROM TABLE  IT_T777F. COMMIT WORK. IF sy-subrc EQ 0. WRITE: 'Insertion successfully completed'. ENDIF.

. Read More →

ABAP – Making Table entries not to release

If u donot want to release the transport the entries then make the field Recording routine in Table Maintenance Generator of the table as “no user , recording routine”.

. Read More →