Thursday, May 24, 2012

Get Current Function Name


Dynamic programming is essential for keeping code clean, tidy and reusable. For this purpose we always need to get information about objects, types, elements (whatever) at runtime. For example, you have to log some kind of event and you need to include the report name which triggered the related event. Basically ABAP developers check sy fields in the first place. In this situation we can get the solution by using sy-repid however when you need the current function name at runtime that variable gives the function group program name which won't work for us. For finding function name at runtime, you can use the code below.




  DATA lt_callstack TYPE sys_callst ,
         ls_callstack LIKE LINE OF lt_callstack.

*** Get Stack
  CALL FUNCTION 'SYSTEM_CALLSTACK'
    EXPORTING
      max_level    0
    IMPORTING
      et_callstack lt_callstack.

  LOOP AT lt_callstack INTO ls_callstack
      WHERE eventtype 'FUNC'" Get Last FUNC Call
    EXIT.
  ENDLOOP.

*** Set Function Name
  e_function_name ls_callstack-eventname.

Thursday, May 17, 2012

Get Payslip PDF



*** Data
DATA gv_seqnr LIKE pa0001-seqnr,
       gv_pernr LIKE pa0001-pernr.

DATA gt_form      LIKE pc408 OCCURS WITH HEADER LINE,
       gs_info      LIKE pc407 ,
       gs_return TYPE bapireturn1.


*** Function
CALL FUNCTION 'GET_PAYSLIP'
  EXPORTING
    employee_number gv_pernr
    sequence_number gv_seqnr
    payslip_variant 'PDF'
  IMPORTING
    return          gs_return
    p_info          gs_info
  TABLES
    p_form          gt_form[].

Wednesday, May 16, 2012

Reverse Goods Issue

This code snippet shows you how to reverse goods issue.It is pretty simple.


DATA lv_vbtyp TYPE likp-vbtyp,
       lv_vbeln TYPE vbuk-vbeln.

DATA lt_mesg TYPE TABLE OF mesg ,
       ls_mesg LIKE LINE OF lt_mesg.


lv_vbeln '10000012'.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
  EXPORTING
    input  lv_vbeln
  IMPORTING
    output lv_vbeln.

SELECT SINGLE vbtyp FROM likp
         INTO lv_vbtyp
        WHERE vbeln lv_vbeln" Check Document
CHECK sy-subrc EQ 0.  " Check Document

SELECT SINGLE COUNT(*FROM vbuk
        WHERE vbeln lv_vbeln
          AND wbstk 'C'.
CHECK sy-subrc EQ 0.  " Check Status.

CALL FUNCTION 'WS_REVERSE_GOODS_ISSUE'
  EXPORTING
    i_vbeln                   lv_vbeln
    i_budat                   sy-datum
    i_vbtyp                   lv_vbtyp
    i_tcode                   'VL09'
  TABLES
    t_mesg                    lt_mesg
  EXCEPTIONS
    error_reverse_goods_issue 1
    OTHERS                    2.
IF sy-subrc EQ 0.
  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
    EXPORTING
      wait 'X'.
ELSE.
  LOOP AT lt_mesg INTO ls_mesg" Get Messages
  ENDLOOP.
ENDIF.

Wednesday, April 25, 2012

HU_CREATE_GOODS_MOVEMENT

HU_CREATE_GOODS_MOVEMENT example ;


DATA :  lv_posted TYPE sysubrc,
        ls_mess TYPE huitem_messages ,
        lt_mess TYPE huitem_messages_t WITH HEADER LINE,
        ls_emkpf TYPE emkpf ,
        lt_move_to TYPE hum_data_move_to_t,
        lt_exidv   TYPE hum_exidv_t WITH HEADER LINE,
        ls_move_to TYPE hum_data_move_to,
        ls_hu_items TYPE hum_humseg,
        lv_venum TYPE vekp-venum,
        gv_temp_message TYPE string.

DATA lt_vepo TYPE TABLE OF vepo WITH HEADER LINE.

lv_venum '100000012'" Internal HU Number

SELECT FROM vepo INTO TABLE lt_vepo
  WHERE venum lv_venum.
IF sy-subrc NE 0.
  MESSAGE 'Please enter a valid HU !' TYPE 'I'.
  EXIT.
ENDIF.

LOOP AT lt_vepo.
*** Move
  ls_move_to-huwbevent '0010'" Process Indicator
  ls_move_to-matnr     '01010101'" Material Number
  ls_move_to-lgort     lt_vepo-lgort"
  ls_move_to-grund     '0004'" Fixed Reason
  ls_move_to-bwart     '309'" Movement Type

  ls_hu_items-venum lt_vepo-venum.
  ls_hu_items-vepos lt_vepo-vepos.

  APPEND ls_hu_items TO ls_move_to-hu_items.
  APPEND ls_move_to TO lt_move_to.

ENDLOOP.

*** Refresh
CALL FUNCTION 'HU_PACKING_REFRESH'.
PERFORM refresh_change_stock(saplv51e).

*** Call Function
CALL FUNCTION 'HU_CREATE_GOODS_MOVEMENT'
  EXPORTING
*   if_event       = lv_event
    if_simulate    ' '
    if_commit      ' '
*   if_tcode       = 'MOBIL'
    it_move_to     lt_move_to[]
    it_external_id lt_exidv[]
  IMPORTING
    ef_posted      lv_posted
    es_message     ls_mess
    et_messages    lt_mess[]
    es_emkpf       ls_emkpf.

*** Check Result
IF NOT lv_posted 1.
  ROLLBACK WORK.

  CALL FUNCTION 'HU_PACKING_REFRESH'.
  CALL FUNCTION 'SERIAL_INTTAB_REFRESH'.

  MESSAGE 'Problem occured!' TYPE 'I'.
ELSE.
  COMMIT WORK AND WAIT.

  CONCATENATE ls_emkpf-mblnr
              ls_emkpf-mjahr
              ' document created!'
         INTO gv_temp_message SEPARATED BY ' '.

  MESSAGE gv_temp_message TYPE 'I'.
ENDIF.

Get Handling Unit Items From Delivery

By the help of the code snippet below , you can get handling units related with specified delivery.

LT_HUS -> Handling Unit Headers -> VEKP
LT_HUPOS-> Handling Unit Items -> VEPO

DATA i_delivery TYPE likp-vbeln.
DATA is_object TYPE hum_object.
DATA lt_hus TYPE hum_hu_header_t WITH HEADER LINE,
       lt_hupos TYPE hum_hu_item_t WITH HEADER LINE,
       lt_serialno TYPE vsep_t_rserob.

is_object-object '03'.
is_object-objkey i_delivery.

CALL FUNCTION 'HU_GET_HUS'
  EXPORTING
    if_lock_hus      'X'
    if_with_text     ' '
    is_objects       is_object
  IMPORTING
    et_header        lt_hus[]
    et_items         lt_hupos[]
    et_item_serialno lt_serialno
  EXCEPTIONS
    hus_locked       1
    no_hu_found      2
    fatal_error      3
    OTHERS           4.


 

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.