Thursday, April 21, 2016

what is abs, sign, floor, ceil, trunc and frac in abap






FunctionfuncReturn value
absAbsolute value of argument arg
signSign of argument arg: -1, if the value of arg is negative; 0, if the value of arg is 0; 1, if the value of arg is positive
ceilSmallest integer that is not less than the value of the argument arg is
floorLargest integer that is not greater than the value of the argument arg is
truncValue of the integer part of the argument arg
fracValue of the decimal places of the argument arg



DATA TYPE DECIMALS 2.
DATA TYPE DECIMALS VALUE '-3.55'.
ABS).  WRITE:  'ABS: 'n.
SIGN)WRITE'SIGN: 'n.
CEIL)WRITE'CEIL: 'n.
FLOOR)WRITE'FLOOR:'n.
TRUNC)WRITE'TRUNC:'n.
FRAC)WRITE'FRAC: 'n.

output: 

ABS:               3.55
SIGN:              1.00-
CEIL:              3.00-
FLOOR:          4.00-
TRUNC:          3.00-
FRAC:             0.55-



Sunday, April 3, 2016

Convert csv file and send to ftp server

DATAIT_FTP TYPE STANDARD TABLE OF ZFTPSERVERLIST ,
      WA_FTP 
TYPE ZFTPSERVERLIST,
      L_SLEN 
TYPE I,
      LV_USER
