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: 

temporary sales order should be generated automatically when click on save button

mohit_mantoo
Explorer
0 Kudos
354

i got an issue regarding creating temporary sales order nummber

the code is below :-

IF SY-UCOMM = 'SAVE'.

DOC_NUM TYPE CHAR10.

SELECT MAX( ZVBELN ) FROM ZLIPS INTO DOC_NUM WHERE VBELN = WA_ZLIPS-ZVBELN.

WA_ZLIPS-ZVBELN = DOC_NUM + 1 .


BREAK-POINT.

MOVE DOC_NUM TO WA_FINAL-ZVBELN.
move wa_zlips-vbeln to wa_final-vbeln.
move wa_zlips-posnr to wa_final-posnr.
move wa_zlips-MATNR to wa_final-MATNR.
MOVE WA_zlips-ZIEME TO WA_final-ZIEME.
MOVE WA_zlips-UMZIZ TO WA_final-UMZIZ.
MOVE WA_zlips-MEINS TO WA_final-MEINS.
MOVE WA_zlips-UMZIN TO WA_final-UMZIN.
MOVE WA_zlips-WERKS TO WA_final-WERKS.
MOVE WA_zlips-ERDAT TO WA_final-ERDAT.
MOVE WA_zlips-MAKTX TO WA_final-MAKTX.

append wa_zlips to it_zLIPS.

modify zlips from table it_ZLIPS.

if sy-subrc = 0.
MESSAGE : 'NEW TEMPORARY ORDER NO.' TYPE 'I'.
endif.

ENDIF.

MESSAGE : 'DATA HAS BEEN SUCCESSFULLY SAVED' TYPE 'S'.

5 REPLIES 5

former_member1716
Active Contributor
0 Kudos
160

mohit.mantoo,

What is the issue here? I do not see any statement on the issue.

mohit_mantoo
Explorer
0 Kudos
160

problem is when i click on save button the program should generate automatic number and save in ztable.

but when i click on save button it didnot generate any number .

former_member1716
Active Contributor
0 Kudos
160

Where have written this Code? have you used the suitable exits?

What is the business Requirement here?

mohit_mantoo
Explorer
0 Kudos
160

requirement :

develop a report alv report which stores temporary sales number when click on save button.

full code:-


TYPE-POOLS SLIS.
TABLES: VBAP, MAKT, ZLIPS.

*DATA:LV_TEMP(10) TYPE C.


TYPES: BEGIN OF TY_VBAP,
VBELN TYPE VBELN, "SALES ORDER
POSNR TYPE POSNR, "ITEM NUMBER
MATNR TYPE MATNR, "MATERIAL NUMBER
ZIEME TYPE DZIEME, "UNIT
UMZIZ TYPE UMZIZ, "70
UMZIN TYPE UMZIN, "1
MEINS TYPE MEINS, "KG
WERKS TYPE WERKS, "PLANT
ERDAT TYPE ERDAT, "DATE
* VRKME TYPE VRKME, "BAG
* NTGEW TYPE NTGEW, "KG
END OF TY_VBAP.

TYPES: BEGIN OF TY_MAKT,
MATNR type MATNR,
MAKTX TYPE MAKTX,
END OF TY_MAKT.

TYPES: BEGIN OF TY_ZLIPS ,
ZVBELN TYPE ZLIPS-ZVBELN,
VBELN TYPE ZLIPS-VBELN,
POSNR TYPE ZLIPS-POSNR,
MATNR TYPE ZLIPS-MATNR,
ZIEME TYPE ZLIPS-ZIEME,
UMZIZ TYPE ZLIPS-UMZIZ,
UMZIN TYPE ZLIPS-UMZIN,
MEINS TYPE ZLIPS-MEINS,
WERKS TYPE ZLIPS-WERKS,
ERDAT TYPE ZLIPS-ERDAT,
MAKTX TYPE ZLIPS-MAKTX,
END OF TY_ZLIPS.

