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: 

Insert entries in ABAP QUERY

Former Member
0 Kudos

Hi

I have an abap query with tables VBRK and VBRP.

The result is all of the items of VBRP.

I want to join this with the item texts, with function READ_TEXT.

How can I do that?

Thanks

Dora

1 ACCEPTED SOLUTION

former_member184158
Active Contributor
0 Kudos

now, I think it is easy to call FM and get the text. So could you please try this code,

may it help you,


REPORT zibo_pg_test99.

TYPES: BEGIN OF ty_vbrp.
       
INCLUDE STRUCTURE vbrp.
TYPES: item_txt TYPE wcf_ust_description,
END OF ty_vbrp.

DATA lt_vbrp TYPE TABLE OF ty_vbrp.

DATA lv_name TYPE tdobname.
DATA lt_item_txt TYPE TABLE OF tline.
DATA ls_item_txt TYPE tline.

FIELD-SYMBOLS <ls_vbrp> TYPE ty_vbrp.

DATA lr_alv TYPE REF TO cl_salv_table.

START-OF-SELECTION.

 
SELECT *
   
INTO CORRESPONDING FIELDS OF TABLE lt_vbrp UP TO 10 ROWS
   
FROM vbrp AS item
    INNER
JOIN vbrk AS header
 
ON header~vbeln = item~vbeln.


 
LOOP AT  lt_vbrp ASSIGNING <ls_vbrp>.
   
CONCATENATE <ls_vbrp>-vbeln <ls_vbrp>-posnr INTO lv_name.
   
CALL FUNCTION 'READ_TEXT'
     
EXPORTING
       
id       = '0001'
       
language = sy-langu
        name    
= lv_name
        object  
= 'VBBP'
     
TABLES
       
lines    = lt_item_txt
     
EXCEPTIONS
       
id       = 1
       
OTHERS   = 2.
   
IF sy-subrc <> 0.
     
CONTINUE.
   
ENDIF.

   
LOOP AT lt_item_txt INTO ls_item_txt.
     
CONCATENATE  <ls_vbrp>-item_txt

          ls_item_txt-tdline INTO <ls_vbrp>-item_txt.
   
ENDLOOP.

 
ENDLOOP.
  cl_salv_table
=>factory(
               
IMPORTING
                  r_salv_table  
= lr_alv
               
CHANGING
                   t_table       
= lt_vbrp  ).
 
lr_alv->display( ).



Regards

Ebrahim

8 REPLIES 8

former_member184158
Active Contributor
0 Kudos

Hi

so at first you can use the FM: Read_Text

but you have to find out the following details:

ID

LANGUAGE

NAME

OBJECT

how can you find them, so you have to do the following steps:

call transaction: VF03


This is the FM: Read_Text


Call transaction: VF03 and select the item, then goto--> item--> item texts.



ID : 0001

LANGUAGE : E

NAME : 0090005177000010 (Billing Document Number+Item Number)

OBJECT : VBBP

former_member184158
Active Contributor
0 Kudos

now, I think it is easy to call FM and get the text. So could you please try this code,

may it help you,


REPORT zibo_pg_test99.

TYPES: BEGIN OF ty_vbrp.
       
INCLUDE STRUCTURE vbrp.
TYPES: item_txt TYPE wcf_ust_description,
END OF ty_vbrp.

DATA lt_vbrp TYPE TABLE OF ty_vbrp.

DATA lv_name TYPE tdobname.
DATA lt_item_txt TYPE TABLE OF tline.
DATA ls_item_txt TYPE tline.

FIELD-SYMBOLS <ls_vbrp> TYPE ty_vbrp.

DATA lr_alv TYPE REF TO cl_salv_table.

START-OF-SELECTION.

 
SELECT *
   
INTO CORRESPONDING FIELDS OF TABLE lt_vbrp UP TO 10 ROWS
   
FROM vbrp AS item
    INNER
JOIN vbrk AS header
 
ON header~vbeln = item~vbeln.


 
LOOP AT  lt_vbrp ASSIGNING <ls_vbrp>.
   
CONCATENATE <ls_vbrp>-vbeln <ls_vbrp>-posnr INTO lv_name.
   
CALL FUNCTION 'READ_TEXT'
     
EXPORTING
       
id       = '0001'
       
language = sy-langu
        name    
= lv_name
        object  
= 'VBBP'
     
TABLES
       
lines    = lt_item_txt
     
EXCEPTIONS
       
id       = 1
       
OTHERS   = 2.
   
IF sy-subrc <> 0.
     
CONTINUE.
   
ENDIF.

   
LOOP AT lt_item_txt INTO ls_item_txt.
     
