Application Development 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: 

abap logic or programming logic

Former Member
0 Kudos

Hi SAP gurus,

I'm trying to do a program which will replace standard report ME2l (purchase order history report). I would like to create purchasing report, where purchase order history displayed in one line.

I found one problem for my programming skills.

I connected for example three tables EKKO (purchasing header), EKPO (purchasing item) and EKKN (Account Assignment in Purchasing Document). EKKO and EKPO as inner join and EKKN as left outer connected. I would like to put some fields from EKKN on selection screen.

Now the logic of the program is. Read from ekko and ekpo all data and fill the fields also from ekkn, where exists. If there is no entry in the table EKKN, leave blank field.

How can I adopt the program if I want to have fields from those leftouter table on selection screen. If the field KOSTL from EKKN table is populated on selection screen, the program should use opposite way. Select from EKKN and then add EKPO and EKKO as left outer join.

I hope someone will understand, what I want to ask you )))))))))))))))

PLEASE HELP!!!

*******************************************************

SELECT * FROM EKKO INTO LW_EKKO

WHERE ( EBELN IN EBELN ) AND

( BEDAT IN BEDAT ) AND

( EKORG IN EKORG ) AND

( LIFNR IN LIFNR ) AND

( BSART NE 'UB' ) AND

( BSTYP = 'F' ) AND

( LOEKZ = ' ').

CLEAR: INT.

IF SY-SUBRC = 0.

MOVE-CORRESPONDING LW_EKKO TO INT.

ENDIF.

SELECT * FROM EKPO INTO LW_EKPO

WHERE ( EBELN = LW_EKKO-EBELN ) AND

( MATNR IN MATNR ) AND

( EREKZ IN EREKZ ) AND

( ELIKZ IN ELIKZ ) AND

( PSTYP IN PSTYP ) AND

( KNTTP IN KNTTP ) AND

( LOEKZ in LOEKZ ).

CLEAR: INT.

MOVE-CORRESPONDING LW_EKKO TO INT.

IF SY-SUBRC = 0.

MOVE-CORRESPONDING LW_EKPO TO INT.

ENDIF.

CLEAR: EKKN.

SELECT SINGLE * FROM EKKN WHERE ( EBELN = LW_EKPO-EBELN ) AND

( EBELP = LW_EKPO-EBELP ) AND

( KOSTL IN KOSTL ) and

( AUFNR IN AUFNR ).

MOVE EKKN-KOSTL TO INT-KOSTL.

MOVE EKKN-AUFNR TO INT-AUFNR.

CALL FUNCTION 'ME_READ_HISTORY'

EXPORTING

EBELN = LW_EKPO-EBELN

EBELP = LW_EKPO-EBELP

WEBRE = ' '

TABLES

XEKBES = BETS.

LOOP AT BETS WHERE ZEKKN EQ SPACE.

MOVE-CORRESPONDING BETS TO INT.

APPEND INT.

ENDLOOP.

IF SY-SUBRC NE 0.

APPEND INT.

ENDIF.

REFRESH BETS.

CLEAR: LW_EKPO.

ENDSELECT.

CLEAR: LW_EKKO.

ENDSELECT.

1 ACCEPTED SOLUTION

former_member223537
Active Contributor
0 Kudos

Hi,

You can validate whether the field on selection screen is populated & accordingly have two different types of select queries.

if s_kostl[] is initial.

Select.........

else.

Select from EKKN and then add EKPO and EKKO as left outer join.

endif.

Best regards,

Prashant

2 REPLIES 2

former_member223537
Active Contributor
0 Kudos

Hi,

You can validate whether the field on selection screen is populated & accordingly have two different types of select queries.

if s_kostl[] is initial.

Select.........

else.

Select from EKKN and then add EKPO and EKKO as left outer join.

endif.

Best regards,

Prashant

0 Kudos

Uf, thanks.

Can you tell me a little bit more, how I can adopt this to my program?

Thanks

Saso