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: 

Problem in comparing the value

Former Member
0 Kudos
197

Hi,

I am working on a code in which i am facing a problem that i am not able to modify the data of a STIT

as it is chekcing the value of STORAGE LOCATION and if that storage location matches then it should make MGEIG EQ 0.

the condition gets satisfied but it is not displayed properly on output.

Please provide me guidelines to solve this problem.

here's the code:-



SELECT A~PRUEFLOS B~MBLNR C~LGORT FROM QALS AS A
INNER JOIN QAMB AS B ON B~PRUEFLOS = A~PRUEFLOS
INNER JOIN MSEG AS C ON C~MBLNR = B~MBLNR AND C~MJAHR = B~MJAHR
INTO TABLE ITSC01
FOR ALL ENTRIES IN STIT
WHERE A~PRUEFLOS EQ STIT-PRUEFLOS AND A~MATNR EQ STIT-MATNR AND
( LGORT = 'SC01' OR LGORT = 'SC02' OR LGORT = 'SC03' OR LGORT = 'SC04' ).

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

SORT ITSC01 BY PRUEFLOS.

LOOP AT STIT.

  IF STIT-MGEIG GE 0.

    LOOP AT ITSC01 WHERE PRUEFLOS EQ STIT-PRUEFLOS.

      L_lgort = ITSC01-lgort.

      IF l_LGORT EQ 'SC03'.

      STIT-MGEIG = 0.

      ENDIF.

ENDLOOP.
  ENDIF.
*    APPEND STIT.
      ENDLOOP.

19 REPLIES 19

Former Member
0 Kudos
165

hi

instead of append stit you should use modify as you are modifying the stit table.

Former Member
0 Kudos
165

Weird. Can you post the data definitions for L_LGORT and ITSC01-lgort?

Both are defined as TYPE LGORT_D?

former_member585060
Active Contributor
0 Kudos
165

Hi,

replace the below code and see

SORT ITSC01 BY PRUEFLOS.
 
LOOP AT STIT.

 w_tabx = sy-tabix.                                                         " add

  IF STIT-MGEIG GE 0.
 
    LOOP AT ITSC01 WHERE PRUEFLOS EQ STIT-PRUEFLOS.
 
      L_lgort = ITSC01-lgort.
 
      IF l_LGORT EQ 'SC03'.
 
      STIT-MGEIG = 0.
 
      ENDIF.
 
MODIFY stit INDEX w_tabx  TRANSPORTING mgeig.                 "   addd

ENDLOOP.

  ENDIF.

CLEAR w_tabx.                                                                       " add

      ENDLOOP.

Regards

Bala Krishna

0 Kudos
165

HI,

I had modified my code but the thing happening now is it is giving values eq 0 (MGEIG).

Please tell me where i am getting wrong....

here 's d code:-



DATA: BEGIN OF ITSC01 OCCURS 0,
      PRUEFLOS LIKE QALS-PRUEFLOS,
      MBLNR LIKE QAMB-MBLNR,
      LGORT LIKE MSEG-LGORT,
      END OF ITSC01.

DATA: l_PRUEFLOS LIKE QALS-PRUEFLOS,
l_MBLNR LIKE QAMB-MBLNR,
l_LGORT LIKE MSEG-LGORT.

SELECT A~PRUEFLOS B~MBLNR C~LGORT FROM QALS AS A
INNER JOIN QAMB AS B ON B~PRUEFLOS = A~PRUEFLOS
INNER JOIN MSEG AS C ON C~MBLNR = B~MBLNR AND C~MJAHR = B~MJAHR
INTO TABLE ITSC01
FOR ALL ENTRIES IN STIT
WHERE A~PRUEFLOS EQ STIT-PRUEFLOS AND A~MATNR EQ STIT-MATNR AND
( LGORT = 'SC01' OR LGORT = 'SC02' OR LGORT = 'SC03' OR LGORT = 'SC04' ).

SORT ITSC01 BY PRUEFLOS.
data: w_tabx type sy-tabix.

LOOP AT STIT.

w_tabx = sy-tabix.

  IF STIT-MGEIG GE 0.

    LOOP AT ITSC01 WHERE PRUEFLOS EQ STIT-PRUEFLOS.

    L_lgort = ITSC01-lgort.

    IF l_LGORT EQ 'SC01' OR L_LGORT EQ 'SC02' OR L_LGORT EQ 'SC03' OR l_LGORT EQ 'SC04' .
      STIT-MGEIG = 0.
    ENDIF.

    MODIFY stit INDEX w_tabx  TRANSPORTING mgeig.
