Skip to Content
author's profile photo
Former Member

Interface validation

Hi

This is my existing interface ,I need to do a validation on Unique id,which i need to add to custom table ZBACKS_GIPD.

Check if there is same unique id within the upload file.

Check from table ZBACKS_GIPD if the same Unique ID already exists ,

Update log file with error message :"Duplicate record"

Please let me know where I need to add this validation in the below code.

REPORT ZBAB005 LINE-SIZE 255

LINE-COUNT 58(2)

NO STANDARD PAGE HEADING

MESSAGE-ID 00.

TABLES: MARA, "Material master

MARC, "Plant Data for Material

MBEW, "Material Valuation

T001K, "Valuation area

t100, "Messages

kna1, "Customer master

SKB1, "G/L account

BKPF, "FIN doc

zprdordhdr, "production order header

ZSTDLOADING, "BACKS-SAP Interface - Generic ProdOrd costing data

ZBACKS_GIPD. "BACKS-SAP Interface - Material Consumption

  • Short name of the interface name

DATA: INTFNAME(4) value 'GIPD'. "Good Issues for Prod. Order

include zbab000. "Common procedures for files handling

SELECTION-SCREEN BEGIN OF BLOCK 6 WITH FRAME TITLE TEXT-006.

parameters: p_usafl obligatory default 'E'. "Usgae indicator

parameters: p_chk_ui as checkbox "check invalid usage ind "UATK922842

default space. "UATK922842

parameters: p_chk_pd as checkbox "check period of the posting date

default 'X'. "UATK923027

SELECTION-SCREEN END OF BLOCK 6.

SELECTION-SCREEN BEGIN OF BLOCK 7 WITH FRAME TITLE TEXT-007.

parameters: fb70mode default 'N'.

parameters: fb50mode default 'N'.

SELECTION-SCREEN END OF BLOCK 7.

SELECTION-SCREEN BEGIN OF BLOCK 8 WITH FRAME TITLE TEXT-008.

parameters:

p_nor radiobutton group rad1, "new posting

p_rep2 radiobutton group rad1. "report (flag '2')

select-options:

recno for zbacks_gipd-recno "record number

default '1' obligatory.

SELECTION-SCREEN END OF BLOCK 8.

DATA: BEGIN OF TAB OCCURS 1000,

WERKS(04), "plant

AUFNR(25), "production order number

MATNR(18), "material

ERDAT(10), "BACKS tx date

MENGE_as_string(17), "qty

USAFL(01), "consumption/usage indicator

SAKNR(10), "G/L account number (this is from user's data file,

"use SAKNR_FOR_POSTING to post mat. doc instead)

  • EXPCD(02), "expenses code

IDNUM(35), "BACKS Identification number

kunnr(10), "customer number

  • The below 3 fields have no use in SAP transactions

  • however they are included in the data file from BACKS.

  • Just store them in ZBACKS_GIPD for future use if required

USACD(10), "usage code

ORDCD(10), "order code

LOSTY(03), "loss type

COTAX(13), " like zbacks_gipd-cotax, "consumption tax

MWSKZ(02), " like zbacks_gipd-MWSKZ, "tax code

  • The below fields are not included in the BACKS incoming data file

  • They are only for the processing of this program

RECNO(10), "record number in the uploaded data file

FAILF(01), "Status flag (0=OK, see documentation for details)

MSGNR(01), "message number

MSGTX(200), "message text

menge(13) type p decimals 3, "qty as numeric

BUKRS like t001-bukrs, "company code

PRCTR like marc-prctr, "profit center

matkl like mara-matkl, "material group

unitstdcost type p decimals 3,"standard cost (per 1 EA)

matloading type i, "material loading

runum like zprdordhdr-runum,"prod. order running number

  • SAKNR like zexpense-saknr, "account no.

KOSTL like zexpense-kostl, "cost center

saknr_for_posting like bseg-saknr,"G/L acct after validation

erdat_raw(10), "BACKS tx date (MM/DD/YYYY)

**>>1104

  • post_seq_ORIG like DATATYPE-INTEGER4,

  • "(5) type n, "random number: posting order

  • post_seq_RAND like DATATYPE-INTEGER4,

  • "(5) type n, "random number: posting order

**>>1104

MATDOC(10), "material document

MATDOCITEM(4), "material document item number

Direction(1), "I=Issue, R=Reverse (based on the +/- of MENGE)

ladra like zbacks_gipd-ladra, "material loading rate

hdr_SUBPR like zprdordhdr-SUBPR, "Sub-con Prodorder "UATK922842

  • the below 2 fields are added to resolve 1-yen issue "DEVK914235

STOCKQTY like ZBACKS_GIPD-STOCKQTY, "total stock (from MBEW)

SALK3 like ZBACKS_GIPD-SALK3, "total value before issue

ISSUESTPRS like ZBACKS_GIPD-ISSUESTPRS,"unit std cost

END OF TAB.

data: START_RECNO like ZBACKS_GIPD-recno.

DATA: BEGIN OF BDCDATA OCCURS 100.

INCLUDE STRUCTURE BDCDATA.

DATA: END OF BDCDATA.

data: begin of msgtab occurs 0.

INCLUDE STRUCTURE BDCMSGCOLL.

data: end of msgtab.

----


  • Constants used in A/C & Inv postings *

----


  • for JV posting

CONSTANTS:

CONST_SAKNR_WIP_LABOUR_OH like BSEG-SAKNR "G/L act: WIP-Labour & O/H

value '0000141000',

CONST_SAKNR_WIP_MAT_LOAD like BSEG-SAKNR "G/L act: WIP Matl. Loading

value '0000543004',

CONST_SAKNR_WIP_MAT like BSEG-SAKNR "G/L act: WIP matl

value '0000140000',

CONST_SAKNR_OTHER_INCOME like BSEG-SAKNR "G/L act: Other income

value '0000725000', "was: '0000400310',

CONST_SAKNR_WIP_MAT_SUB_CON like BSEG-SAKNR "G/L act: Mat supplied

value '0000126001'. "to subcontractor

  • for material movement (inventory posting)

CONSTANTS:

CONST_LGORT like mseg-LGORT "storage location

value 'STR1',

CONST_CHARG like mseg-charg "batch number

value 'BACKS'.

  • for AR customer invoice for sub-contractor

CONSTANTS:

CONST_TAX_RATE type p decimals 2 value '0.05', "i.e. 5%

CONST_PENALTY_RATE type p decimals 2 value '0.2'. "i.e. 20%

----


  • Structures & internal tables for BAPI - Material movement *

----


  • Header segment with control information

DATA: BEGIN OF GOODSMVT_HEADER OCCURS 0.

INCLUDE STRUCTURE BAPI2017_GM_HEAD_01.

DATA: END OF GOODSMVT_HEADER.

DATA: BEGIN OF GOODSMVT_CODE OCCURS 0.

INCLUDE STRUCTURE BAPI2017_GM_CODE.

DATA: END OF GOODSMVT_CODE.

DATA: BEGIN OF GOODSMVT_ITEM OCCURS 0.

INCLUDE STRUCTURE BAPI2017_GM_ITEM_CREATE.

DATA: END OF GOODSMVT_ITEM.

DATA: BEGIN OF REMSG OCCURS 0.

INCLUDE STRUCTURE BAPIRET2.

DATA: END OF REMSG.

DATA: BEGIN OF GOODSMVT_HEADRET OCCURS 0.

INCLUDE STRUCTURE BAPI2017_GM_HEAD_RET.

DATA: END OF GOODSMVT_HEADRET.

