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 in code

Former Member
0 Likes
1,195

Hi,

I had developed the code and i want to display the data according to the given condition. it is displaying the storage location of a material but when i specify a condition that only this should be displayed it is not working properly.

here's the code:-



tables: mard.
data: begin of itab occurs 0,
      matnr like mard-matnr,
      werks like mard-werks,
      lgort like mard-lgort,
      end of itab.

PARAMETERS: item like mard-MATNR,
            plant like mard-werks.

      select matnr werks lgort FROM mard
        into table itab where matnr eq item and werks eq plant." and ( lgort eq 'w1wp' or lgort eq 'w1wp' ).

        sort itab by matnr lgort.

        loop at itab.
          if itab-lgort eq 'w1wp'.
          write: / itab-matnr,itab-lgort.
          else.
          write: / itab-matnr,itab-lgort.
          endif.
        ENDLOOP.

12 REPLIES 12
Read only

GauthamV
Active Contributor
0 Likes
1,158

All the constant values in quotes ' ' should always be in capital letters.



tables: mard.
data: begin of itab occurs 0,
      matnr like mard-matnr,
      werks like mard-werks,
      lgort like mard-lgort,
      end of itab.
 
     PARAMETERS: item like mard-MATNR,
            plant like mard-werks.
 
      select matnr werks lgort FROM mard
        into table itab where matnr eq item and werks eq plant." and ( lgort eq 'W1WP' or lgort   eq 'W1WP' ).
 
        sort itab by matnr lgort.
 
        loop at itab.
          if itab-lgort eq 'W1WP'.
          write: / itab-matnr,itab-lgort.
          else.
          write: / itab-matnr,itab-lgort.
          endif.
        ENDLOOP.

Read only

Former Member
0 Likes
1,158

HI,

I agree wit h you but i had tried it is still not displaying the right data. It is not satisfying the if condition as i checked in the debugged mode.

Read only

GauthamV
Active Contributor
0 Likes
1,158


loop at itab.
          if itab-lgort eq 'W1WP'.
          write: / itab-matnr,itab-lgort.
          else.
          write: / itab-matnr,itab-lgort.
          endif.
        ENDLOOP.
 

There is no point using If condition here.instead you can use the

condition directly in loop for getting only 'W1WP' values.



Loop at itab where lgort EQ 'W1WP'.

    write: / itab-matnr,itab-lgort.
   
ENDLOOP.
 

Read only

Former Member
0 Likes
1,158

hi,

Actually this is a dummy code which i am trying right now ,the problem is with my code in which i have to display that if a storage location matches then it should make qty field to 0 ,but it is not displaying it.



LOOP AT STIT WHERE QMNUM = STIT1-QMNUM.

    IF STIT-MGEIG GE 0.

        SELECT A~PRUEFLOS A~MATNR A~LOSMENGE B~MBLNR B~MJAHR C~ZEILE C~CHARG   
                     C~LGORT C~MENGE 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 WHERE A~PRUEFLOS EQ STIT-PRUEFLOS AND A~MATNR 
                     EQ  STIT-MATNR." AND C~LGORT EQ 'SC01'.

    SORT ITSC01 BY PRUEFLOS.

      ITAB-MATNR = STIT-MATNR.
      ITAB-PRUEFLOS = STIT-PRUEFLOS.
      ITAB-PAENDTERM = STIT-PAENDTERM.
      ITAB-LOSMENGE = STIT-LOSMENGE.
      ITAB-CHARG = STIT-CHARG.
      ITAB-LGORTCHARG = STIT-LGORTCHARG.
      ITAB-MGEIN = STIT-MGEIN.

      IF ITSC01-LGORT EQ 'SC03'. "This Storage location should be satisfied.
      ITAB-MGEIG = 0.
      ELSE.
      ITAB-MGEIG = STIT-MGEIG.
      ENDIF.

      ITAB-NTGEW = STIT-NTGEW.

    ELSE.

      ITAB-MATNR = STIT-MATNR.
      ITAB-PRUEFLOS = STIT-PRUEFLOS.
      ITAB-PAENDTERM = STIT-PAENDTERM.
      ITAB-LOSMENGE = STIT-LOSMENGE.
      ITAB-CHARG = STIT-CHARG.
      ITAB-LGORTCHARG = STIT-LGORTCHARG.
      ITAB-MGEIN = STIT-MGEIN.
      ITAB-MGEIG = STIT-MGEIG.
      ITAB-NTGEW = STIT-NTGEW.

     ENDIF.

    ENDLOOP.
    APPEND ITAB.

  ENDLOOP.