TYPES: BEGIN OF TY_FINAL ,
ZVBELN TYPE ZLIPS-ZVBELN,
VBELN TYPE ZLIPS-VBELN,
POSNR TYPE ZLIPS-POSNR,
MATNR TYPE ZLIPS-MATNR,
ZIEME TYPE ZLIPS-ZIEME,
UMZIZ TYPE ZLIPS-UMZIZ,
UMZIN TYPE ZLIPS-UMZIN,
MEINS TYPE ZLIPS-MEINS,
WERKS TYPE ZLIPS-WERKS,
ERDAT TYPE ZLIPS-ERDAT,
MAKTX TYPE ZLIPS-MAKTX,
END OF TY_FINAL.

*TYPES: BEGIN OF TY_FINAL,
* ZVBELN TYPE ZLIPS-ZVBELN,
* VBELN TYPE VBAP-VBELN,
* POSNR TYPE VBAP-POSNR,
* MATNR TYPE VBAP-MATNR,
* ZIEME TYPE VBAP-ZIEME,
* UMZIZ TYPE VBAP-UMZIZ,
* UMZIN TYPE VBAP-UMZIN,
* MEINS TYPE VBAP-MEINS,
* WERKS TYPE VBAP-WERKS,
* ERDAT TYPE VBAP-ERDAT,
* MAKTX TYPE MAKT-MAKTX,
* END OF TY_FINAL.


DATA: IT_VBAP TYPE STANDARD TABLE OF TY_VBAP,
WA_VBAP TYPE TY_VBAP,
IT_MAKT TYPE STANDARD TABLE OF TY_MAKT,
WA_MAKT TYPE TY_MAKT,
IT_ZLIPS TYPE STANDARD TABLE OF TY_ZLIPS,
WA_ZLIPS TYPE TY_ZLIPS,
IT_FINAL TYPE STANDARD TABLE OF TY_FINAL,
WA_FINAL TYPE TY_FINAL.

DATA: IT_FCAT TYPE SLIS_T_FIELDCAT_ALV,
WA_FCAT LIKE LINE OF IT_FCAT.

loop at it_final into wa_final.

MOVE WA_FINAL-ZVBELN TO WA_ZLIPS-ZVBELN.
move wa_final-vbeln to wa_ZLIPS-vbeln. " = wa_final-vbeln.
move wa_final-posnr to wa_ZLIPS-posnr.
move wa_final-MATNR to wa_ZLIPS-MATNR.
MOVE WA_FINAL-ZIEME TO WA_ZLIPS-ZIEME.
MOVE WA_FINAL-UMZIZ TO WA_ZLIPS-UMZIZ.
MOVE WA_FINAL-MEINS TO WA_ZLIPS-MEINS.
MOVE WA_FINAL-UMZIN TO WA_ZLIPS-UMZIN.
MOVE WA_FINAL-WERKS TO WA_ZLIPS-WERKS.
MOVE WA_FINAL-ERDAT TO WA_ZLIPS-ERDAT.
MOVE WA_FINAL-MAKTX TO WA_ZLIPS-MAKTX. "WA_ZLIPS-MAKTX CHANGED TO WA_FINAL-MAKTX
ENDLOOP.

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
PARAMETERS: P_VBELN TYPE VBAP-VBELN.
* A_VBELN TYPE VBAP-VBELN.

SELECTION-SCREEN END OF BLOCK B1.


*DATA : L_NUM(4) TY,PE N.
*data : temp_zvbeln(4) type n.


FORM GET_DATA .

SELECT VBELN POSNR
MATNR
ZIEME UMZIZ UMZIN MEINS
WERKS ERDAT FROM VBAP INTO TABLE IT_VBAP
WHERE VBELN EQ P_VBELN.

SELECT MATNR MAKTX FROM MAKT INTO TABLE IT_MAKT.

SELECT ZVBELN
VBELN from ZLIPS into table IT_ZLIPS.

ENDFORM.


FORM FINAL_DATA.
*BREAK-POINT.
IF IT_VBAP IS NOT INITIAL.

