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: 

how to work with loops if certain condition to be fulfill.

prashant_kumar30
Participant
0 Kudos

Hi,

I have following conditions.

itab1

seq  plant storage loc  material

01    p1      s1                m1

02    p2      s2                 m1

03   p3      s3                m1 

itab2

material   plant   storage loc.      date                      qty.            mrp area

m1              p1       s1                00000000          0 or q1          mr1

m1              p1       s1                20140102           0 or q1         mr1

m1              p1       s2               00000000            0 or q1          mr1

m1              p1       s3                00000000           0 or q1          mr2

m1              p1       s3                20140102          0 or q1           mr2

now I have to pick the qty from itab 2 as follow.

I need to see first seq (01) in itab1 first and for that I have to pick the desired qty (suppose 6). first with the storage loc s1.

it should search in itab2 for s1 with date 000000.this belongs to mrp area mr1.if it finds the sufficient qty then process the remaing logic otherwise

it should search with other storage loc s2 in same mrp area MR1 where date is 000000.if not then go with s3 but as s3 has diff mrp area.so now it should come back and search with s1 where date is not 0000000. then with s2 with same condition.after that it should go with other mrp area.

I am trying but not able to achieve it completely. please help me to code this.

2 REPLIES 2

rajkumarnarasimman
Active Contributor
0 Kudos

Hi Prashant,

Please find the below code.


"Loop the Header table

LOOP AT ITAB1 INTO WA_TAB1.

"Read the Item table

READ TABLE ITAB2

       INTO WA_TAB2

       WITH KEY MATERIAL = WA_TAB1-MATERIAL

                       PLANT = WA_TAB1-PLANT

                      STORAGE_LOC = WA_TAB1-STORAGE_LOC.

IF SY-SUBRC = 0.

   IF WA_TAB2-QTY = 0.

 

     "Copy the Internal Table

     ITAB2_COPY[] = ITAB2[].

   

    "Delete Internal Table for different MRP

     DELETE ITAB2_COPY WHERE MRP NE WA_TAB2-MRP.

     "Sort the Internal Table

     SORT ITAB2_COPY

         BY MATERIAL

               PLANT

               MRP

               STORAGE_LOC.

     "Delete the Adjacent record for Storage location

     DELETE ADJACENT DUPLICATES ITAB2_COPY COMPARING MATERIAL

                                                                                                     PLANT

                                                                                                     MRP

                                                                                                     STORAGE_LOC.

     "Using Parallel cursor read the next records from Item table

    LOOP AT ITAB2_COPY INTO WA_TAB_CP.

     "Check condition for different materials

       IF MATERIAL = WA_TAB2-MATERIAL

           PLANT    = WA_TAB2-PLANT

           MRP = WA_TAB2-MRP.

          "Exit from the Loop

            EXIT.

  ENDIF.

  "Check Quantity

  IF WA_TAB_CP-QTY <> 0.

     "Move the corresponding value

       MOVE-CORRESPONDING WA_TAB_CP TO WA_FINAL.

      "Assign Quantity

       WA_FINAL-QTY = WA_TAB_CP-QTY.

      "Append Internal Table

       APPEND WA_FINAL TO IT_FINAL.

     "Clear WA

      CLEAR WA_FINAL.

 

     "Come out from the Loop

       EXIT.

  ELSE.

        "Continue the next Record

       CONTINUE.

  ENDIF.

ENDLOOP.

ELSE.

      "Move the corresponding value

       MOVE-CORRESPONDING WA_TAB2 TO WA_FINAL.

 

     "Assign Quantity

       WA_FINAL-QTY = WA_TAB2-QTY.

 

      "Append Internal Table

       APPEND WA_FINAL TO IT_FINAL.

      "Clear WA

      CLEAR WA_FINAL.

    

      "Continue the next Record

       CONTINUE.

ENDIF.

ENDIF.

ENDLOOP.

Regards

Rajkumar Narasimman

Message was edited by: Rajkumar N

0 Kudos

Hi Rajkumar,

thanks for reply

i think you are not clear with my requirment:

i will try to explain below:

1.first i need to follow the sequence of storage loc from itab1.means for materila m1 first of all it is having s1 as sto loc in seq 01.

2.hence for loc s1 ,it should go to itab2 and should check for qty in sto loc s1 with condition

    a. the date is 000000.

    b. if sufficient qty is there let say (requirement is for 6),if it finds 1 or 2 ,then

    c. it should now go back to itab1 and check with seq 02 means sto loc s2.

    d. now for s2 it should search the qty with date 000000.

   e. if sufficient qty is there there come out ,otherwise

   f. again it should go to itab1 and check with seq 03 means sto loc s3.(but as we can see that once it

      will go and check with s3 the mrp area is diff from s1 and s2.

   g...hence now before checking with s3 it should check with sto loc s1 with date ne 0000000.

   h. after that it should check with s2 with date ne 0000000.

   i. after that if requirement of qty is not fulfilled then

   j..it should go to itab 1 and check with se03 with sto loc s3

  k. for s3 it should check in itab2 the qty with date is 0000000.

  l. if not sufficient qty then again i itab1 with seq 04 with s4

it means it has to always follow the seq from itab1 ,but for itab2 it should go with first where date is 00000 then with date ne 0000000. for the same mrp area then for next......

please let me know if u are clear with requiments

if possible please help me