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

select based on condition

Former Member
0 Likes
902

experts,

i need u r help.

plz help to write the code for the below.

can i write one select for the given based on condition or need to write two selects.

kindly help me.

Order_Date:

1. If billing document type (VBFA-VBTYP_N) = ‘M,’ then select from VBFA the preceding document (VBFA-VBELV) where the billing document (VBRK-VBELN) is equal to the follow on document (VBFA-VBELN).

a. Select from VBFA the preceding document (VBFA-VBELV) where the preceding document (VBFA-VBELV) in step 1 is equal to the follow on document (VBFA-VBELN)

b. Select from VBAK the order date (VBAK-ERDAT) where the document selected in step 1a (VBFA-VBELV) is equal to the order (VBAK-VBELN)

2. If billing document type (VBFA-VBTYP_N) = ‘H’ or ‘O’ or ‘P,’ then select from VBFA the preceding document (VBFA-VBELV) where the billing document (VBRK-VBELN) is equal to the follow on document (VBFA-VBELN).

a. Select from VBAK the order date (VBAK-ERDAT) where the document selected in step 2 (VBFA-VBELV) is equal to the order (VBAK-VBELN)

regards,

VC

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
810

Hi

U can use fm RV_ORDER_FLOW_INFORMATION to pick up whole flow of sale document.

Max

5 REPLIES 5
Read only

Former Member
0 Likes
811

Hi

U can use fm RV_ORDER_FLOW_INFORMATION to pick up whole flow of sale document.

Max

Read only

0 Likes
810

hi Max

actually i need to write select quirre for this.

as u told how to use RV_ORDER_FLOW_INFORMATION

in my code.

regards,

VC

Read only

0 Likes
810

how to get this

Read only

0 Likes
810

could u plz help me experts,

regards,

VC

Read only

0 Likes
810

Hi

You have to indicate the document number (so I suppose the bill (?)) and fm return all data of VBFA you need:

TABLES VBCO6.

PARAMETERS: SO_VBELN FOR VBRK-VBELN.

DATA: T_VBRK LIKE STANDARD TABLE OF VBRK WITH HEADER LINE,

T_VBFA LIKE STANDARD TABLE OF VBRK WITH HEADER LINE.

SELECT * FROM VBRK INTO TABLE T_VBRK WHERE VBELN IN SO_VBELN.

LOOP AT T_VBRK.

REFRESH T_VBFA.

VBCO6-VBELN = T_VBRK-VBELN.

CALL FUNCTION 'RV_ORDER_FLOW_INFORMATION'

EXPORTING

COMWA = VBCO6

  • IMPORTING

  • BELEGTYP_BACK =

TABLES

VBFA_TAB = T_VBFA

  • EXCEPTIONS

  • NO_VBFA = 1

  • NO_VBUK_FOUND = 2

  • OTHERS = 3

.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

  • Here read T_VBFA (instead of VBFA)

LOOP AT T_VBFA WHERE...

ENDLOOP.

ENDLOOP.

Anyway u should considere if you need the data of sales order that generated a certain bill, you don't need to read VBFA, because you can pick the number of the order from item data:

DATA: BEGIN OF T_VBRP OCCURS 0,

VBELN TYPE VBELN,

VGBEL TYPE VGBEL,

END OF T_VBRP.

SELECT VBELN VGBEL FROM VBRP INTO TABLE T_VBRP

FOR ALL ENRIES IN T_VBRK

WHERE VBELN = T_VBRK-VBELN.

SORT T_VBRP BY VBELN VGBEL.

DELETE ADJACENT DUPLICATES FROM T_VBRP.

LOOP AT T_VBRK.

LOOP AT T_VBRP WHERE VBELN = T_VBRP-VBELN.

SELECT SINGLE * FROM VBAK WHERE VBELN = T_VBRP-VGBEL.

ENDLOOP.

ENDLOOP.

Max