LOOP AT IT_VBAP INTO WA_VBAP.
*BREAK-POINT.
READ TABLE IT_VBAP INTO WA_VBAP WITH KEY VBELN = WA_VBAP-VBELN.
READ TABLE IT_MAKT INTO WA_MAKT WITH KEY MATNR = WA_VBAP-MATNR.
READ TABLE IT_ZLIPS INTO WA_ZLIPS WITH KEY VBELN = WA_ZLIPS-VBELN.
* WA_FINAL-ZVBELN = A_VBELN. "TEMP DELIVERY ORDER
WA_FINAL-VBELN = WA_VBAP-VBELN. " SALES ORDER
WA_FINAL-POSNR = WA_VBAP-POSNR. "ITEM NUMBER
WA_FINAL-MATNR = WA_VBAP-MATNR. "MATERIAL NUMBER
WA_FINAL-ZIEME = WA_VBAP-ZIEME.
WA_FINAL-UMZIZ = WA_VBAP-UMZIZ.
WA_FINAL-MEINS = WA_VBAP-MEINS.
WA_FINAL-UMZIN = WA_VBAP-UMZIN.
WA_FINAL-WERKS = WA_VBAP-WERKS. "PLANT
WA_FINAL-ERDAT = WA_VBAP-ERDAT. "Date on Which Record Was Created
WA_FINAL-MATNR = WA_VBAP-MATNR. "MATERIAL NUMBER
WA_FINAL-MAKTX = WA_MAKT-MAKTX. "Material Description

data: gd_date(10).

write sy-datum to gd_date DD/MM/YYYY.


SHIFT WA_FINAL-VBELN LEFT DELETING LEADING '0'.
WA_FINAL-VBELN = WA_FINAL-VBELN+0(6).
SHIFT WA_FINAL-POSNR LEFT DELETING LEADING '0'.
WA_FINAL-POSNR = WA_FINAL-POSNR+0(6).
SHIFT WA_FINAL-MATNR LEFT DELETING LEADING '0'.
WA_FINAL-MATNR = WA_FINAL-MATNR+0(6).

APPEND WA_FINAL TO IT_FINAL.
CLEAR: WA_FINAL, WA_VBAP.


*BREAK-POINT.
loop at it_final into wa_final.

move WA_FINAL-ZVBELN to WA_zlips-ZVBELN.
move wa_final-vbeln to wa_zlips-vbeln.
move wa_final-posnr to wa_zlips-posnr.
move wa_final-MATNR to wa_zlips-MATNR.
MOVE WA_FINAL-ZIEME TO WA_ZLIPS-ZIEME.
MOVE WA_FINAL-UMZIZ TO WA_ZLIPS-UMZIZ.
MOVE WA_FINAL-MEINS TO WA_ZLIPS-MEINS.
MOVE WA_FINAL-UMZIN TO WA_ZLIPS-UMZIN.
MOVE WA_FINAL-WERKS TO WA_ZLIPS-WERKS.
MOVE WA_FINAL-ERDAT TO WA_ZLIPS-ERDAT.
MOVE WA_FINAL-MAKTX TO WA_ZLIPS-MAKTX.
insert zlips from WA_final.
CLEAR: WA_FINAL, WA_ZLIPS.
endloop.

ENDLOOP.
ENDIF.


*IF IT_ZLIPS IS NOT INITIAL.
*
* LOOP AT IT_ZLIPS INTO WA_ZLIPS.
*READ TABLE IT_ZLIPS INTO WA_ZLIPS WITH KEY ZVBELN = WA_ZLIPS-ZVBELN.
* WA_FINAL-ZVBELN = WA_ZLIPS-ZVBELN.
* ENDLOOP.
* ENDIF.
ENDFORM.

*FORM FORMAT_VALTO_VALON_DATE USING ERDAT CHANGING WA_ERDAT .
* CLEAR :
* WA_ERDAT.
*
* WA_ERDAT = WA_ERDAT = WA_ERDAT.
*
* CALL FUNCTION 'FORMAT_DATE_4_OUTPUT'
* EXPORTING
* DATIN = WA_ERDAT
* FORMAT = 'DD.MM.YYYY'
* IMPORTING
* DATEX = WA_ERDAT.
*
*ENDFORM.

