You are on page 1of 4

From Production client dated 20th Jul 2016

*&---------------------------------------------------------------------*
*& Include
ZSD_SMINV_PAD_CHECK
*&---------------------------------------------------------------------*
TYPES: BEGIN OF tw_pcec_c.
INCLUDE STRUCTURE pcec.
TYPES: END OF tw_pcec_c.
TYPES: BEGIN OF tw_pad_chk_c.
INCLUDE STRUCTURE zsd_pad_check.
TYPES: END OF tw_pad_chk_c.
TYPES: BEGIN OF tw_payr_c.
INCLUDE STRUCTURE payr.
TYPES: END OF tw_payr_c.
TYPES: BEGIN OF tw_vbak_pad_c.
INCLUDE STRUCTURE vbak.
TYPES: END OF tw_vbak_pad_c.
TYPES: BEGIN OF tw_vbpa_c.
INCLUDE STRUCTURE vbpa.
TYPES: END OF tw_vbpa_c.
DATA: lt_vbak_pad_c
TYPE STANDARD TABLE OF tw_vbak_pad_c,
lt_pcec_c
TYPE STANDARD TABLE OF tw_pcec_c,
lt_payr_c
TYPE STANDARD TABLE OF tw_payr_c,
lt_pcec_chk
TYPE STANDARD TABLE OF tw_pcec_c,
lt_pad_chk_c
TYPE STANDARD TABLE OF tw_pad_chk_c,
lt_pcec_upd_c
TYPE STANDARD TABLE OF tw_pcec_c.
DATA: lw_vbpa_c
TYPE vbpa,
lw_pcec_read_c TYPE tw_pcec_c,
lw_payr_c
TYPE tw_payr_c,
lw_pcec_upd_c
TYPE tw_pcec_c,
lw_pcec_c
TYPE tw_pcec_c,
lw_pad_chk
TYPE tw_pad_chk_c,
lf_inv_no_c
lf_cur_inv_no_c
lf_pernr_c
lf_pernr_chk
lf_hbkid_c
lf_bukrs_c
lf_hktid_c
lf_num01_c
lf_num02_c
lf_num_diff_c

TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE

cepct,
cepct,
char10,
pernr_d,
hbkid,
bukrs,
hktid,
i,
i,
i.

IF sy-tcode EQ 'VA01' OR sy-tcode EQ 'VA02'.

IF vbak-zpad_typ NE 'NPAD'.
SELECT * FROM zsd_pad_check
INTO CORRESPONDING FIELDS OF TABLE lt_pad_chk_c
WHERE bukrs EQ vbak-bukrs_vf
AND vkorg EQ vbak-vkorg
AND vtweg EQ vbak-vtweg
AND spart EQ vbak-spart
AND auart EQ vbak-auart
AND chk_req EQ 'X'.
IF sy-subrc EQ 0.
READ TABLE xvbpa INTO lw_vbpa_c WITH KEY parvw = 'ZE'.

IF sy-subrc EQ 0 AND lw_vbpa_c-pernr <> '00000000'.


IF sy-tcode EQ 'VA02'.
SELECT SINGLE pernr INTO lf_pernr_chk
FROM vbpa
WHERE vbeln = xvbpa-vbeln
AND parvw = 'ZE'.
IF lf_pernr_chk GT 0.
IF lf_pernr_chk NE lw_vbpa_c-pernr.
MESSAGE e000(oo) WITH 'Changing Salesman is not allowed for manua
l Invoice documents'.
ENDIF.
ENDIF.
ENDIF.
WRITE lw_vbpa_c-pernr TO lf_pernr_c NO-ZERO.
CONDENSE lf_pernr_c.
lf_hktid_c = lf_pernr_c.
ELSE.
IF NOT vbak-zinv_no IS INITIAL .
MESSAGE e000(oo) WITH 'Salesman not assigned to the document for proce
ssing' vbak-zinv_no.
ENDIF.
ENDIF.
IF sy-tcode EQ 'VA01'.
lf_bukrs_c = vbak-bukrs_vf.
lf_inv_no_c = vbak-zinv_no.
* For checking the PAD Inv used.
SELECT * FROM vbak
INTO CORRESPONDING FIELDS OF TABLE lt_vbak_pad_c
WHERE zinv_no = lf_inv_no_c.

* For getting the Current Inv No assigned to salesman.


SELECT * FROM pcec
INTO CORRESPONDING FIELDS OF TABLE lt_pcec_c
WHERE zbukr = lf_bukrs_c

AND
AND

hbkid = vbak-zpad_typ
hktid = lf_hktid_c.

IF sy-subrc EQ 0.
clear: lf_num01_c,lf_num02_c,lf_num_diff_c.
LOOP AT lt_pcec_c INTO lw_pcec_c.
IF NOT lw_pcec_c-checl IS INITIAL.
IF lw_pcec_c-checl EQ lw_pcec_c-chect AND lw_pcec_c-fstap EQ ''.
MESSAGE e000(oo) WITH 'Already issued PAD used. Issue new PAD'.
ELSEIF lw_pcec_c-checl NE lw_pcec_c-chect.
lf_cur_inv_no_c = lw_pcec_c-checl + 1.
CONDENSE lf_cur_inv_no_c.
lf_num01_c = STRLEN( lw_pcec_c-checl ).
lf_num02_c = STRLEN( lf_cur_inv_no_c ).
lf_num_diff_c = lf_num01_c - lf_num02_c.
DO lf_num_diff_c TIMES.
CONCATENATE '0' lf_cur_inv_no_c INTO lf_cur_inv_no_c.
CONDENSE lf_cur_inv_no_c.
ENDDO.
CONDENSE lf_cur_inv_no_c.
EXIT.
ENDIF.
ELSE.
lf_cur_inv_no_c = lw_pcec_c-checf.
EXIT.
ENDIF.
ENDLOOP.

* Validation for entered V/s current invoice no.


IF lf_cur_inv_no_c NE lf_inv_no_c.
* Check for pending or cancelled.
SELECT * FROM payr
INTO CORRESPONDING FIELDS OF TABLE lt_payr_c
WHERE zbukr EQ vbak-bukrs_vf
AND hbkid EQ vbak-zpad_typ
AND hktid EQ lf_hktid_c
AND chect EQ vbak-zinv_no
AND ( voidr EQ '11' OR voidr EQ '12' ).
IF sy-subrc EQ 0.
READ TABLE lt_payr_c INTO lw_payr_c WITH KEY hktid = lf_hktid_c
voidr = '11'.
IF sy-subrc EQ 0.
MESSAGE e000(oo) WITH 'Invoice number ' vbak-zinv_no ' has been ca

ncelled'.
ENDIF.
ELSE.
MESSAGE e000(oo) WITH 'Invoice number entered does not match with cu
rrent invoice number' lf_cur_inv_no_c.
ENDIF.
ENDIF.
ELSE.
MESSAGE e000(oo) WITH 'Invoice PAD not Issued for PAD type' vbakzpad_typ 'to salesman' lf_hktid_c.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDIF.