Monday, November 10, 2014

ABAP Tip - Revoke CTS released.

When you implement CTS( or CR-Change Reqeust) to production environment, you should follow the proper quality process under the guide of each company. So, It entails additional tasks each CTS. Sometimes, we release the CTS by mistake. In this case, we can revoke the CTS TO previous status.

There are 2 wasy to revoke CTS released.
1.  Use program : RDDIT076

2.  Change the  table data : E070.

1.  First way - Use program : RDDIT076
It is very simple to use the program. You can just input the CTS release and double click the line to change the CTS status. In poupup screen, it shows the status column which you can change to status ‘D’(D:Modifiable)


 






2.  Second Way : Change the  table data : E070.

The below figure shows the CTS released.





In table E070, the status of cts is ‘R’.




If you change the status to D(D-Modifiable), the cts revoke to changeable status.

 


With t-code:se09, you can see the status of CTS was reverted to ‘D’ modifiable.


In addition, there are object lists in table E071 table.


Thursday, September 18, 2014

ABAP TIP - Function module Test Data

ABAP TIP - Function module Test Data

It’s very trivial to input the test data in function module each test. As you already know, we can save the test data into test data dictionary by pressing save button.




There is another useful way to save test data for function module when function module is called from ABAP program. Let’s make a simple case how to save test data when calling some function module. After writing program, set the break point at the source where calling the function module.

 




When the program meet the debugging point, the debugger become activated. Move to next step by pressing ‘F5’.
 



If pressing the technical button in the debugger, there will be popup screen that can save test data for function module. Press Menu “Save Parameters as Test Data(SE37)”




Enter the title and save.





Moving to T-CODE:SE37 and check the test Data Directory, you can see the test data created.

 



Tuesday, September 16, 2014

ABAP TIP - External Command


ABAP TIP - External Command


You can register the UNIX command as a external command in sap system.
SAP 시스템에서 UNIX 서버의 외부 명령어를 등록하여, 실행할 있다.









1. Let’s execute T-CODE:SM49, SM69 and register external command.  Press ‘create’ icon.
2. If you want to register shell script, you should describe all directory path including shell script file. In case of UNIX command, you can write like below.
3. It’s also possible to use external command you created in T-CODE:SM36 and call external command in abap program like below example.


CONSTANTS: c_extcom    TYPE sxpgcolist-name VALUE 'ZCOMMAND,
           c_oper      TYPE syopsys VALUE 'UNIX'.

DATA: v_dir_input      TYPE sxpgcolist-parameters.  " Input Directory
DATA: t_result         TYPE STANDARD TABLE OF btcxpm.

v_dir_input = '/sapmmt'.

CALL FUNCTION 'SXPG_COMMAND_EXECUTE'
  EXPORTING
    commandname                   = c_extcom
    additional_parameters         = v_dir_input
    operatingsystem               = c_oper
  TABLES
    exec_protocol                 = t_result
  EXCEPTIONS
    no_permission                 = 1
    command_not_found             = 2
    parameters_too_long           = 3
    security_risk                 = 4
    wrong_check_call_interface    = 5
    program_start_error           = 6
    program_termination_error     = 7
    x_error                       = 8
    parameter_expected            = 9
    too_many_parameters           = 10
    illegal_command               = 11
    wrong_asynchronous_parameters = 12
    cant_enq_tbtco_entry          = 13
    jobcount_generation_error     = 14
    OTHERS                        = 15.




Monday, September 15, 2014

ABAP TIP : FILE management with CBO program

ABAP TIP : FILE management with CBO program

Let’s make a program that can upload and download file.
User can select file and upload.






Generally, we use the ‘ASC’ mode when calling function ‘GUI_UPLOAD/GUI_DOWNLOAD’.

 CALL FUNCTION 'GUI_UPLOAD'
    
EXPORTING
      filename                
gv_fname
      filetype                'ASC'


This program aims to upload/donwload file, so we must use the ‘BIN’ mode when calling function.
If we save the file as a BIN mode, it’s possible to download as a origin file.

 CALL FUNCTION 'GUI_UPLOAD'
    
EXPORTING
      filename                
gv_fname
      filetype                'BIN'

Fisrt of all, let’s create 2 table for saving header and contents of file.







And, Let’s write program and activate.

REPORT  zfile.

 
TABLES : zfilehead, zfiledata, sscrfields.
 
DATA : gs_fhead  LIKE zfilehead,
        gt_fdata  
LIKE zfiledata OCCURS WITH HEADER LINE.

*attache file
DATA : BEGIN OF gt_uptab OCCURS 0,
         content
