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: 

how to use feild symbol for deleting data from tables?

Former Member
0 Kudos

how to use feild symbol for deleting data from tables?

suppose itab is my internal table

in which i have 3 table xa1 xa2 xa3

and i have a condition type xa1

then i to delete entries in table where values in field

Xa1 is zero

for e.g

case cond.

when xa1.

delete itab where xa1 = 0.

when xa2.

delete itab where xa2 = 0.

when xa3.

delete itab where xa3 = 0.

endcase.

i want to use a field symbol here

points wll b rewarded

for the correct ans

With Regards

Rohan

2 REPLIES 2

Former Member
0 Kudos

Hi Rohan,

Please find the below code this would be useful.

The keys to the usage are:

1) Defining the table records and the field symbol in a similar type.

  • just an ordinary standard table

TYPES: BEGIN OF it_vbak_line,

vbeln LIKE vbak-vbeln,

vkorg LIKE vbak-vkorg,

vtweg LIKE vbak-vtweg,

spart LIKE vbak-spart,

kunnr LIKE vbak-kunnr,

END OF it_vbak_line.

DATA: it_vbak TYPE TABLE OF it_vbak_line.

FIELD-SYMBOLS: <it_vbak_line> TYPE it_vbak_line.

  • or as a screaming fast hash table for keyed reads

TYPES: BEGIN OF it_vbpa_line,

vbeln LIKE vbak-vbeln,

kunnr LIKE vbak-kunnr,

END OF it_vbpa_line.

DATA: it_vbpa TYPE HASHED TABLE OF it_vbpa_line

WITH UNIQUE KEY vbeln.

FIELD-SYMBOLS: <it_vbpa_line> TYPE it_vbpa_line.

2) In ITAB processing, utilize the ASSIGNING command.

  • loop example

LOOP AT it_vbak ASSIGNING <it_vbak_line>.

  • look at records--populate it_zpartner

  • read example

READ TABLE it_vbpa ASSIGNING <it_vbpa_line>

WITH TABLE KEY vbeln = <it_vbak_line>-vbeln.

3) Refer to the field symbol's fields in the loop or after the read.

wa_zpartner-vkorg = <it_vbak_line>-vkorg.

wa_zpartner-vtweg = <it_vbak_line>-vtweg.

wa_zpartner-spart = <it_vbak_line>-spart.

wa_zpartner-kunag = <it_vbak_line>-kunnr.

wa_zpartner-kunwe = <it_vbpa_line>-kunnr.

See the code example below for further detail. The code was written in R/3 4.6C and should work for all 4.x versions.

Code

REPORT z_cnv_zshipto_from_hist NO STANDARD PAGE HEADING

LINE-SIZE 132

LINE-COUNT 65

MESSAGE-ID z1.

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

  • Program Name: ZSHIPTO from History Creation: 07/23/2003 *

  • *

  • SAP Name : Z_CNV_ZSHIPTO_FROM_HIST Application: SD *

  • *

  • Author : James Vander Heyden Type: 1 *

______________________________________________________________________

  • Description : This program reads tables VBAK & VBPA and populates *

  • ZPARTNER. ZPARTNER table is read in by ZINTSC06. ZINTSC06 updates *

  • the ZSHIPTO relationships. *

______________________________________________________________________

  • Inputs: Selection Screen *

  • *

  • Outputs: *

______________________________________________________________________

  • External Routines *

  • Function Modules: *

  • Transactions : *

  • Programs : *

______________________________________________________________________

  • Return Codes: *

  • *

______________________________________________________________________

  • Ammendments: *

  • Programmer Date Req. # Action *

  • ================ ========== ====== ===============================*

  • J Vander Heyden 07/23/2003 PCR Initial Build *

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

----


  • DATA DICTIONARY TABLES *

----


TABLES:

zpartner.

----


  • SELECTION SCREEN LAYOUT *

----


PARAMETERS: p_load RADIOBUTTON GROUP a1 DEFAULT 'X',

p_deltab RADIOBUTTON GROUP a1.

SELECTION-SCREEN SKIP 2.

SELECT-OPTIONS: s_vkorg FOR zpartner-vkorg MEMORY ID vko OBLIGATORY

NO INTERVALS NO-EXTENSION,

s_vtweg FOR zpartner-vtweg MEMORY ID vtw OBLIGATORY

NO INTERVALS NO-EXTENSION,

s_spart FOR zpartner-spart MEMORY ID spa OBLIGATORY

NO INTERVALS NO-EXTENSION.

----


  • INTERNAL TABLES *

----


TYPES: BEGIN OF it_vbak_line,

vbeln LIKE vbak-vbeln,

vkorg LIKE vbak-vkorg,

vtweg LIKE vbak-vtweg,

spart LIKE vbak-spart,

kunnr LIKE vbak-kunnr,

END OF it_vbak_line.

DATA: it_vbak TYPE TABLE OF it_vbak_line.

FIELD-SYMBOLS: <it_vbak_line> TYPE it_vbak_line.

