‎2006 Feb 07 9:05 AM
Hi everyone, have a look at the following subroutine, expecially at the lower portion where i just recently added to the program:
*------------------------------------------------------------------
* FORM GET_BILLING_DOC
*------------------------------------------------------------------
FORM GET_BILLING_DOC.
DATA: BCKTXT(30) TYPE C, ADRNR LIKE VRPMA-ADRNR.
CLEAR: BCKTXT.
VBELN-SIGN = 'I'.
VBELN-OPTION = 'EQ'.
SELECT VBELN
INTO (VBELN-LOW)
FROM VBRK
WHERE VKORG IN I_VKORG
AND KUNRG IN I_KUNRG
AND FKART IN I_FKART
AND FKDAT IN I_FKDAT
ORDER BY VBELN.
IF SY-SUBRC = 0.
APPEND VBELN.
ENDIF.
ENDSELECT.
SELECT B~VKORG B~VTWEG B~FKDAT A~WERKS B~LAND1 B~BZIRK B~KDGRP
B~KUNRG B~KUNAG E~NAME1 E~ADRNR A~PRODH A~CHARG B~FKTYP
A~AUTYP B~GJAHR B~BELNR B~FKART B~VBELN A~VGBEL A~POSNR
A~MATNR A~ARKTX B~WAERK A~NETWR A~FKIMG A~VOLUM C~BUCHK
D~BEZEI A~ERNAM B~FKSTO B~KNUMV F~LIFNR B~XBLNR "G~NAME1
INTO TABLE WTAB
FROM VBRP AS A
* LEFT OUTER JOIN VBRK AS B
INNER JOIN VBRK AS B
ON B~VBELN = A~VBELN
* LEFT OUTER JOIN VBUK AS C
INNER JOIN VBUK AS C
ON C~VBELN = A~VBELN
INNER JOIN TVBST AS D
ON D~SPRAS = 'EN'
AND D~TBNAM = 'VBUK'
AND D~FDNAM = 'BUCHK'
AND D~STATU = C~BUCHK
INNER JOIN KNA1 AS E
ON E~KUNNR = B~KUNRG
LEFT OUTER JOIN VBPA AS F
ON F~VBELN = A~VBELN
AND F~POSNR = '000000'
AND F~PARVW = 'ZT'
* LEFT OUTER JOIN LFA1 AS G
* ON G~LIFNR = F~LIFNR
WHERE A~VBELN IN VBELN
AND A~MATNR IN I_MATNR
AND NOT ( A~NETWR = 0
AND A~FKIMG = 0
AND A~VOLUM = 0 )
AND B~FKSTO IN I_FKSTO
AND B~VTWEG IN I_VTWEG
ORDER BY B~VKORG B~VTWEG B~FKDAT A~WERKS B~FKART B~VBELN A~VGBEL
A~POSNR A~MATNR.
LOOP AT WTAB
WHERE KNUMV <> ''.
SELECT SINGLE KBETR
INTO (WTAB-KBETR)
FROM KONV AS H
WHERE H~KNUMV = WTAB-KNUMV
AND H~KPOSN = WTAB-POSNR
AND ( H~KSCHL = 'ZP00'
OR H~KSCHL = 'ZREN' )
AND H~STUNR = '010'
AND H~ZAEHK = '01'
AND H~KAPPL = 'V'.
IF SY-SUBRC = 0.
MODIFY WTAB INDEX SY-TABIX TRANSPORTING KBETR.
ENDIF.
ENDLOOP.
LOOP AT WTAB
WHERE LIFNR <> ''.
SELECT SINGLE NAME1
INTO (WTAB-TNAME)
FROM LFA1
WHERE LIFNR = WTAB-LIFNR.
IF SY-SUBRC = 0.
MODIFY WTAB INDEX SY-TABIX TRANSPORTING TNAME.
ENDIF.
ENDLOOP.
* I just added this part
SELECT A~VBELN A~CHARG A~KDMAT A~VGBEL A~VGPOS B~VBELN B~POSNR B~BSTKD
C~VBELN C~POSNR C~ERDAT C~NETPR
INTO TABLE ITAB
FROM LIPS AS A
INNER JOIN VBKD AS B
ON B~VBELN = A~VGBEL AND
B~POSNR = '00000'
INNER JOIN VBAP AS C
ON C~VBELN = A~VGBEL AND
C~POSNR = A~VGPOS
WHERE A~VBELN = WTAB-VGBEL AND
A~CHARG = WTAB-CHARG.
I would like to know how do i do a MOVE statement from my new ITAB to WTAB? I tried doing a MOVE statement earlier and for some reason only the first record was moved but not the others.
And one last thing, i noticed that the internal table WTAB has many fields in it, around 20 or so...would it significantly affect performance?
‎2006 Feb 07 9:09 AM
Hi Bernard,
MOVE statement with tables will only affect the header line. If you want to add the lines of itab to wtab:
wtab[] = itab[] (completely overwrite wtab).
append lines of itab to wtab (add the lines of itab of wtab)
Regards,
John.
‎2006 Feb 07 9:09 AM
move itab[] to watb[], if they both are with header line.
or if they are with headerline,
use
MOVE ITAB TO WTAB.
‎2006 Feb 07 9:18 AM
Hi,
After building itab table, try below code.
Loop at wtab.
read table itab with key f1 = wtab-f1..fn = wtab-fn.
move-corresponding itab to wtab.
modify wtab.
endloop.
this code update ur wtab based on the value of itab.
Main thing u have to write modify statement in a loop.
Regards,
Digesh Panchal
‎2006 Feb 07 9:22 AM
hi
LOOP AT ITAB.
MOVE ITAB TO WTAB.
APPEND WTAB.
ENDLOOP.
move statement moves the contents of the header of iab to header wtab. then append wtab so that it add to the internal table
regards
kishore
‎2006 Feb 07 9:34 AM
I do not intend to replace WTAB with the contents of ITAB. I would just like the fields ITAB-BSTKD, ITAB-VGBEL, ITAB-ERDAT, ITAB-KDMAT AND ITAB-NETPR to fill up their corresponding fields (which i have just declared in WTAB) in table WTAB with a condition where ITAB-VBELN1 = WTAB-VGBEL and ITAB-CHARG = WTAB-CHARG.
Would a MOVE-CORRESPONDING work?
‎2006 Feb 07 9:55 AM
loop at itab .
read table wtab with <key field1> = itab-<key field1>
<key field2> = itab-<key field2> .
move-corresponding itab to wtab .
append wtab .
clear wtab .
endloop .
<keyfield1> and <keyfield2> are the key fields commn in both itab and wtab so that you can get the matching record for itab from wtab.
REgards
Raja
‎2006 Feb 07 9:56 AM
Hi
You can try this:
LOOP AT ITAB.
WTAB-BSTKD = ITAB-BSTKD.
WTAB-VGBEL = ITAB-VGBEL.
WTAB-ERDAT = ITAB-ERDAT.
WTAB-KDMAT = ITAB-KDMAT.
WTAB-NETPR = ITAB-NETPR.
MODIFY WTAB TRANSPORTING BSTKD VGBEL ERDAT KDMAT NETPR
WHERE VGBEL = ITAB-VBEL1
AND CHARG = ITAB-CHARG.
ENDLOOP.
Max
‎2006 Feb 07 10:26 AM
Thanks for the sample codes and i tried both.
Raja, for some reason, only some of the fields are being read and moved to the header of WTAB but still not filled into their correponding fields/lines
Max, your codes managed to retrieve all of the relevant fields that i need to move to WTAB but its not being filled into their corresponding line. The MODIFY statement doesn't seem to be working. It just appears in the header, then it disappears in the next loop.
‎2006 Feb 07 10:31 AM
there was a mistake in my sample earlier, it should have been modify and not append.
data: itab_wa like line of itab ,
wtab_wa like line of wtab .
loop at itab into itab_wa .
read table wtab into wtab_wa with <key field1> = itab_wa-<key field1>
<key field2> = itab_wa-<key field2> .
move-corresponding itab_wa to wtab_wa .
modify wtab from wtab_wa .
clear : itab_wa , wtab_wa .
endloop .
for the move-corresponding to work the fields name in the both the tables has to of same name else use explicit move
(move: itab-fielda to wtab-fielda .)
Regards
Raja
‎2006 Feb 07 10:36 AM
Hi
I can't know how is the data in the ITAB table, but here you want to update the field VGBEL and this field is used in WHERE condition too.
Max
‎2006 Feb 07 10:37 AM
Hi Bernard,
Did you correct the typo in Max's code ie
>>WHERE VGBEL = <i>ITAB-VBEL1</i>
shouldn'it be ITAB-VBELN1?
Regards,
Suresh Datti
‎2006 Feb 07 10:45 AM
Raja, it seems to be creating runtime errors whenever i try to execute the program
‎2006 Feb 07 10:51 AM
Suresh, i did notice and changed the type error accordingly.
Anyhow, just in case, here's the declaration for my internal tables:
DATA: BEGIN OF WTAB OCCURS 0,
VKORG LIKE VBRK-VKORG, "Sales Organization
VTWEG LIKE VBRK-VTWEG, "Distribution Channel
FKDAT LIKE VBRK-FKDAT, "Billing date
WERKS LIKE VBRP-WERKS, "Plant
LAND1 LIKE VBRK-LAND1, "Destination country
BZIRK LIKE VBRK-BZIRK, "Sales district
KDGRP LIKE VBRK-KDGRP, "Customer group
KUNRG LIKE VBRK-KUNRG, "Payer
KUNAG LIKE VBRK-KUNAG, "Sold-to party
NAME1 LIKE KNA1-NAME1, "Name 1
ADRNR LIKE KNA1-ADRNR, "Address
PRODH LIKE VBRP-PRODH, "Product hierarchy
CHARG LIKE VBRP-CHARG, "Batch Number
FKTYP LIKE VBRK-FKTYP, "Billing category
AUTYP LIKE VBRP-AUTYP, "SD document category
GJAHR LIKE VBRK-GJAHR, "Fiscal Year
BELNR LIKE VBRK-BELNR, "Accounting Document Number
FKART LIKE VBRK-FKART, "Billing Type
VBELN LIKE VBRK-VBELN, "Billing Document
VGBEL LIKE VBRP-VGBEL, "Document number of reference document
POSNR LIKE VBRP-POSNR, "Billing item
MATNR LIKE VBRP-MATNR, "Material Number
ARKTX LIKE VBRP-ARKTX, "Short Text for Sales Order Item
WAERK LIKE VBRK-WAERK, "SD document currency
NETWR LIKE VBRP-NETWR, "Net value of billing item in doc curr
FKIMG LIKE VBRP-FKIMG, "Actual Invoiced Quantity
VOLUM LIKE VBRP-VOLUM, "Volume
BUCHK LIKE VBUK-BUCHK, "Posting Status of Billing Document
BEZEI LIKE TVBST-BEZEI, "Status Description
ERNAM LIKE VBRP-ERNAM, "Name of Person who Created the Object
FKSTO LIKE VBRK-FKSTO, "Billing document is cancelled
KNUMV LIKE KONV-KNUMV, "Number of the document condition
LIFNR LIKE VBPA-LIFNR, "Account Number of Vendor or Creditor
TNAME LIKE KNA1-NAME1,
KBETR LIKE KONV-KBETR, "Rate (condition amount or percentage)
BSTKD LIKE VBKD-BSTKD, "Customer PO
VGBEL2 LIKE LIPS-VGBEL, "Sales Order Number
ERDAT LIKE VBAP-ERDAT, "Sales Order Date
KDMAT LIKE LIPS-KDMAT, "Paper Width
NETPR LIKE VBAP-NETPR, "Selling Price/MT
END OF WTAB.
DATA: BEGIN OF ITAB OCCURS 0,
VBELN1 LIKE LIPS-VBELN, "Delivery
CHARG LIKE LIPS-CHARG, "Batch Number
KDMAT LIKE LIPS-KDMAT, "Material belonging to the customer
VGBEL LIKE LIPS-VGBEL, "Ref doc no. (SO No. maintained here)
VGPOS LIKE LIPS-VGPOS, "Item number of the reference item
VBELN2 LIKE VBKD-VBELN, "SD Document Number
POSNR2 LIKE VBKD-POSNR, "Item number of the SD document
BSTKD LIKE VBKD-BSTKD, "Customer purchase order number
VBELN3 LIKE VBAP-VBELN, "Sales Document
POSNR3 LIKE VBAP-POSNR, "Sales Document Item
ERDAT LIKE VBAP-ERDAT, "Date on which the record was created
NETPR LIKE VBAP-NETPR, "Net price
END OF ITAB.
FYI, i just added the last 4 fields in WTAB...ITAB is entirely new and recently added.
‎2006 Feb 07 10:52 AM
Hi
Use the index addition, you're looping ITAB, not WTAB so you have to specify the index of record has to be updated.
loop at itab into itab_wa .
read table wtab into wtab_wa with <key field1> = itab_wa-<key field1>
<key field2> = itab_wa-<key field2> .
if sy-subrc = 0.
move-corresponding itab_wa to wtab_wa .
modify wtab from wtab_wa index sy-tabix.
endif.
clear : itab_wa , wtab_wa .
endloop .
Max
‎2006 Feb 08 11:04 AM
Hi Max, i tried out the ammendment to the codes you posted...but now, it's only retrieving the last line item and moved to WTAB. The earlier records for the earlier lines are not shown...
‎2006 Feb 07 10:26 AM
Hi Bernard,
I would like to share some important points,
1. First of all the number of joins you are using in the
select query will definitely dampens the system
performance badly. So try to use intarnal table and
then try to filter the records. This will improve your
system performance very well.
2. Check whether both the tables WTAB amd ITAB have same
number of fields.
3. If so, you can very well use ,
WTAB[] = ITAB[] (or) APPEND LINES OF ITAB TO WTAB.
4. If fields are different, that is,
Example:
ITAB1 with 10 fields
ITAB2 with 11 fields (the 11th field is extra , but
all other fields are same)
LOOP AT ITAB2 INTO <WORK_AREA_ITAB2>
MOVE-CORRESPONDING <WORK_AREA_ITAB1>.
APPEND <WORK_AREA_ITAB1> to ITAB1.
ENDLOOP.
I hope this is suffice.
Regs,
Venkat Ramanan
‎2006 Feb 07 10:29 AM
Hi Bernard,
I would like to share some important points,
1. First of all the number of joins you are using in the
select query will definitely dampens the system
performance badly. So try to use intarnal table and
then try to filter the records. This will improve your
system performance very well.
2. Check whether both the tables WTAB amd ITAB have same
number of fields.
3. If so, you can very well use ,
WTAB[] = ITAB[] (or) APPEND LINES OF ITAB TO WTAB.
4. If fields are different, that is,
Example:
ITAB1 with 10 fields
ITAB2 with 11 fields (the 11th field is extra , but
all other fields are same)
LOOP AT ITAB2 INTO <WORK_AREA_ITAB2>
MOVE-CORRESPONDING <WORK_AREA_ITAB1>.
APPEND <WORK_AREA_ITAB1> to ITAB1.
ENDLOOP.
I hope this is suffice.
Regs,
Venkat Ramanan
‎2006 Feb 08 11:22 AM
DATA itab LIKE TABLE OF mara.
DATA itab2 LIKE TABLE OF mara.
DATA wtab LIKE LINE OF itab.
SELECT * FROM mara
INTO TABLE itab
UP TO 50 ROWS.
"Copy entire table
itab2[] = itab[].
"Copy particular rows depending on condition
LOOP AT itab INTO wtab.
IF cond
APPEND wtab TO itab2.
ENDIF.
ENDLOOP.Is this what you want?
Else please brief on your requirement.
‎2006 Feb 09 6:05 AM
Thanks G, but what you posted was not what i wanted.
However, i did some ammendments to the earlier code posted and it worked. However, executing it takes quite a while. Perhaps you guys could let me know of anything that would help improve performance?
Have a look at the ammendments i made, actually all i did was do a looping.
LOOP AT WTAB.
SELECT A~VBELN A~CHARG A~KDMAT A~VGBEL A~VGPOS B~VBELN B~POSNR B~BSTKD
C~VBELN C~POSNR C~ERDAT C~NETPR
INTO TABLE ITAB
FROM LIPS AS A
INNER JOIN VBKD AS B
ON B~VBELN = A~VGBEL AND
B~POSNR = '00000'
INNER JOIN VBAP AS C
ON C~VBELN = A~VGBEL AND
C~POSNR = A~VGPOS
WHERE A~VBELN = WTAB-VGBEL AND
A~POSNR = WTAB-VGPOS AND
A~CHARG = WTAB-CHARG.
DATA: ITAB_WA LIKE LINE OF ITAB,
WTAB_WA LIKE LINE OF WTAB.
LOOP AT ITAB INTO ITAB_WA.
READ TABLE WTAB INTO WTAB_WA WITH KEY VGBEL = ITAB_WA-VBELN1
CHARG = ITAB_WA-CHARG.
IF SY-SUBRC = 0.
MOVE-CORRESPONDING ITAB_WA TO WTAB_WA.
MODIFY WTAB FROM WTAB_WA INDEX SY-TABIX.
ENDIF.
CLEAR: ITAB_WA, WTAB_WA.
ENDLOOP.
ENDLOOP.
A collegue suggested i make some ammendments to my SELECT statement by using a different condition (FOR ALL ENTRIES IN WTAB)