(255TYPE x,
       
END OF gt_uptab.

DATA :  gv_length  TYPE int4,
        gv_fname   
TYPE string,
        gv_fname2  
TYPE string,
        gv_ftype   
TYPE zfilehead-filetype,
        gv_temp
(120).


DATA:   gv_work_dir TYPE string,
        gv_cmd
(128).

PARAMETERS : p_carrid TYPE s_carr_id OBLIGATORY,
             p_fname 
TYPE zfilehead-filename.
SELECTION-SCREEN FUNCTION KEY 1.

INITIALIZATION.
    sscrfields
-functxt_01 'Display file'.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fname.

DATA:   l_rc                TYPE i VALUE 1,
        l_window_title      
TYPE string,
        lt_file_table       
TYPE filetable,
        ls_file             
TYPE file_table.

CALL METHOD cl_gui_frontend_services=>file_open_dialog
    
EXPORTING
      window_title            
'Select file'
      file_filter             
'*.*'
      multiselection          
space
    
CHANGING
      file_table              
lt_file_table
      rc                      
l_rc.
      
IF sy-subrc EQ 0.
      
READ TABLE lt_file_table INDEX INTO ls_file.
      p_fname 
ls_file-filename.
      
ENDIF.

 
CLEAR: gt_uptab, gt_uptab[].
 gv_fname 
p_fname.
 
CALL FUNCTION 'GUI_UPLOAD'
    
EXPORTING
      filename                
gv_fname
      filetype                
'BIN'
    
IMPORTING
      filelength              
gv_length
    
TABLES
      data_tab                
gt_uptab.

START-OF-SELECTION.

*& file name
  
CLEAR gv_temp.
  
DO.
    
SPLIT gv_fname AT '\' INTO gv_temp gv_fname.
    
IF gv_fname EQ space.
      gv_fname 
gv_temp.
      
EXIT.
    
ENDIF.
    
IF sy-index 100. EXIT. ENDIF.
  
ENDDO.

*& file type
  
CLEAR gv_temp.
  gv_fname2 
gv_fname.
  
DO.
    
SPLIT gv_fname2 AT '.' INTO gv_temp gv_fname2.
    
IF gv_fname2 EQ space.
      gv_fname2 
gv_temp.
      
EXIT.
    
ENDIF.
    
IF sy-index 100. EXIT. ENDIF.
  
ENDDO.

  gv_ftype 
gv_fname2+0(3).
  
TRANSLATE gv_ftype TO UPPER CASE.
*& Header
  gs_fhead
-carrid   p_carrid.
  gs_fhead
-filename gv_fname.
  gs_fhead
-filetype gv_ftype.
  gs_fhead
-length   gv_length.
  
MODIFY zfilehead FROM gs_fhead.

*& Data.
  
LOOP AT gt_uptab.
    gt_fdata
-carrid p_carrid.
    gt_fdata
-content gt_uptab-content.
    gt_fdata
-seq sy-tabix.
    
APPEND gt_fdata.
  
ENDLOOP.
  
MODIFY zfiledata FROM TABLE gt_fdata.
  
IF sy-subrc EQ 0.
     
MESSAGE 'SUCCESS' TYPE 'S'.
  
ELSE.
     
MESSAGE 'ERROR' TYPE 'E'.
  
ENDIF.


  
AT SELECTION-SCREEN.
    
CHECK sscrfields-ucomm 'FC01'.
CLEAR : gs_fhead, gt_fdata, gt_fdata[].

*& Header
  
SELECT SINGLE INTO gs_fhead FROM zfilehead
                 
WHERE carrid p_carrid.
  
IF sy-subrc NE 0.
         
MESSAGE 'There is no file' TYPE 'E'.
  
ENDIF.

*& detail
  
SELECT INTO CORRESPONDING FIELDS OF TABLE gt_fdata
           
FROM zfiledata
           
WHERE carrid p_carrid.

  
CLEAR: gt_uptab, gt_uptab[].

  
SORT gt_fdata BY seq.
  
LOOP AT gt_fdata.
    gt_uptab
-content gt_fdata-content.
    
APPEND gt_uptab.
  
ENDLOOP.

* Get SAP Working Directory.
  
CALL METHOD cl_gui_frontend_services=>get_sapgui_workdir
    
CHANGING
      sapworkdir 
gv_work_dir.

*& file name
  
CONCATENATE gv_work_dir '\' gs_fhead-filename INTO gv_fname.

*& Download
  
CALL FUNCTION 'GUI_DOWNLOAD'
    
EXPORTING
      bin_filesize            
gs_fhead-length
      filename                
gv_fname
      filetype                
'BIN'
    
TABLES
      data_tab                
gt_uptab.

*& file run
  gv_cmd 
gv_fname.
  
CALL FUNCTION 'GUI_RUN'
    
EXPORTING
      command          
gv_cmd.

Select test image file and execute.



After uploading, press the button ‘display file’ and you can see the file uploaded.