*    ELSE.
*      STIT-MGEIG = STIT-MGEIG.
*   MODIFY STIT transporting MGEIG.

ENDLOOP.
  ENDIF.
CLEAR w_tabx.
ENDLOOP.

It is not displaying the right data.Please provide me guidelines to solve this problem.

Edited by: ricx .s on Jun 5, 2009 1:51 PM

Edited by: ricx .s on Jun 5, 2009 2:00 PM

0 Kudos
165

Hi

U should change the data only if the conditions of IF statament are true:

LOOP AT STIT.
 
   w_tabx = sy-tabix.
 
  IF STIT-MGEIG GE 0.
 
    LOOP AT ITSC01 WHERE PRUEFLOS EQ STIT-PRUEFLOS.
 
        L_lgort = ITSC01-lgort.
 
        IF l_LGORT EQ 'SC01' OR L_LGORT EQ 'SC02' OR L_LGORT EQ 'SC03' OR l_LGORT EQ 'SC04' .
          STIT-MGEIG = 0.
          MODIFY stit INDEX w_tabx  TRANSPORTING mgeig.
        ENDIF.
 
 *   MODIFY stit INDEX w_tabx  TRANSPORTING mgeig.
     ENDLOOP.
  ENDIF.
  CLEAR w_tabx.
ENDLOOP.

Anyway u make sure how many records of table ITSC01 can be matched with STIT, the field MGEIG can be changed as many times as many records of ITSC01.

Max

0 Kudos
165

You have a nested loop. When you loop over internal table ITSC01 (can have multiple entries?), you change the same STIT record multiple times.

You only need to do that once. I cannot see the contents of the tables, but isn't it enought to check only once if you find an entry in ITSC01 where the LGORT = SC01/02/03/04?

Then modify STIT and EXIT the loop over ITSC01.

Cheers,

Edwin.

0 Kudos
165

hi,

i am also trying to do it,but the data is not coming right. I had made modifications in the code but still it is giving the wrong data.



SELECT A~PRUEFLOS B~MBLNR C~LGORT FROM QALS AS A
INNER JOIN QAMB AS B ON B~PRUEFLOS = A~PRUEFLOS
INNER JOIN MSEG AS C ON C~MBLNR = B~MBLNR AND C~MJAHR = B~MJAHR
INTO TABLE ITSC01
FOR ALL ENTRIES IN STIT
WHERE A~PRUEFLOS EQ STIT-PRUEFLOS AND A~MATNR EQ STIT-MATNR AND
( LGORT = 'SC01' OR LGORT = 'SC02' OR LGORT = 'SC03' OR LGORT = 'SC04' ).

**********************************************************************
SORT ITSC01 BY PRUEFLOS.
data: w_tabx type sy-tabix.

LOOP AT STIT.

w_tabx = sy-tabix.

  IF STIT-MGEIG GE 0.

    LOOP AT ITSC01 WHERE PRUEFLOS EQ STIT-PRUEFLOS.

    L_lgort = ITSC01-lgort.

    IF l_LGORT EQ 'SC01' OR L_LGORT EQ 'SC02' OR L_LGORT EQ 'SC03' OR l_LGORT EQ 'SC04' .
      STIT-MGEIG = 0.
    else.
      stit-MGEIG = STIT-MGEIG.
    MODIFY stit INDEX w_tabx  TRANSPORTING mgeig.
   endif.
*     MODIFY stit INDEX w_tabx  TRANSPORTING mgeig.

ENDLOOP.
  ENDIF.
CLEAR w_tabx.
ENDLOOP.

with this it is not changing the value of the MGEIG and displays the data but when i made chnage in the code ;-



IF l_LGORT EQ 'SC01' OR L_LGORT EQ 'SC02' OR L_LGORT EQ 'SC03' OR l_LGORT EQ 'SC04' .
      STIT-MGEIG = 0.
    MODIFY stit INDEX w_tabx  TRANSPORTING mgeig.
   endif.

it displays only the zzerors in the mgeig,Please provide me guidelines to solve this problem.

