Wednesday, July 25, 2012

To find the IP address of application server in SAP

TYPES: BEGIN OF kernel_version,
         key(21) TYPE c,
         data(69) TYPE c,
      END OF kernel_version.
  DATA : gt_kernel_version TYPE STANDARD TABLE OF kernel_version,
         gw_kernel_version TYPE kernel_version.
  DATA ip_address(69) TYPE c.
  CALL 'SAPCORE' ID 'ID' FIELD 'VERSION'
                 ID 'TABLE' FIELD gt_kernel_version[].
  READ TABLE gt_kernel_version INTO gw_kernel_version INDEX 11.
  ip_address = gw_kernel_version-data.
WRITE ip_address.

Shift negative sign from right to left in ABAP

DATA: gv_amount type konp-kbetr.
DATA: gv_amount_text(15)  type c.
gv_amount = 100.
gv_amount = gv_amount * -1.
gv_amount_text = gv_amount.
Now value will be 100 -
CALL FUNCTION 'CLOI_PUT_SIGN_IN_FRONT'
    CHANGING
      value         = gv_amount_text.
Now final value will be -100

Details of messages being displayed on WEB UI in SAP CRM

In order to figure out the details of the messages being displayed on WEB UI in SAP CRM for analysis purpose, the following steps can be performed:
1.      Put a break-point in the method ADD_MESSAGE of the message service class CL_BSP_WD_MESSAGE_SERVICE  and replicate the scenario for which the error message is appearing on the WEB UI. The  import parameters IV_MSG_ID and IV_MSG_NUMBER of this method would have the message details.
2.      The standard database table T100 maintains the standard error messages and their message class and message number.

3.      The method call stack in the debugger (‘Standard’ tab) can then be used to trace where in the logic this message is being added.

Grey out fields on ME21N/ME22N/ME23N

How to grey out fields on ME21N/ME22N/ME23N

For certain Purchase orders, based on some condition, we need to grey out the fields NETPR & KBETR.

In order to do this, we need to find the right BADI or the right user exit to code our functionality. For this debug tool is a must to know where and how these fields are populated on the purchase order screen.

This functionality can be achieved by following the below steps.

For the PO creation/change screen below is the solution to gray out the required fields (NETPR & KBETR)

1. for NETPR:

The field catalog that fills NETPR is TC_1211 Actually in standard program SAPLMEGUI, there is a call to the FM MEGUI_BUILD_PO_ITEMOV_PLUGIN.. Inside that, in line 44, TC_1211 gets populated. This contains all field catalog values. So in BADI, code to disable field NETPR by reading values using field symbols.

In SE19:

Create Implementation — > Classic BADI –> ME_ACTV_CANCEL_PO –> Implementation name ZCL_IM_TEST

In method CHECK_ACTIVITY code the following:

Method IF_EX_ME_ACTV_CANCEL_PO~CHECK_ACTIVITY.
FIELD-SYMBOLS :<fs>        TYPE ANY TABLE,
<ls>        TYPE ANY,
<lr_screen> TYPE screen.

ASSIGN (‘(SAPLMEGUI)TC_1211-COLS’) TO <fs>.
IF sy-subrc IS INITIAL.
LOOP AT <fs> ASSIGNING <ls>.
ASSIGN COMPONENT ’SCREEN’ OF STRUCTURE <ls> TO <lr_screen>.
IF <lr_screen>-name = ’MEPO1211-NETPR’.
<lr_screen>-input = 0.
ENDIF.
ENDLOOP.
ENDIF.

endmethod.

Activate the implementation. NETPR will be disabled in the header when u try to create or change purchase order.

2. for KBETR

In Screen 6201 of program SAPLV69A -> LV69AO03à Module FELDAUSWAHL, there is a User Exit: PERFORM userexit_field_modification.

Inside this EXIT, change the contents of TCTRL_KONDITIONEN-COLS [6]-SCREEN-INPUT to 0. KBETR will get grayed out.

Capture error messages for function modules without exceptions


At times we see function modules without any exceptions but still there is an error message being thrown inside the function module if any piece of code fails. If this situation happens then the program terminates at that point. In this case there is no SY-SUBRC other than 0.

To solve this, in the program where you have written your code for the FM, include the following lines of code.

EXCEPTIONS
    error_message = 99.

By doing this you will ensure that whenever there is any error thrown by the function module, SY-SUBRC is set as 99 and you can then capture the message in system fields i.e. SY-MSGID, SY-MSGTY, SY-MSGNO, SY-MSGV1, SY-MSGV2, SY-MSGV3, SY-MSGV4, and SY-MSGV5.
SAMPLE CODE:
CALL FUNCTION 'RV_CUSTOMER_MATERIAL_UPDATE'
  
TABLES
    xknmt_tab     = lt_xknmt
    yknmt_tab     = lt_ykmt
    tcatalog_tab  = lt_cat
  
EXCEPTIONS
    error_message = 
99.
  IF sy-subrc <> 0.
     
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
         
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  
ENDIF.