Read only

GauthamV
Active Contributor
0 Likes
1,158

Don't use select statements inside loop.

If you are using loop condition for stit table then you have to use read

statement to get data into itsc01 table and then check the condition.



LOOP AT t_ekpo .

    t_outtab-ebeln = t_ekpo-ebeln .
    t_outtab-ebelp = t_ekpo-ebelp .
    t_outtab-txz01 = t_ekpo-txz01 .
    t_outtab-netwr = t_ekpo-netwr .
    t_outtab-werks = t_ekpo-werks .

 READ TABLE t_eket WITH KEY ebeln = t_ekpo-ebeln
                               ebelp = t_ekpo-ebelp.

    IF sy-subrc = 0 .
      t_outtab-eindt = t_eket-eindt.
   endif.

    APPEND t_outtab .
    CLEAR t_outtab .
     clear :  t_eket.

Endloop.

Read only

Former Member
0 Likes
1,158

hi,

if i write the query of fetch data for ITSC01 outside the loop of STIT it is not fetching the data but when it is in the STIT it is picking the data but not satisfying the data.

please provide me guidlines to solve this problem.

Read only

Former Member
0 Likes
1,158

Hi,

I hope using select inside loop is not recommended for performance reasons , so better use For all entries.

And the next thing is you are fetching data into table ITSCO1;

SELECT A~PRUEFLOS A~MATNR A~LOSMENGE B~MBLNR B~MJAHR C~ZEILE C~CHARG   
                     C~LGORT C~MENGE 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* WHERE A~PRUEFLOS EQ STIT-PRUEFLOS AND A~MATNR 
                     EQ  STIT-MATNR." AND C~LGORT EQ 'SC01'.

But after Sorting it you are just using the workarea not internal table so you should loop at ITSC01/READ it inot Workarea before checking;

IF ITSC01-LGORT EQ 'SC03'. "This Storage location should be satisfied.
      ITAB-MGEIG = 0.
      ELSE.
      ITAB-MGEIG = STIT-MGEIG.
      ENDIF.

This is wrong and this happened because you should have declared ITSCO1 with header line. Thats why its not recommended to use WITH HEADER LINE.

So change it, check and revert back

Regards

Karthik D

Read only

0 Likes
1,158

IF ITSC01-LGORT EQ 'SC03'. "This Storage location should be satisfied.

Before this u have to write as

READ TABLE ITSC01 with key prueflos = stat-prueflos

matnr = stat-matnr.

*Now the ITSC01 tables' 1 row will be at header line and u can check the condition

IF ITSC01-LGORT EQ 'SC03'.

Hope this will work

Read only

former_member438956
Active Participant
0 Likes
1,158

Hi ,

chk whether the data is getting populated in the internal table properly or not. Debug the program and check the values for storage location in internal table. use IN statement instead of EQ while fetching data from select query and while checking pls chk the data in CAPS letter.

Regards,

Anil N.

Read only

former_member506713
Participant
0 Likes
1,158

Hi,

Hi,

can u tell why u r using same storage location condition twice in select statement?

( lgort eq 'w1wp' or lgort eq 'w1wp')

if in select statement, lgort is picking only 'w1wp' , then no need to write else condition.

Regards

Lalit

Read only

0 Likes
1,158

sorry my fault ,i will keeep a check.

Read only

0 Likes
1,158

Use read table option for ITSC01. and write the if condition after that. IF ITSC01-LGORT EQ 'SC03'.