ABAP Classes for date & day computation

<<Date questions have been asked so many times that they are not permitted in the ABAP forums>>
Hello, I have a requirement to get the date of last 2 thursdays. Can somebody please help with the class I should use for the purpose?
Thanks!
Edited by: Matt on Aug 16, 2011 11:50 AM

Hey,
DATE_COMPUTE_DAY will give you DAY number for any date, with day number 1 as Monday .....4 as Thursday....and 7 as Sunday.
SO, you can use ..
data: lv_day type SCAL-INDICATOR,
      lv_diff type i,
      lv_thurs1 type sy-datum,
      lv_thurs2 type sy-datum.
PARAMETERS: p_date type datum DEFAULT sy-datum.
CALL FUNCTION 'DATE_COMPUTE_DAY'
  EXPORTING
    date          = p_date
  IMPORTING
    DAY           = lv_day
lv_diff = lv_day - 4.         "since Thursday is 4
if lv_diff GT 0.
  lv_thurs1 = p_date - lv_diff.
else.
  lv_thurs1 = p_date - 7 - lv_diff.
endif.
  lv_thurs2 = lv_thurs1 - 7.
  write:/ lv_thurs1, lv_thurs2.
I have not included today's date if it is Thursday, if you want to include it, change 'GT' to 'GE'.
BR,
Diwakar
Edited by: Diwakar Aggarwal on Aug 16, 2011 10:49 AM

