Logic of for all entrie in abap programming
Hi !
This is ravi, i am working as consultant i have one doubt can any body clarify it.
what is the' logic of for all entries' statement using in the abap coding?its very urgent , can any body helps me plz
regards,
ravi.
Hi,
it is a type of outer join using ITAB. if u r using for all entries then all records from left table will be selected and only matching records form right table will be selected and where it doesnot found the entry in right table then it will return null.
important points while useing this clasue:
1. u should chk itab should not be blank like: if itab[] is not null. "then process entries
2. itab should not contain huge data as it may slowdown sql
3. only uniques keys will be selected so ensures fileds should not be unique using fields like posnr which are differenct for each recort in fld likst
jogdand M B
Similar Messages
-
Use of for all entries in abap
Please tell me how to use "for all entries" in linking two
tables for retrieve informations by using corresponding fields in both the tables.plz send the codings.REPORT YVCHIERSEQ .
TYPE-POOLS:SLIS.
DATA:T_VBAK TYPE STANDARD TABLE OF VBAK INITIAL SIZE 0,
T_VBAP TYPE STANDARD TABLE OF VBAP INITIAL SIZE 0,
W_VBAK TYPE VBAK,
W_VBAP TYPE VBAP,
G_VBELN TYPE VBAK-VBELN,
W_FIELDCAT TYPE SLIS_FIELDCAT_ALV,
T_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
W_KEYINFO TYPE SLIS_KEYINFO_ALV.
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME.
SELECT-OPTIONS:S_VBELN FOR G_VBELN.
SELECTION-SCREEN END OF BLOCK B1.
INITIALIZATION.
CLEAR:W_VBAK,
W_VBAP.
REFRESH:T_VBAK,
T_VBAP.
START-OF-SELECTION.
PERFORM SUB_GET_VBAK.
PERFORM SUB_GET_VBAP.
PERFORM SUB_DISP_OUTPUT.
FORM SUB_GET_VBAK.
SELECT * FROM VBAK INTO TABLE T_VBAK WHERE VBELN IN S_VBELN.
ENDFORM.
FORM SUB_GET_VBAP.
SELECT * FROM VBAP INTO TABLE T_VBAP FOR ALL ENTRIES IN T_VBAK WHERE
VBELN = T_VBAK-VBELN.
ENDFORM.
FORM SUB_DISP_OUTPUT.
W_FIELDCAT-COL_POS = 1.
W_FIELDCAT-FIELDNAME = 'VBELN'.
W_FIELDCAT-SELTEXT_M = 'SALESORDER'.
W_FIELDCAT-TABNAME = 'VBAK'.
APPEND W_FIELDCAT TO T_FIELDCAT.
CLEAR W_FIELDCAT.
W_FIELDCAT-COL_POS = 2.
W_FIELDCAT-FIELDNAME = 'ERNAM'.
W_FIELDCAT-SELTEXT_M = 'NAME'.
W_FIELDCAT-TABNAME = 'VBAK'.
APPEND W_FIELDCAT TO T_FIELDCAT.
CLEAR W_FIELDCAT.
W_FIELDCAT-COL_POS = 3.
W_FIELDCAT-FIELDNAME = 'VBTYP'.
W_FIELDCAT-SELTEXT_M = 'SD CATEGORY'.
W_FIELDCAT-TABNAME = 'VBAK'.
APPEND W_FIELDCAT TO T_FIELDCAT.
CLEAR W_FIELDCAT.
W_FIELDCAT-COL_POS = 4.
W_FIELDCAT-FIELDNAME = 'KUNNR'.
W_FIELDCAT-SELTEXT_M = 'SOLD TO PARTY'.
W_FIELDCAT-TABNAME = 'VBAK'.
APPEND W_FIELDCAT TO T_FIELDCAT.
CLEAR W_FIELDCAT.
W_FIELDCAT-COL_POS = 5.
W_FIELDCAT-FIELDNAME = 'NETWR'.
W_FIELDCAT-SELTEXT_M = 'NET VALUE'.
W_FIELDCAT-TABNAME = 'VBAK'.
APPEND W_FIELDCAT TO T_FIELDCAT.
CLEAR W_FIELDCAT.
W_FIELDCAT-COL_POS = 1.
W_FIELDCAT-FIELDNAME = 'POSNR'.
W_FIELDCAT-SELTEXT_M = 'SALES ITEM'.
W_FIELDCAT-TABNAME = 'VBAP'.
APPEND W_FIELDCAT TO T_FIELDCAT.
CLEAR W_FIELDCAT.
W_FIELDCAT-COL_POS = 2.
W_FIELDCAT-FIELDNAME = 'MATNR'.
W_FIELDCAT-SELTEXT_M = 'MATERIAL NO'.
W_FIELDCAT-TABNAME = 'VBAP'.
APPEND W_FIELDCAT TO T_FIELDCAT.
CLEAR W_FIELDCAT.
W_FIELDCAT-COL_POS = 3.
W_FIELDCAT-FIELDNAME = 'MATKL'.
W_FIELDCAT-SELTEXT_M = 'MAT GROUP'.
W_FIELDCAT-TABNAME = 'VBAP'.
APPEND W_FIELDCAT TO T_FIELDCAT.
CLEAR W_FIELDCAT.
W_FIELDCAT-COL_POS = 4.
W_FIELDCAT-FIELDNAME = 'NETWR'.
W_FIELDCAT-SELTEXT_M = 'NET VALUE'.
W_FIELDCAT-TABNAME = 'VBAP'.
APPEND W_FIELDCAT TO T_FIELDCAT.
CLEAR W_FIELDCAT.
W_KEYINFO-HEADER01 = 'VBELN'.
W_KEYINFO-ITEM01 = 'VBELN'.
CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
EXPORTING
I_INTERFACE_CHECK = ' '
I_CALLBACK_PROGRAM = SY-CPROG
I_CALLBACK_PF_STATUS_SET = ' '
I_CALLBACK_USER_COMMAND = ' '
IS_LAYOUT =
IT_FIELDCAT = T_FIELDCAT
IT_EXCLUDING =
IT_SPECIAL_GROUPS =
IT_SORT =
IT_FILTER =
IS_SEL_HIDE =
I_SCREEN_START_COLUMN = 0
I_SCREEN_START_LINE = 0
I_SCREEN_END_COLUMN = 0
I_SCREEN_END_LINE = 0
I_DEFAULT = 'X'
I_SAVE = ' '
IS_VARIANT =
IT_EVENTS =
IT_EVENT_EXIT =
i_tabname_header = 'VBAK'
i_tabname_item = 'VBAP'
I_STRUCTURE_NAME_HEADER =
I_STRUCTURE_NAME_ITEM =
is_keyinfo = W_KEYINFO
IS_PRINT =
IS_REPREP_ID =
I_BYPASSING_BUFFER =
I_BUFFER_ACTIVE =
IMPORTING
E_EXIT_CAUSED_BY_CALLER =
ES_EXIT_CAUSED_BY_USER =
tables
t_outtab_header = T_VBAK
t_outtab_item = T_VBAP
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. -
Unable to Get the Data Using For All Entries
Hi everybody, i am using for all entries in a program. but when i am writing a code using for all entries i am getting an error as
Where condition does not refers to the FOR ALL ENTRIES tables...
SELECT KUNNR
NAME1
ORT01
LAND1
FROM KNA1 INTO TABLE ITAB1 WHERE KUNNR IN S_KUNNR.
IF NOT ITAB1 IS INITIAL.
SELECT VBELN
ERDAT
KUNNR
FROM VBAK INTO TABLE ITAB2 FOR ALL ENTRIES IN ITAB1 WHERE KUNNR = IT_KNA1-KUNNR.
ENDIF.
can anybody help out in this
regards
hyder aliThe correct one may be like this:
SELECT KUNNR
NAME1
ORT01
LAND1
FROM KNA1 INTO TABLE ITAB1 WHERE KUNNR IN S_KUNNR.
IF NOT ITAB1 IS INITIAL.
SELECT VBELN
ERDAT
KUNNR
FROM VBAK INTO TABLE ITAB2 FOR ALL ENTRIES IN ITAB1 WHERE KUNNR = ITAB1-KUNNR. "modified here
ENDIF.
Edited by: XuJian84 on Mar 9, 2010 4:25 AM -
SD Flow program using For all entries.
using simple ALV grid: I have the urgent requirement of changing the following program using 'For all entries' instead of joins and I should not use 'TABLES' -- For top-of-page I need to get dynamic fields like if I select company code in the selection screen then I need to get 'This report is base on COMPANY CODE'.
This program is about sales flow where i shud get only those records that have ebeln in vbak, delivery, invoice.
The original program is as follows:
*& Report ZSD_DOCU_FLOW *
REPORT zsd_docu_flow NO STANDARD PAGE HEADING .
* Program : ZCOS_SALES *
* Dev. Class : ZSD
* Functional :
* Created on : *
* Project :
* CR Number :
* Transaction : ZSDCSUT *
* Description : * Sales document life cylce for given customer
* to declaired period displaying the sales document
* details ,with relevant del details and corresponding
* Invocie Details
*----------- Tables Declaration -----------*
TABLES: vbak,vbap,vbfa,kna1,vbrk,vbrp,likp,lips,t001.
TYPE-POOLS : slis.
*----------- Internal Tables Declaration -----------*
* Internal Table for Sales Order data *
DATA: BEGIN OF it_so OCCURS 0,
vbeln LIKE vbak-vbeln,
kunnr LIKE vbak-kunnr,
posnr LIKE vbap-posnr,
matnr LIKE vbap-matnr,
kwmeng LIKE vbap-kwmeng,
netwr LIKE vbap-netwr,
END OF it_so.
* Internal Table for Delivery Order data *
DATA: BEGIN OF it_del OCCURS 0,
delnum LIKE likp-vbeln,
lfdat LIKE likp-lfdat,
delitem LIKE lips-posnr,
lfimg LIKE lips-lfimg,
END OF it_del.
* Internal Table for Invoice data *
DATA: BEGIN OF it_inv OCCURS 0,
invnum LIKE vbrk-vbeln,
invitem LIKE vbrp-posnr,
fkimg LIKE vbrp-fkimg,
amount LIKE vbrp-netwr,
END OF it_inv.
* Internal Table for Final data *
DATA: BEGIN OF it_final OCCURS 0,
vbeln LIKE vbak-vbeln,
posnr LIKE vbap-posnr,
kunnr LIKE vbak-kunnr,
name LIKE kna1-name1,
matnr LIKE vbap-matnr,
kwmeng LIKE vbap-kwmeng,
netwr LIKE vbap-netwr,
delnum LIKE likp-vbeln,
lfdat LIKE likp-lfdat,
delitem LIKE lips-posnr,
lfimg LIKE lips-lfimg,
invnum LIKE vbrk-vbeln,
invitem LIKE vbrp-posnr,
fkimg LIKE vbrp-fkimg,
amount LIKE vbrp-netwr,
END OF it_final.
*----------- Variables Declaration -----------*
DATA: v_name LIKE kna1-kunnr," variable for customer name
v_delnum LIKE likp-vbeln," variable for delivery number
v_invnum LIKE vbrk-vbeln." variable for invoce number
DATA : ls_layout TYPE slis_layout_alv,
it_fcat TYPE slis_t_fieldcat_alv ,
wa_fcat TYPE slis_fieldcat_alv,
lh TYPE slis_t_listheader,
ls TYPE slis_listheader,
it_events TYPE slis_t_event ,
ls_event TYPE slis_alv_event ,
i_sort TYPE slis_t_sortinfo_alv,
w_var TYPE i.
DATA : l_date(10).
DATA : l_date1(20).
DATA : l_repid LIKE trdir-name.
l_repid = 'ZSD_DOCU_FLOW1'.
*----------- Select-options & parameters Declaration ---*
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS: p_bukrs LIKE vbak-bukrs_vf,
p_vkorg LIKE vbak-vkorg,
p_vtweg LIKE vbak-vtweg,
p_spart LIKE vbak-spart.
SELECT-OPTIONS: s_kunnr FOR vbak-kunnr,
s_audat FOR vbak-audat.
SELECTION-SCREEN END OF BLOCK b1.
*----------- AT SELECTION-SCREEN --------------------------*
AT SELECTION-SCREEN.
SELECT SINGLE * FROM t001 INTO t001
WHERE bukrs = p_bukrs.
IF sy-subrc <> 0.
MESSAGE e000(8i) WITH 'Enter a Valid Company Code'.
ENDIF.
SELECT SINGLE * FROM vbak INTO vbak
WHERE vkorg = p_vkorg.
IF sy-subrc <> 0.
MESSAGE e000(8i) WITH 'Enter a Valid Sales Organization'.
ENDIF.
SELECT SINGLE * FROM vbak INTO vbak
WHERE vtweg = p_vtweg.
IF sy-subrc <> 0.
MESSAGE e000(8i) WITH 'Enter a Valid distribution channel'.
ENDIF.
SELECT SINGLE * FROM vbak INTO vbak
WHERE spart = p_spart.
IF sy-subrc <> 0.
MESSAGE e000(8i) WITH 'Enter a Valid Division'.
ENDIF.
SELECT SINGLE * FROM kna1 INTO kna1
WHERE kunnr IN s_kunnr.
IF sy-subrc <> 0.
MESSAGE e000(8i) WITH 'Enter a Valid Customer Number'.
ENDIF.
*----------- START-OF-SELECTION-----------------------------*
START-OF-SELECTION.
ls-typ = 'H'.
ls-info = 'Sales Document Flow'.
APPEND ls TO lh.
ls-typ = 'S'.
WRITE: sy-datum TO l_date USING EDIT MASK '__/__/____'.
CONCATENATE 'DATE :' l_date INTO l_date1 SEPARATED BY space.
ls-info = l_date1.
APPEND ls TO lh.
PERFORM field_cat.
PERFORM t_sort_build USING i_sort.
PERFORM get-data.
*----------- END-OF-SELECTION-----------------------------*
END-OF-SELECTION.
IF it_final[] IS INITIAL.
MESSAGE i000(8i) WITH 'No data Found'.
EXIT.
ENDIF.
PERFORM print-data.
*& Form get-data
* text
* --> p1 text
* <-- p2 text
FORM get-data .
* Accesing Sales Data
SELECT a~vbeln a~kunnr b~posnr b~matnr b~kwmeng b~netwr
INTO CORRESPONDING FIELDS OF TABLE it_so
FROM vbak AS a INNER JOIN vbap AS b
ON a~vbeln = b~vbeln
WHERE a~bukrs_vf = p_bukrs
AND a~vkorg = p_vkorg
AND a~vtweg = p_vtweg
AND a~spart = p_spart
AND a~kunnr IN s_kunnr
AND a~audat IN s_audat.
LOOP AT it_so.
SELECT SINGLE name1 FROM kna1 INTO v_name
WHERE kunnr = it_so-kunnr.
SELECT SINGLE vbeln FROM vbfa INTO v_delnum
WHERE vbelv = it_so-vbeln
AND vbtyp_n = 'J'.
IF sy-subrc = 0.
SELECT SINGLE vbeln FROM vbfa INTO v_invnum
WHERE vbelv = v_delnum
AND vbtyp_n = 'M'.
ENDIF.
MOVE-CORRESPONDING it_so TO it_final.
it_final-name = v_name.
it_final-delnum = v_delnum.
it_final-invnum = v_invnum.
APPEND it_final.
CLEAR it_final.
CLEAR v_delnum.
CLEAR v_invnum.
ENDLOOP.
LOOP AT it_final.
IF it_final-delnum NE ' '.
* Reading Del Data.
SELECT SINGLE a~vbeln a~lfdat b~posnr b~lfimg INTO
(it_del-delnum, it_del-lfdat, it_del-delitem,
it_del-lfimg ) FROM
likp AS a INNER JOIN lips AS b ON a~vbeln = b~vbeln
WHERE a~vbeln = it_final-delnum
AND b~posnr = it_final-posnr.
MOVE-CORRESPONDING it_del TO it_final.
MODIFY it_final.
ENDIF.
IF it_final-invnum NE ' '.
* Reading Invoice Data.
SELECT SINGLE vbeln posnr fkimg netwr INTO
(it_inv-invnum, it_inv-invitem, it_inv-fkimg, it_inv-amount )
FROM vbrp WHERE vbeln = it_final-invnum
AND posnr = it_final-posnr.
MOVE-CORRESPONDING it_inv TO it_final.
MODIFY it_final.
ENDIF.
ENDLOOP.
ENDFORM. " get-data
*& Form print-data
* text
* --> p1 text
* <-- p2 text
FORM print-data .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER = ' '
* I_BUFFER_ACTIVE = ' '
i_callback_program = l_repid
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
i_callback_top_of_page = 'TOP'
* I_CALLBACK_HTML_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_END_OF_LIST = ' '
* I_STRUCTURE_NAME =
* I_BACKGROUND_ID = ' '
* I_GRID_TITLE =
* I_GRID_SETTINGS =
* IS_LAYOUT =
it_fieldcat = it_fcat
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
IT_SORT = i_sort[]
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
* I_SAVE = ' '
* IS_VARIANT =
* IT_EVENTS =
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* IT_ALV_GRAPHICS =
* IT_HYPERLINK =
* IT_ADD_FIELDCAT =
* IT_EXCEPT_QINFO =
* I_HTML_HEIGHT_TOP =
* I_HTML_HEIGHT_END =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = it_final.
* EXCEPTIONS
* PROGRAM_ERROR = 1
* OTHERS = 2
* IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
* ENDIF.
ENDFORM. " print-data
*& Form field_cat
* text
* --> p1 text
* <-- p2 text
FORM field_cat .
wa_fcat-col_pos = w_var.
wa_fcat-tabname = 'IT_FINAL'.
wa_fcat-fieldname = 'VBELN'.
wa_fcat-key = 'X'.
wa_fcat-ref_fieldname = 'VBELN'.
wa_fcat-ref_tabname = 'VBAK'.
wa_fcat-seltext_m = 'Sales Order NO'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
ADD 1 TO w_var.
wa_fcat-col_pos = w_var.
wa_fcat-tabname = 'IT_FINAL'.
wa_fcat-fieldname = 'POSNR'.
wa_fcat-ref_fieldname = 'POSNR'.
wa_fcat-ref_tabname = 'VBAP'.
wa_fcat-seltext_m = 'SalesItemNO'.
wa_fcat-fix_column = 'X'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
ADD 1 TO w_var.
wa_fcat-col_pos = w_var.
wa_fcat-tabname = 'IT_FINAL'.
wa_fcat-fieldname = 'KUNNR'.
wa_fcat-seltext_m = 'CUSTNUM'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
ADD 1 TO w_var.
wa_fcat-col_pos = w_var.
wa_fcat-tabname = 'IT_FINAL'.
wa_fcat-fieldname = 'NAME'.
wa_fcat-seltext_m = 'CUSTNAME'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
ADD 1 TO w_var.
wa_fcat-col_pos = w_var.
wa_fcat-tabname = 'IT_FINAL'.
wa_fcat-fieldname = 'MATNR'.
wa_fcat-seltext_m = 'MATNUM'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
ADD 1 TO w_var.
wa_fcat-col_pos = w_var.
wa_fcat-tabname = 'IT_FINAL'.
wa_fcat-fieldname = 'KWMENG'.
wa_fcat-seltext_m = 'Sales Quantity'.
wa_fcat-do_sum = 'X'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
ADD 1 TO w_var.
wa_fcat-col_pos = w_var.
wa_fcat-tabname = 'IT_FINAL'.
wa_fcat-fieldname = 'NETWR'.
wa_fcat-seltext_m = 'Value'.
wa_fcat-do_sum = 'X'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
ADD 1 TO w_var.
wa_fcat-col_pos = w_var.
wa_fcat-tabname = 'IT_FINAL'.
wa_fcat-fieldname = 'DELNUM'.
wa_fcat-seltext_m = 'DeloveryNum'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
ADD 1 TO w_var.
wa_fcat-col_pos = w_var.
wa_fcat-tabname = 'IT_FINAL'.
wa_fcat-fieldname = 'DELITEM'.
wa_fcat-seltext_m = 'DelItemNO'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
ADD 1 TO w_var.
wa_fcat-col_pos = w_var.
wa_fcat-tabname = 'IT_FINAL'.
wa_fcat-fieldname = 'LFDAT'.
wa_fcat-seltext_m = 'DelDate'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
ADD 1 TO w_var.
wa_fcat-col_pos = w_var.
wa_fcat-tabname = 'IT_FINAL'.
wa_fcat-fieldname = 'LFIMG'.
wa_fcat-seltext_m = 'DelQuantity'.
wa_fcat-do_sum = 'X'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
ADD 1 TO w_var.
wa_fcat-col_pos = w_var.
wa_fcat-tabname = 'IT_FINAL'.
wa_fcat-fieldname = 'INVNUM'.
wa_fcat-seltext_m = 'InvoiceNum'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
ADD 1 TO w_var.
wa_fcat-col_pos = w_var.
wa_fcat-tabname = 'IT_FINAL'.
wa_fcat-fieldname = 'INVITEM'.
wa_fcat-seltext_m = 'InvoiceItem'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
ADD 1 TO w_var.
wa_fcat-col_pos = w_var.
wa_fcat-tabname = 'IT_FINAL'.
wa_fcat-fieldname = 'FKIMG'.
wa_fcat-seltext_m = 'INVQuantity'.
wa_fcat-do_sum = 'X'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
ADD 1 TO w_var.
wa_fcat-col_pos = w_var.
wa_fcat-tabname = 'IT_FINAL'.
wa_fcat-fieldname = 'AMOUNT'.
wa_fcat-seltext_m = 'INVvalue'.
wa_fcat-do_sum = 'X'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
ADD 1 TO w_var.
ENDFORM. " field_cat
*& Form top
* text
FORM t_sort_build USING l_sort TYPE slis_t_sortinfo_alv.
DATA: ls_sort TYPE slis_sortinfo_alv.
ls_sort-fieldname = 'VBELN'.
ls_sort-spos = 1.
ls_sort-up = 'X'.
ls_sort-subtot = 'X'.
APPEND ls_sort TO l_sort.
ls_sort-fieldname = 'KUNNR'.
ls_sort-spos = 2.
ls_sort-up = 'X'.
APPEND ls_sort TO l_sort.
ENDFORM. "t_sort_bui
FORM top.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = lh
* I_LOGO =
* I_END_OF_LIST_GRID =
ENDFORM. "TOP
===========================================================================
I have started the new program but i have trouble with the final internal table. Since i'm using For all entries I have declared internal tables for each table. My incomplete new program is as follows(not sure if the logic is correct till what I have coded):
*& Report Z_SDFLOW *
REPORT Z_SDFLOW NO STANDARD PAGE HEADING.
********* TABLES TO BE USED ***********************
**** VBAK - SALES DOCUMENT HEADER
* VBAP - SALES ITEM
* VBFA - SALES DOCUMENT FLOW
* KNA1- CUSTOMER MASTER
* VBRK - BILLING DOCUMENT HEADER
* VBRP - BLLING DOCUMENT ITEM
* LIKP - DELIVERY HEADER
* LIPS - DELIVERY ITEM
* TOO1 - COMPANY CODES
* SLIS.
TYPE-POOLS: SLIS.
** STRUCTURE DECLARATIONS ********
**STRUCTURE FOR ENQUIRY.
**STRUCTURE FOR QUOTATION.
**STRUCTURE FOR SALES ORDER HEADER- VBAK.
TYPES: BEGIN OF XT_VBAK,
VBELN TYPE VBAK-VBELN, "SALES DOCUMENT NUMBER
KUNNR TYPE VBAK-KUNNR, " SOLD-TO-PARTY
END OF XT_VBAK.
**STRUCTURE FOR SALES ORDER ITEM-VBAP
TYPES: BEGIN OF XT_VBAP,
POSNR TYPE VBAP-POSNR, " SALES ITEM NUMBER
MATNR TYPE VBAP-MATNR, " MATERIAL NUMBER
KWMENG TYPE VBAP-KWMENG, " CUMMULATIVE ORDER QUANTITY IN SALES UNITS
NETWR TYPE VBAP-NETWR, " NET VALUE OF THE ORDER ITEM
END OF XT_VBAP.
** STRUCTURE FOR DELIVERY HEADER -LIKP
TYPES: BEGIN OF XT_LIKP,
DELVBELN TYPE LIKP-VBELN, "DELIVERY DOCUMENT NUMBER
LFDAT TYPE LIKP-LFDAT, " DELIVERY DATE
END OF XT_LIKP.
**STRUCTURE FOR DELIVERY ITEM - LIPS
TYPES: BEGIN OF XT_LIPS,
DELPOSNR TYPE LIPS-POSNR, " DELIVERY ITEM NUMBER
LFIMG TYPE LIPS-LFIMG, " ACTUAL QUANTITY DELIVERED
END OF XT_LIPS.
**STRUCTURE FOR BILLING DOCUMENT HEADER -VBRK
TYPES: BEGIN OF XT_VBRK,
INVVBELN TYPE VBRK-VBELN, "BILLING DOCUMENT NUMBER
END OF XT_VBRK.
**STRUCTURE FOR BILLING DOCUMENT ITEM - VBRP
TYPES: BEGIN OF XT_VBRP,
INVPOSNR TYPE VBRP-POSNR, "BILLING ITEM NUMBER
FKIMG TYPE VBRP-FKIMG, "ACTUAL INVOICED QUANTITY
INVNETWR TYPE VBRP-NETWR, "NET VALUE OF THE BILLING ITEM
END OF XT_VBRP.
**STRUCTURE FOR FINAL INTERNAL TABLE.
TYPES: BEGIN OF XT_FINAL,
VBELN TYPE VBAK-VBELN,
DELVBELN TYPE LIKP-VBELN,
INVBELN TYPE VBRK-VBELN,
KUNNR TYPE VBAK-KUNNR,
POSNR TYPE VBAP-POSNR,
DELPOSNT TYPE LIPS-POSNR,
INVPOSNR TYPE VBRP-POSNR,
MATNR TYPE VBAP-MATNR,
KWMENG TYPE VBAP-KWMENG,
NETWR TYPE VBAP-NETWR,
INVNETWR TYPE VBRP-NETWR,
LFDAT TYPE LIKP-LFDAT,
LFIMG TYPE LIPS-LFIMG,
FKIMG TYPE VBRP-FKIMG,
NAME1 TYPE KNA1-NAME1,
END OF XT_FINAL.
**DATA DECLARATIONS
DATA: V_NAME1 TYPE KNA1-NAME1, "#EC *
V_DELVBELN TYPE LIKP-VBELN,
V_INVVBELN TYPE VBRK-VBELN,
V_BUKRS TYPE T001-BUKRS, "COMPANY CODE "#EC *
V_AUDAT TYPE VBAK-AUDAT,
V_VKORG TYPE VBAK-VKORG,
V_VKGRP TYPE VBAK-VKGRP,
V_SPART TYPE VBAK-SPART.
**INTERNAL TABLE DECLARATIONS
DATA: IT_VBAK TYPE STANDARD TABLE OF XT_VBAK,
WA_VBAK TYPE XT_VBAK,
IT_VBAP TYPE STANDARD TABLE OF XT_VBAP,
WA_VBAP TYPE XT_VBAP,
IT_LIKP TYPE STANDARD TABLE OF XT_LIKP,
WA_LIKP TYPE XT_LIKP,
IT_LIPS TYPE STANDARD TABLE OF XT_LIPS,
WA_LIPS TYPE XT_LIPS,
IT_VBRK TYPE STANDARD TABLE OF XT_VBRK,
WA_VBRK TYPE XT_VBRK,
IT_VBRP TYPE STANDARD TABLE OF XT_VBRP,
WA_VBRP TYPE XT_VBRP,
IT_FINAL TYPE STANDARD TABLE OF XT_FINAL,
WA_FINAL TYPE XT_FINAL.
**ALV DECLARATIONS
DATA: IT_FLDCAT TYPE SLIS_T_FIELDCAT_ALV,
WA_FLDCAT TYPE SLIS_FIELDCAT_ALV,
IT_LSTHDR TYPE SLIS_T_LISTHEADER,
WA_LSTHDR TYPE SLIS_LISTHEADER,
IT_EVENTS TYPE SLIS_T_EVENT,
WA_EVENTS TYPE SLIS_ALV_EVENT,
IT_SORT TYPE SLIS_T_SORTINFO_ALV,
IT_LAYOUT TYPE SLIS_LAYOUT_ALV.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECT-OPTIONS: S_BUKRS FOR V_BUKRS NO INTERVALS NO-EXTENSION,
S_VBELN FOR WA_VBAK-VBELN, "SALES DOCUMENT NUMBER
S_KUNNR FOR WA_VBAK-KUNNR, "SOLD-TO-PARTY
S_AUDAT FOR V_AUDAT, "SALES DOCUMENT DATE
S_VKORG FOR V_VKORG, "SALES ORGANISATION
S_VKGRP FOR V_VKGRP, "SALES GROUP
S_SPART FOR V_SPART. "DIVISION
SELECTION-SCREEN END OF BLOCK b1.
*****************SCREEN VALIDATION***************
AT SELECTION-SCREEN.
SELECT SINGLE BUKRS FROM T001 INTO V_BUKRS WHERE BUKRS IN S_BUKRS."#EC *
IF SY-SUBRC <> 0.
MESSAGE E000(Z_SD2) WITH 'ENTER A VALID COMPANY CODE'.
ENDIF.
SELECT SINGLE VBELN FROM VBAK INTO
CORRESPONDING FIELDS OF WA_VBAK WHERE VBELN IN S_VBELN.
IF SY-SUBRC <> 0.
MESSAGE E000(Z_SD2) WITH 'ENTER VALID SALES DOCUMENT NUMBER'.
ENDIF.
SELECT SINGLE KUNNR FROM VBAK INTO
CORRESPONDING FIELDS OF WA_VBAK WHERE KUNNR IN S_KUNNR. "EC *
IF SY-SUBRC <> 0.
MESSAGE E000(Z_SD2) WITH 'ENTER A VALID CUSTOMER NUMBER'.
ENDIF.
SELECT SINGLE AUDAT FROM VBAK INTO V_AUDAT WHERE AUDAT IN S_AUDAT."#EC *
IF SY-SUBRC <> 0.
MESSAGE E000(Z_SD2) WITH 'ENTER A VALID SALES DOCUMENT DATE'.
ENDIF.
SELECT SINGLE VKORG FROM VBAK INTO V_VKORG WHERE VKORG IN S_VKORG."#EC *
IF SY-SUBRC <> 0.
MESSAGE E000(Z_SD2) WITH 'ENTER A VALID SALES ORGANISATION'.
ENDIF.
SELECT SINGLE VKGRP FROM VBAK INTO V_VKGRP WHERE VKGRP IN S_VKGRP."#EC *
IF SY-SUBRC <> 0.
MESSAGE E000(Z_SD2) WITH 'ENTER A VALID SALES GROUP'.
ENDIF.
SELECT SINGLE SPART FROM VBAK INTO V_SPART WHERE SPART IN S_SPART."#EC *
IF SY-SUBRC <> 0.
MESSAGE E000(Z_SD2) WITH 'ENTER A VALID SALES DIVISION'.
ENDIF.
PERFORM GET_DATA.
*& Form GET_DATA
FORM GET_DATA .
SELECT VBELN KUNNR
INTO TABLE IT_VBAK
FROM VBAK
WHERE VBELN IN S_VBELN.
* BUKRS_VF IN S_BUKRS AND
* VKORG IN S_VKORG AND
* VKGRP IN S_VKGRP AND
* SPART IN S_SPART AND
* KUNNR IN S_KUNNR AND
* AUDAT IN S_AUDAT.
IF IT_VBAK[] IS NOT INITIAL.
SELECT POSNR MATNR KWMENG NETWR
INTO TABLE IT_VBAP
FROM VBAP
FOR ALL ENTRIES IN IT_VBAK
WHERE VBELN = IT_VBAK-VBELN.
ENDIF.
IF IT_VBAK[] IS NOT INITIAL.
SELECT VBELN LFDAT
INTO TABLE IT_LIKP
FROM LIKP
FOR ALL ENTRIES IN IT_VBAK
WHERE VBELN = IT_VBAK-VBELN.
ENDIF.
IF IT_VBAP[] IS NOT INITIAL.
SELECT POSNR LFIMG
INTO TABLE IT_LIPS
FROM LIPS
FOR ALL ENTRIES IN IT_VBAP
WHERE POSNR = IT_VBAP-POSNR.
ENDIF.
IF IT_LIKP[] IS NOT INITIAL.
SELECT VBELN
INTO TABLE IT_VBRK
FROM VBRK
FOR ALL ENTRIES IN IT_LIKP
WHERE VBELN = IT_LIKP-DELVBELN.
ENDIF.
IF IT_LIPS[] IS NOT INITIAL.
SELECT POSNR FKIMG NETWR
INTO TABLE IT_VBRP
FROM VBRP
FOR ALL ENTRIES IN IT_LIPS
WHERE POSNR = IT_LIPS-DELPOSNR.
ENDIF.
ENDFORM. " GET_DATA
Edited by: srk s on Jan 29, 2008 7:33 PM
Edited by: Alvaro Tejada Galindo on Jan 29, 2008 9:49 AMHi Satish,
I have started the new program but i have trouble with the final internal table. Since i'm using For all entries, I have declared internal tables for each table. My incomplete new program is as follows(not sure if the logic is correct till what I have coded):
*& Report Z_SDFLOW *
REPORT Z_SDFLOW NO STANDARD PAGE HEADING.
********* TABLES TO BE USED ***********************
**** VBAK - SALES DOCUMENT HEADER
* VBAP - SALES ITEM
* VBFA - SALES DOCUMENT FLOW
* KNA1- CUSTOMER MASTER
* VBRK - BILLING DOCUMENT HEADER
* VBRP - BLLING DOCUMENT ITEM
* LIKP - DELIVERY HEADER
* LIPS - DELIVERY ITEM
* TOO1 - COMPANY CODES
* SLIS.
TYPE-POOLS: SLIS.
** STRUCTURE DECLARATIONS ********
**STRUCTURE FOR ENQUIRY.
**STRUCTURE FOR QUOTATION.
**STRUCTURE FOR SALES ORDER HEADER- VBAK.
TYPES: BEGIN OF XT_VBAK,
VBELN TYPE VBAK-VBELN, "SALES DOCUMENT NUMBER
KUNNR TYPE VBAK-KUNNR, " SOLD-TO-PARTY
END OF XT_VBAK.
**STRUCTURE FOR SALES ORDER ITEM-VBAP
TYPES: BEGIN OF XT_VBAP,
POSNR TYPE VBAP-POSNR, " SALES ITEM NUMBER
MATNR TYPE VBAP-MATNR, " MATERIAL NUMBER
KWMENG TYPE VBAP-KWMENG, " CUMMULATIVE ORDER QUANTITY IN SALES UNITS
NETWR TYPE VBAP-NETWR, " NET VALUE OF THE ORDER ITEM
END OF XT_VBAP.
** STRUCTURE FOR DELIVERY HEADER -LIKP
TYPES: BEGIN OF XT_LIKP,
DELVBELN TYPE LIKP-VBELN, "DELIVERY DOCUMENT NUMBER
LFDAT TYPE LIKP-LFDAT, " DELIVERY DATE
END OF XT_LIKP.
**STRUCTURE FOR DELIVERY ITEM - LIPS
TYPES: BEGIN OF XT_LIPS,
DELPOSNR TYPE LIPS-POSNR, " DELIVERY ITEM NUMBER
LFIMG TYPE LIPS-LFIMG, " ACTUAL QUANTITY DELIVERED
END OF XT_LIPS.
**STRUCTURE FOR BILLING DOCUMENT HEADER -VBRK
TYPES: BEGIN OF XT_VBRK,
INVVBELN TYPE VBRK-VBELN, "BILLING DOCUMENT NUMBER
END OF XT_VBRK.
**STRUCTURE FOR BILLING DOCUMENT ITEM - VBRP
TYPES: BEGIN OF XT_VBRP,
INVPOSNR TYPE VBRP-POSNR, "BILLING ITEM NUMBER
FKIMG TYPE VBRP-FKIMG, "ACTUAL INVOICED QUANTITY
INVNETWR TYPE VBRP-NETWR, "NET VALUE OF THE BILLING ITEM
END OF XT_VBRP.
**STRUCTURE FOR FINAL INTERNAL TABLE.
TYPES: BEGIN OF XT_FINAL,
VBELN TYPE VBAK-VBELN,
DELVBELN TYPE LIKP-VBELN,
INVBELN TYPE VBRK-VBELN,
KUNNR TYPE VBAK-KUNNR,
POSNR TYPE VBAP-POSNR,
DELPOSNT TYPE LIPS-POSNR,
INVPOSNR TYPE VBRP-POSNR,
MATNR TYPE VBAP-MATNR,
KWMENG TYPE VBAP-KWMENG,
NETWR TYPE VBAP-NETWR,
INVNETWR TYPE VBRP-NETWR,
LFDAT TYPE LIKP-LFDAT,
LFIMG TYPE LIPS-LFIMG,
FKIMG TYPE VBRP-FKIMG,
NAME1 TYPE KNA1-NAME1,
END OF XT_FINAL.
**DATA DECLARATIONS
DATA: V_NAME1 TYPE KNA1-NAME1, "#EC *
V_DELVBELN TYPE LIKP-VBELN,
V_INVVBELN TYPE VBRK-VBELN,
V_BUKRS TYPE T001-BUKRS, "COMPANY CODE "#EC *
V_AUDAT TYPE VBAK-AUDAT,
V_VKORG TYPE VBAK-VKORG,
V_VKGRP TYPE VBAK-VKGRP,
V_SPART TYPE VBAK-SPART.
**INTERNAL TABLE DECLARATIONS
DATA: IT_VBAK TYPE STANDARD TABLE OF XT_VBAK,
WA_VBAK TYPE XT_VBAK,
IT_VBAP TYPE STANDARD TABLE OF XT_VBAP,
WA_VBAP TYPE XT_VBAP,
IT_LIKP TYPE STANDARD TABLE OF XT_LIKP,
WA_LIKP TYPE XT_LIKP,
IT_LIPS TYPE STANDARD TABLE OF XT_LIPS,
WA_LIPS TYPE XT_LIPS,
IT_VBRK TYPE STANDARD TABLE OF XT_VBRK,
WA_VBRK TYPE XT_VBRK,
IT_VBRP TYPE STANDARD TABLE OF XT_VBRP,
WA_VBRP TYPE XT_VBRP,
IT_FINAL TYPE STANDARD TABLE OF XT_FINAL,
WA_FINAL TYPE XT_FINAL.
**ALV DECLARATIONS
DATA: IT_FLDCAT TYPE SLIS_T_FIELDCAT_ALV,
WA_FLDCAT TYPE SLIS_FIELDCAT_ALV,
IT_LSTHDR TYPE SLIS_T_LISTHEADER,
WA_LSTHDR TYPE SLIS_LISTHEADER,
IT_EVENTS TYPE SLIS_T_EVENT,
WA_EVENTS TYPE SLIS_ALV_EVENT,
IT_SORT TYPE SLIS_T_SORTINFO_ALV,
IT_LAYOUT TYPE SLIS_LAYOUT_ALV.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECT-OPTIONS: S_BUKRS FOR V_BUKRS NO INTERVALS NO-EXTENSION,
S_VBELN FOR WA_VBAK-VBELN, "SALES DOCUMENT NUMBER
S_KUNNR FOR WA_VBAK-KUNNR, "SOLD-TO-PARTY
S_AUDAT FOR V_AUDAT, "SALES DOCUMENT DATE
S_VKORG FOR V_VKORG, "SALES ORGANISATION
S_VKGRP FOR V_VKGRP, "SALES GROUP
S_SPART FOR V_SPART. "DIVISION
SELECTION-SCREEN END OF BLOCK b1.
*****************SCREEN VALIDATION***************
AT SELECTION-SCREEN.
SELECT SINGLE BUKRS FROM T001 INTO V_BUKRS WHERE BUKRS IN S_BUKRS."#EC *
IF SY-SUBRC <> 0.
MESSAGE E000(Z_SD2) WITH 'ENTER A VALID COMPANY CODE'.
ENDIF.
SELECT SINGLE VBELN FROM VBAK INTO
CORRESPONDING FIELDS OF WA_VBAK WHERE VBELN IN S_VBELN.
IF SY-SUBRC <> 0.
MESSAGE E000(Z_SD2) WITH 'ENTER VALID SALES DOCUMENT NUMBER'.
ENDIF.
SELECT SINGLE KUNNR FROM VBAK INTO
CORRESPONDING FIELDS OF WA_VBAK WHERE KUNNR IN S_KUNNR. "EC *
IF SY-SUBRC <> 0.
MESSAGE E000(Z_SD2) WITH 'ENTER A VALID CUSTOMER NUMBER'.
ENDIF.
SELECT SINGLE AUDAT FROM VBAK INTO V_AUDAT WHERE AUDAT IN S_AUDAT."#EC *
IF SY-SUBRC <> 0.
MESSAGE E000(Z_SD2) WITH 'ENTER A VALID SALES DOCUMENT DATE'.
ENDIF.
SELECT SINGLE VKORG FROM VBAK INTO V_VKORG WHERE VKORG IN S_VKORG."#EC *
IF SY-SUBRC <> 0.
MESSAGE E000(Z_SD2) WITH 'ENTER A VALID SALES ORGANISATION'.
ENDIF.
SELECT SINGLE VKGRP FROM VBAK INTO V_VKGRP WHERE VKGRP IN S_VKGRP."#EC *
IF SY-SUBRC <> 0.
MESSAGE E000(Z_SD2) WITH 'ENTER A VALID SALES GROUP'.
ENDIF.
SELECT SINGLE SPART FROM VBAK INTO V_SPART WHERE SPART IN S_SPART."#EC *
IF SY-SUBRC <> 0.
MESSAGE E000(Z_SD2) WITH 'ENTER A VALID SALES DIVISION'.
ENDIF.
PERFORM GET_DATA.
*& Form GET_DATA
FORM GET_DATA .
SELECT VBELN KUNNR
INTO TABLE IT_VBAK
FROM VBAK
WHERE VBELN IN S_VBELN.
* BUKRS_VF IN S_BUKRS AND
* VKORG IN S_VKORG AND
* VKGRP IN S_VKGRP AND
* SPART IN S_SPART AND
* KUNNR IN S_KUNNR AND
* AUDAT IN S_AUDAT.
IF IT_VBAK[] IS NOT INITIAL.
SELECT POSNR MATNR KWMENG NETWR
INTO TABLE IT_VBAP
FROM VBAP
FOR ALL ENTRIES IN IT_VBAK
WHERE VBELN = IT_VBAK-VBELN.
ENDIF.
IF IT_VBAK[] IS NOT INITIAL.
SELECT VBELN LFDAT
INTO TABLE IT_LIKP
FROM LIKP
FOR ALL ENTRIES IN IT_VBAK
WHERE VBELN = IT_VBAK-VBELN.
ENDIF.
IF IT_VBAP[] IS NOT INITIAL.
SELECT POSNR LFIMG
INTO TABLE IT_LIPS
FROM LIPS
FOR ALL ENTRIES IN IT_VBAP
WHERE POSNR = IT_VBAP-POSNR.
ENDIF.
IF IT_LIKP[] IS NOT INITIAL.
SELECT VBELN
INTO TABLE IT_VBRK
FROM VBRK
FOR ALL ENTRIES IN IT_LIKP
WHERE VBELN = IT_LIKP-DELVBELN.
ENDIF.
IF IT_LIPS[] IS NOT INITIAL.
SELECT POSNR FKIMG NETWR
INTO TABLE IT_VBRP
FROM VBRP
FOR ALL ENTRIES IN IT_LIPS
WHERE POSNR = IT_LIPS-DELPOSNR.
ENDIF.
ENDFORM. " GET_DATA
Code Formatted by: Alvaro Tejada Galindo on Jan 29, 2008 9:48 AM -
I NEED select ..... for all entries for this logic
From table RBDRSEG, we need to pick up the field RBDRSEG-MATNR where RBDRSEG- RBLNR= RBKP-BELNR. If the program does not find any data then it can pick up the material id field from EKPO-MATNR for all the invoices picked up during the processing.
Hi,
Lets say that Invoices are in Int table ITAB.
IF NOT ITAB[] IS INITIAL.
SELECT MATNR FROM RBDRSEG INTO V_MATNR
for all entries in itab
where RBLNR= ITAB-BELNR.
IF SY-SUBRC <> 0.
SELECT MATNR FROM RSEG INTO V_MATNR
for all entries in ITAB
where BELNR= ITAB-BELNR.
ENDIF.
ENDIF.
Use RSEG instead of EKPO because EKPO don't have BELNR(Invoice) field.
Regards,
Anji
Message was edited by:
Anji Reddy Vangala
Message was edited by:
Anji Reddy Vangala -
Performance issue with select query and for all entries.
hi,
i have a report to be performance tuned.
the database table has around 20 million entries and 25 fields.
so, the report fetches the distinct values of two fields using one select query.
so, the first select query fetches around 150 entries from the table for 2 fields.
then it applies some logic and eliminates some entries and makes entries around 80-90...
and then it again applies the select query on the same table using for all entries applied on the internal table with 80-90 entries...
in short,
it accesses the same database table twice.
so, i tried to get the database table in internal table and apply the logic on internal table and delete the unwanted entries.. but it gave me memory dump, and it wont take that huge amount of data into abap memory...
is around 80-90 entries too much for using "for all entries"?
the logic that is applied to eliminate the entries from internal table is too long, and hence cannot be converted into where clause to convert it into single select..
i really cant find the way out...
please help.chinmay kulkarni wrote:Chinmay,
Even though you tried to ask the question with detailed explanation, unfortunately it is still not clear.
It is perfectly fine to access the same database twice. If that is working for you, I don't think there is any need to change the logic. As Rob mentioned, 80 or 8000 records is not a problem in "for all entries" clause.
>
> so, i tried to get the database table in internal table and apply the logic on internal table and delete the unwanted entries.. but it gave me memory dump, and it wont take that huge amount of data into abap memory...
>
It is not clear what you tried to do here. Did you try to bring all 20 million records into an internal table? That will certainly cause the program to short dump with memory shortage.
> the logic that is applied to eliminate the entries from internal table is too long, and hence cannot be converted into where clause to convert it into single select..
>
That is fine. Actually, it is better (performance wise) to do much of the work in ABAP than writing a complex WHERE clause that might bog down the database. -
Plz help me out with for all entries
hi to all experts,
This is my sample code plz tell me how to output the data.plz help me out.im very much beginner in ABAP and i dont want to use loop and endloop is there any way
REPORT Z_FORALLENTERIES .
types : begin of ty_lfa1,
lifnr type lfa1-lifnr,
name1 type lfa1-name1,
land1 type lfa1-land1,
end of ty_lfa1.
types : begin of ty_lfb1 ,
lifnr type lfb1-lifnr,
bukrs type lfb1-bukrs,
pernr type lfb1-pernr,
end of ty_lfb1.
types : begin of ty_lfc1 ,
lifnr type lfc1-lifnr,
gjahr type lfc1-gjahr,
usnam type lfc1-usnam,
end of ty_lfc1.
types : begin of ty_lfbk ,
lifnr type lfbk-lifnr,
banks type lfbk-banks,
bankl type lfbk-bankl,
bankn type lfbk-bankn,
end of ty_lfbk.
types : begin of ty_final,
lifnr type lfa1-lifnr,
name1 type lfa1-name1,
land1 type lfa1-land1,
bukrs type lfb1-bukrs,
pernr type lfb1-pernr,
gjahr type lfc1-gjahr,
usnam type lfc1-usnam,
banks type lfbk-banks,
bankl type lfbk-bankl,
bankn type lfbk-bankn,
end of ty_final.
data : it_lfa1 type standard table of ty_lfa1 initial size 0 with header line.
data : it_lfb1 type standard table of ty_lfb1 initial size 0 with header line.
data : it_lfc1 type standard table of ty_lfc1 initial size 0 with header line.
*--internal for outputting data--
data : it_lfbk type standard table of ty_lfbk initial size 0 with header line.
data : it_final type standard table of ty_final initial size 0,
wa_final like line of it_final.
select lifnr name1 land1
into table it_lfa1[]
from lfa1 up to 10 rows.
if it_lfa1[] is not initial.
select lifnr bukrs pernr
into table it_lfb1[]
from lfb1
for all entries in it_lfa1[]
where lifnr eq it_lfa1-lifnr.
endif.
if it_lfb1[] is not initial.
select lifnr gjahr usnam
into table it_lfc1[]
from lfc1
for all entries in it_lfb1[]
where lifnr eq it_lfb1-lifnr.
endif.
if it_lfc1[] is not initial.
select lifnr banks bankl bankn
into table it_lfbk[]
from lfbk
for all entries in it_lfc1[]
where lifnr eq it_lfc1-lifnr.
endif.Hi
see this program almost same req
**************DATA TYPES DECLARATION **********************
TABLES: HRP1001, HRP1026, HRP1000,PCHDY.
TYPE-POOLS SLIS.
TYPES :BEGIN OF ST_OUTPUT,
COUNT TYPE STRING,
OBJID TYPE HRP1001-OBJID,
STEXT TYPE HRP1000-STEXT,
BEGDA TYPE HRP1000-BEGDA,
ENDDA TYPE HRP1000-ENDDA,
CANCRT TYPE T77CRT-CANCRT,
AEDTM TYPE HRP1026-AEDTM,
UNAME TYPE HRP1026-UNAME,
LSTEXT TYPE HRP1000-STEXT,
RINVT TYPE T777V-RINVT,
END OF ST_OUTPUT.
TYPES: BEGIN OF ST_HRP1000,
OBJID TYPE HRP1001-OBJID,
STEXT TYPE HRP1000-STEXT,
END OF ST_HRP1000.
TYPES : BEGIN OF ST_HRP1001,
OTYPE TYPE HRP1001-OTYPE,
OBJID TYPE HRP1001-OBJID,
RELAT type hrp1001-RELAT,
BEGDA TYPE HRP1001-BEGDA,
ENDDA TYPE HRP1001-ENDDA,
SCLAS TYPE HRP1001-SCLAS,
SOBID TYPE HRP1001-SOBID,
END OF ST_HRP1001.
TYPES : BEGIN OF ST_HRP1026,
OTYPE TYPE HRP1026-OTYPE,
OBJID TYPE HRP1001-OBJID,
AEDTM TYPE HRP1026-AEDTM,
UNAME TYPE HRP1026-UNAME,
DELET TYPE HRP1026-DELET,
CANCR TYPE HRP1026-CANCR,
END OF ST_HRP1026.
TYPES : BEGIN OF ST_REASON,
CANCR TYPE HRP1026-CANCR,
CANCRT TYPE T77CRT-CANCRT,
END OF ST_REASON.
TYPES : BEGIN OF ST_SOBID,
OTYPE TYPE HRP1001-OTYPE,
OBJID TYPE HRP1001-OBJID,
RELAT type hrp1001-OBJID,
BEGDA TYPE HRP1001-BEGDA,
ENDDA TYPE HRP1001-ENDDA,
SCLAS TYPE HRP1001-SCLAS,
SOBID TYPE HRP1001-OBJID,
END OF ST_SOBID.
TYPES : BEGIN OF ST_OBJID,
OBJID TYPE HRP1001-OBJID,
END OF ST_OBJID.
TYPES : BEGIN OF ST_LOCATION,
OTYPE TYPE HRP1001-OTYPE,
OBJID TYPE HRP1001-OBJID,
RSIGN TYPE HRP1001-RSIGN,
RELAT TYPE HRP1001-RELAT,
SCLAS TYPE HRP1001-SCLAS,
SOBID TYPE HRP1001-SOBID,
END OF ST_LOCATION.
TYPES : BEGIN OF ST_LOCATION1,
OTYPE TYPE HRP1001-OTYPE,
OBJID TYPE HRP1001-OBJID,
RSIGN TYPE HRP1001-RSIGN,
RELAT TYPE HRP1001-RELAT,
SCLAS TYPE HRP1001-SCLAS,
SOBID TYPE HRP1001-OBJID,
END OF ST_LOCATION1.
TYPES : BEGIN OF ST_LSTEXT,
OTYPE TYPE HRP1000-OTYPE,
OBJID TYPE HRP1000-OBJID,
LSTEXT TYPE HRP1000-STEXT,
END OF ST_LSTEXT.
TYPES : BEGIN OF ST_OBJID_SH,
OTYPE TYPE HRP1000-OTYPE,
OBJID TYPE HRP1000-OBJID,
END OF ST_OBJID_SH.
DATA : IT_OBJID_SH TYPE STANDARD TABLE OF ST_OBJID_SH.
DATA : WA_OBJID_SH TYPE ST_OBJID_SH.
DATA : IT_LSTEXT TYPE STANDARD TABLE OF ST_LSTEXT. "TOS STORE THE TEXT OF COURCE LOCATION
DATA : WA_LSTEXT TYPE ST_LSTEXT.
DATA : IT_LOCATION TYPE STANDARD TABLE OF ST_LOCATION. " TO STORE THE LOCATION OF COURCE
DATA : WA_LOCATION TYPE ST_LOCATION.
DATA : IT_LOCATION1 TYPE STANDARD TABLE OF ST_LOCATION1. " TO CONVERT SOBID INTO OBJID FOR COURCE LOCATION
DATA : WA_LOCATION1 TYPE ST_LOCATION1.
DATA : IT_SOBID TYPE STANDARD TABLE OF ST_SOBID. " TO CHANGE THE SOBID OF HRP1001 TO OBJID OF HRP1026
DATA : WA_SOBID TYPE ST_SOBID. " BY USING FOR ALL ENTRIES
DATA : IT_REASON TYPE STANDARD TABLE OF ST_REASON. "TO STORE T HE REASON FOR CANCELL TEXT
DATA : WA_REASON TYPE ST_REASON.
DATA : IT_OUTPUT TYPE STANDARD TABLE OF ST_OUTPUT. "OUTPUT FEILDS OF REPORT.
DATA : WA_OUTPUT TYPE ST_OUTPUT.
DATA : IT_OUTPUT_1 TYPE STANDARD TABLE OF ST_OUTPUT. " TEMP OUTPUT FEILDS OF REPORT.
DATA : WA_OUTPUT_1 TYPE ST_OUTPUT.
DATA : IT_HRP1000 TYPE STANDARD TABLE OF ST_HRP1000. "DATA FROM HRP1000 TABLE
DATA : WA_HRP1000 TYPE ST_HRP1000.
DATA : IT_HRP1001 TYPE STANDARD TABLE OF ST_HRP1001. "DATA FROM HRP1001 TABLE
DATA : WA_HRP1001 TYPE ST_HRP1001.
DATA : IT_HRP1026 TYPE STANDARD TABLE OF ST_HRP1026. "DATA FROM HRP1026 TABLE
DATA : WA_HRP1026 TYPE ST_HRP1026.
DATA : IT_OBJID TYPE STANDARD TABLE OF ST_OBJID. " TO STORE THE OBJID OF HRP1001
DATA : WA_OBJID TYPE ST_OBJID.
DATA: WS_FCAT TYPE SLIS_FIELDCAT_ALV . " FEILDCATALOG FOR ALV REPORT
DATA: IN_FCAT TYPE SLIS_T_FIELDCAT_ALV.
DATA: W_LAYOUT TYPE SLIS_LAYOUT_ALV.
DATA : LV_COUNT TYPE I. "FEILD FOR SERIAL NUMBER
***************************END OF DATA DECLARATION******************************************
***********SELECTION SCREEN DESIGN***********************
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
*SELECT-OPTIONS : S_OTYPE FOR HRP1001-OTYPE NO INTERVALS .
SELECT-OPTIONS : S_OBJID FOR HRP1001-OBJID NO INTERVALS .
SELECT-OPTIONS : DATE FOR SY-DATUM NO-EXTENSION OBLIGATORY.
SELECTION-SCREEN END OF BLOCK B1.
**********END OF SELECTION SCREEN DESIGN*****************
*****INITIALIZATION VENT TO ASIGN DEFAULT VALUES TO OTYPE
*INITIALIZATION.
S_OTYPE-LOW = 'D'.
S_OTYPE-SIGN = 'I'.
S_OTYPE-OPTION = 'EQ'.
APPEND S_OTYPE.
CLEAR S_OTYPE.
*************END OF EVENT INITIALIZATION*****************
*********VALIDATION FOR SCREEN FIELDS********************
AT SELECTION-SCREEN ON VALUE-REQUEST FOR S_OBJID-LOW.
IF S_OBJID IS NOT INITIAL.
SELECT OTYPE OBJID FROM HRP1000
INTO TABLE IT_OBJID_SH
WHERE OTYPE = 'D'.
IF SY-SUBRC EQ 0.
SEARCH HELP FOR QUALIFICATION.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
DDIC_STRUCTURE = ' '
RETFIELD = 'OBJID'
PVALKEY = ' '
DYNPPROG = SY-REPID
DYNPNR = SY-DYNNR
DYNPROFIELD = 'S_OBJID'
STEPL = 0
WINDOW_TITLE =
VALUE = ' '
VALUE_ORG = 'S'
MULTIPLE_CHOICE = ' '
DISPLAY = ' '
CALLBACK_PROGRAM = ' '
CALLBACK_FORM = ' '
MARK_TAB =
IMPORTING
USER_RESET =
TABLES
VALUE_TAB = IT_OBJID_SH
FIELD_TAB =
RETURN_TAB = RETURN_TAB
DYNPFLD_MAPPING =
EXCEPTIONS
PARAMETER_ERROR = 1
NO_VALUES_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.
ENDIF.
IF SY-SUBRC NE 0.
MESSAGE 'NO RECORD FOUND FOR THE GIVEN SELECTION CRITERIA.' TYPE 'E'.
ENDIF.
ENDIF.
REFRESH IT_OBJID.
***************VALIDATION OF SCREEN FIELDS ENDS***********
*****************START OF SELECTION ************************
START-OF-SELECTION.
SELECT OTYPE
OBJID
RELAT
BEGDA
ENDDA
SCLAS
SOBID FROM HRP1001 INTO TABLE IT_HRP1001
WHERE OTYPE = 'D'
AND OBJID IN S_OBJID
AND BEGDA GE DATE-LOW
AND ENDDA LE DATE-HIGH
AND ( SCLAS = 'E' OR SCLAS = 'ET' ).
IF SY-SUBRC NE 0.
MESSAGE 'NO RECORD FOUND FOR THE GIVEN SELECTION CRITERIA ' TYPE 'E'.
ENDIF.
LOOP AT IT_HRP1001 INTO WA_HRP1001.
WA_SOBID-OTYPE = WA_HRP1001-OTYPE.
WA_SOBID-OBJID = WA_HRP1001-OBJID.
WA_SOBID-RELAT = WA_HRP1001-RELAT.
WA_SOBID-BEGDA = WA_HRP1001-BEGDA.
WA_SOBID-ENDDA = WA_HRP1001-ENDDA.
WA_SOBID-SCLAS = WA_HRP1001-SCLAS.
WA_SOBID-SOBID = WA_HRP1001-SOBID.
APPEND WA_SOBID TO IT_SOBID.
ENDLOOP.
SELECT OTYPE
OBJID
AEDTM
UNAME
DELET
CANCR
NCONT
FROM HRP1026
INTO TABLE IT_HRP1026
FOR ALL ENTRIES IN IT_SOBID
WHERE OBJID = IT_SOBID-SOBID
AND ( OTYPE = 'E' OR OTYPE = 'ET' )
AND DELET = 'X' AND
BEGDA GE DATE-LOW AND
ENDDA LE DATE-HIGH.
IF SY-SUBRC EQ 0.
SELECT OBJID
STEXT
FROM HRP1000
INTO TABLE IT_HRP1000
FOR ALL ENTRIES IN IT_SOBID
WHERE OBJID = IT_SOBID-SOBID AND
BEGDA GE DATE-LOW AND
ENDDA LE DATE-HIGH.
SELECT CANCR
CANCRT
FROM T77CRT
INTO TABLE IT_REASON
FOR ALL ENTRIES IN IT_HRP1026
WHERE CANCR = IT_HRP1026-CANCR
AND LANGU = 'E' .
********PERFORM FOR GETTING T HE LOCATION OF THE COURCE**
PERFORM GET_LOCATION.
**************END OF LOCATION OF COURCE ******************
ELSE.
MESSAGE 'NO RECORD FOUND FOR THE GIVEN SELECTION CRITERIA ' TYPE 'E'.
ENDIF.
*****PERFORM FOR GETTING DATA INTO THE FINAL INTERNAL TABLE IT_OUTPUT**
PERFORM GET_DATA.
*********************************END OF PERFORM ET DATA ***************
***********LOGIC FOR PRONTING NUMBER OF RECORDS ***********************
LV_COUNT = 0.
LOOP AT IT_OUTPUT INTO WA_OUTPUT.
LV_COUNT = LV_COUNT + 1.
WA_OUTPUT-COUNT = LV_COUNT.
APPEND WA_OUTPUT TO IT_OUTPUT_1.
ENDLOOP.
REFRESH IT_OUTPUT.
IT_OUTPUT = IT_OUTPUT_1.
********************END OF LOGIC FOR NUMBER OF RECORDS ***************
****************DISPLAYING OUTPUT BY USEING GRID DISPLAY**********
PERFORM ALV_DISPLAY.
****************************END OF PERFORM FOR DISPLAYING **********
*& Form PERFORM_ALV
DISPLAY THE RECORDS IN ALV GRID FORMAT.
FORM ALV_DISPLAY.
PERFORM FIELD_CATALOG USING 'COUNT' 'Sr. No.'.
PERFORM FIELD_CATALOG USING 'OBJID' 'COURCE ID.'.
PERFORM FIELD_CATALOG USING 'STEXT' 'COURCE NAME'.
PERFORM FIELD_CATALOG USING 'LSTEXT' 'COURCE LOATION'.
PERFORM FIELD_CATALOG USING 'BEGDA' 'BEGIN DATE '.
PERFORM FIELD_CATALOG USING 'ENDDA' 'END DATE '.
PERFORM FIELD_CATALOG USING 'CANCRT' 'REASON'.
PERFORM FIELD_CATALOG USING 'AEDTM' 'DATE Of CANCEL'.
PERFORM FIELD_CATALOG USING 'NCONT' 'NUMBER OF BOOKINGS'.
PERFORM FIELD_CATALOG USING 'LOCTX' 'COURCE LOCATION'.
PERFORM FIELD_CATALOG USING 'UNAME' 'WHO CANCELLED'.
PERFORM FIELD_CATALOG USING 'LSTEXT' 'COURCE LOATION'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_STRUCTURE_NAME = 'IT_OUTPUT'
I_GRID_TITLE = ' Cancelled courses with reason '
IT_FIELDCAT = IN_FCAT
TABLES
T_OUTTAB = IT_OUTPUT.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. "PERFORM_ALV
*& Form FIELD_CATALOG
text
-->FIELD_NAME text
-->DIS_TEXT text
FORM FIELD_CATALOG USING FIELD_NAME DIS_TEXT.
CLEAR WS_FCAT.
WS_FCAT-TABNAME = 'IT_OUTPUT'.
WS_FCAT-FIELDNAME = FIELD_NAME.
WS_FCAT-SELTEXT_M = DIS_TEXT.
APPEND WS_FCAT TO IN_FCAT .
ENDFORM. "FIELD_CATALOG
*& Form GET_DATA
text
--> p1 text
<-- p2 text
FORM GET_DATA .
*sort it_sobid by objid.
LOOP AT IT_SOBID INTO WA_SOBID." where otype eq s_otype and objid eq s_objid.
READ TABLE IT_HRP1026 WITH KEY OBJID = WA_SOBID-SOBID OTYPE = WA_SOBID-SCLAS INTO WA_HRP1026.
IF SY-SUBRC EQ 0.
READ TABLE IT_HRP1000 WITH KEY OBJID = WA_SOBID-SOBID INTO WA_HRP1000.
READ TABLE IT_REASON WITH KEY CANCR = WA_HRP1026-CANCR INTO WA_REASON.
WA_OUTPUT-OBJID = WA_HRP1026-OBJID.
WA_OUTPUT-BEGDA = WA_SOBID-BEGDA.
WA_OUTPUT-ENDDA = WA_SOBID-ENDDA.
WA_OUTPUT-AEDTM = WA_HRP1026-AEDTM.
WA_OUTPUT-UNAME = WA_HRP1026-UNAME.
WA_OUTPUT-NCONT = WA_HRP1026-NCONT.
READ TABLE IT_HRP1000 WITH KEY OBJID = WA_SOBID-SOBID INTO WA_HRP1000.
WA_OUTPUT-STEXT = WA_HRP1000-STEXT.
READ TABLE IT_REASON WITH KEY CANCR = WA_HRP1026-CANCR INTO WA_REASON.
WA_OUTPUT-CANCRT = WA_REASON-CANCRT.
CLEAR WA_REASON-CANCRT.
READ TABLE IT_LOCATION1 WITH KEY OBJID = WA_HRP1026-OBJID INTO WA_LOCATION1..
READ TABLE IT_LSTEXT WITH KEY OBJID = WA_LOCATION1-SOBID OTYPE = 'F' INTO WA_LSTEXT.
WA_OUTPUT-LSTEXT = WA_LSTEXT-LSTEXT.
CLEAR WA_LSTEXT-LSTEXT.
APPEND WA_OUTPUT TO IT_OUTPUT.
CLEAR WA_OUTPUT.
CLEAR WA_OUTPUT-CANCRT.
ENDIF.
ENDLOOP.
ENDFORM. " GET_DATA
*& Form GET_LOCATION
text
--> p1 text
<-- p2 text
FORM GET_LOCATION .
SELECT OTYPE
OBJID
RSIGN
RELAT
SCLAS
SOBID
FROM HRP1001
INTO TABLE IT_LOCATION
FOR ALL ENTRIES IN IT_HRP1026
WHERE OTYPE = 'E' AND OBJID = IT_HRP1026-OBJID
AND RSIGN = 'A' AND RELAT = '024' AND SCLAS = 'F'
AND BEGDA GE DATE-LOW AND ENDDA LE DATE-HIGH.
IF SY-SUBRC NE 0.
MESSAGE 'NO RECORD FOUND FOR THE GIVEN SELECTION CRITERIA ' TYPE 'E'.
ENDIF.
LOOP AT IT_LOCATION INTO WA_LOCATION.
WA_LOCATION1-OTYPE = WA_LOCATION-OTYPE.
WA_LOCATION1-OBJID = WA_LOCATION-OBJID.
WA_LOCATION1-RSIGN = WA_LOCATION-RSIGN.
WA_LOCATION1-RELAT = WA_LOCATION-RELAT.
WA_LOCATION1-SCLAS = WA_LOCATION-SCLAS.
WA_LOCATION1-SOBID = WA_LOCATION-SOBID.
APPEND WA_LOCATION1 TO IT_LOCATION1.
CLEAR WA_LOCATION1.
ENDLOOP.
SELECT OTYPE
OBJID
STEXT
FROM HRP1000
INTO TABLE IT_LSTEXT
FOR ALL ENTRIES IN IT_LOCATION1
WHERE OBJID = IT_LOCATION1-SOBID
AND OTYPE = 'F'.
AND BEGDA GE DATE-LOW
AND ENDDA LE DATE-HIGH.
ENDFORM. " GET_LOCATION
<b>Reward if usefull</b> -
Hi guru's what is the diff between for all entries & joins
hi guru's what is the diff between for all entries & joins
Hi Vasu,
Joins are used to fetch data fast from Database tables:
Tables are joined with the proper key fields to fetch the data properly.
If there are no proper key fields between tables don't use Joins;
Important thing is that don't USE JOINS FOR CLUSTER tableslike BSEG and KONV.
Only use for Transparenmt tables.
You can also use joins for the database VIews to fetch the data.
JOINS
... FROM tabref1 [INNER] JOIN tabref2 ON cond
Effect
The data is to be selected from transparent database tables and/or views determined by tabref1 and tabref2. tabref1 and tabref2 each have the same form as in variant 1 or are themselves Join expressions. The keyword INNER does not have to be specified. The database tables or views determined by tabref1 and tabref2 must be recognized by the ABAP Dictionary.
In a relational data structure, it is quite normal for data that belongs together to be split up across several tables to help the process of standardization (see relational databases). To regroup this information into a database query, you can link tables using the join command. This formulates conditions for the columns in the tables involved. The inner join contains all combinations of lines from the database table determined by tabref1 with lines from the table determined by tabref2, whose values together meet the logical condition (join condition) specified using ON>cond.
Inner join between table 1 and table 2, where column D in both tables in the join condition is set the same:
Table 1 Table 2
A
B
C
D
D
E
F
G
H
a1
b1
c1
1
1
e1
f1
g1
h1
a2
b2
c2
1
3
e2
f2
g2
h2
a3
b3
c3
2
4
e3
f3
g3
h3
a4
b4
c4
3
|--|||--|
Inner Join
A
B
C
D
D
E
F
G
H
a1
b1
c1
1
1
e1
f1
g1
h1
a2
b2
c2
1
1
e1
f1
g1
h1
a4
b4
c4
3
3
e2
f2
g2
h2
|--||||||||--|
Example
Output a list of all flights from Frankfurt to New York between September 10th and 20th, 2001 that are not sold out:
DATA: DATE LIKE SFLIGHT-FLDATE,
CARRID LIKE SFLIGHT-CARRID,
CONNID LIKE SFLIGHT-CONNID.
SELECT FCARRID FCONNID F~FLDATE
INTO (CARRID, CONNID, DATE)
FROM SFLIGHT AS F INNER JOIN SPFLI AS P
ON FCARRID = PCARRID AND
FCONNID = PCONNID
WHERE P~CITYFROM = 'FRANKFURT'
AND P~CITYTO = 'NEW YORK'
AND F~FLDATE BETWEEN '20010910' AND '20010920'
AND FSEATSOCC < FSEATSMAX.
WRITE: / DATE, CARRID, CONNID.
ENDSELECT.
If there are columns with the same name in both tables, you must distinguish between them by prefixing the field descriptor with the table name or a table alias.
Note
In order to determine the result of a SELECT command where the FROM clause contains a join, the database system first creates a temporary table containing the lines that meet the ON condition. The WHERE condition is then applied to the temporary table. It does not matter in an inner join whether the condition is in the ON or WHEREclause. The following example returns the same solution as the previous one.
Example
Output of a list of all flights from Frankfurt to New York between September 10th and 20th, 2001 that are not sold out:
DATA: DATE LIKE SFLIGHT-FLDATE,
CARRID LIKE SFLIGHT-CARRID,
CONNID LIKE SFLIGHT-CONNID.
SELECT FCARRID FCONNID F~FLDATE
INTO (CARRID, CONNID, DATE)
FROM SFLIGHT AS F INNER JOIN SPFLI AS P
ON FCARRID = PCARRID
WHERE FCONNID = PCONNID
AND P~CITYFROM = 'FRANKFURT'
AND P~CITYTO = 'NEW YORK'
AND F~FLDATE BETWEEN '20010910' AND '20010920'
AND FSEATSOCC < FSEATSMAX.
WRITE: / DATE, CARRID, CONNID.
ENDSELECT.
Note
Since not all of the database systems supported by SAP use the standard syntax for ON conditions, the syntax has been restricted. It only allows those joins that produce the same results on all of the supported database systems:
Only a table or view may appear to the right of the JOIN operator, not another join expression.
Only AND is possible in the ON condition as a logical operator.
Each comparison in the ON condition must contain a field from the right-hand table.
If an outer join occurs in the FROM clause, all the ON conditions must contain at least one "real" JOIN condition (a condition that contains a field from tabref1 amd a field from tabref2.
Note
In some cases, '*' may be specified in the SELECT clause, and an internal table or work area is entered into the INTO clause (instead of a list of fields). If so, the fields are written to the target area from left to right in the order in which the tables appear in the FROM clause, according to the structure of each table work area. There can then be gaps between table work areas if you use an Alignment Request. For this reason, you should define the target work area with reference to the types of the database tables, not simply by counting the total number of fields. For an example, see below:
Variant 3
... FROM tabref1 LEFT [OUTER] JOIN tabref2 ON cond
Effect
Selects the data from the transparent database tables and/or views specified in tabref1 and tabref2. tabref1 und tabref2 both have either the same form as in variant 1 or are themselves join expressions. The keyword OUTER can be omitted. The database tables or views specified in tabref1 and tabref2 must be recognized by the ABAP-Dictionary.
In order to determine the result of a SELECT command where the FROM clause contains a left outer join, the database system creates a temporary table containing the lines that meet the ON condition. The remaining fields from the left-hand table (tabref1) are then added to this table, and their corresponding fields from the right-hand table are filled with ZERO values. The system then applies the WHERE condition to the table.
Left outer join between table 1 and table 2 where column D in both tables set the join condition:
Table 1 Table 2
A
B
C
D
D
E
F
G
H
a1
b1
c1
1
1
e1
f1
g1
h1
a2
b2
c2
1
3
e2
f2
g2
h2
a3
b3
c3
2
4
e3
f3
g3
h3
a4
b4
c4
3
|--|||--|
Left Outer Join
A
B
C
D
D
E
F
G
H
a1
b1
c1
1
1
e1
f1
g1
h1
a2
b2
c2
1
1
e1
f1
g1
h1
a3
b3
c3
2
NULL
NULL
NULL
NULL
NULL
a4
b4
c4
3
3
e2
f2
g2
h2
|--||||||||--|
Example
Output a list of all custimers with their bookings for October 15th, 2001:
DATA: CUSTOMER TYPE SCUSTOM,
BOOKING TYPE SBOOK.
SELECT SCUSTOMNAME SCUSTOMPOSTCODE SCUSTOM~CITY
SBOOKFLDATE SBOOKCARRID SBOOKCONNID SBOOKBOOKID
INTO (CUSTOMER-NAME, CUSTOMER-POSTCODE, CUSTOMER-CITY,
BOOKING-FLDATE, BOOKING-CARRID, BOOKING-CONNID,
BOOKING-BOOKID)
FROM SCUSTOM LEFT OUTER JOIN SBOOK
ON SCUSTOMID = SBOOKCUSTOMID AND
SBOOK~FLDATE = '20011015'
ORDER BY SCUSTOMNAME SBOOKFLDATE.
WRITE: / CUSTOMER-NAME, CUSTOMER-POSTCODE, CUSTOMER-CITY,
BOOKING-FLDATE, BOOKING-CARRID, BOOKING-CONNID,
BOOKING-BOOKID.
ENDSELECT.
If there are columns with the same name in both tables, you must distinguish between them by prefixing the field descriptor with the table name or using an alias.
Note
For the resulting set of a SELECT command with a left outer join in the FROM clause, it is generally of crucial importance whether a logical condition is in the ON or WHERE condition. Since not all of the database systems supported by SAP themselves support the standard syntax and semantics of the left outer join, the syntax has been restricted to those cases that return the same solution in all database systems:
Only a table or view may come after the JOIN operator, not another join statement.
The only logical operator allowed in the ON condition is AND.
Each comparison in the ON condition must contain a field from the right-hand table.
Comparisons in the WHERE condition must not contain a field from the right-hand table.
The ON condition must contain at least one "real" JOIN condition (a condition in which a field from tabref1 as well as from tabref2 occurs).
Note
In some cases, '*' may be specivied as the field list in the SELECT clause, and an internal table or work area is entered in the INTO clause (instead of a list of fields). If so, the fields are written to the target area from left to right in the order in which the tables appear in the llen in der FROM clause, according to the structure of each table work area. There can be gaps between the table work areas if you use an Alignment Request. For this reason, you should define the target work area with reference to the types of the database tables, as in the following example (not simply by counting the total number of fields).
Example
Example of a JOIN with more than two tables: Select all flights from Frankfurt to New York between September 10th and 20th, 2001 where there are available places, and display the name of the airline.
DATA: BEGIN OF WA,
FLIGHT TYPE SFLIGHT,
PFLI TYPE SPFLI,
CARR TYPE SCARR,
END OF WA.
SELECT * INTO WA
FROM ( SFLIGHT AS F INNER JOIN SPFLI AS P
ON FCARRID = PCARRID AND
FCONNID = PCONNID )
INNER JOIN SCARR AS C
ON FCARRID = CCARRID
WHERE P~CITYFROM = 'FRANKFURT'
AND P~CITYTO = 'NEW YORK'
AND F~FLDATE BETWEEN '20010910' AND '20010920'
AND FSEATSOCC < FSEATSMAX.
WRITE: / WA-CARR-CARRNAME, WA-FLIGHT-FLDATE, WA-FLIGHT-CARRID,
WA-FLIGHT-CONNID.
ENDSELECT.
And for all entries,
this will help u.
use of FOR ALL ENTRIES:
1. INNER JOIN
DBTAB1 <----
> DBTAB2
It is used to JOIN two DATABASE tables
having some COMMON fields.
2. Whereas
For All Entries,
DBTAB1 <----
> ITAB1
is not at all related to two DATABASE tables.
It is related to INTERNAL table.
3. If we want to fetch data
from some DBTABLE1
but we want to fetch
for only some records
which are contained in some internal table,
then we use for alll entries.
1. simple example of for all entries.
2. NOTE THAT
In for all entries,
it is NOT necessary to use TWO DBTABLES.
(as against JOIN)
3. use this program (just copy paste)
it will fetch data
from T001
FOR ONLY TWO COMPANIES (as mentioned in itab)
4
REPORT abc.
DATA : BEGIN OF itab OCCURS 0,
bukrs LIKE t001-bukrs,
END OF itab.
DATA : t001 LIKE TABLE OF t001 WITH HEADER LINE.
itab-bukrs = '1000'.
APPEND itab.
itab-bukrs = '1100'.
APPEND itab.
SELECT * FROM t001
INTO TABLE t001
FOR ALL ENTRIES IN itab
WHERE bukrs = itab-bukrs.
LOOP AT t001.
WRITE :/ t001-bukrs.
ENDLOOP.
cheers,
Hema. -
Doubt regarding FOR ALL ENTRIES and INDEXES
Hi iam Aslam ..
and i have a doubt ..regrding .. .
1) what are the disadvs of using FOR ALL ENTRIES
2) what are the disadvs of using INDEXES
3) what is the disadvs of using Binary search ..
4) . how can u do performance tuning ...if u have more than one SELECT statements between ... Loop and Endloop .......
please answer to these questions or reply me to [email protected] ..
thanks in advance ..
byeHI
<b>1) what are the disadvs of using FOR ALL ENTRIES</b>
if there is no data available for you condition mentioned in the where condition then it will retrive all the data from the database table , which we don't want , but we can solve that easily
Ways of Performance Tuning
1. Selection Criteria
2. Select Statements
Select Queries
SQL Interface
Aggregate Functions
For all Entries
Select Over more than one Internal table
Selection Criteria
1. Restrict the data to the selection criteria itself, rather than filtering it out using the ABAP code using CHECK statement.
2. Select with selection list.
Points # 1/2
SELECT * FROM SBOOK INTO SBOOK_WA.
CHECK: SBOOK_WA-CARRID = 'LH' AND
SBOOK_WA-CONNID = '0400'.
ENDSELECT.
The above code can be much more optimized by the code written below which avoids CHECK, selects with selection list
SELECT CARRID CONNID FLDATE BOOKID FROM SBOOK INTO TABLE T_SBOOK
WHERE SBOOK_WA-CARRID = 'LH' AND
SBOOK_WA-CONNID = '0400'.
Select Statements Select Queries
1. Avoid nested selects
2. Select all the records in a single shot using into table clause of select statement rather than to use Append statements.
3. When a base table has multiple indices, the where clause should be in the order of the index, either a primary or a secondary index.
4. For testing existence , use Select.. Up to 1 rows statement instead of a Select-Endselect-loop with an Exit.
5. Use Select Single if all primary key fields are supplied in the Where condition .
Point # 1
SELECT * FROM EKKO INTO EKKO_WA.
SELECT * FROM EKAN INTO EKAN_WA
WHERE EBELN = EKKO_WA-EBELN.
ENDSELECT.
ENDSELECT.
The above code can be much more optimized by the code written below.
SELECT PF1 PF2 FF3 FF4 INTO TABLE ITAB
FROM EKKO AS P INNER JOIN EKAN AS F
ON PEBELN = FEBELN.
Note: A simple SELECT loop is a single database access whose result is passed to the ABAP program line by line. Nested SELECT loops mean that the number of accesses in the inner loop is multiplied by the number of accesses in the outer loop. One should therefore use nested SELECT loops only if the selection in the outer loop contains very few lines or the outer loop is a SELECT SINGLE statement.
Point # 2
SELECT * FROM SBOOK INTO SBOOK_WA.
CHECK: SBOOK_WA-CARRID = 'LH' AND
SBOOK_WA-CONNID = '0400'.
ENDSELECT.
The above code can be much more optimized by the code written below which avoids CHECK, selects with selection list and puts the data in one shot using into table
SELECT CARRID CONNID FLDATE BOOKID FROM SBOOK INTO TABLE T_SBOOK
WHERE SBOOK_WA-CARRID = 'LH' AND
SBOOK_WA-CONNID = '0400'.
Point # 3
To choose an index, the optimizer checks the field names specified in the where clause and then uses an index that has the same order of the fields . In certain scenarios, it is advisable to check whether a new index can speed up the performance of a program. This will come handy in programs that access data from the finance tables.
Point # 4
SELECT * FROM SBOOK INTO SBOOK_WA
UP TO 1 ROWS
WHERE CARRID = 'LH'.
ENDSELECT.
The above code is more optimized as compared to the code mentioned below for testing existence of a record.
SELECT * FROM SBOOK INTO SBOOK_WA
WHERE CARRID = 'LH'.
EXIT.
ENDSELECT.
Point # 5
If all primary key fields are supplied in the Where condition you can even use Select Single.
Select Single requires one communication with the database system, whereas Select-Endselect needs two.
Select Statements contd.. SQL Interface
1. Use column updates instead of single-row updates
to update your database tables.
2. For all frequently used Select statements, try to use an index.
3. Using buffered tables improves the performance considerably.
Point # 1
SELECT * FROM SFLIGHT INTO SFLIGHT_WA.
SFLIGHT_WA-SEATSOCC =
SFLIGHT_WA-SEATSOCC - 1.
UPDATE SFLIGHT FROM SFLIGHT_WA.
ENDSELECT.
The above mentioned code can be more optimized by using the following code
UPDATE SFLIGHT
SET SEATSOCC = SEATSOCC - 1.
Point # 2
SELECT * FROM SBOOK CLIENT SPECIFIED INTO SBOOK_WA
WHERE CARRID = 'LH'
AND CONNID = '0400'.
ENDSELECT.
The above mentioned code can be more optimized by using the following code
SELECT * FROM SBOOK CLIENT SPECIFIED INTO SBOOK_WA
WHERE MANDT IN ( SELECT MANDT FROM T000 )
AND CARRID = 'LH'
AND CONNID = '0400'.
ENDSELECT.
Point # 3
Bypassing the buffer increases the network considerably
SELECT SINGLE * FROM T100 INTO T100_WA
BYPASSING BUFFER
WHERE SPRSL = 'D'
AND ARBGB = '00'
AND MSGNR = '999'.
The above mentioned code can be more optimized by using the following code
SELECT SINGLE * FROM T100 INTO T100_WA
WHERE SPRSL = 'D'
AND ARBGB = '00'
AND MSGNR = '999'.
Select Statements contd Aggregate Functions
If you want to find the maximum, minimum, sum and average value or the count of a database column, use a select list with aggregate functions instead of computing the aggregates yourself.
Some of the Aggregate functions allowed in SAP are MAX, MIN, AVG, SUM, COUNT, COUNT( * )
Consider the following extract.
Maxno = 0.
Select * from zflight where airln = LF and cntry = IN.
Check zflight-fligh > maxno.
Maxno = zflight-fligh.
Endselect.
The above mentioned code can be much more optimized by using the following code.
Select max( fligh ) from zflight into maxno where airln = LF and cntry = IN.
Select Statements contd For All Entries
The for all entries creates a where clause, where all the entries in the driver table are combined with OR. If the number of entries in the driver table is larger than rsdb/max_blocking_factor, several similar SQL statements are executed to limit the length of the WHERE clause.
The plus
Large amount of data
Mixing processing and reading of data
Fast internal reprocessing of data
Fast
The Minus
Difficult to program/understand
Memory could be critical (use FREE or PACKAGE size)
Points to be must considered FOR ALL ENTRIES
Check that data is present in the driver table
Sorting the driver table
Removing duplicates from the driver table
Consider the following piece of extract
Loop at int_cntry.
Select single * from zfligh into int_fligh
where cntry = int_cntry-cntry.
Append int_fligh.
Endloop.
The above mentioned can be more optimized by using the following code.
Sort int_cntry by cntry.
Delete adjacent duplicates from int_cntry.
If NOT int_cntry[] is INITIAL.
Select * from zfligh appending table int_fligh
For all entries in int_cntry
Where cntry = int_cntry-cntry.
Endif.
Select Statements contd Select Over more than one Internal table
1. Its better to use a views instead of nested Select statements.
2. To read data from several logically connected tables use a join instead of nested Select statements. Joins are preferred only if all the primary key are available in WHERE clause for the tables that are joined. If the primary keys are not provided in join the Joining of tables itself takes time.
3. Instead of using nested Select loops it is often better to use subqueries.
Point # 1
SELECT * FROM DD01L INTO DD01L_WA
WHERE DOMNAME LIKE 'CHAR%'
AND AS4LOCAL = 'A'.
SELECT SINGLE * FROM DD01T INTO DD01T_WA
WHERE DOMNAME = DD01L_WA-DOMNAME
AND AS4LOCAL = 'A'
AND AS4VERS = DD01L_WA-AS4VERS
AND DDLANGUAGE = SY-LANGU.
ENDSELECT.
The above code can be more optimized by extracting all the data from view DD01V_WA
SELECT * FROM DD01V INTO DD01V_WA
WHERE DOMNAME LIKE 'CHAR%'
AND DDLANGUAGE = SY-LANGU.
ENDSELECT
Point # 2
SELECT * FROM EKKO INTO EKKO_WA.
SELECT * FROM EKAN INTO EKAN_WA
WHERE EBELN = EKKO_WA-EBELN.
ENDSELECT.
ENDSELECT.
The above code can be much more optimized by the code written below.
SELECT PF1 PF2 FF3 FF4 INTO TABLE ITAB
FROM EKKO AS P INNER JOIN EKAN AS F
ON PEBELN = FEBELN.
Point # 3
SELECT * FROM SPFLI
INTO TABLE T_SPFLI
WHERE CITYFROM = 'FRANKFURT'
AND CITYTO = 'NEW YORK'.
SELECT * FROM SFLIGHT AS F
INTO SFLIGHT_WA
FOR ALL ENTRIES IN T_SPFLI
WHERE SEATSOCC < F~SEATSMAX
AND CARRID = T_SPFLI-CARRID
AND CONNID = T_SPFLI-CONNID
AND FLDATE BETWEEN '19990101' AND '19990331'.
ENDSELECT.
The above mentioned code can be even more optimized by using subqueries instead of for all entries.
SELECT * FROM SFLIGHT AS F INTO SFLIGHT_WA
WHERE SEATSOCC < F~SEATSMAX
AND EXISTS ( SELECT * FROM SPFLI
WHERE CARRID = F~CARRID
AND CONNID = F~CONNID
AND CITYFROM = 'FRANKFURT'
AND CITYTO = 'NEW YORK' )
AND FLDATE BETWEEN '19990101' AND '19990331'.
ENDSELECT.
1. Table operations should be done using explicit work areas rather than via header lines.
2. Always try to use binary search instead of linear search. But dont forget to sort your internal table before that.
3. A dynamic key access is slower than a static one, since the key specification must be evaluated at runtime.
4. A binary search using secondary index takes considerably less time.
5. LOOP ... WHERE is faster than LOOP/CHECK because LOOP ... WHERE evaluates the specified condition internally.
6. Modifying selected components using MODIFY itab TRANSPORTING f1 f2.. accelerates the task of updating a line of an internal table.
Point # 2
READ TABLE ITAB INTO WA WITH KEY K = 'X BINARY SEARCH.
IS MUCH FASTER THAN USING
READ TABLE ITAB INTO WA WITH KEY K = 'X'.
If TAB has n entries, linear search runs in O( n ) time, whereas binary search takes only O( log2( n ) ).
Point # 3
READ TABLE ITAB INTO WA WITH KEY K = 'X'. IS FASTER THAN USING
READ TABLE ITAB INTO WA WITH KEY (NAME) = 'X'.
Point # 5
LOOP AT ITAB INTO WA WHERE K = 'X'.
ENDLOOP.
The above code is much faster than using
LOOP AT ITAB INTO WA.
CHECK WA-K = 'X'.
ENDLOOP.
Point # 6
WA-DATE = SY-DATUM.
MODIFY ITAB FROM WA INDEX 1 TRANSPORTING DATE.
The above code is more optimized as compared to
WA-DATE = SY-DATUM.
MODIFY ITAB FROM WA INDEX 1.
7. Accessing the table entries directly in a "LOOP ... ASSIGNING ..." accelerates the task of updating a set of lines of an internal table considerably
8. If collect semantics is required, it is always better to use to COLLECT rather than READ BINARY and then ADD.
9. "APPEND LINES OF itab1 TO itab2" accelerates the task of appending a table to another table considerably as compared to LOOP-APPEND-ENDLOOP.
10. DELETE ADJACENT DUPLICATES accelerates the task of deleting duplicate entries considerably as compared to READ-LOOP-DELETE-ENDLOOP.
11. "DELETE itab FROM ... TO ..." accelerates the task of deleting a sequence of lines considerably as compared to DO -DELETE-ENDDO.
Point # 7
Modifying selected components only makes the program faster as compared to Modifying all lines completely.
e.g,
LOOP AT ITAB ASSIGNING <WA>.
I = SY-TABIX MOD 2.
IF I = 0.
<WA>-FLAG = 'X'.
ENDIF.
ENDLOOP.
The above code works faster as compared to
LOOP AT ITAB INTO WA.
I = SY-TABIX MOD 2.
IF I = 0.
WA-FLAG = 'X'.
MODIFY ITAB FROM WA.
ENDIF.
ENDLOOP.
Point # 8
LOOP AT ITAB1 INTO WA1.
READ TABLE ITAB2 INTO WA2 WITH KEY K = WA1-K BINARY SEARCH.
IF SY-SUBRC = 0.
ADD: WA1-VAL1 TO WA2-VAL1,
WA1-VAL2 TO WA2-VAL2.
MODIFY ITAB2 FROM WA2 INDEX SY-TABIX TRANSPORTING VAL1 VAL2.
ELSE.
INSERT WA1 INTO ITAB2 INDEX SY-TABIX.
ENDIF.
ENDLOOP.
The above code uses BINARY SEARCH for collect semantics. READ BINARY runs in O( log2(n) ) time. The above piece of code can be more optimized by
LOOP AT ITAB1 INTO WA.
COLLECT WA INTO ITAB2.
ENDLOOP.
SORT ITAB2 BY K.
COLLECT, however, uses a hash algorithm and is therefore independent
of the number of entries (i.e. O(1)) .
Point # 9
APPEND LINES OF ITAB1 TO ITAB2.
This is more optimized as compared to
LOOP AT ITAB1 INTO WA.
APPEND WA TO ITAB2.
ENDLOOP.
Point # 10
DELETE ADJACENT DUPLICATES FROM ITAB COMPARING K.
This is much more optimized as compared to
READ TABLE ITAB INDEX 1 INTO PREV_LINE.
LOOP AT ITAB FROM 2 INTO WA.
IF WA = PREV_LINE.
DELETE ITAB.
ELSE.
PREV_LINE = WA.
ENDIF.
ENDLOOP.
Point # 11
DELETE ITAB FROM 450 TO 550.
This is much more optimized as compared to
DO 101 TIMES.
DELETE ITAB INDEX 450.
ENDDO.
12. Copying internal tables by using ITAB2[ ] = ITAB1[ ] as compared to LOOP-APPEND-ENDLOOP.
13. Specify the sort key as restrictively as possible to run the program faster.
Point # 12
ITAB2[] = ITAB1[].
This is much more optimized as compared to
REFRESH ITAB2.
LOOP AT ITAB1 INTO WA.
APPEND WA TO ITAB2.
ENDLOOP.
Point # 13
SORT ITAB BY K. makes the program runs faster as compared to SORT ITAB.
Internal Tables contd
Hashed and Sorted tables
1. For single read access hashed tables are more optimized as compared to sorted tables.
2. For partial sequential access sorted tables are more optimized as compared to hashed tables
Hashed And Sorted Tables
Point # 1
Consider the following example where HTAB is a hashed table and STAB is a sorted table
DO 250 TIMES.
N = 4 * SY-INDEX.
READ TABLE HTAB INTO WA WITH TABLE KEY K = N.
IF SY-SUBRC = 0.
ENDIF.
ENDDO.
This runs faster for single read access as compared to the following same code for sorted table
DO 250 TIMES.
N = 4 * SY-INDEX.
READ TABLE STAB INTO WA WITH TABLE KEY K = N.
IF SY-SUBRC = 0.
ENDIF.
ENDDO.
Point # 2
Similarly for Partial Sequential access the STAB runs faster as compared to HTAB
LOOP AT STAB INTO WA WHERE K = SUBKEY.
ENDLOOP.
This runs faster as compared to
LOOP AT HTAB INTO WA WHERE K = SUBKEY.
ENDLOOP. -
Calculate Withholding taxes for VEndor Invoices using ABAP program.
Hi All,
I have to upload Vendor Invoices using FB60/Fb01 tcodes. I am able to post the Invoices using FB01/Fb60
but I have to calculate extended withholding taxes also using this program for the Invoices.
Is it possible to upload vendor Invoices and calculate withholding taxes using Program?
If yes,
Does anyone has any idea how do you calculate extended withholding taxes using any BAPI's?
I have used these two BAPI's
BAPI_ACC_DOCUMENT_POST
BAPI_acc_invoice_receipt_post
they are working fine but without withholding tax.
This is a requirement for country India.
Regards,
SushilHi,
Imho, you need to get (meaning, extract into separate fields) the different supplier types from Table1 first. Your key for Table1 is the vendor no, which is also the key in Table2 (or the key for Table2 is Vendor no & Type).
For better performance, better select multiple/all required entries from Table1 instead of doing a select endselect.
Depending on the format of the vendortypes in Table1, put them in a new itab (for our purpose named Table1New where vendor no & type are the only 2 fields. For example, if the type length is fixed to 2 chars, or divided by space,... use your coding accordingly.
Next step is to select all vendor no's in Table2 which you have selected in Table1. If in Table2, the vendor no is the only key (and the all vendor types are filled in a single record), then loop check the vendor types from Table1New against the types in Table2.
If the key of Table2 is vendor no & vendor type, then do a read table for the key.
The logic in pseudo-code:
Select from Table1 into table. If you'd like to limit the selection size, add package size statement.
extract the vendor types in to itab Table1New.
Select the vendor & types from Table2 by using the for all entries option (better performance).
loop at Table1New
check in Table2:
if the unique key is vendor no: check all fields for the vendor type from Table1New
if the unique key combo is vendor no & type: check by using a read table.
If not found => add entry to Table2
endloop.
endselect Table1 (when using package size)
I guess the most difficult step is to extract the types from Table1 into separate fields, all the rest seems straight forward. Please keep in mind the itab type definitions for a better performance.
Good luck!
Best regards,
Zhou -
Dynamic Select Query including Dynamic Tables with For all Entries
Hello everyone,
I need to create a select query which involves using of Dynamic Tables.
Suppose I have a dynamic table <d1> which consist of let say 10 records.
Now i need to make a select query putting data into another dynamic table <d2>
CONCATENATE keyfield '=' '<d1>' INTO g_condition SEPARATED BY space.
CONCATENATE g_condition '-' keyfield INTO g_condition.
SELECT * FROM (wa_all_tables-name) INTO CORRESPONDING FIELDS OF TABLE <d1>
FOR ALL ENTRIES IN <d1>
WHERE (g_condition).
But it is giving dump.
Please help me on this....Short text
A condition specified at runtime has an unexpected format.
What happened?
Error in the ABAP Application Program
The current ABAP program "ZNG_CUSTOMWRITE" had to be terminated because it has
come across a statement that unfortunately cannot be executed.
Error analysis
An exception occurred that is explained in detail below.
The exception, which is assigned to class 'CX_SY_DYNAMIC_OSQL_SEMANTICS', was
not caught in
procedure "WRITE_ARCHIVE_PROD" "(FORM)", nor was it propagated by a RAISING
clause.
Since the caller of the procedure could not have anticipated that the
exception would occur, the current program is terminated.
The reason for the exception is:
The current ABAP program has tried to execute an Open SQL statement
which contains a WHERE, ON or HAVING condition with a dynamic part.
The part of the WHERE, ON or HAVING condition specified at runtime in
a field or an internal table, contains the invalid value "ZCOURIER-ZCOURIERID".
CONCATENATE keyfield '=' g_header INTO g_condition SEPARATED BY space.
CONCATENATE g_condition '-' keyfield INTO g_condition.
SELECT * FROM (wa_all_tables-name) INTO CORRESPONDING FIELDS OF TABLE <dyn_table1>
FOR ALL ENTRIES IN <dyn_table>
WHERE (g_condition). -
"For All Entries in ITAB" -error
Hello!
I am new to this ABAP. I getting one error in Select query "For All Entries" keyword. My problem is,
Iam taking vbeln field from the table LIPS and stored in internal table it_lips. and then based on this vbeln i am taking the material document no. field mblnr from MKPF table. The Common field present in this table is vbeln in LIPS and xblnr in MKPF.
my select query is,
select xblnr mblnr
into corresponding fields of table it_mkpf
from mkpf
for all entries in it_lips
where xblnr = it_lips-vbeln
and blart = 'WL'.Hi,
Use the below logic:
TYPES: BEGIN OF ty_mkpf,
mblnr TYPE mblnr,
xblnr TYPE xblnr1,
END OF ty_mkpf.
TYPES: BEGIN OF ty_lips,
vbeln TYPE vbeln_vl,
vbeln1 TYPE xblnr1,
END OF ty_lips.
DATA: git_mkpf TYPE STANDARD TABLE OF ty_mkpf,
git_lips TYPE STANDARD TABLE OF ty_lips.
DATA: gwa_lips TYPE ty_lips.
SELECT vbeln FROM lips INTO TABLE git_lips
UP TO 5 ROWS.
LOOP AT git_lips INTO gwa_lips.
gwa_lips-vbeln1 = gwa_lips-vbeln.
MODIFY git_lips FROM gwa_lips.
ENDLOOP.
SELECT mblnr xblnr
INTO TABLE git_mkpf
FROM mkpf
FOR ALL ENTRIES IN git_lips
WHERE xblnr = git_lips-vbeln1
AND blart = 'WL'. -
How to use dynamic internal table with FOR ALL ENTRIES
Hello SDNers,
I am having a dynamic internal table & want to use FOR ALL ENTRIES(FAE) using this dyn. table.
This works fine for me:
IF <lt_tmp> IS NOT INITIAL. "<lt_tmp> is my dyn. internal table
SELECT field1 field2
FROM TABLE ztable
INTO TABLE itab "Itab is a static table
FOR ALL ENTRIES IN <lt_tmp>
WHERE (lv_dynwhere). "lv_dynwhere -> dynamic where clause
ENDIF.
SAP documentation says:
"The logical expression sql_cond of the WHERE condition can be comprised of several logical expressions using AND and OR. However, if FOR ALL ENTRIES is specified, there must be at least one comparison with a column of the internal table itab that can be specified statically or dynamically. "
How do we specify the column of the internal table dynamically ? Can we do something like this:
IF <lt_tmp> IS NOT INITIAL. "<lt_tmp> is my dyn. internal table
SELECT field1 field2
FROM TABLE
INTO TABLE itab "Itab is a static table
FOR ALL ENTRIES IN <lt_tmp>
WHERE key_field1 = (dynamic token for column1 of <lt_tmp>)
key_field2 = (dynamic token for column2 of <lt_tmp>)
ENDIF.
ENDIF.
Let me know if i am not clear about my requirement.
BR,
SuhasHello Thomas,
What i meant was something like this:
WHERE key_field1 = ('<LT_TMP-COL1>') AND
key_field2 = ('<LT_TMP-COL2>')
I am confused by what SAP means with "dynamic representation of internal table columns" in FAE ?
@Rob: I was referring to SAPNW 7.0 documentation & the phrase (release 6.40 & higher) is missing. Anyways fyi i am on ECC5.0 ABAP release 6.40.
@Subhankar: This is what Marcin had proposed in For all entries and dynamic table.
Thanks,
Suhas
Edited by: Suhas Saha on Apr 6, 2010 11:53 AM -
For all entries on custom tables
i have created 2 custom tables::zhospital_info n zpatient_info..
zhospitalinfo tab fields:::_
doc_name::prim key
patient_name:::prim key
place::prim key
zpatientinfo tab fields::_
ZDATE ::prim key
JOINING
MEDICINE
PRICE
QUANTITY
DOC_NAME ::for key
PATIENT_NAME::for key
PLACE ::for key
and inserted some values to the table contents..
this is my logic:::
TYPES: BEGIN OF ZHOSPITAL_INFO,
DOC_NAME TYPE ZDOC_NAME,
PATIENT_NAME TYPE ZPATIENT_NAME,
PLACE TYPE ZPLACE,
END OF ZHOSPITAL_INFO.
DATA: W_HI TYPE ZHOSPITAL_INFO.
DATA:T_HI TYPE STANDARD TABLE OF ZHOSPITAL_INFO.
TYPES: BEGIN OF ZPATIENTL_INFO,
ZDATE TYPE ZDATE,
JOINING TYPE ZJOINING,
MEDICINE TYPE ZMEDICINE,
PRICE TYPE ZPRICE,
QUANTITY TYPE ZQUANTITY,
DOC_NAME TYPE ZDOC_NAME,
PATIENT_NAME TYPE ZPATIENT_NAME,
PLACE TYPE ZPLACE,
END OF ZPATIENTL_INFO.
DATA: W_PI TYPE ZPATIENTL_INFO.
DATA:T_PI TYPE STANDARD TABLE OF ZPATIENTL_INFO.
TYPES: BEGIN OF FTAB,
DOC_NAME TYPE ZDOC_NAME,
PATIENT_NAME TYPE ZPATIENT_NAME,
PLACE TYPE ZPLACE,
DATE TYPE ZDATE,
JOINING TYPE ZJOINING,
MEDICINE TYPE ZMEDICINE,
PRICE TYPE ZPRICE,
QUANTITY TYPE ZQUANTITY,
END OF FTAB.
DATA: W_FTAB TYPE FTAB,
T_FTAB TYPE STANDARD TABLE OF FTAB.
SELECT DOC_NAME
PATIENT_NAME
PLACE
INTO TABLE t_hi
FROM ZHOSPITAL_INFO .
IF NOT t_hi IS NOT INITIAL.
SELECT DOC_NAME
PATIENT_NAME
PLACE
ZDATE
MEDICINE*
PRICE
QUANTITY FROM ZPATIENTL_INFO INTO TABLE t_pi FOR ALL ENTRIES IN
t_hi
WHERE DOC_NAME = t_hi-doc_name.
ENDIF.
LOOP AT t_pi INTO w_pi.
MOVE-CORRESPONDING: w_pi TO W_FTAB.
READ TABLE t_hi INTO w_hi WITH KEY DOC_NAME = W_FTAB-DOC_NAME.
MOVE: w_hi-patient_name TO W_FTAB-PATIENT_NAME,
w_hi-place TO W_FTAB-PLACE.
APPEND W_FTAB TO T_FTAB.
ENDLOOP.
LOOP AT T_FTAB INTO W_FTAB.
WRITE:/ W_FTAB-DOC_NAME,
W_FTAB-PATIENT_NAME,
W_FTAB-PLACE,
W_FTAB-DATE,
W_FTAB-JOINING,
W_FTAB-MEDICINE,
W_FTAB-PRICE,
W_FTAB-QUANTITY.
ENDLOOP.
req output:::when i enter doc_name the related info accr to doc_name from the both tables should be display..
m getting no errors but i cant execute my prog..
please check out my code...
thanx in adv..Hi,
The problem is in the select statement:
SELECT DOC_NAME
PATIENT_NAME
PLACE
ZDATE
MEDICINE
PRICE
QUANTITY FROM ZPATIENTL_INFO INTO TABLE t_pi FOR ALL ENTRIES IN
t_hi
WHERE DOC_NAME = t_hi-doc_name.
Change this to SELECT DOC_NAME PATIENT_NAME PLACE ZDATE MEDICINE PRICE QUANTITY FROM ZPATIENTL_INFO INTO CORRESPONDING FIELDS OF TABLE t-pi FOR ALL ENTRIES IN t_hi WHERE DOC_NAME = t_hi-doc_name.
I hope the above code will help you...
Also i hope to tell the following for performance issues and also a good programming practice:
LOOP AT t_pi INTO w_pi.
MOVE-CORRESPONDING: w_pi TO W_FTAB.
READ TABLE t_hi INTO w_hi WITH KEY DOC_NAME = W_FTAB-DOC_NAME.
MOVE: w_hi-patient_name TO W_FTAB-PATIENT_NAME,
w_hi-place TO W_FTAB-PLACE.
APPEND W_FTAB TO T_FTAB.
ENDLOOP.
Please do a sy-subrc check after READ statement always...
LOOP AT t_pi INTO w_pi.
MOVE-CORRESPONDING: w_pi TO W_FTAB.
READ TABLE t_hi INTO w_hi WITH KEY DOC_NAME = W_FTAB-DOC_NAME.
If sy-subrc = 0.
MOVE: w_hi-patient_name TO W_FTAB-PATIENT_NAME,
w_hi-place TO W_FTAB-PLACE.
clear w_hi.
Endif.APPEND W_FTAB TO T_FTAB.
ENDLOOP.
Please revert back for clarifications.
Best Regards,
Suresh -
FOR ALL ENTRIES - CDHDR / CDPOS Tables
Hi,
I know there have been a lot of threads concerning the "for all entries" statement. Nevertheless I got a problem downloading the change document tables CDHDR/CDPOS with this statement and I haven't found anything in this forum regarding this special issue.
While trying the for all entries statement in the below manner for downloading first CDHDR and then the CDPOS for all entries of the selected CDHDR it took 3 days and didn't finish, so we aborted the ABAP. The JOIN statement doesn't work in a 4.6c environment for the Cluster tables, hence this isn't an option.
Can you give me some advise of how to improve downloading those tables in this way:
1. Download CDHDR with limitation of fields OBJECTCLAS and UDATE
2. Then Download CDPOS for all CHANGENR out of the first selection of CDHDR
This was the way I tried it:
SELECT
ACT_CHNGNO CHANGE_IND CHANGENR MANDANT OBJECTCLAS OBJECTID PLANCHNGNR TCODE UDATE USERNAME UTIME WAS_PLANND APPENDING CORRESPONDING FIELDS OF TABLE T_CDHDR FROM CDHDR WHERE UDATE IN s_UDAT1 AND OBJECTCLAS IN s_OBJE0.
ENDSELECT.
SELECT
CHANGENR CHNGIND CUKY_NEW CUKY_OLD FNAME MANDANT OBJECTCLAS OBJECTID TABKEY TABNAME UNIT_NEW UNIT_OLD VALUE_NEW VALUE_OLD INTO gs_CDPOS FROM CDPOS CLIENT SPECIFIED for all entries in T_CDHDR WHERE OBJECTCLAS IN s_OBJE2 AND MANDANT EQ T_CDHDR-MANDANT AND OBJECTCLAS EQ T_CDHDR-OBJECTCLAS AND CHANGENR EQ T_CDHDR-CHANGENR.
ENDSELECT.THis prg might b usefull to u
* Mass display or print Purchase Order History
* You can request report by :
* 1. Change date
* 2. User Name
* 3. Purchase Order Number
* 4. Vendor Code
* Written by : SAP Basis, ABAP Programming and Other IMG Stuff
* http://www.sap-img.com
REPORT ZPOCHANGE LINE-SIZE 132 NO STANDARD PAGE HEADING
LINE-COUNT 065(001)
MESSAGE-ID VR.
TABLES: DD04T,
CDHDR,
CDPOS,
DD03L,
DD41V,
T685T,
VBPA,
TPART,
KONVC,
EKKO.
SELECT-OPTIONS: XUDATE FOR CDHDR-UDATE,
XNAME FOR CDHDR-USERNAME,
XEBELN FOR EKKO-EBELN,
XLIFNR FOR EKKO-LIFNR.
SELECTION-SCREEN SKIP.
* TEXT-001 - Sorting Sequence
SELECTION-SCREEN BEGIN OF BLOCK BLK1 WITH FRAME TITLE TEXT-001.
PARAMETERS: SUDATE RADIOBUTTON GROUP R1,
SNAME RADIOBUTTON GROUP R1,
SOBID RADIOBUTTON GROUP R1.
SELECTION-SCREEN END OF BLOCK BLK1.
DATA: WFLAG,
WCHANGENR LIKE CDHDR-CHANGENR.
DATA: INDTEXT(60) TYPE C.
DATA: BEGIN OF ICDHDR OCCURS 50.
INCLUDE STRUCTURE CDHDR.
DATA: END OF ICDHDR.
DATA: BEGIN OF ICDSHW OCCURS 50.
INCLUDE STRUCTURE CDSHW.
DATA: END OF ICDSHW.
DATA: BEGIN OF EKKEY,
EBELN LIKE EKET-EBELN,
EBELP LIKE EKET-EBELP,
ETENR LIKE EKET-ETENR,
END OF EKKEY.
DATA: BEGIN OF ITAB OCCURS 50,
BEGIN OF EKKEY,
EBELN LIKE EKET-EBELN,
EBELP LIKE EKET-EBELP,
ETENR LIKE EKET-ETENR,
END OF EKKEY,
CHANGENR LIKE CDHDR-CHANGENR,
UDATE LIKE CDHDR-UDATE,
UTIME LIKE CDHDR-UTIME,
USERNAME LIKE CDHDR-USERNAME,
CHNGIND LIKE CDSHW-CHNGIND,
FTEXT LIKE CDSHW-FTEXT,
OUTLEN LIKE CDSHW-OUTLEN,
F_OLD LIKE CDSHW-F_OLD,
F_NEW LIKE CDSHW-F_NEW,
END OF ITAB.
DATA: OLD_OBJECTID LIKE CDHDR-OBJECTID.
FIELD-SYMBOLS: <F_OLD>, <F_NEW>.
SELECT * FROM EKKO WHERE EBELN IN XEBELN AND
LIFNR IN XLIFNR.
CLEAR CDHDR.
CLEAR CDPOS.
CDHDR-OBJECTCLAS = 'EINKBELEG'.
CDHDR-OBJECTID = EKKO-EBELN.
PERFORM GETCHGDOCS.
ENDSELECT.
IF SUDATE = 'X'.
SORT ITAB BY UDATE EKKEY-EBELN CHANGENR EKKEY-EBELP
EKKEY-ETENR.
ELSEIF SNAME = 'X'.
SORT ITAB BY USERNAME EKKEY-EBELN CHANGENR EKKEY-EBELP
EKKEY-ETENR.
ELSE.
SORT ITAB BY EKKEY-EBELN CHANGENR EKKEY-EBELP EKKEY-ETENR.
ENDIF.
LOOP AT ITAB.
CLEAR: INDTEXT, EKKEY.
CASE ITAB-CHNGIND.
WHEN 'U'.
INDTEXT(50) = ITAB-FTEXT.
INDTEXT+51 = TEXT-020.
CONDENSE INDTEXT.
WHEN 'D'.
INDTEXT = TEXT-021.
WHEN 'E'.
INDTEXT(5) = ITAB-FTEXT.
INDTEXT+51 = TEXT-021.
CONDENSE INDTEXT.
WHEN 'I'.
INDTEXT = TEXT-022.
ENDCASE.
RESERVE 4 LINES.
IF WCHANGENR NE ITAB-CHANGENR.
WCHANGENR = ITAB-CHANGENR.
EKKEY = ITAB-EKKEY.
WRITE:/ ITAB-UDATE UNDER 'Change Date',
ITAB-UTIME UNDER 'Time',
ITAB-USERNAME UNDER 'User Name',
ITAB-EKKEY-EBELN UNDER 'PO No',
ITAB-EKKEY-EBELP UNDER 'Item',
ITAB-EKKEY-ETENR UNDER 'Sch No',
INDTEXT UNDER 'Changes'.
ELSEIF ITAB-EKKEY NE EKKEY.
WRITE:/ ITAB-EKKEY-EBELP UNDER 'Item',
ITAB-EKKEY-ETENR UNDER 'Sch No',
INDTEXT UNDER 'Changes'.
ENDIF.
CASE ITAB-CHNGIND.
WHEN 'U'.
ASSIGN ITAB-F_OLD(ITAB-OUTLEN) TO <F_OLD>.
ASSIGN ITAB-F_NEW(ITAB-OUTLEN) TO <F_NEW>.
WRITE: / TEXT-023 UNDER 'Changes',
<F_OLD>.
WRITE: / TEXT-024 UNDER 'Changes',
<F_NEW>.
WHEN 'E'.
ASSIGN ITAB-F_OLD(ITAB-OUTLEN) TO <F_OLD>.
WRITE: TEXT-023 UNDER 'Changes',
<F_OLD>.
ENDCASE.
SKIP.
ENDLOOP.
TOP-OF-PAGE.
WRITE:/ SY-DATUM,SY-UZEIT,
50 'P U R C H A S E O R D E R H I S T O R Y',
120 'Page', SY-PAGNO.
WRITE: / SY-REPID,
60 'Purchase Orders Changes'.
SKIP.
ULINE.
IF SUDATE = 'X'.
WRITE:/001 'Change Date',
014 'Time',
024 'User Name',
038 'PO No',
050 'Item',
057 'Sch No',
065 'Changes'.
ELSEIF SOBID = 'X'.
WRITE:/001 'PO No',
013 'Item',
020 'Sch No',
028 'Change Date',
041 'Time',
051 'User Name',
065 'Changes'.
ELSE.
WRITE:/001 'User Name',
015 'Change Date',
028 'Time',
038 'PO No',
050 'Item',
057 'Sch No',
065 'Changes'.
ENDIF.
ULINE.
FORM GETCHGDOCS.
CALL FUNCTION 'CHANGEDOCUMENT_READ_HEADERS'
EXPORTING
DATE_OF_CHANGE = CDHDR-UDATE
OBJECTCLASS = CDHDR-OBJECTCLAS
OBJECTID = CDHDR-OBJECTID
TIME_OF_CHANGE = CDHDR-UTIME
USERNAME = CDHDR-USERNAME
TABLES
I_CDHDR = ICDHDR
EXCEPTIONS
NO_POSITION_FOUND = 1
OTHERS = 2.
CHECK SY-SUBRC EQ 0.
DELETE ICDHDR WHERE CHANGE_IND EQ 'I'.
CHECK NOT ICDHDR[] IS INITIAL.
LOOP AT ICDHDR.
CHECK ICDHDR-UDATE IN XUDATE.
CHECK ICDHDR-USERNAME IN XNAME.
CALL FUNCTION 'CHANGEDOCUMENT_READ_POSITIONS'
EXPORTING CHANGENUMBER = ICDHDR-CHANGENR
IMPORTING HEADER = CDHDR
TABLES EDITPOS = ICDSHW
EXCEPTIONS NO_POSITION_FOUND = 1
OTHERS = 2.
CHECK SY-SUBRC EQ 0.
LOOP AT ICDSHW.
CHECK ICDSHW-TEXT_CASE EQ SPACE.
MOVE-CORRESPONDING ICDSHW TO ITAB.
MOVE-CORRESPONDING ICDHDR TO ITAB.
MOVE ICDSHW-TABKEY+3 TO ITAB-EKKEY.
APPEND ITAB.
ENDLOOP.
ENDLOOP.
ENDFORM.
* END OF PROGRAM
Maybe you are looking for
-
Crystal Reports xi r2 integrating with vs2005
Hi, I'm having a problem getting these two integrated and working properly with all the functionality that I need. I installed vs2005 and then CRXIR2, and now in vs2005 when I have a report open, I have 2 Crystal Report tabs at the top and in each th
-
Player Installation with Multiple WinXP Users
It seems that normally, if you install the player ActiveX control in IE7 on XP with a Windows administrator account, then the player is available to Windows limited user accounts on the same computer. However I have one location where even after inst
-
"remote desktop connection has stopped working" When printing from remote desktop connection
I have been having a issue when using a windows 7 machine. I have Remote Desktop to a session on Windows2008 R2, I am using the local printer resources to redirect the printing. However everytime i try to print it crashes the remote desktop applicati
-
Which is better to use in a corprate enviornment for back up Windows 2008 Vs. Mozy
Which is better to use in a corprate enviornment for back up Windows 2008 Vs. Mozy
-
Block purchase order for releasing
Hi expert, is it possible for us to block a PO for release if the item in PO already been blocked ? Thank you. Regards Simonksh