Wednesday, March 28, 2012

Change SAP Web Service Default Login Language

 We can configure web services using SOAMANAGER transaction for a long time. This application controls icf nodes regarding selected web services which makes the WS publishing process easier for us. Unfortunately last version of SOAMANAGER don't have an option to change WS login language , either SICF does not allow us to change directly related node and gives SHTTP824 error.

 I have tried a little bit to find a solution however nothing came out. So I decided to code for myself and put it into my toolbox. The program below lets you change WS default login language. After execution it opens sicf transaction by selecting the node you entered. Deactivate and activate node. It's done.

 


*&---------------------------------------------------------------------*
*& Report  ZBCP_CHANGE_WS_LANGU
*&---------------------------------------------------------------------*

REPORT  zbcp_change_ws_langu.

TABLES icfservice.

DATA gt_nodes TYPE TABLE OF icfservice.


PARAMETERS p_lng_fr TYPE sy-langu OBLIGATORY DEFAULT 'EN'.
PARAMETERS p_lng_to TYPE sy-langu OBLIGATORY DEFAULT sy-langu.
PARAMETERS p_node TYPE icfservice-icf_name OBLIGATORY.


START-OF-SELECTION.

  SELECT FROM icfservice INTO TABLE gt_nodes
    WHERE icf_name p_node
      AND icf_langu p_lng_fr.
  IF sy-subrc NE 0.
    MESSAGE 'Node does not exists!' TYPE 'I'.
    EXIT.
  ENDIF.

  LOOP AT gt_nodes INTO icfservice.

    icfservice-icf_langu p_lng_to.
    MODIFY icfservice.
  ENDLOOP.

  MESSAGE 'It''s done please reactivate node !'
     TYPE 'S'.

  SUBMIT rsicftree WITH icf_serv p_node AND RETURN.

Thursday, February 2, 2012

SITIST 2011 - My Presentation


For the 2nd time Sap Inside Track Event was organized by the help of SAP Turkey and SDN community members in İstanbul. I couldn't participated first SIT İstanbul event. However I went to Ankara to be together with the community members. That was really fun. After SIT Ankara event I decided to host a session instead of being just a participant. So, on December 3rd 2011, I had a session to support this event. I think SIT events are so important for Turkish SAP community to get together and share experiences.

Blogs about the event ;

Dilek Adak
Abdülbasit Gülşen
Hüseyin Bilgen


And you can display my PRESENTATION in here.
Sitist 2011 hdereli REST With ABAP and SAP NetWeaver Gateway

* Some of the images that I've used in presentation are not mine.

Friday, January 27, 2012

ABAP Dynamic Function Call

 Code sample below shows how to implement a dynamic function call. Actually we need that kind of dynamic function call rarely instead of static call. However it helped me a lot in a complicated scenario. Less code , less effort and a clean code...

Also you can check standard documentation in here .


Tuesday, November 15, 2011

Open New Window Using ABAP


 While displaying a report , generally user wants to drill down by clicking one of the lines or cells to get more detailed information about related topic. Most common behavior to accomplish this task is displaying detailed information at the same window. However in some cases users need to display the detailed report in another window. They need to see both reports inside different windows. For this purpose check sample below.



DATA ls_params TYPE tpara,
       lt_params TYPE TABLE OF tpara.

ls_params-paramid 'BUK'.
ls_params-partext '0001'.
APPEND ls_params TO lt_params.

ls_params-paramid 'BLN'.
ls_params-partext '00000101'.
APPEND ls_params TO lt_params.

ls_params-paramid 'GJR'.
ls_params-partext '2011'.
APPEND ls_params TO lt_params.


CALL FUNCTION 'CC_CALL_TRANSACTION_NEW_TASK'
  STARTING NEW TASK 'FB03_TASK'
 
DESTINATION 'NONE'
   

EXPORTING
    transaction           'FB03'
    skip_first_screen     'X'
  TABLES
    paramtab              lt_params
  EXCEPTIONS
    communication_failure 97
    system_failure        98
    OTHERS                99.

IF sy-subrc
NE 0.
  MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
          WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF. 









Read Handling Unit Items

