Function module which could calculate the previous month's start date.....

hi,
I want a function module which could calculate the previous month's start date and end date...
Say todays date is  like 29.05.2007(start date) it should return
01.04.2007 and 30.04.2007...
IS there any FM for this ... or how to go about this scenario ???
thanks in advance
samm

See the below Logic :
DATA :g_date(2) TYPE n,           " Date
      g_month(2) TYPE n,          " Month
      g_year(4) TYPE n ,          " Year
      g_bill_low(10) TYPE n,       " From date
      g_bill_high(10) TYPE n,      " To date
      g_month1(2) TYPE n,         " Month
      g_year1(4) TYPE n,          " Year
      g_date1(2) TYPE n,          " Date
      g_year2(4) TYPE n,          " Year
      g_datum LIKE sy-datum.      " System date
RANGES : r_bdate  FOR vbrk-fkdat.             " Billing date
  g_datum = p_date + 10.
  g_month = g_datum+4(2).
  g_year = g_datum+0(4).
  IF g_month = 1.
    g_year = g_year - 1.
    g_month = 12.
    g_date = 1.
  ELSE.
    g_month = g_month - 1.
    g_date = 1.
  ENDIF.
Passing the date to billing date-low
  CONCATENATE  g_year g_month g_date  INTO g_bill_low.
  r_bdate-low = g_bill_low.
  r_bdate-sign = 'I'.
  r_bdate-option = 'BT'.
  g_month1 = g_datum+4(2).
  g_year1 = g_datum+0(4).
  IF g_month1 = 1.
    g_year1 = g_year1 - 1.
    g_month1 = 12.
  ELSE.
    g_month1 = g_month1 - 1.
  ENDIF.
  CASE g_month1.
    WHEN 1.g_date1 = '31'.
    WHEN 3.g_date1 = '31'.
    WHEN 4.g_date1 = '30'.
    WHEN 5.g_date1 =  '31'.
    WHEN 6.g_date1 = '30'.
    WHEN 7.g_date1 = '31'.
    WHEN 8.g_date1 = '31'.
    WHEN 9.g_date1 = '30'.
    WHEN 10.g_date1 = '31'.
    WHEN 11.g_date1 = '30'.
    WHEN 12.g_date1 = '31'.
  ENDCASE.
  g_year2 = g_year1.
  IF g_month1 = 2.
    g_year2 = g_year2 MOD 4 .
    IF g_year2 = 0.
      g_date1 = 29.
    ELSE.
      g_date1 = 28.
    ENDIF.
  ENDIF.
Passing the date to billing date-high
  CONCATENATE  g_year1  g_month1  g_date1 INTO g_bill_high.
  r_bdate-high = g_bill_high.
  APPEND r_bdate.
Reward Points if it is helpful
Thanks
Seshu

