cancel
Showing results for 
Search instead for 
Did you mean: 

Logic inside a loop

Former Member
0 Kudos

Hi Everyone.......

Having a simple doubt regarding the looping

I have done this select query

SELECT WF_ID

          NODE_ID

          WI_ID

          TASK_ID

          LOG_DATE

          LOG_TIME

          WI_AGENT

          RETURNTYP

          LOG_COUNT

     FROM SWPSTEPLOG

     INTO TABLE lt_SWPSTEPLOG

     WHERE wf_id = s_wf_id AND

           log_date in s_log AND

           wi_agent in s_agent.


After this condition i need to introduce a logic as

-Need to identify the task(task_id)

-From the selected task id of the table SWPSTEPLOG need to check the about the RETURNTYP.

-Say condition wen RETURNTYP = RC or EV .

-The return type RC will represent the Start Date/Time for a specific task, while the return type EV represents the action taken by the user for the previous task, so the Completion Date/Time.


Can any one pls help in this case


Accepted Solutions (0)

Answers (5)

Answers (5)

Former Member
0 Kudos

hi

After getting the start date and time for the RC task, look for the Completion date and time in a subsequent task where:

                        WF_ID from RC record = WF_ID from EV record

                        NODE_ID from RC record = NODE_ID from EV record

                        WI_ID from RC record = WI_ID from EV record

                        TASK_ID from RC record = TASK_ID from EV record


how can i achieve this by moving from one record to another

raymond_giuseppi
Active Contributor
0 Kudos

Define your internal table as one the sorted types, use keys TASK_ID and RETURNTYP. Then LOOP at the table and use a logic like

LOOP AT itab ASSIGNING <fs>.
   AT NEW task_id.
     " initialize a new record in final table (e.g. APPEND INITIAL RECORD ASSIGNING <final>).
   ENDAT.
   " move some other fields in new final table record
   CASE <fs>-returntyp.
     WHEN 'RC'.
       " move log date/time to final table start fields
     WHEN 'EV'.
       " move log date/time to final table end fields
   ENDCASE.
   AT END OF task_id.
     " calculate duration
   ENDAT.
ENDLOOP.

Regards,

Raymond

raymond_giuseppi
Active Contributor
0 Kudos

If you need more matching criteria fields (*), just add those in internal table keys list, and process the AT NEW/END OF on the last key.

(e.g. define table with keys WF_ID NODE_ID WI_ID TASK_ID and process the AT NEW/END IF in TASK_ID last key)

Regards,

Raymond

(*) From your duplicate posts Error in Condition and Condition Inside a loop ?

former_member183607
Contributor
0 Kudos

Hi,

     After getting data in internal table

     Read ur internal table no of times according to your requirement.

    Read <itab> into <wa> where task_id = xyz   returntyp = 'RC'

     If sy-subrc eq o.

          starttime =

     endif.

     Read <itab> into <wa> where task_id = xyz   returntyp = 'EV'

     If sy-subrc eq o.

          action taken =

     endif.

Former Member
0 Kudos

Hi Somendra,

thanks for ur reply....this must be inside a loop? since there r 10 task...for each task the value need to b checked

Former Member
0 Kudos

Hi meenakshi,

  data: wa_SWPSTEPLOG like line of  it_SWPSTEPLOG

  loop at lt_SWPSTEPLOG into wa_SWPSTEPLOG.

case   wa_SWPSTEPLOG-RETURNTYP.


when 'RC'.

    

         ******* Start Date/Time for a specific task

                  you can write actions here

when 'EV'.

         ******** action taken by the user for the previous task

                    you can write actions here

endcase.

endloop.

Regards

Ashwin kv

Former Member
0 Kudos

HI ,

Thanks for ur reply,

The return type RC will represent the Start Date/Time for a specific task, while the return type EV represents the action taken by the user for the previous task, so the Completion Date/Time



arthur_alvesteixeira
Active Participant
0 Kudos

Meenakshi,

you can create a internal table copy to access the previous task and use case to check the condition.

it_swpsteplog_pre[] = it_swpsteplog[].

* Read selected entries

loop at it_swpsteplog.

Check returntype values

  CASE it_swpsteplog-returntyp.

* Returntyp = RC

    WHEN 'RC'.

      "your logic about Start Date/Time

* Returntyp = EV

    WHEN 'EV'.

      "your logic about Completion Date/Time

      "read your auxiliar internal table it_swpsteplog_pre

      "to get previous task (example using logic key... or

      "using sy-tabix logic...)

  ENDCASE