cancel
Showing results for 
Search instead for 
Did you mean: 

ABAP ROUTINE 4 INFOPACKAGE AND DTP - LAST MONTH

fthomazetti_costa
Participant
0 Kudos

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,

View Entire Topic
RafkeMagic
Active Contributor
0 Kudos

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.

fthomazetti_costa
Participant
0 Kudos

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