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: 

Sales Order creation question

Former Member
0 Kudos

Hi,

My current program creates Sales orders based on the function 'SD_SALESDOCUMENT_CREATE' and at new kunnr it creates a new SO. User wants me to add the functionality to create separate SO for the same customer if sales area is different. Can you please help me to add this functionality.

Kunnr Sorg Distri Divi

1011 300 20 01

1011 300 20 01

1011 300 10 01

1011 300 10 01

2011 300 10 01

For Ex:

I need 3 SO's, one for records 1 and 2, Two for records 3 and 4, Three for record 5.

Please help me.

Thanks,

Veni.


WHEN 'SORD'.
      DESCRIBE TABLE gt_zprice LINES lv_cnt.
      DO lv_cnt TIMES.
        lv_index = sy-index + 4.
        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[].
      LOOP AT gt4_zprice INTO gs_zprice1.
        IF gs_zprice1-crmemo IS INITIAL.
          AT NEW kunnr.
            MOVE 'Y' TO lv_flg.
          ENDAT.

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

          IF gs_zprice1-eohqty IS INITIAL.
            CONTINUE.
          ENDIF.
          PERFORM itemdata.
          APPEND gs_zprice1 TO gt3_zprice.
          CLEAR gs_zprice1.
          AT END OF kunnr.
            PERFORM call_function.
            PERFORM update_pricetable.
            PERFORM errorcheckandcommit.

            REFRESH gt2_zprice.
            CLEAR chbox.

            REFRESH partner.
            REFRESH item.
            REFRESH itemx.
            REFRESH lt_schedules_in.
            REFRESH lt_schedules_inx.
            REFRESH conditions1.
            REFRESH order_text.
            lv_itemno = 10.
          ENDAT.
        ELSE.
          REFRESH gt2_zprice.
          CLEAR chbox.
        ENDIF.
      ENDLOOP.
      WRITE: /01(179) sy-uline.
      PERFORM headings.
      WRITE: /01(179) sy-uline.
      PERFORM displaydata.

  ENDCASE.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Before the at new, remember to:

SORT gt4_zprice BY kunnr divi.

This will take care of both. Please do F1 on AT NEW.

Rob

Message was edited by:

Rob Burbank

9 REPLIES 9

naimesh_patel
Active Contributor
0 Kudos

Instead of this one in your loop:

         AT NEW kunnr.
            MOVE 'Y' TO lv_flg.
          ENDAT.

Put

          AT NEW DIVISION.
            MOVE 'Y' TO lv_flg.
          ENDAT.

Regards,

Naimesh Patel

0 Kudos

Hi Naimesh,

Thank you for your reply. I need 2 conditions here if KUNNR is different, different SO and for the same Kunnr, if DIVISION is different then also new SO. Please help me.

Thanks,

Veni.

Former Member
0 Kudos

Before the at new, remember to:

SORT gt4_zprice BY kunnr divi.

This will take care of both. Please do F1 on AT NEW.

Rob

Message was edited by:

Rob Burbank

0 Kudos

Hi Rob,

I added sort statement,

gt4_zprice[] = gt2_zprice[].

SORT gt4_zprice BY kunnr vtweg.

LOOP AT gt4_zprice INTO gs_zprice1.

IF gs_zprice1-crmemo IS INITIAL.

AT NEW kunnr. " vtweg.

MOVE 'Y' TO lv_flg.

ENDAT.

IF lv_flg EQ 'Y'.

PERFORM headerdata.

PERFORM texts.

CLEAR lv_flg.

ENDIF.

Should I say 'AT NEW kunnr' or 'vtweg'.

Thanks,

Veni.

0 Kudos

It depends also on the structure of the table - which fields are at the beginning. Please check the help.

Rob

0 Kudos

You must use

'AT NEW vtweg'

regards,

Naimesh Patel

0 Kudos

Thank you Naimesh and Rob.

I used AT NEW vtweg.

Regards,

Veni.

0 Kudos

I am not able to give the points. There are no radio buttons.

-Veni.

0 Kudos

Glad to help - the point system has been down for a day or so.

Rob