Application Development 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: 

select-options issue

Former Member
0 Kudos

hello gurus

I have an internal table itab, it has key pernr.

and in selection screen i have select-options for werks.

now if the select-options is empty then i have to move all the records from itab into itab1, but if its not empty then i want to copy only those records that have a matching werks from select-options into another database table pa0315 with key pernr.

i can use selects with if condition, i was wondering if you have a better idea

10 REPLIES 10

Former Member
0 Kudos

Hi,

Use the


 if


else


Endif.

Statement

If value enter than copy with passing that value into where clause

ELSE

Copy to all

Thanks

Arun kayal

Former Member
0 Kudos

Hi Rocky ,

Here a logic id like to share .

say your select option is s_werks

if s_werk is INITIAL.

move itab to itab1 .

elseif s_werks = '001'.

move itab where werks in s_werks to itab1 .

endif .

this is basic logic.

Hope it helps!

Much Regards ,

Amuktha .

Former Member
0 Kudos

Hi,

If not s_works[] is initial.
 DELETE itab WHERE werks not in s_werks.
" Now you will have all the entries which werks passed in the selection screen
ELSE.
 Itab1[] = itab[].
ENDIF.

Former Member
0 Kudos

Due to the nature of SELECT-OPTIONS, you can do this with the one loop.


LOOP AT ITAB 
    WHERE WERKS in (select-option for WERKS).
   APPEND itab TO itab1.
ENDLOOP.

If your select option is null, all records will be copied. Otherwise, ITAB-WERKS must be within

the values in the SELECT-OPTIONS range.

0 Kudos

hi Paul,

I tried teh same, however when select-options is empty, it doest return anything.

0 Kudos

If the select option is blank then the below statement will delete all the records frm itab.

DELETE itab WHERE werks NOT IN s_werks [].

0 Kudos

Must be a version issue Rocky. I'm running on 4.6c and this works fine.


DATA:
  BEGIN OF my_rec,
    fld1          TYPE c,
    fld2(4)       TYPE c,
  END OF my_rec,
  itab LIKE STANDARD TABLE OF my_rec,
  itab1 LIKE STANDARD TABLE OF my_rec.

SELECT-OPTIONS s_fld FOR my_rec-fld1.

START-OF-SELECTION.

  PERFORM load_the_table.

  REFRESH itab1.
  LOOP AT itab INTO my_rec WHERE fld1 IN s_fld.
    APPEND my_rec TO itab1.
  ENDLOOP.

  LOOP AT itab1 INTO my_rec.
    WRITE:/ my_rec-fld1, my_rec-fld2.
  ENDLOOP.

*&---------------------------------------------------------------------*
*&      Form  load_the_table
*&---------------------------------------------------------------------*
FORM load_the_table.

  my_rec-fld1 = '1'. my_rec-fld2 = 'AA  '. APPEND my_rec TO itab.
  my_rec-fld1 = '1'. my_rec-fld2 = 'AB  '. APPEND my_rec TO itab.
  my_rec-fld1 = '1'. my_rec-fld2 = 'AC  '. APPEND my_rec TO itab.
  my_rec-fld1 = '2'. my_rec-fld2 = 'BA  '. APPEND my_rec TO itab.
  my_rec-fld1 = '2'. my_rec-fld2 = 'BB  '. APPEND my_rec TO itab.
  my_rec-fld1 = '2'. my_rec-fld2 = 'BC  '. APPEND my_rec TO itab.
  my_rec-fld1 = '3'. my_rec-fld2 = 'CA  '. APPEND my_rec TO itab.
  my_rec-fld1 = '3'. my_rec-fld2 = 'CB  '. APPEND my_rec TO itab.
  my_rec-fld1 = '3'. my_rec-fld2 = 'CC  '. APPEND my_rec TO itab.
  my_rec-fld1 = '1'. my_rec-fld2 = 'AD  '. APPEND my_rec TO itab.

ENDFORM.                    " load_the_table

Former Member
0 Kudos

IF s_werks [] IS INITIAL.

*Move the data from 1 table to another

Itab1 = itab.

ELSE.

  • Delete all the entries other than selection screen werks.

DELETE itab WHERE werks NOT IN s_werks [].

Itab1 = itab .

ENDIF.

Former Member
0 Kudos

Hi

Instead of having selects with if condition, this will be good i feel.

tables:

pa0315.

data:

t_itab type table of pa0315 with key pernr.

select-options:

s_werks for pa0315-werks.

select * from pa0315 into table t_itab where werks in s_werks.

if s_werks eq space.

"move to itab1.

else.

"move to pa0315

endif.

Thanks,

Nithya

Former Member
0 Kudos

Hi Rocky,

hope this would help solve your problem,

TABLES:
  PA0315.

DATA:
  W_WERKS LIKE PA0315-WERKS,
  BEGIN OF FS_TAB,
    -RELATED FIELDS----------
    PERNR LIKE PA0315,
  END OF FS_TAB.

DATA:
         T_TAB LIKE
  STANDARD TABLE
               OF FS_TAB.

DATA:
        T_TAB1 LIKE
  STANDARD TABLE
               OF FS_TAB.

SELECT-OPTIONS:
  S_WERKS FOR  W_WERKS.

START-OF-SELECTION.
IF S_WERKS IS INITIAL.
  PERFORM TRANSFER.
ELSE.
  PERFORM TRANSFER_SELECTED.
ENDIF.

FORM TRANSFER.
  MOVE T_TAB TO T_TAB1.
ENDFORM.

FORM TRANSFER_SELECTED.
  SELECT F1
               F2
               F3
               ---
               ---
  FROM   PA0315
  INTO TABLE I_TAB1
  WHERE WERKS IN S_WERKS.
ENDFORM.

In case, you got to insert from I_TAB1 to PA0315, then simply code:

INSERT PA0315 FROM TABLE I_ITAB1

, but for this you got to have access key...

Thanks,

Zahack