Skip to Content
-1

ABAP ROUTINE CURRENT DAY -1 IN DTP

Oct 21, 2016 at 06:21 PM

184

avatar image
Former Member

Hello Experts!

I've an ODS with a lot of registers of a several periods, so I use a DTP to transfer only registers that starts in the day 1 (of the current month) until the current day -1 to another ODS.

Example: Today is 21/10/2016 - My DTP will transfer only data from 01/10/2016 to 20/10/2016.

Tomorrow (22/10) it'll transfer from 01/10/2016 to 21/10/2016, then successively...

I'm using the following ABAP 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.
read table l_t_range with key
fieldname = 'PSTNG_DATE'.
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 = 'ZPSTNG_DATE'.
l_t_range-FIELDNAME = 'PSTNG_DATE'.
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.


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


But when it's executed, I've a dump in ST22: TABLE_INVALID_INDEX.

What is wrong?

Can you help me?

Thanks in advanced,

Flávio Costa

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

2 Answers

Best Answer
Raf Boudewijns Oct 25, 2016 at 06:33 AM
0

Your problem is with this line:

modify l_t_range index l_idx.

I would usually put something like:

if l_idx is initial.

append l_t_range.

else.

modify l_t_range index l_idx.

endif.

Share
10 |10000 characters needed characters left characters exceeded
Nanda Anantha Oct 24, 2016 at 04:14 PM
0

Hi Flvio Costa,

TABLE_INVALID_INDEX occurs when internal table is empty so replace your code as like below.

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.

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

Thanks!

It worked perfectly!

1

While it is true to say you get this error when the table is empty - it's not entirely accurate. You get this error when you use an index that is greater than the number records in the table. Basic ABAP programming.

Furthermore, do you understand why it works perfectly? Your original code refers to infoobject ZPSTNG_DATE, this answer refers to PSTNG_DATE.

0
Former Member
Matthew Billingham

Hi Matthew,
I already had changed the InfoObject before (ZPSTNG_DATE to PSTNG_DATE), but still didn't working. So, probably my error was related to the table. Thanks for your contribution.

0