(30TYPE C,
      LV_PWD
(30TYPE C,
      C_KEY 
TYPE I VALUE 26101957.

DATATO_FILE TYPE CHAR300.
DATAMI_HANDLE TYPE I.
DATAitab1  TYPE truxs_t_text_data.

PERFORM CONVERT_TO_CSV.
PERFORM SERVER_CONN.
PERFORM R3_FTP USING TO_FILE.

FORM convert_to_csv .

  
CALL FUNCTION 'SAP_CONVERT_TO_TEX_FORMAT'
  
EXPORTING
    i_field_seperator    
','
    I_LINE_HEADER        
'X'
  
TABLES
    i_tab_sap_data       
ITAB[] " final file
    
"FIELDNAMES           = T_DESC  " for header file
  
CHANGING
    i_tab_converted_data 
itab1[]
  
EXCEPTIONS
    conversion_failed    
1
    
OTHERS               2.
  
IF sy-subrc <> 0.
    
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  
ENDIF.

ENDFORM.

FORM r3_ftp  USING    p_to_file.
  
""""" SEND FILE TO SERVER""""""
  
CALL FUNCTION 'FTP_R3_TO_SERVER'
  
EXPORTING
    HANDLE         
MI_HANDLE
    FNAME          
TO_FILE          "file path of destination system
    CHARACTER_MODE 
'X'
  
TABLES
    
TEXT           itab1
  
EXCEPTIONS
    TCPIP_ERROR    
1
    COMMAND_ERROR  
2
    DATA_ERROR     
3
    
OTHERS         4.

  
IF sy-subrc <> 0.
    
WRITE 'FILE NOT SEND'.
  
ELSE.
    
WRITE 'FILE SEND'.
  
ENDIF.

ENDFORM.

FORM server_conn .

  
SELECT FROM ZFTPSERVERLIST CLIENT SPECIFIED
  
INTO CORRESPONDING FIELDS OF TABLE IT_FTP
  
WHERE MANDT SY-MANDT
  
AND   ZCOUNTRY 'BD'.

  
CLEAR WA_FTP.
  
READ TABLE IT_FTP INTO WA_FTP INDEX 1.

*----CONNECTING TO FTP SERVER.
  
PERFORM FTP_CONNECT USING WA_FTP-ZUSER WA_FTP-ZPASSWD WA_FTP-ZHOST.

*----CHECKING SUCCESSFUL FTP CONNECTION
  
CHECK SY-SUBRC 0.
  
CLEARTO_FILE.
  
" FILE NAME CREATIONN
  
CONCATENATE WA_FTP-zapp 'test' '_' DATE '.csv' INTO TO_FILE.

ENDFORM.


FORM ftp_connect  USING   LV_USER LV_PWD LV_HOST.

  L_SLEN 
STRLENLV_PWD ).

  
CALL FUNCTION 'HTTP_SCRAMBLE'
  
EXPORTING
    SOURCE      
LV_PWD
    SOURCELEN   
L_SLEN
    
KEY         C_KEY
  
IMPORTING
    DESTINATION 
LV_PWD.

  
CALL FUNCTION 'FTP_CONNECT'
  
EXPORTING
    USER            
LV_USER "Your SAP-UNIX FTP user name (case sensitive)
    PASSWORD        
LV_PWD  "Your SAP-UNIX server host name (case sensitive)
    HOST            
LV_HOST
    RFC_DESTINATION 
'SAPFTPA'
  
IMPORTING
    HANDLE          
MI_HANDLE
  
EXCEPTIONS
    NOT_CONNECTED   
1
    
OTHERS          2.

ENDFORM.

How to read data from schedule job

DATAJOBNAME TYPE TBTCO-JOBNAME.
DATAJOBCOUNT TYPE TBTCO-JOBCOUNT.
DATALISTIDENT TYPE TBTCPV-LISTIDENT.
DATAJOBNO TYPE TSP01-RQIDENT.
DATADATE TYPE C LENGTH 12.

DATAflag TYPE I.

DATABEGIN OF i_outtab OCCURS 0,
  str
(255TYPE C,
END OF i_outtab.


DATABEGIN OF BUFFER OCCURS 100000,
  
TEXT(6000TYPE C,
END OF BUFFER.

DATAstartline TYPE Iendline TYPE I.


" GETTING DATE WISE SPOOL NUMBER

SELECT SINGLE JOBCOUNT FROM TBTCO INTO JOBCOUNT WHERE JOBNAME 'job_name' AND SDLSTRTDT SY-DATUM.

SELECT SINGLE LISTIDENT FROM TBTCPV INTO LISTIDENT WHERE JOBCOUNT JOBCOUNT AND JOBNAME 'job_name' .

CONCATENATE SY-DATUM+6(2SY-DATUM+4(2SY-DATUM+0(4INTO DATE SEPARATED BY '_'.
JOBNO 
LISTIDENT.

IF JOBNO NE '0'.
  
" FETCHING SPOOL DATA TO BUFFER
  startline 
1.

  
DO.
    
REFRESH BUFFER.
    endline 
startline + 99999.
    
CALL FUNCTION 'RSPO_RETURN_SPOOLJOB'
    
EXPORTING
      rqident              
JOBNO
      first_line           
startline
      last_line            
endline
      desired_type         
'RAW'
  
    
TABLES
      
BUFFER               BUFFER
    
EXCEPTIONS
      no_such_job          
1
      job_contains_no_data 
2
      selection_empty      
3
      no_permission        
4
      can_not_access       
5
      read_error           
6
      type_no_match        
7
      
OTHERS               8.
    
IF sy-subrc <> 0.
      
EXIT.
    
ENDIF.

    
LOOP AT BUFFER.
      i_outtab
-str BUFFER-TEXT.
      
APPEND i_outtab.
      
CLEAR i_outtab.
    
ENDLOOP.
    startline 
endline + 1.
  
ENDDO.

EXIT, STOP, CONTINUE, RETURN and LEAVE PROGRAM

EXIT: The EXIT command will stop the LOOP passings, exit from the SUBROUTINES..etc.

The behavior of EXIT keyword is depends on where you use it.

  • If you use EXIT keyword inside IF .. ENDIF., it will comes out of the program.
  • If you use EXIT inside LOOP .. ENDLOOP., it will come out of loop.
  • If you use EXIT inside FORM .. ENDFORM., it will comes out of form (subroutine)

Leave Program : LEAVE PROGRAM always leaves the current program - there is never any processing after LEAVE PROGRAM 

STOP

STOP is a statement which is used to stop processing an event block, ex: If I have two events START-OF-SELECTION and END-OF-SELECTION in my program, If I use STOP keyword in START-OF-SELECTION, the keyword will exits start-of-selection and goes to END-OF-SELECTION.

CONTINUE

CONTINUE is a statement, which is used to skip execution of a record inside loop.. endloop, do..endo, while..endwhile etc. 

RETURN

RETURN is a statement which is used to stop processing of current block immediately.