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: 

For ALL Entries

Former Member
0 Kudos

Hi Friends,

when i am writing the FOR ALL ENTRIES TO JOING A 2 TABLES ..

FOR EXAMPLE I AHVE 2 TABLES..

1)VBAK.

2)VBAP.

MY QUESTION IS :

FIRST I WANT TO WRITE SELECT STATEMENT FROM VBAK OR VBAP??

WHICH TABLE I WANT TO WRITE SELECT QUERY?? THE COMPARE TO ANOTHER TABLE???

PLS.EXPLAIN ANY ONE.

REGARDS,

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

You have to write with respect to VBAK,

If not l_t_vbak[] is initial.

Select vbeln posnr .... from vbap in to l_t_vbap

for all entries in l_t_vbak

where vbeln = l_t_vbak-vbeln.

endif.

<b>Reward if helpful.</b>

22 REPLIES 22

Former Member
0 Kudos

Hi,

You have to write with respect to VBAK,

If not l_t_vbak[] is initial.

Select vbeln posnr .... from vbap in to l_t_vbap

for all entries in l_t_vbak

where vbeln = l_t_vbak-vbeln.

endif.

<b>Reward if helpful.</b>

0 Kudos

Hi Uma sankar,

why i want chose first VBAK and second VBAP..

first we want chose master tables then second item tables ??

it is right??

explain pls.

regards,

0 Kudos

Hi Vijay,

VBAK is the header table so you have to get the data first here.

Based on this you have to data from the item table VBAP.

Reward if helpful.

0 Kudos

Hi Uma Shankar,

thanks for ur help in a short time.

i ahve more doubt in for all entries.

that is :

can write for entries concept any HEADER TABLE TO ITEM TABLE.

LIKE VBAK TO LPIS TABLE..

PLS EXPLAIN.

REGARDS,

Former Member
0 Kudos

Hi,

Use the following piece of code to get an understanding of the same.

SELECT VBELN from VBAK into itab_VBAK.

SELECT VBELN POSNR MATNR from VBAP into itab_VBAP for all entries in itab_VBAK.

0 Kudos

I forgot the where clause in my earlier post.

Hi,

Use the following piece of code to get an understanding of the same.

SELECT VBELN from VBAK into itab_VBAK.

SELECT VBELN POSNR MATNR from VBAP into itab_VBAP for all entries in itab_VBAK where VBELN = itab_VBAK-VBELN.

Former Member
0 Kudos

first select header data -> if you see data here then go to item level.

the same logic applicable to any other tables

Logic would be

select * from vbak into table i_vbak . -> this is main table

if sy-subrc eq 0.

select * from vbap into table i_vbap

for all entries in i_vbak.

endif.

Thanks

Seshu

0 Kudos

Hi Sheshu,

first we want chose master tables then second item tables ??

it is right??

explain pls.

regards,

0 Kudos

It is not master table,it is header table .

yes ,you have to take header table then take the item table data

Master table means material,customer ,vendor,work center

Let me explian you one general scenario :

If you go shopping and you are taking some items.

you get order number - Order number ,order type ,-> these all are Header data

within order number ,you have list of items like material number ,qty - item level.

Thanks

Seshu

0 Kudos

Hi Seshu,

thanks for ur valuble explanation.

but i want ask u one more question..

my question is,

how to improve to writing a LOGIC and Coding part in ABAP??

PLS. EXPLAIN. ANY LINKS .. SEND ME PLS.

REGARDS,

0 Kudos

Check the below code :

REPORT YEDULOCK.

tables : vbak,

vbap.

  • Internal table for VBAK Table

data : begin of i_vbak occurs 0,

vbeln like vbak-vbeln,

vkorg like vbak-vkorg,

kunnr like vbak-kunnr,

end of i_vbak.

  • Internal table for VBAP

data : begin of i_vbap occurs 0,

vbeln like vbap-vbeln,

posnr like vbap-posnr,

matnr like vbap-matnr,

kwmeng like vbap-kwmeng,

netpr like vbap-netpr,

end of i_vbap.

  • internal table for output

data : begin of i_output occurs 0,

vbeln like vbak-vbeln,

vkorg like vbak-vkorg,

kunnr like vbak-kunnr,

posnr like vbap-posnr,

matnr like vbap-matnr,

kwmeng like vbap-kwmeng,

netpr like vbap-netpr,

end of i_output.

select-options : s_vbeln for vbak-vbeln.

start-of-selection.

  • get the data from VBAK Table

select vbeln vkorg kunnr from vbak into table i_vbak

where vbeln in s_vbeln.

if sy-subrc eq 0.

select vbeln posnr matnr kwmeng netpr from vbap into table i_vbap

for all entries in i_vbak

where vbeln = i_vbak-vbeln.

endif.

loop at i_vbap.

read table i_vbak with key vbeln = i_vbap-vbeln.

if sy-subrc eq 0.

i_output-vbeln = i_vbak-vbeln.

i_output-vkorg = i_vbak-vkorg.

i_output-kunnr = i_vbak-kunnr.

i_output-posnr = i_vbap-posnr.

i_output-matnr = i_vbap-matnr.

