10-18-2007 6:01 PM
Hello Gurus,
I have data in two internal tables. One table IT_A contains the fields -
MATNR - SALES ORG - DCHANNEL - STATUS - DESCRIPTION
The other table IT_B contains the fields -
CUSTOMER - SALES ORG.
I need to display the result of all the fields when the sales org of both the tables are equal. i.e IT_A-VKORG = IT_B-VTORG.
MATNR - SALES ORG - DCHANNEL - STATUS - DESCRIPTION.
Please help me out with the code to be written.
Regards,
Balu
10-18-2007 6:06 PM
Hi balu,
declare it_c type table of it_a.
loop at it_a into wa_a.
read table it_b into wa_b with key vkorg = wa_a-vkorg.
if sy-subrc = 0.
append wa_a to it_c.
clear wa_a.
endif.
endloop.
<b> Reward for helpful answers</b>
Satish
Message was edited by:
Satish Panakala
10-18-2007 6:06 PM
Hi balu,
declare it_c type table of it_a.
loop at it_a into wa_a.
read table it_b into wa_b with key vkorg = wa_a-vkorg.
if sy-subrc = 0.
append wa_a to it_c.
clear wa_a.
endif.
endloop.
<b> Reward for helpful answers</b>
Satish
Message was edited by:
Satish Panakala
10-18-2007 6:07 PM
Take one internal table as i_final ( This is final internal table).
sort it_a by sales_org
sort it_b by sales_org.
loop at it_a.
read table it_b with key sales_org = it_a-sale_org binary search.
if sy-subrc eq 0.
move the all values( it_a to i_final).
append i_final.
endif.
clear : it_a,
it_b.
endloop.
Now displays i_final data.
Thanks
Seshu
10-18-2007 6:52 PM
SORT it_b BY vkorg.
LOOP AT it_a.
READ TABLE it_b WITH KEY vkorg = it_a-vkorg
BINARY SEARCH
TRANSPORTING NO FIELDS.
IF sy-subrc EQ 0.
* Display MATNR - SALES ORG - DCHANNEL - STATUS - DESCRIPTION
ENDIF.
ENDLOOP.
10-18-2007 8:38 PM
Thanks Seshu, Mark, Satish for your replies.
I awarded points.
It is working fine when there are entries in the IT_B.
I also have a situation when there are no entries in the table IT_B.
In this case I need to display the IT_A entries in IT_C.
Can you help me to do this.
Regards,
Balu
10-18-2007 9:12 PM
Hi,
Try this..
loop at it_a.
read table it_b with key vkorg = it_a-vkorg.
if sy-subrc = 0.
**Display MATNR - SALES ORG - DCHANNEL - STATUS - DESCRIPTION
else. " If no record found
Display the values from IT_A..
endif.
endloop.
Thanks
Naren
10-18-2007 10:13 PM
Naren,
2 select options. Material and Customer.
There are 2 tables - IT_A and IT_B.
IT_A is populated using material from select oprions. IT_B is populated using customer from select options.
IT_C is the display table needed. IT_A and IT_B has sales org field in common.
Case -1:
IT_B has some entries. If sales org of IT_A is same as sales org of IT_B. I am displaying the contents of IT_A only for the sales org that is in both IT_A and IT_B.
This is working fine.
Case -2:
There is no input customer in the select options. So, IT_B has no entries. It is blank. In this case I just want to display the contents of IT_A in IT_C.
The solution you mentioned solves only case 1 with no entries in it.
I tried to use -
LOOPAT IT_A.
IF IT_B[] is not intial.
CODE.....
IF IT_B[] is initial.
CODE...
ENDLOOP.
Is this correct? I am not getting any result if I give only material and no customer in the selection screen.
Please help me out.
Regards,
Balu
10-18-2007 10:23 PM
the solution looks good to me. why don't you post the actual code you used to implement it.
Rob
10-19-2007 2:02 PM
Is this what you are looking for ?
SORT it_b BY vkorg.
LOOP AT it_a.
* Case 1
IF NOT it_b[] IS INITIAL.
READ TABLE it_b WITH KEY vkorg = it_a-vkorg
BINARY SEARCH
TRANSPORTING NO FIELDS.
IF sy-subrc EQ 0.
* Display MATNR - SALES ORG - DCHANNEL - STATUS - DESCRIPTION
ENDIF.
* Case 2
ELSE.
* Display the contents of IT_A in IT_C.
ENDIF.
ENDLOOP.
10-19-2007 2:13 PM
hi,
try like this.
LOOP AT TAB1.
TAB4-MATNR = TAB1-MATNR.
TAB4-MAKTX = TAB1-MAKTX.
TAB4-EBELN = TAB1-EBELN.
TAB4-MBLNR = TAB1-MBLNR.
TAB4-BUDAT = TAB1-BUDAT.
TAB4-WERKS = TAB1-WERKS.
TAB4-MENGE = TAB1-MENGE.
TAB4-MTART = TAB1-MTART.
LOOP AT TAB3.
IF TAB1-EBELN = TAB3-EBELN.
TAB4-NETPR = TAB3-MENGE1.
ENDIF.
ENDLOOP.
APPEND TAB4.
ENDLOOP.
here i am merging data of itab1 and itab3 into itab4.
reward if useful.
10-19-2007 2:45 PM
TABLES : MVKE, CAUFVD, TVMST.
TYPES : BEGIN OF T_MVKE,
MATNR TYPE MVKE-MATNR,
VKORG TYPE MVKE-VKORG,
VTWEG TYPE MVKE-VTWEG,
VMSTA TYPE MVKE-VMSTA,
VMSTB TYPE TVMST-VMSTB,
END OF T_MVKE.
DATA : LT_MVKE TYPE STANDARD TABLE OF T_MVKE WITH HEADER LINE,
LS_MVKE TYPE T_MVKE.
DATA : LT1_MVKE TYPE STANDARD TABLE OF T_MVKE WITH HEADER LINE,
LS1_MVKE TYPE T_MVKE.
DATA : LT2_MVKE TYPE STANDARD TABLE OF T_MVKE WITH HEADER LINE,
LS2_MVKE TYPE T_MVKE.
TYPES : BEGIN OF T_KNVP,
KUNNR TYPE KNVP-KUNNR,
VKORG TYPE KNVP-VKORG,
END OF T_KNVP.
DATA : LT_KNVP TYPE STANDARD TABLE OF T_KNVP WITH HEADER LINE,
LS_KNVP TYPE T_KNVP.
SELECT-OPTIONS S_MATNR FOR MVKE-MATNR.
PARAMETER : P_KUNNR TYPE KNVP-KUNNR .
START-OF-SELECTION.
SELECT MATNR VKORG VTWEG VMSTA FROM MVKE INTO TABLE LT_MVKE WHERE MATNR IN S_MATNR .
IF SY-SUBRC = 0.
APPEND LT_MVKE.
ELSE.
EXIT.
ENDIF.
SELECT DISTINCT KUNNR VKORG FROM KNVP INTO TABLE LT_KNVP WHERE KUNNR = P_KUNNR.
IF SY-SUBRC = 0.
APPEND LT_KNVP.
ELSE.
EXIT.
ENDIF.
LOOP AT LT_MVKE.
LT1_MVKE-MATNR = LT_MVKE-MATNR.
LT1_MVKE-VKORG = LT_MVKE-VKORG.
LT1_MVKE-VTWEG = LT_MVKE-VTWEG.
LT1_MVKE-VMSTA = LT_MVKE-VMSTA.
SELECT SINGLE VMSTB FROM TVMST INTO LT1_MVKE-VMSTB WHERE VMSTA = LT_MVKE-VMSTA AND SPRAS = SYST-LANGU.
APPEND LT1_MVKE.
CLEAR LT1_MVKE.
ENDLOOP.
LOOP AT LT1_MVKE.
IF NOT LT_KNVP[] is INITIAL.
READ TABLE LT_KNVP WITH KEY VKORG = LT1_MVKE-VKORG BINARY SEARCH TRANSPORTING NO FIELDS.
IF SY-SUBRC = 0.
APPEND LT1_MVKE TO LT2_MVKE.
ELSE.
APPEND LT1_MVKE TO LT2_MVKE.
MESSAGE S003.
ENDIF.
CLEAR LT1_MVKE.
ELSE. "IF LT_KNVP[] IS INITIAL.
APPEND LT1_MVKE TO LT2_MVKE.
ENDIF.
ENDLOOP.
WRITE: /1 'MATERIAL NUMBER', 20 'SALES ORG', 35 'DISTRIBUTION CHANNEL', 65 'MATERIAL STATUS', 85 'STATUS DESCRIPTION'.
LOOP AT LT2_MVKE.
FORMAT HOTSPOT ON.
WRITE: /1 LT2_MVKE-MATNR, 20 LT2_MVKE-VKORG, 35 LT2_MVKE-VTWEG, 65 LT2_MVKE-VMSTA, 85 LT2_MVKE-VMSTB.
HIDE: LT2_MVKE-MATNR, LT2_MVKE-VKORG, LT2_MVKE-VTWEG, LT2_MVKE-VMSTA, LT2_MVKE-VMSTB.
CLEAR LT2_MVKE.
FORMAT HOTSPOT OFF.
ENDLOOP.
AT LINE-SELECTION.
IF LT2_MVKE-VMSTA = ' '.
MESSAGE E002.
ELSE.
SET PARAMETER ID 'MAT' FIELD LT2_MVKE-MATNR.
CALL TRANSACTION 'CO09'.
DATA WERKS(4) TYPE C VALUE '1200'.
SET PARAMETER ID 'WRK' FIELD WERKS.
DATA RULE(2) TYPE C VALUE 'ZB'.
SET PARAMETER ID 'PRR' FIELD RULE.
SET PARAMETER ID 'X' FIELD CAUFVD-PRMBD.
ENDIF.
Hello gurus,
The above code is working fine when I give both Material and customer in the select options. But it is not doing anything when I enter only the material.
Please help.
Regards,
Balu
10-19-2007 2:57 PM
Because you EXIT if you don't find any.
But the program structure could be changed:
Why select from KNVP inside the SELECT from MVKE? They aren't dependent at all.
Do the LOOPs outside the SELECTs
Rob
Message was edited by:
Rob Burbank
10-19-2007 3:17 PM
Thanks Rob.
Assigned Points.
After I posted, I found the error. (Exiting if sy-subrc ne 0, i removed that step and is working fine).
Thanks for your help.
Regards,
Balu
10-19-2007 4:00 PM
It may be working, but not working fine. Just removing the EXIT will help, but look at the other things I suggested as well.
Rob
10-19-2007 4:50 PM
Rob,
do you mean this select inside the loop?-
LOOP AT LT_MVKE.
LT1_MVKE-MATNR = LT_MVKE-MATNR.
LT1_MVKE-VKORG = LT_MVKE-VKORG.
LT1_MVKE-VTWEG = LT_MVKE-VTWEG.
LT1_MVKE-VMSTA = LT_MVKE-VMSTA.
SELECT SINGLE VMSTB FROM TVMST INTO LT1_MVKE-VMSTB WHERE VMSTA = LT_MVKE-VMSTA AND SPRAS = SYST-LANGU.
APPEND LT1_MVKE.
CLEAR LT1_MVKE.
ENDLOOP.
Regards,
balu
10-19-2007 4:59 PM
I was questioning your logic. I think the second SELECT belongs outside the first one and I'm not sure about the placement of the LOOPs. Try to analyze just what you want to do.
Rob