If you need to get the contents of a handling unit , this function will help you.

*** Data
  DATA lf_highest_level_hu TYPE  exidv ,
              lt_hu_header TYPE hum_hu_header_t WITH HEADER LINE,
              lt_hu_items TYPE hum_hu_item_t WITH HEADER LINE .

*** Get Items
  CALL FUNCTION 'HU_GET_ONE_HU_DB'
    EXPORTING
      if_hu_number        i_handling_unit
      if_all_levels       'X'  
" Get All Levels
      if_with_text        'X'
    IMPORTING
      ef_highest_level_hu lf_highest_level_hu
      et_hu_header        lt_hu_header[]
      et_hu_items         lt_hu_items[]
    EXCEPTIONS
      hu_not_found        1
      hu_locked           2
      fatal_error         3
      OTHERS              4.
 

*** Delete root HUs if you need only materials 
   DELETE lt_hu_items WHERE unvel IS NOT INITIAL.  



Thursday, October 27, 2011

Goods Movement For Production Order


 Sample Code to fulfill Goods Movement For Production Order.


*** PARAMETERS PASSED
 i_aufnr , i_aufnr_itno , i_plant , i_lgort , i_quantity
*** PARAMETERS PASSED

*** DATA Decleration
  DATA gs_header TYPE bapi2017_gm_head_01 ,
         gs_code TYPE bapi2017_gm_code ,
         gt_headret TYPE TABLE OF bapi2017_gm_head_ret WITH HEADER LINE ,
         gt_item TYPE TABLE OF bapi2017_gm_item_create WITH HEADER LINE,
         gt_return TYPE TABLE OF bapiret2 WITH HEADER LINE.


 *** Find Order's UNIT
  SELECT SINGLE sbmeh FROM afko INTO lv_sbmeh
     WHERE aufnr i_aufnr.
 


*GM_CODE  TCODE   Description
*01   MB01  Goods receipt for purchase order
*02   MB31  Goods receipt for production order
*03   MB1A  Goods issue
*04   MB1B  Transfer posting
*05   MB1C  Other goods receipt
*06   MB11  Reversal of goods movements
*07   MB04  Subsequent adjustment with regard to a subcontract order


*** Set Code
  gs_code-gm_code '02' .

*** Header
  gs_header-pstng_date sy-datum .
  gs_header-doc_date   sy-datum .
  gs_header-pr_uname   sy-uname .
  gs_header-header_txt 'Text 123'.
  gs_header-ref_doc_no i_aufnr.

*** Item
  CLEAR gt_item  .
  gt_item-move_type  '101' .
  gt_item-spec_stock 'E'.
  gt_item-mvt_ind 'F'.
  gt_item-stck_type 'X'.

*** Order Id
  gt_item-orderid i_aufnr.
  gt_item-order_itno = i_aufnr_itno.
  gt_item-plant      i_plant  .
  gt_item-stge_loc   i_lgort.
  gt_item-entry_qnt  i_quantity  .
  gt_item-entry_uom  lv_sbmeh.
  gt_item-entry_uom_iso  lv_sbmeh.
  gt_item-item_text  i_aufnr .

  APPEND gt_item .



  CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
    EXPORTING
      goodsmvt_header  gs_header
      goodsmvt_code    gs_code
    IMPORTING
      goodsmvt_headret gt_headret
    TABLES
      goodsmvt_item    gt_item[]
      return           gt_return[].

  BREAK-POINT.


  LOOP AT gt_return WHERE type 'S'
                      AND id 'L9'
                      AND number '514'.
  ENDLOOP.
  IF sy-subrc EQ 0.
 
 *** Delivery Created - OK
  ELSE. 
 *** Problem Occured - Check gt_return[]
  ENDIF.

 

Thursday, October 6, 2011

Full-screen ALV

ABAP developers face ALV full-screen problem most of the times as a part of designing issue. Displaying ALV in full-screen mode is just easy as below. You don't need to create a custom container.




  if go_alv is initial.

    create object go_alv
      exporting
        i_parent          = cl_gui_container=>screen0