i_output-kwmeng = i_vbap-kwmeng.

i_output-netpr = i_vbap-netpr.

append i_output. " Moving the data into output internal table

clear : i_vbap,

i_vbak,

i_output.

else.

clear : i_vbap,

i_vbak,

i_output.

continue.

endif.

endloop.

end-of-selection.

loop at i_output.

write:/ i_output-vbeln,i_output-vkorg,i_output-kunnr,i_output-posnr,

i_output-matnr,i_output-kwmeng,i_output-netpr.

endloop.

Thanks

Seshu

0 Kudos

Hi Seshu,

u decalared Final Internal table .. why???

explain pls.

0 Kudos

Then how we will display the data ..

Just remember that when you use for all entries sql query then need to define one final internal table.

move the data into final internal table within loop,then use final internal table to display the data other further things.

Thanks

Seshu

0 Kudos

Hi Seshu,

thanks for report..

i want generate this report output in alv format.

(field catalog).

how can i write the code.

reply pls.

regards,

0 Kudos

Check the ALV Report :

REPORT YEDULOCK.

type-pools : slis.

tables : vbak,

vbap.

  • Internal table for VBAK Table

data : begin of i_vbak occurs 0,

vbeln like vbak-vbeln,

vkorg like vbak-vkorg,

kunnr like vbak-kunnr,

end of i_vbak.

  • Internal table for VBAP

data : begin of i_vbap occurs 0,

vbeln like vbap-vbeln,

posnr like vbap-posnr,

matnr like vbap-matnr,

kwmeng like vbap-kwmeng,

netpr like vbap-netpr,

end of i_vbap.

  • internal table for output

data : begin of i_output occurs 0,

vbeln like vbak-vbeln,

vkorg like vbak-vkorg,

kunnr like vbak-kunnr,

posnr like vbap-posnr,

matnr like vbap-matnr,

kwmeng like vbap-kwmeng,

netpr like vbap-netpr,

end of i_output.

  • Data declaration for ALV

DATA: g_repid like sy-repid,

gt_fieldcat type slis_t_fieldcat_alv.

select-options : s_vbeln for vbak-vbeln.

Initialization.

g_repid = sy-repid.

start-of-selection.

  • get the data from VBAK Table

select vbeln vkorg kunnr from vbak into table i_vbak

where vbeln in s_vbeln.

if sy-subrc eq 0.

select vbeln posnr matnr kwmeng netpr from vbap into table i_vbap

for all entries in i_vbak

where vbeln = i_vbak-vbeln.

endif.

loop at i_vbap.

read table i_vbak with key vbeln = i_vbap-vbeln.

if sy-subrc eq 0.

i_output-vbeln = i_vbak-vbeln.

i_output-vkorg = i_vbak-vkorg.

i_output-kunnr = i_vbak-kunnr.

i_output-posnr = i_vbap-posnr.

i_output-matnr = i_vbap-matnr.

i_output-kwmeng = i_vbap-kwmeng.

i_output-netpr = i_vbap-netpr.

append i_output. " Moving the data into output internal table

clear : i_vbap,

i_vbak,

i_output.

else.

clear : i_vbap,

i_vbak,

i_output.

continue.

endif.

endloop.

end-of-selection.

if not i_output[] is initial.

  • ALV Function Module

perform print_alv.

endif.

&----


*& Form print_alv

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM print_alv.

  • Fill the Fiedlcat

PERFORM fieldcat_init using gt_fieldcat[].

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

  • I_INTERFACE_CHECK = ' '

  • I_BYPASSING_BUFFER =

  • I_BUFFER_ACTIVE = ' '

I_CALLBACK_PROGRAM = g_repid

  • I_CALLBACK_PF_STATUS_SET = ' '

  • I_CALLBACK_USER_COMMAND = g_user_command

  • I_CALLBACK_TOP_OF_PAGE = ' '

  • 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 = gr_layout_bck

IT_FIELDCAT = gt_fieldcat[]

  • IT_EXCLUDING =

  • IT_SPECIAL_GROUPS =

  • IT_SORT =

  • IT_FILTER =

  • IS_SEL_HIDE =

  • I_DEFAULT = 'X'

  • I_SAVE = g_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_ADD_FIELDCAT =

  • IT_HYPERLINK =

  • I_HTML_HEIGHT_TOP =

  • I_HTML_HEIGHT_END =

  • IT_EXCEPT_QINFO =

  • IMPORTING

  • E_EXIT_CAUSED_BY_CALLER =

  • ES_EXIT_CAUSED_BY_USER =

TABLES

T_OUTTAB = i_output

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_alv

&----


*& Form fieldcat_init

&----


  • text

----


  • -->P_GT_FIELDCAT[] text

----


FORM fieldcat_init USING e01_lt_fieldcat type slis_t_fieldcat_alv.

DATA: LS_FIELDCAT TYPE SLIS_FIELDCAT_ALV.

  • Order #

CLEAR LS_FIELDCAT.

LS_FIELDCAT-FIELDNAME = 'VBELN'.

LS_FIELDCAT-TABNAME = 'I_OUTPUT'.

