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: 

Calling Function in a loop for CM

Former Member
0 Kudos

Hi,

I have the program to create Credit Memo with user selected records. It is working if the user selects any one customer and it will create CM for that customer. But now user wants to select different customers and based on each different vkorg vtweg spart kunnr it has to create different Credit Memo's. How should I put the function in the loop so that it creates different CM's based on each customer.

Please help me.

Thanks,

Neelu.


AT USER-COMMAND.
  CASE sy-ucomm.
    WHEN 'CMEMO'.

      DESCRIBE TABLE gt_zprice LINES lv_cnt.
      DO lv_cnt TIMES.
        lv_index = sy-index + 1.
        READ LINE lv_index FIELD VALUE chbox.
        IF chbox = 'X'.
          READ TABLE gt_zprice INTO gs_zprice1 INDEX sy-index.
          IF sy-subrc EQ 0.
            gs_zprice1-index = sy-index.
            APPEND gs_zprice1 TO gt2_zprice.
            CLEAR gs_zprice1.
          ENDIF.
        ENDIF.
        CLEAR chbox.
      ENDDO.

      gt4_zprice[] = gt2_zprice[].

*      SORT gt2_zprice BY vkorg vtweg spart kunnr.
*      DELETE ADJACENT DUPLICATES FROM gt2_zprice
*                      COMPARING vkorg vtweg spart kunnr.
*
*      DESCRIBE TABLE gt2_zprice LINES lv_lines.
*
*      IF lv_lines = 1.
          LOOP AT gt4_zprice INTO gs_zprice1.
            AT NEW kunnr.
              MOVE 'Y' TO lv_flg.
            ENDAT.

            IF lv_flg EQ 'Y'.
              PERFORM headerdata.
              PERFORM texts.
              CLEAR lv_flg.
            ENDIF.

            PERFORM itemdata.
            APPEND gs_zprice1 TO gt3_zprice.
            CLEAR gs_zprice1.
          ENDLOOP.
          lv_itemno = 10.

          PERFORM call_function.
          PERFORM update_pricetable.
          PERFORM errorcheckandcommit.
          PERFORM displaydata.

          REFRESH gt2_zprice.
          CLEAR chbox.
          CLEAR lv_lines.

          REFRESH partner.
          REFRESH item.
          REFRESH itemx.
          REFRESH lt_schedules_in.
          REFRESH lt_schedules_inx.
          REFRESH conditions1.
          REFRESH order_text.

        ELSE.
          REFRESH gt2_zprice.
          CLEAR chbox.
          EXIT.
        ENDIF.
  ENDCASE.


1 ACCEPTED SOLUTION

Former Member
0 Kudos

call the credimemo create routines at end of kunnr inside the loop.

LOOP AT gt4_zprice INTO gs_zprice1.

AT NEW kunnr.

MOVE 'Y' TO lv_flg.

ENDAT.

IF lv_flg EQ 'Y'.

PERFORM headerdata.

PERFORM texts.

CLEAR lv_flg.

ENDIF.

PERFORM itemdata.

APPEND gs_zprice1 TO gt3_zprice.

CLEAR gs_zprice1.

<b>at end of kunnr.

PERFORM call_function.

PERFORM update_pricetable.

PERFORM errorcheckandcommit.

PERFORM displaydata.

REFRESH gt2_zprice.

CLEAR chbox.

CLEAR lv_lines.

REFRESH partner.

REFRESH item.

REFRESH itemx.

REFRESH lt_schedules_in.

REFRESH lt_schedules_inx.

REFRESH conditions1.

REFRESH order_text.

endat.</b>

ENDLOOP.

lv_itemno = 10.

ELSE.

REFRESH gt2_zprice.

CLEAR chbox.

EXIT.

ENDIF.

ENDCASE.

2 REPLIES 2

Former Member
0 Kudos

call the credimemo create routines at end of kunnr inside the loop.

LOOP AT gt4_zprice INTO gs_zprice1.

AT NEW kunnr.

MOVE 'Y' TO lv_flg.

ENDAT.

IF lv_flg EQ 'Y'.

PERFORM headerdata.

PERFORM texts.

CLEAR lv_flg.

ENDIF.

PERFORM itemdata.

APPEND gs_zprice1 TO gt3_zprice.

CLEAR gs_zprice1.

<b>at end of kunnr.

PERFORM call_function.

PERFORM update_pricetable.

PERFORM errorcheckandcommit.

PERFORM displaydata.

REFRESH gt2_zprice.

CLEAR chbox.

CLEAR lv_lines.

REFRESH partner.

REFRESH item.

REFRESH itemx.

REFRESH lt_schedules_in.

REFRESH lt_schedules_inx.

REFRESH conditions1.

REFRESH order_text.

endat.</b>

ENDLOOP.

lv_itemno = 10.

ELSE.

REFRESH gt2_zprice.

CLEAR chbox.

EXIT.

ENDIF.

ENDCASE.

0 Kudos

Thank you Sam.

I really appriciate your help.

Regards,

Neelu.