Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

select inside a loop

Hi friends

I have written a code to find the manager. but am using select statement inside the loop. I tried to do other ways but its in vain. Can any give some idea to change it. Here is my code.

DATA : LV_PERNR LIKE HRP1001-SOBID .
  DATA : RECLIST LIKE SOMLRECI1 OCCURS 1 WITH HEADER LINE.
*  DATA : V_RULE_NO LIKE HRP1240-EXT_OBJID.

*  V_RULE_NO = '95000018'. "CUSTOM RULE NUMBER FOR TRAVEL EXPENSE MANAGER.

  DATA : LV_EXP_PERNR TYPE SOBID.

  DATA : BEGIN OF LT_OBJID OCCURS 0,
         OBJID LIKE HRP1240-EXT_OBJID,
         END OF LT_OBJID.

  DATA : BEGIN OF T_WERKS OCCURS 0,
         V_WERKS_OBJID LIKE HRV1218-OBJID,
         END OF T_WERKS.

  DATA : BEGIN OF T_BTRTL OCCURS 0,
           V_BTRTL_OBJID LIKE HRV1218-OBJID,
           END OF T_BTRTL.

  DATA : V_OBJID LIKE HRV1218-OBJID.

  SELECT OBJID FROM HRP1240 INTO TABLE LT_OBJID WHERE EXT_OBJID = V_RULE_NO.

  LOOP AT LT_OBJID.

    SELECT OBJID FROM HRV1218 INTO TABLE T_WERKS WHERE PLVAR = '01' AND OTYPE = 'RY' AND ENDDA = '99991231'
         AND REFFIELD = 'WERKS' AND EXPR_LOW = LV_PA AND OBJID = LT_OBJID-OBJID.

    IF SY-SUBRC = 0.
      SELECT OBJID INTO TABLE T_BTRTL FROM HRV1218 FOR ALL ENTRIES IN T_WERKS WHERE OBJID = T_WERKS-V_WERKS_OBJID AND
      REFFIELD = 'BTRTL' AND EXPR_LOW = LV_PSA AND PLVAR = '01' AND OTYPE = 'RY' AND ENDDA = '99991231'.

      IF SY-SUBRC = 0.

        SELECT OBJID INTO V_OBJID UP TO 1 ROWS FROM HRV1218 FOR ALL ENTRIES IN T_BTRTL WHERE PLVAR = '01' AND OTYPE = 'RY' AND
        OBJID = T_BTRTL-V_BTRTL_OBJID AND ENDDA = '99991231' AND REFFIELD = 'ORGEH' AND EXPR_LOW LE LV_ORGID AND
        EXPR_HIGH GE LV_ORGID.
        ENDSELECT.

        IF V_OBJID IS INITIAL.
          CONTINUE.
        ELSE.
          EXIT.
        ENDIF.
      ENDIF.
    ENDIF.
  ENDLOOP.

Till the V_OBJID is not initial i am executing the loop. Is there any other way to do this. The V_OBJID contains the personal number. How to modify the code without using select statement inside the loop.

Regards

vijay

Not what you were looking for? View more on this topic or Ask a question