MODULE USER_COMMAND INPUT.
GV_UCOMM = SY-UCOMM.
DATA : LV_REQ TYPE ZREQ.
DATA : LV_IREQ TYPE ZIREQ.
DATA : LV_INTER(10) TYPE N.”zinter.
DATA : GJAHR(8) TYPE C.
DATA: LV_ZTAG1 TYPE T052-ZTAG1,
LV_ZTERM TYPE LFM1-ZTERM.
CLEAR: wa_gmitem, wa_gmhead,matdoc, it_gmitem.
IF GV_UCOMM = ‘&SAVE’.
* *ADDED BY PRATIKB
IF CUST EQ ‘X’.
zsc_head_sadm2-KUNNR = zsc_head_sadm2-LIFNR.
ENDIF.
* *ADDED BY PRATIKB
IF ( “zsc_head_sadm2-nopckg IS INITIAL OR
zsc_head_sadm2-werks IS INITIAL OR
zsc_head_sadm2-lgort IS INITIAL OR
zsc_head_sadm2-lifnr IS INITIAL OR
zsc_head_sadm2-nrgp IS INITIAL ).
MESSAGE: ‘Please enter No of Packages, Plant, Stor. Loc., Vendor, RGP’
TYPE ‘E’.
ENDIF.
IF zsc_head_sadm2-LIFNR NE SPACE.
IF zsc_head_sadm2-NRGP NE SPACE.
IF zsc_head_sadm2-ERDAT EQ ‘00000000’.
zsc_head_sadm2-ERDAT = SY-DATUM.
ENDIF.
IF zsc_head_sadm2-ERZET EQ ‘000000’.
zsc_head_sadm2-ERZET = SY-UZEIT.
ENDIF.
IF zsc_head_sadm2-AUTH EQ SPACE.
zsc_head_sadm2-AUTH = SY-UNAME.
ENDIF.
IF zsc_head_sadm2-REQ = SPACE.
SELECT MAX( REQ ) INTO LV_REQ FROM zsc_head_sadm2.
zsc_head_sadm2-REQ = LV_REQ + 1.
* zsc_head_sadm2-rdate = sy-datum.
ELSE.
zsc_head_sadm2-REQ = zsc_head_sadm2-REQ.
ENDIF.
IF zsc_head_sadm2-NRGP = ‘1’ AND zsc_head_sadm2-KOSTL IS INITIAL.
IF zsc_head_sadm2-INTER = SPACE.
CLEAR : LV_INTER, GJAHR.
*************************************************************
LOOP AT IT_LINE INTO WA_LINE WHERE MATNR IS NOT INITIAL.
WA_GMHEAD-PSTNG_DATE = SY-DATUM.
WA_GMHEAD-DOC_DATE = SY-DATUM.
WA_GMITEM-MATERIAL = WA_LINE-MATNR.
WA_GMITEM-PLANT = zsc_head_sadm2-WERKS.
WA_GMITEM-STGE_LOC = zsc_head_sadm2-LGORT.
* WA_GMITEM-MOVE_TYPE = ‘Z61’.
IF CUST = ‘X’.
WA_GMITEM-CUSTOMER = zsc_head_sadm2-LIFNR.
* wa_gmitem-spec_stock = ‘W’.
WA_GMITEM-MOVE_TYPE = ‘Z31’.
ELSE.
WA_GMITEM-VENDOR = zsc_head_sadm2-LIFNR.
WA_GMITEM-MOVE_TYPE = ‘Z41’.
ENDIF.
WA_GMITEM-ENTRY_QNT = WA_LINE-MENGE.
WA_GMITEM-ENTRY_UOM = WA_LINE-MEINS.
SELECT SINGLE MTART FROM MARA
INTO @DATA(LV_MTART)
WHERE MATNR = @wa_LINE-MATNR.
IF LV_MTART <> ‘UNBW’.
WA_GMITEM-AMOUNT_LC = WA_LINE-KWERT.
ENDIF.
APPEND WA_GMITEM TO IT_GMITEM.
CLEAR : WA_LINE, WA_GMITEM.
ENDLOOP.
CALL FUNCTION ‘BAPI_GOODSMVT_CREATE’
EXPORTING
GOODSMVT_HEADER = WA_GMHEAD
GOODSMVT_CODE = ’03’
TESTRUN = ‘X’
IMPORTING
MATERIALDOCUMENT = MATDOC
TABLES
GOODSMVT_ITEM = IT_GMITEM
RETURN = IT_RETURN.
* IF it_return IS NOT INITIAL.
IF it_return IS INITIAL. “”””Added by Akshata
DATA(lv_check) = abap_true.
ELSE.
READ TABLE IT_RETURN INTO WA_RETURN WITH KEY TYPE = ‘E’.
IF SY-SUBRC = 0.
CONCATENATE WA_RETURN-MESSAGE ‘for Movement Type Z41’ INTO MESSAGE
SEPARATED BY SPACE.
MESSAGE: MESSAGE TYPE ‘E’ DISPLAY LIKE ‘E’.
ENDIF.
ENDIF.
*************************************************************
IF SY-TCODE EQ ‘ZSADM_SUBCDC’ AND lv_check = abap_true.
CALL FUNCTION ‘NUMBER_GET_NEXT’
EXPORTING
NR_RANGE_NR = ‘Q2’
OBJECT = ‘ZNRGP’
* quantity = ‘000000001’
IMPORTING
NUMBER = LV_INTER
EXCEPTIONS
INTERVAL_NOT_FOUND = 1
NUMBER_RANGE_NOT_INTERN = 2
OBJECT_NOT_FOUND = 3
QUANTITY_IS_0 = 4
QUANTITY_IS_NOT_1 = 5
INTERVAL_OVERFLOW = 6
BUFFER_OVERFLOW = 7
OTHERS = 8.
CONCATENATE ‘J’ LV_INTER INTO zsc_head_sadm2-INTER.
“””””””Begin of Changes by Eidikos Mahesh K””””””””
zsc_head_sadm2-CCREADATE = SY-DATUM.
zsc_head_sadm2-CCREATIME = SY-UZEIT.
UPDATE zsc_head_sadm2 SET INTER = zsc_head_sadm2-INTER
CCREADATE = SY-DATUM
CCREATIME = SY-UZEIT
WHERE REQ = zsc_head_sadm2-REQ
AND GJAHR = zsc_head_sadm2-GJAHR.
UPDATE zsc_line_sadm2 SET INTER = zsc_head_sadm2-INTER
WHERE REQ = zsc_head_sadm2-REQ
AND GJAHR = zsc_head_sadm2-GJAHR.
COMMIT WORK AND WAIT.
ENDIF.
CALL FUNCTION ‘GM_GET_FISCAL_YEAR’
EXPORTING
I_DATE = SY-DATUM
I_FYV = ‘V3’
IMPORTING
E_FY = GJAHR.
zsc_head_sadm2-GJAHR = GJAHR.
CLEAR : LV_INTER, GJAHR.
ELSE.
zsc_head_sadm2-INTER = zsc_head_sadm2-INTER.
ENDIF.
ELSEIF ( zsc_head_sadm2-NRGP = ‘2’
OR zsc_head_sadm2-NRGP = ‘3’
OR zsc_head_sadm2-NRGP = ‘4’ )
AND zsc_head_sadm2-KOSTL IS NOT INITIAL.
IF zsc_head_sadm2-INTER = SPACE.
CLEAR : LV_INTER, GJAHR.
**————————————————————————————-added by sadmabap(PNB) 16.10.2024
LOOP AT IT_LINE INTO WA_LINE WHERE MATNR IS NOT INITIAL.
WA_GMHEAD-PSTNG_DATE = SY-DATUM.
WA_GMHEAD-DOC_DATE = SY-DATUM.
WA_GMITEM-MATERIAL = WA_LINE-MATNR.
WA_GMITEM-PLANT = zsc_head_sadm2-WERKS.
WA_GMITEM-STGE_LOC = zsc_head_sadm2-LGORT.
WA_GMITEM-MOVE_TYPE = ‘Z61’.
IF CUST = ‘X’.
WA_GMITEM-CUSTOMER = zsc_head_sadm2-LIFNR.
* wa_gmitem-spec_stock = ‘W’.
* WA_GMITEM-MOVE_TYPE = ‘Z31’.
ELSE.
WA_GMITEM-VENDOR = zsc_head_sadm2-LIFNR.
WA_GMITEM-MOVE_TYPE = ‘Z61’. “”””””ADDED BY AKSHATA
ENDIF.
WA_GMITEM-ENTRY_QNT = WA_LINE-MENGE.
WA_GMITEM-ENTRY_UOM = WA_LINE-MEINS.
SELECT SINGLE MTART FROM MARA
INTO @LV_MTART
WHERE MATNR = @wa_LINE-MATNR.
IF LV_MTART <> ‘UNBW’.
WA_GMITEM-AMOUNT_LC = WA_LINE-KWERT.
ENDIF.
APPEND WA_GMITEM TO IT_GMITEM.
CLEAR : WA_LINE, WA_GMITEM.
ENDLOOP.
CALL FUNCTION ‘BAPI_GOODSMVT_CREATE’
EXPORTING
GOODSMVT_HEADER = WA_GMHEAD
GOODSMVT_CODE = ’03’
TESTRUN = ‘X’
IMPORTING
MATERIALDOCUMENT = MATDOC
TABLES
GOODSMVT_ITEM = IT_GMITEM
RETURN = IT_RETURN.
IF it_return IS INITIAL.
lv_check = abap_true.
ELSE.
READ TABLE IT_RETURN INTO WA_RETURN WITH KEY TYPE = ‘E’.
IF SY-SUBRC = 0.
CONCATENATE WA_RETURN-MESSAGE ‘for Movement Type Z41’ INTO MESSAGE
* CONCATENATE WA_RETURN-MESSAGE ‘for Movement Type Z61’ INTO MESSAGE “””added by akshata z41 to z61
SEPARATED BY SPACE.
MESSAGE: MESSAGE TYPE ‘E’ DISPLAY LIKE ‘E’.
ENDIF.
ENDIF.
**————————————————————————————-added by sadmabap(PNB) 16.10.2024
IF SY-TCODE EQ ‘ZSADM_SUBCDC’ and lv_check = abap_true. “””added by akshata
CALL FUNCTION ‘NUMBER_GET_NEXT’
EXPORTING
NR_RANGE_NR = ‘Q2’
OBJECT = ‘ZNRGP’
* quantity = ‘000000001’
IMPORTING
NUMBER = LV_INTER
EXCEPTIONS
INTERVAL_NOT_FOUND = 1
NUMBER_RANGE_NOT_INTERN = 2
OBJECT_NOT_FOUND = 3
QUANTITY_IS_0 = 4
QUANTITY_IS_NOT_1 = 5
INTERVAL_OVERFLOW = 6
BUFFER_OVERFLOW = 7
OTHERS = 8.
CONCATENATE ‘O’ LV_INTER INTO zsc_head_sadm2-INTER.
zsc_head_sadm2-CCREADATE = SY-DATUM.
zsc_head_sadm2-CCREATIME = SY-UZEIT.
zsc_head_sadm2-remarks = zsc_head_sadm2-remarks.
zsc_head_sadm2-nopckg = zsc_head_sadm2-nopckg.
* UPDATE zsc_line_sadm2 SET INTER = zsc_head_sadm2-INTER
* WHERE REQ = zsc_head_sadm2-REQ
* AND GJAHR = zsc_head_sadm2-GJAHR.
COMMIT WORK AND WAIT.
ENDIF.
CALL FUNCTION ‘GM_GET_FISCAL_YEAR’
EXPORTING
I_DATE = SY-DATUM
I_FYV = ‘V3’
IMPORTING
E_FY = GJAHR.
zsc_head_sadm2-GJAHR = GJAHR.
CLEAR : LV_INTER, GJAHR.
ELSE.
zsc_head_sadm2-INTER = zsc_head_sadm2-INTER.
ENDIF.
ENDIF.
WA_GMHEAD-REF_DOC_NO = zsc_head_sadm2-INTER.
LOOP AT IT_LINE INTO WA_LINE WHERE MATNR IS NOT INITIAL.
WA_LINE-REQ = zsc_head_sadm2-REQ.
IF WA_LINE-IREQ NE ‘0000’.
VAR = WA_LINE-IREQ.
ENDIF.
IF WA_LINE-IREQ EQ ‘0000’.
VAR = VAR + 1.
WA_LINE-IREQ = VAR.
ENDIF.
WA_LINE-KWERT = WA_LINE-MENGE * WA_LINE-KBETR.
WA_LINE-INTER = zsc_head_sadm2-INTER.
WA_LINE-GJAHR = zsc_head_sadm2-GJAHR.
WA_LINE-REMQTY = WA_LINE-MENGE.
**————added by sadmabap(PNB) 16.10.2024
* DATA : mess TYPE char200.
* IF sy-tcode EQ ‘ZSADM_SUBCDC’.
* CONCATENATE ‘Challan No : ‘ zsc_head_sadm2-inter
** ‘And Requset No’ zsc_head_sadm2-req
* ‘has been saved.’
* INTO mess
* SEPARATED BY space.
* ENDIF.
**————added by sadmabap(PNB) 16.10.2024
MODIFY it_line FROM wa_line TRANSPORTING kwert
inter
gjahr
remqty.
* MODIFY zsc_line_sadm2 FROM WA_LINE.
CLEAR : WA_LINE, WA_GMITEM.
ENDLOOP.
CALL FUNCTION ‘BAPI_GOODSMVT_CREATE’
EXPORTING
GOODSMVT_HEADER = WA_GMHEAD
GOODSMVT_CODE = ’03’
IMPORTING
MATERIALDOCUMENT = MATDOC
TABLES
GOODSMVT_ITEM = IT_GMITEM
RETURN = IT_RETURN.
IF MATDOC IS NOT INITIAL.
CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT’
EXPORTING
WAIT = ABAP_TRUE.
zsc_head_sadm2-DCMBLNR = MATDOC.
IF CUST = ‘X’.
zsc_head_sadm2-DCBWART = ‘Z31’.
ELSE.
zsc_head_sadm2-DCBWART = ‘Z41’.
ENDIF.
MODIFY zsc_head_sadm2 FROM zsc_head_sadm2.
LOOP AT it_line INTO wa_line.
wa_line-req = zsc_head_sadm2-req.
wa_line-dcmblnr = matdoc.
IF CUST = ‘X’.
wa_line-DCBWART = ‘Z31’.
ELSE.
wa_line-DCBWART = ‘Z41’.
ENDIF.
* wa_line-dcbwart = ‘Z41’.
MODIFY zsc_line_sadm2 FROM wa_line.
COMMIT WORK AND WAIT.
CLEAR: wa_line..
ENDLOOP.
**————added by sadmabap(PNB) 16.10.2024
* ELSEIF MATDOC IS INITIAL.
* DATA : mess TYPE char200.
* IF sy-tcode EQ ‘ZSADM_SUBCDC’.
* CONCATENATE ‘Challan No : ‘ zsc_head_sadm2-inter
** ‘And Requset No’ zsc_head_sadm2-req
* ‘has been saved.’
* INTO mess
* SEPARATED BY space.
* ENDIF.
**————added by sadmabap(PNB) 16.10.2024
* ELSE.
* READ TABLE IT_RETURN INTO WA_RETURN WITH KEY TYPE = ‘E’.
* IF SY-SUBRC = 0.
* CONCATENATE WA_RETURN-MESSAGE ‘for Movement Type Z41’ INTO MESSAGE
* SEPARATED BY SPACE.
* MESSAGE: MESSAGE TYPE ‘E’ DISPLAY LIKE ‘E’.
* ENDIF.
* ENDIF.
“”””””””””””””””””””””Added by Akshata 26.12.2024″”””””””””‘
ELSEIF MATDOC IS INITIAL.
CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT’
EXPORTING
WAIT = ABAP_TRUE.
zsc_head_sadm2-DCMBLNR = MATDOC.
IF CUST = ‘X’.
zsc_head_sadm2-DCBWART = ‘Z61’.
ELSE.
zsc_head_sadm2-DCBWART = ‘Z61’.
ENDIF.
MODIFY zsc_head_sadm2 FROM zsc_head_sadm2.
LOOP AT it_line INTO wa_line.
wa_line-req = zsc_head_sadm2-req.
wa_line-dcmblnr = matdoc.
IF CUST = ‘X’.
wa_line-DCBWART = ‘Z61’.
ELSE.
wa_line-DCBWART = ‘Z61’.
ENDIF.
* wa_line-dcbwart = ‘Z41’.
MODIFY zsc_line_sadm2 FROM wa_line.
COMMIT WORK AND WAIT.
CLEAR: wa_line..
ENDLOOP.
**————added by sadmabap(PNB) 16.10.2024
* ELSEIF MATDOC IS INITIAL.
* DATA : mess TYPE char200.
* IF sy-tcode EQ ‘ZSADM_SUBCDC’.
* CONCATENATE ‘Challan No : ‘ zsc_head_sadm2-inter
** ‘And Requset No’ zsc_head_sadm2-req
* ‘has been saved.’
* INTO mess
* SEPARATED BY space.
* ENDIF.
**————added by sadmabap(PNB) 16.10.2024
ELSE.
READ TABLE IT_RETURN INTO WA_RETURN WITH KEY TYPE = ‘E’.
IF SY-SUBRC = 0.
CONCATENATE WA_RETURN-MESSAGE ‘for Movement Type Z61’ INTO MESSAGE
SEPARATED BY SPACE.
MESSAGE: MESSAGE TYPE ‘E’ DISPLAY LIKE ‘E’.
ENDIF.
ENDIF.
“”””””””””””ENd of chnages 26.12.2024″”””””””””””””””””””””
DATA : MESS TYPE CHAR200.
IF SY-TCODE EQ ‘ZSADM_SUBCDC’. “AND matdoc IS NOT INITIAL.
CONCATENATE ‘Requset No’ zsc_head_sadm2-REQ ‘AND’
‘Challan No : ‘ zsc_head_sadm2-INTER
‘AND’ ‘Material Document :’ matdoc
‘has been saved.’
INTO MESS
SEPARATED BY SPACE.
ENDIF.