TYPES: BEGIN OF it_vbpa_line,

vbeln LIKE vbak-vbeln,

kunnr LIKE vbak-kunnr,

END OF it_vbpa_line.

DATA: it_vbpa TYPE HASHED TABLE OF it_vbpa_line

WITH UNIQUE KEY vbeln.

FIELD-SYMBOLS: <it_vbpa_line> TYPE it_vbpa_line.

DATA: it_zpartner TYPE TABLE OF zpartner.

DATA: wa_zpartner TYPE zpartner.

----


  • STRUCTURES *

----


----


  • VARIABLES *

----


DATA: z_mode VALUE 'N',

z_commit TYPE i,

z_good TYPE i,

z_bad TYPE i.

----


  • CONSTANTS *

----


----


  • SELECTION-SCREEN HELP *

----


----


  • INITIALIZATION *

----


INITIALIZATION.

----


  • AT LINE SELECTION *

----


AT LINE-SELECTION.

----


  • AT SELECTION SCREEN *

----


AT SELECTION-SCREEN.

----


  • START-OF-SELECTION *

----


START-OF-SELECTION.

IF p_load = 'X'.

PERFORM select_records.

PERFORM process_itab.

ELSE.

PERFORM delete_table.

ENDIF.

----


  • END-OF-SELECTION *

----


END-OF-SELECTION.

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

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

&----


*& Form DELETE_TABLE

&----


  • text

----


FORM delete_table.

DATA: w_answer.

CLEAR: w_answer.

CALL FUNCTION 'POPUP_TO_CONFIRM'

EXPORTING

titlebar = text-002

  • DIAGNOSE_OBJECT = ' '

text_question = text-003

text_button_1 = text-004

icon_button_1 = 'ICON_OKAY'

text_button_2 = text-005

icon_button_2 = 'ICON_CANCEL'

default_button = '2'

display_cancel_button = ''

  • USERDEFINED_F1_HELP = ' '

  • START_COLUMN = 25

  • START_ROW = 6

  • POPUP_TYPE =

IMPORTING

answer = w_answer.

  • TABLES

  • PARAMETER =

  • EXCEPTIONS

  • TEXT_NOT_FOUND = 1

  • OTHERS = 2

.

IF w_answer = 1.

DELETE FROM zpartner

WHERE vkorg IN s_vkorg

AND vtweg IN s_vtweg

AND spart IN s_spart.

MESSAGE i398(00) WITH 'Records deleted from table: '

sy-dbcnt

' '

' '.

ENDIF.

ENDFORM. " DELETE_TABLE

&----


*& Form SELECT_RECORDS

&----


  • text

----


FORM select_records.

  • get vbaks

CLEAR: it_vbak.

SELECT vbeln vkorg vtweg spart kunnr

FROM vbak

INTO CORRESPONDING FIELDS OF TABLE it_vbak

WHERE vkorg IN s_vkorg

AND vtweg IN s_vtweg

AND spart IN s_spart

AND auart = 'TA'.

  • get vbpa we's

CLEAR: it_vbpa.

SELECT *

FROM vbpa

INTO CORRESPONDING FIELDS OF TABLE it_vbpa

FOR ALL ENTRIES IN it_vbak

WHERE vbeln = it_vbak-vbeln

AND posnr = '000000'

AND parvw = 'WE'.

ENDFORM. " SELECT_RECORDS

&----


*& Form PROCESS_ITAB

&----


  • attempt post goods issue for all entries.

----


FORM process_itab.

LOOP AT it_vbak ASSIGNING <it_vbak_line>.

  • look at records--populate it_zpartner

READ TABLE it_vbpa ASSIGNING <it_vbpa_line>

WITH TABLE KEY vbeln = <it_vbak_line>-vbeln.

IF sy-subrc = 0.

CLEAR: wa_zpartner.

wa_zpartner-mandt = sy-mandt.

wa_zpartner-vkorg = <it_vbak_line>-vkorg.

wa_zpartner-vtweg = <it_vbak_line>-vtweg.

wa_zpartner-spart = <it_vbak_line>-spart.

wa_zpartner-kunag = <it_vbak_line>-kunnr.

wa_zpartner-kunwe = <it_vbpa_line>-kunnr.

APPEND wa_zpartner TO it_zpartner.

ENDIF.

*

ENDLOOP.

SORT it_zpartner BY mandt vkorg vtweg spart kunag kunwe..

DELETE ADJACENT DUPLICATES FROM it_zpartner.

  • do a mass table update.

INSERT zpartner FROM TABLE it_zpartner.

IF sy-subrc = 0.

MESSAGE s398(00) WITH 'Inserted records: ' sy-dbcnt.

ENDIF.

ENDFORM. " PROCESS_ITAB

pls reward if helpful.

Regards,

Sharath

0 Kudos

bro

ur ans is good but dat is not wht i want

i have given u the senario

dat is a

case

endcase

just use the above senario and try it out