*        i_appl_events     = 'X'
      exceptions
        error_cntl_create = 1
        error_cntl_init   = 2
        error_cntl_link   = 3
        error_dp_create   = 4
        others            = 5.
    if sy-subrc ne 0.
      message id sy-msgid type sy-msgty number sy-msgno
            with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    endif.

  endif.



Currency Conversion


Like unit conversion , currency conversion is also one of the most needed operation. And for this kind of  common operations we should have code snippets. Here is a sample usage for currency conversion.



*** Currency Conversion
if lv_waers_from ne lv_waers_to.
  perform convert_currency using lv_waers_from
                                 lv_waers_to
                        changing lv_wrbtr.
endif.

*-------------------------------------------
*      Form  convert_currency
*-------------------------------------------
FORM convert_currency  USING    p_from_waers
                                p_to_waers
                       CHANGING p_wrbtr.

  DATA lv_ukurs TYPE tcurr-ukurs .

  CALL FUNCTION 'CONVERT_TO_LOCAL_CURRENCY'
    EXPORTING
      date             gv_keydate
      foreign_amount   p_wrbtr
      foreign_currency p_from_waers
      local_currency   p_to_waers
    IMPORTING
      exchange_rate    lv_ukurs
    EXCEPTIONS
      no_rate_found    1
      overflow         2
      no_factors_found 3
      no_spread_found  4
      derived_2_times  5
      OTHERS           6.

  CHECK sy-subrc EQ 0.

  p_wrbtr p_wrbtr * lv_ukurs.

ENDFORM.                    " convert_currency

 

Monday, September 12, 2011

ABAP Field Symbol Usage


Here is a short sample which illustrates the usage of field symbols with work areas (headers) . Even though we don't know the number or the name of elements in a work area , we can dynamically get them like below. Field symbols are indispensable for complicated applications or reports. Also they could provide a solution for performance issues in some cases. Beside the usage below there are much more ways to use it. For more information just check out the documentation in sdn.




FIELD-SYMBOLS  TYPE ANY ,
                 TYPE ANY .

DATA t_table TYPE TABLE OF pa0001 WITH HEADER LINE.

SELECT FROM pa0001 INTO TABLE t_table UP TO 100 ROWS.

LOOP AT t_table ASSIGNING  .
WRITE /.
  " Loop at fields
  DO.
    ASSIGN COMPONENT sy-index OF STRUCTURE  TO .
    IF sy-subrc EQ 0.
      WRITE .
    ELSE.
      EXIT.
    ENDIF.
  ENDDO.

ENDLOOP.

Basic ABAP HTTP Request Sample


For various needs using http requests could be a life saver. Here is a simple code snippet.




  data : lv_value type string.

  data : http_client type ref to if_http_client .
  data : lv_url type string.
  data : return type string.

    data : lv_err_string type string ,
           lv_ret_code type sy-subrc .


* Build Url

  concatenate 'http://www.example.com/?param='
               lv_value
               into lv_url.

* Create Client 
  call method cl_http_client=>create_by_url
    exporting
      url    = lv_url
    importing
      client = http_client.

* Send 
  call method http_client->send
    exceptions
      http_communication_failure = 1
      http_invalid_state         = 2.

* Receive
  call method http_client->receive
    exceptions
      http_communication_failure = 1
      http_invalid_state         = 2
      http_processing_failed     = 3.
  if sy-subrc ne 0.
    http_client->response->get_status(
      importing
        code   = lv_ret_code
        reason = lv_err_string
           ).
    message lv_err_string type 'I'.
  endif.

* Now we have the response , parse , display  
* do what you like 
  return = http_client->response->get_cdata( ).




Monday, August 22, 2011

UTILITY CLASS

 Utility class is a kind of conceptual class that includes commonly used methods for the related operations. It groups methods together that have the similar purpose about a specific topic and these methods are static which makes them easy to use.

Examples of ABAP Utility Objects ;

CL_HTTP_UTILITY
CL_BSP_UTILITY
CL_ABAP_CHAR_UTILITIES
CL_ABAP_MEMORY_UTILITIES
CL_ABAP_STRING_UTILITIES
....

For Java ;

java.util.Collections

Wikipedia ;

http://en.wikipedia.org/wiki/Utility_class