2014 Sep 03 5:23 PM
Dear experts,
I have an cust. table where once per week from 1 to 3 different values will be written.
Currently I have 3 variables for each table field and I do following:
SELECT *
FROM zdyu_vstel
INTO CORRESPONDING FIELDS OF TABLE ta_dyu_vstel.
LOOP AT ta_dyu_vstel
INTO wa_dyu_vstel.
IF sy-tabix = 1.
v_vstel_1 = wa_dyu_vstel-vstel.
ENDIF.
IF sy-tabix = 2.
v_vstel_2 = wa_dyu_vstel-vstel.
ENDIF.
IF sy-tabix = 2.
v_vstel_3 = wa_dyu_vstel-vstel.
ENDIF.
ENDLOOP.
Could you give me some advise how I can use just one variable in my program which would loop the table and in depends of the ammount of the fields buil itself containing every unique field?
Thank you in advance.
2014 Sep 04 9:11 AM
Hi
I don't know if I've understood exaclty what you need, but if your result has to be:
CONCATENATE sv_vstel_1 v_vstel_2 v_vstel_3
INTO v_string
SEPARATED BY '-'.
You can use only V_STRING:
DATA: L_OFFSET TYPE I.
L_OFFSET = 0.
LOOP AT ta_dyu_vstel
INTO wa_dyu_vstel.
IF NOT V_STRING IS INITIAL.
V_STRING+L_OFFSET = '-'.
L_OFFSET = L_OFFSET + 1.
ENDIF.
V_STRING+L_OFFSET(4) = wa_dyu_vstel-vstel.
L_OFFSET = L_OFFSET + 4.
Max
Hi
I don't know if I've understood exaclty what you need, but if your result has to be:
CONCATENATE sv_vstel_1 v_vstel_2 v_vstel_3
INTO v_string
SEPARATED BY '-'.
You can use only V_STRING:
DATA: L_OFFSET TYPE I.
L_OFFSET = 0.
LOOP AT ta_dyu_vstel
INTO wa_dyu_vstel.
IF NOT V_STRING IS INITIAL.
V_STRING+L_OFFSET = '-'.
L_OFFSET = L_OFFSET + 1.
ENDIF.
V_STRING+L_OFFSET(4) = wa_dyu_vstel-vstel.
L_OFFSET = L_OFFSET + 4.
Max
2014 Sep 03 5:45 PM
Hi
You should explain us what you need to do with V_VSTLE_x variables else it's not easy to give you a solution
Max
2014 Sep 04 8:23 AM
Hi Max,
the point is simple. I use theese variables as a part of the file name I sent as a spool.
I have 2 reports: the first report check the information about shipping points and save the results in the table with following structure:
The second report sent the email with some information from the table above and as a name for the file I want use the shipping point, but the problem is that sometimes as a result of the first report i have only 1 shipping point and sometimes 3.
So I have created 3 different variables for each shipping point and do the code above and after I get the variables I do this:
CONCATENATE sv_vstel_1 v_vstel_2 v_vstel_3
INTO v_string
SEPARATED BY '-'.
So the question: would it be possible just to have one variable which would contain exactly vstel, which are to find in the result table?
I hope it is understandable.
2014 Sep 04 1:22 AM
I don't know exactly what you need. But if you really need to use v_vstle_x variables, you can do it:
REPORT zmrl_tst.
DATA: lv_1 TYPE string, "Your variable v_vstel_1
lv_2 TYPE string, "Your variable v_vstel_2
lv_3 TYPE string, "Your variable v_vstel_2
lv_i TYPE i VALUE 1,
lv_var TYPE string.
FIELD-SYMBOLS: <fs_lv>.
WHILE lv_i LT 4. "loop at your internal table
lv_var = lv_i. "here you can put lv_tabix = sy-tabix. Declare lv_tabix as text variable
CONCATENATE 'lv_' lv_var INTO lv_var. "here you put concatenate 'v_vstel_' lv_tabix into lv_var.
ASSIGN (lv_var) TO <fs_lv>.
<fs_lv> = lv_i. "here you put <fs_lv> = wa_dyu_vstel-vstel.
ADD 1 TO lv_i. "you don't need this.
ENDWHILE.
WRITE: lv_1, lv_2, lv_3.
2014 Sep 04 5:09 AM
Hi,
Another attempt...
2014 Sep 04 5:26 AM
2014 Sep 04 9:11 AM
Hi
I don't know if I've understood exaclty what you need, but if your result has to be:
CONCATENATE sv_vstel_1 v_vstel_2 v_vstel_3
INTO v_string
SEPARATED BY '-'.
You can use only V_STRING:
DATA: L_OFFSET TYPE I.
L_OFFSET = 0.
LOOP AT ta_dyu_vstel
INTO wa_dyu_vstel.
IF NOT V_STRING IS INITIAL.
V_STRING+L_OFFSET = '-'.
L_OFFSET = L_OFFSET + 1.
ENDIF.
V_STRING+L_OFFSET(4) = wa_dyu_vstel-vstel.
L_OFFSET = L_OFFSET + 4.
Max
2014 Sep 04 9:44 AM
Hi,
Unfortunately I get the error message:
At the write position, you cannot use offset and lenght specifixcations with fields of type "STRING"
or "XSTRING".
2014 Sep 04 3:13 PM
Hi
You've defined V_STRING TYPE STRING, that means your variable is a string with indefinite length, so try to define it as string having a certain lenght
DATA: V_STRING(N) TYPE C
N should be the max lenght
Max
2014 Sep 04 3:50 PM
Hi Denis,
Please try the below code.
I am using your code as base with some modifications.
DATA : l_v_vstel TYPE vstel.
Select *
FROM zdyu_vstel
INTO CORRESPONDING FIELDS OF TABLE ta_dyu_vstel.
LOOP AT ta_dyu_vstel
INTO wa_dyu_vstel.
IF sy-tabix EQ 1 .
l_v_vstel = wa_dyu_vstel-vstel.
ELSEIF l_v_count GT 1 AND LE 3.
CONCATENATE l_ v_vstel wa_dyu_vstel-vstel INTO l_v_vstel SEPARATED BY '-'.
ENDIF.
ENDLOOP.
Hope it helps you.
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |