Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

SAP Query

Former Member
0 Likes
660

Dear All.

I have to add some extra validations in an existing SAP Query.

Current Scenario : Now the Query is fetching the details from the tables VBAK & VBAP.

Proposed : After fetching these details I need to check the following . Check whether the field (VBELN) is included in another table(Z-TABLE) or not. If it is there I have to remove that record.

How I will write the code?

Where can I write the code?

Please help me.

Regards,

Lijo

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
627

Hi Lijo,

Go to TCODE : SQ02. Give Infoset name. Under Data fields you will find technical names as VBAK , VBAP etc

Right click on VBAK and select "Code for record processing" . On the right the coding section will open up.

Regards

5 REPLIES 5
Read only

Former Member
0 Likes
627

Hi Lijo,

-> After fetching the values from the table, put a select query on the Z-Table comparing the value of VBELN, and check for the SY-SUBRC value, if the value of SY-SUBRC = 0, record exist, oderwise it doesnt.

-> to remove the record from the Z-Table, use DELETE ZTable where vbeln = vbeln.

Hope this will work fine.

Regards

Karan Arya

Read only

0 Likes
627

Hello Karan,

Thanks for the reply.

My requirement is - Where can I write the code

In infoset(In which area)? SAP Query(In which area)?

or in Report Program which has been automatically generated from the Query?

Can you please let me know?

Regards,

Lijo.

Read only

Former Member
0 Likes
628

Hi Lijo,

Go to TCODE : SQ02. Give Infoset name. Under Data fields you will find technical names as VBAK , VBAP etc

Right click on VBAK and select "Code for record processing" . On the right the coding section will open up.

Regards

Read only

Former Member
0 Likes
627

Hi,

Write the above said logic in ,

Goto Tcode SQ02, select the reuired infoset, then click Change button,

Then Click on the required table and select the Code Button (Shift + F8) .

There in the drop down list in code section, select Record Processing,

then write your code.

Hope you clear in the steps.

Read only

former_member222860
Active Contributor
0 Likes
627

Hey Lijo,

If u want to incorporate ur requirement in report program,, the following piece works:

TABLES: vbak, vbap, zvbak_t.

DATA: BEGIN OF ITAB OCCURS 0,
        VBELN LIKE VBAK-VBELN,
        POSNR LIKE VBAP-POSNR,
      END OF ITAB.

DATA: BEGIN OF ztab occurs 0.
        INCLUDE STRUCTURE zvbak_t.
DATA: END of ztab.

SELECT-OPTIONS: s_vbeln for VBAK-VBELN.

SELECT   a~vbeln
         b~posnr
    INTO  CORRESPONDING FIELDS OF TABLE itab
    FROM  ( VBAK  AS a INNER JOIN VBAP AS b
      ON    a~vbeln = b~vbeln )
   WHERE  a~vbeln IN s_vbeln.

select * from zvbak_t into table ztab for all entries in itab where vbeln = itab-vbeln.

*loop at ztab.
*write:/ ztab-vbeln.
*endloop.
*
write:/ sy-dbcnt.

if sy-subrc = 0.
delete zvbak_t from table ztab.
endif.

thanks\

Mahesh