I'm new in ABAP. I want my code to create a selection where I can enter a number and it shows me the list of my previously created customers.
this is the code:
REPORT ZBSP_CODING.
DATA: ls_ZBSPCUSTOMERS TYPE ZBSPCUSTOMERS,
lt_ZBSPCUSTOMERS TYPE TABLE OF ZBSPCUSTOMERS,
lv_KUNNR TYPE KUNNR.
SELECT-OPTIONS p_KUNNR FOR lv_KUNNR NO INTERVALS.
SELECT * FROM ZBSPCUSTOMERS INTO ls_ZBSPCUSTOMERS WHERE KUNNR IN p_KUNNR.
WRITE: / ls_ZBSPCUSTOMERS-KUNNR,
/ ls_ZBSPCUSTOMERS-NAME_FIRST, ls_ZBSPCUSTOMERS-NAME_LAST,
/ ls_ZBSPCUSTOMERS-STREET, ls_ZBSPCUSTOMERS-HOUSE_NUM1,
/ ls_ZBSPCUSTOMERS-POST_CODE1, ls_ZBSPCUSTOMERS-CITY1.
ENDSELECT.
the problem is, it won't show me any customers. What am I doing wrong?
There will be two cases.-
Either ZBSPCUSTOMERS table doesn't contains any data.
or might be data mismatch for leading 0's in data value for KUNNR field. So, Add these line-
SELECT-OPTIONS p_KUNNR FOR lv_KUNNR NO INTERVALS.
"-------add below lines-----
LOOP AT p_KUNNR.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = p_KUNNR-low
IMPORTING
output = p_KUNNR-low.
MODIFY p_KUNNR.
ENDLOOP.
"-------End of addition-------------
SELECT * FROM ZBSPCUSTOMERS INTO ls_ZBSPCUSTOMERS WHERE KUNNR IN p_KUNNR.
WRITE: / ls_ZBSPCUSTOMERS-KUNNR,
/ ls_ZBSPCUSTOMERS-NAME_FIRST, ls_ZBSPCUSTOMERS-NAME_LAST,
/ ls_ZBSPCUSTOMERS-STREET, ls_ZBSPCUSTOMERS-HOUSE_NUM1,
/ ls_ZBSPCUSTOMERS-POST_CODE1, ls_ZBSPCUSTOMERS-CITY1.
ENDSELECT.
CONVERSION_EXIT_ALPHA_INPUT Function module adds leading 0's in value. for ex- if DE size is 10 digit than if you enter 102, then it'll convert fron 102 to 0000000102.
Thanks everybody it was as #divScorp mentioned it the F8 button instead of the Enter-Key
Related
I'm trying to change the date format from 2020.11.20 to 11/2020
My objective is to remove the day and leave just month/year.
If I change the type of the field EDATU from vbep-EDATU to string it doesn't work.
Any tips on how to achieve my goal?
DATA: GR_COLUMNS TYPE REF TO CL_SALV_COLUMNS_TABLE,
GR_TABLE TYPE REF TO CL_SALV_TABLE.
TYPES: BEGIN OF IT_STR,
EDATU TYPE VBEP-EDATU,
vbeln type vbep-vbeln,
END OF IT_STR.
DATA: IT_FINAL TYPE STANDARD TABLE OF IT_STR.
FIELD-SYMBOLS: <F_DAT> TYPE IT_STR.
SELECT EDATU vbeln FROM VBEP INTO TABLE IT_FINAL up to 10 rows.
LOOP AT IT_FINAL ASSIGNING <F_DAT>.
<F_DAT>-EDATU = <F_DAT>-EDATU+4(2) && '/' && <F_DAT>-EDATU(4).
ENDLOOP.
TRY.
CALL METHOD CL_SALV_TABLE=>FACTORY
EXPORTING
LIST_DISPLAY = IF_SALV_C_BOOL_SAP=>FALSE
IMPORTING
R_SALV_TABLE = GR_TABLE
CHANGING
T_TABLE = IT_FINAL.
CATCH CX_SALV_MSG .
ENDTRY.
GR_COLUMNS = GR_TABLE->GET_COLUMNS( ).
CALL METHOD GR_TABLE->DISPLAY.
Even though a type D is really just a char based data type of length 8 it has some special behavior when outputting it. If you check in the debugger you will see the data in IT_FINAL is what you want, it's just that the ALV processes this data as a date regardless of the value in it.
So, for example date 20221019 got changed in IT_FINAL-EDATU to '10/2022'. Now, when you display it in the ALV it gets interpreted as a date and gets displayed depending on your user settings, assuming yours are yyyy.mm.dd the output would be: '10/2.02.2'.
You can get around this in two ways:
Add a new field to your table with a char-like type to hold the month value as suggested by Skin, and suppress the display of the EDATU field in the ALV
gr_columns->get_column( columnname = 'EDATU' )->set_technical( abap_true ).
Change the behavior of the EDATU column in the ALV by changing the edit mask with:
gr_columns->get_column( columnname = 'EDATU' )->set_edit_mask('_______').
Option 1 is clearly the better way to avoid unintended mishaps in the future.
I created a new colum type C and changed the loop to
LOOP AT IT_FINAL ASSIGNING <F_DAT>.
data(month) = <F_DAT>-EDATU+4(2).
data(year) = <F_DAT>-EDATU(4).
<f_dat>-char = month && '/' && year.
ENDLOOP.
Thanks for everyone who helped me.
I concatenated values of select-options and a parameter. The condition of that query is based on the concatenated data. I can get all the data i need.
here's my code:
TABLES: bkpf.
SELECT-OPTIONS: s_belnr FOR bkpf-belnr NO-EXTENSION OBLIGATORY .
PARAMETERS: p_ghjahr LIKE bkpf-gjahr DEFAULT sy-datum(4) OBLIGATORY. "Fiscal
DATA: it_con TYPE TABLE OF BKPF,
ls_con TYPE bkpf-AWKEY,
lv_belnr LIKE bkpf-belnr,
IT TYPE STANDARD TABLE OF BKPF,
WA TYPE BKPF.
IF s_belnr-high IS INITIAL.
CONCATENATE s_belnr-low p_ghjahr INTO ls_con.
APPEND ls_con TO it_con.
ELSE.
lv_belnr = s_belnr-low.
WHILE lv_belnr LE s_belnr-high.
CONCATENATE lv_belnr p_ghjahr INTO ls_con.
APPEND ls_con TO it_con.
ADD 1 TO lv_belnr.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = lv_belnr
IMPORTING
output = lv_belnr.
ENDWHILE.
ENDIF.
LOOP AT it_concats INTO ls_concats.
SELECT BELNR
FROM BKPF
INTO CORRESPONDING FIELDS OF TABLE IT
FOR ALL ENTRIES IN IT_CONCATS
WHERE AWKEY EQ IT_CONCATS-AWKEY.
ENDLOOP.
LOOP AT IT INTO WA.
WRITE: / WA-BELNR.
ENDLOOP.
Ignoring (because your question is too vague), the type of document you are looking for, I'll suggest something like
(WARNING, I do NOT provide full answers, just code snipets who you must tune to make it work; if someone wants to improve my answer, feel free to do it, and I'll gladly will vote the new one as the good one... if it is)
data: awkey_range type range of bkpf-awkey,
awkey_line like line of awkey_range.
* Fill the awkey_range with something like
awkey_line-sign = 'I'.
awkey_line-option = 'EQ'.
* loop at bkpf_table into bkpf_line.
* concatenate bkpf_line-belnr bkpf_line-ghjahr into awkey_line-low.
* append awkey_line to awkey_range.
* endloop.
* And then a single SQL
select *
from bkpf
into table IT "Ouch, what a name
where awkey in awkey_range.
And it should work, if I'm not missing something.
Hi ABAP users I would like to ask if what process I can make to COLLECT the data on the same field? all I want to do is to sum up or collect the data in dmbtr that belongs to same date, (date field monat) (werks to plant codes)
it_zfi_vbrp_bseg_1-num3 = it_zfi_vbrp_bseg_1-werks.
it_zfi_vbrp_bseg_1-num2 = it_zfi_vbrp_bseg_1-dmbtr.
COLLECT it_zfi_vbrp_bseg_1.
DELETE ADJACENT DUPLICATES FROM it_zfi_vbrp_bseg_1 COMPARING ALL FIELDS.
Sort it_zfi_vbrp_bseg_1 by werks.
LOOP AT it_zfi_vbrp_bseg_1 into wa_zfi_vbrp_bseg_1 WHERE monat = '01'.
IF wa_zfi_vbrp_bseg_1-werks EQ '4030'.
WRITE:/, AT pos wa_zfi_vbrp_bseg_1-dmbtr.
ENDIF.
ENDLOOP.
Any configuration in my codes guys?
Suppose, you already extended standard bseg table with monat field, then you should do like this:
TYPES: BEGIN OF ty_zfi_vbrp_bseg_1,
werks TYPE bseg-werks,
monat TYPE monat,
dmbtr TYPE bseg-dmbtr,
END OF ty_zfi_vbrp_bseg_1.
DATA: it_zfi_vbrp_bseg_1 TYPE TABLE OF ty_zfi_vbrp_bseg_1,
is_zfi_vbrp_bseg_1 TYPE ty_zfi_vbrp_bseg_1.
SELECT werks, monat, dmbtr
INTO TABLE #DATA(lt_bseg)
FROM bseg
WHERE werks = '4030'.
* summation of months
LOOP AT lt_bseg ASSIGNING FIELD-SYMBOL(<fs_line>).
CLEAR: is_zfi_vbrp_bseg_1.
MOVE-CORRESPONDING <fs_line> TO is_zfi_vbrp_bseg_1.
COLLECT is_zfi_vbrp_bseg_1 INTO it_zfi_vbrp_bseg_1.
ENDLOOP.
* output the results
LOOP AT it_zfi_vbrp_bseg_1 ASSIGNING FIELD-SYMBOL(<zfi_line>).
IF <zfi_line>-werks EQ '4030'.
WRITE: / <zfi_line>-werks, <zfi_line>-monat, <zfi_line>-dmbtr.
ENDIF.
ENDLOOP.
Couple of notes to your incorrect code:
COLLECT doesn't work like single statement and should be executed in loop.
To sum with COLLECT statement you should declare work area so that all non-key fields would be numeric. Key fields (even if it is implicit key) can be of any type, as opposed to what Ray said. N type is also OK.
DELETE ADJACENT DUPLICATES is redundant here, because after COLLECT (which makes summation by primary key) you won't have any dups.
This all comes down to how you define your internal table it_zfi_vbrp_bseg_1
For COLLECT to work, you need to define it with character type keys followed by packed field types:
data: begin of it_zfi_vbrp_bseg_1 occurs 0,
werks type werks,
month(2) type c,
dmbtr type dmbtr,
end of it_zfi_vbrp_bseg_1.
That will work.
This will not:
data: begin of it_zfi_vbrp_bseg_1 occurs 0.
include structure vbrp.
data: monat type monat,
dmbtr type dmbtr,
end of it_zfi_vbrp_bseg.
Read the help on COLLECT and define your summary table accordingly.
TABLES: VBRK.
DATA: BEGIN OF it_test,
BUKRS LIKE VBRK-BUKRS,
FKDAT LIKE VBRK-FKDAT,
END OF it_test.
DATA: wa_test LIKE it_test.
SELECT * FROM VBRK INTO CORRESPONDING FIELD OF wa_test.
IF wa_test-BUKRS = 'xxxx'.
wa_test-BUKRS = 'XXXXX' "Problem occurs here as the BUKRS allow 4 value
APPEND wa_test TO it_test.
ENDIF.
Then I want to map the internal table to output as ALV table. Is they any way to change the field length afterwards?
Apart from multiple issues in your code, you can't. If you need something similar to that, add an additional field to the structure with whatever size you require and copy the values over.
If the objective is to output something to the screen that is different(or differently formatted) that what is stored internally(or in the database), then the use of a data element with a conversion exit maybe the way to go.
For an example, look at the key fields of table PRPS.
Expanding the answer of vwegert:
The MOVE-CORRESPONDINGcommand (and SELECT ... INTO CORRESPONDING FIELDS) don't need the same field type. The content is converted. So you could define a 5-character field in your internal structure and copy the BUKRS-value into this 5-character field:
TABLES: VBRK.
DATA: BEGIN OF it_test,
BUKRS(5), "longer version of VBRK-BUKRS,
FKDAT LIKE VBRK-FKDAT,
END OF it_test.
DATA: tt_test TYPE STANDARD TABLE OF it_test.
* I would strongly recommend to set a filter!
SELECT * FROM VBRK INTO CORRESPONDING FIELD OF it_test.
IF it_test-BUKRS = 'xxxx'.
it_test-BUKRS = 'XXXXX'.
APPEND it_test to tt_test.
ENDIF.
ENDSELECT.
A pitfall: When you use it with ALV you will loose the field description. (on the other side, the field description of the original field will not fit any longer the new field.)
I have a database table named zrswheel .I entered 3 datas and want to show them on screen.Here s my code
REPORT ZRS_WHEEL.
TYPES:
BEGIN OF ty_zrswheel,
lv_brand TYPE c,
lv_dimension TYPE i,
lv_pressure TYPE i,
END OF ty_zrswheel.
DATA:
wa_zrswheel TYPE ty_zrswheel,
it_zrswheel TYPE TABLE of ty_zrswheel.
SELECT dimension pressure brand
FROM zrswheel
INTO TABLE it_zrswheel.
*WHERE ID=''.
IF sy-subrc NE 0.
write: 'There is an Error in retrieving data.'.
ELSE.
LOOP AT it_zrswheel INTO wa_zrswheel.
WRITE: wa_zrswheel-lv_dimension,wa_zrswheel-lv_brand,wa_zrswheel-lv_pressure.
NEW-LINE.
ENDLOOP.
ENDIF.
When I execute I get this error:
Runtime Errors : DBIF_RSQL_INVALID_RSQL
Except. CX_SY_OPEN_SQL_DB
What is the structure of your zrswheel?
Does it fit to your internal structure ty_zrswheel?
Without knowing the structure of zrswheel, nobody can help you.
The following is just a guess from my side.
It is very unusual to call fields in a structure like lv_.
So I think your zrswheel is defined as:
dimension type c,
brand type i
pressure type i
I think your report should look like:
REPORT ZRS_WHEEL.
DATA:
wa_zrswheel TYPE zrswheel,
it_zrswheel TYPE TABLE of zrswheel.
SELECT * FROM zrswheel INTO TABLE it_zrswheel.
LOOP AT it_zrswheel INTO wa_zrswheel.
WRITE: / wa_zrswheel-dimension,wa_zrswheel-brand,wa_zrswheel-pressure.
ENDLOOP.
IF sy-subrc NE 0.
write: 'Nothing found'.
ENDIF.
If you want only select an extract of zrswheel, then try:
REPORT ZRS_WHEEL.
TYPES:
BEGIN OF ty_zrswheel,
brand LIKE zrswheel-brand, "or lv_brand?
dimension LIKE zrswheel-dimension, "or lv_dimension?,
pressure LIKE zrswheel-pressure, "or lv_pressure?,
END OF ty_zrswheel.
DATA:
wa_zrswheel TYPE ty_zrswheel,
it_zrswheel TYPE TABLE of ty_zrswheel.
SELECT *FROM zrswheel
INTO corresponding fields of TABLE it_zrswheel.
LOOP AT it_zrswheel INTO wa_zrswheel.
WRITE: / wa_zrswheel-dimension,wa_zrswheel-brand,wa_zrswheel-pressure.
ENDLOOP.
IF sy-subrc NE 0.
write: 'There is an Error in retrieving data.'.
ENDIF.
Remark:
I'm not sure about the correct syntax of INTO CORRESPONDING FIELDS - please check the online help or wait for my update when I have a SAP-system to check the syntax)
Check your order of fields in the structure and in the select statement. Ensure the data types and length match for the fields .