Category Archives: SAP ABAP

FM To calculate Contract Next Adjustment Date

In REFX transaction RECN (Contract), you can check the Next Adjustment Date (calculated) in the tab Adjustments / Sub Tab Conditions in column Next Poss Adjustment.

The following FM reproduces the same calculation which uses method GET_NEXTADJMDATE of the interface IF_RECD_CONDITION.

FUNCTION ZREFX_CNT_INDEX_NEXTADJMDATE .
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     REFERENCE(I_RECNNR) TYPE  RECNNUMBER
*"     REFERENCE(I_BUKRS) TYPE  BUKRS
*"  EXPORTING
*"     REFERENCE(E_NEXTADJMDATE) TYPE  REAJNEXTADJMDATE
*"----------------------------------------------------------------------

  statics:
    lrt_recntype type range of RECNCONTRACTTYPE WITH HEADER LINE,
    lrt_condtype type range of RECDCONDTYPE WITH HEADER LINE.

  data:
    l_numb type     RECDCONDNUMBER,
    lo_condition_mngr TYPE REF TO IF_RECD_CONDITION_MNGR,
    lo_condition    TYPE REF TO IF_RECD_CONDITION,
    ls_condition TYPE RECD_CONDITION,
    l_next TYPE REAJNEXTADJMDATE,
    l_max type  REAJNEXTADJMDATE,
    lo_contract     TYPE REF TO if_recn_contract,
    ls_contract     TYPE recn_contract.

  if lrt_recntype[] is initial.
*    No filtering on condtions for the moment
*    If necessary to filter on rent, need to add
*    1FI, 1BC, 1CC 1DIMF?, 1PFO, 1ER, 1WO	, 1VE, 1UC
*    lrt_condtype-sign = 'I'.
*    lrt_condtype-option = 'BT'.
*    lrt_condtype-low = '0010'.
*    lrt_condtype-high = '0019'.
*    append lrt_condtype.

    lrt_recntype-sign = 'I'.
    lrt_recntype-option = 'EQ'.
    lrt_recntype-low = 'ZRDD'.
    lrt_recntype-high = ''.
    append lrt_recntype.
    lrt_recntype-sign = 'I'.
    lrt_recntype-option = 'EQ'.
    lrt_recntype-low = 'ZRIN'.
    lrt_recntype-high = ''.
    append lrt_recntype.
  endif.

  clear E_NEXTADJMDATE.

  select single * from vicncn into CORRESPONDING FIELDS OF ls_contract
    WHERE recnnr = i_recnnr
      and bukrs = i_bukrs.

  check ls_contract-recntype in lrt_recntype.
  check ls_contract-RECNENDABS > sy-datum.

*     get object
  CALL METHOD cf_recn_contract=>find_by_detail
    EXPORTING
      is_detail   = ls_contract
    RECEIVING
      ro_instance = lo_contract
    EXCEPTIONS
      OTHERS      = 0.

  IF lo_contract IS BOUND.
    lo_condition_mngr = lo_contract->get_condition_mngr( ).

    l_numb = '0001'.

    do.
      CALL METHOD lo_condition_mngr->GET_CONDITION
        EXPORTING
          ID_NUMBER    = l_numb
        RECEIVING
          RO_CONDITION = lo_condition.
      if lo_condition is not BOUND.
        exit.
      endif.
      CALL METHOD LO_CONDITION->GET_DETAIL
        RECEIVING
          RS_DETAIL = ls_condition.

      if ls_condition-condtype in lrt_condtype.
        CALL METHOD lo_condition->GET_NEXTADJMDATE
          RECEIVING
            RD_NEXTADJMDATE = l_next.
        if E_NEXTADJMDATE < l_next.
          E_NEXTADJMDATE = l_next.
        endif.
      endif.
      l_numb = l_numb + 1.
    enddo.
  endif.
ENDFUNCTION.

The FM is available in SLNK format here.
Download – FUGR_ZREFX_INDEXATION.slnk – 7.7 kB – 232   downloads

How to create an instance of CL_RECN_CONTRACT

To create an instance of the Contract object, for a given contract you can use method FIND_BY_DETAIL of the Factory Class CF_RECN_CONTRACT. Here is an example code:

data:
lo_contract TYPE REF TO if_recn_contract,
ls_contract TYPE recn_contract.

select single * from vicncn into CORRESPONDING FIELDS OF ls_contract
WHERE recnnr = i_recnnr
and bukrs = i_bukrs.

* get object

CALL METHOD cf_recn_contract=>find_by_detail
EXPORTING
is_detail = ls_contract
RECEIVING
ro_instance = lo_contract
EXCEPTIONS
OTHERS = 0.

 

ABAP – UUIDs and random strings

If you want to generate a random string in ABAP, you can use the following FM where you can specify the length of the generated random string: CRR_GET_RANDOM_STRING

If you want a random and unique string, then you need to use the UUID generation class cl_system_uuid which can be accessed in either instance or static form. See the API for the UUID generation document attached to SAP Note 935047 – Creating and using GUIDs (UUIDs) or click on the download below.

 

Download – UsingTheUUIDABAPInterface2.pdf – 30.0 kB – 399   downloads

Download – SAPNote0000935047_CreateUseUUIDs.pdf – 38.1 kB – 372   downloads

 

BW Transport Validation Utility

This program was originally posted in SCN code gallery. I tested it on my system and created a SAPLINK file for it (see download button below).

This utility lists the contents of a BW Transport Request and translates BW object IDs into readable format.

This applies to

  • Transformations – TRFN
  • Update Rules – UPDR
  • Query Elements – ELMT
  • DTPs – DTPA

 

Download – PROG_ZBW_TRANSPORT_ANALYSIS.slnk – 71.3 kB – 396   downloads

See original article from Kin C. Chan here

ABAP Substract 2 timestamps

A Google search turns up this recommendation: http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/840ad679-0601-0010-cd8e-9989fd650822#q-8: use the class CL_ABAP_TSTMP. You can also see an example of how to use the class in this thread: http://scn.sap.com/thread/85476.

 cl_abap_tstmp=>systemtstmp_syst2utc(
    exporting
      syst_date = <wa_joblist>-strtdate
      syst_time = <wa_joblist>-strttime
    importing
      utc_tstmp = start_stamp ).

  cl_abap_tstmp=>systemtstmp_syst2utc(
    exporting
      syst_date = sy-datum
      syst_time = sy-uzeit
    importing
      utc_tstmp = now_stamp ).

  seconds = cl_abap_tstmp=>subtract(
      tstmp1 = now_stamp
      tstmp2 = start_stamp ).
See also: http://stackoverflow.com/questions/10539133/difference-between-2-timestamps

Debug SAP after popup – dialog box

So you know how to debug and all is going well until a pop-up (dialog box) appears and exits your debugging session. There is a simple trick to switch on debugging once you reach a pop-up, proceed as follows:

Create a TXT file and save it on your desktop with the following command:

[Function]
Command=/H
Type=SystemCommand

Then if you want to activate debugging on a pop-up/dialog box, simply drag and drop the TXT file from your desktop onto the pop-up/dialog box in SAP. Next time you press enter you will be back in your debugging session. Happiness.

BW Generated extractors for Classifications

See transaction CTBW

Note 306046 – Characters of classifctn – attributes in BW

Recurrent problem with these data sources is that the characteristics are not defined in the ‘customizing’ dev client but in the ‘test’ dev client (characteristics are “master data”) => see Classification Datasource (CTBW) – Different characteristic onfig. in R/3

 

Useful tables

CABN/CABNT/AUSP