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: 

I have a problem with a modify.

Former Member
0 Kudos

Hi people:

I have tree selects and when I insert the data in my internal table t_regup the program insert the last line of payr in all line in the internal table and the selection is from one to many in payr. This is my code:

thanks for the help.


  SELECT empfb xblnr bldat dmbtr sknto qbshh zlsch laufd     
        laufi zbukr vblnr lifnr sknto belnr kunnr blart 
         bukrs shkzg
    FROM regup INTO CORRESPONDING FIELDS OF TABLE t_regup
   WHERE laufd EQ p_laufd
     AND laufi EQ p_laufi
     AND bukrs EQ p_absbu
     AND xvorl <> 'X'.

  LOOP AT t_regup INTO wa_regup.

   SELECT SINGLE  znme1 zbnkn laufd laufi hbkid waers      
                  zaldt hktid
                  lifnr  zland rzawe uzawe absbu
     FROM reguh INTO CORRESPONDING FIELDS OF wa_regup
     WHERE laufd = wa_regup-laufd
       AND laufi = wa_regup-laufi
       AND absbu = p_absbu
       AND vblnr = wa_regup-vblnr.

    IF wa_regup-rzawe = '1'.

      SELECT  laufd laufi zbukr hbkid waers zaldt hktid
              VBLNR chect zland rzawe uzawe voidr
       FROM payr INTO CORRESPONDING FIELDS OF  wa_regup
       WHERE laufd EQ wa_regup-laufd
         AND laufi EQ wa_regup-laufi
         AND zbukr EQ wa_regup-zbukr.

     ENDSELECT.


 MODIFY t_regup FROM wa_regup.

endloop.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Rob,

Is a good idea, but you can show me a little example of how can I modify the wa_regup from others works areas.

I need to create a loop to for this modify part or in the same select of Payr I can do that?

Much Thanks!!

7 REPLIES 7

Former Member
0 Kudos

Try:


LOOP AT t_regup INTO wa_regup.
 
   SELECT SINGLE  znme1 zbnkn laufd laufi hbkid waers      
                  zaldt hktid
                  lifnr  zland rzawe uzawe absbu
     FROM reguh INTO CORRESPONDING FIELDS OF wa_regup
     WHERE laufd = wa_regup-laufd
       AND laufi = wa_regup-laufi
       AND absbu = p_absbu
       AND vblnr = wa_regup-vblnr.
 
    IF wa_regup-rzawe = '1'.
 
      SELECT  laufd laufi zbukr hbkid waers zaldt hktid
              VBLNR chect zland rzawe uzawe voidr
       FROM payr INTO CORRESPONDING FIELDS OF  wa_regup
       WHERE laufd EQ wa_regup-laufd
         AND laufi EQ wa_regup-laufi
         AND zbukr EQ wa_regup-zbukr.
<b>         MODIFY t_regup FROM wa_regup.</b> 
     ENDSELECT.
 
 ENDLOOP.

Former Member
0 Kudos

Rob,

I try that but when I debug the program the modify insert the data that I take out of payr in the first line only and if I have a field like CHECT of payr when modify the table the CHECT is modified only in the first line and the anotherone stay clear.

0 Kudos

Looping at the itab into wa_regup and then selecting into it will destroy the original contents of wa_regup.

I think that you should create a couple of other work areas like wa_regup and do the other selects into them instead of wa_regup. Then modify wa_regup from the other work areas. You may need further logic because you may want to some appending instead of modifying.

Rob

Former Member
0 Kudos

Rob,

Is a good idea, but you can show me a little example of how can I modify the wa_regup from others works areas.

I need to create a loop to for this modify part or in the same select of Payr I can do that?

Much Thanks!!

0 Kudos

I was a bit surprised. The other selects didn't seem to write over the existing data. Try:


SELECT empfb xblnr bldat dmbtr sknto qbshh zlsch laufd
  laufi zbukr vblnr lifnr sknto belnr kunnr blart
  bukrs shkzg
  FROM regup
  INTO CORRESPONDING FIELDS OF TABLE t_regup
  WHERE laufd EQ p_laufd
    AND laufi EQ p_laufi
    AND bukrs EQ p_absbu
    AND xvorl <> 'X'.

LOOP AT t_regup INTO wa_regup.
  SELECT SINGLE  znme1 zbnkn laufd laufi hbkid waers zaldt hktid
    lifnr  zland rzawe uzawe absbu
    FROM reguh
    INTO CORRESPONDING FIELDS OF wa_regup
    WHERE laufd = wa_regup-laufd
      AND laufi = wa_regup-laufi
      AND absbu = p_absbu
      AND vblnr = wa_regup-vblnr.

  IF wa_regup-rzawe = 'C'.
    count = 1.
    SELECT  laufd laufi zbukr hbkid waers zaldt hktid
      vblnr chect zland rzawe uzawe voidr
      FROM payr
      INTO CORRESPONDING FIELDS OF  wa_regup
      WHERE laufd EQ wa_regup-laufd
      AND laufi EQ wa_regup-laufi
      AND zbukr EQ wa_regup-zbukr.
      if count = 1.
        MODIFY t_regup FROM wa_regup.
      else.
        APPEND wa_regup TO t_regup.
      endif.
      count = count + 1.
    ENDSELECT.
  ENDIF.
ENDLOOP.

Rob

0 Kudos

Actually, since you are looping at t_regup and then need to append it, you should declare a separate table (t_regup2) and when appending, append that one instead of t_regup. After the loop is complete:


APPEND LINES OF t_regup2 TO t_regup.

Rob

Former Member
0 Kudos

HI Carlos,

I faced a similar problem..

change the code part of modify ..

use the INDEX addition ..

it worked for me.. give it a try..

 ENDSELECT. 
 <b>MODIFY t_regup FROM wa_regup INDEX sy-tabix.</b> endloop.

regards

satesh