Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

ABAP CODE

Former Member
0 Likes
1,109

Hello Friends,

I have a requirement where I have to do multiple iterations and extract data from the same table couple of time based on a particular field from the same table.

I have an IT T_COBRB and it has data in it.

In this table if the field PS_PSP_PNR is not blank then I have to access data from the same table (COBRB) based on (WHERE OBJNR = T_COBRB-REC_OBJNR1) and delete the record where T_COBRB-PS_PSP_PNR is not blank.

I have written this piece of code. Please suggest if its ok and also let me know if it could be improved in performance.


  LOOP AT T_COBRB WHERE PS_PSP_PNR <> ''.

    SELECT * FROM COBRB
      INTO TABLE T_COBRB_TMP
     WHERE OBJNR = T_COBRB-REC_OBJNR1
       AND ( ( GABJA LE SY-DATUM+0(4)
       AND GABPE LE SY-DATUM+4(2)
       AND GBISJ GE SY-DATUM+0(4)
       AND GBISP GE SY-DATUM+4(2) )
        OR ( GBISJ = '' ) ).

    DELETE T_COBRB.

    LOOP AT T_COBRB_TMP.
      APPEND T_COBRB.
    ENDLOOP.

  ENDLOOP.

Ster

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
987

<b></b>its ok good job

6 REPLIES 6
Read only

Former Member
0 Likes
988

<b></b>its ok good job

Read only

Former Member
0 Likes
987

write this way...

SELECT * FROM COBRB

INTO TABLE T_COBRB_TMP

for all entries of T_COBRB

WHERE OBJNR = T_COBRB-REC_OBJNR1

AND ( ( GABJA LE SY-DATUM+0(4)

AND GABPE LE SY-DATUM+4(2)

AND GBISJ GE SY-DATUM+0(4)

AND GBISP GE SY-DATUM+4(2) )

OR ( GBISJ = '' ) ).

LOOP AT T_COBRB WHERE PS_PSP_PNR <> ''.

Read table T_COBRB_TMP with key OBJNR = T_COBRB-REC_OBJNR1.

if sy-subrc = 0.

DELETE T_COBRB.

endif.

ENDLOOP.

Read only

0 Likes
987

Thanks Ramesh.

I guess the way you have specified would work good only for 2 iterations. But i have to do multiple iterations.

Ster.

Read only

Former Member
0 Likes
987

Hi Ster,

You can do this instead,

/*

SELECT* FROM COBRM

INTO TABLE T_COBRB_TMP.

DELETE T_COBRB WHERE PS_PSP_PNR IS NULL.

CLEAR W_COBRB.

LOOP AT T_COBRB INTO W_COBRB.

CLEAR W_COBRB_TMP.

READ T_COBRB_TMP INTO W_COBRB_TMP

WITH KEY OBJNR = T_COBRB-REC_OBJNR1

GABJA <= SY-DATUM+0(4)

GABPE <= SY-DATUM+4(2)

GBISJ >= SY-DATUM+0(4)

GBISP >= SY-DATUM+4(2).

IF SY-SUBRC EQ 0.

APPEND W_COBRB_TMP TO T_COBRB.

CLEAR W_COBRB_TMP.

ENDIF.

CLEAR W_COBRB.

ENDLOOP.

*/

<b>Reward points if this helps,</b>

Kiran

Read only

marcelo_ramos1
SAP Mentor
SAP Mentor
0 Likes
987

Hi,

Try this code, it's increase you performance.

<b> DELETE t_cobrb WHERE ps_psp_pnr NE space.

DELETE ADJACENT DUPLICATES FROM t_cobrb COMPARING rec_objnr1.

IF NOT t_cobrb[] IS INITIAL.

SELECT * FROM cobrb

INTO TABLE t_cobrb_tmp

FOR ALL ENTRIES IN t_cobrb[]

WHERE objnr = t_cobrb-rec_objnr1

AND ( ( gabja LE sy-datum+0(4)

AND gabpe LE sy-datum+4(2)

AND gbisj GE sy-datum+0(4)

AND gbisp GE sy-datum+4(2) )

OR ( gbisj = '' ) ).

IF sy-subrc IS INITIAL.

MOVE t_cobrb_tmp[] TO t_cobrb[].

ENDIF.

ENDIF.</b>

Regards.

Marcelo Ramos

Read only

former_member194669
Active Contributor
0 Likes
987

Hi,

Check this


 T_COBRB_1[] = T_COBRB[].
  DELETE T_COBRB_1 WHERE PS_PSP_PNR <> ' '.
  SORT T_COBRB_1 BY PS_PSP_PNR.
  DELETE ADJACENT DUPLICATES FROM T_COBRB_1 COMPARING PS_PSP_PNR.

  IF NOT T_COBRB_1[] IS INITIAL.

    SELECT * FROM COBRB
      INTO TABLE T_COBRB   "<< check this
     FOR ALL ENTRIES IN T_COBRB_1  "<< check this
     WHERE OBJNR = T_COBRB_1-REC_OBJNR1
       AND ( ( GABJA LE SY-DATUM+0(4)
       AND GABPE LE SY-DATUM+4(2)
       AND GBISJ GE SY-DATUM+0(4)
       AND GBISP GE SY-DATUM+4(2) )
        OR ( GBISJ = '' ) ).
  ENDIF.

aRs