PERFORM GET_DATA.

PERFORM FINAL_DATA.


END-OF-SELECTION.

PERFORM FIELD_CAT.
*&---------------------------------------------------------------------*
*& Form FIELD_CAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FIELD_CAT .

*WA_FCAT-FIELDNAME = 'ZVBELN'.
*WA_FCAT-REF_TABNAME = 'IT_FINAL'.
*WA_FCAT-SELTEXT_L = 'TEMP. DOCUMENT NO'.
*WA_FCAT-COL_POS = 1.
*WA_FCAT-EDIT = 'X'.
*APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-FIELDNAME = 'VBELN'.
WA_FCAT-REF_TABNAME = 'IT_FINAL'.
WA_FCAT-SELTEXT_L = 'SALES DOCUMENT'.
WA_FCAT-COL_POS = 2.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-FIELDNAME = 'POSNR'.
WA_FCAT-REF_TABNAME = 'IT_FINAL'.
WA_FCAT-SELTEXT_L = 'SALES DOCUMENT ITEM'.
WA_FCAT-COL_POS = 3.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-FIELDNAME = 'MATNR'.
WA_FCAT-REF_TABNAME = 'IT_FINAL'.
WA_FCAT-SELTEXT_L = 'MATERIAL NUMBER'.
WA_FCAT-COL_POS = 4.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-FIELDNAME = 'UMZIZ'.
WA_FCAT-REF_TABNAME = 'IT_FINAL'.
WA_FCAT-SELTEXT_L = 'KG'.
WA_FCAT-EDIT = 'X'.
wa_fcat-do_sum = 'X'.
WA_FCAT-COL_POS = 5.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-FIELDNAME = 'MEINS'.
WA_FCAT-REF_TABNAME = 'IT_FINAL'.
WA_FCAT-SELTEXT_L = 'UNIT'.
WA_FCAT-COL_POS = 6.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-FIELDNAME = 'UMZIN'.
WA_FCAT-REF_TABNAME = 'IT_FINAL'.
WA_FCAT-SELTEXT_L = 'BAG'.
WA_FCAT-EDIT = 'X'.
wa_fcat-do_sum = 'X'.
WA_FCAT-COL_POS = 7.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-FIELDNAME = 'ZIEME'.
WA_FCAT-REF_TABNAME = 'IT_FINAL'.
WA_FCAT-SELTEXT_L = 'UNIT'.
WA_FCAT-COL_POS = 8.
APPEND WA_FCAT TO IT_FCAT.


WA_FCAT-FIELDNAME = 'WERKS'.
WA_FCAT-REF_TABNAME = 'IT_FINAL'.
WA_FCAT-SELTEXT_L = 'PLANT'.
WA_FCAT-COL_POS = 9.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-FIELDNAME = 'ERDAT'.
WA_FCAT-REF_TABNAME = 'IT_FINAL'.
WA_FCAT-SELTEXT_L = 'DATE'.
WA_FCAT-COL_POS = 10.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-FIELDNAME = 'MAKTX'.
WA_FCAT-REF_TABNAME = 'IT_FINAL'.
WA_FCAT-SELTEXT_L = 'DESCRIPTION'.
WA_FCAT-COL_POS = 11.
APPEND WA_FCAT TO IT_FCAT.

call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = sy-repid
it_fieldcat = it_fcat "PASS FIELD CATALOG TO ALV
* i_save = 'X'
I_CALLBACK_PF_STATUS_SET = 'SET_PF_STATUS'


tables
t_outtab = it_final.


ENDFORM.


form set_pf_status using rt_extab type slis_t_extab.


SET PF-STATUS 'SAVE'.
*CASE SY-UCOMM.


* END
* CASE SY-UCOMM.
* WHEN 'SAVE'.
*break-point.
*WHEN 'SAVE'.
IF SY-UCOMM = 'SAVE'.
break-point.
*LOOP.