Similar Messages

  • Function module to subtract a number of months from a date

    I have a field, FISCPER, in the format YYYY/MMM(2007004) and I need to subtract 12 months off of it to get 2006004.  I tried to just subtreact 12 but it gave me the actual value when you subtract the 2.

    Hi,
    Check the following example:
    FM to Get the Day for a Particular Date
    FM or any other means by which we can get the DAY for a particular date?
    Yes, DATE_COMPUTE_DAY
    Sample code:
      clear: hold_day_of_week.
      CALL FUNCTION 'DATE_COMPUTE_DAY'
           EXPORTING
                DATE = workdate
           IMPORTING
                DAY  = day_of_week_num
           EXCEPTIONS
                OTHERS  = 8.
      CASE day_of_week_num.
        WHEN 1.
          hold_day_of_week = 'Monday'.
        WHEN 2.
          hold_day_of_week = 'Tuesday'.
        WHEN 3.
          hold_day_of_week = 'Wednesday'.
        WHEN 4.
          hold_day_of_week = 'Thursday'.
        WHEN 5.
          hold_day_of_week = 'Friday'.
        WHEN 6.
          hold_day_of_week = 'Saturday'.
        WHEN 7.
          hold_day_of_week = 'Sunday'.
        WHEN OTHERS.
          hold_day_of_week = 'invalid'.
      ENDCASE.
    or 
    You can use  DATE_COMPUTE_DAY to get the day number of the week (for example, today gives 5)
    then use WEEKDAY_GET which returns an itab with seven entries (one for each day of the week.)
    You enter in this itab and get the field langt to get the day name.

  • Function Module for calculating NEXT MONTH's start date and End date

    Hi Friends,
    I want a function module which could calculate the next months start date and end date...
    Say my input will be like 01.01.2006(start date) it should return
    01.02.2006 and 28.02.2006...
    IS there any FM for this ... or how to go about this scenario ???
    thanks in advance
    Cheers,
    R.Kripa

    Hi kripa,
    1. There is no DIRECT Way.
    2. We have to do in 2 steps.
    3. See this code (just copy paste in new program)
       U can use its FORM anywhere in your program,
       for getting the desired dates.
    4.
    REPORT abc.
    DATA : sdate TYPE sy-datum,
           edate TYPE sy-datum.
    PARAMETERS : dt TYPE sy-datum DEFAULT sy-datum.
    PERFORM getdt USING dt sdate edate.
    WRITE :/ sdate , edate.
    INDEPENDENT FORM
    FORM getdt USING orgdate stdate enddate.
      DATA : mydate TYPE sy-datum.
      CALL FUNCTION 'HR_PSD_DATES_ADD_MONTHS'
        EXPORTING
          v_date             = orgdate
          V_MONTHS           = 1
       IMPORTING
         E_DATE             = mydate
       EXCEPTIONS
         NOT_POSITIVE       = 1
         OTHERS             = 2
      CALL FUNCTION 'HR_JP_MONTH_BEGIN_END_DATE'
        EXPORTING
          iv_date             = mydate
        IMPORTING
          ev_month_begin_date = stdate
          ev_month_end_date   = enddate.
    ENDFORM.                    "getdt
    regards,
    amit m.

  • Is there a BAPI function module which reverses the sign of an integer

    Hi Friends,
                     Could u plz tell me  a BAPI function module which can reverse the
    sign of an integer ?
    For example:       
    if i get the integer value in work area as <number> <sign> , i need to change it to <sign><number>. 
    i.e if i get the integer value in work area as    "248-" ("-" indicates minus sign) to " -248 ".
    i.e if i get the sign after the value , my requirement is to get the sign before the value.
    The actual ABAP query is:
    data: QTY_1 TYPE CHAR10,
            QTY_2  TYPE CHAR10,
            WA_DISTK_PORTLET-QUANTITY TYPE INT4.
    QTY_1 = WA_DISTK_PORTLET-QUANTITY.
                    SEARCH QTY_1 FOR '-'.
            IF SY-SUBRC = 0 AND SY-FDPOS <> 0.
              SPLIT  QTY_1 AT '-' INTO  QTY_1 QTY_2.
              CONDENSE  QTY_1.
              CONCATENATE '-'  QTY_1  INTO QTY_1.
              CONDENSE  QTY_1.
            ELSE.
              CONDENSE  QTY_1.
            ENDIF.
            CLEAR: WA_DISTK_PORTLET-QUANTITY.
         MOVE : QTY_1 TO  WA_DISTK_PORTLET-QUANTITY.
    when i move this QTY_1 to work area  quantity field The sign is coming after the numeric value.
    Note: There is no possibility to change the datatype of quantity field.
    I have tried my level best with 'CLOI_PUT_SIGN_IN_FRONT' function module.
    I will assign full points to the correct function module.

    Hi Ram,
    try this ang look into fields.
    data: fields type table of SVAL with header line.
    fields-tabname = 'MARA'. fields-fieldname = 'MATNR'. append fields.
    fields-tabname = 'BKPF'. fields-fieldname = 'BUDAT'. append fields.
    CALL FUNCTION 'POPUP_GET_VALUES'
      EXPORTING
        POPUP_TITLE           = 'Value Insert'
      TABLES
        FIELDS                = fields.
    Regards, Dieter

  • Calculating previous month and year of the previous month

    Hi frenz,
    Can anybody know FM to calculate the previous month and year of the previous month.
    are there any standard FMs existed to achieve this?
    br,
    anil.

    hi,
    lv_period gives the month and year which is two months earlier now as we have specified lv_months as -2.
        DATA: LV_PERIOD LIKE S001-SPMON,
              LV_MONTHS(2) TYPE C VALUE '2-',
              LV_DATUM LIKE SY-DATUM,
              LV_NEWDT LIKE SY-DATUM,
            P_SPMON LIKE S001-SPMON VALUE '200601'.
        CONCATENATE P_SPMON '01' INTO LV_DATUM.
        LV_PERIOD = P_SPMON+0(6).
        CALL FUNCTION 'MONTH_PLUS_DETERMINE'
             EXPORTING
                  MONTHS  = LV_MONTHS
                  OLDDATE = LV_DATUM
            IMPORTING
                 NEWDATE = LV_NEWDT
             EXCEPTIONS
                  OTHERS  = 1.
         IF SY-SUBRC = 0.
           LV_PERIOD = LV_NEWDT+0(6).
         ENDIF.
    WRITE :/ LV_PERIOD.
    Regards,
    Sailaja.

  • Function Module for calculation of the net price of a configurable material

    Hi,
    I would like to know if a function module allows to calculate the purchasing /net price of a configurable material at a vendor and at a requested delivery date before the creation of a purchasing order.
    For configurable materials, we have no PIR and no moving / standard price thus the valuation price in the PR is blank.
    I would like to fill in the field "valuation price" in the PR with the net price we can find in the PO.
    However the PR is created before the PO.
    Thanks a lot in advance for yours reply.
    regards,

    hi Pravenn,
    I don't know about these functions, but u can try anything like this:
    data:
    strdate like sy-datum value '20070901',
          enddate like sy-datum value '20070909',
          date(10),
          moddate(1).
    date = enddate - strdate + 1.
    moddate = date mod 7.
    date = date div 7.
    if moddate <> 0.
      date = date + 1.
    endif.
    write: / date.
    Regards
    Allan Cristian
    Message was edited by:
            Allan Cristian

  • Function Module To read all the Files in a Given UNIX directory.

    Can anyone provide me with a FUNCTION MODULE which reads all the files available in a UNIX directory?
    I have the UNIX directory given. I need to find all the files available in that particular Directory so that I can choose and process accordingly. Probably I can store all files in an Internal Table.
    Thanks in advance.
    Sunil

    Hi Nick,
    Thankyou very much for the response.
    The Function Module /SAPDMC/LSM_F4_SERVER_FILE is interactive wherein we can select only one file.
    But my requirement is I need to collect (probably in an internal table) all the files exixting in the given UNIX directory.
    Can you please find in that direction. I would be very grateful.
    Thanks.
    Sunil

  • Any Function Module which will give user id or position

    Hello Friends,
       is there any standard function module which will give the attribute position id or user name if i pass the 'attribute id as CNT' with value of the CNT. i know there is a standard function module 'BBP_READ_ATTRIBUTES'. but this FM will give the value of the attribute id if i pass the user id and attribute id but i want user id or position when i pass attribute id and value.
    john.

    Hi,
    See this related thread:
    Re: Get all users given a specific product category
    You cna use the similar approach to find for the attribte cost centre.
    BR,
    Disha.

  • Function module to get the same date of the previous month

    Hi
    Can anybody tell me how to get the
    same date of the previous month.
    example if i am entering date as 30 may 2007
    i want the date as 30 april 2007

    CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL'
    EXPORTING
    date = pa_end
    days = '00'
    months = '01'
    signum = '-'
    years = '00'
    IMPORTING
    calc_date = pa_end.
    ENDIF.
    nd try below FMs as well...
    CCM_GO_BACK_MONTHS
    HR_PT_ADD_MONTH_TO_DATE
    RP_CALC_DATE_IN_INTERVAL
    Hope it will solve your problem...
    Reward points if useful..
    Thanks & Regards
    ilesh 24x7

  • Function module which calculates GL balances

    Hello to you all,
    I am looking for a function module which calculates balances for GL account as Tcode FS10N do.
    I would like to implement this FM in an ABAP program,
    Thanks,
    Amir

    Hi
    Check the  Code, if it could be of use to you
    http://www.sapfans.com/forums/viewtopic.php?f=10&t=317349
    Regards
    Sanil Bhandari
    Edited by: Sanil K Bhandari on Jun 29, 2011 6:17 PM

  • Function to retrieve all days of the previous month.

    Hi,
    Yes, it's a monthly report i've been given the task to achieve.
    So, all I need is all days of previous month (even if there is no data for this day)
    I've been instructed to use the following code, but it does not return any value:
    DECLARE
       CURSOR CUR_LAST_DAY IS
          SELECT TO_CHAR (LAST_DAY (ADD_MONTHS (SYSDATE, -1) ), 'DD')
            FROM DUAL;
       VVA_LAST_DAY   VARCHAR2 (2);
       VNU_JOUR       NUMBER       := 0;
    BEGIN
       OPEN CUR_LAST_DAY;
       FETCH CUR_LAST_DAY
        INTO VVA_LAST_DAY;
       CLOSE CUR_LAST_DAY;
       WHILE VNU_JOUR <= TO_NUMBER (VVA_LAST_DAY) - 1
       LOOP
          VNU_JOUR := VNU_JOUR + 1;
       END LOOP;
    END;
    --CLOSE CUR_LAST_DAY
    --DEALLOCATE CUR_LAST_DAY-----
    On the other end, i've developped this code:
    SELECT TO_CHAR(SYSDATE,'dd')
    FROM DUAL
    WHERE TO_CHAR(SYSDATE,'dd') >= to_char(to_date(to_char(ADD_MONTHS(SYSDATE, -1),'yyyy-mm')||'-01'),'yyyy-mm-dd')
    AND TO_CHAR(SYSDATE,'dd') < to_char(LAST_DAY(to_date(to_date(to_char(ADD_MONTHS(SYSDATE, -1),'yyyy-mm')||'-01'),'yyyy-mm-dd')));Which is returning a null value. :(
    Regards

    Hello,
    You want to retrieve complete days of last month from one query...so here it is..
    SELECT
    TO_DATE(LEVEL||'-'||TO_CHAR(ADD_MONTHS(SYSDATE,-1),'MON-YY'),'DD-MON-YY') COMP_DATE,
    TO_CHAR(TO_DATE(LEVEL||'-'||TO_CHAR(ADD_MONTHS(SYSDATE,-1),'MON-YY'),'DD-MON-YY'),'DD') ONLY_DD,
    TO_CHAR(TO_DATE(LEVEL||'-'||TO_CHAR(ADD_MONTHS(SYSDATE,-1),'MON-YY'),'DD-MON-YY'),'MM') ONLY_MM,
    TO_CHAR(TO_DATE(LEVEL||'-'||TO_CHAR(ADD_MONTHS(SYSDATE,-1),'MON-YY'),'DD-MON-YY'),'YY') ONLY_YY
    FROM DUAL
    CONNECT BY LEVEL <= TO_NUMBER(TO_CHAR(LAST_DAY(ADD_MONTHS(SYSDATE,-1)),'DD'))I am not at database machine so therefore not tested.
    But one thing keep in mind that this forum only for reports there is separate forum for sql and pl/sql.
    Function to retrieve all days of the previous month.
    -Ammad
    Edited by: Ammad Ahmed on Apr 22, 2010 10:53 PM
    Spelling Mistake

  • What is the function module which is used to trigger email

    Hi ALL,
    can u send me the function module which has to trigger email when sales order was saved.
    kindly send me the inputs
    thanks & regards
    naveen
    Moderator Message: Basic Question. Thread locked.
    Edited by: kishan P on Nov 11, 2010 10:56 AM

    Hi,
    This needs to coded in the Save User Exit of the Sales Order Include MV45AFZZ (USEREXIT_SAVE_DOCUMENT) and use the Function Module "SO_DOCUMENT_SEND_API1" to trigger a mail.
    Please try this and let me know if any.
    Regards,
    Srinivas
    Moderator Message: Do not answer Basic Question.
    Edited by: kishan P on Nov 11, 2010 10:58 AM

  • Functional module which get triggered after posting of the document F-22

    Hi,
    I am posting the documents using the transaction F-22. I need to update some table after the documet will get post.
    I try to find out the BTE'S in the transaction FIBF but unable to find it out.
    Can anyone help me to find out the relvant functional module which will get triggered after the posting of the documents.
    Please help me with this.
    Thanks in advanced.
    Regards,
    Darshana

    Hi Harini,
    It is also not get triggered while i am posting the documents.
    Can you please suggest me some more functional modules.
    Thanks in advanced.
    Regards,
    Darshana

  • Function module which sort the entries in Table maintance generator

    hi
        I want to know the function module which is used to sort the entirs in table maintance genrator.
    Thanks

    Hi,
    Go to the TMG program .You can change the code there.
    Rgds,
    Anversha

  • I need to create RFC function module which creates the IDOC

    Hi-
    Any idea how to create RFC function module which creates the outbound IDOC. If you have any sample code please forward to me.
    Thanks,
    Sony

    My Problem is
    Whenever they create Invoice using T-code's like FV65(Parked Document), automatically should create IDOC's...
    I have used message type FIDCC1 but this message type is usefull only for Posting documents.
    1. Whenever they create parked document, entries will be stored in BKPF(Parked Document-Filed-BKPF-BSTAT = 'V') and Bseg....
    2. I have to read entries from those tables and should create IDOC...
    3. I checked FM's(FI_IDOC_CREATE_FIDCC1, FI_IDOC_PREPARE) but are not useful...
    4. Now I need to write one RFC function module and that FM should create the IDOC's....
    Can anyone please help me out?
    Thanks,
    Sony

Maybe you are looking for

  • I can't upload photos to my ipod touch!... Unknow error (-50)

    i have windows vista 64 bits and itunes 8.0.2.20, and every time i try to sync, when it's optimizing display a message "the ipod .... cannot be synced. An unknown error ocurred (-50)" I tried to reinstall itunes so many times and it doesn't work.. so

  • Rule not un-doing!

    Hello, I've set a parameter (criteria) in a rule that made it move all my emails in an inbox into the trash. Yet I removed these criteria but nothing happened and new email continued to be received in the trash. How can I get back mail to be like it

  • Stop updating firefox every month

    Why does firefox have to update so often? If you guys can't get it right, then maybe you need to hire some smarter people. But seriously, Firefox asks me to update WAY too often and I am getting sick of it. I do not like updates. And I never seen a m

  • Layout problem - Huge headache

    Hi guys, So I'm having this problem with placed images/generated shapes shifting down the page when going from design mode to preview mode and it's giving me a huge headache. Here's how it looks in Design mode: Here's how it looks when I preview: Any

  • Modifying and saving a Excel file by the use of Blob-Stream Method?

    Hi everyone... I'm trying to change and modify a Excel file which is received as Blob variable from database. I wrote a PL/SQL Procedure which get the Excel file and convert it to blob; after that send it as the parameter of a Java source called Test