Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Data Fetching

Former Member
0 Likes
465

Hi,

I am working with a report. Input parameters as kunnr, hityp, hvkorg from the table knvh.

My data in the table is as

KUNNR vkorg hkunnr

10255 2001 30349

53344 2001 30349

45678 2001 30349

74152 2001 30349

In this i need to pick up all kunnr entries associated with hkunnr(30349). If input parameter

is HKUNNR then the below code is working but i have to keep KUNNR as input field.

For the above task i am coding like this

Can anyone help me how to replace HKUNNR with KUNNR.

3 REPLIES 3
Read only

former_member404244
Active Contributor
0 Likes
422

Hi,

U rcdoe will work when the input paramter is hkunnr as it has four records and u will get , but when u go for kunnr u will get the kunnr entry whcih u specified in the selection screen...

my suggestion is use instead of kunnr use hkunnr in the selection screen... else once u get the data for kunnr.. for example i have given in the selection screen , kunnr as 10255 now i will get one record as 10255 2001 30349.

Now onec again query the same table now by using hkunnr = itab-hkunnr (using for all entries) u will get the rest of the records.

Regards,

Nagaraj

Read only

Former Member
0 Likes
422

Hi Venkat,

You can try using;

SELECT B~KUNNR B~HITYP B~HKUNNR  INTO TABLE ITAB 
FROM KNVH AS A INNER JOIN
KNVH AS B ON B~HKUNNR = A~HKUNNR WHERE A~KUNNR = PA_CUST
AND A~HVKORG = PA_CCODE
AND A~HITYP = PA_HITYP.

I am not sure whether it works, just try and let me know.

regards

Karthik D

Read only

Former Member
0 Likes
422

Solved by own.

Below is the code by which it is working fine.

LOOP AT ITAB.

IF ITAB-HKUNNR NE 0.

MOVE ITAB-HKUNNR TO LV_HKUNNR.

MOVE ITAB-HVKORG TO LV_CCODE.

MOVE ITAB-HITYP TO LV_HITYP.

ENDIF.

SELECT * FROM KNVH INTO TABLE ITAB1 WHERE HKUNNR = LV_HKUNNR

AND HVKORG = LV_CCODE

AND HITYP = LV_HITYP.

LOOP AT ITAB1.

WRITE: /2 ITAB1-HITYP, 4 ITAB1-KUNNR, 15 ITAB1-VKORG, 23 ITAB1-SPART, 35 ITAB1-HKUNNR.

ENDLOOP. "FOR ITAB

ENDLOOP. "FOR ITAB1.