*break-point.
DATA : DOC_NUM TYPE CHAR10.
*LOOP at it_vbap into wa_vbaP.
*LOOP AT IT_FINAL INTO WA_FINAL.
READ TABLE IT_ZLIPS INTO wa_zlips with key vbeln = wa_vbaP-VBELN.
*READ TABLE IT_ZLIPS INTO wa_zlips with key vbeln = wa_zlips-VBELN.
*BREAK-POINT.
* SHIFT WA_VBAP-VBELN LEFT DELETING LEADING '0'.
*select max( zvbeln ) from zlips into DOC_NUM where vbeln = WA_zlips-VBELN.
*SELECT MAX( ZVBELN ) FROM ZLIPS INTO DOC_NUM WHERE VBELN = WA_ZLIPS-ZVBELN. "INTO DOC_NUM
* wa_VBAP-vbeln.
* vbeln = wa_vbap-vbeln.
* zvbeln = wa_zlips-zvbeln.
* wa_FINAL-zvbeln = 2020 + temp_zvbeln + 1.
WA_ZLIPS-ZVBELN = DOC_NUM + 1 . " DOC_NUM + 1
* WA_ZLIPS-ZVBELN = WA_ZLIPS-ZVBELN + 1.
* DOC_NUM = WA_ZLIPS-ZVBELN + 1.


*BREAK-POINT.
*loop at it_final into wa_final.
move DOC_NUM to WA_final-ZVBELN.
* MOVE DOC_NUM TO WA_zlips-ZVBELN.
move wa_zlips-vbeln to wa_final-vbeln.
move wa_zlips-posnr to wa_final-posnr.
move wa_zlips-MATNR to wa_final-MATNR.
MOVE WA_zlips-ZIEME TO WA_final-ZIEME.
MOVE WA_zlips-UMZIZ TO WA_final-UMZIZ.
MOVE WA_zlips-MEINS TO WA_final-MEINS.
MOVE WA_zlips-UMZIN TO WA_final-UMZIN.
MOVE WA_zlips-WERKS TO WA_final-WERKS.
MOVE WA_zlips-ERDAT TO WA_final-ERDAT.
MOVE WA_zlips-MAKTX TO WA_final-MAKTX.

append wa_zlips to it_zLIPS.
clear zlips .
CLEAR DOC_NUM.
* APPEND WA_ZLIPS TO IT_FINAL.
* delete it_zlips index 1.
modify zlips from table it_ZLIPS.
*endloop.
if sy-subrc = 0.
MESSAGE : 'NEW TEMPORARY ORDER NO.' TYPE 'I'.

endif.
*ENDLOOP.
ENDIF.

MESSAGE : 'DATA HAS BEEN SUCCESSFULLY SAVED' TYPE 'S'.
*endloop.
*endcase.

*WHEN 'BACK'.
IF SY-UCOMM = 'BACK'.
LEAVE PROGRAM.
ENDIF.
* WHEN 'EXIT'.
IF SY-UCOMM = 'EXIT'.
* LEAVE TO SCREEN 0.
LEAVE PROGRAM.
ENDIF.
* WHEN 'CANCEL'.
IF SY-UCOMM = 'CANCEL'.
LEAVE PROGRAM.
* LEAVE PROGRAM.
ENDIF.
*ENDCASE.
* WHEN 'BACK'.
*IF SY-UCOMM = 'BACK'.
* LEAVE PROGRAM.
*ENDIF.
** WHEN 'EXIT'.
*IF SY-UCOMM = 'EXIT'.
** LEAVE TO SCREEN 0.
* LEAVE PROGRAM.
*ENDIF.
** WHEN 'CANCEL'.
*IF SY-UCOMM = 'CANCEL'.
* LEAVE PROGRAM.
** LEAVE PROGRAM.
*ENDIF.
** ENDCASE.

ENDFORM.

dev_parbutteea
Active Contributor
160

Your requirement + solution does not make sense functionally speaking:

1. Why do you even need to save a temp sales order number ?

2. Even if you are able to save the temp order number, Nothing prevents the system from creating a new sales order number with the same temp order your saved....

2. You may need to define a new number range or devise a custom number range for your requiement .. like YYYYMMDDxxx, where xxx is incremental.