Skip to Content
0

ABAP ROUTINE 4 INFOPACKAGE AND DTP - LAST MONTH

Nov 01, 2016 at 07:31 PM

227

avatar image
Former Member

Hello Experts,

I've an abap routine in my InfoPackage and another one in my DTP. Both refers to "Day -1".

I've to change them to consider "last month". No matter the day of the current month that I'll execute it, always consider last month.

Could you please help me?

Here's the InfoPackage routine:

program conversion_routine.
* Type pools used by conversion program
type-pools: rsarc, rsarr, rssm.
tables: rssdlrange.
* Global code used by conversion rules
*$*$ begin of global - insert your declaration only below this line *-*
* TABLES: ...
* DATA: ...
*$*$ end of global - insert your declaration only before this line *-*
* -------------------------------------------------------------------
* InfoObject =
* Fieldname = PDATA
* data type = DATS
* length = 000008
* convexit =
* -------------------------------------------------------------------
form compute_PDATA
tables l_t_range structure rssdlrange
using p_infopackage type rslogdpid
p_fieldname type rsfnm
changing p_subrc like sy-subrc.

data: l_idx like sy-tabix.
read table l_t_range with key

fieldname = 'PDATA'.

l_idx = sy-tabix.

data: g_date(6) type n.
data: g_date1 type d.
data: g_date2 type d.

g_date1 = sy-datum.
g_date = g_date1+0(6).

clear g_date1.

concatenate g_date '01' into g_date1.

g_date2 = sy-datum - 1.

l_t_range-iobjnm = 'ZPDATA'.
l_t_range-FIELDNAME = 'PDATA'.
l_t_range-sign = 'I'.
L_T_RANGE-OPTION = 'BT'.
l_t_range-LOW = g_date1.
l_t_range-high = g_date2.

modify l_t_range index l_idx.

p_subrc = 0.

Here's my DTP routine:

*&---------------------------------------------------------------------*
*& Include RSBC_SEL_ROUTINE_TPL
*&---------------------------------------------------------------------*

program conversion_routine.
* Type pools used by conversion program
type-pools: rsarc, rsarr, rssm.
tables: rssdlrange.
* Global code used by conversion rules
*$*$ begin of global - insert your declaration only below this line *-*
* TABLES: ...
* DATA: ...
*$*$ end of global - insert your declaration only before this line *-*
* -------------------------------------------------------------------
* Fieldname = PSTNG_DATE
* data type = DATS
* length = 000008
* -------------------------------------------------------------------
form c_PSTNG_DATE
tables l_t_range structure rssdlrange
using i_r_request type ref to IF_RSBK_REQUEST_ADMINTAB_VIEW
i_fieldnm type RSFIELDNM
changing p_subrc like sy-subrc.
* Insert source code to current selection field
*$*$ begin of routine - insert your code only below this line *-*

DATA: L_IDX LIKE SY-TABIX.
DATA: W_T_RANGE TYPE RSSDLRANGE.
DATA: G_DATE(6) TYPE N.
DATA: G_DATE1 TYPE D.
DATA: G_DATE2 TYPE D.

G_DATE1 = SY-DATUM.
G_DATE = G_DATE1+0(6).

CLEAR G_DATE1.

CONCATENATE G_DATE '01' INTO G_DATE1.

G_DATE2 = SY-DATUM - 1.

W_T_RANGE-IOBJNM = 'PSTNG_DATE'.
W_T_RANGE-FIELDNAME = 'PSTNG_DATE'.
W_T_RANGE-SIGN = 'I'.
W_T_RANGE-OPTION = 'BT'.
W_T_RANGE-LOW = G_DATE1.
W_T_RANGE-HIGH = G_DATE2.

APPEND W_T_RANGE TO L_T_RANGE.

P_SUBRC = 0.

*$*$ end of routine - insert your code only before this line *-*
endform.

Thanks,

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Best Answer
Raf Boudewijns Nov 15, 2016 at 07:42 AM
0

Ok, now you're clear ;-)

You could do this in the routine by checking on the last 2 characters of your date, in this case SY-DATUM+6(2). When "less or equal" than 5, take previous month, otherwise take this month.

A better solution (in my opinion) would be to work with a "decision step" in the process chain (which checks on the day) and have 2 DTPs ready. In this case when your "number of days" should change, you simply need to modify the process chain (instead of changing the routine) and it's "visually" more clear what happens.

Show 1 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Hello Raf,

I got it! ;-)

I used SY-DATUM+6(2) working with some "hard codes" according the situation (last month or current day) and it's working perfectly! I thought to use a decision step in my PCs, but as all of my process are automatics, with a lot of steps, jobs, etc (well I think I created a monster), I was afraid concerning the consequences in case of an error.

I appreciate you help, support and patience.

Thank you,

Flávio

0
Raf Boudewijns Nov 02, 2016 at 08:36 AM
0

You're currently selecting everything between <the first day of this month > and <the last day of the previous month> which doesn't make sense. So your low value should be the first day of the previous month...

Also, when you need to change "dates" you could use function module RSARCH_DATE_SHIFT (instead of the string manipulation you're currently doing).

Show 1 Share
10 |10000 characters needed characters left characters exceeded
Former Member

I'm selecting everything between <the first day of the current month> and <the "day before today" (day-1) of the current month> during the current month. I've two problems in my routines:

- I never have data from the last day of the month. No matter if the month ends on 28/29, 30 or 31, I never load registers from this day because the next day is the first day of the new month, so my routine works in this new month.

- The first day of the month is a day without registers. As I'm selecting everything between <the first day of the current month> and <the "day before today" (day-1) of the current month>, in the day 1 what I'll select? Nothing.

These two routines are working for me, but I've to create another one to cover up these "gaps".

0
Raf Boudewijns Nov 08, 2016 at 03:14 PM
0

so your goal is to load "month to date" figures? but you have a "special" behaviour for the 1st day of the month... the question is: what do you want then? just 1 day? or the entire previous month? when you know the answer to this question, we can proceed.

Show 1 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Hello Raf,
I think I'm not clear enough.
In a simple way:
We're in November. From 1st until 5th November, I need to select October (full month).
From 6th until 30th November, I need to select the current month following the rule day-1. For example, in 6th November select data from 1st until 5th. In 7th November, 1st until 6th, and so on until 30th November, where I'll have data from 1st until 29th. From 1st until 5th December, I'll have a full November including 30th.

A perfect solution would be include these two requisites in one routine.

Thanks,

0