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

problem with condition statement...

aris_hidalgo
Contributor
0 Likes
1,243

Hello experts,

Can you please give me a condition that if a material's movement type is 702, 708, 712 and 718 it would instead be moved to a different table named t_ztm_acc_variance. Below is the code that I am trying to modify. Thanks guys!

PERFORM get_new_variance.

FORM get_new_variance.

LOOP AT it_objk.

READ TABLE it_ser03 WITH KEY obknr = it_objk-obknr.

IF sy-subrc EQ 0.

LOOP AT it_mseg_mara WHERE mblnr = it_ser03-mblnr

AND mjahr = it_ser03-mjahr

AND zeile = it_ser03-zeile

AND bwart = it_ser03-bwart

AND werks = it_ser03-werk

AND lgort = it_ser03-lagerort.

CLEAR t_ztm0019_dum.

LOOP AT t_ztm0019_dum WHERE matnr = it_mseg_mara-matnr

AND sernr = it_objk-sernr.

MOVE: 'X' TO t_ztm0019_dum-delete_flag.

MODIFY t_ztm0019_dum.

ENDLOOP.

MOVE: it_mseg_mara-werks TO t_ztm0019-werk,

it_mseg_mara-lgort TO t_ztm0019-lagerort,

it_mseg_mara-matkl TO t_ztm0019-matkl,

it_mseg_mara-matnr TO t_ztm0019-matnr,

it_mseg_mara-mblnr TO t_ztm0019-mblnr,

it_mseg_mara-bwart TO t_ztm0019-bwart,

it_mseg_mara-grund TO t_ztm0019-grund,

it_mseg_mara-sgtxt TO t_ztm0019-sgtxt.

MOVE: it_objk-sernr TO t_ztm0019-sernr,

it_objk-equnr TO t_ztm0019-equnr.

READ TABLE it_ztm0020 WITH KEY bwart = it_mseg_mara-bwart.

MOVE: it_ztm0020-ztype TO t_ztm0019-lbbsa.

SELECT SINGLE maktx INTO t_ztm0019-maktx

FROM makt

WHERE spras = 'EN'

AND matnr = it_mseg_mara-matnr.

SELECT SINGLE wgbez INTO t_ztm0019-wgbez

FROM t023t

WHERE matkl = it_mseg_mara-matkl.

SELECT SINGLE lgobe INTO t_ztm0019-lgobe

FROM t001l

WHERE lgort = it_mseg_mara-lgort.

t_ztm0019-verpr = it_mseg_mara-dmbtr / it_mseg_mara-erfmg.

READ TABLE it_mkpf WITH KEY mblnr = it_ser03-mblnr

mjahr = it_ser03-mjahr

MOVE: it_mkpf-budat TO t_ztm0019-budat,

it_mkpf-bldat TO t_ztm0019-bldat,

it_mkpf-usnam TO t_ztm0019-usnam.

MOVE: it_ser03-datum TO t_ztm0019-datum,

it_ser03-uzeit TO t_ztm0019-uzeit.

APPEND t_ztm0019.

CLEAR t_ztm0019.

ENDLOOP.

ENDIF.

ENDLOOP.

ENDFORM. " GET_NEW_VARIANCE

1 ACCEPTED SOLUTION
Read only

vinod_gunaware2
Active Contributor
0 Likes
1,225

Hi

Copy Orignal table into another table.

From orignal table delete entries whose movement type is

702,708,712, and 718 by using delete statment.

and from other table delete entries whose movement type is not equal to 702,708,712, and 718 by using delete statment.

regard

vinod

11 REPLIES 11
Read only

Former Member
0 Likes
1,225

Hi viraylab,

You can do like this..

APPEND LINES OF TABLE tblnm TO t_ztm_acc_variance.

DELETE t_ztm_acc_variance WHERE movty NE '702' OR

movty NE '708' OR

movty NE '712' OR

movty NE '718'.

Read only

Former Member
0 Likes
1,225

hi Viraylab,

you can use ranges..

data : <f> like itab-<fieldname>.

ranges : range for <f>.

range-low = '702'.

range-sign = 'I'.

range-option = 'EQ'.

append Range.

range-low = '708'.

range-sign = 'I'.

range-option = 'EQ'.

append Range.

range-low = '712'.

range-sign = 'I'.

range-option = 'EQ'.

append Range.

range-low = '718'.

range-sign = 'I'.

range-option = 'EQ'.

append Range.

loop at itab where <field> in range.

move itab to t_ztm_acc_variance.

append t_ztm_acc_variance.

endloop.

regards

satesh

Read only

vinod_gunaware2
Active Contributor
0 Likes
1,226

Hi

Copy Orignal table into another table.

From orignal table delete entries whose movement type is

702,708,712, and 718 by using delete statment.

and from other table delete entries whose movement type is not equal to 702,708,712, and 718 by using delete statment.

regard

vinod

Read only

0 Likes
1,225

hello guys, Thanks for the expert replies. However, I do not want records that contains 702, 708, 712 and 718 to be added to t_ztm0019.How can I restrict that given the code above?thank you so much guys...

Read only

0 Likes
1,225

delete t_ztm0019 where cond = 712

or cond = 718

or................

Read only

0 Likes
1,225

delete t_ztm0019 where cond = 712

or cond = 718

or................

Read only

0 Likes
1,225

hi Viray,

You can use my previuos post with a little modification..

use

<b>range-sign = 'E'.</b> an all places..

which means Excluding..