Similar Messages

  • Abap Routine for Date selection in Infopackage

    Hi
    I have to write an abap routine for date selections in the infopackage,
    There are two date begda and enda.
    Do i code for BEGDA and fill in the begin date using routine and use another routine to fill the ENDA.
    JPJP

    Hi JP,
      If you have two info objects BEGDA and ENDA in the Info package for selection
      then you will have to write seperate routine for each of them.
      If you want to give single value for each date field then update only the field l_t_range- low otherwise if you want to give range then you can update the internal table fields l_t_range-low and l_t_range-high .
    Regards,
    Prakash

  • Include in ABAP class for Workflow

    Hi,
    In order to use BOR macros inside ABAP class, (From SAP help) came to know that we need to use include <cntn02> .
    How to add this include to ABAP class for workflow?
    Regds,
    Akshay

    Hi Akshay,
    Slight difference, I said "keeping the class clean of BOR <i>code</i>". By all means use BO's in the class: basically create a ZCL_MATERIAL, and use BUS1001 as an attribute (I use a naming convention BO_* for these). As long as it's the right type (SIBFLPORB I think - no system handy right now), and the key values are populated correctly the system will instantiate it as necessary. So in WF I can refer to ZCL_MATERIAL.BO_MATERIAL whenever I need any of the BO's functionality.
    You are correct though, creating a proper business class which you can instantiate such as material does involve a fair bit of effort and coding to set up. e.g. my last project I ended up creating one ZBOR subtype because all I needed was one new attribute - definitely not worthwhile creating a new class for. (USR01.zEmailAddress for what it's worth).
    I've said before somewhere, it's not without pain, so if you're under time pressure etc, then it may be better to do whatever's quickest. There's nothing wrong with using BOR macros, it will still work for quite a few versions. I just meant to say that pure class(y) code is a preferred way to go if it makes sense to do so. This is not always the case.
    Hope that helps,
    Mike

  • BOR or ABAP Class for MM41

    Hi all.
    I am wondering whether anyone ever use workflow in transaction MM41.
    Does SAP provide standard BOR or ABAP Class for transaction MM41.
    I  know there is BUS1001006 but this only get triggers from MM01.
    Does user exit or BADI is the only way to trigger workflow from MM41?
    Thanks

    Hello,
    It might help if you said what MM41 was.
    As usual, turn on the event trace (SWELS), create and save something in your chosen transaction and then check the event trace (SWEL) for any events.
    regards
    Rick Bakker
    hanabi technology

  • ABAP code for Date Range

    Hi All,
    I have requirement to write code for date range.
    Characterstic = Run-Out Date, it was created reference to 0Date.
    Requirement is data should load depends on Run-Out Date 7 days old and 14 days future.
    Logic is -7 days old >= Run_out date <= 14 days future.
    please let me know how I need to proceed with ABAP code for this requirement.
    Thanks.
    Please do not ask for ABAP code here. Its not a training forum
    Edited by: Pravender on Aug 18, 2011 1:46 AM

    >
    Sree vignesh wrote:
    > Hi,
    > In the select option we have a field month range as
    > SELECT-OPTION : FROM 01.2007       TO  01.2009 " Let say Ur Selection option is SO_MONTH
    > but now i need to add the DMBTR field considering the month range in the SELECT OPTION i.e., only FROM 01.2007 TO  01.2009 i mean without 2006 data.
    >
    > LOOP AT LT_DATA WHERE month in SO_MONTH. " Here add a Where condition
    >     ls_output-matnr = lt_data-belnr.
    >     ls_output-werks = lt_data-bukrs.
    >     ls_output-lgort = lt_data-dmbtr.   
    >
    >     COLLECT  ls_output INTO lt_output .
    >
    >   ENDLOOP.
    >
    > please help with code .
    >
    > thanks in advance.
    Regards,
    Suneel G

  • Error handling in Abap Class for SAP Workflow

    Hi Experts,
    I would like to know if we have an option in abap classes used in workflows to send errors to the workflow log. We can achieve this in BOR Object methods by using the EXIT_RETURN <CODE> var 1 var 2 to send the errors back to the workflow, but how is this achieved through methods from classes  used in workflows.
    Appreciate your quick responses,
    Chaitanya

    Just raise exceptions in the normal OO way. Any exception that is a subclass of CX_BO_ERROR should be automatically available in workflow. Use subclasses of CX_BO_TEMPORARY for temporary errors.

  • Abap Class for Enterprise Service

    Hi guys.
    I've published as webservice in SAP ECC as enterprise service get it in Enterprise Service Workplace.
    I have two questions:
    1- How can I know the abap class associated to this enterprise service.
    2- Could I extend the functionality of this enterprise service? For instance I'd like to response with one more field. Is that possible or I have to create a new one?
    Thaks a lot.
    Regards.
    Edited by: Christian  Abad Chico on Feb 20, 2012 4:03 PM

    Hi
    May be the below link helps you,
    [http://wiki.sdn.sap.com/wiki/display/EmTech/PublishWeberviceinABAP,ConsumeWebserviceinABAPandAdobeFlex.]
    Regards,
    Vijay V

  • ABAP classes for WebTemplate development

    Hi experts,
    I am manipulating a report via ABAP classes.  I need to hide an entire column including the header.  Currently I have done this under the DATA_CELL method and have only been able to hide the KF area.  If I need to hide the Header in the column (built under a structure) as well must I move all my code under the CAPTION_CELL method instead?
    Secondly, I also need to search for a row by the text "Overall Results."  Is there a quick way to search the Y axis for this particular row using the text "Overall Results?
    mark

    hi Mark,
    you can try in
    method CAPTION_CELL
    if i_iobjnm_row = 'your charateristic to be hidden'.
    C_CELL_TD_EXTEND = 'style="display:none;"'.
    endif.
    and ...
    method CHARACTERISTIC_CELL
    if I_IOBJNM = 'your charateristic to be hidden'.
      C_CELL_TD_EXTEND = 'style="display:none;"'.
    endif.
    and I_IS_SUM <> 'X' if result not hide       
    to search 'Overall Result' (if you didnt get yet), can try
    method CHARACTERISTIC_CELL
    I_TEXT
    not sure what's your requirement, to hide a characteristic you can set it bex query designer, characteristic's property 'display' = no display.
    hope this helps.

  • InfoPackage ABAP Routine for Date Range - Only Start Date Extracted

    I am using an ABAP Routine in an InfoPackage to select data for a 2 year period.  The routine converts SY-DATUM into the Current Fiscal Year and Period, and then calculates the Starting and Ending Fiscal Year / Period of a 24 month period.  The Start and End values are passed to the InfoPackage as l_t_range-low and l_t_range-high.
    The Source and Target are both Basic Infocubes.
    The InfoPackage executes successfully, and the Selection values on the Header tab of the monitor reflect a 24 month period.  Unfortunately, on closer review of the data in the cube, only data for the first month appears to have been loaded.  I’m guessing that the extract was only performed with the From value, even though a To value was also provided.
    I created a simple Infopackage and manually input the selection parameter values just to be sure I wasn’t overlooking something. The InfoPackage performed as expected, loading more data which spanned the selection time period.
    I can provide the code if it helps, but the fact that the monitor reflects a Start and End value suggests that the problem is with the InfoPackage, not the ABAP routine.
    Has anybody ever experienced this before ?  Any ideas would be greatly appreciated ?
    Thanks,
    Lyle

    We can write ABAP routine in Infopackage with a range of values (From & To). Make sure you fill all the following information while building the final range information as below,
       l_s_range-sign    = 'I'.
       l_s_range-option  = 'BT'.
       l_s_range-low     = lowvalue.
       l_s_range-high    = highvalue.
      MODIFY l_t_range FROM l_s_range INDEX l_idx.
    As you can see the key is passing the "BT" information for capturing range.
    Hope it helps..
    thanks
    Kumar

  • Using ABAP routines for data selection

    Hello,
    I want to use ABAP routine to determine value range of data selection in Data Package but when I use routine for one field, selection criterias for other fields are ignored, e.g.:
    in Data Package I have two selection fields:
    CPUDT     Accounting Document Entry Date
    AEDAT     Date of the Last Document Change by Transaction
    For CPUDT I wrote ABAP routine
    and for AEDAT I have just typed in period of time.
    I started data extraction and open Monitor for this Data Package.
    At Header tag I checked selections info and there is selection only for CPUDT.
    Could somebody explain me is it normal system behaviour?
    Thanks
    Andrzej

    Thanks for reply but that would be too easy...
    I have tried your advice but nothing changed.
    I think this is data extraction configuration problem.
    Andrzej

  • ABAP Class for BOR IMAGE

    Is there an ABAP Object class which wraps or implements the BOR IMAGE?
    ( In particiluar, I wan't to be able to use the display method. )
    Thanks...
    ,..Mike

    closed

  • File to Proxy Scenario using ABAP Class and DB Multi Connect

    Hello Friends,
    I have a scenario below and a proposed solution. I would like some input as to whether i am headed the right way.
    Scenario: Thousands of records come in from the legacy accounting system. The fields of these records need to be mapped to SAP fields using cross-reference tables stored in DB2. Finally, summarize the records by deleting a few fields and feed to R/3.
    Solution i proposed:
    (1) File Adapter is used to send the file
    (2) Although JDBC adapter comes first to mind but since i need to access the DB2 tables multiple times for each record i propose to use an ABAP class for the mapping. Within the ABAP class the intent is to open an database connection to DB2, read the relevant cross tables using native SQL and finally generate the output XML.
    (3) Reciever is Proxy which feeds this generated XML to SAP for creating posting via BAPI_ACC_DOCUMENT_POST
    Question: Is the above solution correct or is there a better method to implement this scenario?
    Please let me know.
    Thanks,
    Minhaj.

    Looks fine. Few observations -
    1. Whether it is ABAP class or Mapping in RFC lookup, you are making multiple trips to the database.
    2. It looks like PI is being used only for reading the file and converting it to XML.
    3. If using PI is not mandatory, then a complete ABAP class on ECC it self would be faster than swtching between PI Java, PI ABAP then round trips to DB2 finally data push to ECC.
    If you could look at something like fetching all the required RFC look up data in one go and then map the fields according, might save u on processor and network resources.
    VJ

  • REG:USER EXIT FOR DATA SOURCE 0HR_LSO_1

    Hi ,
    I have to write the enhancement ABAP code for data source 0HR_LSO_1 which is related to module " training and event management "(also known as LMS or LSO) in ECC 6.0 .
    So how can I find out appropriate user exit for the same .I have to concentrate on the field "kostl (cost centre)" in that data source .
    Please provide some suggestions .
    Thanking You ,
    Tarun Brijwani .

    Hi Tarun...
      I this might help you.
      In the HR System:
    1) T-CODE: CMOD
    2) Choose an existing project (vg: Z12345)
    3) Modify
    4) Press Components button
    5) Look for the enhance: RSAP0001  (the BW extracting enhancement)
    6) The you have one of the following option:
    a- If the Data Source is "transaction data": The exit is "EXIT_SAPLRSAP_001"
    b- If the Data Source is "master data": The exit is "EXIT_SAPLRSAP_002"
    7) double-click in the appropriate one
    8) You'll see an INCLUDE sentence. Could be this ZXRSAU01 or this ZXRSAU02 (depending on the previous step). Double-click and you'll be redirected to the SE38
    9)  some code:
    CASE i_datasource
      WHEN '0HR_LSO_1'.
        LOOP i_t_data INTO my_struct
           my_struct-KOSTL           "Here you'll must have your Cost Center
           ...etc...etc...etc
        ENDLOOP.
      WHEN OTHERS.
    ENDCASE
    Hope it helps.
    gdmon

  • User exit for data source 0HR_LSO_1

    Hi ,
    I have to write the enhancement ABAP code for data source 0HR_LSO_1 which is related to module " training and event management "(also known as LMS or LSO) in ECC 6.0 .
    So how can I find out appropriate user exit for the same .I have to concentrate on the field "kostl (cost centre)" in that data source .
    Please provide some suggestions .
    Thanking You ,
    Tarun Brijwani .

    Hi Tarun...
      I this might help you.
      In the HR System:
    1) T-CODE: CMOD
    2) Choose an existing project (vg: Z12345)
    3) Modify
    4) Press Components button
    5) Look for the enhance: RSAP0001  (the BW extracting enhancement)
    6) The you have one of the following option:
    a- If the Data Source is "transaction data": The exit is "EXIT_SAPLRSAP_001"
    b- If the Data Source is "master data": The exit is "EXIT_SAPLRSAP_002"
    7) double-click in the appropriate one
    8) You'll see an INCLUDE sentence. Could be this ZXRSAU01 or this ZXRSAU02 (depending on the previous step). Double-click and you'll be redirected to the SE38
    9)  some code:
    CASE i_datasource
      WHEN '0HR_LSO_1'.
        LOOP i_t_data INTO my_struct
           my_struct-KOSTL           "Here you'll must have your Cost Center
           ...etc...etc...etc
        ENDLOOP.
      WHEN OTHERS.
    ENDCASE
    Hope it helps.
    gdmon

  • Hide a specific cell using ABAP classes

    Hi Experts,
    Is there a way to hide a specific cell using ABAP classes for reports?
    Marcelo

    Hello Thomas Daly
        I never saw a way to grant permission to a List, the only way I ever saw a list get its permissions is thru
    the group site it resides in, the Discussion Board is the problem in this case (it has preconfigure permissions but they seem more like properties that you select the value from RadioButtons).  However, ms-addnew gets rid of the Add new link but it
    gets rid of the one in the Discusson Board too because Discussion Board falls in the category of List.
        In other words ms-addnew in the master got rid of all of the Add new items, link etc as hoped but now
    I can't add to the Discussion Board.
        I am alright with a hack (I am open to any suggestions) that would work if it works but, the List's I am referring to are all "Links" in the Quick Launch so I dont know how you would be able to apply the jquery, how would you apply the
    jquery to a Links in a Quick Launch?
        Thank you
        Shabeaut

Maybe you are looking for

  • PSE 7 Problems Fixed in PSE 8

    Since PSE 6 was released, I’ve tracked all the reproducible bugs I’ve encountered and reported to Adobe.  I’ve tested these problems in PSE 8 and listed the results below – problems that appear to have been fixed in PSE 8 are marked [F], and problems

  • T-SQL functions in ORACLE

    Use T-SQL functions in ORACLE too, so you can write one script version that works in SYBASE, SQLSERVER and ORACLE when need to use the following functions: ceiling, charindex, dateadd, datediff, datename, datepart, day, db_id, db_name, getdate, host_

  • Unpairing remote on mavericks osx

    Help! I have my Mac mini that acts as a file server for my Apple TV, however when I control my Apple TV using my Apple remote, it also controls my iTunes. I have opened up system preferences as all the forums say, gone into security and privacy in th

  • I have a warning AY 7:36 what does this mean?

    I have a warning AY 7:36 in my doc bar what does this mean?

  • Mandatory/Default field for mrp/forecast profile mrp area

    Dear guru, In MM01/MM02 when i create a new mrp area for a material I want Mrp profile field and forecast profile field as mandatory field. Or as alternative solution purposed with a default. How can I do that ?