Sunday, June 29, 2014

Example Code For Selection Screen Output

REPORT ZSELECTION_SCREEN.

selection-screen :begin of block test with frame title text-001
parameters:radiobutton group one user-command test
                 b radiobutton group one
selection-screen:end of block test
selection-screen:begin of block test2 with frame title text-002
parameters:input1(10TYPE MODIF ID TL
                 input2(10TYPE MODIF ID TT
selection-screen:end of block test2
   
AT SELECTION-SCREEN OUTPUT
  IF 'X'
      LOOP AT SCREEN
          CHECK SCREEN-GROUP1 'TT'
          SCREEN-INPUT '0'
          MODIFY SCREEN
      ENDLOOP
  ENDIF.

  IF 'X'
      LOOP AT SCREEN
         CHECK SCREEN-GROUP1 'TL'
         SCREEN-INPUT '0'
         MODIFY SCREEN
      ENDLOOP
  ENDIF.

Thursday, April 24, 2014

HOW TO BLOCK MATERIAL MASTER

Material master locked is when one user will try to use material code which is currently used by another user so he will get the message that material is locked by user.
Blocked means we can't do any further processing action at the block level and using program run we can able to delete the material, using MARA, MARC MARD tables can find the different level of Blocking and Flag for deletions.(Tcode MM06)
Using T.code SE11--> MARA -->LVORM(X)

Monday, March 3, 2014

How to create cockpit


REPORT ZCOCKPIT no standard page heading.
tables : sscrfields.

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

selection-screen skip 1.
selection-screen begin of line.
selection-screen : position 10, pushbutton (30) p_but1 user-command but1,
                   pushbutton (30) p_but2 user-command but2,
                   pushbutton (30) p_but3 user-command but3.

selection-screen end of line.

selection-screen begin of line.
selection-screen : position 10, pushbutton (30) p_but4 user-command but4,
                   pushbutton (30) p_but5 user-command but5,
                   pushbutton (30) p_but6 user-command but6.
selection-screen end of line.

selection-screen : end of block block1.


initialization.

  p_but1  = 'CREATE SALES ORDER'.
  p_but2  = 'CREATE OBD ORDER'.
  p_but3  = 'CREATE GR'.
  p_but4  = 'CREATE PGI ORDER'.
  p_but5  = 'CREATE SHIPMENT ORDER'.
  p_but6  = 'MISC'.

at selection-screen.
  case sscrfields-ucomm.
    when 'BUT1'.
      leave to transaction 'VA01'.
    when 'BUT2'.
      leave to transaction 'VL01N'.
    when 'BUT3'.
      leave to transaction 'MIGO'.
    when 'BUT4'.
      leave to transaction 'VL02N'.
    when 'BUT5'.
      leave to transaction 'VT01N'.
    when 'BUT6'.
      leave to transaction 'VT02N'.
  endcase.



Output:



Wednesday, December 4, 2013

CREATE XML FILE and SEND TO FTP SERVER


REPORT ZXML_FILE .

type-pools: ixml.
tables: vbak.

types: begin of ty_vbak,
       vbeln type vbak-vbeln,
       auart type vbak-auart,
      end of ty_vbak.

data: ty_ftp type standard table of zftpinfo,
      wa_ftp type zftpi,
      l_slen type i,
      lv_user(30) type c,
      lv_pwd(30) type c,
      c_key type i value 26101957.

data: begin of t_title occurs 0,
      title(4000) type c,
      end of t_title.
data: temp_file(200) type c.
data: to_file type char30000.
data: c_gw type string.
data: mi_handle type i.

data: t_vbak type ty_vbak occurs 0 with header line.

selection-screen begin of block b1 with frame title text-001.
select-options: so_num for vbak-vbeln.
selection-screen end of block b1.

*START OF SELECTION
start-of-selection.

select
  vbeln auart
  from vbak into corresponding fields of table t_vbak
  where vbeln in so_num.

"" FOR GETTING FTP SEVER CONNECTION INFO FROM MAINTAING TABLE
select * from zftpinfo client specified
    into corresponding fields of table ty_ftp
    where mandt = sy-mandt
    and   zcountry = 'BD'.

  clear wa_ftp.
  read table ty_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.

    if t_vbak[] is not initial.
    perform c_xml. " FOR CREATING XML FILE
    endif.

form c_xml.

  clear t_title[].
 "" SERVER DESTINATION FILE PATH EX: /.../.../.../
  concatenate 'SERVER FILE PATH' 'SOINFO' '.xml'  into to_file.

*----BUILDING THE XML FILE
  t_title-title = '<?xml version="1.0" encoding="UTF-8"?>'.
  append t_title.
  t_title-title = '<n1:SalesOderInfo xmlns:n1="SalesOderInfo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'.
  append t_title.

  loop at t_vbak.
    concatenate '<SONUM>' t_vbak-vbeln '</SONUM>' into temp_file.
    t_title-title = temp_file.
    append t_title.
    clear temp_file.

    concatenate '<DOCTYPE>' t_vbak-auart '</DOCTYPE>' into temp_file.
    t_title-title = temp_file.
    append t_title.
    clear temp_file.

    endloop.

    t_title-title = '</n1:SalesOderInfo>'.
    append t_title.

  perform r3_ftp using to_file.

endform.



form r3_ftp using to_file.
  call function 'FTP_R3_TO_SERVER'
    exporting
      handle         = mi_handle
      fname          = to_file          "file path of destination system
      character_mode = 'X'
    tables
      text           = t_title
    exceptions
      tcpip_error    = 1
      command_error  = 2
      data_error     = 3
      others         = 4.
endform.

form ftp_connect using lv_user lv_pwd lv_host.

  l_slen = strlen( lv_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.

Sunday, December 1, 2013

Simple Code to consume Web service using SAP ABAP

REPORT  zpw_webservice.

*&---------------------------------------------------------------------*
*&      Selection Screen
*&---------------------------------------------------------------------*
PARAMETERS : p_cnt TYPE t005t-landx .

*&---------------------------------------------------------------------*
*&      Types and Data
*&---------------------------------------------------------------------*
DATA:  http_client    TYPE REF TO if_http_client ,
       http_url       TYPE string                ,
       p_content      TYPE string                .

*&---------------------------------------------------------------------*
*&      Start of Selection
*&---------------------------------------------------------------------*
START-OF-SELECTION .

* Build the url string based on input
  CONCATENATE 'http://www.webservicex.net/globalweather.asmx'
  '/GetCitiesByCountry?CountryName='
  p_cnt
  INTO http_url .

* Creation of new IF_HTTP_Client object
  CALL METHOD cl_http_client=>create_by_url
    EXPORTING
      url                = http_url
    IMPORTING
      client             = http_client
    EXCEPTIONS
      argument_not_found = 1
      plugin_not_active  = 2
      internal_error     = 3
      OTHERS             = 4.

  http_client->request->set_header_field( name  = '~request_method'
  value = 'GET' ).
* Send the request
  http_client->send( ).

* Reterive the result
  CALL METHOD http_client->receive
    EXCEPTIONS
      http_communication_failure = 1
      http_invalid_state         = 2
      http_processing_failed     = 3
      OTHERS                     = 4.

  p_content = http_client->response->get_cdata( ).
  REPLACE  ALL OCCURRENCES OF '&lt;' IN p_content WITH '<' .
  REPLACE  ALL OCCURRENCES OF '&gt;' IN p_content WITH '>' .

*&---------------------------------------------------------------------*
*&      Processing string
*&---------------------------------------------------------------------*

  DATA : moff  TYPE syst-tabix ,
         moff1 TYPE syst-tabix ,
         len   TYPE syst-tabix .

  DO .
    FIND '<City>' IN SECTION OFFSET moff OF p_content IGNORING CASE MATCH OFFSET moff .
    IF sy-subrc = 0 .
      moff = moff + 6 .
      FIND '</City>' IN SECTION OFFSET moff OF p_content IGNORING CASE MATCH OFFSET moff1 .
      len = moff1 - moff .
      WRITE : / p_content+moff(len) .
    ELSE.
      EXIT.
    ENDIF.
  ENDDO .

In this code processing of XML string is done using FIND statement. SAP has introduced command CALL TRANSFORMATION since Basis release 6.10 for XML processing. This command CALL TRANSFORMATION process the whole XML string based on defined transformation and return it in variable/internal table. Transformations can be defined using transaction SE80. Ok I am leaving this topic for next blog ;)



 

Simple Code to consume Web service using SAP ABAP

REPORT  zpw_webservice.
 
*&---------------------------------------------------------------------*
*&      Selection Screen
*&---------------------------------------------------------------------*
PARAMETERS : p_cnt TYPE t005t-landx .
 
*&---------------------------------------------------------------------*
*&      Types and Data
*&---------------------------------------------------------------------*
DATA:  http_client    TYPE REF TO if_http_client ,
       http_url       TYPE string                ,
       p_content      TYPE string                .
 
*&---------------------------------------------------------------------*
*&      Start of Selection
*&---------------------------------------------------------------------*
START-OF-SELECTION .
 
* Build the url string based on input
  '/GetCitiesByCountry?CountryName='
  p_cnt
  INTO http_url .
 
* Creation of new IF_HTTP_Client object
  CALL METHOD cl_http_client=>create_by_url
    EXPORTING
      url                = http_url
    IMPORTING
      client             = http_client
    EXCEPTIONS
      argument_not_found = 1
      plugin_not_active  = 2
      internal_error     = 3
      OTHERS             = 4.
 
  http_client->request->set_header_field( name  = '~request_method'
  value = 'GET' ).
* Send the request
  http_client->send( ).
 
* Reterive the result
  CALL METHOD http_client->receive
    EXCEPTIONS
      http_communication_failure = 1
      http_invalid_state         = 2
      http_processing_failed     = 3
      OTHERS                     = 4.
 
  p_content = http_client->response->get_cdata( ).
  REPLACE  ALL OCCURRENCES OF '&lt;' IN p_content WITH '<' .
  REPLACE  ALL OCCURRENCES OF '&gt;' IN p_content WITH '>' .
 
*&---------------------------------------------------------------------*
*&      Processing string
*&---------------------------------------------------------------------*
 
  DATA : moff  TYPE syst-tabix ,
         moff1 TYPE syst-tabix ,
         len   TYPE syst-tabix .
 
  DO .
    FIND '<City>' IN SECTION OFFSET moff OF p_content IGNORING CASE MATCH OFFSET moff .
    IF sy-subrc = 0 .
      moff = moff + 6 .
      FIND '</City>' IN SECTION OFFSET moff OF p_content IGNORING CASE MATCH OFFSET moff1 .
      len = moff1 - moff .
      WRITE : / p_content+moff(len) .
    ELSE.
      EXIT.
    ENDIF.
  ENDDO .

In this code processing of XML string is done using FIND statement. SAP has introduced command CALL TRANSFORMATION since Basis release 6.10 for XML processing. This command CALL TRANSFORMATION process the whole XML string based on defined transformation and return it in variable/internal table. Transformations can be defined using transaction SE80. Ok I am leaving this topic for next blog ;)