CONCATENATE  <ls_vbrp>-item_txt

          ls_item_txt-tdline INTO <ls_vbrp>-item_txt.
   
ENDLOOP.

 
ENDLOOP.
  cl_salv_table
=>factory(
               
IMPORTING
                  r_salv_table  
= lr_alv
               
CHANGING
                   t_table       
= lt_vbrp  ).
 
lr_alv->display( ).



Regards

Ebrahim

0 Kudos

In a program I know how to make that, but I want to make it in a abap query.

is this possible?

Thanks

Dora

0 Kudos

Yes, it is possible.

You can create an additional field in your infoset and ABAP coding for that field.

1. Create new field group (on this picture it is "02 Additional").

2. Press "Extras" button

3. Create an additional field in new fieldgroup. To do so, press the "New"  button and create a field.

Here is an example:

The result should be something like this

4. Select this field and press "coding for action" button

5. Write your own code.

5. Activate the InfoSet

6. Add this new field into your report in SQ01.

As a result, you'll get a new field with the text.

* * *

Please note, that some screenshots were automatically cut. If you want to view them, you must click on each of them.

0 Kudos

I Ivan

this work's but it shows just one line of texts.

FM READ TEXT returns a table with 10 entries and I'm not able to return all that entries here.

Can you help me?

Thanks

Dora

0 Kudos

1. In my example the entire table is being processed in a loop. As a result, all table rows are being concatenated in the one long text variable - LTEXT.

In my example the length of additional fields is limited by 100 first characters. If you want to display longer texts - you should increase the length of this field.

2. It is possible that your texts are extremely long. In that case it will be difficult to display the entire text in the single cell of ALV grid.

One of the possible workarounds is:

- create several additional text fields (e.g. LTEXT1, LTEXT2, and so on);

- split the text into several parts

- display each part in the corresponding field (e.g. part1 in LTEXT1, part2 in LTEXT2, ... ).

0 Kudos

In fact, there is no good way to display a long string in an ALV cell.

But there are two most common workarounds.

1. I have already described it in my previous reply. You can split the text into few additional text columns. But, of course, this solution is not elegant.

2. You can implement a drill-down for the text field. By default you can display first 100 characters in your text field (LTEXT). In most cases it is enougth.

But if the text is longer, user can use double-click on that cell to display entire text.

I have discovered that it is possible in SAP Query.

2.1. Create an ABAP report.

It should have two obligatory parameters with types VBRP-VBELN and VBRP-POSNR.

In the report you should retrieve the whole text with FM READ_TEXT and display it in popup window. See an example below.

2.2. Create transaction for this report.

2.3. Add the drill-down report into your query.

- Open you query in SQ01

- Goto -> Report assignment

- In the popup window "Assign reports" press the "Insert row" button.

- in the next popup press "Other report type"

- choose "Transaction" and then enter your t-code.

- As a result, you should get somethink like this:

3. That is all.

Now, run your query.

If you want, you can double-click on the row and display the whole text. In my simple example it looks like that. Of course, it is better to use a popup with CL_GUI_TEXT_EDIT instead.

- - -

REPORT z_test_19.

* Please note, that parameters types a the same as in Infoset
PARAMETERS: p_vbeln TYPE vbrp-vbeln OBLIGATORY,
             p_posnr TYPE vbrp-posnr OBLIGATORY.

DATA lv_name TYPE tdobname.
DATA lt_item_txt TYPE TABLE OF tline.
DATA: lt_text_as_table TYPE TABLE OF tline.

FIELD-SYMBOLS: <fs_item_txt> LIKE LINE OF lt_item_txt.

CONCATENATE p_vbeln p_posnr INTO lv_name.
CALL FUNCTION 'READ_TEXT'
   EXPORTING
     id       = '0001'
     language = 'R'
     name     = lv_name
     object   = 'VBBP'
   TABLES
     lines    = lt_item_txt
   EXCEPTIONS
     id       = 1
     OTHERS   = 2.
IF sy-subrc = 0.
   LOOP AT lt_item_txt ASSIGNING <fs_item_txt>.
     APPEND <fs_item_txt> TO lt_text_as_table.
   ENDLOOP.
ENDIF.



* Not excellent, but very fast example.
* In my opinion, it is better to display a popup window
* with CL_GUI_TEXTEDIT control.
* But implementation will take more time.
DATA: lr_salv TYPE REF TO cl_salv_table.

cl_salv_table=>factory(
   IMPORTING
     r_salv_table = lr_salv
   CHANGING
     t_table      = lt_text_as_table
).

lr_salv->display( ).

0 Kudos

Hi Ivan, this is a very good answer, thank you so much for all your help.