then select * from ... where <f> in range..

regards

satesh

Read only

0 Likes
1,225

Hello satesh, If you don't mind, can you give me an example using my code above? I'm really new to abap so please bear with me:) thanks you so much.

Read only

0 Likes
1,225

HI Viary,

hope BWART is the movement type..

so when you populate the table itab <b>t_ztm0019</b> using select statement, use the following ranges for your selection..

TABLES:MSEG.
data : char like mseg-bwart.
data : t_ztm0019 like table of mseg with header line.
ranges : range for char.
range-low = '708'.
range-sign = 'E'.
range-option = 'EQ'.
append Range.

range-low = '712'.
range-sign = 'E'.
range-option = 'EQ'.
append Range.

range-low = '712'.
range-sign = 'E'.
range-option = 'EQ'.
append Range.

range-low = '718'.
range-sign = 'E'.
range-option = 'EQ'.
append Range.


select * from mseg into table t_ztm0019 where BWART in range.

this will stop all four movement types into t_ztm0019..

regards

satesh

Read only

0 Likes
1,225

Hi,

As per my understanding of ur req i added some codes in ur prg. just try it.

PERFORM GET_NEW_VARIANCE.

FORM GET_NEW_VARIANCE.

LOOP AT IT_OBJK.

READ TABLE IT_SER03 WITH KEY OBKNR = IT_OBJK-OBKNR.

IF SY-SUBRC EQ 0.

LOOP AT IT_MSEG_MARA WHERE MBLNR = IT_SER03-MBLNR

AND MJAHR = IT_SER03-MJAHR

AND ZEILE = IT_SER03-ZEILE

AND BWART = IT_SER03-BWART

AND WERKS = IT_SER03-WERK

AND LGORT = IT_SER03-LAGERORT.

CLEAR T_ZTM0019_DUM.

LOOP AT T_ZTM0019_DUM WHERE MATNR = IT_MSEG_MARA-MATNR

AND SERNR = IT_OBJK-SERNR.

MOVE: 'X' TO T_ZTM0019_DUM-DELETE_FLAG.

MODIFY T_ZTM0019_DUM.

ENDLOOP.

MOVE: IT_MSEG_MARA-WERKS TO T_ZTM0019-WERK,

IT_MSEG_MARA-LGORT TO T_ZTM0019-LAGERORT,

IT_MSEG_MARA-MATKL TO T_ZTM0019-MATKL,

IT_MSEG_MARA-MATNR TO T_ZTM0019-MATNR,

IT_MSEG_MARA-MBLNR TO T_ZTM0019-MBLNR,

IT_MSEG_MARA-BWART TO T_ZTM0019-BWART,

IT_MSEG_MARA-GRUND TO T_ZTM0019-GRUND,

IT_MSEG_MARA-SGTXT TO T_ZTM0019-SGTXT.

MOVE: IT_OBJK-SERNR TO T_ZTM0019-SERNR,

IT_OBJK-EQUNR TO T_ZTM0019-EQUNR.

READ TABLE IT_ZTM0020 WITH KEY BWART = IT_MSEG_MARA-BWART.

MOVE: IT_ZTM0020-ZTYPE TO T_ZTM0019-LBBSA.

SELECT SINGLE MAKTX INTO T_ZTM0019-MAKTX

FROM MAKT

WHERE SPRAS = 'EN'

AND MATNR = IT_MSEG_MARA-MATNR.

SELECT SINGLE WGBEZ INTO T_ZTM0019-WGBEZ

FROM T023T

WHERE MATKL = IT_MSEG_MARA-MATKL.

SELECT SINGLE LGOBE INTO T_ZTM0019-LGOBE

FROM T001L

WHERE LGORT = IT_MSEG_MARA-LGORT.

T_ZTM0019-VERPR = IT_MSEG_MARA-DMBTR / IT_MSEG_MARA-ERFMG.

READ TABLE IT_MKPF WITH KEY MBLNR = IT_SER03-MBLNR

MJAHR = IT_SER03-MJAHR

MOVE: IT_MKPF-BUDAT TO T_ZTM0019-BUDAT,

IT_MKPF-BLDAT TO T_ZTM0019-BLDAT,

IT_MKPF-USNAM TO T_ZTM0019-USNAM.

MOVE: IT_SER03-DATUM TO T_ZTM0019-DATUM,

IT_SER03-UZEIT TO T_ZTM0019-UZEIT.

APPEND T_ZTM0019.

CLEAR T_ZTM0019.

*********************************

  • insertion of code.

IF IT_MSEG_MARA-BWART EQ '702' AND

IT_MSEG_MARA-BWART EQ '708' AND

IT_MSEG_MARA-BWART EQ '712' AND

IT_MSEG_MARA-BWART EQ '718'.

MOVE-CORRESPONDING IT_MSEG_MARA TO T_ZTM_ACC_VARIANCE.

  • { fill all the fields in t_ztm_acc_variance table)

APPEND T_ZTM_ACC_VARIANCE.

CLEAR T_ZTM_ACC_VARIANCE.

ENDIF

  • end of insertion

********************************

ENDLOOP.

ENDIF.

ENDLOOP.

ENDFORM. " GET_NEW_VARIANCE

venkatesh

Read only

0 Likes
1,225

hello venkateshkumar,

Should I use 'AND' or should I use 'OR' in your IF statement? And also, How can I delete records from T_ZTM0019 that contains those restrictions I said after appending them as from the code given. Where would place the delete statement?thanks!