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

ABAP code in SQ01

Former Member
0 Likes
5,678

Hi,

I have very limited experience of coding in ABAP

Basically I want to take dataset from a database table, and manipulate it, and output this into a report in SQ01

Is this possible?

Any help would be greatly appreciated

Thanks

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
4,795

Hi Brian,

  

I propose to consider a similar example.

Query based on join table KNA1 with KNVK .

 

There are 3 lines being generated because there are 3 telephone numbers

per customer 13023 in KNVK.

In "Extras" we add an abap code.

We use fields “Telephone 2” and “Telebox”  to place the second and third telephone numbers

on the first line and skip other lines with statement "CHECK 0 = 1".

.

Finally we have

Regards

Boris    

10 REPLIES 10
Read only

FredericGirod
Active Contributor
0 Likes
4,795

Hi Brian,

if you are limited in ABAP (or SQL) try the SQVI transaction. It's more simple.

If you need help maybe give us the requierment.

Regards

Fred    

Read only

0 Likes
4,795

Basically I want to take a field from a row, add that field to a different row, then delete the entire row... Hope that makes sense?

This is the code im working with...

   clear ADR2-TEL_EXTENS.
DATA: countTelephone TYPE int4.

SELECT COUNT( DISTINCT TEL_NUMBER ) FROM ADR2
  INTO countTelephone
  WHERE ADDRNUMBER = KNA1-ADRNR.
if countTelephone > 1.

  DATA TEMP_TABLE LIKE ADR2 OCCURS 10 WITH HEADER LINE.
  LOOP AT TEMP_TABLE.
    DELETE TEMP_TABLE WHERE CONSNUMBER = '002'.
    ADR2-TEL_EXTENS = ADR2-TEL_NUMBER.
  ENDLOOP.

endif.

Read only

0 Likes
4,795

(i have not check the code)

for me it's better to do like that :

types : begin of ts_adr2 occurs ,

addrnumber type ... ,

tel_number type ... ,

count type i ,

end of ts_adr2 ,

tt_adr2 type table of ts_adr2.

data : it_adr2 type tt_adr2 ,

it_temp type tt_adr2 ,

is_adr2 type ts_adr2.

select addrnumber tel_number

into table it_adr2

from adr2

where ...

sort it_adr2.

loop at it_adr2 into is_adr2.

move 1 to is_adr2-count.

condense is_adr2 to it_temp.

endloop.

you will have into the table IT_TEMP the count set with the number of different addrnumber / tel_numbeR.

(after I'm not sure to understand what you expected to delete)

Fred

Read only

0 Likes
4,795

Brian Murphy wrote:

Basically I want to take a field from a row, add that field to a different row, then delete the entire row... Hope that makes sense?

Not really... If you look at the report generated for a query, you'll see that it's basically one giant SELECT... ENDSELECT. There is no internal table to manipulate. Everything is processed one line at a time. So the coding options are limited by this design.

Read only

0 Likes
4,793

Thanks for the help.

This is what I currently have...

KNA1 linked with ARD2 on the Address Number field.

I want to have 1 line per customer - but there are 2 lines being generated because there are 2 telephone numbers per customer.

I need to take the second telephone number and add it to a different field on the first line

Can I use a Group By to get rid of the second line?

Thanks

Read only

0 Likes
4,793

You can't make that with a simple query, with an abap code it's simple.

we could help you to write this code

Fred    

Read only

0 Likes
4,793

What would the ABAP code be?

Please bear in mind that this is an SQ01 report

Thanks

Read only

Former Member
0 Likes
4,796

Hi Brian,

  

I propose to consider a similar example.

Query based on join table KNA1 with KNVK .

 

There are 3 lines being generated because there are 3 telephone numbers

per customer 13023 in KNVK.

In "Extras" we add an abap code.

We use fields “Telephone 2” and “Telebox”  to place the second and third telephone numbers

on the first line and skip other lines with statement "CHECK 0 = 1".

.

Finally we have

Regards

Boris    

Read only

0 Likes
4,793

Thank you very much for posting, very helpful!

Can I please ask one or two questions with regards to your code?

Would you be able to explain what the following peices of code are:

  • READ TABLE it_knvk INTO st_knvk
  • What is "sy_subrc"?
  • What is "sy_tabix"?

Thank you

Read only

0 Likes
4,793

Hi Brian,

I use " READ TABLE it_knvk  .... "  to determine the first line for each customer among

all the lines which query supplies for every customer.

" sy-subrc NE 0 " means that we have first line for customer.

In this case the internal table "it_knvk" does not have records containing phone numbers of the customer and I select all phone numbers from database table KNVK into  internal table "it_knvk".

After that in " Loop ... "  sy-tabix give the number of line in internal table " it_knvk " 

making it possible to place all telephone numbers on the first line .

Regards

Boris