0 Kudos
165

Hi,

What you want to say can you explain a little. I didn't get it..

Edited by: ricx .s on Jun 5, 2009 2:25 PM

0 Kudos
165

Hi

IF l_LGORT EQ 'SC01' OR L_LGORT EQ 'SC02' OR L_LGORT EQ 'SC03' OR l_LGORT EQ 'SC04' .
      STIT-MGEIG = 0.
    else.
      stit-MGEIG = STIT-MGEIG.
      MODIFY stit INDEX w_tabx  TRANSPORTING mgeig.
   endif.

Here no record will be changed:

IF LGORT is SC01,....... u set the value 0 in STIT-MGEIG but u don't modify the table, if LGORT isn't SC01.....u move the same value: stit-MGEIG = STIT-MGEIG.

So no changes can be done in this code.

IF l_LGORT EQ 'SC01' OR L_LGORT EQ 'SC02' OR L_LGORT EQ 'SC03' OR l_LGORT EQ 'SC04' .
      STIT-MGEIG = 0.
    MODIFY stit INDEX w_tabx  TRANSPORTING mgeig.
 endif.

Here u set the value 0 if storage location is SC01, now if you say u can see the value 0, it means there are SC01, SC02,.....SC04 as storage location.

Infact check your code to select the data from database:

SELECT A~PRUEFLOS B~MBLNR C~LGORT FROM QALS AS A
           INNER JOIN QAMB AS B ON B~PRUEFLOS = A~PRUEFLOS
           INNER JOIN MSEG AS C ON C~MBLNR = B~MBLNR AND C~MJAHR = B~MJAHR
               INTO TABLE ITSC01
                    FOR ALL ENTRIES IN STIT
                      WHERE A~PRUEFLOS EQ STIT-PRUEFLOS AND 
                                    A~MATNR      EQ STIT-MATNR        AND
                                  ( LGORT = 'SC01' OR  "<---------
                                    LGORT = 'SC02' OR  "<--------- 
                                    LGORT = 'SC03' OR   "<---------
                                    LGORT = 'SC04' ).       "<---------

So probably the problem is not how you try to change the data, but how u select the data.

Max

0 Kudos
165

Hi Max,

I had tried this also but it is making effect on the whole code as it is displaying the value eq 0 of mgeig where itis not requiered.

what should i do?

0 Kudos
165

You use LOOP AT ITSC01.

When one entry is found for the mentioned LGORT's, you can modify the STIT record, and exit the loop.

I am just wondering if there will be more records in the innermost loop than in the outer loop (STIT).

Cheers,

Edwin.

0 Kudos
165

hI

Just as I said (but excuse me for my English):

SELECT A~PRUEFLOS B~MBLNR C~LGORT FROM QALS AS A
           INNER JOIN QAMB AS B ON B~PRUEFLOS = A~PRUEFLOS
           INNER JOIN MSEG AS C ON C~MBLNR = B~MBLNR AND C~MJAHR = B~MJAHR
               INTO TABLE ITSC01
                    FOR ALL ENTRIES IN STIT
                      WHERE A~PRUEFLOS EQ STIT-PRUEFLOS AND 
                                    A~MATNR      EQ STIT-MATNR        AND
                                  ( LGORT = 'SC01' OR  "<---------
                                    LGORT = 'SC02' OR  "<--------- 
                                    LGORT = 'SC03' OR   "<---------
                                    LGORT = 'SC04' ).       "<---------

You're selecting records with storage location SC01, SC02, SC03 and SC04 only.

So this control is useless, because it's always true.

IF l_LGORT EQ 'SC01' OR L_LGORT EQ 'SC02' OR L_LGORT EQ 'SC03' OR l_LGORT EQ 'SC04' .
      STIT-MGEIG = 0.
ENDIF.

Let's know which conditions have to be true in order to change MGEIG: I suppose u need to change it only for certain storage location, don't you?

Max

Edited by: max bianchi on Jun 5, 2009 2:59 PM

0 Kudos
165

Hi,

I had change the code a bit but it seems to be same. i had finished the concept of ITSC01 and i am storing the values in the variables. I am looping in the STIT table and then combined the IF statement and transporting the value to the variables.

here's the code:-