*DATA: MATDOC LIKE BAPI2017_GM_HEAD_RET-MAT_DOC.

DATA: DOCYEAR LIKE BAPI2017_GM_HEAD_RET-DOC_YEAR.

----


  • Structures & internal tables for BAPI - Account Doc Posting *

----


DATA: DOCUMENTHEADER like BAPIACHE08.

DATA: BEGIN OF ACCOUNTGL occurs 0.

include structure BAPIACGL08.

DATA: END OF ACCOUNTGL.

DATA: BEGIN OF CURRENCYAMOUNT occurs 0.

include structure BAPIACCR08.

DATA: END OF CURRENCYAMOUNT.

DATA: BEGIN OF RETURN occurs 0.

include structure BAPIRET2.

DATA: END OF RETURN.

----


  • Misc. internal tables and variable for error logging *

----


DATA: BEGIN OF ERRTX OCCURS 0,

MSGTX(110).

DATA: END OF ERRTX.

DATA: ERR(1) TYPE C.

  • TTLQTY(12) TYPE P,

  • SUCQTY(12) TYPE P,

  • FALQTY(12) TYPE P.

----


  • Calculation variables for sub-contractor *

----


data: ar_amt_vendor type p decimals 0.

data: ar_amt_penalty type p decimals 0.

data: ar_amt_total type p decimals 0.

data: ar_amt_tax type p decimals 0.

data: ar_amt_vendor_as_text(13).

data: ar_amt_penalty_as_text(13).

data: ar_amt_total_as_text(13).

data: ar_amt_tax_as_text(13).

data: last_werks like tab-werks. "plant

data: last_matnr like tab-matnr. "to avoid locking problem -> Sleep if

"the current p/n is the same as the last one

data: last_direction.

DATA: FI_DOC_TEXT(50). "contains: 1-35: BACKS ID

" 36-50: Quantity

data: begin of tab_by_matnr occurs 0.

include structure tab.

data: end of tab_by_matnr.

data: MATDOC_AND_ITEM(16). "to put in reference fields

----


  • Data for mat doc item rearrangement *

----


*Max. no. of items in a single material doc.

*This number must be less than the half of the FI doc. item limit (999)

constants:

c_max_mat_doc_items type i value '400'.

  • last flag to indicate if a break is required

data: l_last_matnr like tab-matnr. "last material

data: l_last_direction like tab-direction. "last direction (+ or -)

data: l_last_werks like tab-werks. "last plant

  • count the no. of items (to check against the max. no. of item limit)

data: l_matnr_counter type i.

----


  • Start and End date of the allowed posting priod *

----


data: g_period_start_date like sy-datum. "first date of current period

data: g_period_end_date like sy-datum. "end date of current period

----


  • Stock info before Goods issue (to solve 1-yen issue) *

----


data: G_SALK3(16) type p decimals 0. "total stock value

data: G_LBKUM like mbew-lbkum. "total stock qty

*----


  • T O P O F P A G E

*----


TOP-OF-PAGE.

CALL FUNCTION 'Z_PRINT_REPORT_HEADING'

EXPORTING

I_WERKS = 'IHK1'

I_LINSZ = SY-LINSZ

I_CPROG = SY-CPROG

I_TITLE = SY-TITLE.

WRITE: /1(006) 'Plant' color 1,

(025) 'Production Order No' color 1,

(018) 'Material' color 1,

(010) 'CreDate' color 1,

(015) 'Qty' color 1,

(010) 'Usage Ind.' color 1,

(010) 'G/L Acct.' color 1,

(025) 'BACKS ID' color 1,

(010) 'Cust.No.' color 1,

(001) 'Fail Flag' color 1,

(100) 'Message' color 1.

ULINE.

----


  • START - OF - SELECTION *

----


START-OF-SELECTION.

if p_chk_pd = 'X'. "check preiod is needed "UATK923027

perform start_end_date_of_period. "calculate period start/end date

if g_period_start_date is initial "if the start/end date is not

or g_period_end_date is initial. "determined, stop the program

write: / 'Period start/end date not determined, program stopped.'.

stop.

endif.

endif.

if p_nor = 'X'.

PERFORM COMMON_SETUP_FILENAMES. "auto setup filenames by current date

PERFORM COMMON_UPLOAD_FILES. "upload input files: TXT and FLG

PERFORM CONVERSION_DATA.

elseif p_rep2 = 'X'.

perform read_data_from_GIPD.

endif.

PERFORM CHECK_DATA.

PERFORM MAIN_UPDATE.

PERFORM PRINT_OUTPUT.

PERFORM COMMON_DOWNLOAD_FILES. "download the log & status file

----


  • FORM READ_DATA_FROM_GIPD *

----


form read_data_from_GIPD.

select * from zbacks_gipd

where failf = '2'

and recno in recno.

clear tab.

clear result_total. "reset the record counter

tab-werks = zbacks_gipd-WERKS. "plant

tab-aufnr = zbacks_gipd-AUFNR. "production order no.

tab-matnr = zbacks_gipd-MATNR. "material

tab-erdat = zbacks_gipd-BUDAT. "transaction date

tab-recno = zbacks_gipd-recno.

TAB-MENGE = zbacks_gipd-menge. "qty

TAB-USAFL = zbacks_gipd-usafl. "usage/consumption ind.

  • TAB-EXPCD "Expenses code

TAB-SAKNR = zbacks_gipd-saknr. "G/L account number

TAB-IDNUM = zbacks_gipd-idnum. "BACKS identification no.

TAB-KUNNR = zbacks_gipd-kunnr. "Customer Number

TAB-USACD = zbacks_gipd-usacd. "usage code

TAB-ORDCD = zbacks_gipd-ordcd. "order code

TAB-LOSTY = zbacks_gipd-losty. "loss type

TAB-COTAX = zbacks_gipd-cotax. "consumption tax

TAB-MWSKZ = zbacks_gipd-mwskz. "tax code

tab-runum = zbacks_gipd-runum. "running number

tab-failf = zbacks_gipd-failf. "failure flag

tab-msgnr = zbacks_gipd-failf. "failure flag

tab-matdoc = zbacks_gipd-docm1. "material doc

tab-msgtx = 'Repost 2nd step'.

  • tab-erdat_raw = tab-erdat. "keep the MM/DD/YYYY format

  • CONCATENATE TAB-ERDAT6(4) TAB-ERDAT0(2) TAB-ERDAT+3(2)

  • INTO TAB-ERDAT.

concatenate tab-erdat+4(2) '/'

tab-erdat+6(2) '/'

tab-erdat+0(4)

into tab-erdat_raw.

*Process only a particular set of usage indicator first

if tab-usafl = p_usafl.

APPEND TAB.

result_total = result_total + 1. "Increase the record counter

endif.

endselect.

write: / 'Re-processing records for usage indicator', p_usafl.

endform.

----


  • FORM CONVERSION_DATA *

----


FORM CONVERSION_DATA.

data: saknr_len type i. "field length of GL acct

data: kunnr_len type i. "field length of cust no.

describe field tab-saknr length saknr_len.

describe field tab-kunnr length kunnr_len.

clear result_total. "reset the record counter

LOOP AT STR_TXT.

CLEAR TAB.

SPLIT STR_TXT-SLINE AT '|'

INTO TAB-WERKS "plant

TAB-AUFNR "production order no.

TAB-MATNR "material

TAB-ERDAT "transaction date

TAB-MENGE_as_string "qty

TAB-USAFL "usage/consumption ind.

  • TAB-EXPCD "Expenses code

TAB-SAKNR "G/L account number