ls_fieldcat-seltext_L = 'Order #'.

ls_fieldcat-seltext_M = 'Order #'.

ls_fieldcat-seltext_S = 'Order #'.

APPEND LS_FIELDCAT TO E01_LT_FIELDCAT.

  • Sales Org

CLEAR LS_FIELDCAT.

LS_FIELDCAT-FIELDNAME = 'VKORG'.

LS_FIELDCAT-OUTPUTLEN = 10.

LS_FIELDCAT-TABNAME = 'I_OUTPUT'.

ls_fieldcat-seltext_L = 'Sales Org'.

APPEND LS_FIELDCAT TO E01_LT_FIELDCAT.

  • Customer number

CLEAR LS_FIELDCAT.

LS_FIELDCAT-FIELDNAME = 'KUNNR'.

LS_FIELDCAT-OUTPUTLEN = 10.

LS_FIELDCAT-TABNAME = 'I_OUTPUT'.

ls_fieldcat-seltext_L = 'Customer #'.

APPEND LS_FIELDCAT TO E01_LT_FIELDCAT.

  • Item #

CLEAR LS_FIELDCAT.

LS_FIELDCAT-FIELDNAME = 'POSNR'.

LS_FIELDCAT-OUTPUTLEN = 8.

LS_FIELDCAT-TABNAME = 'I_OUTPUT'.

ls_fieldcat-seltext_L = 'Item #'.

APPEND LS_FIELDCAT TO E01_LT_FIELDCAT.

  • Material #

CLEAR LS_FIELDCAT.

LS_FIELDCAT-FIELDNAME = 'MATNR'.

LS_FIELDCAT-OUTPUTLEN = 18.

LS_FIELDCAT-TABNAME = 'I_OUTPUT'.

ls_fieldcat-seltext_L = 'Material #'.

APPEND LS_FIELDCAT TO E01_LT_FIELDCAT.

  • Qty

CLEAR LS_FIELDCAT.

LS_FIELDCAT-FIELDNAME = 'KWMENG'.

LS_FIELDCAT-OUTPUTLEN = 15.

LS_FIELDCAT-TABNAME = 'I_OUTPUT'.

ls_fieldcat-seltext_L = 'Qty'.

APPEND LS_FIELDCAT TO E01_LT_FIELDCAT.

  • Net Price

CLEAR LS_FIELDCAT.

LS_FIELDCAT-FIELDNAME = 'NETPR'.

LS_FIELDCAT-OUTPUTLEN = 15.

LS_FIELDCAT-TABNAME = 'I_OUTPUT'.

ls_fieldcat-seltext_L = 'Net Price'.

APPEND LS_FIELDCAT TO E01_LT_FIELDCAT.

ENDFORM. " fieldcat_init

Thanks

Seshu

0 Kudos

Hi seshu,

thanks for ur help.

thanks alot.

0 Kudos

Hi seshu,

can anyone help me this below problem.

i am executing a program in forgroung the records are displaying fine.

but when displaying same program with Back ground with spool the record width

displaying very less.

i want record width same in foreground and background.

REGARDS,

0 Kudos

Hi Seshu,

my code is :

itab-vbeln = bseg-vbeln.

if not itab-vbeln is initial.

select single vbeln inco1 inco2 into ( itab-vbeln itab-inco1 itab-inco2)

from vbrk where vbeln = itab-vbeln.

appned itab.

note : here inco1 inco2 are incoterms

my question is can we direct move the values of bseg-vbeln into itab-vbeln. ???

and i am generating the report with one varient , when i debug this report the

there is no value in bseg-vbeln. it is showing null value.thats why my select query is not working..but i want execute this select query final.

in output i want display the inco1 inco2 data.(incoterms)

any help please.

urgent.

regards,

vijay.

0 Kudos

Hi vijay,

starting with ECC600/Basis 640 you can use the same internal table in for all entries clause as in INTO target area.

Should be something like


select vbeln inco1 inco2 
  into corresponding fields of itab
  from vbrk 
  for all entries in itab
  where vbeln = itab-vbeln.

Regards,

Clemens

0 Kudos

Hi Seshu,

the Technical people are required Functional Knowledge??

functional people are explaining theire Issues on busness level.

but Technical People Don't have Functional Knowledge.

How technical people solve issues according to functional issues.

pls.explain.

regards,

Former Member
0 Kudos

first select from VBAK into table t_vbak

if t_vbak[] is not initial.

select from vbap

for all entries in t_vbak

where vbap-vbeln = t_vbak-vbeln.

endif.

Clemenss
Active Contributor
0 Kudos

Hi vijay,

FOR ALL ENTRIES does not do a JOIN.


select vbak~vbeln vbap~posnr ...
  into corresponding fields of table i_vbak_vbap
  from VBAP "first the table with more records
  join vbap on vbap~vbeln = vbak~vbeln
  where vbak~erdat in s_erdat.

The job of combining the values from 2 databse tables in one internal table is done by the database.

The primary use of FOR ALL ENTRIES is to make sure the WHERE condition does not get too long (thousands of values in a select-option-range will cause a dump).

Regards,

Clemens