0% found this document useful (0 votes)
49 views5 pages

Safta Creation:: Function

This document contains an RFC function used to generate SAFTA invoices. It imports invoice details like country, LC number, buyer details, etc. and validates the data. If valid, it generates a unique invoice number, saves the invoice header and details to a database table, and returns the invoice number. It locks and unlocks database tables to prevent concurrent access during invoice creation.

Uploaded by

itkishorkumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views5 pages

Safta Creation:: Function

This document contains an RFC function used to generate SAFTA invoices. It imports invoice details like country, LC number, buyer details, etc. and validates the data. If valid, it generates a unique invoice number, saves the invoice header and details to a database table, and returns the invoice number. It locks and unlocks database tables to prevent concurrent access during invoice creation.

Uploaded by

itkishorkumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

SAfta creation:

FUNCTION YV_BD_CREATE_SAFTA_IN.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(LAND1) TYPE CHAR3 OPTIONAL
*" VALUE(LCNUM) TYPE CHAR10 OPTIONAL
*" VALUE(BUYER) TYPE CHAR30 OPTIONAL
*" VALUE(ADDRESS1) TYPE CHAR30 OPTIONAL
*" VALUE(ADDRESS2) TYPE CHAR30 OPTIONAL
*" VALUE(ADDRESS3) TYPE CHAR30 OPTIONAL
*" VALUE(ADDRESS4) TYPE CHAR30 OPTIONAL
*" VALUE(CONSIGNEE) TYPE CHAR30 OPTIONAL
*" VALUE(NOTIFY_PARTY) TYPE CHAR30 OPTIONAL
*" VALUE(CON_ADDRESS1) TYPE CHAR30 OPTIONAL
*" VALUE(NP_ADDRESS1) TYPE CHAR30 OPTIONAL
*" VALUE(CON_ADDRESS2) TYPE CHAR30 OPTIONAL
*" VALUE(NP_ADDRESS2) TYPE CHAR30 OPTIONAL
*" VALUE(CON_ADDRESS3) TYPE CHAR30 OPTIONAL
*" VALUE(NP_ADDRESS3) TYPE CHAR30 OPTIONAL
*" VALUE(CON_ADDRESS4) TYPE CHAR30 OPTIONAL
*" VALUE(NP_ADDRESS4) TYPE CHAR30 OPTIONAL
*" VALUE(PACKAGE_TYP) TYPE CHAR75 OPTIONAL
*" VALUE(QTY) TYPE CHAR17 OPTIONAL
*" VALUE(MEINS) TYPE CHAR3 OPTIONAL
*" VALUE(MOT) TYPE CHAR2 OPTIONAL
*" VALUE(EPCG_LIC) TYPE CHAR20 OPTIONAL
*" VALUE(CRMCODE) TYPE CHAR10 OPTIONAL
*" EXPORTING
*" VALUE(LV_RETURN1) TYPE YYSTATMSG
*" VALUE(E_SAFTA_INVOICE) TYPE CHAR20
*" VALUE(E_CRMCODE) TYPE CHAR10
*"----------------------------------------------------------------------
**&--------------------------------------------------------------------&*
**&RFC Name : YV_BD_CREATE_SAFTA_IN &*
**&Requested : Mr. Anand Dwivedi AM-PC-M &*
**&Developed By : Kishor Kumar &*
**&Module Name : Export &*
**&FM Type : RFC &*
**&SAP Release : ECC6.0 Transport No :DEVK9A0RE6 &*
**&Created By : HP &*
**&Description : This RFC used to generate the Safta Invoice&*
*"----------------------------------------------------------------------*"
DATA : l_epcg_dtl TYPE yva_epcg_dtl.
DATA : g_invc_type TYPE char1.
data : t_yva_exp_invc type table of yva_exp_invc with header line.
CLEAR l_epcg_dtl.
g_invc_type = 'S'.
E_CRMCODE = CRMCODE.
DATA : tabkey LIKE rstable-varkey.
IF land1 IS INITIAL OR
lcnum IS INITIAL.
LV_RETURN1 = 'Please Enter Country and LC Number'.
EXIT.
ENDIF.

IF EPCG_LIC IS NOT INITIAL.


SELECT SINGLE * FROM yva_epcg_dtl
INTO l_epcg_dtl
WHERE epcg_no = epcg_lic.
move l_epcg_dtl-EPCG_DT to t_yva_exp_invc-EPCG_DT.

IF l_epcg_dtl-validity LT sy-datum.
LV_RETURN1 = 'Validity of EPCG Lic expired.'.
exit.
ENDIF.
IF l_epcg_dtl-land1 <> land1.
LV_RETURN1 = 'EPCG Lic country differs from invoice country'.
exit.
ENDIF.
ENDIF.
IF qty IS NOT INITIAL AND
meins IS INITIAL.
LV_RETURN1 = 'Please Enter unit'.
EXIT.
ENDIF.
if lv_return1 is not initial .
exit.
endif .
*****************************************************************************
******
* L O C K T A B L E
*****************************************************************************
******
tabkey = '590@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@'.
tabkey+0(3) = sy-mandt.
tabkey+23(3) = land1.
tabkey+26(10) = lcnum.

CALL FUNCTION 'ENQUEUE_E_TABLEE'


EXPORTING
mode_rstable = 'E'
tabname = 'YVA_EXP_INVC'
varkey = tabkey
EXCEPTIONS
foreign_lock = 1
system_failure = 2
* OTHERS = 3
.
IF sy-subrc <> 0.
CASE sy-subrc .
WHEN 1 OR 2.
LV_RETURN1 = 'Table locked please try again after the some time'.
EXIT.
ENDCASE.
ENDIF.