TAB-IDNUM "BACKS identification no.

TAB-KUNNR "Customer Number

TAB-USACD "usage code

TAB-ORDCD "order code

TAB-LOSTY "loss type

TAB-COTAX "consumption tax

TAB-MWSKZ "tax code

.

tab-erdat_raw = tab-erdat. "keep the MM/DD/YYYY format

CONCATENATE TAB-ERDAT6(4) TAB-ERDAT0(2) TAB-ERDAT+3(2)

INTO TAB-ERDAT.

tab-menge = tab-menge_as_string. "convert to numeric field

*set tab-msgnr to 1 for invalid usage indicator

*so that the error records will be included in the error log

if p_chk_ui = 'X'.

perform check_usage_indicator.

endif.

*Process only a particular set of usage indicator first

*{Gary Tang 02/10/2003 UATK922842 also include MSGNR=1 (invalid usage

*incicator records

if tab-usafl = p_usafl "this is the target usage indicator

or tab-msgnr = '1'. "this is 1 because of invalid usage ind.

*}Gary Tang 02/10/2003 UATK922842

  • add leading zero to numeric GL acct no.

  • e.g. data file: 230330 --> convert to: 0000230330

CALL FUNCTION 'Z_PURE_NUMERIC_ADD_LEADING_0'

EXPORTING

INPUT_FIELD = tab-saknr

TARGET_LEN = saknr_len

IMPORTING

OUTPUT_FIELD = tab-saknr

.

  • add leading zero to numeric cust num

  • e.g. data file: 3100001 --> convert to: 0003100001

  • e.g. data file: NEC-JP --> no conversion: NEC-JP

CALL FUNCTION 'Z_PURE_NUMERIC_ADD_LEADING_0'

EXPORTING

INPUT_FIELD = tab-kunnr

TARGET_LEN = kunnr_len

IMPORTING

OUTPUT_FIELD = tab-kunnr

.

APPEND TAB.

result_total = result_total + 1. "Increase the record counter

endif.

ENDLOOP.

write: / 'Processing records for usage indicator', p_usafl.

ENDFORM.

----


  • FORM CHECK_DATA *

----


FORM CHECK_DATA.

if p_nor = 'X'.

PERFORM GET_NEXT_RECNO.

endif.

LOOP AT TAB.

perform check_data_on_period."record date must in current period

perform check_data_on_zprdordhdr. "production order header

perform check_data_on_mara. "material master (general)

perform check_data_on_marc. "material master (plant)

perform check_data_on_t001k. "company code vs plant

perform check_data_on_mbew. "Material Valuation

perform check_usage_indicator. "usage indicator

perform check_sub_contract. "must have customer number

perform check_data_on_kna1. "customer number

perform check_data_on_skb1. "G/L account

perform check_menge. "quantity

  • perform check_expense. "for eXpenses

perform calculate_materail_loading.

  • perform gen_random_posting_sequence.

if p_nor = 'X'.

PERFORM INSERT_TABLE_ZBACKS_GIPD.

endif.

MODIFY TAB.

endloop.

if p_nor = 'X'.

  • print the last record number for reference

write: / 'ZBACKS_GIPD record number (RECNO) to :',

ZBACKS_GIPD-RECNO.

skip 1.

endif.

endform.

----


  • FOMR Gen_random_posting_sequence *

----


*form gen_random_posting_sequence.

*

  • tab-post_seq_ORIG = SY-TABIX.

*

  • if tab-msgnr = '1'. "no need to go further if already rejected

  • tab-post_seq_RAND = 0.

  • else.

*

  • CALL FUNCTION 'RANDOM_I4'

  • EXPORTING

  • RND_MIN = 1

  • RND_MAX = 50000

  • IMPORTING

  • RND_VALUE = tab-Post_seq_RAND

  • .

  • endif.

*

*

*endform.

----


  • FOMR CHECH_MENGE *

----


form check_MENGE.

if tab-menge > 0. "Issue qty > 0

tab-direction = 'I'. "Issue (i.e. decrease the inventory)

elseif tab-menge < 0. "Issue qty < 0

tab-direction = 'R'. "Reverse (i.e. increase the inventory

elseif tab-menge = 0. "Issue qty = 0 ==> Strange case, error!

TAB-MSGNR = '1'.

tab-msgtx = 'Qty is 0. Nothing to post!'.

endif.

endform.

----


  • FOMR CHECH_USAGE_INDICATOR *

----


form check_usage_indicator.

case tab-usafl.

when 'I'. "Inhouse production

when 'E'. "External procurement

when 'X'. "Expense

when 'T'. "transfer to sub-contractor

when 'S'. "sale to sub-contractor

when 'C'. "consign to sub-contractor

  • when '?'. "add new usage indicator here if needed!

when others. "illegal value! reject the record

TAB-MSGNR = '1'.

  • concatenate 'Invalid usage indicator'

  • into tab-msgtx separated by space.

tab-msgtx = 'Invalid usage indicator'.

endcase.

endform.

*form check_expense.

*

  • check not tab-msgnr = '1'. "no need to go further if already rejected*

*

  • check tab-usafl = 'X'. "only for expense

*

*

  • SELECT SINGLE ZEXPENSE~SAKNR

  • ZEXPENSE~KOSTL

  • into (TAB-SAKNR,

  • TAB-KOSTL)

  • FROM ZEXPENSE

  • WHERE ZEXPENSE~WERKS = TAB-WERKS

  • AND ZEXPENSE~EXPCD = TAB-EXPCD.

  • IF SY-SUBRC <> 0.

  • TAB-MSGNR = '1'.

  • TAB-MSGTX = 'Expense code not found (ZEXPENSE)'.

  • endif.

*

*endform.

----


  • FOMR CALCULATE_MATERIAL_LOADING *

----


form calculate_materail_loading.

check not tab-msgnr = '1'. "no need to go further if already rejected

*Material loading is calculated for all records

*Though posting only required for usage 'E'

  • check tab-usafl = 'E'. "only for External procurement need to post

select single ZSTDLOADING~LADRA "loading %

into ZSTDLOADING-LADRA "loading %

from ZSTDLOADING "standard loading info.

where WERKS = tab-werks "plant

and MATGP = tab-matkl+0(2) "customer code

  • and LADTY = tab-usafl. "usage code

and LADTY = 'P'. "material loading

if ( sy-subrc <> 0 ).

  • or ( zstdloading-LADRA is initial ). "DEVK909574

TAB-MSGNR = '1'.

TAB-MSGTX = 'Mat. loading % not found or = 0% (ZSTDLOADING)'.

else.

tab-ladra = zstdloading-ladra. "store the loading rate into table

*{Gary Tang 02/10/2003 "UATK922842

  • round the qty*stdcost to integer before multiplying the loading rate

tab-matloading "type is integer (result will be rounded off)

= tab-menge "qty

  • tab-unitstdcost. "std cost (of 1 EA)

  • * ZSTDLOADING-LADRA "material loading percentage (%)

  • / 100. "because material loading is in %

tab-matloading "type is integer (result will be rounded off)

= tab-matloading

  • ZSTDLOADING-LADRA "material loading percentage (%)

/ 100. "because material loading is in %

*}Gary Tang 02/10/2003 "UATK922842

endif.

endform.

----


  • FORM CHECK_DATA_ON_SKB1 *

----


form check_data_on_SKB1.

data: saknr_as_numeric(10) type n. "for leading zero

check not tab-msgnr = '1'. "no need to go further if already rejected

case tab-usafl.

when 'I' or 'E' or 'C'.

if not tab-saknr is initial.

TAB-MSGNR = '1'.

concatenate 'G/L Account no. should be blank for usage indicator'

tab-usafl into tab-msgtx separated by space.

else.

tab-saknr_for_posting = CONST_SAKNR_WIP_MAT.

endif.

when 'T' or 'S'.

if not tab-saknr is initial.

TAB-MSGNR = '1'.

concatenate 'G/L Account no. should be blank for usage indicator'

tab-usafl into tab-msgtx separated by space.

else.

tab-saknr_for_posting = CONST_SAKNR_WIP_MAT_SUB_CON.

endif.

when 'X'. "G/L acct is required for eXpense

if tab-saknr is initial.

TAB-MSGNR = '1'.

concatenate 'G/L Account no. is REQUIRED for usage indicator'

tab-usafl into tab-msgtx separated by space.

else.

CATCH SYSTEM-EXCEPTIONS CONVT_NO_NUMBER = 4.

SAKNR_AS_NUMERIC = TAB-SAKNR.

endcatch.

if sy-subrc = 4.

TAB-MSGNR = '1'.

TAB-MSGTX = 'Invild G/L acct no. (should be numeric)'.

endif.

select single skb1~saknr

into skb1-saknr

from skb1

where skb1~bukrs = tab-bukrs

and skb1~saknr = saknr_as_numeric. " tab-saknr.

if sy-subrc = 0.

tab-saknr_for_posting = saknr_as_numeric. " tab-saknr.

else.

TAB-MSGNR = '1'.

TAB-MSGTX = 'G/L Account no. not found (SKB1)'.

endif.

endif.

endcase.

endform.

----


  • FORM CHECK_DATA_ON_PREIOD *

----


form check_data_on_period.

check p_chk_pd = 'X'. "check period option is selected

check not tab-msgnr = '1'. "no need to go further if already rejected

if tab-erdat < g_period_start_date "record in past period, reject!

or tab-erdat > g_period_end_date. "record in future period, reject!

TAB-MSGNR = '1'.

TAB-MSGTX = 'Record date is not in open period.'.

endif.

endform.

----


  • FORM CHECK_DATA_ON_MBEW *

----


form check_data_on_mbew.

data: local_stprs like mbew-stprs. "std price

data: local_peinh like mbew-peinh. "price unit

check not tab-msgnr = '1'. "no need to go further if already rejected

*Standard cost is checked for all records

*Though calculation is only required for usage 'E'

  • check tab-usafl = 'E' "for External procurement

  • or tab-usafl = 'T' "for Transfer to sub-contractor

  • or tab-usafl = 'S'."for Sale to sub-contractor

select single stprs "std price

peinh "price unit

into (local_stprs, "std price

local_peinh) "price unit

from mbew "material valuation

where matnr = tab-matnr "material

and bwkey = tab-werks. "plant

if ( sy-subrc <> 0 ) "record not round

or ( local_stprs = 0 ). "std cost = 0 (should not happen)

TAB-MSGNR = '1'.

TAB-MSGTX = 'Standard cost not found or = 0 (MBEW)'.

else. "calculate the cost of 1 EA

tab-unitstdcost = local_stprs / local_peinh * 100.

endif.

endform.

----


  • FORM CHECK_DATA_ON_ZPRDORDHDR *

----


form check_data_on_zprdordhdr.

check not tab-msgnr = '1'. "no need to go further if already rejected

  • Production order is not required for usage indicator 'T' or 'S'

  • Even the number is provided, it may or may not exist in ZPRDORDHDR

  • Therefore, all checking on production order can be skipped for T & S

  • (11/11/2002, confirmation from Stephen Chung, Miura-san, Sato-san)

check tab-usafl <> 'T' "Transfer to sub-contract

and tab-usafl <> 'S' "Sales to sub-contract

  • Confirmed by Miura-san on 11/30/2002

  • Production order no. is also not required for 'X' (Expense)

and tab-usafl <> 'X'. "Expenses

if tab-aufnr is initial.

TAB-MSGNR = '1'.

TAB-MSGTX = 'Production order number is missing'.

exit.

endif.

select single zprdordhdr~aufnr

into zprdordhdr-aufnr

from zprdordhdr

where zprdordhdr~werks = tab-werks

and zprdordhdr~aufnr = tab-aufnr.

if sy-subrc <> 0.

TAB-MSGNR = '1'.

TAB-MSGTX = 'Production order number not found (ZPRDORDHDR)'.

else.

select max( zprdordhdr~runum )

into tab-runum

from zprdordhdr

where zprdordhdr~werks = tab-werks

and zprdordhdr~aufnr = tab-aufnr.

  • if tab-runum is initial.

  • TAB-MSGNR = '1'.

  • TAB-MSGTX = 'Production order number not found (ZPRDORDHDR)'.

  • else.

select single

stats "production order status

SUBPR "Sub-contracting Production Order

into (zprdordhdr-stats,

tab-hdr_SUBPR) "save into internal table TAB directly!

from zprdordhdr

where zprdordhdr~werks = tab-werks

and zprdordhdr~aufnr = tab-aufnr

and zprdordhdr~runum = tab-runum.

if ( zprdordhdr-stats <> 'O' )

and ( zprdordhdr-stats <> 'C' ).

TAB-MSGNR = '1'.

concatenate 'No tx is allowed, production order in status'

zprdordhdr-stats into tab-msgtx separated by space.

endif.

  • endif.

endif.

endform.

----


  • FORM CHECK_DATA_ON_MARA *

----


form check_data_on_mara.

check not tab-msgnr = '1'. "no need to go further if already rejected

  • get cost center that is from profit center in MARC

SELECT SINGLE MARA~MATKL "material group

into MARA-MATKL "material group

FROM MARA "Material master

WHERE MATNR = TAB-MATNR. "material

IF SY-SUBRC = 0.

TAB-MATKL = MARA-MATKL. "material group

ELSE.

TAB-MSGNR = '1'.

TAB-MSGTX = 'Material not found (mat.gp./cust code missing) (MARA)'.

ENDIF.

ENDFORM.

----


  • FORM CHECK_DATA_ON_MARC *

----


form check_data_on_marc.

check not tab-msgnr = '1'. "no need to go further if already rejected

  • get cost center that is from profit center in MARC

SELECT SINGLE PRCTR

into MARC-PRCTR

FROM MARC "Plant Data for Material

WHERE MATNR = TAB-MATNR "material

AND WERKS = TAB-WERKS. "plant

IF SY-SUBRC EQ 0.

TAB-PRCTR = MARC-PRCTR. "profit center

ELSE.

TAB-MSGNR = '1'.

TAB-MSGTX =

'Mat. not found in plant. (Profit center missing) (MARC)'.

ENDIF.

ENDFORM.

----


  • FORM CHECK_DATA_ON_KNA1 *

----


form check_data_on_kna1. "customer number

  • data: kunnr_as_numeric(10) type n.

  • data: kunnr_as_string(10).

check not tab-msgnr = '1'. "no need to go further if already rejected

check not tab-kunnr is initial.

  • IF NOT TAB-KUNNR CA 'ABCDEFGHIJKLMNOPQRSTUVWXYZ.,-_#'.

  • kunnr_as_numeric = tab-kunnr.

  • kunnr_as_string = kunnr_as_numeric.

  • else.

  • kunnr_as_string = tab-kunnr.

  • ENDIF.

select single kna1~kunnr

into kna1-kunnr

from kna1

  • where kunnr = kunnr_as_string. " tab-kunnr.

where kunnr = tab-kunnr. "customer no. (w/ leading zero if numeric)

if sy-subrc <> 0.

TAB-MSGNR = '1'.

concatenate 'Customer number' tab-kunnr 'not found (KNA1)'

into tab-msgtx separated by space.

ENDIF.

endform.

----


  • FORM CHECK_Sub_contract *

----


form check_sub_contract.

check not tab-msgnr = '1'. "no need to go further if already rejected

if tab-kunnr is initial.

if ( tab-usafl = 'T' )

or ( tab-usafl = 'S' ).

TAB-MSGNR = '1'.

concatenate 'Cust number should not be blank for usage indicator'

tab-usafl into tab-msgtx separated by space.

endif.

else.

if ( tab-usafl <> 'T' )

and ( tab-usafl <> 'S' ).

TAB-MSGNR = '1'.

concatenate 'Cust. number should be blank for usage indicator'

tab-usafl into tab-msgtx separated by space.

endif.

endif.

endform.

----


  • FORM CHECK_DATA_ON_t001k *

----


form check_data_on_t001k.

check not tab-msgnr = '1'. "no need to go further if already rejected

select single * from t001k "Valuation area

where bwkey = tab-werks. "plant

if sy-subrc = 0.

tab-bukrs = t001k-bukrs. "company code

else.

TAB-MSGNR = '1'.

concatenate 'Company code not found for plant'

tab-werks '(T001K)'

into tab-msgtx separated by space.

endif.

endform.

----


  • FORM POST_GOODS_ISSUE *

----


form post_goods_issue.

perform UPDATE_GI_FOR_COST_CTR.

  • clear FI_DOC_TEXT.

  • FI_DOC_TEXT+0(35) = tab-idnum.

  • write: tab-menge to FI_DOC_TEXT+35(15) right-justified.

  • write: / '**', tab-matdoc, '**'.

endform.

----


  • FORM MAIN_UPDATE *

----


FORM MAIN_UPDATE.

data: current_lock_matnr like mara-matnr.

*>>1104

  • sort tab by post_seq_RAND ascending.

*>>1104

  • Direction: I=Issue, R=Reverse

  • Do reverse first since it will increase invenotry

sort tab by direction descending "R first, then I

werks ascending

matnr ascending. "Sort by plant and then material

if p_nor = 'X'. "new posting first step

  • read the first record into the last flag to avoid problem when

  • processing the 1st record

loop at tab where msgnr <> '1'. "skip the rejected records

last_matnr = tab-matnr.

last_direction = tab-direction.

last_werks = tab-werks.

exit.

endloop.

loop at tab where msgnr <> '1'. "skip the rejected records

if ( tab-werks <> last_werks )

or ( tab-matnr <> last_matnr )

or ( tab-direction <> last_direction )

  • check if the no. of material i.e.items reach the limit "DE1K901698

or ( l_matnr_counter >= c_max_mat_doc_items ). "DE1K901698

  • if sy-tabix <> '1'. "not needed! "DE1K901698

  • sleep for 5 seconds before different plant and Issues/Reversal tx

if ( tab-werks <> last_werks )

or ( tab-direction <> last_direction )

  • or ( tab-matnr = last_matnr ). "DE1K901698

or ( tab_by_matnr-matnr = current_lock_matnr ). "DE1K901698

  • write: / tab-matnr, last_matnr.

write: / tab-recno.

perform sleep_5_seconds.

endif.

  • describe table tab_by_matnr lines sy-tfill.

  • write: / tab_by_matnr-werks, tab_by_matnr-matnr, sy-tfill.

perform post_goods_issue.

current_lock_matnr = tab_by_matnr-matnr.

clear l_matnr_counter.

last_werks = tab-werks.

last_matnr = tab-matnr.

last_direction = tab-direction.

refresh tab_by_matnr.

endif.

clear tab_by_matnr. "DE1K901698 record for the same material

tab_by_matnr = tab. "DE1K901698 put into a temp table

append tab_by_matnr. "DE1K901698 will be posted to 1 mat doc

l_matnr_counter = l_matnr_counter + 1. "DE1K901698 count the mat.

  • clear tab_by_matnr. "DE1K901698 moved to the start of the loop

  • tab_by_matnr = tab. "DE1K901698 moved to the start of the loop

  • append tab_by_matnr. "DE1K901698 moved to the start of the loop

endloop.

  • check if the temp item table still contains record

describe table tab_by_matnr lines sy-tfill.

  • sleep for 5 seconds before different plant and Issues/Reversal tx

if sy-tfill > 0. "still need to post the last batch

write: / 'last'.

perform sleep_5_seconds.

  • Post goods issues for the last batch of records (after ENDLOOP)

perform post_goods_issue.

endif.

endif. "new posting step 1 done

  • perform UPDATE_GI_FOR_COST_CTR.

  • clear FI_DOC_TEXT.

  • FI_DOC_TEXT+0(35) = tab-idnum.

  • write: tab-menge to FI_DOC_TEXT+35(15) right-justified.

  • loop at TAB where msgnr <> '1'. "skip the rejected records

  • msgnr = 2 ==> ready for step 2. (Mat doc. already posted)

loop at TAB where msgnr = '2'. "skip the rejected records

*>>1104

  • if tab-matnr = last_matnr.

*

  • write: / 'Sleep 1 sec', tab-matnr, tab-post_seq_rand.

  • CALL FUNCTION 'RZL_SLEEP'

  • EXPORTING

  • SECONDS = 1

  • EXCEPTIONS

  • ARGUMENT_ERROR = 1

  • OTHERS = 2.

*

  • IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

  • ENDIF.

  • *

    • else.

    • last_matnr = tab-matnr.

    • endif.

    *****>>1104

    • perform UPDATE_GI_FOR_COST_CTR.

    • clear FI_DOC_TEXT.

    • FI_DOC_TEXT+0(35) = tab-idnum.

    • write: tab-menge to FI_DOC_TEXT+35(15) right-justified.

    *>>1104

    • post JV for different usage indicator

    if ( tab-usafl = 'E' "external procurement

    and tab-hdr_SUBPR = space ) "not sub-contract "UATK922842

    or tab-usafl = 'C'. "consignment "UATK922842

    if tab-msgnr = '2'. "ready for step 2

    "mat. loading amount = 0, no need to create doc

    if tab-matloading = 0.

    TAB-MSGNR = '0'.

    CONCATENATE tab-msgtx ', JV (Mat.Load.) Not needed (0)'

    INTO TAB-MSGTX separated by space.

    MODIFY TAB TRANSPORTING MSGNR MSGTX.

    result_ok = result_ok + 1.

    "Increase record counter (Successful)

    perform update_zbacks_gipd

    using tab-werks

    tab-aufnr

    tab-matnr

    tab-erdat

    tab-recno

    tab-msgnr

    space "parameter not needed for mat doc

    • msgtab-msgv1. "FI DOC for material loading

    'N/A'. "FI DOC N/A

    else. "post a JV for material loading

    perform UPDATE_MATERIAL_LOADING_JV.

    endif.

    endif.

    endif.

    if ( tab-usafl = 'T' ) "transfer to subcon

    or ( tab-usafl = 'S' ). "sales to subcon

    if tab-msgnr = '2'. "ready for step 2

    perform update_sub_contractor.

    endif.

    endif.

    *no JV posting is needed for inhouse production

    • if tab-usafl = 'I'. "inhouse production

    • if tab-msgnr = '0'.

    • perform update_???

    • endif.

    • endif.

    *no JV posting is needed for expenses

    • if tab-usafl = 'X'. "expenses

    • if tab-msgnr = '0'.

    • perform update_???

    • endif.

    • endif.

    *no JV posting is needed for consign to sub-contractor

    • if ( tab-usafl = 'C' ). "consign to subcon

    • if tab-msgnr = '0'.

    • perform update_???.

    • endif.

    • endif.

    endloop.

    ENDFORM.

    ----


    • FORM UPDATE_SUB_CONTRACTOR *

    ----


    form update_sub_contractor.

    perform sub_con_fb70_prepare.

    perform sub_con_fb70_fillscreen.

    perform sub_con_fb70_calltx.

    endform.

    ----


    • FORM SUB_CON_FB70_PREPARE *

    ----


    form sub_con_fb70_prepare.

    clear ar_amt_vendor. "material amount (std price * qty)

    clear ar_amt_penalty. "penalty amount

    clear ar_amt_total. "total amount (with tax)

    clear ar_amt_tax. "tax amount

    ar_amt_vendor

    = tab-menge "qty

    • tab-unitstdcost. "std cost (of 1 EA)

    if tab-usafl = 'T'. "Transfer to sub-contractor

    ar_amt_penalty "Add the amount for penalty

    = ar_amt_vendor

    • CONST_PENALTY_RATE.

    endif.

    *>>1104

    • ar_amt_tax = ( ar_amt_vendor + ar_amt_penalty ) * CONST_TAX_RATE.

    ar_amt_tax = tab-cotax.

    *>>1104

    ar_amt_total "Total amonut (with tax)

    = ar_amt_vendor

    + ar_amt_penalty

    + ar_amt_tax.

    • * ( '1.0' + CONST_TAX_RATE ).

    ar_amt_total_as_text = abs( ar_amt_total ).

    ar_amt_vendor_as_text = abs( ar_amt_vendor ).

    ar_amt_penalty_as_text = abs( ar_amt_penalty ).

    ar_amt_tax_as_text = abs( ar_amt_tax ).

    endform.

    ----


    • FORM SUB_CON_FB70_FILLSCREEN *

    ----


    form sub_con_fb70_fillscreen.

    • DATA: FI_DOC_TEXT(50).

    • clear FI_DOC_TEXT.

    • FI_DOC_TEXT+0(35) = tab-idnum.

    • write: tab-menge to FI_DOC_TEXT+35(15) right-justified.

    clear MATDOC_AND_ITEM.

    concatenate TAB-MATDOC '-' TAB-MATDOCITEM into MATDOC_AND_ITEM.

    condense MATDOC_AND_ITEM.

    clear FI_DOC_TEXT.

    FI_DOC_TEXT+0(35) = tab-idnum.

    write: tab-menge to FI_DOC_TEXT+35(15) right-justified.

    refresh bdcdata.

    PERFORM BDC_DYNPRO USING 'SAPMF05A' '1200'.

    • PERFORM BDC_FIELD USING 'BDC_OKCODE' '=DUMM'.

    PERFORM BDC_FIELD USING 'BDC_OKCODE' '=MORE'. "goto Details tab

    IF TAB-MENGE > 0.

    PERFORM BDC_FIELD USING 'RF05A-BUSCS' 'R'. "Invoice

    ELSE.

    PERFORM BDC_FIELD USING 'RF05A-BUSCS' 'G'. "Credit memo

    ENDIF.

    • PERFORM BDC_FIELD USING 'BDC_CURSOR' 'ACGL_ITEM-HKONT(01)'.

    PERFORM BDC_FIELD USING 'INVFO-ACCNT' TAB-KUNNR. "customer number

    PERFORM BDC_FIELD USING 'INVFO-BLDAT' TAB-ERDAT_RAW. "invoice date

    PERFORM BDC_FIELD USING 'INVFO-BUDAT' TAB-ERDAT_RAW. "posting date

    PERFORM BDC_FIELD USING 'INVFO-XBLNR' MATDOC_AND_ITEM. "Material Doc.

    PERFORM BDC_FIELD USING 'INVFO-SGTXT' FI_DOC_TEXT. "tab-idnum.

    "BACKS ID No.

    PERFORM BDC_FIELD USING 'INVFO-WAERS' 'JPY'. "Currency

    PERFORM BDC_FIELD USING 'INVFO-WRBTR' ar_amt_total_as_text. "Amount

    PERFORM BDC_FIELD USING 'INVFO-MWSKZ' TAB-MWSKZ. "tax code

    PERFORM BDC_FIELD USING 'INVFO-WMWST' ar_amt_tax_as_text. "Tax amount

    • PERFORM BDC_FIELD USING 'INVFO-XMWST' 'X'. "auto cal. tax

    • CLEAR AUFNR.

    • CONCATENATE TAB-AUFNR '-' TAB-RUNUM INTO AUFNR.

    • PERFORM BDC_FIELD USING 'INVFO-SGTXT' AUFNR. "PO no.

    PERFORM BDC_DYNPRO USING 'SAPMF05A' '1200'.

    PERFORM BDC_FIELD USING 'BDC_OKCODE' '/00'.

    PERFORM BDC_FIELD USING 'INVFO-BKTXT' tab-aufnr. "Productioin order

    PERFORM BDC_FIELD USING 'INVFO-ZUONR' TAB-MATNR. "material no.

    PERFORM BDC_FIELD USING 'ACGL_ITEM-HKONT(01)'

    CONST_SAKNR_WIP_MAT_SUB_CON.

    PERFORM BDC_FIELD USING 'ACGL_ITEM-WRBTR(01)' ar_amt_vendor_as_text.

    PERFORM BDC_FIELD USING 'ACGL_ITEM-KOSTL(01)' TAB-PRCTR.

    PERFORM BDC_FIELD USING 'ACGL_ITEM-SGTXT(01)' FI_DOC_TEXT."TAB-IDNUM.

    PERFORM BDC_FIELD USING 'ACGL_ITEM-ZUONR(01)' TAB-MATNR.

    PERFORM BDC_FIELD USING 'ACGL_ITEM-MWSKZ(01)' TAB-MWSKZ. "Tax code

    if tab-usafl = 'T'. "Transfer: add the penalty!

    PERFORM BDC_FIELD USING 'ACGL_ITEM-HKONT(02)' "other income

    CONST_SAKNR_OTHER_INCOME.

    PERFORM BDC_FIELD USING 'ACGL_ITEM-WRBTR(02)'

    ar_amt_penalty_as_text.

    PERFORM BDC_FIELD USING 'ACGL_ITEM-KOSTL(02)' TAB-PRCTR.

    PERFORM BDC_FIELD USING 'ACGL_ITEM-SGTXT(02)' FI_DOC_TEXT.

    "TAB-IDNUM.

    PERFORM BDC_FIELD USING 'ACGL_ITEM-ZUONR(02)' TAB-MATNR.

    endif.

    • PERFORM BDC_DYNPRO USING 'SAPMF05A' '1200'.

    • PERFORM BDC_FIELD USING 'BDC_OKCODE' '=TEXT'.

    *

    • PERFORM BDC_DYNPRO USING 'SAPLFTXT' '0100'.

    • PERFORM BDC_FIELD USING 'BDC_CURSOR' 'RTEXT-SPRAS(01)'.

    • PERFORM BDC_FIELD USING 'BDC_OKCODE' '=TEDE'.

    • PERFORM BDC_FIELD USING 'RTEXT-SPRAS(01)' 'JA'.

    *

    • PERFORM BDC_DYNPRO USING 'SAPLSTXX' '1100'.

    • PERFORM BDC_FIELD USING 'BDC_CURSOR' 'RSTXT-TXLINE(02)'.

    • PERFORM BDC_FIELD USING 'BDC_OKCODE' '=EDNL'.

    • CLEAR TEXT.

    • CONCATENATE ' QUANTITY : ' TAB-MENGE INTO TEXT.

    • PERFORM BDC_FIELD USING 'RSTXT-TXLINE(02)' TEXT.

    • PERFORM BDC_DYNPRO USING 'SAPLSTXX' '1100'.

    • PERFORM BDC_FIELD USING 'BDC_OKCODE' '=TXBA'.

    • PERFORM BDC_DYNPRO USING 'SAPLFTXT' '0100'.

    • PERFORM BDC_FIELD USING 'BDC_OKCODE' '=BACK'.

    • PERFORM BDC_DYNPRO USING 'SAPMF05A' '1200'.

    • PERFORM BDC_FIELD USING 'BDC_OKCODE' '=MORE'.

    • PERFORM BDC_DYNPRO USING 'SAPMF05A' '1200'.

    • PERFORM BDC_FIELD USING 'BDC_OKCODE' '/00'.

    • PERFORM BDC_FIELD USING 'INVFO-BKTXT' TAB-VBELN.

    PERFORM BDC_DYNPRO USING 'SAPMF05A' '1200'.

    PERFORM BDC_FIELD USING 'BDC_OKCODE' '=BU'.

    endform.

    ----


    • FORM SUB_CON_FB70_CALLTX *

    ----


    form sub_con_fb70_calltx.

    refresh msgtab.

    if ar_amt_total = 0. "Amount = 0, no need to post AR

    TAB-MSGNR = '0'.

    CONCATENATE TAB-MSGTX

    ', AR invoice not needed (Amount=0)'

    INTO TAB-MSGTX separated by space.

    result_ok = result_ok + 1.

    else. "Amount <> 0, post AR

    call transaction 'FB70'

    using bdcdata

    update 'S'

    mode fb70mode

    messages into msgtab.

    if sy-subrc <> 0.

    • TAB-MSGNR = '3'. "no need to change, this is remain in 2

    read table msgtab with key MSGTYP = 'E'.

    if sy-subrc = 0.

    select single t100~text

    into t100-text

    from t100

    where t100~sprsl = sy-langu

    and arbgb = msgtab-msgid

    and msgnr = msgtab-msgnr.

    if sy-subrc = 0.

    CONCATENATE TAB-MSGTX ', AR invoice error:' t100-text

    INTO TAB-MSGTX separated by space.

    else.

    CONCATENATE TAB-MSGTX

    ', AR invoice error:' '(error message not found)'

    INTO TAB-MSGTX separated by space.

    endif.

    endif.

    • result_err = result_err + 1.

    else.

    read table msgtab with key msgid = 'F5' msgnr = '312'.

    if sy-subrc = 0.

    TAB-MSGNR = '0'.

    CONCATENATE TAB-MSGTX

    ', AR invoice posted:' msgtab-msgv1

    INTO TAB-MSGTX separated by space.

    result_ok = result_ok + 1.

    perform update_zbacks_gipd

    using tab-werks

    tab-aufnr

    tab-matnr

    tab-erdat

    tab-recno

    tab-msgnr

    space "parameter not needed for mat doc

    MSGTAB-MSGV1. "Customer invoice

    else.

    TAB-MSGNR = '0'.

    CONCATENATE TAB-MSGTX

    'AR invoice problem:' '(Cannot display invoice no.)'

    INTO TAB-MSGTX separated by space.

    • result_err = result_err + 1.

    endif.

    endif.

    endif.

    MODIFY TAB TRANSPORTING MSGNR MSGTX.

    endform.

    ----


    • FORM UPDATE_GI_FOR_COST_CTR *

    ----


    form UPDATE_GI_FOR_COST_CTR.

    REFRESH: GOODSMVT_HEADER, GOODSMVT_CODE, GOODSMVT_ITEM, REMSG.

    CLEAR: GOODSMVT_HEADER, GOODSMVT_CODE, GOODSMVT_ITEM, REMSG.

    CLEAR: ERR, TAB-MATDOC, DOCYEAR.

    PERFORM MAINTAIN_GOODSMVT_HEADER.

    PERFORM MAINTAIN_GOODSMVT_CODE.

    PERFORM MAINTAIN_GOODSMVT_ITEM.

    CALL FUNCTION 'BAPI_GOODSMVT_CREATE'

    EXPORTING

    GOODSMVT_HEADER = GOODSMVT_HEADER

    GOODSMVT_CODE = GOODSMVT_CODE

    • TESTRUN = ' '

    IMPORTING

    • GOODSMVT_HEADRET =

    MATERIALDOCUMENT = TAB-MATDOC

    MATDOCUMENTYEAR = DOCYEAR

    TABLES

    GOODSMVT_ITEM = GOODSMVT_ITEM

    • GOODSMVT_SERIALNUMBER =

    RETURN = REMSG

    .

    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

    • EXPORTING

    • WAIT =

    • IMPORTING

    • RETURN =

    .

    *>>>

    commit work.

    *>>>

    IF REMSG-TYPE = 'E'.

    ERR = 'X'.

    CONCATENATE REMSG-NUMBER REMSG-MESSAGE INTO

    ERRTX-MSGTX SEPARATED BY SPACE.

    ENDIF.

    LOOP AT REMSG.

    IF REMSG-TYPE = 'E'.

    ERR = 'X'.

    CONCATENATE REMSG-NUMBER REMSG-MESSAGE

    INTO ERRTX-MSGTX SEPARATED BY SPACE.

    APPEND ERRTX.

    ENDIF.

    ENDLOOP.

    • ENDIF.

    IF ERR EQ 'X'.

    TAB-MSGNR = '1'.

    • TAB-MSGTX = 'Update failed for Goods Issue'.

    concatenate 'Update failed for Goods Issue:'

    errtx-msgtx(68) into tab-msgtx

    separated by space.

    loop at tab_by_matnr.

    TAB-STOCKQTY = TAB_BY_MATNR-STOCKQTY. "DEVK914235

    TAB-ISSUESTPRS = TAB_BY_MATNR-ISSUESTPRS. "DEVK914235

    MODIFY TAB TRANSPORTING MSGNR MSGTX MATDOC

    STOCKQTY "DEVK914235

    ISSUESTPRS "DEVK914235

    WHERE " MSGNR EQ ' '

    WERKS = TAB_BY_MATNR-werks

    and matnr = tab_by_matnr-matnr

    and recno = tab_by_matnr-recno.

    perform update_zbacks_gipd

    using tab_by_matnr-werks

    tab_by_matnr-aufnr

    tab_by_matnr-matnr

    tab_by_matnr-erdat

    tab_by_matnr-recno

    TAB-MSGNR "must be '1' failed

    space "no mat doc since posting failed

    space. "parameter not needed for FI doc

    endloop.

    • result_err = result_err + 1.

    ELSEIF ERR EQ ' '.

    • TAB-MSGNR = '0'.

    CONCATENATE 'Mat. doc.:' TAB-MATDOC

    INTO TAB-MSGTX.

    loop at tab_by_matnr.

    TAB-MATDOCITEM = SY-TABIX.

    if tab-usafl = 'I' "Inhouse production

    or tab-usafl = 'X' "Expenses

    *{Gary Tang 02/10/2003 "UATK922842

    • Usage ind. 'C' should be 2 tx in fact, mat loading is REQUIRED

    • or tab-usafl = 'C'. "Consignment "UATK922842

    • Usage ind. 'E' and ZPRDORDHDR-SUBPR = 'X', mat loading NOT required

    or ( tab-usafl = 'E' and tab_by_matnr-hdr_SUBPR = 'X' ).

    *}Gary Tang 02/10/2003 "UATK922842

    *Only 1 tx (MvT 201/202) is needed for the above usage ind.

    *Therefore, update the no. of OK record now

    result_ok = result_ok + 1.

    TAB-MSGNR = '0'. "all work is done!

    else.

    TAB-MSGNR = '2'. "first step (mvt 201/202) is done, but

    "next step (mat loading JV or cust AR is needed

    endif.

    TAB-STOCKQTY = TAB_BY_MATNR-STOCKQTY. "DEVK914235

    TAB-ISSUESTPRS = TAB_BY_MATNR-ISSUESTPRS. "DEVK914235

    MODIFY TAB TRANSPORTING MSGNR MSGTX MATDOC MATDOCITEM

    STOCKQTY "DEVK914235

    ISSUESTPRS "DEVK914235

    WHERE " MSGNR EQ ' '

    WERKS = TAB_BY_MATNR-werks

    and matnr = tab_by_matnr-matnr

    and recno = tab_by_matnr-recno.

    perform update_zbacks_gipd

    using tab_by_matnr-werks

    tab_by_matnr-aufnr

    tab_by_matnr-matnr

    tab_by_matnr-erdat

    tab_by_matnr-recno

    TAB-MSGNR "0 (all done) or 2 (first step done)

    tab-matdoc

    space. "parameter not needed for FI doc

    endloop.

    **>> MODIFY TAB TRANSPORTING MSGNR MSGTX.

    • WHERE MSGNR EQ ' '.

    ENDIF.

    endform.

    ----


    • UPDATE MATERIALLOADING_JV *

    ----


    form UPDATE_MATERIAL_LOADING_JV.

    • perform prepare_jv_DOCUMENTHEADER.

    • perform prepare_jv_ACCOUNTGL.

    • perform prepare_jv_currencyamount.

    • perform perpare_jv_return.

    • perform call_bapi_jv.

    perform FB50_FILL_SCREEN.

    CALL TRANSACTION 'FB50'

    USING BDCDATA

    MODE fb50mode

    MESSAGES INTO Msgtab.

    read table msgtab with key

    MSGTYP = 'S'

    MSGID = 'F5'

    MSGNR = '312'.

    if sy-subrc = 0.

    TAB-MSGNR = '0'.

    CONCATENATE tab-msgtx ', JV (Mat.Load.) Posted:' msgtab-msgv1

    INTO TAB-MSGTX separated by space.

    MODIFY TAB TRANSPORTING MSGNR MSGTX.

    result_ok = result_ok + 1. "Increase record counter (Successful)

    perform update_zbacks_gipd

    using tab-werks

    tab-aufnr

    tab-matnr

    tab-erdat

    tab-recno

    tab-msgnr

    space "parameter not needed for mat doc

    msgtab-msgv1. "FI DOC for material loading

    else.

    • TAB-MSGNR = '3'. "no need to change, it is remain in 2

    concatenate tab-msgtx 'JV (Mat.Load.) failed:'

    into tab-msgtx separated by space.

    loop at msgtab where MSGTYP = 'E'.

    concatenate tab-msgtx msgtab-msgid msgtab-msgnr

    into tab-msgtx separated by space.

    MODIFY TAB TRANSPORTING MSGNR MSGTX.

    endloop.

    endif.

    endform.

    ----


    • FORM FB50_FILL_SCREEN *

    ----


    FORM FB50_FILL_SCREEN.

    DATA: MATLOADINg_AS_STRING(12).

    CLEAR: BDCDATA, MSGTAB.

    REFRESH: BDCDATA, MSGTAB.

    clear MATDOC_AND_ITEM.

    concatenate TAB-MATDOC '-' TAB-MATDOCITEM into MATDOC_AND_ITEM.

    condense MATDOC_AND_ITEM.

    matloading_as_string = abs( tab-matloading ).

    clear FI_DOC_TEXT.

    FI_DOC_TEXT+0(35) = tab-idnum.

    write: tab-menge to FI_DOC_TEXT+35(15) right-justified.

    PERFORM BDC_DYNPRO USING 'SAPMF05A' '1001'.

    PERFORM BDC_FIELD USING 'BDC_OKCODE' '/00'.

    PERFORM BDC_FIELD USING 'ACGL_HEAD-BLDAT' tab-erdat_raw.

    PERFORM BDC_FIELD USING 'ACGL_HEAD-BUDAT' tab-erdat_raw.

    PERFORM BDC_FIELD USING 'ACGL_HEAD-WAERS' 'JPY'.

    PERFORM BDC_FIELD USING 'ACGL_HEAD-BKTXT' tab-aufnr.

    PERFORM BDC_FIELD USING 'ACGL_HEAD-XBLNR' MATDOC_AND_ITEM.

    PERFORM BDC_DYNPRO USING 'SAPMF05A' '1001'.

    PERFORM BDC_FIELD USING 'BDC_OKCODE' '=BU'.

    • 1st item

    PERFORM BDC_FIELD USING 'ACGL_ITEM-HKONT(01)'

    CONST_SAKNR_WIP_LABOUR_OH.

    If tab-matloading > 0.

    PERFORM BDC_FIELD USING 'ACGL_ITEM-SHKZG(01)' 'S'.

    else.

    PERFORM BDC_FIELD USING 'ACGL_ITEM-SHKZG(01)' 'H'.

    endif.

    PERFORM BDC_FIELD USING 'ACGL_ITEM-WRBTR(01)'

    matloading_as_string.

    PERFORM BDC_FIELD USING 'ACGL_ITEM-KOSTL(01)' TAB-prctr.

    PERFORM BDC_FIELD USING 'ACGL_ITEM-MARKSP(01)' 'X'.

    PERFORM BDC_FIELD USING 'ACGL_ITEM-SGTXT(01)' FI_DOC_TEXT.

    PERFORM BDC_FIELD USING 'ACGL_ITEM-ZUONR(01)' TAB-MATNR.

    • 2nd item

    PERFORM BDC_FIELD USING 'ACGL_ITEM-HKONT(02)' "Mat. loading

    CONST_SAKNR_WIP_MAT_LOAD.

    If tab-matloading > 0.

    PERFORM BDC_FIELD USING 'ACGL_ITEM-SHKZG(02)' 'H'.

    else.

    PERFORM BDC_FIELD USING 'ACGL_ITEM-SHKZG(02)' 'S'.

    endif.

    PERFORM BDC_FIELD USING 'ACGL_ITEM-WRBTR(02)'

    matloading_as_string.

    PERFORM BDC_FIELD USING 'ACGL_ITEM-KOSTL(02)' TAB-prctr.

    PERFORM BDC_FIELD USING 'ACGL_ITEM-MARKSP(02)' 'X'.

    PERFORM BDC_FIELD USING 'ACGL_ITEM-SGTXT(02)' FI_DOC_TEXT.

    PERFORM BDC_FIELD USING 'ACGL_ITEM-ZUONR(02)' TAB-MATNR.

    PERFORM BDC_DYNPRO USING 'SAPMF05A' '1001'.

    PERFORM BDC_FIELD USING 'BDC_OKCODE' '=BU'.

    endform.

    Add comment
    10|10000 characters needed characters exceeded

    • Follow
    • Get RSS Feed

    1 Answer

    • author's profile photo
      Former Member
      Posted on Sep 28, 2007 at 10:31 AM

      Yes I had solved this

      Add comment
      10|10000 characters needed characters exceeded