我这里有脚本,用于分割文件。例如,总lds_trandetail.rowcount()是56,我必须在3个文件中切碎56个,最多满20行,最后一个文件将处理剩余的16个行。我能够生成第一个文件20个行很好。但我无法弄清楚如何获得剩余的行。有人请帮忙...
The expected output should be:
20 Full Rows in a File = Header as First Row(1) + Detail(18) + Footer as Last Row(1)
1st File : 18 rows (lds_trandetail rows from 1 to 18)
2nd File : 18 rows (lds_trandetail rows from 19 to 36)
3rd File : 18 rows (lds_trandetail rows from 37 to 54)
4th File : 2 (lds_trandetail rows from 55 to 56)
//Variable Desclarations Here.....
IF NOT ISVALID (lds_TranHeader) THEN
lds_TranHeader = CREATE DataStore
lds_TranHeader.DataObject = 'd_export_inventoryheader'
lds_TranHeader.SetTransObject(SQLCA)
END IF
IF NOT ISVALID (lds_TranDetail) THEN
lds_TranDetail = CREATE DataStore
lds_TranDetail.DataObject = 'd_export_inventorydetail'
lds_TranDetail.SetTransObject(SQLCA)
END IF
lds_TranHeader.Retrieve( )
lds_TranDetail.Retrieve( )
ll_detailrow = lds_TranDetail.RowCount()
IF lds_TranDetail.RowCount( ) > 0 THEN
//Initialize the total rowcount of inventory.
li_fileint = (ll_detailrow/18)
ldec_filecount = Dec(ll_detailrow/18)
ls_remainder = String(ldec_filecount,'####.000')
li_pos = POS(ls_remainder,'.')
ls_remainder = Mid(ls_remainder, li_pos)
ldec_remainder = Dec(ls_remainder)
IF ldec_remainder > 0 THEN
li_fileint = li_fileint + 1
ELSEIF ldec_remainder < 0 THEN
li_fileint = (ll_detailrow/18)
END IF
ls_seqnum = gf_control_num('EDI_HW4C1FOOTER',10)
//Perform Iteration to the inventory rowcount.
FOR ll_detail = 1 TO lds_TranDetail.RowCount()
IF lds_TranHeader.RowCount() = 1 THEN
ls_recordidh = lds_TranHeader.getItemString(1,'RECORDIDH')
ls_schcontactname = lds_TranHeader.getItemString(1,'SCHCONTACTNAME')
ls_schcontactemail = lds_TranHeader.getItemString(1,'schcontactemail')
ls_schcontactphone = lds_TranHeader.getItemString(1,'schcontactphone')
ls_schdunsnum = lds_TranHeader.getItemString(1,'schdunsnum')
ldt_createddt = lds_TranHeader.getItemDateTime(1,'createddt')
ls_hwdnunsnum = lds_TranHeader.getItemString(1,'hwdunsnum')
ls_createddt = String(ldt_createddt,'YYYYMMDDHHMMSS')
ls_header = ls_recordidh + '~t'
ls_header += ls_schcontactname + '~t'
ls_header += ls_schcontactemail + '~t'
ls_header += ls_schcontactphone + '~t'
ls_header += ls_schdunsnum + '~t'
ls_header += ls_createddt + '~t'
ls_header += ls_hwdnunsnum + '~t' + '~t' + '~t' + '~t'
END IF
ls_recordidd = lds_TranDetail.getItemString(ll_detail,'recordidd')
ls_clnum = lds_TranDetail.getItemString(ll_detail,'clnum')
ls_schdunsnum = lds_TranDetail.getItemString(ll_detail,'schdunsnum')
ls_schlsname = lds_TranDetail.getItemString(ll_detail,'schlsname')
ls_company = lds_TranDetail.getItemString(ll_detail,'company')
ls_hwwhsecode = lds_TranDetail.getItemString(ll_detail,'hwwhsecode')
ls_hwdunsnum = lds_TranDetail.getItemString(ll_detail,'hwdunsnum')
ls_hwsubcompany = lds_TranDetail.getItemString(ll_detail,'hwsubcompany')
ls_boxname = lds_TranDetail.getItemString(ll_detail,'boxname')
ls_boxnumb = lds_TranDetail.getItemString(ll_detail,'boxnumb')
ls_contractnum = lds_TranDetail.getItemString(ll_detail,'contractnum')
//ldec_ItemQty = Dec(lds_TranDetail.getItemNumber(ll_detail,'itemqty'))
ls_itemqty = String(lds_TranDetail.getItemNumber(ll_detail,'itemqty'))
ls_itemcode = lds_TranDetail.getItemString(ll_detail,'itemcode')
ls_boxstatus = lds_TranDetail.getItemString(ll_detail,'boxstatus')
ls_detail += ls_recordidd + '~t'
ls_detail += ls_clnum + '~t'
ls_detail += ls_schdunsnum + '~t'
ls_detail += ls_schlsname + '~t'
ls_detail += ls_company + '~t'
ls_detail += ls_hwwhsecode + '~t'
ls_detail += ls_hwdunsnum + '~t'
ls_detail += ls_hwsubcompany + '~t'
ls_detail += Trim(ls_boxname) + '~t'
ls_detail += ls_boxnumb + '~t'
ls_detail += ls_contractnum + '~t'
ls_detail += ls_itemqty + '~t'
ls_detail += Trim(ls_itemcode) + '~t'
ls_detail += ls_boxstatus + '~t' + '~t' + '~t' + '~t' + '~r~n'
Long ll_insert
Long ll_getrow, ll_counter, ll_totalrow, ll_loop = 0
String ls_trandate, ls_generateddt
IF ll_detail = 18 AND (li_fileint <> li_filecount) THEN
ldt_trandate = gnv_app.of_getServerDate( )
ls_trandate = String(ldt_TranDate,'YYYYMMDDHHMMSS')
li_pagefile++ //Increment
ls_Footer = 'F' + '~t' + String(li_pagefile) + '~t' + '.' + '~t'
ls_Footer += ls_seqnum + '~t' + '/' + '~t' + 'E' + '~t' + '~t' + '~t' + '~t'
ls_Message = ls_Header + '~r~n' + ls_Detail + ls_Footer + '~r~n'
FilePath = String(dw_path.Object.outboundfilepath[1])
FileName = ls_FilePrefix + '_' +String(li_pagefile)+'_'+String(ldt_TranDate,'YYYYMMDDHHMMSS') + '.txt'
FileDir = FilePath + '/' + FileName
li_FileNum = FileOpen(FileDir, TextMode!, Write!, LockWrite!, Append!)
ll_status = FileWriteEx(li_FileNum, ls_Message)
IF ll_Status >= 1 THEN
FileClose(li_FileNum)
END IF
IF Trim(ls_Message) <> "" OR Len(Trim(ls_Message)) > 0 THEN ls_Message = ""
IF Trim(ls_Header) <> "" OR Len(Trim(ls_Header)) > 0 THEN ls_Header = ""
IF Trim(ls_Detail) <> "" OR Len(Trim(ls_Detail)) > 0 THEN ls_Detail = ""
ll_getrow = lds_trandetail.RowCount()
li_filecount = li_filecount + 1
ll_loop = ll_detail + 18
ll_totalrow = ll_detailrow - ll_detail
ll_detail = 18 * li_filecount
END IF
NEXT
END IF
RETURN ib_RETURN = TRUE
答案 0 :(得分:0)
你说每个文件有20行,但即使是标题行,你也会在每个文件中放入18-19行。我不完全理解你的代码,但我会写一个for循环,如果计数器可以除以20,我将关闭实际文件并打开一个新文件。
增加:
我认为问题在于这个条件:
IF ll_detail = 18 AND (li_fileint <> li_filecount) THEN
这是假的,因为你第一次只检查了18行,这就是你只得到一个文件的原因。
您应该更改此类似内容:
IF (Mod(ll_detail, 18) = 0 or ll_detail = lds_TranDetail.RowCount()) AND (li_fileint <> li_filecount) THEN
Mod(ll_detail, 18) = 0
条件会检查您是否是另一行18的结尾或ll_detail = lds_TranDetail.RowCount()
您在所有行的末尾!
我认为这可行。
溴。的Gabor