DATA: l_PRUEFLOS LIKE QALS-PRUEFLOS,
l_MBLNR LIKE QAMB-MBLNR,
l_LGORT LIKE MSEG-LGORT.
data: w_tabx TYPE sy-tabix.

LOOP AT STIT.
w_tabx = sy-tabix.

IF STIT-MGEIG GE 0.

SELECT A~PRUEFLOS B~MBLNR C~LGORT FROM QALS AS A
INNER JOIN QAMB AS B ON B~PRUEFLOS = A~PRUEFLOS
INNER JOIN MSEG AS C ON C~MBLNR = B~MBLNR AND C~MJAHR = B~MJAHR
INTO (l_PRUEFLOS , l_MBLNR, l_LGORT)
WHERE A~PRUEFLOS EQ STIT-PRUEFLOS.
ENDSELECT.

IF l_LGORT EQ 'SC01' OR L_LGORT EQ 'SC02' OR L_LGORT EQ 'SC03' OR l_LGORT EQ 'SC04' .
      STIT-MGEIG = 0.
     MODIFY stit INDEX w_tabx  TRANSPORTING mgeig.
endif.

*  IF STIT-MGEIG GE 0 AND ( l_LGORT EQ 'SC01' OR L_LGORT EQ 'SC02' OR L_LGORT EQ 'SC03' OR l_LGORT EQ 'SC04' ).
*      STIT-MGEIG = 0.

CLEAR w_tabx.

ENDIF.
ENDLOOP.

Edited by: ricx .s on Jun 5, 2009 3:29 PM

Edited by: ricx .s on Jun 5, 2009 3:46 PM

Former Member
0 Kudos
165

Hi,

You should read carefully what Max wrote. It really seems like you are allways selecting LGORT with values 'SC01', 'SC02', 'SC03', 'SC04'. This means you will allways enter the condition and modify the field to 0.

Regards,

Bruno

0 Kudos
165

Rick

I think it's better you say us when u need to change it, u've changed the select conditions, but it seems (just as Bruno said) you still select records with LGORT equal to 'SC01', 'SC02', 'SC03', 'SC04'.

Max

0 Kudos
165

Hi,

Actually i am fetching the data and storing it in the STIT w.r.t. Inspection Lot. In ITSC01 ,it is storing the data w.r.t. SC01,SCO2,SC03,SCO4 according to the Material Document coming from QAMB . I am checking that if the data is stored in scrap storage location then qty(MGEIG).. should become 0,otherwise it will remain same if it does not have data for scrap st.loc..

This is the functionality which is to be achieved but the problem it is making 0 all the quantities.

what should i do ? please provide me guidelines for solving this problem.

0 Kudos
165

Hi

I believe your first code it was right, it had to be improved only:

SORT ITSC01 BY PRUEFLOS.

LOOP AT STIT.
 
  IF STIT-MGEIG GE 0.
 
    LOOP AT ITSC01 WHERE PRUEFLOS EQ STIT-PRUEFLOS.
 
      L_lgort = ITSC01-lgort.
 
      IF l_LGORT EQ 'SC03'. " Condition ?
 
         STIT-MGEIG = 0.        "Change value
         MODIFY STIT.            "Update changed value
         EXIT.                          "Exit: the value should be changed once.

      ENDIF.
 
     ENDLOOP.
  ENDIF.
ENDLOOP.

Now I don't know in which contest you work, so I don't know what "scrap storage location" means: u need to transform it to your IF condition.

If it means it's storage location SC03, the code above should work

Max

Former Member
0 Kudos
165

Hi,

Try to write the code some thing like this

FIELD-SYMBOLS : <FS> TYPE ANY. "or you can define as structure of STIT

LOOP AT STIT ASSIGNING <FS>.

CHECK <FS>-MGEIG GE 0.

LOOP AT ITSC01 WHERE PRUEFLOS EQ <FS>-PRUEFLOS.

L_lgort = ITSC01-lgort.

IF l_LGORT EQ 'SC03'. "add any other conditions as per your requirement.

<FS>-MGEIG = 0.

EXIT. "Its ideal to exit from the inner loop. Otherwise there is no point in looping for the same value again and again

ENDIF.

ENDLOOP.

I hope this definetely modifies value in internal table.

Regards,

Venkat

Former Member
0 Kudos
165

MODIFY is inefficient in this case. Loop with field symbol to modify directly. This code won't fly with OO programming.