*****************************************************************************
******
* G E N E R A T E I N V O I C E N U M B E R
*****************************************************************************
******
DATA : l_indxkey LIKE indx-srtfd,
l_invoice_no(20),
l_invoice_curr(5) TYPE n,
l_year(4),
l_month(2).
*DATA : g_invc_type TYPE char1.
data : safta_invc type YYSAFTA.
CLEAR : l_year, l_month, l_indxkey, l_invoice_no.

"Get fiscal year


l_year = sy-datum+0(4).
l_month = sy-datum+4(2).

IF l_month = '01' OR
l_month = '02' OR
l_month = '03'.
l_year = l_year - 1.
ENDIF.

CONCATENATE land1 g_invc_type l_year INTO l_invoice_no .

l_indxkey = l_invoice_no .
*---- Lock Current Row before fetching
CALL FUNCTION 'ENQUEUE_ESINDX'
EXPORTING
mode_indx = 'E'
mandt = sy-mandt
relid = 'ei'
srtfd = l_indxkey
EXCEPTIONS
foreign_lock = 1
system_failure = 2
OTHERS = 3.

IF sy-subrc <> 0 .
LV_RETURN1 = 'Current number is locked.Process terminating.'.
exit.
ENDIF .

*---- Import Existing Number from database .


IMPORT l_invoice_curr FROM DATABASE indx(ei) ID l_indxkey.
*---- If it does not exist , make current no. as 1 .
IF sy-subrc <> 0 .
l_invoice_curr = '00001' .
*---- Else , increment existing number by 1
ELSE .
l_invoice_curr = l_invoice_curr + 1 .
ENDIF .
*---- Export current no.
EXPORT l_invoice_curr TO DATABASE indx(ei) ID l_indxkey.

CALL FUNCTION 'DEQUEUE_ESINDX'


EXPORTING
mode_indx = 'E'
mandt = sy-mandt
relid = 'ei'
srtfd = l_indxkey
EXCEPTIONS
OTHERS = 1.
"**************************************************************************
*****

CONCATENATE land1 '/SAFTA/' l_year '/' l_invoice_curr INTO safta_invc.

*****************************************************************************
******
* S A V E D E T A I L S
*****************************************************************************
******
IF g_invc_type = 'S'.

t_yva_exp_invc-MANDT = sy-mandt.
t_yva_exp_invc-SAFTA_INVC = safta_invc.
t_yva_exp_invc-LAND1 = land1.
t_yva_exp_invc-LCNUM = lcnum.
t_yva_exp_invc-BUYER = buyer.
t_yva_exp_invc-ADDRESS1 = address1.
t_yva_exp_invc-ADDRESS2 = address2.
t_yva_exp_invc-ADDRESS3 = address3.
t_yva_exp_invc-ADDRESS4 = address4.
t_yva_exp_invc-CONSIGNEE = consignee.
t_yva_exp_invc-CON_ADDRESS1 = CON_ADDRESS1.
t_yva_exp_invc-CON_ADDRESS2 = CON_ADDRESS2.
t_yva_exp_invc-CON_ADDRESS3 = CON_ADDRESS3.
t_yva_exp_invc-CON_ADDRESS4 = CON_ADDRESS4.
t_yva_exp_invc-NOTIFY_PARTY = NOTIFY_PARTY.
t_yva_exp_invc-NP_ADDRESS1 = NP_ADDRESS1.
t_yva_exp_invc-NP_ADDRESS2 = NP_ADDRESS2.
t_yva_exp_invc-NP_ADDRESS3 = NP_ADDRESS3.
t_yva_exp_invc-NP_ADDRESS4 = NP_ADDRESS4.
t_yva_exp_invc-PACKAGE_TYP = PACKAGE_TYP.
t_yva_exp_invc-QTY = qty.
t_yva_exp_invc-MEINS = meins.
t_yva_exp_invc-MOT = mot.
t_yva_exp_invc-EPCG_LIC = EPCG_LIC.
* t_yva_exp_invc-EPCG_DT
* t_yva_exp_invc-CANC_SAFTA
t_yva_exp_invc-ERNAM = sy-uname.
t_yva_exp_invc-ERDAT = sy-datum.
t_yva_exp_invc-ERZET = sy-uzeit.
* t_yva_exp_invc-AENAM
* t_yva_exp_invc-AEDAT
* t_yva_exp_invc-AEZET
* t_yva_exp_invc-MOT_DESC
MODIFY yva_exp_invc from t_yva_exp_invc.
if sy-subrc = 0 .
commit work.
E_SAFTA_INVOICE = safta_invc.
else.
rollback work.
LV_RETURN1 = 'Unable to save data at the moment,Please try again later.'.
exit.
endif.
endif.
*****************************************************************************
******
* U N L O C K T A B L E
*****************************************************************************
******
tabkey = '590@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@'.
tabkey+0(3) = sy-mandt.
tabkey+23(3) = land1.
tabkey+26(10) = lcnum.

CALL FUNCTION 'DEQUEUE_E_TABLEE'


EXPORTING
mode_rstable = 'E'
tabname = 'YVA_EXP_INVC'
varkey = tabkey.
*****************************************************************************
******
CLEAR:LAND1,LCNUM,BUYER,ADDRESS1,ADDRESS2,ADDRESS3,ADDRESS4,CONSIGNEE,NOTIFY_P
ARTY,
CON_ADDRESS1,NP_ADDRESS1,CON_ADDRESS2,NP_ADDRESS2,CON_ADDRESS3,NP_ADDRESS3,CON
_ADDRESS4,
NP_ADDRESS4,NP_ADDRESS4,PACKAGE_TYP,QTY,MEINS,MOT,EPCG_LIC.
endfunction.

You might also like